#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess. 

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

#export DEB_BUILD_ARCH = arm-linux
#export DEB_BUILD_GNU_SYSTEM = arm-linux

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

ifneq (,$(findstring thumb, $(DEB_BUILD_OPTIONS)))
	CFLAGS += -mthumb
endif

ifeq (,$(findstring nolauncher,$(DEB_BUILD_OPTIONS)))
	LAUNCHER = yes
	LAUNCHER_DEPENDS = -Vlauncher:Depends="maemo-launcher"
	LAUNCHER_CFLAGS = $(shell pkg-config --cflags maemo-launcher-app)
	LAUNCHER_LDFLAGS = $(shell pkg-config --libs maemo-launcher-app)
endif

configure: configure-stamp
configure-stamp:
	$(CURDIR)/autogen.sh
	CFLAGS="$(CFLAGS)" $(CURDIR)/configure --prefix=/usr

	touch configure-stamp

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

	# Add here commands to compile the package.
	$(MAKE) \
	LD_LIBRARY_PATH=$(libpath):$(LD_LIBRARY_PATH) \
	MAEMO_LAUNCHER_CFLAGS="$(LAUNCHER_CFLAGS)" \
	MAEMO_LAUNCHER_LDFLAGS="$(LAUNCHER_LDFLAGS)"


	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f configure-stamp build-stamp

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean

	#-rm -rf ${PACKAGE}

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/<packagename>
	#$(MAKE) prefix=debian/`dh_listpackages` install
	$(MAKE) install DESTDIR=$(CURDIR)/debian/fmdir

ifeq "$(strip $(LAUNCHER))" "yes"
	mv $(CURDIR)/debian/fmdir/usr/bin/ossofilemanager \
		$(CURDIR)/debian/fmdir/usr/bin/ossofilemanager.launch
	ln -s /usr/bin/maemo-invoker \
	 	$(CURDIR)/debian/fmdir/usr/bin/ossofilemanager
endif

	dh_link
	dh_install --sourcedir=debian/fmdir

	 	
# 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_link
	dh_strip --dbg-package="osso-filemanager-ui"
	dh_compress
	dh_fixperms
	dh_makeshlibs -V
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol -- $(LAUNCHER_DEPENDS)
	dh_builddeb

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