#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/buildtools.mk
include /usr/share/dpkg/buildflags.mk

noatomicarch = $(shell dpkg-architecture -qDEB_HOST_ARCH | egrep -x "(armel|powerpc|powerpcspe|m68k|mips|mipsel|sh4|riscv64)")
# link with libatomic on architectures without built-in atomic
ifeq ($(if $(noatomicarch),atomic), atomic)
        LIBS += -latomic
endif

# Allow cross compiling
ifneq (${DEB_BUILD_ARCH},${DEB_HOST_ARCH})
	export CROSS_COMPILING = true
endif

export NOOPT = true
export VERBOSE = true

ifeq ($(DEB_HOST_ARCH),amd64)
	export BUILD_PROFILE=x86_64
endif
ifeq ($(DEB_HOST_ARCH),i386)
	export BUILD_PROFILE=i586
endif
ifeq ($(DEB_HOST_ARCH),arm64)
	export BUILD_PROFILE=aarch64
endif
# https://wiki.debian.org/ArchitectureSpecificsMemo#armel
ifeq ($(DEB_HOST_ARCH),armel)
	export BUILD_PROFILE=armv5te
endif
ifeq ($(DEB_HOST_ARCH),armhf)
	export BUILD_PROFILE=armv7a
endif

CFLAGS   += $(CPPFLAGS)
CXXFLAGS += $(CPPFLAGS)

%:
	dh $@

override_dh_auto_configure:
	$(MAKE) config FEATURES='jack ladspa lv2 vst2 xdg' PREFIX=/usr VERBOSE=1
	dh_auto_configure

override_dh_auto_test:
	# the test suite requires build options incompatible with what we
	# ship in the package, so disable until upstream resolves this
