#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

PACKAGES        = $(shell dh_listpackages -a)
UDEB_DIRS	= lib/debian-installer-startup.d \
		  usr/lib/base-installer.d \
		  usr/lib/finish-install.d

CONFIGS		= ts209.lua ts219.lua ts409.lua ts41x.lua

%:
	dh $@

override_dh_auto_install:
	dh_install
	dh_installudev --priority=60

	# Install the following "manually" as they need a rename
	@set -ex; $(foreach PACKAGE, $(PACKAGES), \
	    $(foreach CONFIG, $(CONFIGS), \
		install -m0644 examples/$(CONFIG) \
			debian/$(PACKAGE)/etc/qcontrol/; \
            ) \
        )
	install -m0755 qcontrol-static \
		debian/qcontrol-udeb/usr/sbin/qcontrol
	install -m0755 debian/initramfs/hook \
		debian/qcontrol/usr/share/initramfs-tools/hooks/qcontrol
	install -m0755 debian/initramfs/init-bottom \
		debian/qcontrol/usr/share/initramfs-tools/scripts/init-bottom/qcontrol
	# Install the following "manually" as they need permissions set
	install -m0755 debian/udeb/qcommand \
		debian/qcontrol-udeb/usr/sbin/
	@set -ex; $(foreach UDEB_DIR, $(UDEB_DIRS), \
		install -m0755 debian/udeb/$$(basename $(UDEB_DIR))/* \
			debian/qcontrol-udeb/$(UDEB_DIR); )

override_dh_installinit:
	dh_installinit --name=qcontrold
	# This initscript just changes the LEDs and sounds the buzzer. No need
	# to do this on install or upgrade.
	dh_installinit --no-start --no-stop-on-upgrade
