#!/usr/bin/make -f
# ssystem debian build rules
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.
 
package=tochnog
package2=tochnog-doc

INSTALL=/usr/bin/install

CC=cc
CXX=g++

build:
	$(checkdir)
	cd src; \
	make tn \
	"SYSFILE=sysposix" \
	"OBJ=o" \
        "BCPP=" \
        "VCPP=" \
	"COMPILER_C=$(CC)" \
	"COMPILER_CPP=$(CXX)" \
	"COMPILER_FLAGS= -g -ansi -c -Wall -D_REENTRANT" \
	"LINK_FLAGS_BEFORE=" \
	"LINK_FLAGS_AFTER=  -lm -lpthread -o tochnog"
	

#  -f2c was included above , but is apparantly not needed.

	cd doc; export TMP=/tmp ; latex2html tnp.tex
	cd doc; export TMP=/tmp ; latex2html tnu.tex
	cd doc; export TMP=/tmp ; latex2html vtn.tex



clean:
	$(checkdir)
	-rm -f build
	-cd src; make clean
	-cd doc; rm -rf tnp tnu vtn
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars

binary-indep: checkroot
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch: checkroot
	$(checkdir)
	-rm -rf debian/tmp

#  Install directories
	install -d debian/tmp/usr/bin
	install -d debian/tmp/usr/doc/$(package)
	install -d debian/tmp/usr/doc/$(package)/examples
	install -d debian/tmp/DEBIAN



#  Install binary
	strip --strip-unneeded src/$(package)
	install -m 755 src/$(package) debian/tmp/usr/bin

# Install example file
	cp test/* debian/tmp/usr/doc/$(package)/examples
	gzip -9v debian/tmp/usr/doc/$(package)/examples/*

# Install man pages


# Install docs in proper directory and gzip them
#
	$(INSTALL) -m 644 debian/README.debian debian/tmp/usr/doc/$(package)
	cp debian/changelog debian/tmp/usr/doc/$(package)/changelog.Debian
#	cp ChangeLog debian/tmp/usr/doc/$(package)/changelog
	-gzip -9fv debian/tmp/usr/doc/$(package)/*

# don't gzip these
#
	cp debian/copyright debian/tmp/usr/doc/$(package)/copyright



# Install data
	   dpkg-shlibdeps debian/tmp/usr/bin/*
	   dpkg-gencontrol -p$(package)
	   chown -R root.root debian/tmp
	   chmod -R go=rX debian/tmp
	   dpkg --build debian/tmp ..

###########################################################
#  Now build Doc package.

	-rm -rf debian/tmp

#  Install directories
	install -d debian/tmp/usr/doc/$(package2)
	install -d debian/tmp/usr/doc/$(package)
	install -d debian/tmp/DEBIAN

	cp -r doc/tnp doc/tnu doc/vtn debian/tmp/usr/doc/$(package)
	cp doc/*.tex debian/tmp/usr/doc/$(package)
	cp -r doc/ps debian/tmp/usr/doc/$(package)

# Install man pages

#	install -m 644  debian/admesh.1 debian/tmp/usr/man/man1
#	gzip -vf9 debian/tmp/usr/man/man1/*


# Install docs in proper directory and gzip them
#
	$(INSTALL) -m 644 debian/README.debian debian/tmp/usr/doc/$(package2)
	cp debian/README.debian.doc \
	   debian/tmp/usr/doc/$(package2)/README.debian
	cp debian/changelog debian/tmp/usr/doc/$(package2)/changelog.Debian
	-gzip -9fv debian/tmp/usr/doc/$(package2)/*

# don't gzip these
#
	cp debian/copyright debian/tmp/usr/doc/$(package2)/copyright



# Build doc package
	   dpkg-gencontrol -p$(package2)
	   chown -R root.root debian/tmp
	   chmod -R go=rX debian/tmp
	   dpkg --build debian/tmp ..




define checkdir
	/usr/bin/test -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot




