#!/usr/bin/make -f

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

OPTS = ""
CFLAGS += -g

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)))
	OPTS += "--enable-maemo-launcher=yes"
	USE_MAEMO_LAUNCHER = true
endif

PACKAGENAME=scv-reader

config.status:
	dh_testdir
	autoreconf -s -i -m
	CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/sbin --enable-final $(OPTS)

build: build-stamp

build-stamp: config.status
	dh_testdir
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -rf *stamp
	-$(MAKE) maintainer-clean
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k

	$(MAKE) install DESTDIR=`pwd`/debian/$(PACKAGENAME)

binary-indep: build install

binary-arch: build install
	dh_maemo_package_icons
	dh_testdir
	dh_testroot
	dh_installdocs -a AUTHORS NEWS README
	dh_installmenu -a

	dh_installchangelogs ChangeLog -a

	dh_link -a

	if test "x$(USE_MAEMO_LAUNCHER)" = "xtrue"; then \
		dh_maemolauncher; \
	fi

	dh_strip --dbg-package=$(PACKAGENAME)
	dh_compress -a

	dh_fixperms -a
	dh_installdeb -a

	dh_shlibdeps -a
	dh_gencontrol -a

	dh_md5sums -a
	# maemo-optify all packages the standard way, except pidgin-emotes-default
	if test -x /usr/bin/maemo-optify; then \
		maemo-optify; \
	fi
	dh_builddeb -a
	dh_maemo_package_icons -r

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