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

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
export DEB_CPPFLAGS_MAINT_APPEND =
export DEB_LDFLAGS_MAINT_APPEND =

# iem-plugin-suite uses some c++11 features requiring atomic_store_8 and
# atomic_load_8, so we need to link with libatomic on
# armel, powerpc, powerpcspe, m68k, mips, mipsel, and sh4
# see also:
# - https://gcc.gnu.org/wiki/Atomic
# - https://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary
# - the 'clasp' packaging
noatomicarch = $(shell dpkg-architecture -qDEB_HOST_ARCH | egrep -x "(armel|powerpc|powerpcspe|m68k|mips|mipsel|sh4)")

# link with libatomic on architectures without built-in atomic
ifeq ($(if $(noatomicarch),atomic), atomic)
	DEB_LDFLAGS_MAINT_APPEND += -latomic
endif

JUCE_VERSION := $(shell dpkg-query --show --showformat='$${source:Version}' juce-modules-source)

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- \
		-DIEM_USE_SYSTEM_JUCE=ON \
		-DIEM_BUILD_STANDALONE=ON \
		-DIEM_BUILD_VST2=ON \
		-DIEM_BUILD_VST3=OFF \
		-DVST2SDKPATH=/usr/include \
		$(empty)

execute_before_dh_auto_build:
	@echo "blhc: ignore-line-regexp: ^\[[ 0-9]+%\] Building CXX object .*"

execute_before_dh_install:
	# install the VST plugins and the standalong applications
	find $(CURDIR) -type f -executable -path "*_artefacts/*" -path "*/Standalone/*" -exec ./debian/install.sh {} +

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog.md


override_dh_gencontrol:
	dh_gencontrol -- \
                -Vjuce:BuiltUsing="juce ( = $(JUCE_VERSION) )"

DEB_COPYRIGHT_CHECK_IGNORE_REGEX = \
        debian/.*|resources/lookAndFeel/.*\.ttf|resources/Standalone/.*\.png|BinauralDecoder/Source/.*\.wav
# 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
