#!/usr/bin/make -f

include /usr/share/quilt/quilt.make

DEB_VERSION := $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')

config.status: patch configure.ac
	dh_testdir
	echo $(DEB_VERSION) > .version
	./autogen.sh --noconfigure
	./configure --prefix=/usr

build: build-stamp
build-stamp: config.status
	dh_testdir
	$(MAKE)
	touch $@

install: build-stamp
	dh_testroot
	dh_clean -k
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp/

clean: unpatch
	dh_testdir
	dh_testroot
	dh_clean
	rm -f build-stamp
	test -f Makefile && $(MAKE) distclean || true

binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_install --sourcedir=debian/tmp
	dh_installdocs
	dh_installman
	dh_link
	dh_strip --dbg-package=gstreamer0.10-openmax
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

ORIGIN_REF := omap
PATCHES_REF := maemo5-patches

update-patch-series:
	mkdir -p debian/patches
	rm -f debian/patches/*.patch
	git format-patch -N -o debian/patches $(PATCHES_REF) ^$(ORIGIN_REF) | \
	        xargs -n 1 basename > debian/patches/series
	for patch in debian/patches/*.patch; do \
		lines=$$(cat $$patch | wc -l) ; \
		head -n $$(($$lines - 3)) $$patch > $${patch}.chomped ; \
		mv $${patch}.chomped $$patch ; \
	done
	git ls-files --modified --others -z 'debian/patches/*.patch' 'debian/patches/series' | \
		git update-index --add --remove -z --stdin
