#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk

DEB_HOST_ARCH     ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_BUILD_ARCH    ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
    CROSSCC=$(DEB_HOST_GNU_TYPE)-
endif

export KVERS

%:
	dh $@

override_dh_auto_build:
ifeq (i386,$(shell dpkg-architecture -qDEB_HOST_ARCH))
	# Mark slmodemd as not requiring executable stack (LP: #537650)
	objcopy modem/dsplibs.o modem/dsplibs.o.new \
		--set-section-flags ".note.GNU-stack"=contents,readonly
	mv modem/dsplibs.o.new modem/dsplibs.o

	$(MAKE) SUPPORT_ALSA=1 CC=$(CROSSCC)gcc

	# 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-$(DEB_VERSION_UPSTREAM)

	# 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-$(DEB_VERSION_UPSTREAM)
	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
