#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# This needs to be changed whenever a new upstream version is imported,
# unless we are sure that the ABI hasn't changed
debian_abi = 0


enable_testing = OFF

ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
enable_testing = ON
endif

%:
	dh $@

# The ada tarball ships a pre-generated amalgamation of the idna component
# (src/ada_idna.cpp and include/ada/ada_idna.h). Regenerate both from the idna
# component shipped in idna/, so that is the source the build uses. dh_clean
# restores the two overwritten files, keeping 'clean' compliant with 4.9.
execute_before_dh_auto_configure:
	dh_assistant restore-file-on-clean src/ada_idna.cpp include/ada/ada_idna.h
	python3 idna/singleheader/amalgamate.py
	# The amalgamation embeds a generation date; keep the build reproducible.
	sed -i '1s|.*|/* auto-generated from the idna component. Do not edit! */|' \
	  idna/singleheader/ada_idna.h idna/singleheader/ada_idna.cpp
	cp idna/singleheader/ada_idna.h include/ada/ada_idna.h
	cp idna/singleheader/ada_idna.cpp src/ada_idna.cpp

override_dh_auto_configure-arch:
	dh_auto_configure -- -DCPM_USE_LOCAL_PACKAGES=ON -DADA_TESTING=$(enable_testing) -DADA_TOOLS=False -DBUILD_SHARED_LIBS=True -DCMAKE_DISABLE_FIND_PACKAGE_Python3=True -DADA_USE_SIMDUTF=ON -DADA_LIB_ABI=$(debian_abi)

# Skip compilation for 'all' architecture.
override_dh_auto_configure-indep:

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
execute_after_dh_auto_build-indep:
	doxygen doxygen
endif

execute_after_dh_auto_clean:
	$(RM) -r docs/html
