
SHELL = @SHELL@

AWK = @AWK@
AWK ?= awk

MKOCTFILE = @MKOCTFILE@ -v
NC_CONFIG = @NC_CONFIG@

%.oct: %.cc ; $(MKOCTFILE) $<

NCHEADER=$(shell $(NC_CONFIG) --includedir)/netcdf.h
NETCDF_CPPFLAGS=@NETCDF_CPPFLAGS@
NETCDF_LIBS=@NETCDF_LIBS@

SRC = __netcdf__.cc

all: __netcdf__.oct ../PKG_ADD

netcdf_constants.h:
	$(info generating netcdf_constants.h)
	@if [ -f $(NCHEADER) ]; then \
	  $(AWK) -f netcdf_constants.awk $(NCHEADER)  > netcdf_constants.h; \
	elif [ -f /usr/include/netcdf.h ]; then \
	  $(AWK) -f netcdf_constants.awk /usr/include/netcdf.h > netcdf_constants.h; \
	else \
	  echo >&2 "Couldnt find netcdf.h"; \
	  false; \
	fi;

clean:
	rm -f __netcdf__.o __netcdf__.oct netcdf_constants.h

distclean: clean
	-rm -f oct-alt-includes.h
	-rm -f config.status config.log config.h
	-rm -f Makefile

realclean: distclean
	rm -f ../PKG_ADD ../PKG_DEL

__netcdf__.oct: $(SRC) netcdf_constants.h
	$(MKOCTFILE) $(NETCDF_CPPFLAGS) $(SRC) $(NETCDF_LIBS)

../PKG_ADD: $(SRC)
	$(shell sh ./PKG_ADD.sh)
