#	@(#)Makefile.GMT	3.12  11/30/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
#		GNU, Sys V, and BSD Compatible
#
#	Follow the instructions in this makefile to customize your setup.
#	Commands marked *** are optional
#	1. run configure in the main GMT directory.
#	2. make all
#	3. make suppl   ***
#	4. make run-examples ***
#
#	Then, if you have the necessary directory permissions:
#
#	5. make install-all
#
#	or any combination of
#
#	make install
#	make install-suppl
#	make install-data
#	make install-man
#	make install-www
#	
#	When done, clean out directory with "make clean".  To clean
#	the entire build distribution, do "make cleandist"
#
#
#	Authors:	Paul Wessel, SOEST, U. of Hawaii
#			Walter H. F. Smith, Lab for Satellite Altimetry, NOAA
#
#	Date:		19-NOV-1999
#-------------------------------------------------------------------------------
#	Get Default Macros
#-------------------------------------------------------------------------------
#

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

#-------------------------------------------------------------------------------
#	!! STOP EDITING HERE, THE REST IS FIXED !!
#-------------------------------------------------------------------------------

SUPPL	=	cps dbase imgsrc meca mex mgg misc segyprogs spotter x2sys xgrid
SUPPL_M	=	cps dbase imgsrc meca mgg misc segyprogs spotter x2sys

all:		gmt suppl

install-all:	install install-suppl install-data install-man install-www

gmt:		
		cd src; \
		$(MAKE) all; \
		cd ..

install:	gmt
		cd src; \
		$(MAKE) install; \
		cd ..

suppl:
		for d in $(SUPPL); do \
			if [ -d src/$$d ] ; then \
				cd src/$$d; \
				$(MAKE) all; \
				cd ../..; \
			fi; \
		done

install-suppl:
		for d in $(SUPPL); do \
			if [ -d src/$$d ] ; then \
				cd src/$$d; \
				$(MAKE) install; \
				cd ../..; \
			fi; \
		done

install-data:
		if [ ! $(rootdir)/share = $(datadir) ]; then \
			mkdir -p $(datadir); \
			cp -r share $(dir $(datadir)); \
		else \
			echo "Install share directory the same as distribution share directory - nothing copied"; \
		fi


install-man:
		\rm -f manjob.sh
		for d in $(SUPPL_M); do \
			if [ -d src/$$d ] ; then \
				cd src/$$d; \
				for f in *.man; do \
					\cp $$f $(rootdir)/man/manl; \
					echo "\\mv $$f $$f" | sed -e 's/.man$$/.l/g' >> $(rootdir)/manjob.sh; \
				done; \
				cd ../..; \
			fi; \
		done
		if [ -f manjob.sh ]; then \
			cd man/manl; \
			$(SHELL) $(rootdir)/manjob.sh; \
			\rm -f $(rootdir)/manjob.sh; \
		fi
		if [ ! $(rootdir)/man/manl = $(mandir)/man$(mansection) ]; then \
			mkdir -p $(mandir)/man$(mansection); \
			cp man/manl/*.l $(mandir)/man$(mansection); \
			cd $(mandir)/man$(mansection); \
			for f in *.l; do \
				echo "\\mv $$f $$f" | sed -e 's/.l$$/.$(mansection)/g' >> $(rootdir)/manjob.sh; \
			done; \
			$(SHELL) $(rootdir)/manjob.sh; \
			\rm -f $(rootdir)/manjob.sh; \
			cd $(rootdir); \
		else \
			echo "Install man directory the same as distribution man directory - nothing copied"; \
		fi


install-www:
		for d in $(SUPPL_M); do \
			if [ -d src/$$d ] ; then \
				\cp src/$$d/*.html $(rootdir)/www/gmt/doc/html; \
			fi; \
		done
		if [ ! $(rootdir)/www = $(wwwdir) ]; then \
			mkdir -p $(wwwdir); \
			cp -r www $(dir $(wwwdir)); \
		else \
			echo "Install www directory the same as distribution www directory - nothing copied"; \
		fi

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

clean:
		cd src; \
		$(MAKE) clean; \
		cd ..
		for d in $(SUPPL); do \
			if [ -d src/$$d ] ; then \
				cd src/$$d; \
				$(MAKE) clean; \
				cd ../..; \
			fi; \
		done

spotless:	clean
		cd src; \
		$(MAKE) spotless; \
		cd ..
		for d in $(SUPPL); do \
			if [ -d src/$$d ] ; then \
				cd src/$$d; \
				$(MAKE) spotless; \
				cd ../..; \
			fi; \
		done

distclean:	spotless
