#!/usr/bin/make -f

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

PJPROJECT_VERSION := 2.1.0

%:
	dh $@ 

override_dh_auto_configure:
#	cd daemon/libs/ && ./compile_pjsip.sh
	cd daemon/libs/pjproject-$(PJPROJECT_VERSION) && CFLAGS=-fPIC ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --disable-sound --disable-video
	cd daemon && ./autogen.sh --prefix=/usr
	cd daemon && ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS) -fPIC" LDFLAGS="-Wl,-z,defs" --disable-doxygen
	cd gnome && ./autogen.sh --prefix=/usr
	cd gnome && ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"
	cd kde && ./config.sh --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"
	cd plugins && ./autogen.sh --prefix=/usr
	cd plugins && ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"

override_dh_auto_build:
#	cd daemon/libs/ && ./compile_pjsip.sh
	cd daemon/libs/pjproject-$(PJPROJECT_VERSION) && make
	cd daemon && make
	cd gnome && make
	cd kde/build && make
	cd plugins && make

override_dh_auto_clean:
	cd daemon/libs/pjproject-$(PJPROJECT_VERSION) && [ ! -f build.mak ] || $(MAKE) distclean
	cd daemon && [ ! -f Makefile ] || $(MAKE) distclean
	cd gnome && [ ! -f Makefile ] || $(MAKE) distclean
	cd kde && [ ! -f Makefile ] || $(MAKE) distclean
	cd plugins && [ ! -f Makefile ] || $(MAKE) distclean
	dh_auto_clean

override_dh_auto_install:
	cd daemon && make DESTDIR=$(CURDIR)/debian/sflphone-daemon install
	cd gnome && make DESTDIR=$(CURDIR)/debian/sflphone-gnome install
	cd kde/build && make DESTDIR=$(CURDIR)/debian/sflphone-kde install
	cd plugins && make DESTDIR=$(CURDIR)/debian/sflphone-evolution 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

	# Move architecture-independent files to the data package
	if test -d "$(CURDIR)/debian/sflphone-data/usr/share/sflphone/" ; then \
	    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/ ;\
	fi
	rm -rf $(CURDIR)/debian/sflphone-gnome/usr/share/sflphone/
	rm -rf $(CURDIR)/debian/sflphone-daemon/usr/share/sflphone/

	dh_auto_install

get-orig-source:
	uscan --download-current-version
