#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

package=babel

stamp-configure:
	dh_testdir
	(cd runtime && libtoolize --force)
	(cd runtime && aclocal)
	(cd runtime && automake)
	(cd runtime && autoconf)
	libtoolize --force
	aclocal
	automake
	autoconf
	JNI_INCLUDES=-I/usr/lib/jvm/java-gcj/include \
	  PYTHON=python ./configure --prefix=/usr
	touch $@

PYVER := $(shell pyversions -vd)
PYOTHERS := $(filter-out $(PYVER), $(shell pyversions -vr))

build: stamp-build $(PYOTHERS:%=stamp-build-python%)
stamp-build: stamp-configure
	dh_testdir
	$(MAKE)
	touch $@

stamp-build-python%: stamp-build
	dh_testdir
	rm -f  runtime/python/babel-stamp
	$(MAKE) -C runtime python/babel-stamp \
	  PYTHON=python$* \
	  PYTHONINC="-I/usr/include/python$* -I/usr/include/python$*/numpy/" \
	  PYTHONLIB=/usr/lib/python$* \
	  PYTHON_SHARED_LIBRARY=/usr/lib/libpython$*.so \
	  PYTHON_VERSION=$* \
	  WHICH_PYTHON=/usr/bin/python$*
	rm -f  runtime/python/babel-stamp2
	$(MAKE) -C runtime python/babel-stamp2 \
	  PYTHON=python$* \
	  PYTHONINC="-I/usr/include/python$* -I/usr/include/python$*/numpy/" \
	  PYTHONLIB=/usr/lib/python$* \
	  PYTHON_SHARED_LIBRARY=/usr/lib/libpython$*.so \
	  PYTHON_VERSION=$* \
	  WHICH_PYTHON=/usr/bin/python$*
	touch $@

clean:
	dh_testdir
	if [ -e Makefile ]; then $(MAKE) distclean; fi
	rm -f lib/babel*.jar lib/sidl*.jar debian/babel140.1
# This is left by a quilt push/pop sequence
	rm -rf .pc
	rm -f stamp-configure stamp-build*
	dh_clean

install: build $(PYOTHERS:%=install-python%)
# Kludge to fix an unknown bug...
	cp -a runtime/libparsifal/src/.libs/libparsifal.la \
	  runtime/libparsifal/src/.libs/libparsifal.lai
	cp -a runtime/libchasmlite/.libs/libchasmlite.la \
	  runtime/libchasmlite/.libs/libchasmlite.lai
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
	mv debian/tmp/usr/bin/babel debian/tmp/usr/bin/babel140
	mv debian/tmp/usr/share/doc/babel-1.4.0 debian/tmp/usr/share/doc/babel-doc
#	mv debian/tmp/usr/share/doc/babel-doc/babel101/hello/lib/Hello_World_Impl.cc debian/tmp/usr/share/doc/babel-doc/babel101/hello/lib/Hello_World_Impl.cxx
	mv debian/tmp/usr/lib/*.scl debian/tmp/usr/share/babel-1.4.0/
	mv debian/tmp/usr/share/sidl.sidl debian/tmp/usr/share/babel-1.4.0/
	mv debian/tmp/usr/share/sidlx.sidl debian/tmp/usr/share/babel-1.4.0/
	mv debian/tmp/usr/share/sgml debian/tmp/usr/share/babel-1.4.0/
	rm debian/tmp/usr/include/c
	mkdir debian/tmp/usr/include/c
	(cd debian/tmp/usr/include/c && ln -s ../*.h .)
	rm -f debian/tmp/usr/bin/babel-libtool
	ln -s libtool debian/tmp/usr/bin/babel-libtool

install-python%:
	$(MAKE) -C runtime install-data-am-python prefix=`pwd`/debian/tmp/usr \
	  PYTHON=python$* \
	  PYTHONINC="-I/usr/include/python$* -I$(wildcard /usr/lib/python$*/*-packages/numpy/core/include/numpy)" \
	  PYTHONLIB=/usr/lib/python$* \
	  PYTHON_SHARED_LIBRARY=/usr/lib/libpython$*.so \
	  PYTHON_VERSION=$* \
	  WHICH_PYTHON=/usr/bin/python$*

binary-indep: install
	dh_testdir -i
	dh_testroot -i
	dh_installdirs -i
	dh_movefiles -i
	dh_installdocs -i
#	/usr/bin/perl debian/babel-manpage-script > debian/babel140.1
#	dh_installman -pbabel-1.4.0 debian/babel140.1
	dh_installchangelogs -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch: install
	dh_testdir -a
	dh_testroot -a
	dh_installdirs -a
	dh_movefiles -a
	dh_installdocs -a
	dh_installman -plibsidl-dev debian/babel-config.1
	dh_installchangelogs -a
	dh_strip -a
	dh_makeshlibs -a
	dh_compress -a
	dh_python2 -ppython-sidl
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean
