#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

# This has to be exported to make some magic below work.
#export DH_OPTIONS

%:
	dh $@ --with-systemd

#override_dh_shlibdeps:
#        dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info

override_dh_auto_configure:
	dh_auto_configure --sourcedir=$$(pwd) \
		--builddir=$$(pwd)/debian/build --  \
		--prefix=/usr \
		--libdir=/usr/lib/emulab \
		--libexecdir=/usr/libexec
	#autoreconf
	#mkdir -p $$(pwd)/debian/build
	#cd $$(pwd)/debian/build
	#../../configure --prefix=/usr --enable-shared

override_dh_auto_test:
	# skip executing tests

override_dh_auto_build:
	$(MAKE) -C $$(pwd)/debian/build

override_dh_missing:
	# Ignore uninstalled packages

override_dh_auto_install:
	$(MAKE) DESTDIR=$$(pwd)/debian/tmp -C $$(pwd)/debian/build \
		NETWORKTARGETS="'systemd-networkd NetworkManager'" \
		client-install
	mkdir -p $$(pwd)/debian/tmp/usr/share/emulab
	mkdir -p $$(pwd)/debian/tmp/etc/apt/apt.conf.d
	cp -p tmcc/linux/apt-conf-emulab $$(pwd)/debian/tmp/etc/apt/apt.conf.d/99emulab
	cp -p git-version $$(pwd)/debian/tmp/etc/emulab/version
	$(MAKE) DESTDIR=$$(pwd)/debian/tmp -C $$(pwd)/debian/build/tip \
		rack-control-install
	$(MAKE) DESTDIR=$$(pwd)/debian/tmp -C $$(pwd)/debian/build/tmcc/linux \
		NETWORKTARGETS="'systemd-networkd NetworkManager'" \
		xen-install
	cp $$(pwd)/debian/lilo.bootsector.dd $$(pwd)/debian/tmp/etc/emulab/lilo.bootsector.dd
	chmod 644 $$(pwd)/debian/tmp/etc/emulab/lilo.bootsector.dd
	mkdir -p $$(pwd)/debian/tmp/var/log/tiplogs
	mkdir -p $$(pwd)/debian/tmp/lib/systemd/system/
	cp $$(pwd)/debian/capture@.service $$(pwd)/debian/tmp/lib/systemd/system/capture@.service

override_dh_installinit:
	dh_installinit --no-start
	dh_systemd_enable testbed.service tbprepare.service \
		emulab-fstab-fixup.service
	if [ -e $$(pwd)/debian/tmp/lib/systemd/system/emulab-xenbridge-setup.service \
		-o -e $$(pwd)/debian/tmp/etc/systemd/system/emulab-xenbridge-setup.service ]; then \
		dh_systemd_enable emulab-xenbridge-setup.service ; \
	fi

override_dh_perl:
	dh_perl -Pdebian/tmp -p emulab-client \
		usr/libexec/emulab usr/libexec/emulab/rc
