#!/usr/bin/make -f
# (c) 2011-2013, Eric Maeker, MD (fr), The FreeMedForms project
# This code is released under the BSD 3 clause license

#--------------------------------------------------------------------
# Comments on the updates:
#--------------------------------------------------------------------
# Updating from 0.8.2 to 0.9.0
# The optional plugins and features can now be defined in the 
#     buildspecs/optionalplugins.pri
#     buildspecs/optionalfeatures.pri
# You can edit these files and modify the plugins/features you want to build/ignore.
#
# The qmake command line is then shortened to
#     qmake -r {spec} {release config} {LinuxIntegratedConfigFlag if required} {libs tags} {project_file}
# Find the documentation of the new build process here
#     http://www.freemedforms.com/en/code/buildsystem
#
# FreeAccount is now obsolete as unmaintained.
#--------------------------------------------------------------------
# Updating form 0.7.x to 0.8.x
# The new build system of the FreeMedForms project (0.8+) creates the
#   buildpsecs/compiling.pri
# during the qmake step. This file differs from apps to apps, so we need
# cache it and reuse it before doing any make steps.
#--------------------------------------------------------------------

# vars
FREEMEDFORMS_EMR:=freemedforms
FREEDIAMS:=freediams

QMAKE:=qmake-qt4
QMAKE_GLOBAL_CONFIG:="CONFIG+=LINUX_INTEGRATED" "CONFIG+=dontbuildquazip"
QMAKE_SUBPROJECT_CONFIG := "CONFIG+=dontbuildlibs" "CONFIG+=dontinstallresources" "CONFIG+=dontinstalllibs"
QMAKE_IPATH := "INSTALL_ROOT_PATH=/usr/"
QMAKE_COMPILING:=buildspecs/compiling.pri

# func
AUTOCONF_MAIN = -r $(QMAKE_GLOBAL_CONFIG) $(QMAKE_IPATH) $(1).pro
AUTOCONF_SUB = -r $(QMAKE_GLOBAL_CONFIG) $(QMAKE_IPATH) $(1).pro

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

override_dh_auto_configure:
	lrelease global_resources/translations/*.ts

	dh_auto_configure -D$(FREEMEDFORMS_EMR) -- $(call AUTOCONF_MAIN, $(FREEMEDFORMS_EMR)) $(extra_configure_opts)
	cp $(QMAKE_COMPILING) build/$(FREEMEDFORMS_EMR).pri

	dh_auto_configure -D$(FREEDIAMS) -- $(call AUTOCONF_SUB, $(FREEDIAMS)) $(extra_configure_opts)
	cp $(QMAKE_COMPILING) build/$(FREEDIAMS).pri

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:
	cp build/$(FREEMEDFORMS_EMR).pri $(QMAKE_COMPILING)
	dh_auto_build -D$(FREEMEDFORMS_EMR)

	cp build/$(FREEDIAMS).pri $(QMAKE_COMPILING)
	dh_auto_build -D$(FREEDIAMS)

override_dh_auto_install:
	cp build/$(FREEMEDFORMS_EMR).pri $(QMAKE_COMPILING)
	dh_auto_install -D$(FREEMEDFORMS_EMR) -Smakefile -- INSTALL_ROOT=$(CURDIR)/debian/tmp

	cp build/$(FREEDIAMS).pri $(QMAKE_COMPILING)
	dh_auto_install -D$(FREEDIAMS) -Smakefile -- INSTALL_ROOT=$(CURDIR)/debian/tmp

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

get-orig-source:
	mkdir -p ../tarballs
	uscan --verbose --force-download --destdir=../tarballs
