#!/usr/bin/make -f

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

# 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

# Set the results of dpkg-buildflags as make variables.  We don't use this
# to communicate to dh_auto_configure; it calls dpkg-buildflags itself.
# It's only used to strip those flags out of the pkgconfig file.  If we
# can't import this, we don't care.
-include /usr/share/dpkg/buildflags.mk

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 build flags out
# of the Cflags and Libs pkgconfig configuration.  LDFLAGS and CPPFLAGS are
# set by /usr/share/dpkg/buildflags.mk above.
override_dh_install:
	rm -r debian/tmp/usr/share/doc/opensaml*
	dh_install -a -i --fail-missing
	perl -i -pe 's/^(Libs: .*)\Q$(LDFLAGS)\E/$$1/' \
	    debian/*/usr/lib/*/pkgconfig/opensaml.pc
	perl -i -pe 's/^(Cflags: .*)\Q$(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

override_dh_autoreconf:
	dh_autoreconf --as-needed

%:
	dh $@ --with autoreconf

# Don't attempt to build the buildflags.mk file if it doesn't exist.
/usr/share/dpkg/buildflags.mk:
