#!/usr/bin/make -f
# This file was originally written by Joey Hess and Craig Small.

include /usr/share/quilt/quilt.make

CFLAGS = -Wall -g

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

ifneq (,$(findstring vfp,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -mcpu=arm1136jf-s -mtune=arm1136jf-s -mfpu=vfp -mfloat-abi=softfp
endif

MAKE += LNG=ENGLISH PREFIX=/usr MANPREFIX=/usr/share WITH_MAEMO5=yes BUILDFLAGS="$(CFLAGS)" 

build: patch build-stamp

build-stamp: 
	dh_testdir

	$(MAKE)

	touch $@

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

	-$(MAKE) clean
	rm -f $(CURDIR)/sgp/SetTitle.d $(CURDIR)/sgp/SetTitle.o

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	$(MAKE) DESTDIR=$(CURDIR)/debian/ja2 install
	install -m755 -D $(CURDIR)/debian/ja2launcher.sh $(CURDIR)/debian/ja2/usr/bin/ja2launcher
	uudecode $(CURDIR)/debian/ja2.png.uuencoded -o $(CURDIR)/debian/ja2/usr/share/icons/hicolor/scalable/apps/ja2.png
	install -m644 $(CURDIR)/debian/ja2.service $(CURDIR)/debian/ja2/usr/share/dbus-1/services/
	install -m644 $(CURDIR)/ja2-stracciatella.desktop $(CURDIR)/debian/ja2/usr/share/applications/hildon/ja2.desktop
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs Changelog
	dh_installdocs
	install -m644 $(CURDIR)/"SFI Source Code license agreement.txt" $(CURDIR)/debian/ja2/usr/share/doc/ja2/
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep: build install
# We have nothing to do by default.

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