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

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

version	= 2.4.18
patch	= benh,xfs
flavour	= powerpc-xfs

configure: configure-stamp
configure-stamp:
	dh_testdir

# unpack the kernel source
	tar jxf /usr/src/kernel-source-$(version).tar.bz2

# add a default configuration file
	cp -p config-default kernel-source-$(version)/.config

# tell make-kpkg that this is an official kernel
	mkdir kernel-source-$(version)/debian
	touch kernel-source-$(version)/debian/official

# patch the kernel source
	export PATCH_THE_KERNEL=YES; \
	cd kernel-source-$(version); \
	make-kpkg --added-patches $(patch) debian

# add a few of our files
	cp -p debian/{changelog,control,copyright,README.Debian} kernel-source-$(version)/debian
	cp -p debian/README.Debian.1st kernel-source-$(version)/README.Debian

# prepare a separate build tree for each flavour
	for i in $(flavour); do \
		if test $(words $(flavour)) -eq 1; \
		then ln -s kernel-source-$(version) tmp-$$i; \
		else cp -al kernel-source-$(version) tmp-$$i; \
		fi; \
		cp -p config-$$i tmp-$$i/.config; \
	done

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f install-stamp build-stamp configure-stamp

# remove the main source tree and all build directories
	rm -rf kernel-source-$(version) tmp-*

	dh_clean

install: install-stamp
install-stamp:	build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	touch install-stamp

# Build architecture-independent files here.
binary-indep: build install

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

# build a kernel image for each flavour and add it to the global files list
	touch debian/files
	for i in $(flavour); do \
		cd tmp-$$i; \
		cp -p ../debian/*.{postinst,prerm}.debhelper debian; \
		EXTRA_DOCS=debian/copyright make-kpkg --append-to-version -$$i kernel-image; \
		cat debian/files >> ../debian/files; \
		cd ..; \
	done
	mv *.deb ..

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