#!/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/-[^-]*$$//')

include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/gnome.mk

# Optimise the linking and only depend on directly required libraries
DEB_CONFIGURE_SCRIPT_ENV += LDFLAGS="$(LDFLAGS) -Wl,-O1 -Wl,--as-needed"
DEB_CONFIGURE_EXTRA_FLAGS := --enable-tests --enable-examples --enable-gtk-doc
DEB_CONFIGURE_EXTRA_FLAGS += --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)
DEB_CONFIGURE_SCRIPT = $(CURDIR)/$(DEB_SRCDIR)/autogen.sh

GIT_URL = git://git.gnome.org/jana
DB2MAN = /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl
XP     = xsltproc -''-nonet -''-param man.charmap.use.subset "0"

jana-ecal-event.1: debian/jana-ecal-event.xml
	$(XP) $(DB2MAN) $<
jana-ecal-store-view.1: debian/jana-ecal-store-view.xml
	$(XP) $(DB2MAN) $<
jana-ecal-time.1: debian/jana-ecal-time.sgml
	$(XP) $(DB2MAN) $<
jana-ecal-time-2.1: debian/jana-ecal-time-2.sgml
	$(XP) $(DB2MAN) $<

build/libjana-test:: jana-ecal-event.1 jana-ecal-store-view.1 \
		     jana-ecal-time.1 jana-ecal-time-2.1

clean::
	rm -rf autom4te.cache
	rm -rf libjana/doc/reference/html libjana-ecal/doc/reference/html
	rm -rf libjana-gtk/doc/reference/html

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
