#!/usr/bin/make -f
#
# debian/rules for kernel-image-*-alpha
#
# GNU copyright 1997 to 1999 by Joey Hess.
# Copyright (c) 2000 Ben Collins <bcollins@debian.org>
# Copyright (c) 1999-2001 Herbert Xu <herbert@debian.org>
#
# $Id: rules,v 1.4 2002/03/04 08:25:24 herbert Exp $

SHELL := sh -e

version := $(shell \
	head -1 debian/changelog | \
	sed 's/^kernel-image-\(.*\)-alpha.*$$/\1/' \
)
flavours := $(shell \
	find config -maxdepth 1 -type f ! -name default -printf '%f\n' \
)

unpack: unpack-stamp
unpack-stamp:
	tar jxf /usr/src/kernel-source-$(version).tar.bz2
	mkdir -p kernel-source-$(version)/debian
	cp debian/changelog kernel-source-$(version)/debian
	cp debian/control kernel-source-$(version)/debian
	> kernel-source-$(version)/debian/official
	install post-install kernel-source-$(version)/debian
	for i in $(flavours); do \
		cp -al kernel-source-$(version) build-$$i; \
		cp config/$$i build-$$i/.config; \
	done
	cp config/default kernel-source-$(version)/.config
	ln -s `command -v touch` bin/touch.orig

	touch unpack-stamp

build: build-stamp
build-stamp: unpack-stamp
	PATH=$$PWD/bin:$$PATH; \
	for i in $(flavours); do \
		cd build-$$i; \
		make-kpkg --append_to_version -$$i build; \
		cd ..; \
	done

	touch build-stamp

clean:
	rm -f unpack-stamp build-stamp install-stamp
	rm -rf kernel-source-$(version) build-* install-* bin/touch.orig
	dh_clean

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

	touch install-stamp

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

# Build architecture-dependent files here.
binary-arch: build
	cd kernel-source-$(version); \
		make-kpkg kernel-headers
	mv kernel-source-$(version)/debian/files debian
	for i in $(flavours); do \
		cp -al build-$$i install-$$i; \
		cd install-$$i; \
		make-kpkg --append_to_version -$$i \
			kernel-headers; \
		make-kpkg --append_to_version -$$i --initrd \
			kernel-image; \
		cd ..; \
		cat install-$$i/debian/files >> debian/files; \
		rm -rf install-$$i; \
	done
	mv *.deb ..

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