#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

%:
	dh --with python2  $@

CFLAGS += -fPIC
VERSION:=2.12.9

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

override_dh_auto_clean:
	find . -type l -exec rm {} \;
	find . -name '*.pyc' -exec rm {} \;
	find test \( -name '*.ps' -o -name '*.pdf' -o -name '*.svg' -o -name '*.png' \
	       -o -name '*.kmz' \)  -exec rm  {} \;
	rm -f config.log
	rm -rf share/magics/ttf src/terralib
	# make -k distclean || echo "Ignoring errors since terralib not present" 

override_dh_auto_configure:
	# 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/
	# Link terralib
	[ -e src/terralib ] || ln -sf  /usr/include/terralib src/terralib
	# Now build. LDFLAGS is a nasty hack past libtool breakage in install, where it fails
	# to find libraries _it_ created. And it makes stuff in the install step. bah.
	# autoreconf -if
	dh_auto_configure -- \
		--enable-bufr --enable-static --enable-cairo --with-emos-libraries=/usr/lib \
		--with-terralib=/usr  --enable-python \
		LDFLAGS=-L$(shell pwd)/src/.libs

override_dh_auto_test:
	(ulimit -s 8192; export PYTHONPATH=$(shell pwd)/swig ; export MAGPLUS_HOME=$(shell pwd) ; $(MAKE) check )
	
override_dh_auto_install:
	chrpath -d swig/*.so
	dh_auto_install
	$(MAKE) -C swig install PYTHON_INCLUDE_DIR=/usr/include/$(shell pyversions -d) \
		DESTDIR=$(CURDIR)/debian/tmp \
		MAGPLUS_HOME=$(shell pwd) 
	dh_python2
	dh_numpy -p python-magics++
	# remove fonts that are present in dejavu-ttf
	rm -rf debian/libmagics++-data/usr/share/magics/ttf
