#!/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.
# Some lines taken from debmake, by Cristoph Lameter.

# Notes (Jose Kahan):
# When building a new version, update the value of the SOURCE: field to
# point to the latest tar. It should include the version number and say
# orig too.
#
# In order to compile the GTK version, add the following line to the
# call for configure
#                  --with-gtk \
#
# To launch the build, make a directory called amaya-v.
# Copy the debian directory there.
# Change the SOURCE: field as stated above
# The rules file should be +x
# Make a symlink to the tar file saying amaya-src-vv-orig.tar.gz
# cd to the amaya-v directory
# type dpkg-buildpackage -b
# The .deb file will be put on the top directory.
# Ref: http://www.infodrom.org/Debian/doc/maint/Maintenance-pkgbuild.html

#export DH_VERBOSE=1

SOURCE:=amaya-src-8.1a-orig.tar.gz

build: build-stamp
build-stamp: patch-stamp
	dh_testdir

	-mkdir Amaya/BUILD
	cd Amaya && \
		cp /usr/share/libtool/config.sub /usr/share/libtool/config.guess . \
		&& autoconf && autoheader
	cd Amaya/BUILD && ../configure \
		 --enable-redland \
		 --enable-bookmarks \
		 --with-gtk \
		 --prefix=/usr --datadir=/usr/lib \
		`dpkg --print-architecture`-linux
	# Make the unix.fonts.deb the default filez
	cp Amaya/config/fonts.unix Amaya/config/fonts.unix.other
	cp Amaya/config/fonts.unix.deb Amaya/config/fonts.unix
	# Add here commands to compile the package.
	cd Amaya/BUILD && make CFLAGS="-O2 -Wall" all amaya

	touch build-stamp

patch: patch-stamp
patch-stamp: source-stamp
	if [ -d debian/patches ]; then \
	for i in debian/patches/*; do \
		patch -p0 -s <$$i; \
	done; fi

	touch patch-stamp

source: source-stamp
source-stamp:
	tar zxf $(SOURCE)
	cd libwww && libtoolize --force --copy
	cp /usr/share/libtool/config.guess /usr/share/libtool/config.sub Amaya
	touch source-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f *-stamp

	-rm -rf Amaya libwww

	dh_clean

# Build architecture-independent files here.
binary-indep: build
	dh_testdir

# Build architecture-dependent files here.
binary-arch: build
#	dh_testversion
	dh_testdir
	dh_testroot
	dh_clean -k -a
	dh_installdirs -a

	# Install
	cd Amaya/BUILD && $(MAKE) install prefix=`pwd`/../../debian/tmp/usr datadir=`pwd`/../../debian/tmp/usr/lib

	# Doesn't quite work, so we move some stuff around
	mv debian/tmp/usr/Amaya debian/tmp/usr/lib
	-rm debian/tmp/usr/bin/amaya
	ln -s ../lib/Amaya/applis/bin/amaya debian/tmp/usr/bin
	install -m 0644 Amaya/amaya/AmayaPage.html \
		debian/tmp/usr/lib/Amaya/amaya
	install -m 0644 debian/amaya.1 debian/tmp/usr/share/man/man1
	cp Amaya/amaya/*.{en,fr,TRA,STR,PRS,trans,gif,png,conf} \
		debian/tmp/usr/lib/Amaya/amaya
	cp Amaya/annotlib/*.{en,TRA,STR,PRS,gif,png} \
		debian/tmp/usr/lib/Amaya/annotlib
	chmod -R o+w debian/tmp/usr/lib/Amaya

	dh_installdocs -a Amaya/doc/html/ Amaya/doc/images/
	ln -s ../../../share/doc/amaya/html debian/tmp/usr/lib/Amaya/doc/html
	ln -s ../../../share/doc/amaya/images debian/tmp/usr/lib/Amaya/doc/images
	dh_installexamples -a
	dh_installmenu -a
#	dh_installmanpages
#	dh_undocumented
	dh_installchangelogs -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
#	dh_makeshlibs
	dh_md5sums -a
	dh_builddeb -a

#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
