#!/usr/bin/make -f

export KVERS

CVERSION := $(shell dpkg-parsechangelog | grep '^Version:' | cut -d' ' -f2 | cut -d- -f1)

%:
	dh $@ --with dkms

override_dh_auto_build:
ifeq (i386,$(shell dpkg-architecture -qDEB_BUILD_ARCH))
	$(MAKE) SUPPORT_ALSA=1
	# Mark slmodemd as not requiring executable stack (LP: #537650)
	PATH=/usr/sbin:/sbin:$$PATH execstack -c modem/slmodemd

	# Make 15sl-modem-daemon executable before install:
	chmod +x debian/15sl-modem-daemon
endif

override_dh_auto_install:
	mkdir -p debian/sl-modem-dkms/usr/src/sl-modem-$(CVERSION)

	# Copy only the driver source to the proper location
	tar -c --exclude ".svn" modem/modem_defs.h drivers patches ungrab-winmodem | tar x -C debian/sl-modem-dkms/usr/src/sl-modem-$(CVERSION)
	chmod -R a+r debian/sl-modem-dkms/

override_dh_installchangelogs:
	dh_installchangelogs Changes

override_dh_installdebconf:
	dh_installdebconf
	perl debian/setcountries.pl debian/sl-modem-daemon/DEBIAN/templates

override_dh_installinit:
	dh_installinit -n

override_dh_installmodules:
	dh_installmodules --name=sl-modem

override_dh_dkms:
	dh_dkms -V
