#!/usr/bin/make -f

VERSION := $(shell dpkg-parsechangelog | grep ^Version: | cut -d' ' -f2 \
		| cut -d- -f1)

# Enable compiler hardening flags.
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Force linking with -lpthread, working around a bug in libtool that drops
# the linkage because it uses -nostdlib.  See #468555.  Add --as-needed to
# drop a few unnecessary dependencies.
export DEB_LDFLAGS_MAINT_APPEND = -lpthread -Wl,--as-needed

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
    DEBUG = --enable-debug
else
    DEBUG =
endif

override_dh_auto_configure:
	dh_auto_configure -- --disable-static $(DEBUG) log4shib_cflags=' '
# avoid leaking build flags into the pkg-config file

override_dh_install-arch:
	pod2man --release=$(VERSION) --section=1 --center=log4shib \
	    debian/log4shib-config.pod debian/log4shib-config.1
	rm debian/tmp/usr/lib/x86_64-linux-gnu/liblog4shib.la
	dh_install -Xman3 --fail-missing

override_dh_install-indep:
	find debian/tmp/usr/share/doc/log4shib-*/api/html -name "*.md5" -delete
	dh_install -Xman3 --fail-missing

override_dh_autoreconf:
	dh_autoreconf --as-needed

%:
	dh $@ --with autoreconf
