#!/usr/bin/make -f

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

VERSION=$(shell debian/vercheck)
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/
	# install the dbus stuff
	install -o root -g root -m 755 update-apt-xapian-index-dbus debian/$(cdbs_curpkg)/usr/share/apt-xapian-index
	install -o root -g root -m 644 data/org.debian.AptXapianIndex.conf debian/$(cdbs_curpkg)/etc/dbus-1/system.d
	install -o root -g root -m 644 data/org.debian.AptXapianIndex.service debian/$(cdbs_curpkg)/usr/share/dbus-1/system-services/org.debian.AptXapianIndex.service
	install -o root -g root -m 644 data/org.debian.aptxapianindex.policy debian/$(cdbs_curpkg)/usr/share/polkit-1/actions

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

vercheck:
	debian/vercheck > /dev/null

debsrc: vercheck
	fakeroot debian/rules clean
	test -z "`git ls-files -d -o -m -u -s`" || (echo "There are uncommitted changes" >&2; /bin/false)
	test -z "`git diff --cached`" || (echo "There are uncommitted changes in the index" >&2; /bin/false)
	git archive --format=tar --prefix=$(RELEASE_PACKAGE)-$(VERSION)/ master | gzip -9 > ../$(RELEASE_PACKAGE)_$(VERSION).tar.gz
	debuild -S -us -uc -rfakeroot -i.git -I.git
	rm -f ../$(RELEASE_PACKAGE)_$(VERSION)_source.changes

#release: clean
#	( 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)
