#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk

RELEASE_VERSION=$(shell head -1 debian/changelog | sed -re 's/[^(]+\(([^)]+)\).+/\1/')
RELEASE_PACKAGE=apt-xapian-index

build/apt-xapian-index::
	help2man --section=8 --no-info ./update-apt-xapian-index > update-apt-xapian-index.8

install/apt-xapian-index::
	# Install the executable
	install -o root -g root -m 755 update-apt-xapian-index debian/$(cdbs_curpkg)/usr/sbin
	# Install the plugins
	install -o root -g root -m 755 -d debian/$(cdbs_curpkg)/usr/share/apt-xapian-index/plugins
	install -o root -g root -m 644 plugins/*.py debian/$(cdbs_curpkg)/usr/share/apt-xapian-index/plugins/

clean::
	find . -name "*.pyc" -delete
	rm -f update-apt-xapian-index.8

release: clean
	test -z "`git-ls-files -d -o -m -u -s`" || (echo "There are uncommitted changes"; /bin/false)
	test -z "`git diff --cached`" || (echo "There are uncommitted changes in the index"; /bin/false)
	git archive --format=tar --prefix=$(RELEASE_PACKAGE)-$(RELEASE_VERSION)/ master | gzip -9 > ../$(RELEASE_PACKAGE)_$(RELEASE_VERSION).tar.gz
	dpkg-buildpackage -us -uc -S -I.git
	rm -f ../$(RELEASE_PACKAGE)_$(RELEASE_VERSION)_source.changes
	( cd .. && FAKEROOTKEY= LD_PRELOAD= sbuild -c sid -A --nolog -s $(RELEASE_PACKAGE)_$(RELEASE_VERSION).dsc )
	( cd .. && FAKEROOTKEY= LD_PRELOAD= lintian $(RELEASE_PACKAGE)_$(RELEASE_VERSION)_*.changes )
	git tag -s -m "Tagged version $(RELEASE_VERSION)" v$(RELEASE_VERSION)
