#!/usr/bin/make -f

DOCPATH=$(CURDIR)/debian/libsysactivity-doc/usr/share/doc/libsysactivity-doc/api

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ -Bbuild --parallel

override_dh_auto_configure-indep:
	# Do nothing for indep

override_dh_auto_configure-arch:
	dh_auto_configure -Bbuild -- -DCMAKE_C_FLAGS="$(CFLAGS) $(CPPFLAGS)" \
				-DCMAKE_SHARED_LINKER_FLAGS="$(LDFLAGS)" \
				-DCMAKE_EXE_LINKER_FLAGS="$(LDFLAGS)" \
				-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \
				-DCMAKE_SKIP_RPATH:BOOL=ON -DHAS_FLTO_FLAG:BOOL=OFF

# This override is not strictly required, but without it debhelper
# will call cmake for the indep build (which is a bit wasteful :P)
override_dh_auto_build-arch:
	dh_auto_build

override_dh_auto_build-indep:
	sh debian/build-doc.sh

override_dh_auto_test-indep:
	# Do nothing for indep

override_dh_auto_test:
	# Disabled

override_dh_auto_test-arch:
	$(MAKE) -C build -f test/Makefile all
	cd build && LD_LIBRARY_PATH="$(CURDIR)/build/src/$(ARCH)" ctest -V --force-new-ctest-process -E "$(DISABLED_TESTS)"

override_dh_strip-arch:
	dh_strip --dbg-package=libsysactivity1-dbg

override_dh_install-indep:
	dh_install
# Remove the embedded library. It will be changed to a symlink to the lib already in system.
	rm -rf $(DOCPATH)/jquery.js
# Using rdfind to transform duplicated files in hardlinks.
	rdfind -makehardlinks true -makeresultsfile false $(DOCPATH)

override_dh_auto_clean-indep:
	# Remove the doc-directories
	rm -fr doc/*/
	rm -f doc/doxygen_sqlite3.db
