#!/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.
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independant
# package.

version=$(shell cat version.txt)
package=rhtvision
destdir=debian/tmp/usr

# 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
# Rename debian/rhtvision.postinst file if it exists:
ifneq ($(wildcard debian/rhtvision.postinst),)
	mv debian/rhtvision.postinst debian/rhtvision$(version).postinst
endif
	./configure --prefix=$(destdir) --fhs
	$(MAKE) CPPFLAGS="-D_REENTRANT"   
	touch build-stamp


clean: clean-debian debianbackup.tar
# If we don't configure there is no guarantee that we have a Makefile:
	./configure --prefix=$(destdir) --fhs
	$(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 3 files to his clean target:
	rm -f linuxso/gkeyli.cc linuxso/instlib configure.cache
	rm -f build-stamp

clean-debian:
	dh_testdir
	dh_testroot
# Rename rhtvision$(version).postinst file if it exists:
ifneq ($(wildcard debian/rhtvision$(version).postinst),)
	mv debian/rhtvision$(version).postinst debian/rhtvision.postinst
endif
	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 -p $(package)$(version)-dev usr/lib usr/include/$(package) usr/share/doc usr/share/doc/$(package)$(version)-dev usr/share/doc/$(package)$(version)-dev/examples
	dh_installdirs -p $(package)$(version) usr/lib usr/share usr/share/doc/$(package)$(version) usr/share/doc/$(package)$(version)/eterm
	$(MAKE) install
# We need to move files for other packages than the first one in the control file:
	dh_movefiles -p $(package)$(version) usr/lib/librhtv.so.$(version)


binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs -p $(package)$(version) extra/eterm/ borland.txt copying copying.rh readme.txt
	dh_installdocs -p $(package)$(version)-dev examples/ borland.txt copying copying.rh readme.txt
	find $(destdir) -iname '.cvsignore' -exec rm '{}' \;
#	dh_installexamples
#	dh_installmenu
#	dh_installemacsen
#	dh_installinit
#	dh_installcron
#	dh_installmanpages
#	dh_undocumented -p $(package)$(version) rhtvision.3
	dh_installchangelogs change.log
	dh_strip
	dh_compress
	dh_fixperms
#	dh_suidregister
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_makeshlibs -m$(version)
	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

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

