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

DEBDIR = ..

# Build options
ENABLE_MULTITOUCH = false
DEFAULT_PLUGIN = nemo-keyboard.qml
SERVER_ARGUMENTS  = "-software -use-self-composition -graphicssystem raster"

QMAKE_OPTIONS += MALIIT_SERVER_ARGUMENTS=$(SERVER_ARGUMENTS)
QMAKE_OPTIONS += M_IM_ENABLE_MULTITOUCH=$(ENABLE_MULTITOUCH)
QMAKE_OPTIONS += M_IM_DEFAULT_PLUGIN=$(DEFAULT_PLUGIN) M_IM_DEFAULT_HW_PLUGIN=""
QMAKE_OPTIONS += CONFIG+="notests nosdk"

configure: configure-stamp
configure-stamp:
	dh_testdir
	for p in debian/patches/*; do patch -t -p1 < $$p; done
	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 $(EXCLUSIONS)

	# Then proceed to normal installation
	GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=1 INSTALL_ROOT=$(CURDIR)/debian/tmp make  $(PARALLEL_MAKEFLAGS) install
	# clean unused elements
	rm -rf $(CURDIR)/debian/tmp/usr/lib/maliit-framework-tests
	rm -rf $(CURDIR)/debian/tmp/usr/bin/maliit-exampleapp-*


# 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 $(EXCLUSIONS)
	dh_testroot $(EXCLUSIONS)
	dh_installchangelogs $(EXCLUSIONS)
	dh_installdocs $(EXCLUSIONS)
	dh_install --list-missing --fail-missing --sourcedir=debian/tmp $(EXCLUSIONS) -v
	dh_gconf $(EXCLUSIONS)
	dh_link $(EXCLUSIONS)
	dh_strip --dbg-package=libmaliit1-dbg --dbg-package=maliit-server-dbg --dbg-package=libmaliit-plugins0-dbg --dbg-package=libmaliit-plugins-quick0-dbg
	dh_compress $(EXCLUSIONS)
	dh_fixperms $(EXCLUSIONS) -X/etc/X11/Xsession.post
	dh_makeshlibs $(EXCLUSIONS)
	dh_installdeb $(EXCLUSIONS)

	# Unknown why this is needed. shlibdeps should consider this to be a private library and let it go with a warning
	LD_LIBRARY_PATH=`pwd`/debian/tmp/usr/lib/maliit/plugins-0.80/factories:$$LD_LIBRARY_PATH dh_shlibdeps $(EXCLUSIONS)
	dh_gencontrol $(EXCLUSIONS)
	dh_md5sums $(EXCLUSIONS)
	dh_builddeb --destdir=$(DEBDIR) $(EXCLUSIONS)

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