#!/usr/bin/make -f

CXXFLAGS += -DBUILD_DATE="\"$(shell LC_ALL=C date -u --date="`dpkg-parsechangelog -SDate`" +'%b %e %Y')\""
VERSION=$(shell dpkg-parsechangelog -SVersion)

%:
	dh $@ --parallel -Scmake

override_dh_auto_configure:
	# Patched source FTBFS if this embedded code copy is present
	tar cf antlr.tar src/antlr
	rm -rf src/antlr

	dh_auto_configure -- \
	  -DPYTHONDIR=/usr \
	  -DPYTHONVERSION=2.7 \
	  -DDEB_BUILD_MULTIARCH=`dpkg-architecture -qDEB_BUILD_MULTIARCH` \
	  -DFFTW=YES \
	  -DPYTHON=YES \
	  -DPYTHON_MODULE=YES \
	  -DWXWIDGETS=YES \
	  -DGRIB=YES \
	  -DUDUNITS=YES \
	  -DPSLIB=YES

override_dh_auto_test:
	( cd obj*/testsuite \
	&& cp ../../testsuite/formats.idl . \
	&& $(CXX) -o libtest_ce.so ../../testsuite/libtest_ce.cpp -shared -fPIC \
	&& $(CC) -o launchtest ../../testsuite/launchtest.c )
	LD_LIBRARY_PATH="../src" xvfb-run dh_auto_test --no-parallel -Scmake || true

override_dh_auto_clean:
	if [ -f  antlr.tar ]; then tar xf antlr.tar; fi
	rm -f antlr.tar
	dh_auto_clean --parallel

override_dh_compress:
	dh_compress -X.pro

# The epoch in front of python-gdl's version number is needed since
# Debian Squeeze had a python-gdl binary package with version 2.25.3-7
# built from the gnome-python-extras source package.
override_dh_gencontrol:
	dh_gencontrol -ppython-gdl -- -v1:$(VERSION)
	dh_gencontrol --remaining
