#!/usr/bin/make -f
#
# debian/rules for kernel-source.
#
# GNU copyright 1997 to 1999 by Joey Hess.
# Copyright (c) 1999-2002 Herbert Xu <herbert@debian.org>
# Copyright (c) 2004 Jens Schmalzing <jensen@debian.org>
#

# This is the debhelper compatability version to use.
export DH_COMPAT=4
export LC_ALL=C
export SHELL=/bin/bash -e

stem := linux

# extract the upstream release and the full package version from the changelog
release	:= $(shell sed -n '1s/^.*(\(.*\)-.*).*$$/\1/p' debian/changelog)

# extract the version from the package name that can be different from release
pkgversion := $(shell sed -n '1s/^$(stem)-source-\([^ ]*\) .*/\1/p' debian/changelog)

# extract all the Debian revisions for this release from the changelog
revisions := $(shell sed -n 's/^$(stem)-source-$(pkgversion)\ .*($(release)-\(.*\)).*$$/\1/p' debian/changelog | tac)

# set the current Debian revision to the latest by default;
# note that for some targets, the two may actually be different.
revision ?= $(word $(words $(revisions)),$(revisions))

# Get the previously built revision; we compare ABIs with that.  If no 
# previous revision, default to 0.
prev_revisions := $(filter-out $(revision),0.0 $(revisions))
prev_revision := $(word $(words $(prev_revisions)),$(prev_revisions))

abidir := $(CURDIR)/debian/abi

version.Debian: 
	echo $(pkgversion) > $@

release.Debian:
	echo $(release)-$(revision) > $@


# This is an internally used mechanism for the daily kernel builds. It
# creates packages who's ABI is suffixed with a minimal representation of
# the current git HEAD sha. If .git/HEAD is not present, then it uses the
# uuidgen program,
#
# AUTOBUILD can also be used by anyone wanting to build a custom kernel
# image, or rebuild the entire set of Ubuntu packages using custom patches
# or configs.
export AUTOBUILD
ifeq ($(AUTOBUILD),)

autobuild	= n
skipabi		= false

else

autobuild	= y
skipabi		= true

gitver=$(shell if test -f .git/HEAD; then cat .git/HEAD; else uuidgen; fi)
gitverpre=$(shell echo $(gitver) | cut -b -3)
gitverpost=$(shell echo $(gitver) | cut -b 38-40)

endif

ifneq ($(NOKERNLOG),)
ubuntu_log_opts = --no-kern-log
endif

ifeq ($(autobuild),y)
abinum		:= $(shell echo $(revision) | sed -e 's/\..*//')-$(gitverpre)$(gitverpost)
else
abinum		:= $(shell echo $(revision) | sed -e 's/\..*//')
endif

version		:= $(release)
debnum		:= -$(abinum)

export abinum debnum version

appvan := --append_to_version $(debnum)

arch := $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)

basedir := debian/config/$(arch)

configs := $(notdir $(wildcard $(basedir)/config.*))
config_common = debian/config/config $(basedir)/config
flavours := $(filter-out %.disabled,$(patsubst config.%,%,$(configs)))
ifeq ($(NOEXTRAS),)
crashdump := $(shell if [ -f $(basedir)/crashdump ]; then cat $(basedir)/crashdump; else echo -n; fi)
lowlatency := $(shell if [ -f $(basedir)/lowlatency ]; then cat $(basedir)/lowlatency; else echo -n; fi)
endif

builddir := $(CURDIR)/debian/build
srcdir := $(builddir)/$(stem)-source-$(version)

export DEBIAN_SRCTOP := $(srcdir)
export DEBIAN_UPSTREAM_VERSION := $(version)
export DEBIAN_STEM := $(stem)

export UBUNTUBUILD=1

# Parse archmap
export KPKG_SUBARCH := $(shell \
	grep "^headers-$(arch)[[:space:]]" debian/config/archmap | \
	grep -v ^\# | awk '{print $$2}')

export KPKG_ARCH := $(arch)

headers_arch := $(shell \
	grep "^headers-$(arch)[[:space:]]" debian/config/archmap | \
	grep -v ^\# | awk '{print $$3}')

defconfig := $(shell \
	grep "^headers-$(arch)[[:space:]]" debian/config/archmap | \
	grep -v ^\# | awk '{print $$4}')

ifeq ($(arch),sparc)
PRE_CMD := sparc64
endif
MAKE_KPKG := $(PRE_CMD) make-kpkg --stem $(stem)

unpack: stamp-unpack
stamp-unpack:
	dh_testdir
	find . \( -path ./debian -o -path ./.git -o -name .gitignore \) -prune -o -print | \
		cpio -dumpl $(srcdir)
	cd $(srcdir); rm -f stamp-* version.Debian release.Debian
	mkdir -p $(srcdir)/debian
	cp debian/changelog $(srcdir)/debian
	cp debian/control $(srcdir)/debian
	cp debian/copyright $(srcdir)/debian
	> $(srcdir)/debian/official
	install -D -m755 debian/abi-install $(srcdir)/debian/image.d/abi-install
	install -D -m755 debian/ubuntu-fixups $(srcdir)/debian/image.d/ubuntu-fixups
	install -D -m755 debian/post-install $(srcdir)/debian/post-install
	chmod u+x debian/header-install
	@for i in $(flavours); do \
		echo "Setting up $$i..."; \
		cp -al $(srcdir) $(builddir)/build-$$i; \
		if [ "$$i" = "$(crashdump)" ]; then \
			echo "Setting up kdump based on $$i..."; \
			cp -al $(srcdir) $(builddir)/build-kdump; \
			rm -f $(builddir)/build-kdump/.config \
				$(builddir)/build-kdump/debian/image.d/abi-install \
				$(builddir)/build-kdump/debian/post-install; \
		fi; \
                if [ "$$i" = "$(lowlatency)" ]; then \
			echo "Setting up lowlatency based on $$i..."; \
                        cp -al $(srcdir) $(builddir)/build-lowlatency; \
                        rm -f $(builddir)/build-lowlatency/.config \
				$(builddir)/build-lowlatency/debian/image.d/abi-install; \
                fi; \
		rm -f $(builddir)/build-$$i/.config.old; \
		for t in $(config_common); do \
			if [ -f $${t} ]; then \
				cat $${t} >> $(builddir)/build-$$i/.config.old; \
			fi; \
		done; \
		cat $(basedir)/config.$$i >> $(builddir)/build-$$i/.config.old; \
		sed -e 's/.*CONFIG_VERSION_SIGNATURE.*/CONFIG_VERSION_SIGNATURE="Ubuntu $(release)-$(revision)-'$$i'"/' \
			$(builddir)/build-$$i/.config.old > \
			$(builddir)/build-$$i/.config; \
		$(MAKE) -C $(builddir)/build-$$i ARCH=$(KPKG_SUBARCH) silentoldconfig; \
		if [ "$$i" = "$(crashdump)" ]; then \
			cat $(builddir)/build-$$i/.config.old > $(builddir)/build-kdump/.config.old; \
			echo 'CONFIG_PROC_VMCORE=y' >> $(builddir)/build-kdump/.config.old; \
			sed  -e 's/.*CONFIG_CRASH_DUMP.*/CONFIG_CRASH_DUMP=y/' \
			     -e 's/.*CONFIG_PHYSICAL_START.*/CONFIG_PHYSICAL_START=0x1000000/' \
			     -e 's/.*CONFIG_VERSION_SIGNATURE.*/CONFIG_VERSION_SIGNATURE="Ubuntu $(release)-$(revision)-kdump"/' \
				$(builddir)/build-kdump/.config.old > \
				$(builddir)/build-kdump/.config; \
			$(MAKE) -C $(builddir)/build-kdump ARCH=$(KPKG_SUBARCH) silentoldconfig; \
		fi; \
                if [ "$$i" = "$(lowlatency)" ]; then \
                        cat $(builddir)/build-$$i/.config.old > $(builddir)/build-lowlatency/.config.old; \
                        sed  -e 's/.*CONFIG_HZ.*//' -e 's/.*CONFIG_PREEMPT.*//' \
				$(builddir)/build-lowlatency/.config.old > \
				$(builddir)/build-lowlatency/.config; \
			cat debian/config/lowlatency.config >> \
				$(builddir)/build-lowlatency/.config; \
			$(MAKE) -C $(builddir)/build-lowlatency ARCH=$(KPKG_SUBARCH) silentoldconfig; \
                fi; \
		ln -s $(abidir)/$(release)-$(revision)/${arch}/$$i $(builddir)/build-$$i/debian/abi-${release}${debnum}-$$i; \
	done
	ln -s ../../../firmware $(srcdir)/debian

	touch stamp-unpack

build_prereq := \
	release.Debian version.Debian \
	debian/control \
	unpack

build: $(build_prereq)
	dh_testdir

	cd $(srcdir); \
		make ARCH=$(KPKG_SUBARCH) $(defconfig); \
		mv .config .config.old; \
		sed -e 's/^# \(CONFIG_MODVERSIONS\) is not set$$/\1=y/' \
			-e 's/.*CONFIG_LOCALVERSION_AUTO.*/# CONFIG_LOCALVERSION_AUTO is not set/' \
			.config.old > .config; \
		make ARCH=$(KPKG_SUBARCH) prepare

	mkdir -p $(abidir)/$(release)-$(revision)/${arch}
	echo $(abinum) > $(abidir)/$(release)-$(revision)/abiname

	@for i in $(flavours); do \
		echo "Building $$i..."; \
		cd $(builddir)/build-$$i; \
		if [ -e /CurrentlyBuilding ] && [ -z "$(CONCURRENCY_LEVEL)" ]; then \
			CONCURRENCY_LEVEL=$$(getconf _NPROCESSORS_ONLN) && \
			CONCURRENCY_LEVEL=$$(expr $$CONCURRENCY_LEVEL \* 2) && \
			export CONCURRENCY_LEVEL; \
		fi; \
		$(MAKE_KPKG) --append_to_version $(debnum)-$$i build; \
		if [ "$$i" = "$(crashdump)" ]; then \
			cd $(builddir)/build-kdump; \
			$(MAKE_KPKG) --append_to_version -kdump build; \
			cd $(builddir)/build-$$i; \
		fi; \
                if [ "$$i" = "$(lowlatency)" ]; then \
                        cd $(builddir)/build-lowlatency; \
                        $(MAKE_KPKG) --append_to_version $(debnum)-lowlatency build; \
                        cd $(builddir)/build-$$i; \
                fi; \
		sed -e 's/^\(.\+\)[[:space:]]\+\(.\+\)[[:space:]]\(.\+\)$$/\3 \2 \1/' \
			Module.symvers | sort > \
			$(abidir)/$(release)-$(revision)/${arch}/$$i; \
		if [ ! -e "$(abidir)/${arch}.ignore" ]; then \
			echo "Checking module listings..."; \
			find -name \*.ko | sed -e 's/.*\/\([^\/]*\)\.ko/\1/' | sort > \
				$(abidir)/$(release)-$(revision)/${arch}/$$i.modules; \
			if [ "`diff -u $(abidir)/$(release)-$(prev_revision)/${arch}/$$i.modules $(abidir)/$(release)-$(revision)/${arch}/$$i.modules | grep ^-[^-] | wc -l`" != "0" ]; then \
				real_missing=`diff -u $(abidir)/$(release)-$(prev_revision)/${arch}/$$i.modules $(abidir)/$(release)-$(revision)/${arch}/$$i.modules | grep ^-[^-] | sed -e 's/^-//'`; \
				if [ -e $(abidir)/$(release)-$(prev_revision)/${arch}/modules.ignore ]; then \
					real_missing=`(echo $$real_missing | xargs -n1 echo; cat $(abidir)/$(release)-$(prev_revision)/${arch}/modules.ignore) | sort | uniq -u`; \
				fi; \
				if [ "$$real_missing" != "" ]; then \
					echo "Modules have gone missing:"; \
					echo $$real_missing; \
					echo; \
					echo "Will not continue!"; \
					exit 1; \
				fi; \
			fi; \
		fi; \
		if [ "$(prev_revision)" != "0.0" ] && [ "$(abinum)" = "$(shell cat $(abidir)/$(release)-$(prev_revision)/abiname)" ]; then \
			echo "Checking ABI for $$i..."; \
			if [ ! -e "$(abidir)/${arch}.ignore" -a "$(skipabi)" != "true" ]; then \
				if [ "`diff -u $(abidir)/$(release)-$(prev_revision)/${arch}/$$i $(abidir)/$(release)-$(revision)/${arch}/$$i | grep ^-[^-] | wc -l`" != "0" ]; then \
					echo "ABI has changed!  Refusing to continue; please update the ABINAME accordingly.  Differences:"; \
					diff -u $(abidir)/$(release)-$(prev_revision)/${arch}/$$i $(abidir)/$(release)-$(revision)/${arch}/$$i; \
					exit 1; \
				fi; \
				if [ "`diff -u $(abidir)/$(release)-$(prev_revision)/${arch}/$$i $(abidir)/$(release)-$(revision)/${arch}/$$i | grep ^+[^+] | wc -l`" != "0" ]; then \
					echo "WARNING: new symbols have been added.  This is not critical, but probably is not a good idea when attempting to maintain ABI stability.  Differences:"; \
					diff -u $(abidir)/$(release)-$(prev_revision)/${arch}/$$i $(abidir)/$(release)-$(revision)/${arch}/$$i || true; \
				fi; \
			else \
				if [ -e $(abidir)/$(release)-$(prev_revision)/${arch}/$$i ]; then \
					if ! diff -u $(abidir)/$(release)-$(prev_revision)/${arch}/$$i $(abidir)/$(release)-$(revision)/${arch}/$$i >/dev/null 2>&1; then \
						echo "WARNING! ABI check override for ${arch} has been detected, and there were changes!"; \
						diff -u $(abidir)/$(release)-$(prev_revision)/${arch}/$$i $(abidir)/$(release)-$(revision)/${arch}/$$i || true; \
					fi; \
				else \
					echo "WARNING! ABI check override for ${arch} has been detected!"; \
					echo "ABI compatibility can NOT be verified! but still proceeding as requested"; \
				fi; \
			fi; \
		fi; \
		cd - > /dev/null; \
	done

clean: debian/control
	dh_testdir
	dh_testroot

	rm -f stamp-* .config* release.Debian version.Debian
	rm -rf $(abidir)/$(release)-$(revision)
	rm -rf $(builddir)

	dh_clean

	# udebs/kernel-wedge
	rm -rf firmware modules kernel-versions package-list \
		debian/d-i-$(arch)
	cp -f debian/control.stub debian/control

ifneq ($(prev_revision),0.0)
	# Check for the previous kernel's abi file; now a requirement for
	# builds!
	
	@if [ ! -f "$(abidir)/$(release)-$(prev_revision)/abiname" ]; then \
		echo "Missing $(abidir)/$(release)-$(prev_revision)/abiname file." 1>&2; \
		exit 1; \
	fi
	@if [ "$(prev_revision)" != "0" ] && [ "$(abinum)" = "$(shell cat $(abidir)/$(release)-$(prev_revision)/abiname)" ]; then \
		if [ ! -e "$(abidir)/${arch}.ignore" -a "$(skipabi)" != "true" ]; then \
			for i in $(flavours); do \
				echo "Checking ABI for $$i..."; \
				if [ ! -f "$(abidir)/$(release)-$(prev_revision)/${arch}/$$i" ]; then \
					echo "Missing $(abidir)/$(release)-$(prev_revision)/${arch}/$$i file." 2>&1; \
					exit 1; \
				fi; \
			done \
		else \
			echo "WARNING! ABI check override for ${arch} has been detected!"; \
			echo "ABI compatibility can NOT be verified! but still proceeding as requested"; \
		fi; \
	fi
endif

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	> debian/files

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot

	cd $(srcdir); \
		$(MAKE_KPKG) kernel-source; \
		$(MAKE_KPKG) kernel-doc

	mv $(builddir)/*.deb ..
	cat $(srcdir)/debian/files >> debian/files
	rm $(srcdir)/debian/files

	dh_installchangelogs -plinux-kernel-devel
	dh_installdocs -plinux-kernel-devel
	dh_compress -plinux-kernel-devel
	dh_fixperms -plinux-kernel-devel
	dh_installdeb -plinux-kernel-devel
	dh_gencontrol -plinux-kernel-devel
	dh_md5sums -plinux-kernel-devel
	dh_builddeb -plinux-kernel-devel

headers_tmp := $(CURDIR)/debian/tmp-headers
headers_dir := $(CURDIR)/debian/linux-libc-dev

header_make_args := -C $(srcdir) O=$(headers_tmp) \
	EXTRAVERSION=$(debnum) INSTALL_HDR_PATH=$(headers_tmp)/install

header-deb:
	dh_testdir
	dh_testroot

	rm -rf $(headers_dir) $(headers_tmp)
	install -d $(headers_dir)/usr/include $(headers_tmp)

	make $(header_make_args) ARCH=$(headers_arch) $(defconfig)
	mv $(headers_tmp)/.config $(headers_tmp)/.config.old
	sed -e 's/^# \(CONFIG_MODVERSIONS\) is not set$$/\1=y/' \
		-e 's/.*CONFIG_LOCALVERSION_AUTO.*/# CONFIG_LOCALVERSION_AUTO is not set/' \
		$(headers_tmp)/.config.old > $(headers_tmp)/.config
	make $(header_make_args) ARCH=$(headers_arch) oldconfig
	make $(header_make_args) ARCH=$(headers_arch) headers_install

	mv $(headers_tmp)/install/include/asm* \
		$(headers_dir)/usr/include/
	mv $(headers_tmp)/install/include/linux \
		$(headers_dir)/usr/include/

	dh_installchangelogs -plinux-libc-dev
	dh_installdocs -plinux-libc-dev
	dh_compress -plinux-libc-dev
	dh_fixperms -plinux-libc-dev
	dh_installdeb -plinux-libc-dev
	dh_gencontrol -plinux-libc-dev
	dh_md5sums -plinux-libc-dev
	dh_builddeb -plinux-libc-dev

	rm -rf $(headers_dir) $(headers_tmp)

# Build architecture-dependent files here.
binary-debs: install
	dh_testdir
	dh_testroot

	cd $(srcdir); \
		 HEADER_CLEAN_HOOK=$(CURDIR)/debian/header-install \
			 $(MAKE_KPKG) $(appvan) kernel-headers

	for i in $(flavours); do \
		olddir=`pwd`; \
		cd $(builddir)/build-$$i; \
		$(MAKE_KPKG) --append_to_version $(debnum)-$$i \
			--initrd kernel-image; \
		if [ "$$i" = "$(crashdump)" ]; then \
			cd $(builddir)/build-kdump; \
			$(MAKE_KPKG) --append_to_version -kdump \
				--initrd kernel-image; \
		fi; \
                if [ "$$i" = "$(lowlatency)" ]; then \
                        cd $(builddir)/build-lowlatency; \
                        $(MAKE_KPKG) --append_to_version $(debnum)-lowlatency \
                                --initrd kernel-image; \
                fi; \
		cd $$olddir > /dev/null; \
		cat $(builddir)/build-$$i/debian/files >> debian/files; \
		if [ "$$i" = "$(crashdump)" ]; then \
			cat $(builddir)/build-kdump/debian/files >> debian/files; \
		fi; \
                if [ "$$i" = "$(lowlatency)" ]; then \
                        cat $(builddir)/build-lowlatency/debian/files >> debian/files; \
                fi; \
	done

binary-arch: binary-debs header-deb binary-udebs
	dh_testdir
	dh_testroot

	mv $(builddir)/*.deb ..
	cat $(srcdir)/debian/files >> debian/files
	rm $(srcdir)/debian/files

binary: binary-indep binary-arch

.PHONY: build clean binary-indep binary-arch binary-debs binary install unpack debnum abinum

#####################
# The following targets set the stage for building the debian-installer udebs

.PHONY: debian/control binary-udebs debian/control.stub

debian/control.stub: FORCE
	for i in debian/d-i/kernel-versions.in debian/control.stub.in; do	\
	  new=`echo $$i | sed 's/\.in$$//'`;					\
	  cat $$i | sed -e 's/PKGVER/$(pkgversion)/g' -e 's/ABINUM/$(abinum)/g' > \
		$$new;								\
	done
	flavours="$(shell ls -d debian/config/vars.* debian/config/*/vars.*)";	\
	for i in $$flavours; do							\
	  $(SHELL) debian/bin/control-create $$i |				\
		sed -e 's/PKGVER/$(pkgversion)/g' -e 's/ABINUM/$(abinum)/g' >>	\
		debian/control.stub;						\
	done
	cp debian/control.stub debian/control

debian/control: debian/control.stub
	# Copy stuff for kernel-wedge
	rm -rf firmware modules kernel-versions package-list
	mkdir -p modules/$(arch)/ firmware/$(arch)/
	cp debian/d-i/modules/* modules/$(arch)/
	cp debian/d-i/firmware/* firmware/$(arch)/
	cp debian/d-i/package-list debian/d-i/kernel-versions .
	touch modules/$(arch)/kernel-image

	# Per flavour module lists
	flavour_modules=`ls debian/d-i/modules.$(arch)-* 2>/dev/null`	\
	    || true;							\
	if [ "$$flavour_modules" != "" ]; then				\
	    for flav in $$flavour_modules; do				\
		name=`echo $$flav | sed 's/.*\/modules.$(arch)-//'`;	\
		mkdir modules/$(arch)-$$name;				\
		(cd debian/d-i/modules/; tar cf - `cat ../../../$$flav`) |\
		    (cd modules/$(arch)-$$name/; tar xf -);		\
		touch modules/$(arch)-$$name/kernel-image;		\
	    done;							\
	fi

	# Remove unwanted stuff
	if [ -r "debian/d-i/exclude-modules.$(arch)" ]; then		\
		(cat debian/d-i/exclude-modules.$(arch); 		\
			ls modules/$(arch)/) | sort | uniq -d |		\
			(cd modules/$(arch)/; xargs rm -f);		\
	fi
	if [ -r "debian/d-i/exclude-firmware.$(arch)" ]; then		\
		(cat debian/d-i/exclude-firmware.$(arch);		\
			ls firmware/$(arch)/) | sort | uniq -d |	\
			(cd firmware/$(arch)/; xargs rm -f);		\
        fi

	if [ ! -d modules/$(KPKG_SUBARCH) ]; then		\
		mkdir -p modules/$(KPKG_SUBARCH);		\
                cp modules/$(arch)/* modules/$(KPKG_SUBARCH);	\
	fi

	kernel-wedge gen-control > debian/control

binary-udebs: binary-debs
	dh_testdir
	dh_testroot

	# unpack the kernels into a temporary directory
	mkdir -p debian/d-i-${arch}

	# XXX: this stuff finds the kernels that need upacking according to
	# kernel-versions and unpack them into the temp dir.

	imagelist=$$(cat kernel-versions | grep ^${arch} | awk '{print $$4}') && \
	for i in $$imagelist; do \
	  dpkg -x $$(ls debian/build/$(stem)-image-$$i\_*${arch}.deb) debian/d-i-${arch}; \
	done

	export SOURCEDIR=debian/d-i-${arch} && \
	  kernel-wedge install-files && \
	  kernel-wedge check

	dh_fixperms -s
	dh_gencontrol -s

	# XXX: this stuff builds only the .udeb. We cannot call dh_builddeb for everything
	# since the .deb will be generated by make-kpkg.
	dilist=$$(dh_listpackages -s | grep "\-di$$") && \
	for i in $$dilist; do \
	  dh_builddeb -p$$i; \
	done

#####################
# The following targets are for the maintainer only! do no run if you don't
# know what they do.

.PHONY: printenv updateconfigs printchanges insertchanges startnewrelease diffupstream help

help:
	@echo "These are the targets in addition to the normal debian ones:"
	@echo
	@echo "  printenv        : Print some variables used in the build"
	@echo
	@echo "  updateconfigs   : Update debian/config/*"
	@echo
	@echo "  printchanges    : Print the current changelog entries (from git)"
	@echo
	@echo "  insertchanges   : Insert current changelog entries (from git)"
	@echo
	@echo "  startnewrelease : Start a new changelog set"
	@echo
	@echo "  diffupstream    : Diff stock kernel code against upstream (git)"
	@echo
	@echo "  help            : If you are kernel hacking, you need the professional"
	@echo "                    version of this"
	@echo
	@echo "Environment variables:"
	@echo
	@echo "  NOKERNLOG       : Do not add upstream kernel commits to changelog"
	@echo "  NOEXTRAS        : Do not build extra things like lowlatency kernels"

updateconfigs:
	dh_testdir
	@for arch in i386 amd64 ia64 hppa powerpc sparc; do	\
		$(SHELL) debian/bin/oldconfig $$arch;		\
	done
	rm -rf build

printenv:
	dh_testdir
	@echo release        = $(release)
	@echo pkgversion     = $(pkgversion)
	@echo revisions      = $(revisions)
	@echo revision       = $(revision)
	@echo prev_revisions = $(prev_revisions)
	@echo prev_revision  = $(prev_revision)
	@echo version        = $(version)
	@echo debnum         = $(debnum)
	@echo abinum         = $(abinum)
	@echo gitver         = $(gitver)
	@echo flavours       = $(flavours)
	@echo crashdump      = $(crashdump)
	@echo lowlatency     = $(lowlatency)

printchanges:
	@git-log --pretty=short Ubuntu-2.6.20-$(prev_revision)..HEAD | \
		perl -w -f debian/bin/git-ubuntu-log $(ubuntu_log_opts)

insertchanges:
	@perl -w -f debian/bin/insert-changes.pl

diffupstream:
	@git-diff-tree -p upstream-linux..HEAD $(shell ls | grep -vE '^(ubuntu|debian|\.git.*)')

startnewrelease:
	dh_testdir
	@nextminor=$(shell expr `echo $(revision) | awk -F. '{print $$2}'` + 1); \
	user=$(shell whoami); \
	memyselfandirene="$$(getent passwd $$user | cut -d ":" -f 5 | cut -d "," -f 1)"; \
	now="$(shell date -R)"; \
	echo "Creating new changelog set for $(release)-$(abinum).$$nextminor..."; \
	echo -e "$(stem)-source-$(version) ($(release)-$(abinum).$$nextminor) UNRELEASED; urgency=low\n" > debian/changelog.new; \
	echo "  CHANGELOG: Do not edit directly. Autogenerated at release." >> \
		debian/changelog.new; \
	echo "  CHANGELOG: Use the printchanges target to see the curent changes." \
		>> debian/changelog.new; \
	echo "  CHANGELOG: Use the insertchanges target to create the final log." \
		>> debian/changelog.new; \
	echo -e "\n -- $$memyselfandirene <$$user@ubuntu.com>  $$now\n" >> \
		debian/changelog.new ; \
	cat debian/changelog >> debian/changelog.new; \
	mv debian/changelog.new debian/changelog

FORCE:
