#		$Id: makefile.in,v 1.2 2001/04/11 19:58:09 pwessel Exp $
#
#	Makefile for gmt <--> matlab conversion programs
#	Use with GMT 3.3.5 or later
#

include ../makegmt.macros

# Note that if you have write permission in $MATLAB/toolbox/local
# then that is where install will place the files.  Otherwise, it
# will put them in $(bindir).

#----------------------------------------------------------------------------
#	The rest should should be ok. NO EDITING BEYOND HERE, unless your
#	Matlab setup was not auto-detected by the configure file
#	If so, please let us know what you needed to change.
#----------------------------------------------------------------------------

MATLAB		= @MATLAB@
MATLAB_EXT	= @MATLAB_EXT@
MATLAB_MEX	= @MATLAB_MEX@
MATLAB_LIB	= @MATLAB_LIB@

MEX	= $(MATLAB)/bin/mex
MEXLIB	= -L$(MATLAB)/extern/lib/$(MATLAB_MEX)$ -l$(MATLAB_LIB)
GMT     = -L.. -L$(libdir) -lgmt -lpsl
CDF     = -L$(NETCDF)/lib -lnetcdf
FLAGS	= -I$(srcdir) -I$(MATLAB)/extern/include -I$(NETCDF)/include

PROG		= grdinfo grdread grdwrite

all:		$(PROG)

install:	all
		for f in *.$(MATLAB_EXT) *.m; do \
			if [ -w $(MATLAB)/toolbox/local ] ; then \
				$(INSTALL) $$f $(MATLAB)/toolbox/local; \
			else \
				$(INSTALL) $$f $(bindir); \
			fi \
		done

# Because grdinfo is also a GMT program the source here is called
# grdinfo2.c but we make a mex file called grdinfo.$MATLAB_EXT

grdinfo:	
		$(MEX) $(FLAGS) grdinfo2.c -output grdinfo $(GMT) $(CDF) $(MEXLIB) 

grdread:	
		$(MEX) $(FLAGS) grdread.c $(GMT) $(CDF) $(MEXLIB) 

grdwrite:	
		$(MEX) $(FLAGS) grdwrite.c $(GMT) $(CDF) $(MEXLIB)

spotless:	clean
		\rm -f makefile config.cache config.log config.status

clean:
		\rm -f *.$(MATLAB_EXT) .gmt* .mexrc.sh
		for f in $(PROG); do \
			rm -f $$.$(MATLAB_EXT); \
		done
