#!/usr/bin/make -f
DEB_SOURCE := $(shell dpkg-parsechangelog | grep Source: | sed -e 's/Source: //')
DEB_VERSION := $(shell dpkg-parsechangelog | grep Version: | sed -e 's/Version: //')
DEB_UPSTREAM_VERSION := $(shell echo $(DEB_VERSION) | sed -e 's/-[^-]*$$//')
GIT_URL = git://codeaurora.org/quic/xwin/xf86-video-msm.git

%:
	dh $@ --with autoreconf,xsf

override_dh_autoreconf:
	dh_autoreconf ./autogen.sh

override_dh_auto_configure:
	dh_auto_configure -- --with-kernel-headers=$(CURDIR)/debian/include \
		CFLAGS="$(CFLAGS) -Wno-error=unused-but-set-variable"

override_dh_strip:
	dh_strip --dbg-package=xserver-xorg-video-msm-lts-quantal-dbg

get-orig-source:
	set -e; if echo $(DEB_VERSION) | grep -c "git"; \
	then \
		git_version=`echo $(DEB_VERSION) | sed -e 's/^.*git\([0-9]*\)*\.\(.*\)-.*$$/\2/g'`; \
	else \
		git_version=$(DEB_UPSTREAM_VERSION); \
	fi; \
	tmpdir=`mktemp -d -t`; \
	cd $$tmpdir; \
	echo "checkout upstream repository ..."; \
	git clone $(GIT_URL); echo "getting specific upstream revision/tag: $$git_version"; \
	cd `ls | head -n 1`; git checkout -b orig $$git_version; cd ..; \
	tar --exclude=.git -czvf $(CURDIR)/$(DEB_SOURCE)_$(DEB_UPSTREAM_VERSION).orig.tar.gz `ls | head -n 1`; \
	cd $(CURDIR); \
	rm -rf $$tmpdir
