#!/usr/bin/make -f
#
# debian/rules for kernel-image-*-hppa
#
# GNU copyright 1997 to 1999 by Joey Hess.
# Copyright (c) 1999-2001 Herbert Xu <herbert@debian.org>
# Copyright (c) 2001 Richard Hirst <rhirst@linuxcare.com>
#

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

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

SHELL := sh -e

configdir := linux/arch/parisc/debian-configs

export version := $(shell \
	head -1 debian/changelog | \
	sed 's/^kernel-image-\(.*\)-hppa.*$$/\1/' \
)
fullversion := $(shell \
	dpkg-parsechangelog | sed -n 's/^Version: //p; t e; b; :e; q' \
)
flavours := $(shell \
	if ( command -v hppa64-linux-gcc > /dev/null 2>&1 ); \
	then \
		find $(configdir) -maxdepth 1 \( -type f -o -type l \) -a -printf '%f\n'; \
	else \
		echo -e "\n\nWARNING: ============================================================" >&2; \
		echo "  Cannot build 64 bit kernel images as the 32 to 64 bit hppa cross-compiler" >&2; \
		echo "  is not installed.  If the official package is not yet available, an" >&2; \
		echo "  unofficial one may be found at" >&2; \
		echo "  <http://ftp.parisc-linux.org/unofficial-debs/>" >&2; \
		echo -e "WARNING: ================================================================\n\n" >&2; \
		find $(configdir) -maxdepth 1 \( -type f -o -type l \) -a ! -name '64*' -printf '%f\n'; \
	fi \
)

cvs-update:
	( cd linux; \
	rm -f Makefile ; \
	cvs -z3 -d :pserver:anonymous@cvs.parisc-linux.org:/var/cvs up -d . ; \
	grep ^EXTRAVERSION Makefile > ../linux-EXTRAVERSION; \
	mv -f Makefile Makefile.tmp; \
	sed 's/^EXTRAVERSION.*/EXTRAVERSION =/' < Makefile.tmp > Makefile; \
	rm -f Makefile.tmp; \
	)

unpack: stamp-unpack
stamp-unpack:
	# add Debian packaging goo
	mkdir linux/debian
	cp debian/changelog linux/debian
	cp debian/control linux/debian
	> linux/debian/official

	# copy the source tree for each image flavor, fold in config file
	for i in $(flavours); do \
		cp -al linux build-$$i; \
		cp $(configdir)/$$i build-$$i/.config; \
		cd build-$$i; \
		cd ..; \
	done

	touch stamp-unpack

build: stamp-build
stamp-build: stamp-unpack

	# little to do here... the real work is done in binary-arch target
	
	touch stamp-build

clean:
	rm -rf linux/debian build-* stamp-* *.deb
	( cd linux; make distclean )
	dh_clean

# Build architecture-independent files here.
binary-indep:
	
	# create kernel-headers and kernel-source packages

	cp $(configdir)/32 linux/.config
	cd linux; \
		make-kpkg --append-to-version=-hppa kernel-headers
	cd linux; \
		make-kpkg --append-to-version=-hppa kernel-source
	cat linux/debian/files >> debian/files

	mv *.deb ..


# Build architecture-dependent files here.
binary-arch: stamp-build

	# create kernel-image packages.

	for i in $(flavours); do \
		cd build-$$i; \
		make-kpkg --append-to-version=-$$i kernel_image; \
		cd ..; \
		cat build-$$i/debian/files >> debian/files; \
	done

	mv *.deb ..

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