#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

ifneq (,$(findstring $(DEB_HOST_ARCH),amd64 arm64))
  ENABLE_WASMEDGE := 1
endif

ifeq ($(ENABLE_WASMEDGE),1)
  DEB_CONFIGOPTS += --with-wasmedge
endif

%:
	dh $@

override_dh_auto_clean:
	-dh_auto_clean

# The test suite tries to perform all kinds of privileged operations, like
# spawn containers, that are not necessarily allowed in the build environment,
# as is the case in the Debian buildd network.
#
# Thus run the suite, but ignore all errors; proper testing can happen in the
# autopkgtest testing environment
override_dh_auto_test:
	-dh_auto_test

execute_before_dh_auto_build:
	# These are generated with gperf, but regenerated for DFSG reasons here
	make generate-signals.c
	make generate-mount_flags.c
	# upstream ships prebuilt manpages, regenerate them
	rm -f *.1
	make generate-man
	# we don't ship this, but autopkgtest needs it through build-needed
	make tests/init

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp
ifeq ($(ENABLE_WASMEDGE),1)
	dh_link usr/bin/crun usr/bin/crun-wasm
	dh_link usr/share/man/man1/crun.1 usr/share/man/man1/crun-wasm.1
endif
	-$(RM) debian/tmp/usr/lib/*/*.la

execute_after_dh_gencontrol:
	# ensure we are linking against libyajl, and not building the embedded copy
	grep -q yajl debian/crun.substvars
