#!/usr/bin/make -f
#
# debian/rules for alsa-modules-*-i386
#
# GNU copyright 1997 to 1999 by Joey Hess.
# Copyright (c) 1999-2001 Herbert Xu <herbert@debian.org>
#
# $Id: rules,v 1.4 2001/03/11 04:20:31 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

revision := $(shell \
	head -1 debian/changelog | \
	sed 's/^.*(\(.*\)).*$$/\1/' \
)
version := $(shell \
	head -1 debian/changelog | \
	sed 's/^alsa-modules-\(.*\)-i386.*$$/\1/' \
)
ifeq ($(flavours),)
flavours := $(shell \
	find config -maxdepth 1 -type f ! -name default -printf '%f\n' \
)
endif

unpack: unpack-stamp
unpack-stamp:
	tar jxf /usr/src/kernel-source-$(version).tar.bz2
	tar zxf /usr/src/alsa-driver.tar.gz
	install -d modules/alsa-driver*/debian
	install -d kernel-source-$(version)/debian
	cp debian/kernel-image-i386.changelog kernel-source-$(version)/debian/changelog
	cp debian/control.source modules/alsa-driver*/debian/modules.d/control.source
	cp debian/changelog modules/alsa-driver*/debian
	for i in $(flavours); do \
		cp -al kernel-source-$(version) build-$$i; \
		cp config/$$i build-$$i/.config; \
		cd build-$$i; \
		cd ..; \
	done
	cp config/default kernel-source-$(version)/.config

	touch unpack-stamp

build: unpack

clean:
	rm -f unpack-stamp install-stamp
	rm -rf kernel-source-$(version) build-* modules
	rm -f *.deb
	dh_clean

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

# Build architecture-dependent files here.
binary-arch: build
#	echo $(MODULE_LOC) $(MODVERS)
	for i in $(flavours); do \
		cd build-$$i; \
		KERNEL_DEPENDS=y MODVERS=$(revision) ALSA_CARDS=all ALSA_NOPNP=n ALSA_DEBUG=n MODULE_LOC='../modules' make-kpkg --append_to_version -$$i modules-image; \
		cd ..; \
	done
	for p in *.deb; do \
		dpkg-distaddfile $$p sound optional ; \
	done
	mv *.deb ..

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