#!/usr/bin/make -f

# The magic debhelper  rule
%:
	dh $@

# Use mpicc as compiler if mpi-defaults-dev is installed (and hence mpi dev packages)
#defaults_file:=$(wildcard /usr/share/mpi-default-dev/*)
ifneq (,$(findstring mpi,$(DEB_BUILD_OPTIONS)))
        COND_CC:= "CC=mpicc"
else
        COND_CC:=
endif

CFLAGS += -fPIC

ARCH:=$(shell dpkg --print-architecture)
WITH_GRIB:= --with-grib-api=/usr --disable-cgribex
WITH_JASPER:= --with-jasper=/usr

# grib-api not available on these arches; jasper is only needed for grib-api
ifeq ($(ARCH), mips)
  WITH_GRIB:=
  WITH_JASPER:=
endif
ifeq ($(ARCH), hppa)
  WITH_GRIB:=
  WITH_JASPER:=
endif
ifeq ($(ARCH), sparc)
  WITH_GRIB:=
  WITH_JASPER:=
endif

override_dh_auto_clean:
	dh_auto_clean	|| echo "distclean ok"
	find . -name Makefile.in -delete
	find . -type l -delete
	rm -f src/config.h.in aclocal.m4 config/depcomp config/install-sh config/ltmain.sh config/missing configure INSTALL
	rm -rf src/.deps

override_dh_auto_configure:
	ln -sf /usr/include/cfortran.h libcdi/src/cfortran.h 
	autoreconf -if
	LDFLAGS="-Wl,--as-needed"  \
	  ./configure --prefix=/usr \
		--with-zlib=/usr --with-netcdf=/usr  --with-proj=/usr --with-hdf5=/usr \
		 $(WITH_GRIB) $(WITH_JASPER) $(COND_CC)
	
