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

# C build environmet neeed for perl
export LC_ALL=C
# UTF-8 build environmet neeed for w3m (see makefile)

#  Build multi file html, single file html, and single file text formats.
#  makefile for developer-reference was used as my reference.
#
# ------------------------------------------------------------------- #
#                          WARNING                                    #
#         Use with caution, aimed at Lenny system                     #
# ------------------------------------------------------------------- #

# do not use default suffix rules such as .tex.dvi: (uses tex, not latex!)
.SUFFIXES:
# =================================================================== #
#                 Default configuration part                          #
# =================================================================== #

WIKI_ROOT	:= wiki
HTML_ROOT	:= html

MANUAL := debian-reference
## Build language list
LANG_XML := en
LANG_SGML := fr it pt-br es de pl zh-tw zh-cn ja
LANG_ALL := $(LANG_XML) $(LANG_SGML)
# For testing use reduced set instead for speed.
#LANG_SGML := fr
BUILD_TYPE := package

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Do nothing
	touch configure-stamp


build: build-stamp
build-stamp: configure-stamp 
	dh_testdir
	# Add here commands to compile the package.
##	$(MAKE) "MANUAL=$(MANUAL)" \
##		"LANG_ALL=$(LANG_ALL)" \
##		"LANG_XML=$(LANG_XML)" \
##		"LANG_SGML=$(LANG_SGML)" \
##	        "BUILD_TYPE=$(BUILD_TYPE)" \
##		all
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	# Add here commands to clean up after the build process.
	# usual web activity leaves many files in html/
	-$(MAKE) "MANUAL=$(MANUAL)" \
		"LANG_ALL=$(LANG_ALL)" \
		"LANG_XML=$(LANG_XML)" \
		"LANG_SGML=$(LANG_SGML)" \
	        "BUILD_TYPE=$(BUILD_TYPE)" \
	    	"HTML_ROOT=$(CURDIR)/html" \
		clean resethtml

	-cd $(CURDIR)/debian/ ; \
	rm -f debian-reference-common.postinst

	-cd $(CURDIR)/debian/ ; for xx in $(LANG_ALL) ; do \
	rm -f debian-reference-$${xx}.dirs \
	      debian-reference-$${xx}.doc-base \
	      debian-reference-$${xx}.postrm \
	      debian-reference-$${xx}.postinst ; \
	done

	-for xx in $(LANG_SGML) ; do \
	rm -f debian-reference.$${xx}.sgml ; \
	done
	dh_clean

refresh: clean
	dh_testdir
	dh_testroot
# 	cvs -d :ext:osamu@cvs.sf.net:/cvsroot/qref up
#	cvs -d :pserver:anonymous@cvs.sf.net:/cvsroot/qref up

new:    clean
#	rm ../debian-refernce
#	cvs -d :ext:osamu@cvs.sf.net:/cvsroot/qref export -d ../debian-reference -D tomorrow qref
#	cvs -d :pserver:anonymous@cvs.sf.net:/cvsroot/qref up


copyfiles:
	cd $(CURDIR)/debian/ ; \
	cp postinst-full     debian-reference-common.postinst
	# debian-reference-common.prerm exists and removes everything

	cd $(CURDIR)/debian/ ; for xx in $(LANG_ALL) ; do \
	cp postinst-full     debian-reference-$${xx}.postinst ; \
	cp postrm-full       debian-reference-$${xx}.postrm ; \
	done


	set -e; cd $(CURDIR)/debian/ ; for xx in $(LANG_ALL) ; do \
	case $$xx in \
	en) LANG="English" ;;  \
	de) LANG="German" ;;   \
	fr) LANG="French" ;;   \
	fi) LANG="Finnish" ;;  \
	es) LANG="Spanish" ;;  \
	it) LANG="Italian" ;;  \
	ja) LANG="Japanese" ;; \
	pl) LANG="Polish" ;; \
	pt-br) LANG="Portuguese (Brazil)" ;; \
	zh-tw) LANG="Chinese (Traditional)" ;; \
	zh-cn) LANG="Chinese (Simplified)" ;; \
	esac ; \
	cp debian-reference.dirs.all debian-reference-$${xx}.dirs ; \
	sed  -e "s/@@/$$xx/" -e "s/@LANG@/$$LANG/" \
	<debian-reference.doc-base-all  >debian-reference-$${xx}.doc-base ; \
	done

install: build copyfiles
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/debian-reference-??.
	#  (No more examples)

	install -d $(CURDIR)/debian/debian-reference-common/usr/share/applications
	install -m 644 debian/debian-reference-common.desktop \
	    $(CURDIR)/debian/debian-reference-common/usr/share/applications/

	install -m 755 --preserve-timestamps debian-reference \
	    $(CURDIR)/debian/debian-reference-common/usr/bin/debian-reference

	install -m 755 --preserve-timestamps bin/mkindexhtml \
	    $(CURDIR)/debian/debian-reference-common/usr/share/debian-reference/mkindexhtml

	set -e; for xx in $(LANG_ALL); do \
	mkdir -p $(CURDIR)/debian/debian-reference-$${xx}/usr/share/doc/debian-reference-$${xx} ;\
	ln -fs ../debian-reference-common/README.gz \
	$(CURDIR)/debian/debian-reference-$${xx}/usr/share/doc/debian-reference-$${xx}/README.gz ;\
	done
	set -e; for xx in $(LANG_XML); do \
	$(MAKE) -f Makefile-xml "MANUAL=$(MANUAL)" \
		"LANG_ALL=$${xx}" \
	        "BUILD_TYPE=$(BUILD_TYPE)" \
	    	"HTML_ROOT=$(CURDIR)/debian/debian-reference-$${xx}/usr/share/doc/debian-reference-common/html" \
	    	all ;\
	done
	set -e; for xx in $(LANG_SGML); do \
	$(MAKE) -f Makefile-sgml "MANUAL=$(MANUAL)" \
		"LANG_ALL=$${xx}" \
	        "BUILD_TYPE=$(BUILD_TYPE)" \
	    	"HTML_ROOT=$(CURDIR)/debian/debian-reference-$${xx}/usr/share/doc/debian-reference-common/html" \
	    	all ;\
	done
	$(MAKE) -f Makefile-xml "MANUAL=$(MANUAL)" \
		"LANG_ALL=en" \
	        "BUILD_TYPE=$(BUILD_TYPE)" \
	    	"HTML_ROOT=$(CURDIR)/debian/debian-reference-common/usr/share/doc/debian-reference-common/html" \
	    	resethtml ;\


# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf	
#	dh_movefiles
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installcron
	dh_installman -p debian-reference-common debian-reference.1 debian-reference.*.1 
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs 
	dh_link
	dh_strip
	dh_desktop
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install

binary: binary-indep binary-arch

# if rule bomb out, delete the target
.DELETE_ON_ERROR:
