#!/usr/bin/make -f

export DH_COMPAT=2

vpath build debian/pmt/
vpath install debian/pmt/
cfg = --enable-fsstd=yes --mandir=/usr/share/man --enable-new-remember
pwd := $(shell pwd)

SHELL = /bin/sh -e
INSTALL = /usr/bin/install

build:
	dh_testdir
	test -x ./configure && ./configure $(cfg)  || ./autogen.sh $(cfg)
	
	# temp dir
	$(INSTALL) -d debian/pmt
	
	cp libtool debian/pmt/libtool
	sed \
	-e 's/^hardcode_libdir_flag_spec.*$$/hardcode_libdir_flag_spec="-D__LIBTOOL_IS_A_FOOL__ "/' \
	-e '/^archive_cmds="/s/"$$/ \\$$deplibs"/' debian/pmt/libtool > libtool
	
	# the configure script anal, hardcodes $EBIN and $EROOT from the running
	# environment into the Makefile, so we hijack those variables beforehand
	export EBIN=usr/bin; \
	export EROOT=$(pwd)/debian/epplets/usr/share/enlightenment; \
	$(MAKE)
	
	touch debian/pmt/$@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	-$(MAKE) -k clean distclean
	-rm -rf debian/pmt
	dh_clean

install: build
	dh_testdir 
	dh_testroot 
	dh_clean -k
	dh_installdirs 

	# parts shamelessly stolen from the bz2 package

	# bin package, epplets
	$(MAKE) install DESTDIR=$(pwd)/debian/epplets/
	mkdir -p debian/epplets/usr/share/doc/epplets
	test -f COPYING && test -f debian/copyright-info && test -f epplets/Emix-data/Emix.COPYING && echo "Emix:" | cat debian/copyright-info COPYING - epplets/Emix-data/Emix.COPYING > debian/epplets/usr/share/doc/epplets/copyright || touch debian/epplets/usr/share/doc/epplets/copyright
	rm debian/epplets/usr/share/enlightenment/epplet_data/Emix/Emix.COPYING # accounted for above
	mkdir -p debian/epplets/usr/share/man/man1
	test -f epplets/man/epplets.1 && cp -v epplets/man/epplets.1 debian/epplets/usr/share/man/man1/epplets.1 || touch debian/epplets/usr/share/man/man1/epplets.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Areas.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-LoadMeter.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-NetGraph.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Time.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Biff.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Magic.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Pinger.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Toolbox.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Clock.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-MemWatch.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Power.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Pants.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-UrlWatch.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Cpu.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Mixer.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-SD.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Xss.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Disk.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-MoonClock.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-ScreenSave.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/Emix.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Exec.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Mountbox.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-ScreenShoot.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-GtkRc.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Net.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Slides.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Load.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-NetFlame.epplet.1
	dh_link usr/share/man/man1/epplets.1 usr/share/man/man1/E-Sys.epplet.1

	# dev package, libepplet-dev
	$(INSTALL) -d debian/libepplet-dev/usr/lib
	mv -v debian/epplets/usr/lib/libepplet.{so,a} debian/libepplet-dev/usr/lib
	mv -v debian/epplets/usr/include debian/libepplet-dev/usr/include
	mkdir -p debian/libepplet-dev/usr/share/doc/libepplet-dev
	test -f COPYING && test -f debian/copyright-info && cat debian/copyright-info COPYING > debian/libepplet-dev/usr/share/doc/libepplet-dev/copyright || touch debian/libepplet-dev/usr/share/doc/libepplet-dev/copyright

	# lib package, libepplet0
	$(INSTALL) -d debian/libepplet0/usr/lib
	mv -v debian/epplets/usr/lib/libepplet.so.???* debian/libepplet0/usr/lib/
	mv -v debian/epplets/usr/lib/libepplet.so* debian/libepplet0/usr/lib/
	chmod -x debian/libepplet0/usr/lib/*
	mkdir -p debian/libepplet0/usr/share/doc/libepplet0
	test -f COPYING && test -f debian/copyright-info && cat debian/copyright-info COPYING > debian/libepplet0/usr/share/doc/libepplet0/copyright || touch debian/libepplet0/usr/share/doc/libepplet0/copyright
	
	# remove leftovers
	rm -rfv debian/epplets/usr/lib/
	
	touch debian/pmt/$@


binary-arch: build install
	dh_testdir 
	dh_testroot 
	dh_installdocs
	dh_installmenu 
	dh_undocumented
	dh_installchangelogs 
	dh_strip 
	dh_compress 
	dh_fixperms 
	dh_installdeb 
	dh_makeshlibs -V
	# dh_shlibdeps will probably generate a lot of harmless
	# warnings if there is no libepplet0 currently installed
	dh_shlibdeps -ldebian/libepplet0/usr/lib
	dh_gencontrol 
	dh_md5sums 
	dh_builddeb 

binary-indep:

binary: binary-arch

.PHONY: clean binary-indep binary-arch binary
