#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/pkg-info.mk

JAVA_HOME=/usr/lib/jvm/default-java

CMAKE_FLAGS = -DJAVA_HOME=$(JAVA_HOME) \
              -DCMAKE_BUILD_TYPE=RelWithDebInfo \

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure-arch:
	dh_auto_configure -- $(CMAKE_FLAGS) -DA2_BUILD_ARCH_ONLY=ON

override_dh_auto_configure-indep:
	# Use a different build directory in order not to interfere with arch build
	cmake -B build-indep -DCMAKE_INSTALL_PREFIX=/usr $(CMAKE_FLAGS) -DA2_BUILD_INDEP_ONLY=ON

override_dh_auto_build-indep:
	cmake --build build-indep

override_dh_auto_test:
	# We don't run test for the time being
	# and default fails when building only indep
	# for lack of the CMake build directory expected

override_dh_auto_install-indep:
	cd build-indep && make DESTDIR=$(shell pwd)/debian/tmp install

execute_after_dh_auto_install-indep:
	ln -sr debian/tmp/usr/share/java/org.argeo.jjml-$(DEB_VERSION_UPSTREAM).jar \
	 debian/tmp/usr/share/java/org.argeo.jjml.jar
	ln -sr debian/tmp/usr/share/java/org.argeo.jjml.multimedia-$(DEB_VERSION_UPSTREAM).jar \
	 debian/tmp/usr/share/java/org.argeo.jjml.multimedia.jar
