#!/usr/bin/make -f

%:
	dh $@ --with quilt

override_dh_auto_configure:
	qmake-qt4 -r -config release "CONFIG+=LINUX_INTEGRATED" "INSTALL_ROOT_PATH=$(CURDIR)/debian/tmp/usr/" freediams.pro

# Upstream does not seem to provide a proper clean target - clean up here
override_dh_auto_clean:
	rm -rf bin/plugins/* bin/freediams
	find build -type d -name "\.*" -exec rm -rf \{\} \; 2> /dev/null || true
	rm -rf global_resources/doc/FreeDiams global_resources/doc/freediams/en/* global_resources/doc/freediams/fr/*
	rm -rf contrib/quazip/libz.a
	test ! -f Makefile || make distclean

override_dh_auto_install:
	make install

override_dh_install:
	# Install documentation
	mkdir -p $(CURDIR)/debian/tmp/usr/share/doc/freediams/en
	mkdir -p $(CURDIR)/debian/tmp/usr/share/doc/freediams/fr
	mv global_resources/doc/freediams/en/html/* $(CURDIR)/debian/tmp/usr/share/doc/freediams/en
	mv global_resources/doc/freediams/fr/html/* $(CURDIR)/debian/tmp/usr/share/doc/freediams/fr

	# Remove those Links to dynamic libraries which have no version number (this should only
	# be provided in -dev packages.  But some *.so files are real files without version number
	# FIXME
	# find $(CURDIR)/debian/tmp/usr/lib/freediams -type l -name "*.so" -exec rm -f \{\} \;

	dh_install --autodest

override_dh_shlibdeps::
	LD_LIBRARY_PATH=debian/tmp/usr/lib/freediams dh_shlibdeps -l/usr/lib/freediams

override_dh_installdeb:
	# remove extra license file
	rm -f $(CURDIR)/debian/freediams-data/usr/share/freediams/textfiles/COPYING.txt
	dh_installdeb
