#!/usr/bin/make -f

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Ensure that we link against all needed libraries (cf. Policy 10.2)
# This needs adding libraries to libpengine_la_LIBADD
# Not upstreamed, see https://github.com/ClusterLabs/pacemaker/pull/800
export DEB_LDFLAGS_MAINT_APPEND=-Wl,-z,defs

# Avoid useless dependencies in the utilities
export DEB_LDFLAGS_MAINT_APPEND+=-Wl,--as-needed

# Ubuntu/i386 shrank into a compatibility layer not carrying the
# dependencies of some of our binary packages (#948379):
ifeq ($(shell dpkg-vendor --query vendor)/$(DEB_HOST_ARCH), Ubuntu/i386)
    UBUNTU_EXCLUDES = \
	-Npacemaker \
	-Npacemaker-cli-utils \
	-Npacemaker-remote \
	-Npacemaker-resource-agents
endif

# https://bugs.launchpad.net/bugs/1915828
#
# Programs using libqb logging exit due to failed assertion on qb log init.
#
# The libqb docs do contain two suggestions to possibly work around this bug,
# specifically using either -l:libqb.so.0 or -DQB_KILL_ATTRIBUTE_SECTION, or
# both. Either or both approaches do help with the simple test case, but more
# testing is needed that actually exercises the log functionality to make sure
# nothing else breaks.
CFLAGS = -DQB_KILL_ATTRIBUTE_SECTION

# https://bugs.launchpad.net/bugs/1881762 (LP: #1881762)
#
# Sticking with ftime() causes deprecation errors. By mistake clock_gettime()
# code was not finished and made default in version 2.0.3 (git log: b5ff0e4).
# I could have removed ftime() support by picking upstream merges #1992 and
# #1997 entirely, but for the purpose of a SRU it didn't feel right (after
# discussions with SRU team).
#
# Commenting the line below will re-enable ftime() clock functions but,
# unfortunately, it will break nagios and systemd resources support (as they
# require clock_gettime). It will also cause compilation warning-as-errors
# for deprecated ftime() function (which can be work around by
# -Wno-error=deprecated-declarations if ever needed).
#
CPPFLAGS = -UPCMK_TIME_EMERGENCY_CGT

%:
	dh $@ --with python3 $(UBUNTU_EXCLUDES)

# autoreconf options taken from autogen.sh
# without symlink usage (-s) to make --as-needed effective
override_dh_autoreconf:
	dh_autoreconf --as-needed autoreconf -- -vif -Wno-portability

# Explicit BASH_PATH makes build reproducible on merged-usr vs non-merged:
override_dh_auto_configure:
	dh_auto_configure -- --disable-static \
		BASH_PATH=/bin/bash \
		PYTHON=/usr/bin/python3 \
		--with-brand=clusterlabs \
		--with-configdir=/etc/default \
		--libexecdir=/usr/lib
# because the daemon executables and Nagios plugins don't need multiarch paths

override_dh_auto_build-indep:
	dh_auto_build
	$(MAKE) -C doc doxygen
	# the Doxygen output isn't installed, we can cleanup immediately:
	rm doc/api/html/*.md5

# make check does not check the compiled software, but rebuilds everything
# with clang.  This takes a lot of time and does not help us at all.  Skip.
override_dh_auto_test:

override_dh_install:
	rm -r	debian/tmp/usr/lib/*/lib*.la \
		debian/tmp/usr/share/doc/pacemaker/COPYING \
		debian/tmp/usr/share/doc/pacemaker/README.markdown \
		debian/tmp/usr/share/doc/pacemaker/licenses
	dh_install

override_dh_installdocs:
	dh_installdocs -A README.markdown

override_dh_installinit:
# Upstream ships the pacemaker and pacemaker-remote init files,
# so we have to force the maintainer script modifications
	dh_installinit --onlyscripts --no-restart-after-upgrade -p pacemaker
	dh_installinit --onlyscripts --no-restart-after-upgrade -p pacemaker-remote --name=pacemaker_remote

override_dh_installsystemd:
	dh_installsystemd --no-restart-after-upgrade

override_dh_missing:
	dh_missing --fail-missing

override_dh_auto_clean:
	dh_auto_clean
	rm -rf doc/api
