#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export systemdsystemunitdir = $(shell pkg-config --variable=systemdsystemunitdir systemd | sed s,^/,,)

include /usr/share/dpkg/default.mk

%:
	dh ${@} --buildsystem=meson

override_dh_auto_configure:
	dh_auto_configure -- \
		-Dman=true \
		-Dapparmor=true \
		-Dselinux=true \
		-Dcapabilities=true \
		-Dexamples=true \
		-Dpam-cgroup=true \
		-Dtests=true \
		-Dinit-script=sysvinit,systemd

override_dh_clean:
	dh_clean

override_dh_auto_build:
	dh_auto_build
	# See https://github.com/lxc/lxc/issues/4156
	cd doc/api/ && doxygen

override_dh_auto_install:
	dh_auto_install

	# install pam config
	cp $(CURDIR)/debian/pam-cgfs.config \
		$(CURDIR)/debian/libpam-cgfs/usr/share/pam-configs/cgfs

	# cleanup .la files
	find debian/tmp/ -type f -name \*.la -delete

	# move the tests
	mkdir -p debian/lxc-tests/usr/bin
	mv debian/tmp/usr/bin/lxc-test-* debian/lxc-tests/usr/bin/

	# increase limit of inotify listeners
	mkdir -p debian/tmp/etc/sysctl.d
	cp debian/lxc.sysctl debian/tmp/etc/sysctl.d/30-lxc-inotify.conf

	# fix the sysvinit script name
	mv $(CURDIR)/debian/tmp/etc/init.d/lxc-containers \
		$(CURDIR)/debian/tmp/etc/init.d/lxc

	dh_apparmor -p liblxc-common --profile-name=usr.bin.lxc-copy
	dh_apparmor -p liblxc-common --profile-name=usr.bin.lxc-start

override_dh_compress:
	dh_compress -X.cfg

override_dh_fixperms:
	dh_fixperms -Xusr/libexec/lxc/lxc-user-nic

override_dh_installinit:
	dh_installinit -p lxc --onlyscripts --no-stop-on-upgrade --no-start --name lxc
	dh_installinit -p lxc --onlyscripts --no-stop-on-upgrade --no-start --name lxc-net

override_dh_installsystemd:
	dh_installsystemd --no-stop-on-upgrade

override_dh_missing:
	dh_missing --fail-missing