#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1

# I took these from older rules - are they really needed?
CPPFLAGS = -D__STDC_CONSTANT_MACROS -fPIC
CFLAGS = -Wall -g -fPIC
CXXFLAGS = -std=c++0x

PYVERS=$(shell pyversions -r)

export ROOTSYS=/usr
#export LD_LIBRARY_PATH=/usr/lib (why?)

DMTRUN = yes
ifeq ($(DMTRUN), yes)
CONFIG_RUNFLAG = --enable-dmt-runtime
else
CONFIG_RUNFLAG = --disable-dmt-runtime
endif

%:
	dh $@ --with=python2

override_dh_auto_configure:
override_dh_auto_build:
override_dh_auto_install:
	for pyvers in $(PYVERS) ; do \
	PYTHON="$$pyvers" \
	PKG_CONFIG_PATH=/usr/lib/pkgconfig \
	CPPFLAGS="$(CPPFLAGS)" \
	CFLAGS="$(CFLAGS)" \
	CXXFLAGS="$(CXXFLAGS)" \
	./configure \
	    --prefix=/usr \
	    --libdir=/usr/lib \
	    --includedir=/usr/include/gds \
	    --mandir=/usr/share/man \
	    --sysconfdir=/etc \
	    --enable-online --enable-dtt --enable-python \
	    $(CONFIG_RUNFLAG) \
	&& \
	$(MAKE) V=0 && \
	$(MAKE) V=1 check && \
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp && \
	$(MAKE) clean ; \
	done
	# sysconfdir not handled properly?
	mkdir -p $(CURDIR)/debian/tmp/etc
	-mv -f $(CURDIR)/debian/tmp/usr/etc/* $(CURDIR)/debian/tmp/etc/
	dh_install

override_dh_auto_test:

# removed from configure line (2.17.2):
#	    --without-hdf5 \

override_dh_python2:
	dh_python2 --no-guessing-versions

