#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk

UPSTREAM_VERSION = $(DEB_VERSION_UPSTREAM)
MAKE_ARGS = PREFIX=/usr LIBDIR=/lib/$(DEB_HOST_MULTIARCH)

%:
	dh $@

# uPDFParser ships as the "updfparser" component tarball; upstream expects
# it in lib/updfparser (where scripts/setup.sh would git clone it). The obj
# directories are created here because the Makefiles create them in a rule
# the object files do not depend on, which races under make -j.
override_dh_auto_configure:
	mkdir -p lib obj updfparser/obj
	ln -sfn ../updfparser lib/updfparser

override_dh_auto_build:
	dh_auto_build --sourcedirectory=updfparser -- BUILD_STATIC=1 BUILD_SHARED=0
	dh_auto_build -- $(MAKE_ARGS)

override_dh_auto_install:
	dh_auto_install -- $(MAKE_ARGS) install_headers
	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig
	sed -e 's/@MULTIARCH@/$(DEB_HOST_MULTIARCH)/' \
	    -e 's/@VERSION@/$(UPSTREAM_VERSION)/' \
	    debian/libgourou.pc.in \
	    > debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/libgourou.pc

# Upstream has no test suite; see debian/tests for autopkgtest.
override_dh_auto_test:

override_dh_auto_clean:
	[ ! -f updfparser/Makefile ] || dh_auto_clean --sourcedirectory=updfparser
	dh_auto_clean
	rm -rf lib
	rm -f utils/*.o
