#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk

CFLAGS ?= -Wall -g

# For DKMS
DRIVER_NAME := speakup
VERSION := $(shell dpkg-parsechangelog | grep '^Version:' | cut -d' ' -f2 | cut -d- -f1 | cut -d\: -f2)
PKG_kernel_src  := speakup
ARCH := $(shell dpkg --print-architecture)
ifeq ($(ARCH),amd64)
ARCH_SUFFIX=x86_64
else
ARCH_SUFFIX=i386
endif

DEB_DH_INSTALLINIT_ARGS = -R
DEB_UPDATE_RCD_PARAMS = start 46 S .

ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif

DEB_INSTALL_DOCS_speakup-tools = contrib/README

install/speakup-source::
	# Enforce executable bit on debian/rules, and create
	# directory structure for modules source
	install -D -m 0755 debian/rules.modules \
		debian/tmp/modules/speakup/debian/rules
	
	# Prepare the other debian stuff
	for f in *.modules.in control compat copyright changelog; do \
		install -m 0644 debian/$$f \
			debian/tmp/modules/speakup/debian/; \
	done
	
	# Prepare upstream source
	(cd src ; find . -printf "%P\n" | \
		cpio -admp ../debian/tmp/modules/speakup/ )
		
	# Prepare the debian source tarball
	tar jcf debian/speakup-source/usr/src/speakup.tar.bz2 \
		-C debian/tmp modules

binary-install/speakup-doc::
	dh_installdocs

configure/$(PKG_kernel_src)::
	#Replace important strings
	for i in dkms.conf \
		$(PKG_kernel_src).install; do \
		sed -e "s|#VERSION#|$(VERSION)|"   \
			-e "s|#ARCH#|$(ARCH_SUFFIX)|"   \
			debian/$$i.in > debian/$$i;      \
	done

clean::
	rm -f debian/dkms.conf \
	debian/$(PKG_kernel_src).install
	rm -Rf $(CURDIR)/$(PKG_kernel_src)
	rm -f stamp-patch
