#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# The build system doesn't use any flags from the environment! Pass
# CFLAGS/CPPFLAGS via OPTIMIZER, LDFLAGS by patching the build system.

# Not entirely true anymore.

# We have patched the build system to pick up the Debian build flags
# from the environment and do NOT use the OPTMIZER setting.
# So this works now. 
 
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -g
 
%:
	dh $@

d_server = $(CURDIR)/debian/hylafaxplus-server
d_client = $(CURDIR)/debian/hylafaxplus-client
d_lib = $(CURDIR)/debian/libfaxutil
d_doc = /usr/share/doc

override_dh_auto_configure:
	cp -p /usr/share/misc/config.* .
	yes | /bin/bash ./configure \
		--with-HTML=yes \
		--with-REGEX=no \
		--with-LIBREGEX='' \
		--with-REGEXINC='' \
		--with-UTMP=auto \
		--with-DIR_BIN="/usr/bin" \
		--with-DIR_LIBDATA="/etc/hylafax" \
		--with-DIR_LIB="/usr/lib/hylafax" \
		--with-DIR_LIBEXEC="/usr/sbin" \
		--with-DIR_MAN="/usr/share/man" \
		--with-DIR_SBIN="/usr/sbin" \
		--with-DIR_LOCKS="/var/lock" \
		--with-PATH_AFM="/usr/share/fonts/type1/gsfonts" \
		--with-FONTMAP="/usr/share/ghostscript/9.19/lib" \
		--with-MANSCHEME="bsd-source-gzip-strip" \
		--with-DIR_HTML="/usr/share/doc/hylafax" \
		--with-DIR_CGI="/usr/lib/cgi-bin" \
		--with-HTMLPATH="/doc/hylafax" \
		--with-SYSGID="root" \
		--with-SYSUID="root" \
		--with-PATH_GETTY="/etc/hylafax/getty-link" \
		--with-PATH_VGETTY="/etc/hylafax/vgetty-link" \
		--with-PATH_EGETTY="/etc/hylafax/egetty-link" \
		--with-CONFIG_MAXGID="65534" \
		--with-CMP="/usr/bin/cmp" \
		--with-COL="/usr/bin/col" \
		--with-MKFIFO="/usr/bin/mkfifo" \
		--with-SORT="/usr/bin/sort" \
		--with-OPTIMIZER="" \
		--with-MANDIR="/usr/share/man" \
		--with-PATH_DPSRIP="" \
		--with-PATH_IMPRIP="/usr/bin/psrip" \
		--with-AWK="/usr/bin/awk"

override_dh_missing override_dh_dwz:


override_dh_auto_build:
	dh_auto_build --no-parallel

override_dh_auto_install:
	dh_auto_install -- INSTALLROOT=$(CURDIR)/debian/tmp

override_dh_shlibdeps:
	dh_shlibdeps -l /usr/lib/hylafax/

override_dh_installinit:
	dh_installinit -n --name=hylafax

override_dh_installchangelogs:
	dh_installchangelogs
	mv $(d_server)$(d_doc)/hylafaxplus-server/changelog.Debian $(d_server)$(d_doc)/hylafaxplus-server/changelog.Devuan
	mv $(d_client)$(d_doc)/hylafaxplus-client/changelog.Debian $(d_client)$(d_doc)/hylafaxplus-client/changelog.Devuan
	mv $(d_lib)$(d_doc)/libfaxutil/changelog.Debian $(d_lib)$(d_doc)/libfaxutil/changelog.Devuan

override_dh_installexamples:
	dh_installexamples debian/examples/*

override_dh_installcron:
	dh_installcron --name=hylafax

override_dh_installlogrotate:
	dh_installlogrotate --name xferfaxlog

override_dh_fixperms:
	dh_fixperms
	chgrp uucp $(d_server)/etc/hylafax
	for i in client config dev info log recvq status archive docq doneq pollq sendq tmp .; \
	do chown uucp:uucp $(d_server)/var/spool/hylafax/$$i; done
	for i in archive docq doneq pollq sendq; \
	do chmod 755 $(d_server)/var/spool/hylafax/$$i; done
	chmod 775 $(d_server)/var/spool/hylafax
	chmod 1777 $(d_server)/var/spool/hylafax/tmp
	chmod 755  $(d_server)/var/spool/hylafax/dev
	chown uucp $(d_server)/var/spool/hylafax/etc/hosts.hfaxd
	chmod 600  $(d_server)/var/spool/hylafax/etc/hosts.hfaxd
	chown uucp:uucp $(d_server)/var/spool/hylafax/log/xferfaxlog
	chmod 660 $(d_server)/var/spool/hylafax/log/xferfaxlog
