#!/usr/bin/make -f

# exiv2 uses std::auto_ptr<> a lot, so avoid the lots of deprecation warnings
export DEB_CXXFLAGS_MAINT_APPEND = -Wno-deprecated-declarations

CMAKE_COMMON_ARGS = \
	-DEXIV2_ENABLE_NLS=ON \
	-DEXIV2_ENABLE_VIDEO=ON \
	-DEXIV2_ENABLE_WEBREADY=ON \
	-DEXIV2_BUILD_SAMPLES=$(if $(filter nocheck,$(DEB_BUILD_OPTIONS)),OFF,ON) \
	-DEXIV2_BUILD_UNIT_TESTS=$(if $(filter nocheck,$(DEB_BUILD_OPTIONS)),OFF,ON)

%:
	dh $@ --with pkgkde_symbolshelper --buildsystem cmake --builddirectory=build

override_dh_auto_configure-indep:
	dh_auto_configure -- \
	    $(CMAKE_COMMON_ARGS) \
	    -DEXIV2_BUILD_DOC=ON \
	    -DCMAKE_INSTALL_DOCDIR=/usr/share/doc/exiv2/html

override_dh_auto_configure-arch:
	dh_auto_configure -a -- \
	    $(CMAKE_COMMON_ARGS)

override_dh_strip:
	dh_strip --dbgsym-migration='libexiv2-dbg (<= 0.25-4~~)'

override_dh_install:
	dh_install
	find $(CURDIR)/debian -type f -name exiv2 | xargs /usr/bin/chrpath -d

override_dh_auto_build-indep:
	dh_auto_build
	dh_auto_build -- doc

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	cp debian/test_data/* test/data/
	# Ignore errors, because they were never enabled in bullseye before
	# and we don't know whether they pass on all architectures.
	-./build/bin/unit_tests
	# Ignore errors, because
	# bugfixes.github.test_issue_ghsa_mvc4_g5pv_4qqq.JpegBasePrintStructureInfiniteLoop
	# produces a different error message than expected.
	-$(MAKE) -C test python_tests
endif

override_dh_installdocs:
	dh_installdocs -A -Xcmd.txt -XMakefile -Xtemplates -XChangeLog
	find $(CURDIR)/debian -name jquery.js -exec ln -sfv /usr/share/javascript/jquery/jquery.js {} \;
	find $(CURDIR)/debian \( -name '*.map' -o -name '*.md5' \) -delete

override_dh_installchangelogs:
	dh_installchangelogs -A doc/ChangeLog

override_dh_compress:
	dh_compress -X.xls -X.js -X.idx -X.xml -X.php -X.cpp

override_dh_fixperms-indep:
	dh_fixperms -i
	find $(CURDIR)/debian/libexiv2-doc -name '*.ini' -exec chmod -x {} \;

execute_after_dh_clean:
	for f in debian/test_data/*; do rm -f "test/$${f#debian/test_}"; done
