#!/usr/bin/make -f

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

# We can't ensure that we link against all needed libraries (cf. Policy 10.2),
# because libpe_status uses get_object_root from libcib and libcib uses
# symbols from libpe_rules, which is built in the same subdir.
# Not upstreamed, see https://github.com/ClusterLabs/pacemaker/pull/800
#export DEB_LDFLAGS_MAINT_APPEND=-Wl,-z,defs

# 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

# Fix gcc10 warnings as errors while upstream doesn't catch up
export DEB_CFLAGS_PREPEND=-Wno-error=format-overflow=
export DEB_CXXFLAGS_PREPEND=${DEB_CFLAGS_PREPEND}

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

override_dh_autoreconf:
	dh_autoreconf ./autogen.sh

# 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-cibsecrets \
		--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
	# The init scripts aren't installed since 2.1.2 (ac768052) when using systemd:
	install -d debian/tmp/etc/init.d
	install -t debian/tmp/etc/init.d etc/init.d/pacemaker daemons/execd/pacemaker_remote
	dh_install

override_dh_installdocs:
	dh_installdocs -A README.markdown

override_dh_installinit:
# Upstream provides 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
