#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/dpkg/architecture.mk

# Hardening flags.
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export DEB_CFLAGS_MAINT_APPEND=-Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed

# Available precisions.
PRECISIONS = single double
ifneq (,$(filter libnfft3-long2,$(shell dh_listpackages)))
	PRECISIONS+=long
endif

# Tested precisions.
# NOTE: Testing is temporarily restricted to single- and double-precision
# builds on powerpc architectures. See Bug-Debian #844403.
ifneq (,$(filter $(DEB_HOST_ARCH_CPU),powerpc ppc64el))
	TESTED_PRECISIONS=single double
else
	TESTED_PRECISIONS=$(PRECISIONS)
endif

# Build options common to arch and indep targets.
BUILD_OPTIONS=--disable-applications \
	--disable-doxygen-doc \
	--disable-examples \
	--disable-static \
	--enable-all \
	--enable-openmp

%:
	dh $@

override_dh_auto_clean:
	for p in $(PRECISIONS) ; do \
		dh_auto_clean --builddirectory=build-$$p ; \
	done

override_dh_auto_configure-arch:
	dh_auto_configure --builddirectory=build-single -- \
		$(BUILD_OPTIONS) \
		--enable-single
	dh_auto_configure --builddirectory=build-double -- \
		$(BUILD_OPTIONS)
ifneq (,$(filter long,$(PRECISIONS)))
	dh_auto_configure --builddirectory=build-long -- \
		$(BUILD_OPTIONS) \
		--enable-long-double
endif

override_dh_auto_configure-indep:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	dh_auto_configure --builddirectory=build-double -- \
		$(BUILD_OPTIONS) \
		--enable-doxygen-doc
endif

override_dh_auto_build-arch:
	for p in $(PRECISIONS) ; do \
		dh_auto_build --builddirectory=build-$$p ; \
	done

override_dh_auto_build-indep:
	dh_auto_build --builddirectory=build-double -- doc

override_dh_auto_test-arch:
	for p in $(TESTED_PRECISIONS) ; do \
		dh_auto_test --builddirectory=build-$$p ; \
	done

override_dh_auto_test-indep:
	# No-op.

override_dh_auto_install-arch:
	for p in $(PRECISIONS) ; do \
		dh_auto_install --builddirectory=build-$$p ; \
	done

override_dh_installdocs-indep:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	dh_installdocs --indep
	dh_doxygen --indep
endif

get-orig-source:
	uscan --download-current-version --force-download --no-symlink
