#!/usr/bin/make -f
# -*- makefile -*-
# 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

# Forrest is installed into this location
export FORREST_DIR=/usr/share/forrest


configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	# Add here commands to compile the package.
	#$(MAKE)
	#/usr/bin/docbook-to-man debian/forrest.sgml > forrest.1
	/usr/bin/xsltproc -o debian/forrest.1 --nonet /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl debian/forrest.xml
	/usr/bin/xsltproc -o debian/forrestbot.1 --nonet /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl debian/forrestbot.xml

	touch build-stamp

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

	# Add here commands to clean up after the build process.
	#-$(MAKE) clean
	sh ./build.sh clean
	rm -f debian/forrest.1
	rm -f debian/forrestbot.1

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/forrest.
	#$(MAKE) install DESTDIR=$(CURDIR)/debian/forrest
	sh ./build.sh -Ddist-shbat.dir=$(CURDIR)/debian/forrest/$(FORREST_DIR)
	sed -e 's#@FORREST_DIR@#$(FORREST_DIR)#' $(CURDIR)/debian/forrest/$(FORREST_DIR)/bin/forrest >	$(CURDIR)/debian/forrest/usr/bin/forrest
	chmod 755 $(CURDIR)/debian/forrest/usr/bin/forrest
	sed -e 's#@FORREST_DIR@#$(FORREST_DIR)#' $(CURDIR)/debian/forrest/$(FORREST_DIR)/bin/forrestbot > $(CURDIR)/debian/forrest/usr/bin/forrestbot
	chmod 755 $(CURDIR)/debian/forrest/usr/bin/forrestbot

	# remove windows batch files
	rm -f $(CURDIR)/debian/forrest/$(FORREST_DIR)/bin/*.bat

	# make bundled scripts executable
	chmod 755 $(CURDIR)/debian/forrest/$(FORREST_DIR)/forrestbot/scripts/*
	chmod 644 $(CURDIR)/debian/forrest/$(FORREST_DIR)/forrestbot/scripts/README.txt
	chmod 644 $(CURDIR)/debian/forrest/$(FORREST_DIR)/forrestbot/scripts/local-vars-cocoondev.org
	chmod 644 $(CURDIR)/debian/forrest/$(FORREST_DIR)/forrestbot/scripts/local-vars-sample

	# remove legal directory, all contents is specified in the copyright file
	rm -rf $(CURDIR)/debian/forrest/$(FORREST_DIR)/legal
	
# 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_installchangelogs 
	dh_installdocs
	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman debian/forrest.1 debian/forrestbot.1
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	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
