COMPILFORTAN  = ifort
COMPILCPP     = icc

NETCDFPATH    = ${NETCDF}
HDF5PATH      = ${HDF5}

OPTIFLAGSFORTRAN   =  -O2
OPTIFLAGSCPP  =  -O2

FORTANFLAGS   =  -shared-intel -fpp -convert big_endian $(OPTIFLAGSFORTRAN)
CPPFLAGS =  $(OPTIFLAGSCPP)

INCS          = -Isrc -I. -I$(NETCDFPATH)/include
LIBSFORTRAN   = -L$(NETCDFPATH)/lib -lnetcdf -lnetcdff
LIBSCPP       = -L$(NETCDFPATH)/lib -lnetcdf_c++ -lnetcdf -lnetcdff


EXE =  veget_outp_to_nc EvoluCat2NetCDF EvoluCat2NetCDFan PutUnlimited OceanGrideChange NoisyVolc crop_grille_ecbilt

all:$(EXE)

veget_outp_to_nc: veget_outp_to_nc.f90
	$(COMPILFORTAN) $(FORTANFLAGS) $(INCS) -o $(<D)/$@ $^ $(LIBSFORTRAN)

EvoluCat2NetCDF: EvoluCat2NetCDF.cpp
	$(COMPILCPP) $(CPPFLAGS) $(INCS) -o $(<D)/$@ $^ $(LIBSCPP)

EvoluCat2NetCDFan: EvoluCat2NetCDFan.cpp
	$(COMPILCPP) $(CPPFLAGS) $(INCS) -o $(<D)/$@ $^ $(LIBSCPP)

PutUnlimited: PutUnlimited.cpp
	$(COMPILCPP) $(CPPFLAGS) $(INCS) -o $(<D)/$@ $^ $(LIBSCPP)

OceanGrideChange: OceanGrideChange.f90
	$(COMPILFORTAN) $(FORTANFLAGS) $(INCS) -o $(<D)/$@ $^ $(LIBSFORTRAN)

NoisyVolc: NoisyVolc.cpp
	$(COMPILCPP) $(CPPFLAGS) $(INCS) -o $(<D)/$@ $^ $(LIBSCPP)

crop_grille_ecbilt: crop_grille_ecbilt.f90
	$(COMPILFORTAN) $(FORTANFLAGS) $(INCS) -o $(<D)/$@ $^ $(LIBSFORTRAN)

%.o: %.cpp
	$(COMPILCPP) -o $@ -c $<

%.o: %.f90
	$(COMPILFORTAN) $(FORTANFLAGS) $(INCS) -module $(<D) -o $@ -c $<

clean:
	@for i in ${EXE}; do \
	  resu=`find . -name "$${i}"`; \
	  if [ "$${resu}" != "" ]; then echo "rm -f $${resu}"; rm -f $${resu}; fi;\
        done; \
	resu=`find . -name "*.o"`; if [ "$${resu}" != "" ]; then echo "rm -f $${resu}"; rm -f $${resu}; fi;\
	resu=`find . -name "*.mod"`; if [ "$${resu}" != "" ]; then echo "rm -f $${resu}"; rm -f $${resu}; fi;\
	resu=`find . -name "*__genmod.f90" -exec rm -rf {} \;`;\
