#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.
#
# This version is for a multibinary package. It also allows you to build any
# of the binary packages independantly, via binary-<package> targets.

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

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

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

# Other Stuff
pwd:=$(shell pwd)
cfg=--prefix=/usr --enable-upgrade=no  --enable-fsstd=yes --mandir=/usr/share/man 
INSTALL=/usr/bin/install -o root -g root

build: build-stamp
build-stamp:
	
	dh_testdir

	test -x autogen.sh && ./autogen.sh $(cfg) || ./configure $(cfg)
	
	$(MAKE)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

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

	rm -rf build-stamp
	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install DESTDIR=$(pwd)/debian/enlightenment-data

	# The lucida font doesn't exist on Debian boxes or something *shrug*
	# Changed to "fixed" in all themes
	find debian/enlightenment-data/usr/share/enlightenment/themes/ -type f \
		-name '*.cfg'  -exec grep -l lucida  {} \; | \
		xargs perl -i -pwe 's#".*?lucida.*?"#"fixed"#'

	# Move files to sub-packages and remove empty directories
	dh_movefiles --sourcedir=debian/enlightenment-data
	cd debian/enlightenment-data/usr; rm -rf bin \
		share/enlightenment/themes/BlueSteel \
		share/enlightenment/themes/ShinyMetal \
		share/enlightenment/themes/Ganymede \
		debian/enlightenment-data/usr/share/man

	# Populate /usr/share/doc/enlightenment with interesting looking stuff
	$(INSTALL) -m 644 ABOUT-NLS INSTALL README AUTHORS NEWS \
		debian/enlightenment/usr/share/doc/enlightenment/
	$(INSTALL) -m 644 src/ChangeLog \
		debian/enlightenment/usr/share/doc/enlightenment/changelog-src
	$(INSTALL) -m 755  sample-scripts/*.{pl,sh} \
		debian/enlightenment/usr/share/doc/enlightenment/examples
	
	# Add stub to menus.cfg for Debian menus
	perl -pw debian/menumangler.pl src/themes/configs/menus.cfg > \
		debian/enlightenment-data/usr/share/enlightenment/config/menus.cfg

	# Something is stuffed with EBIN in the install script, so hardcode it
	perl -pi -lwe 's/^EBIN=.*/EBIN=\/usr\/bin/' \
		debian/enlightenment/usr/bin/enlightenment.install

	# *sigh*
	-rm debian/enlightenment-theme-ganymede/usr/share/enlightenment/themes/Ganymede/dialogs/#dialogs.cfg#
	
	# man page
	cp -v debian/e-utils.1 debian/enlightenment/usr/share/man/man1/
	
# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
binary-common:
	# Need this version of debhelper for DH_OPTIONS to work.
	dh_testversion 2.0
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installmenu
	dh_installchangelogs
	dh_link
	dh_compress
	dh_strip
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
binary-indep: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

# Any other binary targets build just one binary package at a time.
binary-%: build install
	make -f debian/rules binary-common DH_OPTIONS=-p$*

manpage:
	pod2man debian/e-utils.pod \
	--center="Debian GNU/Linux" \
	--release="woody" > debian/e-utils.1
	
binary: install binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
