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

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

# Compile the beast!:
build: build-stamp
build-stamp: debianbackup.tar
	dh_testdir
	./configure --prefix=$(shell pwd)/debian/tmp/usr --fhs --no-comp-exe
	$(MAKE)
	touch build-stamp


# Clean everything as if nothing happened :) :
clean: clean-debian debianbackup.tar
# Heh, for cleaning we need to run the configure script in order to create the makefile that cleans! :-)))
	./configure
	$(MAKE) clean
# Restore upstream provided regenerated files:
	test -e debianbackup.tar && tar -xf debianbackup.tar
	rm -f debianbackup.tar
# FIXME: ask upstream about adding the next files to his clean target:
	rm -f internac/de_iso.po internac/fix.exe internac/es_iso.po \
		internac/gr.po internac/po_list internac/potfiles.po internac/de.mo \
		internac/de_iso.mo internac/es.mo internac/es_iso.mo
# Don't delete this files (they are on the tarball but not on CVS):
#		doc/Makefile internac/Makefile

# Use the following target when you just want for example to rebuild the
# package without recompiling the sources:
clean-debian:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	dh_clean


# Let's backup modified files to restore them later!:
debianbackup.tar:
	dh_testdir
# Backup upstream provided regenerated files:
	tar -cf debianbackup.tar --files-from=debian/files_to_backup

	
# Copy needed files to the temporary directories for the packages:
install: build
	dh_testdir
	dh_testroot
	dh_clean
#   dh_installdirs
# Add here commands to install the package into debian/tmp.
	$(MAKE) install
# We need to move files for other packages than the first one in the control file:
	dh_movefiles -p infview usr/bin/infview usr/share/doc/infview/ usr/share/infview/ usr/share/man/man1/infview.1.gz
# I don't know why dh_movefiles doesn't remove the directories I requested for moving to the infview package, so I move them by hand (anyway I don't know why that command exists in the first place!):
	rm -rf debian/tmp/usr/share/doc/infview/ debian/tmp/usr/share/infview/
	mv debian/tmp/usr/share/doc/setedit/change.log.gz \
		debian/tmp/usr/share/doc/setedit/changelog.gz
	cp debian/tmp/usr/share/doc/setedit/changelog.gz \
		debian/infview/usr/share/doc/infview/
	dh_link usr/share/man/man1/setedit.1.gz usr/share/man/man1/e.1.gz
	mkdir debian/infview/usr/share/info
	cp debian/tmp/usr/share/info/infview.info.gz debian/infview/usr/share/info/infview.info.gz
	cp debian/README.debian \
		debian/infview/usr/share/doc/infview/README.Debian


# Build the packages for a specific architecture:
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdebconf
	dh_installdocs
#	dh_installexamples
	dh_installmenu
#	dh_installemacsen
#	dh_installinit
#	dh_installcron
#	dh_installmanpages
#	dh_undocumented e.1 setedit.1
	dh_installchangelogs 
	dh_strip
	dh_compress
	dh_fixperms
	chmod 4755 debian/tmp/usr/bin/setedit
	chmod 4755 debian/infview/usr/bin/infview
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol -p setedit
	dh_gencontrol -p infview -- -v$$(cat infview/version.txt)-$$(cat version.txt)-$$(head -n1 debian/changelog | sed 's/.* (.*-//' | sed 's/) .*//')
#	dh_makeshlibs  This is for libraries.
	dh_md5sums
	dh_builddeb


# Build architecture-independent files here.
binary-indep: build install
#This package doesn't have architecture-independent files for the moment...

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

# Build all the packages:
binary: binary-indep binary-arch

.PHONY: build clean binary-indep binary-arch binary clean-debian

