#	@(#)makefile.gmt	1.48  11/19/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.3 src directory
#		GNU, Sys V, and BSD Compatible
#
#	Normally, this makefile is activated by the main Makefile in
#	the GMT main directory.  However, you can also issue commands
#	directy to this makefile from within the src directory.
#	First, run configure in the main GMT directory.
#	To compile/link them, try "make init", "make all", and "make install".
#	When done, clean out directory with "make clean".
#	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:		20-NOV-1999
#-------------------------------------------------------------------------------
#	Get Default Macros
#-------------------------------------------------------------------------------
#

include makegmt.macros	# GMT-specific settings determined by user & install_gmt

#-------------------------------------------------------------------------------
#	!! STOP EDITING HERE, THE REST IS FIXED !!
#-------------------------------------------------------------------------------
NETCDFLIB	= $(NETCDF)/lib
NETCDFINC	= $(NETCDF)/include
CFLAGS		= -I$(NETCDFINC) $(WIN32) $(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 \
	  gmt_notposix.h \
	  gmt_notunix.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

first:	all

#-------------------------------------------------------------------------------
#	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 $<

# Assembly wrapper for sincos on Dec Alphas
# Only used if ALPHA_SINCOS_O are set in makegmt.macros

alpha-sincos.o:	alpha-sincos.s
		$(AS) -o alpha-sincos.o $<

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

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

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

all:		init libs $(PROGS)

init:		gmt_notposix.h gmt_nan.h
		
gmt_nan.h:	
		$(CC) $(CFLAGS) gmt_nan_init.c $(CDF) $(LIBS) -o gmt_nan_init
		$(EMX) -o gmt_nan_init$(EXE) gmt_nan_init
		$(COMPRESS) gmt_nan_init$(EXE)
		./gmt_nan_init

gmt_notposix.h:	
		echo "Warning: You probably should run configure manually instead"; \
		cd ..; \
		./configure

install:	all
		if [ ! -d $(bindir) ]; then \
			mkdir -p $(bindir); \
		fi
		for i in $(PROGS); do \
			$(INSTALL) $$i$(EXE) $(bindir); \
		done
		if [ -f libpsl.$(SL) ]; then \
			$(INSTALL) libpsl.$(SL) $(bindir); \
			$(INSTALL) libgmt.$(SL) $(bindir); \
		fi

clean:
		rm -f *.o gmt_nan_init$(EXE)
		for i in $(PROGS); do \
			rm -f $$i$(EXE); \
		done

spotless:	clean
		rm -f $(GMTLIB) gmt_nan.h gmt_notposix.h

distclean:	spotless

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

libs:		$(GMTLIB)

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

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

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

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

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

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

$(PROGS):	$(GMTLIB) $(PROGS_O)
		$(CC) $(CFLAGS) $@.o -L. -lgmt -lpsl $(CDF) $(LIBS) $(LDFLAGS) -o $@
		$(EMX) -o $@$(EXE) $@
		$(COMPRESS) $@$(EXE)
.c.o:
		$(CC) -c $(CFLAGS) $<
