#!/usr/bin/make -f

# build variables
export QTDIR=$(shell pwd)

# re-set $(LD_LIBRARY_PATH)
OLD_LD_LIBRARY_PATH := $(LD_LIBRARY_PATH)
export LD_LIBRARY_PATH=$(QTDIR)/lib:$(OLD_LD_LIBRARY_PATH)

# fix path
OLD_PATH := $(PATH)
export PATH=$(QTDIR)/bin:$(OLD_PATH)

# The default gzip compressor has been changed in dpkg >= 1.17.0.
deb_default_compress = $(shell LANG=C dpkg-deb --version | head -n1 | \
                         sed -e "s|.*version ||" -e "s| .*||" | \
                         xargs -r dpkg --compare-versions 1.17.0 lt \
                         && echo xz || echo gzip)
ifeq ($(deb_default_compress),gzip)
DEB_DH_BUILDDEB_ARGS += -- -Z$(shell dpkg-deb --help | grep -q ":.* xz[,.]" \
                               && echo xz || echo bzip2)
endif

DEB_HOST_ARCH		?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_ARCH_CPU	?= $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)
DEB_HOST_MULTIARCH	?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# Honour "parallel=N" option of DEB_BUILD_OPTIONS.  Comment out to
# never build in parallel, regardless of DEB_BUILD_OPTIONS.
DEB_BUILD_PARALLEL ?= true

ifeq ($(DEB_HOST_ARCH_OS),hurd)
	PLATFORM_ARG = hurd-g++
else #hurd
ifeq ($(DEB_HOST_ARCH),sparc)
	PLATFORM_ARG = linux-g++-sparc
else #sparc
	PLATFORM_ARG = linux-g++
endif #sparc
endif #hurd

# quilt stuff
#include /usr/share/cdbs/1/rules/patchsys-quilt.mk

# build variables (directorys)
DEBIAN = $(shell pwd)/debian
P_LIBS = $(DEBIAN)/libtqt3-mt
P_DOC = $(DEBIAN)/tqt3-doc
P_APPSDEV = $(DEBIAN)/tqt3-apps-dev
P_HEADERS = $(DEBIAN)/libtqt3-headers
P_QTMTDEV = $(DEBIAN)/libtqt3-mt-dev

RPC_INCLUDES = $(if $(wildcard /usr/include/tirpc),-I/usr/include/tirpc,)

TMP_INSTALL = $(DEBIAN)/tmp-install

CONFIGURE_OPTS = \
		-prefix		"/usr"				\
		-sysconfdir	"/etc/tqt3"			\
		-datadir	"/usr/share/tqt3"		\
		-headerdir	"/usr/include/tqt3"		\
		-docdir		"/usr/share/tqt3/doc"		\
		-libdir		"/usr/lib/$(DEB_HOST_MULTIARCH)"		\
		-plugindir	"/usr/lib/$(DEB_HOST_MULTIARCH)/tqt3/plugins"	\
		-translationdir	"/usr/share/tqt3/translations"	\
						\
		-thread				\
		-shared				\
		-fast				\
		-no-exceptions			\
		-platform $(PLATFORM_ARG)	\
						\
		-nis				\
		-no-pch				\
		-cups				\
		-stl				\
		-ipv6				\
						\
		-sm				\
		-xshape				\
		-xinerama			\
		-xcursor			\
		-xrandr				\
		-xrender			\
		-xft				\
		-tablet				\
		-xkb				\
						\
		-system-zlib			\
		-system-libpng			\
		-system-libmng			\
		-system-libjpeg			\
		-system-nas-sound		\
						\
		-enable-opengl			\
		-dlopen-opengl			\
						\
		-qt-gif				\
		-qt-imgfmt-png			\
		-qt-imgfmt-jpeg			\
		-plugin-imgfmt-mng		\
						\
		-plugin-sql-odbc		\
		-plugin-sql-psql		\
		-plugin-sql-mysql		\
		-plugin-sql-ibase		\
		-plugin-sql-sqlite		\
		-plugin-sql-sqlite3		\
						\
		-I/usr/include/mysql		\
		-I/usr/include/freetype2	\
		-I`pg_config --includedir`	\
		-I`pg_config --includedir-server`	\
		$(RPC_INCLUDES)			\
						\
		-L/usr/lib/$(DEB_HOST_MULTIARCH)\
						\
		-lfontconfig			\
		-inputmethod			\
		-glibmainloop			\
		# End of CONFIGURE_OPTS

interbase_archs := i386 amd64 sparc powerpc
ifneq ($(DEB_HOST_ARCH_CPU),$(findstring $(DEB_HOST_ARCH_CPU),$(interbase_archs)))
	CONFIGURE_OPTS += -no-sql-ibase
	IBASE = -Nlibtqt3-mt-ibase
else
	IBASE =
endif

ifeq ($(DEB_HOST_ARCH_OS),hurd)
	CONFIGURE_OPTS += -no-sql-ibase
	IBASE = -Nlibtqt3-mt-ibase
endif

ifeq ($(DEB_HOST_ARCH),arm)
	CONFIGURE_OPTS += -DQT_QLOCALE_USES_FCVT
endif

post-patches::
	dh_testdir

build build-arch: libqt-thread-stamp
build-indep:

	touch build-stamp

libqt-thread-stamp: post-patches

	@echo "QTDIR is ${QTDIR}"

	dh_testdir

	echo yes | ./configure $(CONFIGURE_OPTS)

	# proceed
	$(MAKE) sub-src sub-plugins sub-tools
	$(MAKE) -C src INSTALL_ROOT=$(TMP_INSTALL) install_target
	$(MAKE) INSTALL_ROOT=$(TMP_INSTALL) install
	$(MAKE) INSTALL_ROOT=$(TMP_INSTALL) plugins-install

	# archives get accidentally stripped by make install. Copy over unstripped ones for now.
	-cp lib/lib*.a $(TMP_INSTALL)/usr/lib/

	cp bin/tqtrename140 $(TMP_INSTALL)/usr/bin/
	cp bin/tqtfindtr $(TMP_INSTALL)/usr/bin/

	# build tqtconv2ui
	cd tools/designer/tools/tqtconv2ui && $(MAKE)
	cp bin/tqtconv2ui $(TMP_INSTALL)/usr/bin/tqtconv2ui

	# build tqvfb
	cd tools/tqvfb/ && $(MAKE)
	cp tools/tqvfb/tqvfb $(TMP_INSTALL)/usr/bin/tqvfb

	# install qmake.cache file
	install -d $(P_QTMTDEV)/usr/share/tqt3/
	cat .qmake.cache | sed "s#$(QTDIR)#/usr/share/tqt3#g" > $(P_QTMTDEV)/usr/share/tqt3/.qmake.cache

	touch libqt-thread-stamp

clean::

	dh_testdir

	-rm -rf debian/patched
	-rm -rf build-stamp libqt-thread-stamp

	-chmod -R u+w *
	-chmod a-x doc/html/layout?.png

	if [ -f "src/Makefile" ]; then \
		$(MAKE) -C src clean; $(MAKE) -C plugins/src distclean; $(MAKE) -C tools distclean; \
		$(MAKE) -C tools/maketqpf distclean; $(MAKE) -C tools/qconfig distclean; $(MAKE) -C tools/tqvfb distclean; \
		$(MAKE) -C tools/msg2tqm distclean; $(MAKE) -C tools/tqtmergetr distclean; $(MAKE) -C tools/qembed distclean; \
		$(MAKE) -C tools/designer/tools/tqtconv2ui distclean; $(MAKE) -C tools/designer/tools/tqtcreatecw distclean; \
		$(MAKE) -C tools/designer/plugins/glade distclean; $(MAKE) -C tools/designer/plugins/qglwidget distclean; \
		$(MAKE) -C config.tests/unix/largefile distclean; $(MAKE) -C qmake distclean; \
	fi

	-rm -rf .qmake.cache src/.qmake.internal.cache tools/designer/designer/.qmake.internal.cache qmake/GNUmakefile \
		config.status bin/moc bin/tqmake src/moc/*.o mkspecs/default lib/lib* `pwd`/debian/doc $(TMP_INSTALL) \
		src/tools/qconfig.cpp include/ntqconfig.h include/ntqmodules.h plugins/accessibleqtwidgets.prl \
		config.tests/unix/ipv6/ipv6test config.tests/unix/ipv6/ipv6test.o config.tests/unix/ptrsize/ptrsizetest.o \
		config.tests/unix/ptrsize/ptrsizetest config.tests/unix/endian/endiantest.o \
		config.tests/unix/endian/endiantest lib/tqt-mt.pc extensions/nsplugin/examples/trivial/libtrivial.prl \
		extensions/nsplugin/examples/grapher/libgrapher.prl bin/designer

	rm -f qmake/*o
	rm -f src/.obj/debug-shared-mt/*o plugins/src/inputmethods/imsw-multi/.obj/debug-shared-mt/*o plugins/inputmethods/*so
	rm -f plugins/src/inputmethods/imsw-none/.obj/debug-shared-mt/*o plugins/src/inputmethods/simple/.obj/debug-shared-mt/*o plugins/src/inputmethods/xim/.obj/debug-shared-mt/*o

	# delete generated Makefiles but save the toplevel Makefile
	-mv Makefile Makefile.save
	for a in `find . -name 'Makefile'`; do rm -f "$$a"; done
	-mv Makefile.save Makefile

	cd examples/ && find . -name '.obj' | xargs rm -rf

	# revert multi-arch path in install files
	for a in debian/*install debian/*links; do \
	    [ ! -f $$a.arch ] || \
	    mv $$a.arch $$a; \
	done

	dh_clean

install: build

	dh_testdir
	dh_testroot

	dh_clean -i
	dh_installdirs

	# update multi-arch path in install files
	for a in debian/*install debian/*links; do \
	    [ -d $$a ] || [ -f $$a.arch ] || \
	    sed -i.arch "s|\$$(DEB_HOST_MULTIARCH)|$(DEB_HOST_MULTIARCH)|g" $$a; \
	done

	# fix .prl files
	for a in $(TMP_INSTALL)/usr/lib/$(DEB_HOST_MULTIARCH)/*prl; do cat "$$a" | sed \
	"s#$(QTDIR)#/usr/share/tqt3#g" > "$$a".new && mv "$$a".new "$$a"; done

	dh_install $(IBASE) --sourcedir=$(TMP_INSTALL)

	## build tqt3-doc package
	# copy all docs there first
	install -d $(P_DOC)/usr/share/tqt3/doc/html/
	for a in `cd $(TMP_INSTALL)/usr/share/tqt3/doc/html/ && find`; do cp $(TMP_INSTALL)/usr/share/tqt3/doc/html/"$$a" $(P_DOC)/usr/share/tqt3/doc/html/; done

	## build designer package documentation
	# tqt3-designer
	install -d `pwd`/debian/tqt3-designer/usr/share/tqt3/doc/html/
	for a in `cat doc/html/designer*.html doc/html/designer*.dcf | grep png | sed 's/^.*src=\"\([^\"]+\)\".*$$/\1/' | \
	perl -pe 's#<\?p[^>]+>##' | tee outputfile | perl -ne '/<img [^>]*(src=\"[^"]+\")/; print $$1' | \
	sed 's/src=//g' | sed 's/"/ /g'`; do cp doc/html/"$$a" `pwd`/debian/tqt3-designer/usr/share/tqt3/doc/html/ && \
	rm -rf $(P_DOC)/usr/share/tqt3/doc/html/"$$a" || true; done
	rm -rf outputfile `pwd`/debian/tqt3-designer/usr/share/tqt3/doc/html/logo32.png
	rm -rf `pwd`/debian/tqt3-doc/usr/share/tqt3/doc/html/designer*

	## build linguist package documentation
	# tqt3-linguist
	install -d `pwd`/debian/tqt3-linguist/usr/share/tqt3/doc/html/
	for a in `cat doc/html/linguist*.html doc/html/linguist*.dcf | grep png | sed 's/^.*src=\"\([^\"]+\)\".*$$/\1/' | \
	perl -pe 's#<\?p[^>]+>##' | tee outputfile | perl -ne '/<img [^>]*(src=\"[^"]+\")/; print $$1' | \
	sed 's/src=//g' | sed 's/"/ /g'`; do cp doc/html/"$$a" `pwd`/debian/tqt3-linguist/usr/share/tqt3/doc/html/ && \
	rm -rf $(P_DOC)/usr/share/tqt3/doc/html/"$$a" || true; done
	rm -rf outputfile `pwd`/debian/tqt3-linguist/usr/share/tqt3/doc/html/logo32.png
	rm -rf `pwd`/debian/tqt3-doc/usr/share/tqt3/doc/html/linguist*

	## tqt3-assistant
	# remove docs from tqt3-doc for qt-assistant
	rm -rf `pwd`/debian/tqt3-doc/usr/share/tqt3/doc/html/assistant*

	## all packages
	# install the overrides files
	#for a in debian/overrides/*; do install -d debian/`echo "$$a" | sed 's/debian\/overrides\///g'`/usr/share/lintian/overrides; done
	#for a in debian/overrides/*; do cp "$$a" debian/`echo "$$a" | sed 's/debian\/overrides\///g'`/usr/share/lintian/overrides/`echo "$$a" | sed 's/debian\/overrides\///g'`; done

	chmod 644 debian/tqt3-dev-tools/usr/share/tqt3/mkspecs/aix-g++-64/qplatformdefs.h
	chmod 644 debian/tqt3-dev-tools/usr/share/tqt3/mkspecs/macx-pbuilder/Info.plist.app

binary-indep: build install

	# Build architecture-independent files here.
	dh_testdir
	dh_testroot

	dh_installdocs -i -XREADME.Debian
	dh_installchangelogs -i changes-3.3.8
	dh_installchangelogs -i changes-3.3.8b

	dh_installman -i

	find doc/man -path \*/CVS -prune -o -print | cpio -pmd $(P_DOC)/usr/share/tqt3/doc/

	-rm -f `find $(P_DOC)/usr/share/tqt3/doc/ -name "*.o"`
	find $(P_DOC) -type f -perm +0100 | xargs --no-run-if-empty rm -f

	install -d $(P_DOC)/usr/share/man/man3/

	for i in $(P_DOC)/usr/share/tqt3/doc/doc/man/man3/* ; do mv $$i $(P_DOC)/usr/share/man/man3/ ; done

	-rm -rf $(P_DOC)/usr/share/tqt3/doc/doc

	# other i18n files
	for a in `cd translations/ && find . -name 'qt_*.qm' | sed 's/qt_//' | sed 's/\.qm//' | sed 's/\.\///g'`; do \
	install -m644 -D `pwd`/translations/qt_"$$a".qm `pwd`/debian/libtqt3-i18n/usr/share/tqt3/translations/qt_"$$a".qm; done

	# logo32.png
	cp `pwd`/doc/html/logo32.png `pwd`/debian/tqt3-doc/usr/share/tqt3/doc/html/

	# remove qmake html docu from tqt3-doc
	rm -rf `pwd`/debian/tqt3-doc/usr/share/tqt3/doc/html/qmake*

	# create examples package
	install -d `pwd`/debian/doc/tqt3-examples/tools/designer
	install -d `pwd`/debian/doc/tqt3-examples/tools/linguist
	cp -ax examples `pwd`/debian/doc/tqt3-examples
	cp -ax tutorial `pwd`/debian/doc/tqt3-examples
	cp -ax tools/designer/examples `pwd`/debian/doc/tqt3-examples/tools/designer/
	cp -ax tools/linguist/tutorial `pwd`/debian/doc/tqt3-examples/tools/linguist/
	for a in `cd $(DEBIAN)/doc/tqt3-examples/ && find $(DEBIAN)/doc/tqt3-examples/ -name 'tt1'`; do rm -f "$$a"; done
	for a in `cd $(DEBIAN)/doc/tqt3-examples/ && find $(DEBIAN)/doc/tqt3-examples/ -name 'tt2'`; do rm -f "$$a"; done
	for a in `cd $(DEBIAN)/doc/tqt3-examples/ && find $(DEBIAN)/doc/tqt3-examples/ -name 'tt3'`; do rm -f "$$a"; done
	for a in `cd $(DEBIAN)/doc/tqt3-examples/ && find $(DEBIAN)/doc/tqt3-examples/ -name '.moc'`; do rm -rf "$$a"; done
	for a in `cd $(DEBIAN)/doc/tqt3-examples/ && find $(DEBIAN)/doc/tqt3-examples/ -name '.obj'`; do rm -rf "$$a"; done
	for a in `cd $(DEBIAN)/doc/tqt3-examples/ && find $(DEBIAN)/doc/tqt3-examples/ -name 'Makefile'`; do rm -f "$$a"; done
	install -Dpm 755 `pwd`/debian/maintain/build-examples.sh `pwd`/debian/doc/tqt3-examples/build-examples
	cd `pwd`/debian/doc/ && \
	find tqt3-examples/ -type f -print0 | LC_ALL=C sort -z | \
	tar cvv --no-recursion --null -T - \
	    --mode=u+rw,go=rX,a-s \
	    --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime | \
	gzip -n > tqt3-examples.tar.gz
	install -D `pwd`/debian/doc/tqt3-examples.tar.gz `pwd`/debian/tqt3-examples/usr/share/doc/tqt3-examples/tqt3-examples.tar.gz

	# proceed
	dh_compress -i -Xhtml/
	dh_link -i

	dh_fixperms -i
	dh_installdeb -i

	dh_perl -i
	dh_shlibdeps -i

	# fix shlibdeps madness
	for a in `find debian/ -name '*.substvars'`; do cat "$$a" | sed 's/, xlibs (>> 4.1.0)//g' > "$$a".new &&  mv "$$a.new" "$$a"; done

	dh_gencontrol -i
	dh_md5sums -i

	dh_builddeb -i $(DEB_DH_BUILDDEB_ARGS)

binary-arch: build install

	dh_testdir
	dh_testroot
	dh_installdirs -a

	## create tqt3-apps-dev-package
	install -d $(P_APPSDEV)/usr/include/tqt3/
	cp `pwd`/tools/designer/interfaces/*.h $(P_APPSDEV)/usr/include/tqt3/
	cp `pwd`/tools/designer/editor/*.h $(P_APPSDEV)/usr/include/tqt3/
	rm -rf `pwd`/debian/tqt3-apps-dev/usr/include/tqt3/preferences.ui.h

	## tqvfb package
	install -m644 -D `pwd`/tools/tqvfb/pda.skin `pwd`/debian/tqt3-dev-tools-embedded/etc/tqt3/tqvfb/pda.skin
	install -m644 -D `pwd`/tools/tqvfb/pda_down.png `pwd`/debian/tqt3-dev-tools-embedded/usr/share/tqvfb/pda_down.png
	install -m644 -D `pwd`/tools/tqvfb/pda_up.png `pwd`/debian/tqt3-dev-tools-embedded/usr/share/tqvfb/pda_up.png

	# remove utterly ugle symlink
	rm -rf `pwd`/debian/tqt3-dev-tools//usr/share/tqt3/mkspecs/linux-g++/linux-g++

	# language file for linguist
	install -d `pwd`/debian/tqt3-linguist/usr/share/doc/tqt3-linguist/
	cp translations/template.ts `pwd`/debian/tqt3-linguist/usr/share/doc/tqt3-linguist/qt_untranslated.ts

	# fix that stupid friggin professional file
	perl -pi -e 's{\$$\$$QT_SOURCE_TREE}{$(QTDIR)}' src/qt_professional.pri

	## i18n files for designer, linguist and assistant
	(cd `pwd`/tools/designer/designer/ && tqlrelease designer.pro)
	for a in `cd tools/designer/designer/ && find . -name 'designer_*.qm' | sed 's/designer_//' | sed 's/\.qm//' | sed 's/\.\///g'`; do \
	install -m644 -D tools/designer/designer/designer_"$$a".qm `pwd`/debian/tqt3-designer/usr/share/tqt3/translations/designer_"$$a".qm; done
	rm -rf `pwd`/tools/designer/designer/*.qm

	(cd `pwd`/tools/assistant/ && tqlrelease assistant.pro)
	for a in `cd tools/assistant/ && find . -name 'assistant_*.qm' | sed 's/assistant_//' | sed 's/\.qm//' | sed 's/\.\///g'`; do \
	install -m644 -D tools/assistant/assistant_"$$a".qm `pwd`/debian/tqt3-assistant/usr/share/tqt3/translations/assistant_"$$a".qm; done
	rm -rf `pwd`/tools/assistant/*.qm `pwd`/debian/libtqt3-i18n/usr/share/tqt3/translations/assistant_de.qm

	(cd `pwd`/tools/linguist/linguist/ && tqlrelease linguist.pro)
	for a in `cd tools/linguist/linguist/ && find . -name 'linguist_*.qm' | sed 's/linguist_//' | sed 's/\.qm//' | sed 's/\.\///g'`; do \
	install -m644 -D tools/linguist/linguist/linguist_"$$a".qm `pwd`/debian/tqt3-linguist/usr/share/tqt3/translations/linguist_"$$a".qm; done
	rm -rf `pwd`/tools/linguist/linguist/*.qm

	# include logo32 for every program
	cd `pwd`/debian/tqt3-designer/usr/share/tqt3/doc/html && for a in `find . -name '*.html'`; \
	do cat "$$a" | sed 's/logo32/logo32-designer/g' > "$$a".new && mv "$$a".new "$$a"; done

	cd `pwd`/debian/tqt3-linguist/usr/share/tqt3/doc/html && for a in `find . -name '*.html'`; \
	do cat "$$a" | sed 's/logo32/logo32-linguist/g' > "$$a".new && mv "$$a".new "$$a"; done

	cd `pwd`/debian/tqt3-assistant/usr/share/tqt3/doc/html && for a in `find . -name '*.html'`; \
	do cat "$$a" | sed 's/logo32/logo32-assistant/g' > "$$a".new && mv "$$a".new "$$a"; done

	cd `pwd`/debian/tqt3-dev-tools/usr/share/tqt3/doc/html && for a in `find . -name '*.html'`; \
	do cat "$$a" | sed 's/logo32/logo32-qmake/g' > "$$a".new && mv "$$a".new "$$a"; done

	for a in designer linguist assistant; do install -m644 -D `pwd`/doc/html/logo32.png `pwd`/debian/tqt3-"$$a"/usr/share/tqt3/doc/html/logo32-"$$a".png; done
	install -m644 -D `pwd`/doc/html/logo32.png `pwd`/debian/tqt3-dev-tools/usr/share/tqt3/doc/html/logo32-qmake.png

	# fix qmake.conf files
	cd `pwd`/debian/tqt3-dev-tools/usr/share/tqt3/mkspecs/ && for a in *; do cd "$$a" && cat qmake.conf | sed 's/\$$(QTDIR)\/include/\/usr\/share\/tqt3\/include/g' | sed 's/\$$(QTDIR)/\/usr\/share\/tqt3/g' | \
	sed 's/\-I\/usr\/include/&\/tqt3/g' >> qmake.conf.new && mv qmake.conf.new qmake.conf && cd ../; done

	dh_link -ptqt3-designer usr/share/tqt3/doc/html usr/share/doc/tqt3-designer/html
	dh_link -ptqt3-assistant usr/share/tqt3/doc/html usr/share/doc/tqt3-assistant/html
	dh_link -ptqt3-linguist usr/share/tqt3/doc/html usr/share/doc/tqt3-linguist/html
	dh_link -ptqt3-dev-tools usr/share/tqt3/doc/html usr/share/doc/tqt3-dev-tools/html

	# copy README.Debian
	for a in libtqt3-mt-dev libtqt3-mt tqt3-doc; do install -D `pwd`/debian/README.Debian `pwd`/debian/"$$a"/usr/share/doc/"$$a"/README.Debian; done

	# install the qmake binary
	rm -rf `pwd`/debian/tqt3-dev-tools/usr/bin/tqmake
	install -D `pwd`/qmake/tqmake `pwd`/debian/tqt3-dev-tools/usr/bin/tqmake

	# Install source for the designer tools, such as tqtcreatecw.
	cp -ra tools/designer/tools debian/tqt3-designer/usr/share/tqt3/tools
	rm -f debian/tqt3-designer/usr/share/tqt3/tools/tqtcreatecw/tqtcreatecw
	rm -rf debian/tqt3-designer/usr/share/tqt3/tools/tqtcreatecw/.moc
	rm -rf debian/tqt3-designer/usr/share/tqt3/tools/tqtcreatecw/.obj
	rm -f debian/tqt3-designer/usr/share/tqt3/tools/tqtcreatecw/Makefile
	rm -f debian/tqt3-designer/usr/share/tqt3/tools/tqtconv2ui/tqtconv2ui
	rm -rf debian/tqt3-designer/usr/share/tqt3/tools/tqtconv2ui/.moc
	rm -rf debian/tqt3-designer/usr/share/tqt3/tools/tqtconv2ui/.obj
	rm -f debian/tqt3-designer/usr/share/tqt3/tools/tqtconv2ui/Makefile

	# run remaining debhelper scripts
	dh_installdocs -a $(IBASE) -XREADME.Debian
	dh_installmenu -a $(IBASE)

	dh_installchangelogs -a $(IBASE) changes-3.3.8
	dh_installchangelogs -a $(IBASE) changes-3.3.8b

	dh_installman -a $(IBASE)

	dh_link -a $(IBASE)
	dh_strip -a $(IBASE) --dbg-package=tqt-x11-free-dbg
	$(if $(wildcard /usr/bin/dh_strip_nondeterminism),\
	dh_strip_nondeterminism -a $(IBASE))
	dh_compress -a $(IBASE)
	dh_fixperms -a $(IBASE)

	# run remaining debhelper scripts
	dh_makeshlibs -a $(IBASE) -V
	dh_installdeb -a $(IBASE)
	dh_perl -a $(IBASE)
	dh_shlibdeps -a $(IBASE) -l`pwd`/debian/libtqt3-mt/usr/lib

	# fix shlibdeps madness
	for a in `find debian/ -name '*.substvars'`; do cat "$$a" | sed 's/, xlibs (>> 4.1.0)//g' > "$$a".new &&  mv "$$a.new" "$$a"; done

	# fix conffiles file for tqt3-dev-tools-embedded
	echo "/etc/tqt3/tqvfb/pda.skin" > `pwd`/debian/tqt3-dev-tools-embedded/DEBIAN/conffiles

	dh_gencontrol -a $(IBASE)
	dh_md5sums -a $(IBASE)
	dh_builddeb -a $(IBASE) $(DEB_DH_BUILDDEB_ARGS)

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