#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/pkg-info.mk

%:
	dh $@ -Dsoftware

override_dh_auto_clean:
	make -C software -f Makefile.linux clean
	dh_auto_clean -Dsoftware/tools

override_dh_auto_build:
	dh_auto_build --buildsystem=makefile -Dsoftware -- -f Makefile.linux CFLAGS="$(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIC -IKeccak -DGIT_VERSION=\\\"$(DEB_VERSION_UPSTREAM)\\\" -DGIT_COMMIT=\\\"Debian\\\" -DGIT_DATE=\\\"$(shell date --utc +%FT%T%:z -d @$(SOURCE_DATE_EPOCH))\\\" -DLINUX"
	dh_auto_build -Dsoftware/tools -- CFLAGS="$(CPPFLAGS) $(CFLAGS) $(LDFLAGS)"

override_dh_auto_configure:
# Copy various files so that debhelper tools can process them
	cp software/init_scripts/infnoise.conf.systemd debian/infnoise.conf
	cp software/init_scripts/75-infnoise.rules debian/infnoise.udev
	cp software/init_scripts/infnoise.service.sbin debian/infnoise.service

override_dh_auto_install:
	mkdir tmp
	for file in passgen dice entcheck hex2bin bin2hex findlongest flipbits; do mv software/tools/$${file} software/tools/infnoise-$${file}; cp software/tools/$${file}.1 tmp/infnoise-$${file}.1; done
	mv software/tools/healthcheck software/tools/infnoise-healthcheck
	cp software/healthcheck.1 tmp/infnoise-healthcheck.1

override_dh_installinit:
	dh_installinit --error-handler=true