#!/usr/bin/make -f
#export DH_VERBOSE=1

include /usr/share/dpkg/default.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DPKG_GENSYMBOLS_CHECK_LEVEL = 4

%:
	dh $@

ifeq ($(DEB_BUILD_ARCH),$(filter $(DEB_BUILD_ARCH),amd64 x32))
  CMAKE_EXTRA_FLAGS += -DOJPH_DISABLE_INTEL_SIMD:BOOL=OFF
else
  CMAKE_EXTRA_FLAGS += -DOJPH_DISABLE_INTEL_SIMD:BOOL=ON
endif

# upstream requires amd64 binaries from kakadu (non-free) to run non-regression
# testing. Make sure to set BUILD_TESTING to OFF for now:
ifeq (,$(filter check,$(OPENJPH_BUILD_TESTING)))
  BUILD_TESTING=OFF
else
  BUILD_TESTING=ON
endif

CMAKE_EXTRA_FLAGS += \
	-DBUILD_SHARED_LIBS:BOOL=ON \
	-DBUILD_TESTING:BOOL=$(BUILD_TESTING) \

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_EXTRA_FLAGS)

execute_after_dh_auto_build:
	cd docs && doxygen

override_dh_auto_test-arch:
ifeq (,$(filter check,$(OPENJPH_BUILD_TESTING)))
else
	dh_auto_test
endif

execute_before_dh_installman:
	help2man --version-string=$(DEB_VERSION_UPSTREAM) --help-option=" " --include=debian/ojph_compress.1.in --output=debian/ojph_compress.1  --no-info --no-discard-stderr ./debian/tmp/usr/bin/ojph_compress
	help2man --version-string=$(DEB_VERSION_UPSTREAM) --help-option=" " --include=debian/ojph_expand.1.in --output=debian/ojph_expand.1  --no-info --no-discard-stderr ./debian/tmp/usr/bin/ojph_expand
