#!/usr/bin/make -f

-include /usr/share/dpkg/vendor.mk

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh ${@} --parallel --with autoreconf,autotools_dev

override_dh_auto_configure:
	dh_auto_configure -- \
		--disable-rpath \
		--enable-doc \
		--enable-api-docs \
		--enable-apparmor \
		--enable-selinux \
		--disable-cgmanager \
		--enable-capabilities \
		--enable-examples \
		--enable-python \
		--disable-mutex-debugging \
		--enable-lua \
		--enable-bash \
		--enable-tests \
		--enable-configpath-log \
		--with-distro=debian \
		--with-init-script=sysvinit,systemd

override_dh_auto_install:
	dh_auto_install -- SYSTEMD_UNIT_DIR=/lib/systemd/system

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

	# fix systemd service
	sed -i	-e "s|/usr/libexec/lxc/lxc-devsetup|/usr/lib/$(DEB_HOST_MULTIARCH)/lxc|" \
		-e "s|/usr/libexec/lxc/lxc-startup start|/usr/bin/lxc-autostart|" \
		-e "s|/usr/libexec/lxc/lxc-startup stop|/usr/bin/lxc-autostart --shutdown|" \
	debian/tmp/lib/systemd/system/lxc.service

	# template
ifeq ($(DEB_VENDOR),Progress Linux)
	# rename lxc-debian to lxc-debian.upstream
	mv debian/tmp/usr/share/lxc/templates/lxc-debian debian/tmp/usr/share/lxc/templates/lxc-debian.upstream
endif

	# remove lxc-top until lua-alt-getopt is available
	rm -f debian/tmp/usr/bin/lxc-top
	rm -f debian/tmp/usr/share/man/*/lxc-top.*
	rm -f debian/tmp/usr/share/man/*/*/lxc-top.*

override_dh_builddeb:
	dh_builddeb -- -Zxz

override_dh_compress:
	dh_compress -X.cfg

override_dh_install:
	dh_install --fail-missing

override_dh_installinit:
	dh_installinit -p lxc --onlyscripts --no-restart-on-upgrade --no-start --name lxc
	dh_installinit -plxc-stuff --onlyscripts --no-restart-on-upgrade --no-start --name irkerhook-lxc

override_dh_link:
ifeq ($(DEB_VENDOR),Progress Linux)
	# install lxc-debconfig as lxc-debian
	dh_link -plxc-stuff /usr/share/lxc/templates/lxc-debconfig	/usr/share/lxc/templates/lxc-debian
	dh_link -plxc-stuff /usr/share/lxc/templates/lxc-debconfig.d	/usr/share/lxc/templates/lxc-debian.d
endif

override_dh_strip:
	dh_strip --dbg-package=lxc-dbg
