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

DEBIAN_DESTINATION=$(shell 'pwd')/debian/tmp/usr

# This is needed for the make install target.
export PREFIX=$(DEBIAN_DESTINATION)


build: build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.

	# If it is necessary to backup the original mp3/libamp/libamp.mak...
ifeq ($(wildcard mp3/libamp/libamp.mak.orig),)
	cp mp3/libamp/libamp.mak mp3/libamp/libamp.mak.orig
endif
	# If the directory makes.orig doesn't exist, then it means that we
	# have to copy the files in the makes directory to the makes.orig
	# directory and modify the files in the directory makes to suit Debian
	# needs.
ifeq ($(wildcard makes.orig),)
	cp -R makes makes.orig
	cp debian/rhide.env makes/rhide.env
	touch makes/*.gpr
	touch mp3/libamp/libamp.gpr
	#cd makes; $(MAKE) force-patch
	cd makes; perl patchenv.pl
	# The patchenv.pl Perl script doesn't touch all the .mak files, so we touch them ourselves.
	touch makes/*.mak
	touch mp3/libamp/libamp.mak
        # The next two commands are temporary until the upstream maintainer
        # improves its build system:
	mkdir rhtvision.tmp
	ln -fs /usr/include/rhtvision rhtvision.tmp/include
endif
	# Little hack to make this thing compile without the supplied libraries
	# in the upstream source...
ifeq ($(wildcard support.orig),)
	mv support support.orig
	ln -fs /usr/include support
endif

	cd makes; $(MAKE) install
	mv debian/tmp/usr/doc/setedit/change.log.gz debian/tmp/usr/doc/setedit/changelog.gz

	touch build-stamp


clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp install-stamp
	# If the directory makes.orig exists, it means that we are using the
	# Debian version of the files in the makes directory, and we need to
	# restore the original makes directory files.
ifneq ($(wildcard makes.orig),)
	rm -fr makes
	mv makes.orig makes
        # The next two commands are temporary until the upstream maintainer
        # improves its build system:
	rm -f rhtvision.tmp/include
	rmdir rhtvision.tmp
endif
	# If it is necessary to restore the original mp3/libamp/libamp.mak...
ifneq ($(wildcard mp3/libamp/libamp.mak.orig),)
	rm -f mp3/libamp/libamp.mak
	mv mp3/libamp/libamp.mak.orig mp3/libamp/libamp.mak
endif
	# Little hack to make this thing compile without the supplied libraries
	# in the upstream source...
ifneq ($(wildcard support.orig),)
	rm -f support
	mv support.orig support
endif
	# FIXME: Upstream maintainer should provide a clean target to avoid this...
	cd doc; rm -f editor.inf editor.txt infeng.inf infeng.txt sdg.inf sdg.txt sdh.exe

	dh_clean


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


install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	#dh_clean -k  Not needed because the needed files already copied there and this would delete them!
	#dh_installdirs  Not needed because upstream source takes care to create the directories!

	# Add here commands to install the package into debian/tmp.
	#$(MAKE) install DESTDIR=`pwd`/debian/tmp  Already installed by build-stamp target!

	touch install-stamp


# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.


# Build architecture-dependent files here.
binary-arch: build install
#	dh_testversion
	dh_testdir
	dh_testroot
	dh_installdocs
#	dh_installexamples
	dh_installmenu
#	dh_installemacsen
#	dh_installinit
#	dh_installcron
# FIXME: It would be nice if I write a small manpage describing the editor...
#	dh_installmanpages
	dh_undocumented e.1 setedit.1
	dh_installchangelogs 
	dh_strip
	dh_compress
	dh_fixperms
	dh_suidregister /usr/bin/e
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
#	dh_makeshlibs  I don't understand the purpose of this program! The dh_shlibdeps seems to do the same but better... I don't know...
	dh_md5sums
	dh_builddeb

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

