#! /usr/bin/make -f

CODENAME ?= $(shell lsb_release -c -s)

export DEB_BUILD_MAINT_OPTIONS ?=hardening=-pie
ifneq (,$(filter $(CODENAME),jammy))
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
endif

export DEB_LDFLAGS_MAINT_APPEND ?=-Wl,--as-needed -Wl,-s
# LFS support
export DEB_CPPFLAGS_MAINT_APPEND=$(shell getconf LFS_CFLAGS)

include /usr/share/dpkg/architecture.mk

I=$(CURDIR)/debian/install

%:
	dh $@ --buildsystem=cmake

override_dh_auto_clean:
	dh_auto_clean
	rm -rf bin Build/linux/release debian/install

# -arch bits

override_dh_auto_configure-arch:

override_dh_auto_build-arch:
	# First make static
	cd $(CURDIR)/Build/linux && ./build.sh --prefix /usr --static release && cd Release && make install DESTDIR=$(I)
	# Second rewrite with dynamic
	cd $(CURDIR)/Build/linux && ./build.sh --prefix /usr release && cd Release && make install DESTDIR=$(I)

override_dh_auto_install-arch:

override_dh_install:
	dh_install --sourcedir=$(I) -a
	dh_install -i

# -indep bits

# no configure, test and install for indep
override_dh_auto_configure-indep override_dh_auto_test-indep override_dh_auto_install-indep:

override_dh_auto_build-indep:

override_dh_auto_test:
