#!/usr/bin/make -f

#export DH_VERBOSE=1

# Cope with lam not providing mpicc.
include /usr/share/mpi-default-dev/debian_defaults 
ifeq ($(ARCH_DEFAULT_MPI_IMPL),lam)
  CC:=mpicc.lam
else
  CC:=mpicc
endif

ARCH:=$(shell dpkg --print-architecture)
WITH_LUSTRE := 

#ifeq ($(ARCH), i386) 
#  WITH_LUSTRE:= --with-lustre=/usr
#endif
#ifeq ($(ARCH), amd64)
#  WITH_LUSTRE:= --with-lustre=/usr
#endif
#ifeq ($(ARCH), powerpc) 
#  WITH_LUSTRE:= --with-lustre=/usr
#endif
#ifeq ($(ARCH), ia64) 
#  WITH_LUSTRE:= --with-lustre=/usr
#endif

DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

DESTDIR:=$(shell pwd)/debian/tmp
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
NETCDF_LIBS ?= $(shell pkg-config --libs heimdal-gssapi netcdf libffi)
LIBDIR:=/usr/lib/$(DEB_HOST_MULTIARCH)
BINDIR:=$(DESTDIR)/usr/bin


# magic debhelper rule
%:
	dh $@ --with python2,python3,autoreconf

override_dh_auto_clean:
	dh_clean
	find . -name '*.pyc' -delete

override_dh_auto_configure:
	dh_auto_configure --  $(WITH_LUSTRE) --enable-shared --prefix=$(DESTDIR) MPIFC=mpif77 CC=$(CC)\
	    --with-netcdf-libs="-lm -lcurl $(NETCDF_LIBS) -lz -lidn -lrtmp -lgcrypt -lgnutls -lgssapi_krb5\
	    -llber -lldap_r -lgpg-error -ltasn1 -lp11-kit -lk5crypto -lkrb5support -lsasl2 -lkeyutils\
            -lsqlite3"

override_dh_auto_install:
	$(MAKE) install prefix=$(DESTDIR)/usr
	# remove due to it not working in multi-arch;
	rm -f  $(BINDIR)/adios_config.flags
	# renamed as per Adios CCS issue #118716, Debbug #639257
	mv $(BINDIR)/gpp.py $(BINDIR)/adiosxml2h
	mv $(BINDIR)/ad_config.py $(BINDIR)/ad_config
	mv $(BINDIR)/skel_cat.py $(BINDIR)/skel_cat
	mv $(BINDIR)/skel_extract.py $(BINDIR)/skel_extract
	cp debian/adios_config $(BINDIR)/adios_config
	# mv $(DESTDIR)/bin/xmlparser.py $(DESTDIR)/bin/xmlparser
