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

package=gnuplot

build:
	$(checkdir)
	./configure --prefix=/usr --with-gnu-readline --with-lasergnu  --without-gd
	make CFLAGS="-O2 -g -Wall"
	(cd docs; make doc2tex; doc2tex gnuplot.doc gp.tex) 
	(cd docs; sed "2740s/ccl/rccl/g" < gp.tex > gnuplot.tex; rm gp.tex)
	(cd docs; make info html tutorial gnuplot.ps gpcard.dvi)
	(cd docs; dvips gpcard.dvi -o gpcard.ps)
	mv docs/latextut/tutorial.dvi docs/latex_tutorial.dvi
	cp 0README README.gnuplot
	cp 0FAQ gnuplot-faq.txt
	head -c1m WhatsNew README.3p5 README.3p4 README.3p3 README.3p2 README.3p1 History > changelog
	touch build

clean:
	$(checkdir)
	# to get rid of some unnecessary files:
	rm -f makefile.r
	-rm -f build
	-make distclean
	-rm -f `find . -name "*~"`
	-rm -f changelog
	-rm -rf debian/tmp debian/files* core debian/substvars
	-rm -f docs/*.dvi README.gnuplot gnuplot-faq.txt docs/gnuplot.html docs/doc2html
	-rm -f docs/latextut/done docs/latextut/tutorial.aux 

binary-indep:	checkroot build
	$(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 build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp
	cd debian/tmp && install -d `cat ../dirs`
	make install prefix=`pwd`/debian/tmp/usr
	chmod u-s `pwd`/debian/tmp/usr/bin/gnuplot
	mkdir -p `pwd`/debian/tmp/etc
	install -g root -o root -m 644 `pwd`/debian/gnuplot.conf `pwd`/debian/tmp/etc/
	mkdir -p `pwd`/debian/tmp/usr/sbin
	install -g root -o root -m 755 `pwd`/debian/gnuplotconfig `pwd`/debian/tmp/usr/sbin/
# Must have debmake installed for this to work. Otherwise please copy
# /usr/bin/debstd into the debian directory and change debstd to debian/debstd
	debstd changelog README.3d README.iso README.mf README.pic docs/gnuplot.html docs/*.ps docs/latex_tutorial.dvi README.gnuplot gnuplot-faq.txt
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R go=rX debian/tmp
	dpkg --build debian/tmp ..

define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

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

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