#!/usr/bin/make -f
#
# debian/rules for kernel-image-speakup-i386
#
# GNU copyright 1997 to 1999 by Joey Hess.
# Copyright (c) 1999-2002 Herbert Xu <herbert@debian.org>
#
# $Id: rules,v 1.24 2003/09/27 08:14:38 herbert Exp $

# 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

khsed := s/^Package: kernel-headers-\([^-]*\)\(-speakup\)$$/\1 \2/
debver := $(shell sed -n '$(khsed); t e; b; :e; p; q' debian/control)
export version := $(firstword $(debver))
export debnum := $(word 2,$(debver))
debver := $(version)$(debnum)
appvan :=

ifneq ($(debnum),)
appvan := --append_to_version $(debnum)
endif

ktver := $(shell sed -n 's/.*kernel-tree-\([^,]*\).*/\1/p; t e; b; :e q' \
		debian/control)

unpack: unpack-stamp
unpack-stamp:
	dh_testdir
	tar jxf /usr/src/kernel-source-$(version).tar.bz2
	cd kernel-source-$(version); \
		/usr/src/kernel-patches/all/apply/speakup;
	cd kernel-source-$(version); \
		/usr/src/kernel-patches/all/$(version)/apply/debian $(ktver)
	cp debian/changelog kernel-source-$(version)/debian
	cp debian/control kernel-source-$(version)/debian
	cp debian/copyright kernel-source-$(version)/debian
	> kernel-source-$(version)/debian/official
	cp -al kernel-source-$(version) build-speakup
	cp config/speakup build-speakup/.config
	ln -s `command -v touch` bin/touch.orig

	touch unpack-stamp

build: build-stamp
build-stamp: unpack-stamp
	dh_testdir
	PATH=$$PWD/bin:$$PATH; \
	cd build-speakup; \
		make-kpkg --append_to_version $(debnum) build; \

	touch build-stamp

clean:
	dh_testdir
	rm -f unpack-stamp build-stamp
	rm -rf kernel-source-$(version) build-* install-*
	rm -f bin/touch.orig
	dh_clean

install: build
	dh_testdir
	dh_clean -k
	dh_installdirs

# Build architecture-independent files here.
binary-indep:

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

	cp -al build-speakup install-speakup
	cd install-speakup; \
		make-kpkg $(appvan) kernel_headers; \
		make-kpkg $(appvan) kernel_doc; \
		make-kpkg $(appvan) --initrd kernel_image
	mv install-speakup/debian/files debian
	rm -rf install-$$i
	mv *.deb ..

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