#!/usr/bin/make -f
# spice-gtk debian/rules using debhelper
# Copyright (C) 2011 Liang Guo <bluestonechina@gmail.com>

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
  CXXFLAGS += -g
endif

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

#libspice_client_gtkinclude_HEADERS and libspice_client_glibinclude_HEADERS 
#should be copied to build directory, or build will fail.
 
build-arch: build
build-indep: build

build: build-stamp
build-stamp: build-gtk3-stamp build-gtk2-stamp
	touch build-stamp

build-gtk2-stamp:
	dh_auto_configure -- \
		--enable-smartcard=no --with-gtk=2.0 --disable-static \
		--enable-introspection
	dh_auto_build 
	touch build-gtk2-stamp

build-gtk3-stamp:
	dh_auto_configure -B$(CURDIR)/build-gtk3  -- \
		--enable-smartcard=no --with-gtk=3.0 --disable-static \
		--enable-introspection
	dh_auto_build -B$(CURDIR)/build-gtk3 -D$(CURDIR)
	touch build-gtk3-stamp

clean: clean-patched 
clean-patched: 
	dh_testdir
	dh_testroot
	[ ! -d $(CURDIR)/build-gtk3 ] || rm -rf $(CURDIR)/build-gtk3
	[ ! -f Makefile ] || $(MAKE) clean
	[ ! -f po/Makefile ] || $(MAKE) -C po distclean
	[ ! -f common/Makefile ] || $(MAKE) -C common distclean
	[ ! -f gtk/Makefile ] || $(MAKE) -C gtk distclean
	[ ! -f python_modules/Makefile ] || $(MAKE) -C python_modules distclean
	-rm Makefile data/Makefile config.h config.log config.status \
		libtool spice-client-glib-2.0.pc spice-client-gtk-2.0.pc \
		spice-client-gtk-3.0.pc spice-controller.pc doc/Makefile \
		doc/reference/Makefile stamp-h1
	dh_clean 

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	$(MAKE) -C $(CURDIR)/build-gtk3 install DESTDIR=$(CURDIR)/debian/tmp
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
	mv $(CURDIR)/debian/tmp/usr/bin/snappy $(CURDIR)/debian/tmp/usr/bin/spicy-snapshot
	dh_install --sourcedir=debian/tmp
	touch install-stamp

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs 
	dh_installexamples
	dh_installman
	dh_python2 --no-guessing-versions
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_girepository
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

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

