#!/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.

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

PACKAGE=aolserver
DOCDIR=aolserver-doc
PGDIR=aolserver-postgres

build: build-stamp
build-stamp:
	dh_testdir
	bash -n debian/aolserver.postinst
	bash -n debian/aolserver-doc.postinst
	bash -n debian/aolserver-postgres.postinst
	bash -n debian/aolserver.postrm
	bash -n debian/aolserver-doc.postrm
	bash -n debian/aolserver-postgres.postrm
	bash -n debian/aolserver.preinst
	bash -n debian/aolserver.prerm
	bash -n debian/aolserver-doc.prerm
	bash -n debian/aolserver-postgres.postrm
	perl -c debian/aolsrvconfig
	perl -c debian/aolpgconfig
	perl -c debian/aoladddb
	$(MAKE) install	
	
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp install-stamp
	-rm -r `pwd`/root

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean

	dh_clean
	

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

	# Add here commands to install the package into debian/tmp.
	cp -ar /tmp/aolserver/* `pwd`/debian/tmp/usr/lib/aolserver
	cp `pwd`/debian/init.example `pwd`/debian/tmp/usr/lib/aolserver/bin/init
	cp `pwd`/debian/table.example `pwd`/debian/$(PGDIR)/usr/share/doc/aolserver-postgres/examples
	cp `pwd`/include/* `pwd`/debian/tmp/usr/include/aolserver
	rm `pwd`/debian/tmp/usr/include/aolserver/Makefile.*
	rm `pwd`/debian/tmp/usr/include/aolserver/tcl*
	mv `pwd`/debian/tmp/usr/lib/aolserver/bin/nspostgres.so `pwd`/debian/$(PGDIR)/usr/lib/aolserver/bin
	rm -r `pwd`/debian/tmp/usr/lib/aolserver/log
	cp `pwd`/debian/aolsrvconfig `pwd`/debian/tmp/usr/sbin
	chmod +x `pwd`/debian/tmp/usr/sbin/aolsrvconfig
	cp `pwd`/debian/aolpgconfig `pwd`/debian/$(PGDIR)/usr/sbin
	chmod +x `pwd`/debian/$(PGDIR)/usr/sbin/aolpgconfig
	cp `pwd`/debian/aoladddb `pwd`/debian/$(PGDIR)/usr/sbin
	chmod +x `pwd`/debian/$(PGDIR)/usr/sbin/aoladddb

	# Patch up the nsd.tcl file for Debian use
	cp `pwd`/debian/nsd.tcl `pwd`/debian/tmp/usr/share/doc/aolserver/examples
	cp `pwd`/debian/cron.conf `pwd`/debian/tmp/usr/share/doc/aolserver/examples/cron.conf
	cp `pwd`/debian/cron.daily `pwd`/debian/tmp/etc/cron.daily/aolserver
	chmod +x `pwd`/debian/tmp/etc/cron.daily/aolserver
	
	# Move the documentation
	cp `pwd`/README.txt `pwd`/debian/tmp/usr/share/doc/aolserver/README
	cp `pwd`/debian/aolsrvconfig.8 `pwd`/debian/tmp/usr/share/man/man8
	cp `pwd`/debian/aolpgconfig.8 `pwd`/debian/$(PGDIR)/usr/share/man/man8
	cp `pwd`/debian/aoladddb.8 `pwd`/debian/$(PGDIR)/usr/share/man/man8
	cp `pwd`/doc/nspostgres.txt `pwd`/debian/$(PGDIR)/usr/share/doc/aolserver-postgres/README
	cp `pwd`/debian/testdb.adp `pwd`/debian/$(PGDIR)/usr/share/doc/aolserver-postgres/examples/testdb.adp

	# Move the examples
	cp -ar `pwd`/nsexample `pwd`/debian/tmp/usr/share/doc/aolserver/examples/c
	cp `pwd`/debian/intro.html `pwd`/debian/tmp/usr/share/doc/aolserver/examples
	cp `pwd`/debian/app3.tcl `pwd`/debian/tmp/usr/lib/aolserver/servers/server1/modules/tcl

	# Install the icons
	uudecode `pwd`/debian/aolserver.png.uu --output=`pwd`/debian/tmp/usr/share/aolserver/icons/aolserver.png
	uudecode `pwd`/debian/openlogo-50.jpg.uu --output=`pwd`/debian/tmp/usr/share/aolserver/icons/openlogo-50.jpg

	touch install-stamp

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.
	cp -ar `pwd`/doc/admin `pwd`/debian/$(DOCDIR)/usr/share/doc/aolserver-doc/html
	cp -ar `pwd`/doc/cdev `pwd`/debian/$(DOCDIR)/usr/share/doc/aolserver-doc/html
	cp -ar `pwd`/doc/tcldev `pwd`/debian/$(DOCDIR)/usr/share/doc/aolserver-doc/html
	cp -ar `pwd`/doc/driver `pwd`/debian/$(DOCDIR)/usr/share/doc/aolserver-doc/html
	cp `pwd`/doc/*.txt `pwd`/debian/$(DOCDIR)/usr/share/doc/aolserver-doc
	cp `pwd`/doc/index.html `pwd`/debian/$(DOCDIR)/usr/share/doc/aolserver-doc/html/index.html
	cp `pwd`/debian/aolserver-doc.dhelp `pwd`/debian/$(DOCDIR)/usr/share/doc/aolserver-doc/html/.dhelp
	cp `pwd`/debian/aolserver-doc.dwww-index `pwd`/debian/$(DOCDIR)/usr/share/doc/aolserver-doc/html/.dwww-index

# Build architecture-dependent files here.
binary-arch: build install
#	dh_testversion
	dh_testdir
	dh_testroot
	dh_installdocs
#	dh_installexamples
#	dh_installmenu
#	dh_installemacsen
#	dh_installinit
#	dh_installcron
#	dh_installmanpages
#	dh_undocumented
	dh_installchangelogs 
	dh_strip
	dh_compress
	dh_fixperms
	dh_suidregister
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
#	dh_makeshlibs
	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
