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

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

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

CFLAGS = -Wall -g -fPIC -Werror

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

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -DMAEMOSEC_DEBUG_ENABLED
endif

# shared library versions, option 1
version=0.0.0
major=0
# option 2, assuming the library is created as src/.libs/libfoo.so.2.0.5 or so
#version=`ls src/.libs/lib*.so.* | \
# awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'`
#major=`ls src/.libs/lib*.so.* | \
# awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'`

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	./autogen.sh
	./configure --prefix=/usr
	touch $@


build: build-stamp
build-stamp: configure-stamp 
	dh_testdir
	$(MAKE)
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean 

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

install-arch:
	dh_testdir
	dh_testroot
	dh_clean -k -s
	install -d debian/tmp debian/libmaemosec0 debian/libmaemosec-dev debian/libmaemosec-certman0 debian/libmaemosec-certman-dev debian/maemosec-certman-tools debian/maemosec-certman-common-ca
	dh_installdirs -s
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
	dh_movefiles
	dh_install -s

binary-common: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs debian/changelog
	dh_installdocs
#	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_installman
	dh_link
	dh_strip --dbg-package="libmaemosec0" \
		 --dbg-package="libmaemosec-certman0" \
		 --dbg-package="maemosec-certman-tools"
	dh_compress
	dh_fixperms
#	dh_gconf
#	dh_perl
#	dh_python
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independent packages using the common target.
binary-indep: build install-indep
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build install-arch
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

# Build architecture-dependent files here.

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