#
#  $Author: pkubota $
#  $Date: 2007/10/10 20:28:03 $
#  $Revision: 1.4 $
#
# $Id: Makefile,v 1.4 2007/10/10 20:28:03 pkubota Exp $
#
SHELL=/bin/sh
#
# Makefile for Pos-Proccessing output global model
#
# Targets are the suffixes of the system-specific makefiles in
# the makefiles/ directory.
# For example, to build PosGrib for Solaris, give the command
#
#   make solaris
#
# This builds an intermediate library in the util/ directory,
# then builds the nedit and nc executables in the source/ directory.
#
MAKE=make
PATH2=./
EXEC=ibis-2.6b5.exe
all:
	@echo "Please specify target:"
	@echo "(For example, type \"make linux\" for a Linux system.)"
	@(cd  makefiles && ls -C Makefile* | sed -e 's/Makefile.//g')

.DEFAULT:
	@- (cd .; if [ -f makefiles/Makefile.$@ -a ! -f main/Makefile.$@ ];\
	   then ln -fs ../makefiles/Makefile.$@ main/Makefile.$@; fi)
	@- (cd .; if [ -f makefiles/Makefile.$@ -a ! -f utils/Makefile.$@ ];\
	   then ln -fs ../makefiles/Makefile.$@ utils/Makefile.$@; fi)
	@- (cd .; if [ -f makefiles/Makefile.$@ -a ! -f csm_share/Makefile.$@ ];\
	   then ln -fs ../makefiles/Makefile.$@ csm_share/Makefile.$@; fi)	   
	@- (cd .; if [ -f makefiles/Makefile.$@ -a ! -f biogeophys/Makefile.$@ ];\
	   then ln -fs ../makefiles/Makefile.$@ biogeophys/Makefile.$@; fi)
	@- (cd .; if [ -f makefiles/Makefile.$@ -a ! -f biogeochem/Makefile.$@ ];\
	   then ln -fs ../makefiles/Makefile.$@ biogeochem/Makefile.$@; fi)

	(cd utils;$(MAKE) -f Makefile.$@)
	(cd .;cp -fp utils/*.o utils/*.mod csm_share/)
	(cd .;cp -fp utils/*.o utils/*.mod main/)
	(cd .;cp -fp utils/*.o utils/*.mod biogeophys/)
	(cd .;cp -fp utils/*.o utils/*.mod biogeochem/)

	(cd csm_share;$(MAKE) -f Makefile.$@)
	(cd .;cp -fp csm_share/*.o csm_share/*.mod main/)
	
	(cd biogeophys;$(MAKE) -f Makefile.$@)
	(cd .;cp -fp biogeophys/*.o biogeophys/*.mod main/)

	(cd biogeochem;$(MAKE) -f Makefile.$@)
	(cd .;cp -fp biogeochem/*.o biogeochem/*.mod main/)
	
	(cd main;$(MAKE) -f Makefile.$@)
	(mv -f main/$(EXEC) $(PATH2)/)

# We need a "dev-all" target that builds the docs plus binaries, but
# that doesn't work since we require the user to specify the target.  More
# thought is needed

clean:
	@echo "$(MAKE)"

	(cd utils;$(MAKE) -f Makefile.common clean)
	(cd csm_share;$(MAKE) -f Makefile.common clean)
	(cd biogeophys;$(MAKE) -f Makefile.common clean)
	(cd biogeochem;$(MAKE) -f Makefile.common clean)
	(cd main;$(MAKE) -f Makefile.common clean)
	(rm -f $(EXEC))
