#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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


# 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)
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
else
CROSS= --build $(DEB_BUILD_GNU_TYPE)
endif


config.status:
	dh_testdir
	# Add here commands to configure the package.
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub sflphone-common/config.sub
	cp -f /usr/share/misc/config.sub sflphone-client-gnome/config.sub
	cp -f /usr/share/misc/config.sub sflphone-common/libs/pjproject/config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.sub sflphone-common/config.guess
	cp -f /usr/share/misc/config.sub sflphone-client-gnome/config.guess
	cp -f /usr/share/misc/config.sub sflphone-common/libs/pjproject/config.guess
endif
	cd sflphone-common/libs/pjproject && ./configure $(CROSS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --disable-ilbc-codec
	cd sflphone-common && ./autogen.sh --prefix=/usr
	cd sflphone-common && ./configure $(CROSS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs" --disable-doxygen --without-ilbc
	cd sflphone-client-gnome && ./autogen.sh --prefix=/usr
	cd sflphone-client-gnome && ./configure $(CROSS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"

build-arch:
build-indep:
build: build-stamp

build-stamp:  config.status 
	dh_testdir

	# Add here commands to compile the package.
	cd sflphone-common/libs/pjproject && $(MAKE) V=1
	cd sflphone-common && $(MAKE) V=1
	cd sflphone-client-gnome && $(MAKE) V=1
	touch $@

clean: 
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	# Add here commands to clean up after the build process.
	cd sflphone-common/libs/pjproject && [ ! -f build.mak ] || $(MAKE) distclean
	cd sflphone-common && [ ! -f Makefile ] || $(MAKE) distclean
	cd sflphone-client-gnome && [ ! -f Makefile ] || $(MAKE) distclean

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_prep  
	dh_installdirs

	# Add here commands to install the package into debian/sflphone.
	cd sflphone-common && $(MAKE) DESTDIR=$(CURDIR)/debian/sflphone-daemon install
	cd sflphone-client-gnome && $(MAKE) DESTDIR=$(CURDIR)/debian/sflphone-gnome install

	# Move gconf schemas to the right place
	mv $(CURDIR)/debian/sflphone-gnome/usr/etc/gconf/schemas/* $(CURDIR)/debian/sflphone-gnome/usr/share/gconf/schemas/
	cd $(CURDIR)/debian/sflphone-gnome/usr/ && rmdir -p etc/gconf/schemas

	# Remove a few files
	rm -rf $(CURDIR)/debian/sflphone-daemon/usr/include
	rm -f $(CURDIR)/debian/sflphone-daemon/usr/bin/dbusxx-*
	rm -f $(CURDIR)/debian/sflphone-daemon/usr/bin/*Tester
	rm -f $(CURDIR)/debian/sflphone-gnome/usr/bin/sflphone
	rm -f $(CURDIR)/debian/sflphone-daemon/usr/lib/*.la
	rm -f $(CURDIR)/debian/sflphone-daemon/usr/lib/*.a
	rm -f $(CURDIR)/debian/sflphone-daemon/usr/lib/*.so

	# Move architecture-independent files to the data package
	mv $(CURDIR)/debian/sflphone-gnome/usr/share/sflphone/* $(CURDIR)/debian/sflphone-data/usr/share/sflphone/
	mv $(CURDIR)/debian/sflphone-daemon/usr/share/sflphone/ringtones/ $(CURDIR)/debian/sflphone-data/usr/share/sflphone/
	rmdir $(CURDIR)/debian/sflphone-gnome/usr/share/sflphone/
	rmdir $(CURDIR)/debian/sflphone-daemon/usr/share/sflphone/

# Build architecture-independent files here.
binary-indep: install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs NEWS
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_perl
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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