#! /usr/bin/make -f

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

AUTOGEN_DEB_FILES := flash-kernel.templates flash-kernel-installer.postinst default/flash-kernel

ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
DEFAULT_CMDLINE := quiet splash
else
DEFAULT_CMDLINE := quiet
endif

override_dh_auto_install:
	for i in $(AUTOGEN_DEB_FILES); do \
		sed "s/@DEFAULT_CMDLINE@/$(DEFAULT_CMDLINE)/" \
			< debian/$$i.in > debian/$$i; \
	done

	install -m0755 -p -d debian/flash-kernel/etc/flash-kernel/bootscript
	set -ex ; for arch in all $(DEB_HOST_ARCH) ; do \
		[ -d bootscript/$${arch} ] || continue ; \
		install -m0644 bootscript/$${arch}/* \
			debian/flash-kernel/etc/flash-kernel/bootscript/ ; \
	done

	dh_auto_install

override_dh_auto_clean:
	for i in $(AUTOGEN_DEB_FILES); do \
		rm -f debian/$$i; \
	done
	dh_auto_clean

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	FK_CHECKOUT=. ./test_db
	FK_CHECKOUT=. ./test_flash-kernel
	FK_CHECKOUT=. ./test_functions
endif

%:
	dh $@
