#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

# This is the debhelper compatibility version to use.
#export DH_COMPAT=4 

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CFLAGS = -Wall -g

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

config.status: configure

build: build-stamp
build.indep: build-stamp.indep

build-stamp:  config.status
	dh_testdir
	./configure \
		--host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/usr \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--disable-docs --enable-pam \
	        --enable-ssl --with-ssl=/usr \
		--enable-mysql --with-mysql=/usr \
		--enable-cookies
	$(MAKE)
	touch build-stamp

build-stamp.indep:  config.status
	dh_testdir
	./configure \
		--host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/usr \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--enable-docs --enable-pam \
	        --enable-ssl --with-ssl=/usr \
		--enable-mysql --with-mysql=/usr \
		--enable-cookies
	$(MAKE) docs
	touch build-stamp.indep

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp build-stamp.indep config.status

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif


	dh_clean

install: build
	dh_testdir -a
	dh_testroot -a
	dh_clean -k -a
	dh_installdirs -a
	$(MAKE) install prefix=$(CURDIR)/debian/tmp/usr
	$(MAKE) install-contrib prefix=$(CURDIR)/debian/tmp/usr
	$(MAKE) install-checks prefix=$(CURDIR)/debian/tmp/usr
	$(MAKE) install-test prefix=$(CURDIR)/debian/tmp/usr
	# XXX this is temporary for pre 1.3.1/1.2.2 versions
	-test -e test/run-http2-tests && mv $(CURDIR)/debian/tmp/usr/lib/kannel/test/run-http2-tests $(CURDIR)/debian/tmp/usr/lib/kannel/test/run-http2-tests.sh
	dh_install -a
	dh_movefiles -a

install.indep: build.indep
	dh_testdir -i
	dh_testroot -i
	dh_clean -k -i
	dh_installdirs -i
	$(MAKE) install-docs prefix=$(CURDIR)/debian/tmp/usr
	dh_install -i
	dh_movefiles -i

# Build architecture-independent files here.
binary-indep: build.indep install.indep
	dh_testdir -i
	dh_testroot -i
#	dh_installdebconf -i
	dh_installdocs -i
#	dh_installexamples -i
#	dh_installmenu -i
#	dh_installlogrotate -i
#	dh_installemacsen -i
#	dh_installpam -i
#	dh_installmime -i
#	dh_installinit -i
#	dh_installcron -i
#	dh_installman -i
#	dh_installinfo -i
#	dh_undocumented -i
	dh_installchangelogs ChangeLog -i
	dh_link -i
#	dh_strip -i
	dh_compress -i
	dh_fixperms -i
#	dh_makeshlibs -i
	dh_installdeb -i
#	dh_perl -i
#	dh_shlibdeps -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
#	dh_installdebconf -a	
	dh_installdocs -a
	dh_installexamples -a
#	dh_installmenu -a
	dh_installlogrotate -a
#	dh_installemacsen -a
#	dh_installpam -a
#	dh_installmime -a
	dh_installinit -a
#	dh_installcron -a
	dh_installman -a
#	dh_installinfo -a
#	dh_undocumented -a
	dh_installchangelogs ChangeLog -a
	dh_link -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
#	dh_makeshlibs -a
	dh_installdeb -a
#	dh_perl -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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