#!/usr/bin/make -f

DEB_VERSION = $(shell dpkg-parsechangelog | grep ^Vers | cut -d\  -f2)
VERSION = $(shell echo $(DEB_VERSION) | sed 's,-.*,,' | sed 's,+dfsg.*,,')
DEB_CLI_ABI_VERSION = 1.1
DEB_CLI_API_VERSION = 0.3

override_dh_auto_configure:
	dh_auto_configure -- CSC=/usr/bin/mono-csc --prefix=/usr

override_dh_install:
	perl -pe 's/#DEB_CLI_ABI_VERSION#/$(DEB_CLI_ABI_VERSION)/' -i \
	  $(CURDIR)/debian/tmp/usr/lib/pkgconfig/webkit-sharp-1.0.pc
	dh_install

override_dh_makeclilibs:
	dh_makeclilibs -i -m $(DEB_CLI_API_VERSION)

%:
	dh $@ --with autoreconf,cli

BASE_NAME = webkit-sharp
TARBALL_NAME = $(BASE_NAME).tar.gz
TARBALL_VERSION = $(shell ls $(BASE_NAME)/$(BASE_NAME)-*.tar.gz | egrep -o "([[:digit:]]+\.)+[[:digit:]]")
$(TARBALL_NAME):
	svn export http://anonsvn.mono-project.com/source/tags/webkit-sharp/$(DEB_CLI_API_VERSION) $(BASE_NAME)
	tar -czf $(TARBALL_NAME) $(BASE_NAME)

unpack-upstream-source: $(TARBALL_NAME)
	tar -xzvf $(TARBALL_NAME)
	rm $(TARBALL_NAME)

$(BASE_NAME)/configure: unpack-upstream-source
	cd $(BASE_NAME) && autoreconf -i -v

build-tarball: $(BASE_NAME)/configure
	cd $(BASE_NAME) && ./configure && make dist

get-orig-source: build-tarball
	mkdir -p ../tarballs
	mv $(BASE_NAME)/$(BASE_NAME)-$(TARBALL_VERSION).tar.gz \
	   ../tarballs/$(BASE_NAME)_$(TARBALL_VERSION).orig.tar.gz
	rm -rf $(BASE_NAME)

.PHONY: get-orig-source build-tarball $(BASE_NAME)/configure unpack-upstream-source
