#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.
#
# This version is for a multibinary package. It also allows you to build any
# of the binary packages independantly, via binary-<package> targets.

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

COMMON_CONFIGURE_FLAGS = \
  --prefix=/usr \
  --enable-static --enable-shared \
  --disable-dependency-tracking \
  --without-mesa \
  --with-coin

CFLAGS = -g -D_REENTRANT -Wl,-z,defs
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif

build: build-stamp-qt4

build-stamp-qt4:
	dh_testdir
	test -d build.qt4 || mkdir build.qt4
	cd build.qt4 && ../configure $(COMMON_CONFIGURE_FLAGS) \
		--enable-man --mandir=/usr/share/man \
		--enable-html htmldir=/usr/share/doc/libsoqt-dev-common/html \
		--with-suffix=4 QTDIR=/usr/share/qt4
	$(MAKE) -C build.qt4
	touch build-stamp-qt4

clean:
	dh_testdir
	dh_testroot
	rm -rf build-stamp-qt? build.qt?
	rm -f cfg/wrapmsvc.exe
	rm -f src/Inventor/Qt/stamp-h3

	dh_clean

# This file was deleted from my CVS repository.  It is not needed
# on linux, but it is a dependency of the top-level "install" rule,
# so it has to exist.
cfg/wrapmsvc.exe:
	touch $@

install: DH_OPTIONS=
install: build cfg/wrapmsvc.exe
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	rm -f build.qt?/man/man3/_*

	$(MAKE) -C build.qt4 DESTDIR=$(CURDIR)/debian/tmp/qt4 install

	sed -i "/dependency_libs/ s/'.*'/''/" `find . -name '*.la'`
	rmdir debian/tmp/qt4/usr/include/Inventor/Qt/engines

	cd debian/tmp/qt4/usr/share/Coin/conf && mv soqt-default.cfg soqt-qt4.cfg

	dh_install -plibsoqt4-20 debian/tmp/qt4/usr/lib/libSoQt4.so.[0-9]* usr/lib
	cd debian/libsoqt4-20/usr/lib && ln -s libSoQt4.so.20 libSoQt.so.20

	dh_install -plibsoqt-dev-common debian/tmp/qt4/usr/bin/soqt-config usr/bin
	dh_install -plibsoqt-dev-common debian/tmp/qt4/usr/include usr
	dh_install -plibsoqt-dev-common debian/tmp/qt4/usr/share/aclocal usr/share
	dh_install -plibsoqt-dev-common debian/tmp/qt4/usr/share/doc/libsoqt-dev-common usr/share/doc
	dh_install -plibsoqt-dev-common debian/tmp/qt4/usr/share/man usr/share
	dh_install -plibsoqt-dev-common test-code/* usr/share/doc/libsoqt-dev-common/examples
	dh_installdocs -plibsoqt-dev-common AUTHORS FAQ NEWS README

	dh_install -plibsoqt4-dev debian/tmp/qt4/usr/lib/libSoQt4.so usr/lib
	dh_install -plibsoqt4-dev debian/tmp/qt4/usr/lib/libSoQt4.la usr/lib
	dh_install -plibsoqt4-dev debian/tmp/qt4/usr/lib/libSoQt4.a usr/lib
	dh_install -plibsoqt4-dev debian/tmp/qt4/usr/share/Coin usr/share

	dh_installdocs -plibsoqt4-dev -plibsoqt-dev-common \
		debian/README.Debian

# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
binary-common:
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installman
	dh_strip
	dh_link
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
binary-indep: build install
# (Uncomment this next line if you have such packages.)
#	 $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

# Any other binary targets build just one binary package at a time.
binary-%: build install
	make -f debian/rules binary-common DH_OPTIONS=-p$*

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
