#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS
DEB_CONFIGURE_EXTRA_FLAGS ?= ""

pname:=mstflint
pdkms:=$(pname)-dkms
dkms_pkg:=$(pname)-$(pversion)
pversion_number:=$(shell sed -r '1 s:(.*) \((.*)\).*:\2:; q' debian/changelog)
pversion_string:=$(shell sed -r '1 s:(.*) \((.*)\).*:\1 \2:; q' debian/changelog)

%:
	dh $@ --with dkms

# override_dh_auto_clean:

override_dh_auto_configure:
	./autogen.sh
	dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS) "MSTFLINT_VERSION_STR=$(pversion_string)" --enable-adb-generic-tools

override_dh_auto_build:
	make

override_dh_auto_install:
	sed -e 's:@PKGVER@:$(pversion_number):' < debian/$(pdkms).dkms.in > debian/$(pdkms).dkms
	make DESTDIR=$(CURDIR)/debian/tmp install
	make -C kernel DESTDIR=$(CURDIR)/debian/tmp install-dkms
