#!/usr/bin/make -f
# -*- Makefile -*-
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independant
# package.
# Modified by Rafael Laboissiere <rafael@debian.org> on 1998/06/12
# for the plplot package

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

export DH_COMPAT=4

version		:= $(shell perl debian/get-upstream-version.pl < configure.ac)
debbase		:= $(shell pwd)/debian
debtmp		:= $(debbase)/tmp
debusr		:= $(debtmp)/usr
deblib		:= $(debusr)/lib
debshr		:= $(debusr)/share
debdoc		:= $(debshr)/doc
debinfo		:= $(debshr)/info
debex		:= $(deblib)/plplot$(version)/examples
deboct		:= $(debtmp)$(shell octave-config --oct-site-dir)

autotools:
	-rm -f config.sub config.guess
	ln -s /usr/share/misc/config.sub config.sub
	ln -s /usr/share/misc/config.guess config.guess

config: config-stamp
config-stamp: autotools
	./configure --prefix=/usr --mandir=/usr/share/man --enable-tcl \
                    --enable-tk --enable-gd --enable-dyndrivers        \
                    --disable-static --enable-python --enable-octave   \
                    --enable-gnome --with-double --disable-linuxvga    \
                    --infodir=/usr/share/info --with-freetype          \
                    --without-rpath --with-prebuiltdoc
	( python_version=`egrep "^PYTHON_VERSION =" Makefile           \
	      | sed "s/PYTHON_VERSION = *//" | sed 's/ *$$//'`       ; \
	  echo "python:Depends=python$$python_version"                 \
	      > debian/python-plplot.substvars ;                       \
	  octver=`egrep "^OCTAVE_VERSION =" Makefile                   \
	      | sed "s/OCTAVE_VERSION = *//" | sed 's/ *$$//'`       ; \
	  next=`echo $$octver                                          \
	      | perl -ne '/(\d+\.\d+\.)(\d+)/;print($$1,$$2+1)'`     ; \
	  octpkgver=`echo $$octver | sed 's/\.[0-9]*$$//'`           ; \
	  pv=octave$$octpkgver                                       ; \
	  echo "octave:Depends=$$pv (>= $$octver), $$pv (<< $$next)"   \
	      > debian/octave-plplot.substvars )
	touch config-stamp

build: build-stamp
build-stamp: config
	dh_testdir
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp install-stamp config-stamp debian/files
	-$(MAKE) clean
	find . -name config.log -o -name config.status | xargs rm -f
	dh_clean

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot

	make DESTDIR=$(debtmp) install

	( cd $(debdoc)/plplot ; \
	  rm -f COPYING.LIB *.dvi ; \
	  mv ChangeLog changelog )
	mv $(debdoc)/plplot $(debdoc)/libplplot5
	mv $(debex) $(debdoc)/libplplot5

	for i in libplplot-dev plplot-xwin plplot-tcl plplot-gnome \
                 octave-plplot python-plplot plplot-gd plplot-doc  \
                 plplot-tcl-dev ; do \
	  ln -s libplplot5 $(debdoc)/$$i ; \
	done

	dh_movefiles -a --no-package=libplplot5
	dh_movefiles -i --no-package=libplplot-dev
	dh_movefiles --package=libplplot-dev
	dh_movefiles --package=libplplot5

	touch install-stamp

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installdirs -i
	dh_installdocs --package=plplot-doc --exclude=copyright
	dh_compress -i --exclude=.pdf
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_installdirs -a

	dh_installdocs --package=libplplot5
	dh_installchangelogs --package=libplplot5

	dh_strip -a
	dh_compress -a -Xexamples/
	dh_fixperms -a
	dh_makeshlibs -V -a
	dh_shlibdeps -L libplplot5 -L plplot-tcl \
	  -l $(debbase)/libplplot5/usr/lib:$(debbase)/plplot-tcl/usr/lib
	dh_installdeb -a
	dh_shlibdeps -a -l$(debbase)/plplot-tcl/usr/lib
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary config autotools
