#!/usr/bin/make -f
# Copyright © 2010 Hans-Christoph Steiner <hans@eds.org>
# Copyright © 2018-2023 IOhannes m zmölnig <umlaeute@debian.org>

#enable hardening
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

FLAVORS = pd32
builddir=debian/build/flavor-

pd64ext=$(shell /usr/share/puredata/debian/dekencpu $(DEB_HOST_ARCH))

ifneq ($(pd64ext), )
	FLAVORS += pd64
endif

CONFIG= \
	--libdir=/usr/lib/pd/extra \
	$(empty)
CONFIG_pd32 = \
	$(empty)
CONFIG_pd64 = \
	--with-floatsize=64 \
	--with-extension=linux-$(pd64ext)-64.so \
	$(empty)

%:
	dh $@

# Add configuration options:
override_dh_auto_configure: $(patsubst %,configure_%,$(FLAVORS))
configure_%:
	$(info $()   debian/rules $@)
	dh_auto_configure --builddir $(builddir)$* -- $(strip $(CONFIG) $(CONFIG_$*))

# Remove the subdirectories generated for the flavors.
override_dh_auto_clean:
	rm -rf $(dir $(builddir))

override_dh_auto_build-arch: $(patsubst %,build_%,$(FLAVORS))
build_%:
	$(info $()  debian/rules $@)
	dh_auto_build -a --builddir=$(builddir)$* || (cat $(builddir)$*/config.log && exit 1)

override_dh_auto_install:  $(patsubst %,install_%,$(FLAVORS))
install_%:
	$(info $()  debian/rules $@)
	dh_auto_install -B $(builddir)$*
execute_after_dh_auto_install:
	# don't want libtools artifacts
	find $(CURDIR)/debian/*/$(pkglibdir) -name "*.la" -delete
# fix permissions
	find $(CURDIR)/debian/*/$(pkglibdir) -name "*.pd_linux" -exec \
		chmod 0664 {} +

DEB_COPYRIGHT_CHECK_IGNORE_REGEX = \
	debian/.*
# licensecheck v1
.PHONY: licensecheck
licensecheck:
	LANG=C.UTF-8 licensecheck \
		-i "^($(DEB_COPYRIGHT_CHECK_IGNORE_REGEX))$$" \
		--check '.*' --recursive --deb-machine --lines 0 * \
		> debian/copyright_newhints
	cmp debian/copyright_hints debian/copyright_newhints \
		&& rm debian/copyright_newhints
