#!/usr/bin/make -f
# -*- makefile -*-


include /usr/share/quilt/quilt.make

#export DH_VERBOSE=1
export DH_ALWAYS_EXCLUDE="CVS:.svn"

# Get package version info.
SOURCE_VERSION := $(shell head -1 debian/changelog | cut -d\( -f2 | cut -d\) -f1)
UPSTREAM_VERSION := $(shell echo "$(SOURCE_VERSION)" | cut -d- -f1)


build: $(QUILT_STAMPFN) build-stamp
build-stamp:
	dh build --before auto_configure
	dh build --after auto_test
	touch $@ 


clean: unpatch
	dh clean --before auto_clean
	dh clean --after auto_clean


install: build install-stamp
install-stamp:
	dh install --before auto_install

	install -d                                        $(CURDIR)/debian/vhba-dkms/usr/src/vhba-$(UPSTREAM_VERSION)
	install -m 644 -D $(CURDIR)/debian/vhba-dkms.dkms $(CURDIR)/debian/vhba-dkms/usr/src/vhba-$(UPSTREAM_VERSION)/dkms.conf
	install -m 644 -D $(CURDIR)/Makefile              $(CURDIR)/debian/vhba-dkms/usr/src/vhba-$(UPSTREAM_VERSION)/
	install -m 644 -D $(CURDIR)/*.c                   $(CURDIR)/debian/vhba-dkms/usr/src/vhba-$(UPSTREAM_VERSION)/
	install -d                                        $(CURDIR)/debian/vhba-dkms/usr/src/vhba-$(UPSTREAM_VERSION)/kat
	install -m 644 -D $(CURDIR)/kat/*                 $(CURDIR)/debian/vhba-dkms/usr/src/vhba-$(UPSTREAM_VERSION)/kat/
	install -m 755 -D $(CURDIR)/kat/kat               $(CURDIR)/debian/vhba-dkms/usr/src/vhba-$(UPSTREAM_VERSION)/kat/

	dh install --after auto_install
	touch $@


binary-indep: install
	dh binary-indep --until installdeb

	# Version magic
	SED_EXPR="s/\$${VERSION}/$(subst .,\.,$(UPSTREAM_VERSION))/"; \
	VERFILES="$(addprefix $(CURDIR)/debian/vhba-dkms/, $(addprefix DEBIAN/, preinst postinst prerm) usr/src/vhba-$(UPSTREAM_VERSION)/dkms.conf)"; \
	for file in $${VERFILES}; do echo "$${file}"; sed --in-place $${SED_EXPR} "$${file}"; done

	dh binary-indep --after installdeb

binary-arch: install
# We have nothing to do by default.

binary: binary-indep binary-arch

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

