#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

DEBDIR = ..

comma :=,
empty :=
space := $(empty) $(empty)


# Set the build type (debug/release)
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	QMAKE_OPTIONS+=CONFIG+=debug
else
	QMAKE_OPTIONS+=CONFIG+=release
endif

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
    INSTALL_PROGRAM += -s
endif

TMP_BUILD_OPTS = $(subst $(comma),$(space),$(DEB_BUILD_OPTIONS))

ifneq (,$(filter parallel=%,$(TMP_BUILD_OPTS)))
         NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(TMP_BUILD_OPTS)))
         PARALLEL_MAKEFLAGS += -j$(NUMJOBS)
endif

ifneq (,$(filter coverage,$(TMP_BUILD_OPTS)))
	QMAKE_OPTIONS += COV_OPTION=on
endif

ifneq (,$(filter timestamps,$(TMP_BUILD_OPTS)))
    QMAKE_OPTIONS += DEFINES+=M_TIMESTAMP
endif

ifneq (,$(filter noreactionmap,$(TMP_BUILD_OPTS)))
    QMAKE_OPTIONS += CONFIG+=noreactionmap
endif


# shared library versions, option 1
version=0.1.0
major=0

configure: configure-stamp
configure-stamp:
	dh_testdir

	/opt/qt4-maemo5/bin/qmake -r $(QMAKE_OPTIONS)

	touch configure-stamp


build: build-stamp
build-stamp: configure-stamp 
	dh_testdir

	make  $(PARALLEL_MAKEFLAGS)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot

	rm -f build-stamp configure-stamp

	make  $(PARALLEL_MAKEFLAGS) clean || true
	rm -f lib/*
	rm -rf .obj	

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/tmp

	#libmeegotouch0 package 
	INSTALL_ROOT=$(CURDIR)/debian/tmp make  $(PARALLEL_MAKEFLAGS) install


# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_install --sourcedir=debian/tmp -v 
	dh_gconf
#	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_installman
	dh_link
	dh_strip --dbg-package=meego-keyboard-quick
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb --destdir=$(DEBDIR)

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