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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_LDFLAGS_MAINT_APPEND = -fvisibility=hidden
export DEB_CPPFLAGS_MAINT_APPEND = -DH5Oget_info_by_name_vers=1 -DH5O_info_t_vers=1

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


# deduce documentation option (build-indep target)
ifeq "" "$(filter %-doc,$(shell dh_listpackages))"
  BUILDDOC = OFF
else
  BUILDDOC = ON
endif


.PHONY: override_dh_strip override_dh_shlibdeps

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
	-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
	-DALWAYS_CREATE_DOC=$(BUILDDOC)  \
	-DSTRICT_DEPENDECIES=ON \
	-DMIA_CREATE_MANPAGES=ON \
	-DMIA_CREATE_USERDOC=$(BUILDDOC) \
	-DMIA_CREATE_NIPYPE_INTERFACES=OFF \
	-DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=OFF

override_dh_auto_test-indep: ;

# Skip some failing tests; variable definitions should be kept in sync
# with those at debian/tests/testsuite.
SKIP := 2d-imageio|2dmyocardsegset-io-xml|3d-vectorfield|3d-rigidregister|cmdlineparseroutput|cmdxmlhelp|fastica-implementation-fastica
ifeq ($(DEB_HOST_ARCH_BITS),32)
SKIP_32 := |2dimage-cost-lsd
endif
override_dh_auto_test-arch:
	dh_auto_test -- ARGS\+="--exclude-regex \"$(SKIP)$(SKIP_32)\""

# dh_strip detects executable files, so make *.mia files executable then strip then
# remove the executable flag
override_dh_strip:
	`pwd`/debian/run_strip

override_dh_auto_build-indep:
	dh_auto_build -- doc

override_dh_auto_build-arch:
	dh_auto_build

override_dh_auto_install-indep:
	# Install process expects some files that are not built in arch all builds
	dh_auto_install -i || true
	find debian/*/usr/share/doc -name CMakeLists.txt -delete

override_dh_shlibdeps:
	dh_shlibdeps -- $(shell find  debian/libmia-2.4-4/ -name "*.mia")

override_dh_missing:
	find debian/tmp \( -name "*-doc.desktop" -o -name COPYING \) -delete
	dh_missing
