#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# FIXME: use cdbs-dh7 and cmake magic stuff instead

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

configure: configure-stamp
configure-stamp:
	dh_testdir

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	mkdir -p $(CURDIR)/qtm-geoservices-extras/build
	cd $(CURDIR)/qtm-geoservices-extras/build && cmake -DCMAKE_PREFIX_PATH=/usr/bin -DCMAKE_INSTALL_PREFIX=/opt/lugdulov/lib -DMOBILITY_VERSION=1.2 -DCMAKE_BUILD_TYPE=Release $(CURDIR)/qtm-geoservices-extras/ && $(MAKE)

	mkdir -p $(CURDIR)/build
	cd $(CURDIR)/build && cmake -DCMAKE_PREFIX_PATH=/usr/bin -DCMAKE_INSTALL_PREFIX=/opt/lugdulov -DQMAPCONTROL=ON -DMOBILITY_VERSION=1.2 -DCMAKE_BUILD_TYPE=Release $(CURDIR) && $(MAKE)
	# Append -DQJSON_LIBRARIES=/home/iksaif/dev/qjson-0.7.1/build/lib/libqjson.a -DQJSON_INCLUDE_DIR=/home/iksaif/dev/qjson-0.7.1/src/ to use a static qjson
	# Append -DMOBILITY_MKSPEC_VERSION=11 to use libqtm-11-dev

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	rm -rf $(CURDIR)/qtm-geoservices-extras/build
	rm -rf $(CURDIR)/build
	dh_clean debian/shlibs.local
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	cd $(CURDIR)/qtm-geoservices-extras/build && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
	cd $(CURDIR)/build && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
	chmod +x debian/tmp/opt/lugdulov/bin/lugdulov-wrapper


# 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_install --sourcedir=debian/tmp
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps -l/opt/qtm12/lib/
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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