#!/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

VER  := $(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
ARCH := $(shell dpkg --print-architecture)
FILENAME := debootstrap-udeb_$(VER)_$(ARCH).udeb

# This is the debhelper compatability version to use.
export DH_COMPAT=2

configure:
	dh_testdir

clean:
	dh_testdir

	-$(MAKE) clean

	dh_clean

build: configure
#	 need to be root to make devices, so build is done in install target

real-build: build
	dh_testdir
	dh_testroot

	$(MAKE) all

install: real-build
	dh_testdir
	dh_testroot

	dh_clean -k
	dh_installdirs

#	 install the package into debian/debootstrap
	$(MAKE) install DESTDIR=$(CURDIR)/debian/debootstrap
	$(MAKE) install DESTDIR=$(CURDIR)/debian/debootstrap-udeb

binary-indep: install
# We have nothing to do by default.

ARCHES="i386"
SUITE="testing"
VERSION=$(SUITE)
MIRROR="http://ftp.debian.org/debian"

binary-basedebs:
	dh_testdir
	dh_testroot

	$(MAKE) pkgdetails

	ln -s . scripts
	for a in $(ARCHES); do \
	    rm -rf chroot-dir; \
	    mkdir -p chroot-dir; \
	    DEBOOTSTRAP_DIR=. ./debootstrap --arch $$a --download-only $(SUITE) chroot-dir $(MIRROR); \
	    (cd chroot-dir && tar cf ../../basedebs_$(VERSION)_$$a.tar *); \
	    rm -rf chroot-dir; \
	done
	rm -f scripts

binary-arch: install debootstrap-udeb
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installemacsen
#	dh_installpam
#	dh_installinit
	dh_installcron
	dh_installmanpages
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs 
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb -pdebootstrap
#	dh_perl
	dh_shlibdeps -pdebootstrap
	dh_gencontrol -pdebootstrap
	dh_md5sums -pdebootstrap
	dh_builddeb -pdebootstrap

debootstrap-udeb: install
	dh_testdir
	dh_testroot
	-rm -rf debian/debootstrap-udeb/usr/share \
		debian/debootstrap-udeb/scripts/slink \
		debian/debootstrap-udeb/scripts/potato
	dh_strip -pdebootstrap-udeb
	dh_compress -pdebootstrap-udeb
	dh_fixperms -pdebootstrap-udeb
	dh_installdeb -pdebootstrap-udeb
	dh_shlibdeps -pdebootstrap-udeb
	dh_gencontrol -- -fdebian/debootstrap-udeb.files~
	dpkg-distaddfile $(FILENAME) debian-installer extra
	dh_md5sums -pdebootstrap-udeb
	dh_builddeb -pdebootstrap-udeb --filename=$(FILENAME) 

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