#! /usr/bin/make -f

PATCH=ia64

kver = 2.4.25
kdir = kernel-source-${kver}
PACKAGE=kernel-patch-${kver}-${PATCH}

####################

arch=$(shell dpkg --print-architecture)

topdir=$(shell pwd)
destdir=${topdir}/debian/tmp
docdir=${destdir}/usr/share/doc/${PACKAGE}
patches=linux-2.4.25-ia64-040218.diff 2.4-sigcontext-nat-fix.diff

build:	build-stamp

build-stamp:
	dh_testdir

	## Why not just cat the patches together?
	##
	## The script generated by dh_installkpatches attempts to do a 
	## patch --dry-run before actually applying.  patch doesn't keep
	## track of changes it may have made earlier to every file, so
	## patches that have dependencies on earlier patches will cause it
	## to fail.
	##
	## This also serves as a test case - making sure the patches apply
	## to the source tree.
	##
	## Oh yeah, and it makes for a smaller binary package.
	tar xjf /usr/src/${kdir}.tar.bz2
	cp -a ${kdir} ${kdir}.orig
	cd ${kdir} && for p in $(patches); do                          \
	  patch -p1 < ../$${p} || exit 1;                              \
	done

	find ${kdir} -name "*.orig" -exec rm {} \;

	## Though i couldn't find it documented (#228441)
	## I'm guessing diff returns 1 when there's a difference to report
	diff -urN ${kdir}.orig ${kdir} > ia64-${kver}.patch || [ $$? -eq 1 ]
	mkdir $(destdir)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot

	rm -f ia64-${kver}.patch
	rm -rf ${kdir} ${kdir}.orig
	rm -f build-stamp
	## editor backup files
	find . -name "*~" -exec rm {} \;

	dh_clean

binary-arch:	build

binary-indep:	build
	dh_testdir
	dh_testroot
	dh_clean -k

	dh_installkpatches
	dh_installchangelogs
	dh_installdocs

	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-arch binary-indep

.PHONY: binary binary-arch binary-indep clean checkroot
