#!/usr/bin/make -f
#
# debian/rules for kernel-image-*-i386.
#
# GNU copyright 1997 to 1999 by Joey Hess.
# Copyright (c) 1999 Herbert Xu <herbert@debian.org>
#
# $Id: rules,v 1.2 1999/11/20 01:28:51 herbert Exp $

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

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

Version:=$(shell head -1 debian/changelog | sed 's/^kernel-image-\(.*\)-i386.*$$/\1/')

unpack: unpack-stamp
unpack-stamp:
	tar Ixf /usr/src/kernel-source-$(Version).tar.bz2

	touch unpack-stamp

build: build-stamp
build-stamp: unpack-stamp
	mkdir -p kernel-source-$(Version)/debian
	cp debian/changelog kernel-source-$(Version)/debian
	touch kernel-source-$(Version)/debian/official
	cp debian/config kernel-source-$(Version)/.config
	cd kernel-source-$(Version); make-kpkg build
	csplit -s -k kernel-source-$(Version)/debian/control /Package:/ {3}
	(echo "Source: kernel-image-$(Version)-i386"; tail +2 xx00; \
	 sed 's/^\(Architecture:\) any/\1 i386/' xx01; cat xx03) \
		> debian/control
	cp debian/control kernel-source-$(Version)/debian

	touch build-stamp

clean:
	rm -f build-stamp install-stamp unpack-stamp

	-rm -rf kernel-source-$(Version)
	-rm -f xx*

	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 install
#	dh_testversion

# Build architecture-dependent files here.
binary-arch: build install
#	dh_testversion
	cd kernel-source-$(Version); \
		make-kpkg kernel-headers; \
		make-kpkg kernel-image
	mv *.deb ..
	cp kernel-source-$(Version)/debian/files debian

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