#/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# *                                                                 *
# * Copyright (C) 1998 Timothy E. Dowling                           *
# *                                                                 *
# * 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; either version 2  *
# * of the License, or (at your option) any later version.          *
# * A copy of this License is in the file:                          *
# *   $EPIC_PATH/License.txt                                        *
# *                                                                 *
# * 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.            *
# *                                                                 *
# * You should have received a copy of the GNU General Public       *
# * License along with this program; if not, write to the Free      *
# * Software Foundation, Inc., 59 Temple Place - Suite 330,         *
# * Boston, MA  02111-1307, USA.                                    *
# *                                                                 *
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#
#  The top Makefile for the EPIC model.
#
#  T. Dowling
#
#  Note: Each logical line after a target is executed as a separate
#        shell, therefore, to propagate variables use backslashes and
#        semicolons to string commands together into one line.
#  Note: Do not put spaces around the "=" in variable assignments
#        in the Bourne shell.
#

SHELL = /bin/sh

all:
	@if [ $(MACHINE_TYPE) = LINUX ] ; then \
	  export CC=/usr/bin/gcc ; \
	  export CPPFLAGS="-DNDEBUG -Df2cFortran" ; \
	  export CFLAGS="-O3" ; \
	  export FC=/usr/bin/g77 ; \
	  export FFLAGS="-O3" ; \
	  export CXX=/usr/bin/g++ ; \
	elif [ $(MACHINE_TYPE) = decmips ] ; then \
	  CC=gcc ;        export CC ; \
	  CFLAGS=-g ;     export CFLAGS ; \
	  FC="" ;         export FC ; \
	  FFLAGS="" ;     export FFLAGS ; \
	  CXX="";         export CXX ; \
	  CPPFLAGS=-g ;   export CPPFLAGS ; \
	fi ; \
	cd $(EPIC_PATH)/netcdf/src ; \
	echo "Configuring netCDF (Network Common Data Format)..." ; \
	./configure > configure.log ; \
	echo "Making netCDF..." ; \
	make 
	@if [ $(EPIC_MPI_HOST) = $(MACHINE_NAME) ] ; then \
	  if [ $(MPI_PATH) != none ] ; then \
	    cd $(EPIC_PATH)/src/mpg ; \
	    make ; \
	    cd $(EPIC_PATH)/src/mpi ; \
	    make ; \
	    cp -p mpi_launch.csh $(EPIC_PATH)/bin ; \
	  else \
	    echo MPI_PATH = $(MPI_PATH) ; \
	  fi ; \
	else \
	  echo EPIC_MPI_HOST = $(EPIC_MPI_HOST) ; \
	fi 
	@if [ $(EPIC_SINGLE_HOST) != none ] ; then \
	  cd $(EPIC_PATH)/src/single ; \
	  make ; \
	  cp -p single_launch.csh $(EPIC_PATH)/bin ; \
	else \
	  echo EPIC_SINGLE_HOST = $(EPIC_SINGLE_HOST) ; \
	fi 
	@if [ $(EPIC_VIEW_HOST) = $(MACHINE_NAME) ] ; then \
	    cd $(EPIC_PATH)/src/view ; \
	    make ; \
	else \
	  echo EPIC_VIEW_HOST = $(EPIC_VIEW_HOST) ; \
	fi 

clean:
	@cd $(EPIC_PATH)/netcdf/src ; \
	make clean ; 
	cd $(EPIC_PATH)/src/mpi ; \
	make clean ; \
	cd $(EPIC_PATH)/src/single ; \
	make clean ; \
	cd $(EPIC_PATH)/src/view ; \
	make clean ; \
	cd $(EPIC_PATH)/src/mpg ; \
	make clean 

clear:
	@rm -f *BAK *bak *~ ; \
	cd $(EPIC_PATH)/netcdf/src ; \
	make distclean ; \
	cd $(EPIC_PATH)/src/mpi ; \
	make clear ; \
	cd $(EPIC_PATH)/src/single ; \
	make clear ; \
	cd $(EPIC_PATH)/src/view ; \
	make clear ; \
	cd $(EPIC_PATH)/src/mpg ; \
	make clear ; \
	cd $(EPIC_PATH) ; \
	rm -f *BAK *bak *~ *% *.log; \
	cd $(EPIC_PATH)/tmp ; \
	rm -f *; \
	cd $(EPIC_PATH)/help ; \
	rm -f *BAK *bak *~ *% *.log; \
	cd $(EPIC_PATH)/idl ; \
	rm -f *BAK *bak *~ *% *.ps *.dat *.nc *.pca *.gif *.log; \
	cd $(EPIC_PATH)/util ; \
	rm -f *BAK *bak *~ *% *.log; \
	cd $(EPIC_PATH)/include ; \
	rm -f *BAK *bak *~ *% *.log; \
	cd $(EPIC_PATH)/src/shared ; \
	rm -f core *o *BAK *bak *~ *% *.log; \
	cd $(EPIC_PATH)/src/shared/thermo_fortran ; \
	rm -f core *o *BAK *bak *~ *% *.log; \
	cd $(EPIC_PATH)/bin ; \
	rm -f core list_dir *.dat *.nc *.mod *.$(MACHINE_TYPE) *BAK *bak *~ *% *.log; 

install:
	@if [ $(MACHINE_TYPE) = LINUX ] ; then \
	  export CC=/usr/bin/gcc ; \
	  export CPPFLAGS="-DNDEBUG -Df2cFortran" ; \
	  export CFLAGS="-O3" ; \
	  export FC=/usr/bin/g77 ; \
	  export FFLAGS="-O3" ; \
	  export CXX=/usr/bin/g++ ; \
	elif [ $(MACHINE_TYPE) = decmips ] ; then \
	  CC=gcc ;        export CC ; \
	  CFLAGS=-g ;     export CFLAGS ; \
	  FC="" ;         export FC ; \
	  FFLAGS="" ;     export FFLAGS ; \
	  CXX="";         export CXX ; \
	  CPPFLAGS=-g ;   export CPPFLAGS ; \
	fi ; \
	cd $(EPIC_PATH)/netcdf/src ; \
	echo "Configuring netCDF (Network Common Data Format)..." ; \
	if [ $(MACHINE_TYPE) = decmips ] ; then \
	  ./configure ; \
	else \
	  ./configure > configure.log ; \
	fi ; \
	echo "Making netCDF..." ; \
	make ; \
	echo "Installing netCDF..." ; \
	make install  
	@if [ $(EPIC_MPI_HOST) = $(MACHINE_NAME) ] ; then \
	  if [ $(MPI_PATH) != none ] ; then \
	    cd $(EPIC_PATH)/src/mpg ; \
	    make install ; \
	    cd $(EPIC_PATH)/src/mpi ; \
	    make install ; \
	    cp -p mpi_launch.csh $(EPIC_PATH)/bin ; \
	  else \
	    echo MPI_PATH is $(MPI_PATH) ; \
	  fi ; \
	else \
	  echo EPIC_MPI_HOST = $(EPIC_MPI_HOST) ; \
	fi
	@if [ $(EPIC_SINGLE_HOST) != none ] ; then \
	  cd $(EPIC_PATH)/src/single ; \
	  make install ; \
	  cp -p single_launch.csh $(EPIC_PATH)/bin ; \
	else \
	  echo EPIC_SINGLE_HOST = $(EPIC_SINGLE_HOST) ; \
	fi 
	@if [ $(EPIC_VIEW_HOST) = $(MACHINE_NAME) ] ; then \
	  cd $(EPIC_PATH)/src/view ; \
	  make install ; \
	else \
	  echo EPIC_VIEW_HOST = $(EPIC_VIEW_HOST) ; \
	fi 

depend:
	@if [ $(EPIC_MPI_HOST) = $(MACHINE_NAME) ] ; then \
	  if [ $(MPI_PATH) != none ] ; then \
	    cd $(EPIC_PATH)/src/mpi ; \
	    make depend ; \
	  else \
	    echo MPI_PATH = $(MPI_PATH) ; \
	  fi ; \
	else \
	  echo EPIC_MPI_HOST = $(EPIC_MPI_HOST) ; \
	fi
	@if [ $(EPIC_SINGLE_HOST) != none ] ; then \
	  cd $(EPIC_PATH)/src/single ; \
	  make depend ; \
	else \
	  echo EPIC_SINGLE_HOST = $(EPIC_SINGLE_HOST) ; \
	fi 
	@if [ $(EPIC_VIEW_HOST) = $(MACHINE_NAME) ] ; then \
	  cd $(EPIC_PATH)/src/view ; \
	  make depend; \
	else \
	  echo EPIC_VIEW_HOST = $(EPIC_VIEW_HOST) ; \
	fi 


