#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.

include /usr/share/dpkg/architecture.mk

#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

PARALLEL_OPTION = $(filter parallel=%,$(DEB_BUILD_OPTIONS))
ifneq (,$(PARALLEL_OPTION))
	NUMJOBS = $(patsubst parallel=%,%,$(PARALLEL_OPTION))
else
	NUMJOBS = 1
endif

ifeq (${DEB_HOST_ARCH_CPU},i386)
export DEB_CFLAGS_MAINT_APPEND=-fexcess-precision=fast -ffloat-store
export DEB_CXXFLAGS_MAINT_APPEND=-fexcess-precision=fast -ffloat-store
endif

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@ --buildsystem cmake+ninja


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

override_dh_auto_configure-arch:
	dh_auto_configure -- \
		-DCMAKE_BUILD_TYPE=Release \
		-DWITH_DBUS=ON \
		$(if $(embed_2geom),-D2GEOM_BUILD_SHARED=OFF)

#override_dh_auto_test-arch:
#	cd obj-$(DEB_HOST_GNU_TYPE) && LC_ALL=C.UTF-8 ninja -j$(NUMJOBS) -v tests
#	# some tests are not parallel-safe, since they try to look at the same file
#	dh_auto_test -a --no-parallel

override_dh_auto_test:
	@# this is not run in parallel just because I'm too lazy to parse DEB_BUILD_OPTIONS
	# $(MAKE) -C obj-$(DEB_HOST_GNU_TYPE) tests
	# some tests are not parallel-safe, since they try to look at the same file
	# dh_auto_test -a --no-parallel
	echo "skip tests because gtest is bad on bionic. Uncomment the above in 2028."

override_dh_auto_install-arch:
	# The tutorials are manually installed, the rest goes here
	dh_auto_install --destdir=debian/inkscape
	rm -rv debian/inkscape/usr/share/inkscape/tutorials

override_dh_auto_configure-indep: nothing
override_dh_auto_build-indep: nothing
override_dh_auto_install-indep: nothing
override_dh_auto_test-indep: nothing
.PHONY: nothing
nothing:
	: Do nothing for the -indep build