#	@(#)makefile.gmt	1.26  06/29/99
#
#	Copyright (c) 1991-1999 by P. Wessel and W. H. F. Smith
#	See COPYING file for copying and redistribution conditions.
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; version 2 of the License.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	Contact info: www.soest.hawaii.edu/gmt
#-------------------------------------------------------------------------------
#		Makefile for GMT Version 3.3.1
#		GNU, Sys V, and BSD Compatible
#
#	Follow the instructions in this makefile to customize your setup.
#	To compile/link them, try "make init", "make all", and "make install".
#	When done, clean out directory with "make clean".  If the example
#	scripst have been installed in ../examples, try "make examples".
#	To start completely from scratch, first do "make spotless".
#
#	Authors:	Paul Wessel, SOEST, U. of Hawaii
#			Walter H. F. Smith, Lab for Satellite Altimetry, NOAA
#
#	Date:		16-JUN-1999
#-------------------------------------------------------------------------------
#	Get Default Macros
#-------------------------------------------------------------------------------
#

include makegmt.macros	# Edit this file to change current settings

#-------------------------------------------------------------------------------
#	!! STOP EDITING HERE, THE REST IS FIXED !!
#-------------------------------------------------------------------------------
NETCDFLIB	= $(NETCDF)/lib
NETCDFINC	= $(NETCDF)/include
SHELL=/bin/sh
MAKE_OPTS = RANLIB=$(RANLIB)
CFLAGS		= -I$(NETCDFINC) $(SI) $(CC_OPT) -DGMT_DEFAULT_PATH=\"$(GMT_DEFAULT_PATH)\" $(TRIANGLE_D)
CDF		= -L$(NETCDFLIB) -lnetcdf

PS	= -lpsl
GMT	= -lgmt

LIB_C	= fourt.c \
	  gmt_cdf.c \
	  gmt_customio.c \
	  gmt_grdio.c \
	  gmt_init.c \
	  gmt_io.c \
	  gmt_map.c \
	  gmt_plot.c \
	  gmt_shore.c \
	  gmt_stat.c \
	  gmt_support.c \
	  gmt_vector.c

GMT_H	= gmt.h \
	  gmt_math.h \
	  gmt_nan.h \
	  gmt_map.h \
	  gmt_boundcond.h \
	  gmt_shore.h \
	  gmt_project.h \
	  gmt_grd.h \
	  gmt_funcnames.h \
	  gmt_colors.h \
	  gmt_grdio.h \
	  gmt_customio.h \
	  gmt_bcr.h \
	  gmt_unique.h \
	  gmt_keywords.h \
	  gmt_io.h \
	  pslib.h

GMT_I	= gmt_init.h \
	  gmt_defaults.h \
	  gmt_media_name.h \
	  gmt_media_size.h \
	  PS_font_names.h \
	  PS_font_heights.h

PS_H	= pslib.h \
	  pslib_inc.h \
	  PS_font_names.h \
	  PS_font_heights.h

PROGS_C	= blockmean.c blockmedian.c blockmode.c filter1d.c fitcircle.c \
	  grdfilter.c gmtconvert.c gmtdefaults.c gmtmath.c gmtselect.c \
	  gmtset.c grd2cpt.c grd2xyz.c grdcontour.c grdcut.c grdclip.c \
	  grdedit.c grdfft.c grdgradient.c grdhisteq.c grdimage.c grdinfo.c \
	  grdlandmask.c grdmask.c grdtrack.c grdreformat.c grdmath.c \
	  grdpaste.c grdproject.c grdsample.c grdtrend.c grdvector.c grdview.c \
	  grdvolume.c makecpt.c mapproject.c minmax.c nearneighbor.c project.c \
	  psbasemap.c psclip.c pscoast.c pshistogram.c psimage.c psmask.c \
	  psrose.c psscale.c pstext.c pscontour.c pswiggle.c psxy.c psxyz.c \
	  sample1d.c spectrum1d.c splitxyz.c surface.c trend1d.c trend2d.c \
	  triangulate.c xyz2grd.c

#-------------------------------------------------------------------------------
#	object file dependencies
#-------------------------------------------------------------------------------

LIB_O	= ${LIB_C:.c=.o}

PROGS_O	= ${PROGS_C:.c=.o}

PROGS	= ${PROGS_C:.c=}

$(LIB_O):	$(GMT_H) $(GMT_I)

$(PROGS_O):	$(GMT_H)

# Jonathan Shewchuck's triangulation model (www.cs.cmu.edu/~quake)
# Only used if TRIANGLE_D and TRIANGLE_O are set in makegmt.macros
# Please read README.TRIANGLE in this source directory.

triangle.o:	triangle.c
		$(CC) -c $(CFLAGS) -DNO_TIMER -DTRILIBRARY -DREDUCED -DCDT_ONLY $<

#-------------------------------------------------------------------------------

SHARED_LIB	= libpsl.a libgmt.a libpsl.$(SL) libgmt.$(SL)
STATIC_LIB	= libpsl.a libgmt.a

#-------------------------------------------------------------------------------

all:		init libs $(PROGS)

init:		gmt_nan.h gmt_math.h

gmt_nan.h:	
		$(CC) $(CFLAGS) gmt_nan_init.c $(CDF) -lm -o gmt_nan_init
		./gmt_nan_init

gmt_math.h:	
		$(CSH) gmt_math_init.$(CSH)

gmt_endian:	gmt_endian.c
		$(CC) $(CFLAGS) gmt_endian.c -lm -o gmt_endian

install:	all
		for i in $(PROGS); do \
			cp $$i$(DOS) $(BINDIR); \
		done
		if [ -f libpsl.$(SL) ]; then \
			cp lib*.$(SL) $(BINDIR); \
		fi

examples:
		if [ -d ../examples ]; then \
			cd ../examples; \
			$(CSH) do_examples.$(CSH); \
			cd ../src; \
		else \
			echo "examples directory not installed"; \
		fi

clean:
		rm -f $(PROGS) *.o gmt_nan_init gmt_endian

spotless:	clean
		rm -f $(LIB) gmt_nan.h gmt_math.h

#-------------------------------------------------------------------------------
#	libraries
#-------------------------------------------------------------------------------

libs:		$(LIB)

libpsl.a:	pslib.o
		$(AR) cvr libpsl.a $?
		$(RANLIB) libpsl.a

pslib.o:	pslib.c $(PS_H)
		$(CC) $(CFLAGS) -c pslib.c

libgmt.a:	$(LIB_O) $(TRIANGLE_O)
		$(AR) cvr $@ $?
		$(RANLIB) $@

libpsl.$(SL):	pslib.o
		$(LD) $(LD_OPT) $? -o $@

libgmt.$(SL):	$(LIB_O) $(TRIANGLE_O)
		$(LD) $(LD_OPT) $(LIB_O) $(TRIANGLE_O) -o $@

#-------------------------------------------------------------------------------
#	program dependencies
#-------------------------------------------------------------------------------

$(PROGS):	$(LIB) $(PROGS_O)
		$(CC) $(CFLAGS) $@.o -L. -lgmt -lpsl $(CDF) $(MATH) $(LDFLAGS) -o $@

.c.o:
		$(CC) -c $(CFLAGS) $<
