#!/usr/bin/make -f

# debian/rules file for gtk+ Debian package
# written Feb 1999 by Ionutz Borcoman <borco@borco-ei.eng.hokudai.ac.jp>
# used the script written  April 1998 by Ben Gertzfield <che@debian.org> for glib

#include /usr/share/dpatch/dpatch.make

export DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


build-arch: build
build-indep: build
build: build-stamp 
build-stamp:
	dh_testdir
	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/usr --enable-debug=no \
		--enable-testvdk=no --mandir=/usr/share/man \
		--enable-gnome=yes
	$(MAKE)
	$(MAKE) docs
	touch build-stamp

build-dbg: build-dbg-stamp 
build-dbg-stamp:
	dh_testdir
	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
	         --prefix=/usr --enable-debug=yes \
		--enable-testvdk=no --mandir=/usr/share/man \
		--enable-gnome=yes
	$(MAKE)
	touch build-dbg-stamp

clean: clean1 
clean1:
	dh_testdir
	dh_testroot
	rm -f build-stamp build-dbg-stamp install-stamp install-dbg-stamp
	# autotools-dev stuff
	-test -r /usr/share/misc/config.sub && \
	  cp -f /usr/share/misc/config.sub config.sub
	-test -r /usr/share/misc/config.guess && \
	  cp -f /usr/share/misc/config.guess config.guess

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean
	find . -name '*.o' -o -name '_libs' -o -name '*.lo' -o -name '*.a' -o -name '.deps' | xargs rm -rf
	dh_clean

install: install-stamp
install-stamp: build
	dh_testdir
	dh_testroot
	$(MAKE) DESTDIR=`pwd`/debian/libvdk2-2c2 install
	rm -f $(CURDIR)/debian/libvdk2-2c2/usr/lib/*.la
	chrpath -d $(CURDIR)/debian/libvdk2-2c2/usr/lib/*.so*
	touch install-stamp

install-dbg: install-dbg-stamp
install-dbg-stamp: build-dbg
	dh_testdir
	dh_testroot
	$(MAKE) DESTDIR=`pwd`/debian/libvdk2-dbg install
	touch install-dbg-stamp

# Build architecture-independent files here.
binary-indep: build install libvdk2-doc 
libvdk2-doc: build
	dh_testdir -plibvdk2-doc
	dh_testroot -plibvdk2-doc

	dh_installdirs -plibvdk2-doc

	# Add here commands to install the files from debian/libvdk2-2c2
	dh_movefiles -plibvdk2-doc --sourcedir=debian/libvdk2-2c2

	# copy documentation
	files="\
		html" ; \
        working_dir=`pwd`; \
	cd doc/doxy; \
	for file in $$files; do \
	    echo $$file; \
	    install -d $$working_dir/debian/libvdk2-doc/usr/share/doc/libvdk2-doc/$$file; \
	    install -m 644 $$file/* \
		$$working_dir/debian/libvdk2-doc/usr/share/doc/libvdk2-doc/$$file/; \
	done

	dh_installdocs -plibvdk2-doc
	dh_installchangelogs -plibvdk2-doc ChangeLog
	dh_strip -plibvdk2-doc
	dh_compress -plibvdk2-doc
	dh_fixperms -plibvdk2-doc

	dh_installdeb -plibvdk2-doc
	dh_shlibdeps -plibvdk2-doc
	dh_gencontrol -plibvdk2-doc
	dh_md5sums -plibvdk2-doc
	dh_builddeb -plibvdk2-doc


# Build architecture-dependent files here.
binary-arch: build install libvdk2-dev libvdk2-2c2 libvdk2-dbg

libvdk2-2c2: build
	dh_testdir -plibvdk2-2c2
	dh_testroot -plibvdk2-2c2
	dh_installdirs -plibvdk2-2c2

	# Add here commands to install the files into debian/tmp
	rm -rf debian/libvdk2-2c2/usr/bin \
		debian/libvdk2-2c2/usr/include \
		debian/libvdk2-2c2/usr/share/aclocal \
		debian/libvdk2-2c2/usr/share/man \
		debian/libvdk2-2c2/usr/lib/*.la
	dh_installdocs -plibvdk2-2c2

	dh_installchangelogs -plibvdk2-2c2 ChangeLog
	dh_strip -plibvdk2-2c2
	dh_compress -plibvdk2-2c2
	dh_fixperms -plibvdk2-2c2
	dh_installdeb -plibvdk2-2c2
	dh_shlibdeps -plibvdk2-2c2
	dh_gencontrol -plibvdk2-2c2
	dh_makeshlibs -plibvdk2-2c2 -V 'libvdk2-2c2 (>= 2.0.3-3)'
	dh_md5sums -plibvdk2-2c2
	dh_builddeb -plibvdk2-2c2


libvdk2-dev: build
	dh_testdir -plibvdk2-dev
	dh_testroot -plibvdk2-dev

	dh_installdirs -plibvdk2-dev

	# Add here commands to install the files from debian/libvdk2-2c2
	dh_movefiles -plibvdk2-dev --sourcedir=debian/libvdk2-2c2
	cp vdk-config-2 debian/libvdk2-dev/usr/bin

	# start copying the examples 
	# here we do something not very clean, but it is working
	# aka, we sometimes try to "install -m 644" some directories
	# the final thing works anyhow
	files="\
		childtask \
		iotut \
		hello \
		template" ; \
    working_dir=`pwd`; \
	for file in example/$$files; do \
	    install -d debian/libvdk2-dev/usr/share/doc/libvdk2-dev/examples/$$file; \
	    cd $$working_dir; \
	    install -m 644 example/$$file/* \
		debian/libvdk2-dev/usr/share/doc/libvdk2-dev/examples/$$file/; \
	done

	files="\
		testvdk \
		doc \
		sigcvdktest " ; \
    working_dir=`pwd`; \
	for file in $$files; do \
	    install -d debian/libvdk2-dev/usr/share/doc/libvdk2-dev/$$file; \
	    cd $$working_dir; \
	    install -m 644 $$file/* \
		debian/libvdk2-dev/usr/share/doc/libvdk2-dev/$$file/; \
	done
	echo finished docs

	# remove unwanted stuff from debian/libvdk2-dev/usr/share/doc/libvdk2-dev/doc
	rm -f debian/libvdk2-dev/usr/share/doc/libvdk2-dev/doc/Makefile*  \
	    debian/libvdk2-dev/usr/share/doc/libvdk2-dev/doc/vdk-config-2.1 \
	    debian/libvdk2-dev/usr/share/doc/libvdk2-dev/doc/vdk-config-2.1.in
	dh_installdocs -plibvdk2-dev 
	dh_installchangelogs -plibvdk2-dev ChangeLog
	dh_strip -plibvdk2-dev
	dh_compress -plibvdk2-dev
	dh_fixperms -plibvdk2-dev

	dh_installdeb -plibvdk2-dev
	dh_shlibdeps -plibvdk2-dev
	dh_gencontrol -plibvdk2-dev
	dh_md5sums -plibvdk2-dev
	dh_builddeb -plibvdk2-dev

libvdk2-dbg: install-dbg
	dh_testdir -plibvdk2-dbg
	dh_testroot -plibvdk2-dbg
	dh_installdirs -plibvdk2-dbg

	# Add here commands to install the files into debian/libvdk2-dbg
	rm -rf debian/libvdk2-dbg/usr/bin \
		debian/libvdk2-dbg/usr/include \
		debian/libvdk2-dbg/usr/share/man \
		debian/libvdk2-dbg/usr/share \
		debian/libvdk2-dbg/usr/lib/*.la \
		debian/libvdk2-dbg/usr/lib/*.so*
	for file in `find debian/libvdk2-dbg/usr/lib -name '*.a'` ; do \
	  mv $$file debian/libvdk2-dbg/usr/lib/`basename $$file .a`_g.a; \
    done

	dh_installdocs -plibvdk2-dbg
	dh_installchangelogs -plibvdk2-dbg ChangeLog
	dh_compress -plibvdk2-dbg
	dh_fixperms -plibvdk2-dbg
	dh_installdeb -plibvdk2-dbg
	dh_shlibdeps -plibvdk2-dbg
	dh_gencontrol -plibvdk2-dbg
	dh_md5sums -plibvdk2-dbg
	dh_builddeb -plibvdk2-dbg

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

binary: binary-indep binary-arch
.PHONY: build build-arch build-indep clean binary-indep binary-arch binary patch unpatch
