#!/usr/bin/make -f
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Also some stuff taken from debmake scripts, by Cristopt Lameter.

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

export GNUEDIR=/usr/lib/gnue
export GNUEBINDIR=/usr/bin
export GNUEVARDIR=/var/lib/gnue
export GNUEETCDIR=/etc/gnue
export GNUESHAREDIR=/usr/share/gnue
export GNUEDOCDIR=/usr/share/doc/gnue-common

python	= python
d	= debian/tmp

build: build-stamp
build-stamp:
	dh_testdir
	$(python) setup.py install ##--cfg-file $(GNUEDIR)/site.cfg
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp install-stamp

#	-$(MAKE) -C lib/python clean
#	-$(MAKE) -C lib/python/gnue clean
#	-$(MAKE) -C lib/python/gnue/common clean
	find . -regex ".+\.pyc" -o -regex ".+\.so" -o -regex ".+\.o" \
		| xargs rm -f
	find lib/python -name Makefile -o -name Makefile.pre \
		-o -name Makefile.pre.in \
		-o -name sedscript -o -name config.c \
		| xargs rm -f
	rm -f setup.cfg gnue_sys.py
	rm -rf stage
	dh_clean

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Installing GNUe's lib/python in the $(d) area
	install -d $(d)$(GNUEDIR)/lib/python
	cp -a stage/lib/python/gnue $(d)$(GNUEDIR)/lib/python/gnue

	# ..system control file
	install site.cfg.debian $(d)$(GNUEDIR)/site.cfg

	# Installing translations
	install -d $(d)$(GNUESHAREDIR)
	cp -a translations $(d)$(GNUESHAREDIR)/translations

	# ..images
	cp -a stage/shared/images $(d)$(GNUESHAREDIR)/images

	# ..scripts
##	install -d $(d)$(GNUEBINDIR)/
##	cp -a stage/bin/* $(d)$(GNUEBINDIR)/

	# ..docs
	install -d $(d)$(GNUEDOCDIR)/
	cp -a doc/*.txt $(d)$(GNUEBINDIR)/
##	cp -a doc/*.html $(d)$(GNUEBINDIR)/

	# ..etc
	install -d $(d)$(GNUEETCDIR)/
	install etc/sample.* $(d)$(GNUEETCDIR)/


	# We don't need those relicts from building GNUe
	find $(d)$(GNUEDIR) -name .cvsignore \
		| xargs rm -f

	find $(d)$(GNUEDIR) -name "Makefile.*" \
		-o -regex ".+\.[cho]" -o -regex ".+\.pyc" \
		-o -name setup.cfg -o -name setup.cfg.in \
		| xargs rm -f


	: # Replace all '#!' calls to python with $(python)
	: # and make them executable
##	cd debian && \
##	for i in `find tmp/$(GNUEBINDIR) -type f`; do \
##	  sed '1s,#!.*python[^ ]*\(.*\),#! /usr/bin/$(python)\1,' \
##		$$i > $$i.temp; \
##	  if cmp --quiet $$i $$i.temp; then \
##	    rm -f $$i.temp; \
##	  else \
##	    mv -f $$i.temp $$i; \
##	    chmod 755 $$i; \
##	    echo "fixed interpreter: $$i"; \
##	  fi; \
##	done

	touch install-stamp

# 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
#	dh_testversion
	dh_testdir
	dh_testroot
	##rm -f debian/*.debhelper
	dh_installdocs README* debian/README*  \
	   doc/*.txt \
##	   doc/*.html
#	dh_installmenu
#	dh_installemacsen
#	dh_installpam
#	dh_installinit
#	dh_installcron
#	dh_installmanpages
#	dh_undocumented
#	cat doc/CHANGES.txt doc/HISTORY.txt >ChangeLog
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress -X.zexp
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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