#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ --buildsystem=cmake

# The archived templates are experimental and php-mustache does not use
# them. On armhf two serializations of the same template differ (the
# "cista_archive" test fails). Without them the bundled Cista and xxHash
# headers are not compiled either.
override_dh_auto_configure:
	dh_auto_configure -- \
		-DMUSTACHE_BUILD_CLI=OFF \
		-DMUSTACHE_ENABLE_ARCHIVED_TEMPLATES=OFF \
		-DMUSTACHE_ENABLE_JSON=ON \
		-DMUSTACHE_ENABLE_YAML=ON

override_dh_makeshlibs:
	dh_makeshlibs -V

override_dh_auto_test:
	# the "spec" test needs the mustache/spec submodule, which the release
	# archive does not include
	dh_auto_test -- ARGS+=-E ARGS+='^spec$$'

# Added by ubuntu-dbgsym-deb when this source package was made for an Ubuntu
# release; it is not in the packaging repository. Ubuntu's debhelper names
# debug packages NAME-dbgsym_VERSION_ARCH.ddeb, and the archive these builds
# are published from takes only .deb files. Rename them once they are built
# and correct debian/files, from which the .changes file is written.
.PHONY: execute_after_dh_builddeb-arch dbgsym-ddeb-to-deb
execute_after_dh_builddeb-arch: dbgsym-ddeb-to-deb
dbgsym-ddeb-to-deb:
	@for f in $$(sed -n 's/^\([^ ]*\)\.ddeb .*/\1/p' debian/files 2>/dev/null); do \
		if mv "../$$f.ddeb" "../$$f.deb"; then \
			sed -i "s/^$$f\.ddeb /$$f.deb /" debian/files; \
			echo "dbgsym-ddeb-to-deb: renamed $$f.ddeb to $$f.deb"; \
		fi; \
	done
