#!/usr/bin/make -f
#
# debian/rules for kernel-image-*-alpha
#
# GNU copyright 1997 to 1999 by Joey Hess.
# Copyright (c) 1999-2001 Herbert Xu <herbert@debian.org>
# Copyright (c) 2000 Ben Collins <bcollins@debian.org>
#

SHELL := sh -e

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

unpack: unpack-stamp
unpack-stamp:
	tar Ixf /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
	for i in $(Subarches); do \
		cp -al kernel-source-$(Version) build-$$i; \
		cp config/$$i build-$$i/.config; \
	done

	touch unpack-stamp

build: build-stamp
build-stamp: unpack-stamp
	for i in $(Subarches); do \
		cd build-$$i; \
		make-kpkg build --subarch $$i --arch_in_name build; \
		cd ..; \
	done
	touch build-stamp

clean:
	rm -f unpack-stamp build-stamp install-stamp
	rm -rf kernel-source-$(Version) build-*
	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 build-generic; \
		make-kpkg kernel-headers
	mv build-generic/debian/files debian
	for i in $(Subarches); do \
		cd build-$$i; \
		make-kpkg --subarch $$i kernel-image --arch_in_name; \
		cd ..; \
		cat build-$$i/debian/files >> debian/files; \
	done
	mv *.deb ..

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