#!/usr/bin/make -f

PYVER=2.5
PYTHON=python$(PYVER)

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

d=debian/tmp
p_base=python-gnome
d_base=debian/python$(PYVER)-gnome
d_dev=debian/python$(PYVER)-gnome-dev

ifeq ($(DEB_BUILD_ARCH),armel)
   CFLAGS=-Os -mthumb -mfloat-abi=softfp -Wall -Wstrict-prototypes
else
   CFLAGS=-Os -Wall -Wstrict-prototypes
endif

config.status: configure
	dh_testdir
	PYTHON=`which $(PYTHON)` ./autogen.sh --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"


CLEANFILES = gconf/gconf.c gconf/*.pyo gconf/*.lo gconf/*.la gconf/*.in

build: build-stamp
build-stamp: config.status
	dh_testdir
	#CFLAGS="$(CFLAGS)" python$(PYVER) setup.py build
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 
	#CFLAGS="$(CFLAGS)" python$(PYVER) setup.py clean -a
	-$(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 $(CLEANFILES)

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
	
	#FIXME Hardcoded paths...
	mkdir -p $(CURDIR)/debian/tmp/usr/share/doc/python2.5-gnome-dev/examples
	cp -R $(CURDIR)/examples/gconf $(CURDIR)/debian/tmp/usr/share/doc/python2.5-gnome-dev/examples
	cp -R $(CURDIR)/examples/vfs $(CURDIR)/debian/tmp/usr/share/doc/python2.5-gnome-dev/examples/gnomevfs
	rm -rf $(CURDIR)/debian/tmp/usr/share/doc/python2.5-gnome-dev/examples/gnomevfs/pygvfsmethod

	python$(PYVER) -OO -m compileall -d / $(d)/usr/lib

binary-indep: build install
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdirs
	dh_installchangelogs
	dh_installman
	dh_installdocs
	dh_install --source=debian/tmp -v
	dh_link
	dh_strip
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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