#! /usr/bin/make -f

ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH)

tmp = $(CURDIR)/debian/base-installer

build: build-stamp debian/templates
build-stamp:
	dh_testdir
ifeq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	$(MAKE) small
else
	$(MAKE) DEBUG=1
endif
	touch $@

debian/templates: debian/templates-arch
	debian/templates-build.pl $(ARCH) < $< > $@
	# give the new templates file the same mtime as the input file, so
	# that po2debconf doesn't decide that it needs to run
	# debconf-updatepo
	touch -mr $< $@

clean:
	dh_testdir
	rm -f build-stamp
	$(MAKE) clean    
	dh_clean debian/templates

test:
	$(MAKE) -C kernel test

install: build test
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_install run-debootstrap usr/sbin
	if [ -e "kernel/$(ARCH).sh" ]; then \
		dh_installdirs usr/lib/base-installer; \
		install -m644 "kernel/$(ARCH).sh" \
		              $(tmp)/usr/lib/base-installer/kernel.sh; \
	fi
	dh_installdirs usr/lib/finish-install.d
	install -m755 finish-install $(tmp)/usr/lib/finish-install.d/90base-installer

binary-indep:

binary-arch: install
	dh_testdir
	dh_testroot
	dh_installdebconf -n
	(echo ; cat debian/templates) >> debian/base-installer/DEBIAN/templates
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: clean binary-indep binary-arch binary install
