#!/usr/bin/make -f
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

#enable hardening
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

-include /usr/share/dpkg/buildtools.mk

PKG_CONFIG?=pkg-config
CFLAGS+=$(shell $(PKG_CONFIG) --cflags pd-flext)
LDFLAGS+=$(shell $(PKG_CONFIG) --libs pd-flext)

pkglibdir = /usr/lib/pd/extra

DEB_COPYRIGHT_CHECK_IGNORE_REGEX = \
	^\./\.git/.*|\./debian/|\./pool\.mcp|\./pool\.help$

%:
	dh $@

override_dh_install:
	dh_install
# fix permissions
	find $(CURDIR)/debian/*/$(pkglibdir) -name "*.pd_linux" -exec \
		chmod 0664 {} +
# remove license file so we can replace it with link to the Debian license file
	rm -f -- $(CURDIR)/debian/*/$(pkglibdir)/*/LICENSE.txt

override_dh_auto_clean \
override_dh_auto_build \
override_dh_auto_test \
override_dh_auto_install:
	$(patsubst override_%,%,$@) -- \
		PDLIBBUILDER_DIR=/usr/share/pd-lib-builder/ \
		prefix=/usr pkglibdir=$(pkglibdir) \
		arch.flags="" \
		cflags="-DFLEXT_ATTRIBUTES=1" \
		CPPFLAGS="$(CPPFLAGS)" \
		CFLAGS="$(CPPFLAGS) $(CFLAGS) $(CXXFLAGS)" \
		LDFLAGS="$(LDFLAGS)" \
		$(empty)

licensecheck:
	licensecheck -i "$(DEB_COPYRIGHT_CHECK_IGNORE_REGEX)" --deb-machine -r . \
		> debian/copyright_newhints
	cmp debian/copyright_hints debian/copyright_newhints \
		&& rm debian/copyright_newhints
