#!/usr/bin/make -f

export DH_OPTIONS


DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


CFLAGS = -Wall -g
LDFLAGS = -Wl,--as-needed

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

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	#/usr/bin/ruby1.8 ./configure.rb --prefix=/usr --sdk --tests --examples
	/usr/bin/ruby1.8 ./configure.rb --prefix=/usr

	touch configure-stamp

#Architecture 
build: build-arch build-indep

build-arch: build-arch-stamp
build-arch-stamp: configure-stamp 

	# Add here commands to compile the arch part of the package.
	$(MAKE) 
	touch $@

build-indep: build-indep-stamp
build-indep-stamp: configure-stamp 

	# Add here commands to compile the indep part of the package.
	#$(MAKE) doc
	touch $@

clean: 
	dh_testdir
	dh_testroot
	rm -f build-arch-stamp build-indep-stamp configure-stamp #CONFIGURE-STAMP#
	rm -rf bin lib

	-$(MAKE) distclean

	# Add here commands to clean up after the build process.
	dh_clean 

install: install-indep install-arch
install-indep:
	dh_testdir
	dh_testroot
	dh_clean -k -i 
	dh_installdirs -i

	# Add here commands to install the indep part of the package into
	# debian/<package>-doc.
	#INSTALLDOC#

	dh_install -i

install-arch:
	dh_testdir
	dh_testroot
	dh_clean -k -s 
	dh_installdirs -s

	# Add here commands to install the arch part of the package into 
	# debian/tmp.
	$(MAKE) install INSTALL_ROOT=$(CURDIR)/debian/tmp

	mkdir -p $(CURDIR)/debian/tmp/usr/share/applications/hildon
	mv $(CURDIR)/debian/tmp/usr/bin/qimsys $(CURDIR)/debian/tmp/usr/bin/qimsys.bin
	cp -a $(CURDIR)/debian/qimsys.sh $(CURDIR)/debian/tmp/usr/bin/qimsys
	mv $(CURDIR)/debian/tmp/usr/share/applications/qimsys.desktop $(CURDIR)/debian/tmp/usr/share/applications/hildon

	dh_install --sourcedir=$(CURDIR)/debian/tmp -s
# Must not depend on anything. This is to be called by
# binary-arch/binary-indep
# in another 'make' thread.
binary-common:
# Build architecture independant packages using the common target.
binary-indep: 
#binary-indep: build-indep install-indep
	#$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
#	dh_testdir
#	dh_testroot
#	dh_installchangelogs 
#	dh_installdocs
#	dh_installexamples
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate	
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_installman
#	dh_link
#	dh_strip
#	dh_compress 
#	dh_fixperms
#	dh_perl
#	dh_makeshlibs
#	dh_installdeb
#	dh_shlibdeps
#	dh_gencontrol
#	dh_md5sums
#	dh_builddeb
# Build architecture dependant packages using the common target.
binary-arch: build-arch install-arch
	#$(MAKE) -f debian/rules DH_OPTIONS=-s binary-common
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	#dh_installdocs
	#dh_installexamples
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate	
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress 
	dh_fixperms
#	dh_perl
	dh_makeshlibs
	dh_installdeb
#	dh_shlibdeps
	dh_gencontrol
	maemo-optify
	dh_md5sums
	dh_builddeb

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