#!/usr/bin/make -f

#export DH_VERBOSE=1
export DH_OPTIONS=
export QTDIR=/usr/share/qt4/QtGui

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
with_doxywizard := yes
ifneq (,$(filter $(DEB_BUILD_ARCH),hurd-i386))
  with_doxywizard := no
endif

CFLAGS+=$(if $(findstring debug,$(DEB_BUILD_OPTIONS)),-g)
CFLAGS+=$(if $(findstring noopt,$(DEB_BUILD_OPTIONS)),-O0,-O2)
ifeq ($(with_doxywizard),yes)
  CONFIGUREFLAGS+=--with-doxywizard
endif
CONFIGUREFLAGS+=--dot /usr/bin/dot
CONFIGUREFLAGS+=--install /usr/bin/install

configure: configure-stamp
configure-stamp:
	dh_testdir
	CFLAGS="$(CFLAGS)" ./configure $(CONFIGUREFLAGS)
	sed -i 's/^TMAKE_MOC *=.*/TMAKE_MOC = moc/' addon/doxywizard/doxywizard.pro
	touch $@

build: build-stamp
build-stamp: configure-stamp
	dh_testdir
	TMAKE_CFLAGS_RELEASE="-g -O2" $(MAKE) QMAKE=/usr/bin/qmake-qt4
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f configure-stamp build-stamp install*stamp
	rm -rf qt
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f qtools/Makefile.qtools
	dh_clean

uninstall:
	dh_testdir
	dh_testroot
	rm -f install*stamp
	dh_clean -k

install-indep: install-arch
install-indep: install-indep-stamp
install-indep-stamp: DH_OPTIONS=-i
install-indep-stamp: INSDIR=$(shell pwd)/debian/doxygen/usr
install-indep-stamp: DOCDIR=$(shell pwd)/debian/doxygen-doc/usr/share/doc/doxygen
install-indep-stamp:
	dh_testdir
	dh_testroot
	dh_installdirs
	$(MAKE) install_docs \
		INSTALL=$(INSDIR) DOCDIR=$(DOCDIR) MAN1DIR=share/man/man1
	-find debian -name .cvsignore -o -name CVS | xargs rm -rf
	touch $@

install-arch: build
install-arch: install-arch-stamp
install-arch-stamp: DH_OPTIONS=-a
install-arch-stamp: INSDIR=$(shell pwd)/debian/doxygen/usr
install-arch-stamp: DOCDIR=$(shell pwd)/debian/doxygen/usr/share/doc/doxygen
install-arch-stamp:
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) install \
		INSTALL=$(INSDIR) DOCDIR=$(DOCDIR) MAN1DIR=share/man/man1
ifeq ($(with_doxywizard),yes)
	dh_movefiles -Ndoxygen --sourcedir=debian/doxygen \
		usr/bin/doxywizard \
		usr/share/man/man1/doxywizard.1
endif
	-find debian -name .cvsignore -o -name CVS | xargs rm -rf
	touch $@

install: install-indep install-arch

binary-indep: DH_OPTIONS=-i
binary-indep: install-indep
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installchangelogs 
	dh_strip
	dh_link
	dh_compress -X.pdf
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

ifeq ($(with_doxywizard),yes)
binary-arch: DH_OPTIONS=-a
else
binary-arch: DH_OPTIONS=-a -Ndoxygen-gui
endif
binary-arch: install-arch
	dh_testdir
	dh_testroot
	dh_installdocs LANGUAGE.HOWTO PLATFORMS README VERSION
	dh_installman
	dh_installchangelogs 
	dh_strip
	dh_link
	dh_installmenu
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-arch binary-indep

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