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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export FFLAGS += -fallow-argument-mismatch

%:
	dh $@

# The network variants pick up the exported -fallow-argument-mismatch through
# src/Makefile, but src-phd/Makefile assigns FFLAGS with ':=' so that flag is
# discarded for profphd_net.  That Makefile instead rewrites the hardening
# '-Wformat -Werror=format-security' entry of CFLAGS into
# -fallow-argument-mismatch (skip_some_flags_for_fortran.patch), so build the
# net binaries/man pages as before and build src-phd separately with that CFLAGS
# value.  gfortran >= 10 requires -fallow-argument-mismatch for the
# INTEGER(2)/INTEGER(4) argument mismatches in phd.f.
override_dh_auto_build:
	make patch
	make CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" net man
	make CFLAGS="-Wformat -Werror=format-security" LDFLAGS="$(LDFLAGS)" phd

override_dh_auto_install:
	$(MAKE) DESTDIR=$(CURDIR)/debian/profnet-bval prefix=/usr install-bval
	$(MAKE) DESTDIR=$(CURDIR)/debian/profnet-chop prefix=/usr install-chop
	$(MAKE) DESTDIR=$(CURDIR)/debian/profnet-con prefix=/usr install-con
	$(MAKE) DESTDIR=$(CURDIR)/debian/profnet-isis prefix=/usr install-isis
	$(MAKE) DESTDIR=$(CURDIR)/debian/profnet-md prefix=/usr install-md
	$(MAKE) DESTDIR=$(CURDIR)/debian/profnet-norsnet prefix=/usr install-norsnet
	$(MAKE) DESTDIR=$(CURDIR)/debian/profnet-prof prefix=/usr install-prof
	$(MAKE) DESTDIR=$(CURDIR)/debian/profnet-snapfun prefix=/usr install-snapfun
	$(MAKE) DESTDIR=$(CURDIR)/debian/profphd-net prefix=/usr install-phd

override_dh_shlibdeps:
	dh_shlibdeps
	# sneak in common part of package descriptions
	for i in $$(sed -n '/^Package: / s///p' debian/control); do \
		cat debian/Description >> debian/$$i.substvars; \
	done;
