#!/usr/bin/make -f

LIBRARY_NAME = libdir
PACKAGE = pd-$(LIBRARY_NAME)
pkglibdir = /usr/lib/pd/extra

%:
	dh $@ --buildsystem=makefile

override_dh_auto_build:
	dh_auto_build -- \
		arch.flags="" \
		CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" \
		LDFLAGS="$(LDFLAGS) -Wl,-as-needed" \
		$(empty)

override_dh_auto_install:
	dh_auto_install -- prefix=/usr pkglibdir=$(pkglibdir)
# fix permissions
	find $(CURDIR)/debian/$(PACKAGE) -name "*.pd_linux" -exec \
		chmod 0664 {} +
# replace license file with link to the Debian license file
	rm -f -- $(CURDIR)/debian/$(PACKAGE)/$(pkglibdir)/$(LIBRARY_NAME)/LICENSE.txt

override_dh_shlibdeps:
	find $(CURDIR)/debian/$(PACKAGE) -name "*.pd_linux" -exec \
		dpkg-shlibdeps \
			-T$(CURDIR)/debian/$(PACKAGE).substvars \
			{} +
override_dh_strip:
	dh_strip
	find $(CURDIR)/debian/$(PACKAGE) -name "*.pd_linux" -exec \
		strip \
			--remove-section=.comment \
			--remove-section=.note \
			--strip-unneeded \
			{} +
