#!/usr/bin/make -f

version         := $(shell dpkg-parsechangelog -SVersion | sed -s 's/^0.//; s/-[^-]*$$//')
dkms_target     := usr/src/kdbus-$(version)

%:
	dh $@ --with dkms

override_dh_auto_build:

override_dh_auto_install:
	install -d debian/tmp/$(dkms_target)
	cp -r Changelog Documentation README include ipc Makefile* samples tools usr debian/tmp/$(dkms_target)

override_dh_dkms:
	dh_dkms -V $(version)

# TODO: filter .gitignore files when creating the orig tarball
get-orig-source:
	set -e; mkdir -p debian/tmp; cd debian/tmp; \
	git clone https://github.com/systemd/kdbus.git; \
	cd kdbus; \
	commit_id=`git describe --always`; \
	commit_date=`date --utc --date="$$(git log --pretty=fuller -n1 --date=rfc | grep CommitDate: | sed -e 's/CommitDate:[^0-9]*//')" "+%Y%m%dt%H%M%S"`; \
	git archive --format=tar master | xz -9 > $(CURDIR)/../kdbus-dkms_0.$$commit_date.$$commit_id.orig.tar.xz
	rm -rf debian/tmp
