#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

CFLAGS += -fPIC

# --enable-opengl can't be used as lesstif not supported - missing Motif functionality

# DEB_MAKE_CHECK_TARGET := check
DEB_MAKE_CLEAN_TARGET := clean distclean maintainer-clean
DEB_CONFIGURE_EXTRA_FLAGS :=  --enable-bufr --enable-static --enable-cairo --with-emos-libraries=/usr/lib \
 --with-terralib=/usr  --enable-python 
DEB_AUTO_UPDATE_LIBTOOL := pre
DEB_SHLIBDEPS_LIBRARY_magics++ := libmagplus3
DEB_SHLIBDEPS_INCLUDE_magics++ := debian/libmagplus3/usr/lib/
DEB_MAKE_ENVVARS:= MAGPLUS_HOME=`pwd` PYTHON_INCLUDE_DIR=/usr/include/$(shell pyversions -d)
DEB_PYTHON_SYSTEM:= pysupport

clean::
	find . -type l -exec rm {} \;

configure/libmagics++-dev::
	# Delete the libtool crap and install debian libtool
	rm -f libtool
	ln -sf /usr/bin/libtool .
	# link for font for tesing.
	mkdir -p share/fonts/truetype/ttf-dejavu/
	ln -sf /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf share/fonts/truetype/ttf-dejavu/

makebuilddir/libmagics++-dev::
	[ -e src/terralib ] || ln -sf  /usr/include/terralib src/terralib
	autoreconf -if

binary-install/libmagics++-dev::
	ln -sf libMagPlus.so.3.0.0 debian/libmagics++-dev/usr/lib/libMagPlus.so

binary-install/libmagplus3::
	ln -sf libMagPlus.so.3.0.0 debian/libmagplus3/usr/lib/libMagPlus.so.3	

# Post-squeeze, do this properly with pysupport and debhelper
binary-install/python-magics++::
	find debian/python-magics++ -name '*.so' -exec chrpath -d {} \;
	#Test building using only update-modules
	#ln -sf /usr/share/pyshared/Magics.py  debian/python-magics++/usr/lib/pymodules/python2.6/Magics.py  
	#ln -sf /usr/share/pyshared/MagML.py  debian/python-magics++/usr/lib/pymodules/python2.6/MagML.py  
	#ln -sf /usr/share/pyshared/magmacro.py  debian/python-magics++/usr/lib/pymodules/python2.6/magmacro.py
	#ln -sf /usr/lib/pyshared/python2.6/_Magics.so  debian/python-magics++/usr/lib/pymodules/python2.6/_Magics.so
	#ln -sf /usr/lib/pyshared/python2.6/_MagML.so  debian/python-magics++/usr/lib/pymodules/python2.6/_MagML.so
	dh_pysupport
	dh_numpy -p python-magics++

# Store build information
common-binary-post-install-arch common-binary-post-install-indep::
	dh_buildinfo
