#!/usr/bin/make -f
# (c) 2012, Eric Maeker, MD (fr), The FreeMedForms project, BSD revised license
# The @ in front of a command prevents make from displaying

# var: keep the project order (should begin with freemedforms) 
FREEMEDFORMS_EMR := freemedforms
FREEDIAMS := freediams
FREEACCOUNT := freeaccount

QMAKE_CONFIG := "CONFIG+=LINUX_INTEGRATED" -r
QMAKE_SUBPROJECT_CONFIG := "CONFIG+=dontbuildlibs" "CONFIG+=dontinstallresources" "CONFIG+=dontinstalllibs"
QMAKE_IPATH := "INSTALL_ROOT_PATH=/usr/"

# func
AUTOCONF_MAIN =  -D$(1) -- $(QMAKE_CONFIG) $(QMAKE_IPATH) LOWERED_APPNAME="$(1)" $(1).pro
AUTOCONF_SUB =  -D$(1) -- $(QMAKE_CONFIG) $(QMAKE_IPATH) $(QMAKE_SUBPROJECT_CONFIG) LOWERED_APPNAME="$(1)" $(1).pro

%:
	dh $@ --parallel --buildsystem=qmake_qt4 # --dbg-package=freemedforms-project-dbg

override_dh_auto_configure:
	lrelease global_resources/translations/*.ts
	dh_auto_configure $(call AUTOCONF_MAIN, $(FREEMEDFORMS_EMR)) $(extra_configure_opts)
	dh_auto_configure $(call AUTOCONF_SUB, $(FREEDIAMS)) $(extra_configure_opts)
	dh_auto_configure $(call AUTOCONF_SUB, $(FREEACCOUNT)) $(extra_configure_opts)

override_dh_auto_clean:
	rm -Rf bin
	rm -Rf build
	rm -f global_resources/translations/[a-ps-z]*.qm
	dh_auto_clean
	find . -name Makefile -delete

override_dh_auto_build:
	dh_auto_build -D$(FREEMEDFORMS_EMR)
	dh_auto_build -D$(FREEDIAMS)
	dh_auto_build -D$(FREEACCOUNT)

override_dh_auto_install:
	dh_auto_install -D$(FREEMEDFORMS_EMR) -Smakefile -- INSTALL_ROOT=$(CURDIR)/debian/tmp
	dh_auto_install -D$(FREEDIAMS) -Smakefile -- INSTALL_ROOT=$(CURDIR)/debian/tmp
	dh_auto_install -D$(FREEACCOUNT) -Smakefile -- INSTALL_ROOT=$(CURDIR)/debian/tmp

	# Remove empty dirs
	find $(CURDIR)/debian/tmp/usr/share -type d -empty -delete

