#!/usr/bin/make -f
# -*- makefile -*-

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

include /usr/share/quilt/quilt.make

# This has to be exported to make some magic below work.
export DH_OPTIONS


PYTHON_EXECUTABLE = $(shell which python2.5)

configure: configure-stamp
configure-stamp: patch
	dh_testdir
	
	mkdir -p build
	cd build; cmake \
		-DWL_INSTALL_PREFIX=/opt/widelands \
		-DWL_INSTALL_DATADIR=share/games/widelands \
		-DWL_INSTALL_BINDIR=games \
		-DWL_INSTALL_LOCALEDIR=/opt/widelands/share/games/widelands/locale \
		-DCMAKE_INSTALL_PREFIX=/opt/widelands \
		-DCMAKE_BUILD_TYPE=Release \
		-DPYTHON_EXECUTABLE=$(PYTHON_EXECUTABLE)  \
		-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/debian/maemo.cmake \
		../; cat src/config.h

	
	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	cd build; make all	
		
	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	
	# Add here commands to clean up after the build process.
	rm -rf build
	find . -name '*.py[co]' -exec rm {} \;
	
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	
	# Add here commands to install the package into debian/widelands.
	#sed -i 's#INSTALL DESTINATION ".*widelands/locale" TYPE#INSTALL DESTINATION "$${CMAKE_INSTALL_PREFIX}/share/games/widelands/locale" TYPE#' build/compile/cmake_install.cmake
	cd build ; make install DESTDIR=`pwd`/../debian/tmp

	mkdir -p debian/tmp/usr/share/icons/hicolor/48x48/hildon
	cp  $(CURDIR)/pics/wl-ico-48.png $(CURDIR)/debian/tmp/usr/share/icons/hicolor/48x48/hildon/widelands.png
	mkdir -p  debian/tmp/usr/share/applications/hildon
	cp debian/widelands.desktop debian/tmp/usr/share/applications/hildon


# 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 ChangeLog
	dh_installdocs
#	dh_installexamples
	dh_install
#	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-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
