#!/usr/bin/make -f
#
# debian/rules for Ubuntu linux
#
# Use this however you want, just give credit where credit is due.
#
# Copyright (c) 2007 Ben Collins <bcollins@ubuntu.com>
#

# dpkg-buildpackage passes options that are incomptatible
# with the kernel build.
unexport CFLAGS
unexport LDFLAGS

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

# Common variables for all architectures
include debian/rules.d/0-common-vars.mk

# Pill in some arch specific stuff
include debian/rules.d/$(arch).mk

# Maintainer targets
include debian/rules.d/1-maintainer.mk

# Debian Build System targets
binary: binary-indep binary-arch

#build: build-arch build-indep
build: unpack apply-patchset build-arch

clean: debian/control
	dh_testdir
	dh_testroot
	dh_clean

	# d-i stuff
	rm -rf modules kernel-versions package-list
	rm -rf debian/d-i-$(arch)

	# normal build junk
	rm -rf debian/abi/$(release)-$(revision)
	rm -rf $(builddir)
	rm -f $(stampdir)/stamp-*
	rm -rf debian/linux-*

	# This gets rid of the d-i packages in control
	cp -f debian/control.stub debian/control

	# Remove patched sources
	for nf in `$(SHELL) -c ls`; do \
		if [ $$nf != "debian" ]; then \
		rm -fr $$nf; \
		fi \
	done

# Builds the image, arch headers and debug packages
include debian/rules.d/2-binary-arch.mk

# Rules for building the udebs (debian-installer)
#include debian/rules.d/5-udebs.mk

# Builds the source, doc and linux-headers indep packages
include debian/rules.d/3-binary-indep.mk

# Various checks to be performed on builds
include debian/rules.d/4-checks.mk

# Misc stuff
debian/control.stub: debian/scripts/control-create	\
		debian/control.stub.in			\
		debian/changelog			\
		$(wildcard debian/control.d/* debian/sub-flavours/*.vars)
#	for i in debian/control.stub.in; do
	for i in debian/control.stub.in; do	\
	  new=`echo $$i | sed 's/\.in$$//'`;					\
	  cat $$i | sed -e 's/PKGVER/$(release)/g' -e 's/ABINUM/$(abinum)/g' >	\
		$$new;								\
	done
	flavours="$(wildcard debian/control.d/vars.* debian/sub-flavours/*.vars)";\
	for i in $$flavours; do							\
	  $(SHELL) debian/scripts/control-create $$i |				\
		sed -e 's/PKGVER/$(release)/g' -e 's/ABINUM/$(abinum)/g' >>	\
		debian/control.stub;						\
	done
	cp debian/control.stub debian/control
