#!/usr/bin/make -f

# verbose output from dpkg-buildpackage
export DEB_BUILD_OPTIONS=debug
# debhelper verbose mode
# export DH_VERBOSE=yes
# standard debhelper compatibility level
export DH_OPTIONS =

# expect this to be something like ../build/deb/pcp-X.Y.Z
here := $(shell pwd)

# some globals we need
#
export GZIP = -9qn
export DIST_TMPFILES = $(here)/install.tmpfiles
export DIST_ROOT = $(here)/debian/pcp
export NO_CHOWN=true

configure_tools = export QT_SELECT=5;
# Note: configure options come from $(configure_paths) _plus_ any
#       passed in from the environment via $(configure_opts)
# Makepkgs uses the latter mechanism to refine the configure options
# but for distro builds $(configure_opts) is not set in the environment
# and defaults to --with-non-debug=yes (so assert() is a no-op)
#
ifeq "$(configure_opts)" ""
configure_opts = --with-non-debug=yes
endif
configure_paths = --prefix=/usr --libexecdir=/usr/lib --sysconfdir=/etc --localstatedir=/var --with-rcdir=/etc/init.d --with-sysconfigdir=/etc/default --with-zip=/bin/gzip --with-tar=/bin/tar SED=/bin/sed ECHO=/bin/echo QMAKE=/usr/bin/qmake MAKEDEPEND=/bin/true BZIP2=/bin/bzip2

# for dh_autoreconf, which runs autoreconf, there are some things we don't
# want run
#
export AUTOCONF = true
export AUTOHEADER = true

%:
	dh $@ --with python3

# pass in all our configure magic
#
override_dh_auto_configure:
	$(configure_tools) dh_auto_configure -- $(configure_paths) $(configure_debug) $(configure_opts)

# need some extra work here ...
#
override_dh_clean:
	dh_clean
	@# stuff we leave behind after make clean
	-rm -f qa/localconfig src/include/builddefs src/include/pcp.conf

# need less work here ...
#
override_dh_auto_clean:
	make clean
	@# stuff we leave behind after make clean
	-rm -f qa/localconfig src/include/builddefs src/include/pcp.conf

# post-auto-install flags
# -v => report per-package processing of .install (or other filelist) and
#	.dirs
# -v -v => as above plus report /* trimming from *.install, glob expansion
# 	from *.install
# -v -v -v => as above plus dump tarball contents used for copying from
# 	pcp into the other packages
#
override_dh_auto_install:
	dh_auto_install --destdir=debian/pcp
	debian/post-auto-install -v -v

# nothing to do here, all done in override_dh_auto_install
# (really debian/post-auto-install)
#
override_dh_install:

# we have some "special" cases
#
override_dh_fixperms:
	dh_fixperms -Xvar/lib/pcp/tmp -Xvar/lib/pcp/pmcd -Xusr/lib/pcp/bin

# the "auto-generated" recipe is not well-matched to the PCP services
# architecture, leading to things like this when the packages are installed
# ...
# pmie_daily.service is a disabled or a static unit not running, not starting...
# ...
# Could not execute systemctl:  at /usr/bin/deb-systemd-invoke line ...
#
# Leave all this to our roll-you-own methods in the *.pre* and *.post*
# scripts
#
override_dh_systemd_enable:
override_dh_systemd_start:
override_dh_installinit:

# up the verbosity here so we can see all the warnings
#
override_dh_shlibdeps:
	dh_shlibdeps -- -v

# our Python scripts use #!/usr/bin/env pmpython, so don't rewrite #!
#
override_dh_python3:
	dh_python3 --no-shebang-rewrite
