#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=3
VERS=1.0.0
DVDVERS=vdr-1.0.0pre5-nav7

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	mkdir build-tree
	cd build-tree ; tar zxvf ../upstream/vdr-$(VERS).tgz; mv vdr-$(VERS)/* .
	cp upstream/* build-tree -a
#	cd build-tree ; zcat ../patches/* | patch -p1
	cd build-tree ; cat ../debian/patches/* | patch -p1
	
	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	cd build-tree; $(MAKE) DVBDIR=/usr DVDDIR=/usr VFAT=1 DVD=1
	cd build-tree; cp vdr vdr-kbd
	cd build-tree; make clean
	cd build-tree; $(MAKE) DVBDIR=/usr DVDDIR=/usr VFAT=1 REMOTE=NONE DVD=1
	cd build-tree; cp vdr vdr-daemon
	cd build-tree; make clean
	cd build-tree; $(MAKE) DVBDIR=/usr DVDDIR=/usr VFAT=1 REMOTE=LIRC DVD=1
	cd build-tree; cp vdr vdr-lirc
	cd build-tree; make clean
	cd build-tree; $(MAKE) DVBDIR=/usr DVDDIR=/usr VFAT=1 REMOTE=RCU DVD=1
	cd build-tree; cp vdr vdr-rcu

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	rm -rf build-tree

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs -a usr/share/doc

	# Add here commands to install the package into debian/vdr.
	cd build-tree; install -m 755 $(CURDIR)/debian/vdr-message vdr-lirc vdr-kbd vdr-rcu vdr-daemon $(CURDIR)/debian/vdr/usr/bin/
	cd build-tree; cp -a epg2html.pl svdrpsend.pl $(CURDIR)/debian/vdr/usr/share/vdr/
	dh_installman $(CURDIR)/debian/vdr-message.1 -p vdr
	cd build-tree; for x in vdr-lirc vdr-kbd vdr-rcu vdr-daemon ; do mkdir -p $(CURDIR)/debian/$$x/usr/share/doc; ln -s vdr-message.1.gz $(CURDIR)/debian/vdr/usr/share/man/man1/$$x.1.gz; ln -s vdr $(CURDIR)/debian/$$x/usr/share/doc/$$x; done
	dh_movefiles --sourcedir=debian/vdr

# 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_testdir
	dh_testroot
	dh_installdocs
	dh_installdebconf -pvdr-daemon
	dh_installexamples build-tree/*.conf* -pvdr
	dh_installman $(CURDIR)/build-tree/vdr.1 $(CURDIR)/build-tree/vdr.5 -p vdr
	dh_installmenu
	dh_installchangelogs build-tree/HISTORY -pvdr
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
