#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

DEFAULTS = \
	common networked main-server workstation thin-client-server \
	standalone ltsp-chroot

INSTALL      = install -D -m0755
INSTALL_DATA = install -D -m0644

PACKAGES=$(shell dh_listpackages)

INSTALLUDEB=debian-edu-install-udeb
PROFILEUDEB=debian-edu-profile-udeb
VERSION=$(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
ARCH=all
INSTALLUDEBFILENAME=$(INSTALLUDEB)_$(VERSION)_$(ARCH).udeb
REPORTBUGUDEBFILENAME=$(REPORTBUGUDEB)_$(VERSION)_$(ARCH).udeb
PROFILEUDEBFILENAME=$(PROFILEUDEB)_$(VERSION)_$(ARCH).udeb

build:
	$(MAKE)

clean:
	debconf-updatepo
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	$(MAKE) clean
	dh_clean

install-common: build
	dh_prep
	dh_testdir
	dh_testroot
	dh_installdirs

install-debian-edu-install: install-common
	$(MAKE) install DESTDIR=$(CURDIR)/debian/debian-edu-install
	cp debian/debian-edu-install.lintian-override $(CURDIR)/debian/debian-edu-install/usr/share/lintian/overrides/debian-edu-install
	$(INSTALL) -d $(CURDIR)/debian/debian-edu-install/lib/debian-edu-install/

.PHONY: install-debian-edu-profile-udeb
install-debian-edu-profile-udeb: install-common
	$(INSTALL) base-installer $(CURDIR)/debian/debian-edu-profile-udeb/usr/lib/base-installer.d/10debian-edu-profile-udeb
	$(INSTALL) post-base-installer $(CURDIR)/debian/debian-edu-profile-udeb/usr/lib/post-base-installer.d/01debian-edu-profile-udeb
	$(INSTALL) pre-pkgsel $(CURDIR)/debian/debian-edu-profile-udeb/usr/lib/pre-pkgsel.d/10debian-edu-profile-udeb
	$(INSTALL) finish-install $(CURDIR)/debian/debian-edu-profile-udeb/usr/lib/finish-install.d/13debian-edu-profile-udeb
	$(INSTALL) apt-setup/generators/70debian-edu-install $(CURDIR)/debian/debian-edu-profile-udeb/usr/lib/apt-setup/generators/70debian-edu-install
	for profile in $(DEFAULTS) ; do \
	    $(INSTALL_DATA) preseed-values/defaults.$$profile $(CURDIR)/debian/debian-edu-profile-udeb/usr/lib/debian-edu-install ; \
	done
	$(MAKE) install-partman-recipes DESTDIR=$(CURDIR)/debian/debian-edu-profile-udeb
	$(INSTALL_DATA) lib/partman/commit.d/* $(CURDIR)/debian/debian-edu-profile-udeb/lib/partman/commit.d
	$(INSTALL) debian-edu-profile $(CURDIR)/debian/debian-edu-profile-udeb/usr/bin
	touch $(CURDIR)/debian/debian-edu-profile-udeb/etc/uselvm
	$(INSTALL_DATA) version $(CURDIR)/debian/debian-edu-profile-udeb/usr/lib/debian-edu-install/.

	for p in tools/edu-etcvcs tools/edu-is-testinstall tools/laptop-detect ; do \
	    $(INSTALL) $$p $(CURDIR)/debian/debian-edu-profile-udeb/usr/bin/. ; \
	done

# Build architecture-independent files here.
binary-indep: install debian-edu-install debian-edu-install-udeb debian-edu-profile-udeb

debian-edu-install-udeb: # install-debian-edu-install-udeb
	dh_testdir -p$@
	dh_testroot -p$@
	dh_installdebconf -p$@ -n
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	cp debian/debian-edu-install-udeb.isinstallable debian/debian-edu-install-udeb/DEBIAN/isinstallable
	chmod 755 debian/debian-edu-install-udeb/DEBIAN/isinstallable
	dh_installdeb -p$@
	dh_gencontrol -p$@ -- -n$(INSTALLUDEBFILENAME)
	dh_builddeb -p$@ --filename=$(INSTALLUDEBFILENAME)

.PHONY: debian-edu-profile-udeb
debian-edu-profile-udeb: install-debian-edu-profile-udeb
	dh_testdir -p$@
	dh_testroot -p$@
	dh_installdebconf -p$@ -n
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	dh_installdeb -p$@
	dh_gencontrol -p$@ -- -n$(PROFILEUDEBFILENAME)
	dh_builddeb -p$@ --filename=$(PROFILEUDEBFILENAME)

debian-edu-install: install-debian-edu-install
	dh_testdir -p$@
	dh_testroot -p$@
	dh_installdebconf -p$@
	dh_installdocs -p$@
	dh_installexamples -p$@
	dh_installmenu -p$@
	dh_installcron -p$@
	dh_installman -p$@
	dh_installinfo -p$@
	# Use prefix 99x* to make sure it is the very last script in the boot sequence.
	dh_installinit -pdebian-edu-install --name=xdebian-edu-firstboot --no-start -u"start 99 2 3 4 5 ."
	dh_installchangelogs -p$@
	dh_link -p$@
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	dh_installdeb -p$@
	dh_gencontrol -p$@
	dh_md5sums -p$@
	dh_builddeb -p$@

# Build architecture-dependent files here.
binary-arch: build install

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