#!/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 expr `pwd` : '.*-\([0-9.]*\)')
#version_major=$(shell expr `pwd` : '.*-\([0-9]*\).[0-9.]*')

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:
	dh_testversion 2.0.40
	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)
	touch build-stamp


clean: clean-debian
# Upstream doesn't have a clean target yet.
	rm -f linux/obj/*.o
	rm -f linux/librhtv.a
	rm -f linuxso/librhtv.so*
	rm -f linuxso/Makefile
	rm -f linuxso/gkeyli.cc
	rm -f linuxso/instlib
	rm -f linuxso/obj/*.o
	rm -f configure.cache
	rm -f Makefile
	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


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/man usr/share/man/man3 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
	rm $(destdir)/share/doc/$(package)$(version)-dev/examples/.cvsignore
#	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

