#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

PACKAGE=revelation

DB2MAN=/usr/share/xml/docbook/stylesheet/nwalsh/manpages/docbook.xsl
XP=xsltproc --nonet

CFLAGS = -Wall -g

SCHEMAS=$(CURDIR)/debian/revelation/usr/share/gconf/schemas

PREFIX=/usr

PYVERS=$(shell pyversions -vr debian/control)

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

build-python%-stamp:
	dh_testdir

	PYTHON=/usr/bin/python$* ./configure \
		--with-python-include=/usr/include/python$* \
		--prefix=$(PREFIX) --sysconfdir=/etc \
		--libexecdir=/usr/share/revelation/libexec \
		--disable-mime-update --disable-desktop-update --disable-schemas-install

	$(MAKE) clean
	$(MAKE)
	$(MAKE) install DESTDIR=$(CURDIR)/debian/revelation

	touch $@


build-stamp: patch-stamp
	dh_testdir
	dh_prep
	autoreconf -i
	for py in $(PYVERS); do \
	    $(MAKE) -f debian/rules build-python$$py-stamp; \
	done
	touch $@

patch-stamp:
	touch patch-stamp

build: build-arch build-indep

build-arch: build-stamp
build-indep: build-stamp

clean: do-clean unpatch
	rm -f config.guess config.sub aclocal.m4 compile configure
	find . -name Makefile.in -exec rm {} \;

do-clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp build-python*-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean 
	rm -rf build tmp revelation.1

unpatch:
	rm -rf patch-stamp debian/patched

revelation.1:
	$(XP) $(DB2MAN) debian/revelation.1.xml

install: build
	dh_testdir
	dh_testroot
	dh_installdirs

	mkdir -p $(CURDIR)/tmp

	convert $(CURDIR)/data/icons/32x32/revelation.png \
		-colors 24 -resize 32x32 \
		$(CURDIR)/tmp/revelation.xpm

	install -D -o root -g root -m 644 \
		$(CURDIR)/tmp/revelation.xpm \
		$(CURDIR)/debian/revelation/$(PREFIX)/share/pixmaps/revelation.xpm

	for py in $(PYVERS); do \
	    chmod 755 $(CURDIR)/debian/revelation/$(PREFIX)/lib/python$$py/dist-packages/revelation/bundle/PBKDFv2.py; \
	done

	# install .desktop by hand, hides lintian dh_desktop-is-deprecated
	install -D -o root -g root -m 644 $(CURDIR)/data/mime/revelation.desktop $(CURDIR)/debian/usr/share/applications/revelation.desktop

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install revelation.1
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installmenu
	dh_installmime
	dh_installman revelation.1
	dh_link
	dh_strip
	dh_makeshlibs
	dh_shlibdeps
	dh_compress
	dh_fixperms
	dh_python2
	dh_gconf
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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