#!/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)
libpkg          := libplplot9
debbase		:= $(shell pwd)/debian
debtmp		:= $(debbase)/tmp
debusr		:= $(debtmp)/usr
deblib		:= $(debusr)/lib
debshr		:= $(debusr)/share
debdoc		:= $(debshr)/doc
debinfo		:= $(debshr)/info
debex		:= $(debshr)/plplot$(version)/examples

# Architecture exclusion for octave-plplot package
arch		:= $(shell dpkg-architecture -qDEB_HOST_ARCH)
# Keep the code below, just in case it is needed again
# ifeq ($(shell if test "$(arch)" = hppa -o "$(arch)" = powerpc
#                 -o "$(arch)" = m68k -o "$(arch)" = arm ; then
ifeq ($(shell if test "$(arch)" = none ; then \
                echo yes ; \
              else \
                echo no ; \
              fi), no)
octave_cfg := --enable-octave
octave_pkg := octave-plplot
octave_xcl :=
else
octave_cfg := --disable-octave
octave_pkg :=
octave_xcl := --no-package=octave-plplot
endif

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

config: config-stamp
config-stamp: autotools-stamp
	PKG_CONFIG_ENV=" "                                              \
	./configure --prefix=/usr --mandir=/usr/share/man --enable-tcl  \
                    --enable-tk --enable-gd --enable-dyndrivers         \
                    --enable-static --enable-python $(octave_cfg)       \
                    --enable-gnome --with-double --disable-linuxvga     \
                    --infodir=/usr/share/info --with-freetype           \
                    --without-rpath --with-prebuiltdoc --disable-java   \
                    --with-pthreads --with-ltdlsystem --with-pkg-config
	( octver=`egrep "^OCTAVE_VERSION =" Makefile                   \
              | sed "s/OCTAVE_VERSION = *//" | sed 's/ *$$//'`       ; \
          octpkgver=`echo $$octver | sed 's/\.[0-9]*$$//'`           ; \
          echo "octave:Depends=octave$$octpkgver (>= $$octver)"        \
              > debian/octave-plplot.substvars )
	touch config-stamp

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

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp install-stamp config-stamp autotools-stamp \
              debian/files
	-$(MAKE) -k distclean
	rm -f config.sub config.guess
	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

	rm -f $(debtmp)/usr/bin/plplot-config

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

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

	dh_movefiles -a --no-package=$(libpkg) --no-package=libplplot-dev \
	                $(octave_xcl)
	dh_movefiles -i
	dh_movefiles --package=libplplot-dev
	dh_movefiles --package=$(libpkg)

	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=$(libpkg)
	dh_installchangelogs --package=$(libpkg)

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

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
