#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

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

# This is the debhelper compatability version to use.
#export DH_COMPAT=4
# This has to be exported to make some magic below work.
export DH_OPTIONS

docdir=/usr/share/doc
ja=dvi2ps-fontdata-ja
three=dvi2ps-fontdata-three

MAKE=make -f debian/rules

FONTS=$(DESTDIR)/usr/share/texmf/fonts

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

	touch configure-stamp


#Architecture 
build: build-arch build-indep

build-arch: build-arch-stamp
build-arch-stamp: configure-stamp 

	# Add here commands to compile the arch part of the package.
	#$(MAKE) 
	touch build-arch-stamp

build-indep: build-indep-stamp
build-indep-stamp: configure-stamp 

	# Add here commands to compile the indep part of the package.
#	$(MAKE)
	uudecode -o /dev/stdout debian/ptexfake-tfm.tar.gz.uu | tar xvpfz -

	touch build-indep-stamp

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

	# Add here commands to clean up after the build process.
#	-$(MAKE) clean
	-rm -rf ptexfake-tfm

	dh_clean

install: install-indep install-arch
install-indep:
	dh_testdir
	dh_testroot
	dh_clean -k -i
	dh_installdirs -i

	# Add here commands to install the indep part of the package into
	chmod +x debian/install-jdoc
	debian/install-jdoc README debian/$(ja)$(docdir)/$(ja)/README.ja
	debian/install-jdoc vfdata.doc debian/$(ja)$(docdir)/$(ja)
	debian/install-jdoc 3/README debian/$(ja)$(docdir)/$(ja)/README.three
	install -m 644 prninfo.ps debian/$(ja)$(docdir)/$(ja)

	$(MAKE) install-ja DESTDIR=`pwd`/debian/$(ja)

	$(MAKE) install-a2n DESTDIR=`pwd`/debian/dvi2ps-fontdata-a2n

	$(MAKE) install-n2a DESTDIR=`pwd`/debian/dvi2ps-fontdata-n2a

	$(MAKE) install-tbank DESTDIR=`pwd`/debian/dvi2ps-fontdata-tbank

	$(MAKE) install-rsp DESTDIR=`pwd`/debian/dvi2ps-fontdata-rsp

	$(MAKE) install-three DESTDIR=`pwd`/debian/$(three)

	$(MAKE) install-ptexfake DESTDIR=`pwd`/debian/dvi2ps-fontdata-ptexfake

	dh_movefiles -i --sourcedir=debian/$(ja)

install-ja:
	cd morisawa2; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vfdev/morisawa/ptex/`basename $$i .vf`.jvf ; \
	done
	cd morisawa2-v; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vfdev/morisawa/ptex/`basename $$i .vf`.jvf ; \
	done
	# morisawa2-v2h, -vsy, -vsyd
	cd morisawa2-v2h; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vf/ptex/a2mor2-jp/$$i ; \
	done
	cd morisawa2-vsy; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vf/ptex/a2mor2-ps/$$i ; \
	done
	cd morisawa2-vsyd; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vf/ptex/a2mor2-dir/$$i ; \
	done
	cd morisawa2-tfm ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/tfm/morisawa/$$i ; \
	done
	cd morisawa2-v-tfm ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/tfm/morisawa/$$i ; \
	done

install-a2n:
	cd a2n; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vf/a2n/$$i ; \
	done

install-n2a:
	cd n2a; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vf/n2a/$$i ; \
	done

install-tbank:
	cd typebank-tfm ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/tfm/jp/$$i ; \
	done
	cd typebank ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vf/ptex/a2tbank/$$i ; \
	done
	# virtical fonts
	cd typebank-v-tfm ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/tfm/jp/$$i ; \
	done
	cd typebank-v ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vf/ptex/a2tbank/$$i ; \
	done

install-rsp:
	cd ricohsp-tfm ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/tfm/jp/$$i ; \
	done
	cd ricohsp ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vf/ptex/a2rsp/$$i ; \
	done
	# virtical fonts
	cd ricohsp-v-tfm ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/tfm/jp/$$i ; \
	done
	cd ricohsp-v ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/vf/ptex/a2rsp/$$i ; \
	done

install-three:
	cd 3-tfm ; \
	for i in *.tfm ; do \
	install -m 644 $$i $(FONTS)/tfm/jp/$$i ; \
	done
	cd 3 ; \
	for i in *.vf ; do \
	install -m 644 $$i $(FONTS)/vf/ptex/a2mor2/$$i ; \
	done
	# dvi2ps
	cp tfm/*.tfm $(FONTS)/tfm/ptex/three
	cp dvi2ps/three $(DESTDIR)/etc/texmf/dvi2ps
	cp -a dvi2ps/fontsk/*-three $(DESTDIR)/usr/share/texmf/dvi2ps/fontsk
	cp dvi2ps/styles/three.sty $(DESTDIR)/usr/share/texmf/ptex/platex/misc
	# dvips
	cp debian/three.map $(DESTDIR)/etc/texmf/dvipsj
	cp dvi2ps/styles/three.dtx dvi2ps/styles/three.ins \
		debian/$(three)/usr/share/texmf/source/platex/three

install-ptexfake:
	cd ptexfake-tfm ; \
	for i in * ; do \
	install -m 644 $$i $(FONTS)/tfm/ptex/$$i ; \
	done

install-arch:
	dh_testdir
	dh_testroot
#	dh_clean -k -a
#	dh_installdirs -a

	# Add here commands to install the arch part of the package into 
	# debian/dvi2ps-fontdata-ja.
	#$(MAKE) install DESTDIR=$(CURDIR)/debian/dvi2ps-fontdata

#	dh_movefiles -a
# Must not depend on anything. This is to be called by
# binary-arch/binary-multi
# in another 'make' thread.

binary-common:
	dh_testdir
	dh_testroot
	dh_link
#	dh_installdebconf	
	dh_installdocs
#	dh_installexamples
#	dh_installmenu
#	dh_installemacsen
#	dh_installpam
#	dh_installinit
#	dh_installcron
#	dh_installmanpages
#	dh_installinfo
#	dh_undocumented
	dh_installchangelogs 
#	dh_link
#	dh_strip
	dh_compress 
	dh_fixperms
	# You may want to make some executables suid here.
#	dh_suidregister
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_gencontrol
	dh_md5sums
	dh_builddeb
# Build architecture independant packages using the common target.
binary-indep: build-indep install-indep
	make -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build-arch install-arch
	#$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

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