#!/usr/bin/make -f

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

# For stripping the flags back out of pkgconfig.
STRIP_CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
STRIP_LDFLAGS  := $(shell dpkg-buildflags --get LDFLAGS)

DOCS = debian/libsaml2-doc/usr/share/doc/libsaml2-doc

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

override_dh_auto_configure:
	dh_auto_configure -- --disable-dependency-tracking $(DEBUG)

# Remove the upstream-installed documentation, and strip the hardening flags
# out of the Cflags and Libs pkgconfig configuration.
override_dh_install:
	rm -r debian/tmp/usr/share/doc/opensaml*
	dh_install -a -i --fail-missing
	perl -i -pe 's/^(Libs: .*)\Q$(STRIP_LDFLAGS)\E/$$1/' \
	    debian/*/usr/lib/*/pkgconfig/opensaml.pc
	perl -i -pe 's/^(Cflags: .*)\Q$(STRIP_CPPFLAGS)\E/$$1/' \
	    debian/*/usr/lib/*/pkgconfig/opensaml.pc

override_dh_installdocs:
	dh_installdocs -A doc/NOTICE.txt
	set -e; if [ -d "$(DOCS)" ] ; then \
	    if [ -f "$(DOCS)/html/jquery.js" ] ; then \
		rm $(DOCS)/html/jquery.js ; \
		ln -s /usr/share/javascript/jquery/jquery.min.js \
		    $(DOCS)/html/jquery.js ; \
	    fi ; \
	fi

%:
	dh $@ --with autoreconf,pkgkde_symbolshelper
