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

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: 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
	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

clean-debian:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	dh_clean


debianbackup.tar:
	dh_testdir
# Backup upstream provided regenerated files:
	tar -cf debianbackup.tar --files-from=debian/files_to_backup

	
install: build
	dh_testdir
	dh_testroot
	dh_clean
#   dh_installdirs
# Add here commands to install the package into debian/tmp.
	$(MAKE) install
	mv debian/tmp/usr/share/doc/setedit/change.log.gz debian/tmp/usr/share/doc/setedit/changelog.gz
	dh_link usr/share/man/man1/setedit.1.gz usr/share/man/man1/e.1.gz
# 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/
	mkdir debian/infview/usr/share/info
	cp debian/tmp/usr/share/info/infview.info.gz debian/infview/usr/share/info/infview.info.gz


# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	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
# We have nothing to do by default.

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 clean-debian
