#!/usr/bin/make -f
# -*- makefile -*-

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

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

# CMake options common to -arch and -indep builds.
CMAKE_BUILD_OPTIONS = \
	-DCMAKE_BUILD_TYPE=RelWithDebInfo \
	-DAF_INSTALL_CMAKE_DIR=/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/ArrayFire \
	-DAF_INSTALL_LIB_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) \
	-DAF_INSTALL_INCLUDE_DIR=/usr/include \
	-DBUILD_CUDA=OFF \
	-DBUILD_EXAMPLES=OFF \
	-DBUILD_GRAPHICS=OFF \
	-DBUILD_NONFREE=OFF \
	-DBUILD_OPENCL=OFF \
	-DBUILD_UNIFIED=OFF \
	-DWITH_COVERAGE=OFF

# Prevent execution of slow tests.
CTEST_EXCLUDE_REGEX = large|dense

%:
	dh $@ --parallel

override_dh_auto_clean-arch:
	dh_auto_clean --arch --builddirectory=build-arch
	# Remove auto-generated files.
	find $(CURDIR) -name "version.h" -delete

override_dh_auto_clean-indep:
	dh_auto_clean --indep --builddirectory=build-indep
	# Remove auto-generated files.
	find $(CURDIR) -name "version.h" -delete

override_dh_auto_configure-arch:
	dh_auto_configure --builddirectory=build-arch -- \
		$(CMAKE_BUILD_OPTIONS) \
		-DBUILD_CPU=ON \
		-DBUILD_DOCS=OFF \
		-DBUILD_GTEST=ON \
		-DBUILD_TEST=ON

override_dh_auto_configure-indep:
	dh_auto_configure --builddirectory=build-indep -- \
		$(CMAKE_BUILD_OPTIONS) \
		-DBUILD_CPU=OFF \
		-DBUILD_DOCS=ON \
		-DBUILD_GTEST=OFF \
		-DBUILD_TEST=OFF

override_dh_auto_build-arch:
	dh_auto_build --arch --builddirectory=build-arch

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

override_dh_auto_install-arch:
	dh_auto_install --arch --builddirectory=build-arch

override_dh_auto_install-indep:
	dh_auto_install --indep --builddirectory=build-indep 

override_dh_auto_test-arch:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	cd build-arch && \
	CTEST_OUTPUT_ON_FAILURE=1 ctest --force-new-ctest-process -R "cpu" \
		-E "$(CTEST_EXCLUDE_REGEX)"
endif

override_dh_install-indep:
	dh_install --indep -X LICENSE

override_dh_installchangelogs:
	dh_installchangelogs docs/pages/release_notes.md

override_dh_strip-arch:
	dh_strip --package=libarrayfire-cpu3 \
		--dbg-package=libarrayfire-cpu3-dbg
