#Assumes ${NETCDF} is defined to the root of the netcdf library
CC = $(shell nf-config --g++)
FFLAGS = -O3
FCINCLUDES = $(shell nf-config --fflags)
RPATH_FLAGS = $(shell nf-config --flibs | grep -o -e '-L\S\+\( \|$$\)' | sed 's/^-L/-Wl,-rpath,/' | tr -d '\n')
RPATH_FLAGS += $(shell nc-config --libs | grep -o -e '-L\S\+\( \|$$\)' | sed 's/^-L/-Wl,-rpath,/' | tr -d '\n')
FCLIBS = -L$(shell nc-config --libdir) $(shell nf-config --flibs) $(RPATH_FLAGS)

#CC=g++
CFLAGS= -O3
EXECUTABLE= PointsToMpas.x

NCINCDIR=${NETCDF}/include
NCLIBDIR=${NETCDF}/lib

all:
	${CC} points-mpas.cpp ${CFLAGS} -o ${EXECUTABLE} ${FCINCLUDES} ${FCLIBS} -lnetcdf_c++ -lnetcdf

debug:
	${CC} points-mpas.cpp  -g -o ${EXECUTABLE} ${FCINCLUDES} ${FCLIBS} -lnetcdf_c++ -lnetcdf

clean:
	rm -f grid.nc
	rm -f graph.info
	rm -f ${EXECUTABLE}

