#!/usr/bin/make -f
%:
	dh $@

PACKAGE=geneweb

WAY=$(shell if [ -f "/usr/bin/ocamlc.opt" ]; then echo "opt"; \
else echo "out"; \
fi)

# Maintainer test : uncomment the next line to test WAY=out
#WAY=out

ifeq ($(WAY),out)
override_dh_strip:
	# Don't strip ocaml bytecode executables
endif

override_dh_installdeb:
	# Use of the dh-buildinfo package: see http://people.debian.org/~dirson/buildinfo/
	dh_buildinfo
	dh_installdeb
	
override_dh_auto_clean:

override_dh_auto_install:

override_dh_auto_configure:
	chmod a+x ./configure
	./configure

override_dh_auto_build:
	# Move the proper makefile into place	
	cp -f `pwd`/tools/Makefile.debian.$(WAY) `pwd`/tools/Makefile.debian
	chmod a+x tools/*.sh
	chmod a+x contrib/gwbase/etc/*.sh
	$(MAKE) $(WAY)
	$(MAKE) distrib
	cp `pwd`/distribution/gw/images/favicon_gwd.png `pwd`/distribution/geneweb.png
	cp `pwd`/distribution/gw/images/favicon_gwsetup.png `pwd`/distribution/gwsetup.png
	mv `pwd`/distribution/gw/gui `pwd`/distribution/gw/geneweb-gui
	mv `pwd`/distribution/CHANGES.txt `pwd`/distribution/changelog
	cp `pwd`/distribution/gw/a.gwf `pwd`/distribution/default.gwf
	cp `pwd`/distribution/gw/connex `pwd`/distribution/geneweb-connex

override_dh_clean:
	rm -rf debian/iso-codes
	rm -rf debian/pobuild
	rm -f debian/geneweb.templates.tmp
	rm -f debian/geneweb.templates
	debconf-updatepo
	# Add here commands to clean up after the build process.
	[ ! -f tools/Makefile.inc ] || [ ! -f Makefile ] || $(MAKE) clean
	# Clean out cruft left by former builds
	rm -f compilation.ml
	dh_clean

override_dh_install:
	dh_install
	# The CGI script
	chmod 755 `pwd`/debian/gwtp/usr/lib/cgi-bin/gwtp/gwtp.cgi
	# The wrappers
	chmod 755 `pwd`/debian/gwsetup/usr/lib/geneweb/gwsetup.wrapper

override_dh_installdebconf:
	# Grab ISO 639-2 language code translations
	chmod u+x debian/get-iso-codes
	debian/get-iso-codes
	# Build templates
	chmod u+x debian/mktemplates
	debian/mktemplates
	dh_installdebconf
