#		$Id: makefile.in,v 1.4 2006/04/01 02:17:27 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		= /Applications/MATLAB704
MATLAB_EXT	= mexmac
MATLAB_MEX	= mac
MATLAB_LIB	= mat

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 -O

PROG_C		= grdinfo.c grdread.c grdwrite.c
PROG_M		= ${PROG_C:.c=.$(MATLAB_EXT)}

all:		$(PROG_M)

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.$(MATLAB_EXT):	
		$(MEX) $(FLAGS) grdinfo2.c -output grdinfo $(GMT) $(CDF) $(MEXLIB) 

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

grdwrite.$(MATLAB_EXT):	
		$(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_M); do \
			rm -f $$f; \
		done
