#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

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

patches:=$(wildcard uml-patch-*.bz2)
changelogs:=$(shell ls changelogs/*.html | sed -re 's/^.*-([0-9]*)\.([0-9]*)\.([0-9]*)-?([0-9]*)?.*$$/& \1 \2 \3 \4/' | sort -rnb -k 2,2 -k 3,3 -k 4,4 -k 5,5 | sed -e 's/ .*$$//')
tmp:=`pwd`/debian/kernel-patch-uml

configure: configure-stamp
configure-stamp:
	dh_testdir

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	for patch in $(patches); do \
		bunzip2 -k $$patch; \
		diff=`basename $$patch .bz2`.debdiff; \
		if test -f $$diff; then \
			patch `basename $$patch .bz2` < $$diff; \
		fi; \
	done

	for changelog in $(changelogs); do \
		echo "$$(basename $$changelog):"; \
		echo; \
		cat $$changelog | \
			sed -ne '/^<ul>$$/,/^<\/ul>$$/ p' | \
			egrep -v '^(<.*>)?$$' | \
			sed -e 's/^/  /'; \
		echo; \
	done | gzip -9 > changelog.gz

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f configure-stamp build-stamp

	for patch in uml-patch-*.bz2; do \
		rm -f `basename $$patch .bz2`; \
	done

	rm -f changelog.gz

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installkpatches
	dh_install changelog.gz usr/share/kernel-patch-uml
	dh_link usr/share/kernel-patch-uml/changelog.gz usr/share/doc/kernel-patch-uml/changelog.gz

binary-arch: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
#	dh_installexamples
#	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installman
#	dh_installinfo
#	dh_undocumented
	dh_installchangelogs
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
#	dh_perl
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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