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

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

UDEB_DIRS	= lib/debian-installer-startup.d \
		  usr/lib/base-installer.d \
		  usr/lib/finish-install.d

DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)

ifeq ($(DEB_HOST_ARCH),armel)
WANT_UDEB           := yes
WANT_INITRAMFS_HOOK := yes
endif
ifeq ($(DEB_HOST_ARCH),armhf)
WANT_UDEB           := no
WANT_INITRAMFS_HOOK := no
endif
ifeq ($(DEB_HOST_ARCH),amd64)
WANT_UDEB           := no
WANT_INITRAMFS_HOOK := no
endif

%:
	dh $@

override_dh_installdirs:
ifeq ($(WANT_INITRAMFS_HOOK),yes)
	dh_installdirs usr/share/initramfs-tools/hooks \
	               usr/share/initramfs-tools/scripts/init-bottom
else
	dh_installdirs
endif

override_dh_auto_install:
	dh_install

ifeq ($(WANT_INITRAMFS_HOOK),yes)
	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
endif
ifeq ($(WANT_UDEB),yes)
	install -m0755 qcontrol-static \
		debian/qcontrol-udeb/usr/sbin/qcontrol
	# Install the following "manually" as they need permissions set
	install -m0755 debian/udeb/qcommand \
		debian/qcontrol-udeb/usr/sbin/
	$(foreach UDEB_DIR, $(UDEB_DIRS), \
		install -m0755 debian/udeb/$$(basename $(UDEB_DIR))/* \
			debian/qcontrol-udeb/$(UDEB_DIR); )
endif

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-restart-on-upgrade
