#!/usr/bin/make -f

# 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

# This is the debhelper compatability version to use.
export DH_COMPAT=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

#
# Modified to be a prototype for debmake by Christoph Lameter <clameter@debian.org>
#
# Modified to work for fte by Riku Voipio <riku.voipio@iki.fi>
#
# Modified to work for fte by Zdenek Kabelac <kabi@debian.org>


INST=install -p
DEBSTD=debstd
package=fte
docs=$(package)-docs
console=$(package)-console
terminal=$(package)-terminal
xwindow=$(package)-xwindow

allpackages=\
	debian/tmp\
	debian/$(docs)\
        debian/$(console)\
        debian/$(terminal)\
        debian/$(xwindow)

build:
	@dh_testdir
	$(MAKE) -C src -j 2 -f fte-unix.mak
	touch build

cleanB:
	@dh_testdir
	@dh_clean

clean: cleanB
	@dh_testdir
	@rm -f build
	@$(MAKE) -C src -f fte-unix.mak clean

binary-indep:
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch: cleanB checkroot checkscripts build
	@dh_testdir
	@echo ":: Preparing packages"
#	@$(INST) -d debian
#	@cd debian; install -d `cat *.dirs`
	dh_testdir
	dh_testroot
	dh_installdirs

	@echo "/etc/fte/system.fterc" >debian/conffiles
##	find config -type f | sed -e 's/^/\/etc\/fte\//g' >>debian/conffiles
	@$(INST) -s src/cfte debian/tmp/usr/bin/
	@cd config; ../src/cfte main.fte ../debian/tmp/etc/fte/system.fterc

	@tar cf debian/$(docs)/usr/share/doc/fte/config-example.tar config
	@$(INST) -s -m 4755 src/vfte debian/$(console)/usr/bin/
	@$(INST) -s src/sfte debian/$(terminal)/usr/bin/
	@$(INST) -s src/xfte debian/$(xwindow)/usr/X11R6/bin/
	@$(INST) -m 755 debian/fte debian/tmp/usr/bin/fte
	@ln -s ../../../share/man/man1/fte.1.gz debian/$(xwindow)/usr/X11R6/man/man1/xfte.1.gz
	@ln -s fte.1.gz debian/$(console)/usr/share/man/man1/vfte.1.gz
	@ln -s fte.1.gz debian/$(terminal)/usr/share/man/man1/sfte.1.gz
	@cp -a debian/fte-console.lintian debian/$(console)/usr/share/lintian/overrides/fte-console

#	@cp -a debian/cfte.1 debian/$(docs)/usr/share/man/man1
#	@find doc -type f | grep -v INDEX >debian/$(docs).docs
# Must have debmake installed for this to work. Otherwise please copy
# /usr/bin/debstd into the debian directory and change debstd to debian/debstd
#	@chown -R root.root $(allpackages)
#	@chmod -R go=rX $(allpackages)
#	@$(DEBSTD) -m BUGS HISTORY README TODO

	dh_installdocs BUGS HISTORY README TODO

	dh_installexamples
	dh_installchangelogs

# this way we are saving few inodes and making it more user friendly
	@rm -rf debian/$(docs)/usr/share/doc/$(docs)
	@rm -rf debian/$(console)/usr/share/doc/$(console)
	@rm -rf debian/$(terminal)/usr/share/doc/$(terminal)
	@rm -rf debian/$(xwindow)/usr/share/doc/$(xwindow)
	@ln -s fte debian/$(docs)/usr/share/doc/$(docs)
	@ln -s fte debian/$(console)/usr/share/doc/$(console)
	@ln -s fte debian/$(terminal)/usr/share/doc/$(terminal)
	@ln -s fte debian/$(xwindow)/usr/share/doc/$(xwindow)

	@cp -a doc/*.html debian/$(docs)/usr/share/doc/$(docs)

	dh_installmenu
	dh_installcron
	dh_installmanpages -pfte
	dh_movefiles
	dh_strip
	dh_compress
	dh_fixperms
#obsoleted	dh_suidregister
	dh_shlibdeps
	dh_gencontrol
	dh_makeshlibs
	dh_installdeb
	dh_md5sums
	dh_builddeb -v

#	dpkg-shlibdeps debian/tmp/usr/X11R6/bin/xfte -drecommends debian/tmp/usr/bin/vfte debian/tmp/usr/bin/cfte
#	@dpkg-gencontrol -pfte
#	dpkg --build debian/tmp ..

checkscripts:
	@echo ":: Checking scripts"
	@bash -n debian/postrm
	@bash -n debian/postinst

# Below here is fairly generic really

binary: binary-indep binary-arch

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

checkroot:
	@dh_testdir
	@echo ":: Checking ROOT user"
	@test root = "`whoami`"

.PHONY: binary binary-indep binary-arch clean checkroot
