#!/usr/bin/make -f


# 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

config.status: configure
	dh_testdir
	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/usr --mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--with-sphinxbase=auto CFLAGS="$(CFLAGS)"

build: build-stamp
build-stamp: config.status
	dh_testdir
	$(MAKE)
	$(RM) -r python/build
	cd python && python2.5 setup.py build
	cd python && python2.5-dbg setup.py build
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean
	$(RM) -r python/build

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
	cd python && python2.5 setup.py install --root=$(CURDIR)/debian/python-pocketsphinx
	cd python && python2.5-dbg setup.py install --root=$(CURDIR)/debian/python-pocketsphinx-dbg
	mkdir -p debian/python-pocketsphinx/usr/share/doc/python-pocketsphinx
	dh_installexamples -p python-pocketsphinx python/ps_test.py
	find debian/python-*-dbg ! -type d ! -name '*.so' | xargs rm -f
	find debian/python-*-dbg -depth -empty -exec rmdir {} \;
	find debian -name '*.py[co]' | xargs rm -f

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

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
	dh_install --sourcedir=debian/tmp
	dh_installman
	dh_link
	dh_strip --exclude=_d.so
	rm -rf debian/python-pocketsphinx-dbg/usr/share/doc/python-pocketsphinx-dbg
	ln -s python-pocketsphinx \
		debian/python-pocketsphinx-dbg/usr/share/doc/python-pocketsphinx-dbg
	dh_compress -X.py
	dh_fixperms
	dh_pysupport
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps -V "libpocketsphinx1 (>=0.6)"
	dh_gencontrol
	maemo-optify
	dh_md5sums
	dh_builddeb

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