#!/bin/csh -f # # $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/Attic/genmake,v 1.38 2001/07/13 15:16:48 heimbach Exp $ # $Name: $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 # adapted by aja 06/98 # modified by aja 01/00 # Default lists set DISABLE = ( aim autodiff cal cost ctrl ecco exf grdchk ) set ENABLE = ( ) set MODS = ( ) # Grab variables/lists from .genmakerc if (-r .genmakerc) source .genmakerc # Process command-line arguments set allargs=( $argv ) while ($#allargs) set arg = $allargs[1] switch ($arg) case -makefile: set mfile = ( Makefile ) breaksw case -makefile=*: set mfile = ( `echo $arg | sed 's/-makefile=//' `) breaksw case -platform: case -platform=: echo "To change platform you must specify one with -platform=" echo "eg. -platform=sparc or -platform=mips" exit breaksw case -platform*: if ($?platform) then echo Option -platform=dir can only be specified once.; exit 1 endif set platform = ( `echo $arg | sed 's/-platform=//' `) breaksw case -rootdir: case -rootdir=: echo "To specify root directory you must specify one with -rootdir=dir" echo "with NO space eg. -rootdir=../../.. or -rootdir=/usr/people/joe/src" exit breaksw case -rootdir=*: if ($?ROOTDIR) then echo "***" Warning: variable \$ROOTDIR is already set to $ROOTDIR echo "***" Command line \"$arg\" will override this. endif set ROOTDIR = ( `echo $arg | sed 's/-rootdir=//' `) breaksw case -mods: case -mods=: echo "To specify an additional source directory you must specify one with -mods=dir" echo "with NO space eg. -mods=../code or -mods=/usr/people/joe/src" exit breaksw case -mods=*: set MODS = ( $MODS `echo $arg | sed 's/-mods=//' | sed 's/,/ /g' `) breaksw case -disable: case -disable=: echo "To disable packages from compilation use -disable=pkg1,pkg2" echo "with NO spaces eg. -disable=kpp,gmredi or -disable=all (to enable all packages)" exit breaksw case -disable=*: set DISABLE = ( $DISABLE `echo $arg | sed 's/-disable=//' | sed 's/,/ /g' `) breaksw case -enable: case -enable=: echo "To enable packages from compilation use -enable=pkg1,pkg2" echo "with NO spaces eg. -enable=aim or -enable=all (to enable all packages)" echo "-enable overrides -disable, ie. a package listed in both is enabled" exit breaksw case -enable=*: set ENABLE = ( $ENABLE `echo $arg | sed 's/-enable=//' | sed 's/,/ /g' `) breaksw case -mpi: echo "Enabling MPI options" set USEMPI breaksw case -jam: set include_jam_libs echo "Including paths to JAM libraries" breaksw case -help: echo "usage: $0 [-help] [-makefile[=...]] [-platform=...] [-mpi] [-jam] [-disable=pkg1[,pkg2,...]] [-enable=pkg1[,pkg2,...]] [-mods=dir1[,dir2,...]] [-rootdir=dir]" cat << EOF $0 is used to generate the Makefile in the current directory. Typical invocations are: o from "bin": ../tools/genmake o from "verification/expt/code": ../../../tools/genmake o from "verification/expt/input": ../../../tools/genmake -mods=../code o from a scratch directory: ~/mitgcm/tools/genmake -rootdir=~/mitgcm or ~/mitgcm/tools/genmake -rootdir=~/mitgcm -mods=~/mymods Packages (collected modules of code) can be disabled to avoid unnecessary compilation of unused code. For instance if you know you will not use GM/Redi, KPP and OBCS and they are appropriate turned-off in the configuration: .../tools/genmake -disable=gmredi,kpp,obcs If you add some source files you can re-call the previous instance of genmake with "make makefile". genmake also reads the file .genmakerc which can be used to configure options (primarily the command-line options above) for particular experiments. EOF exit breaksw default: echo "Unknown command-line option: " $arg echo $0 "-help to show usage" exit breaksw endsw shift allargs end # Default actions/options # If platform wasn't specified then determine platform type of the host if (! $?platform) then set platform = (`uname`) endif # If name of makefile wasn't specified then use default "Makefile" if (! $?mfile) set mfile = ( Makefile ) set mach = ( `uname -a` ) echo Operating system: $mach # Directories for source, includes, binaries and executables # # If -rootdir wasn't specified then assume script is being run from bin # but if it was supplied then we should place the executable in the build dir if (! $?ROOTDIR) then set pwd=`pwd` if ($pwd:t == bin & -d ../model & -d ../eesupp & -d ../pkg) then set ROOTDIR = ( .. ) endif endif # Scan for logical ROOTDIR if (! $?ROOTDIR) then foreach dr (. .. ../.. ../../.. ../../../.. ../../../../..) if (-d $dr/model & -d $dr/eesupp & -d $dr/pkg) then set ROOTDIR = $dr echo ROOTDIR was not specified. Setting ROOTDIR = \"$ROOTDIR\" break endif end endif if (! $?ROOTDIR) then echo Root directory was not specified and could not be determined. echo Specify the root location of the model source with -rootdir=dir exit 1 endif if (! -d $ROOTDIR) then echo Root directory $ROOTDIR not found.;exit 1 endif # If -mods wasn't specified then we will assume that we can find all the # source code in the standard directories if (! $?MODS) then set SOURCEDIRS = ( ) set INCLUDEDIRS = ( . ) else set SOURCEDIRS = ( $MODS ) set INCLUDEDIRS = ( . $MODS ) endif if (! $?BUILDDIR) set BUILDDIR = ( . ) if (! -d $BUILDDIR) then echo Build directory $BUILDDIR not found.;exit 1 endif if (! $?EXEDIR) then set pwd=`pwd` if ($pwd:t == bin & -d ../exe & $ROOTDIR == ..) then set EXEDIR = ( ../exe ) else set EXEDIR = ( . ) endif endif if (! -d $EXEDIR) then echo Executable directory $EXEDIR not found.;exit 1 endif if (! $?TOOLSDIR) set TOOLSDIR = ( $ROOTDIR/tools ) if (! -d $TOOLSDIR) then echo Tools directory $TOOLSDIR not found.;exit 1 endif if (! $?EXECUTABLE) set EXECUTABLE = ( mitgcmuv ) # We have a special set of source files in eesupp/src which # are generated from some template source files. We'll make them # first so the appear as regular source code if (-r $ROOTDIR/eesupp/src/Makefile) then echo Making source files in eesupp from templates... (cd $ROOTDIR/eesupp/src/; make) >& make_eesupp.errs if ($status == 0) then rm -f make_eesupp.errs else cat make_eesupp.errs exit 2 endif endif # Now scan the standard source code tree foreach dr ($SOURCEDIRS) set adr=$dr if (! -d $adr) then echo mods directory $adr not found.; exit 1 endif echo Adding mods dir: $adr end if (! $?PACKAGES) then set PACKAGES=() foreach pkg (`cd $ROOTDIR/pkg; find . -type d | grep -v CVS | sed 's:\./::' | grep -v "\." | sort`) if (-d $ROOTDIR/pkg/$pkg) set PACKAGES=($PACKAGES $pkg) end endif foreach dr ($PACKAGES) set enable foreach p ($DISABLE) if ($p != 'all' & ! -d $ROOTDIR/pkg/$p) then echo Specified package \"$p\" does not exist. exit 1 endif if ($dr == $p) unset enable if ($p == 'all') unset enable # The following allows entire trees to be disabled if ($dr:h == $p) unset enable if ($dr:h:h == $p) unset enable if ($dr:h:h:h == $p) unset enable if ($dr:h:h:h:h == $p) unset enable end foreach p ($ENABLE) if ($dr == $p) set enable end if ($?enable) then set adr=$ROOTDIR/pkg/$dr if (! -d $adr) then echo Source directory $adr not found.; exit 1 endif echo Adding pkg dir: $adr set SOURCEDIRS = ($SOURCEDIRS $adr) set INCLUDEDIRS = ($INCLUDEDIRS $adr) else echo " *" Package \"$dr\" NOT enabled. endif end if (! $?STANDARDDIRS) set STANDARDDIRS=(eesupp model) foreach dr ($STANDARDDIRS) set adr=$ROOTDIR/$dr/src if (! -d $adr) then echo Source directory $adr not found.; exit 1 endif echo Adding src dir: $adr set SOURCEDIRS = ($SOURCEDIRS $adr) set idr = `echo $adr | sed 's/src/inc/'` set INCLUDEDIRS = ($INCLUDEDIRS $idr) end # This is the generic configuration. # Platform specific options are chosen below set LN = ( 'ln -s' ) set CPP = ( '/lib/cpp -P' ) set KPP = ( ) set FC = ( 'f77' ) set LINK = ( 'f77' ) set DEFINES = ( ) set INCLUDES = ( ) set FFLAGS = ( ) set FOPTIM = ( ) set KFLAGS1 = ( ) set KFLAGS2 = ( ) set LIBS = ( ) set KPPFILES = ( ) set NOOPTFILES = ( ) set NOOPTFLAGS = ( ) set RMFILES = ( ) # We often want to use different compile/link options is using MPI if ($?USEMPI) then set USEMPI = ( '+mpi' ) set DEFINES = ( ${DEFINES} '-DALLOW_USE_MPI -DALWAYS_USE_MPI' ) else set USEMPI # set DEFINES = ( ${DEFINES} '-UALLOW_USE_MPI -UALWAYS_USE_MPI' ) endif # Platform specific options switch ($platform$USEMPI) case OSF1: case OSF1+mpi: echo "Configuring for DEC Alpha" set CPP = ( '/usr/bin/cpp -P' ) set DEFINES = ( ${DEFINES} '-DTARGET_DEC -DWORDLENGTH=1' ) set KPP = ( 'kapf' ) set KPPFILES = ( 'main.F' ) set KFLAGS1 = ( '-scan=132 -noconc -cmp=' ) set FC = ( 'f77' ) set FFLAGS = ( '-convert big_endian -r8 -extend_source -automatic -call_shared -notransform_loops -align dcommons' ) set FOPTIM = ( '-O5 -fast -tune host -inline all' ) set NOOPTFLAGS = ( '-O0' ) set LIBS = ( '-lfmpi -lmpi -lkmp_osfp10 -pthread' ) set NOOPTFILES = ( 'barrier.F different_multiple.F external_fields_load.F') set RMFILES = ( '*.p.out' ) breaksw case IRIX64+mpi: echo "Configuring for SGI Mips with MPI" set DEFINES = ( ${DEFINES} '-DTARGET_SGI -DWORDLENGTH=4' ) set INCLUDES = ( '-I/usr/local/mpi/include' ) set FC = ( 'mpif77' ) set LINK = ( 'mpif77' ) set FFLAGS = ( '-extend_source -bytereclen -r10000 -mips4' ) set FOPTIM = ( '-O3' ) set RMFILES = ( 'rii_files' ) breaksw case IRIX64: echo "Configuring for SGI Mips" set DEFINES = ( ${DEFINES} '-DTARGET_SGI -DWORDLENGTH=4' ) set INCLUDES = ( '-I/usr/local/mpi/include' ) set FFLAGS = ( '-extend_source -mp -mpio -bytereclen -r10000 -mips4 -r8 -static' ) set FOPTIM = ( '-O3' ) # set NOOPTFLAGS = ( '-O0' ) # set NOOPTFILES = ( 'barrier.F different_multiple.F ' \ # 'external_fields_load.F' ) set RMFILES = ( 'rii_files' ) breaksw case o2: case IRIX: echo "Configuring for SGI O2 running IRIX 6.5" set DEFINES = ( ${DEFINES} '-DTARGET_SGI -DWORDLENGTH=4' ) set FFLAGS = ( '-extend_source -bytereclen -r10000 -mips4' ) set FOPTIM = ( '-O2' ) set NOOPTFLAGS = ( '-O0' ) breaksw case o2+mpi: case IRIX+mpi: echo "Configuring for SGI O2 running IRIX 6.5 with MPI" set DEFINES = ( ${DEFINES} '-DTARGET_SGI -DWORDLENGTH=4' ) set FFLAGS = ( '-extend_source -bytereclen -r10000 -mips4' ) set FOPTIM = ( '-O2' ) set NOOPTFILES = ( 'barrier.F different_multiple.F external_fields_load.F' ) set NOOPTFLAGS = ( '-O0' ) set LIBS = ( '-lmpi' ) breaksw case o2k+mpi: echo "Configuring for SGI Origin2000 running IRIX 6.5" set DEFINES = ( ${DEFINES} '-DTARGET_SGI -DWORDLENGTH=4' ) set INCLUDES = ( '-I/usr/include' ) set FFLAGS = ( '-n32 -extend_source -bytereclen' ) set FOPTIM = ( '-O2' ) set NOOPTFILES = ( 'calc_mom_rhs.F' ) set NOOPTFLAGS = ( '-O1' ) set LIBS = ( '-lmpi -lscs' ) breaksw case onyx: case onyx+mpi: echo "Configuring for SGI ONYX running IRIX64" set DEFINES = ( ${DEFINES} '-DTARGET_SGI -DWORDLENGTH=4' ) set FFLAGS = ( '-extend_source -bytereclen -r10000 -64' ) set FOPTIM = ( '-O2' ) set NOOPTFLAGS = ( '-O0' ) set NOOPTFILES = ( 'barrier.F different_multiple.F external_fields_load.F' ) set LIBS = ( '-lmpi' ) breaksw case SunOS: set LN = ( '/usr/bin/ln -s' ) set CPP = ( '/usr/ccs/lib/cpp -P' ) set DEFINES = ( ${DEFINES} '-DTARGET_SUN -DWORDLENGTH=4' ) set FFLAGS = ( '-stackvar -explicitpar -vpara -e -u -noautopar') set FOPTIM = ( '-fast -O3' ) set NOOPTFLAGS = ( '-O0' ) set NOOPTFILES = ( 'barrier.F different_multiple.F external_fields_load.F ini_vertical_grid.F ini_spherical_polar_grid.F ini_cori.F') breaksw case SunOS+mpi: set LN = ( '/usr/bin/ln -s' ) set CPP = ( '/usr/ccs/lib/cpp -P' ) set DEFINES = ( ${DEFINES} '-DTARGET_SUN -DWORDLENGTH=4' ) set INCLUDES = ( '-I/usr/local/mpi/include' ) set FFLAGS = ( '-stackvar -explicitpar -vpara -e -u -noautopar') set FOPTIM = ( '-fast -O3' ) set NOOPTFLAGS = ( '-O0' ) set LIBS = ( '-L/usr/local/mpi/lib/solaris/ch_shmem -lmpi -lthread' \ '-lsocket -lnsl' ) set NOOPTFILES = ( 'barrier.F different_multiple.F external_fields_load.F ini_vertical_grid.F ini_spherical_polar_grid.F ini_cori.F') breaksw case IRIX32: echo "Configuring for SGI ONYX running IRIX64" set DEFINES = ( ${DEFINES} '-DTARGET_SGI -DWORDLENGTH=4' ) set INCLUDES = ( '-I/usr/include' ) set FFLAGS = ( '-extend_source -bytereclen -r10000 -64' ) set FOPTIM = ( '-O2' ) set NOOPTFLAGS = ( '-O0' ) set NOOPTFILES = ( 'barrier.F different_multiple.F ' \ 'external_fields_load.F' ) set LIBS = ( '-lmpi' ) breaksw case HP-UX+mpi: set FC = ( 'mpif77' ) set LINK = ( 'mpif77' ) set INCLUDES = ( '-I/opt/mpi/include' ) case HP-UX: echo "Configuring for HP Exemplar" set CPP = ( '/usr/ccs/lbin/cpp -P' ) set DEFINES = ( ${DEFINES} '-DTARGET_HP -DWORDLENGTH=4' ) set FFLAGS = ( '+es +U77 +Onoautopar +Oexemplar_model' \ '+Okernel_threads' ) set FOPTIM = ( '+O2' ) set NOOPTFLAGS = ( '+O0' ) set NOOPTFILES = ( 'barrier.F different_multiple.F' \ 'external_fields_load.F' ) breaksw case Linux+mpi: set LIBS = ( '-L/usr/local/lib/LINUX/ch_p4/ -lfmpich -lmpich' ) set INCLUDES = ( '-I/usr/local/include' ) case Linux: set LN = ( '/bin/ln -s' ) set CPP = ( '/lib/cpp -traditional -P' ) set DEFINES = ( ${DEFINES} '-D_BYTESWAPIO -DWORDLENGTH=4' ) set FC = ( 'g77' ) set FFLAGS = ( '-Wimplicit -Wunused -Wuninitialized' ) set FOPTIM = ( '-O3 -malign-double -funroll-loops ' ) set LINK = ( 'g77' ) breaksw case Linux+pgi+mpi: if ($?include_jam_libs) then set INCLUDES = ( '-I/usr/local/mpich-1.2.1/pgi_fortran_binding/include' ) set LIBS = ( '-L/usr/local/mpich-1.2.1/pgi_fortran_binding/lib/ -lfmpich -lmpich' ) else set INCLUDES = ( '-I/usr/local/include' ) set LIBS = ( '-L/usr/local/lib/LINUX/ch_p4/ -lfmpich -lmpich' ) endif case Linux+pgi: set LN = ( '/bin/ln -s' ) set CPP = ( '/lib/cpp -traditional -P' ) set DEFINES = ( ${DEFINES} '-DWORDLENGTH=4' ) set FC = ( 'pgf77' ) set FFLAGS = ( '-byteswapio -r8 -Mnodclchk -Mextend' ) set FOPTIM = ( '-tp p6 -v -O2 -Munroll -Mvect=cachesize:512000,transform -Kieee' ) set LINK = ( 'pgf77' ) breaksw case T3E: case sn6312: set CPP = ( '/opt/ctl/bin/cpp -P') set DEFINES = ( ${DEFINES} '-DTARGET_T3E -DWORDLENGTH=4' ) set FC = ( 'f90' ) set LINK = ( 'f90' ) set FFLAGS = ( '-O 2,fusion' ) breaksw case T90: case sn7113: set FC = ( 'f90' ) set LINK = ( 'f90' ) set LN = ( '/bin/ln -s' ) set CPP = ( '/opt/ctl/bin/cpp -N -P' ) set DEFINES = ( ${DEFINES} '-DTARGET_CRAY_VECTOR -DWORDLENGTH=4' ) set FFLAGS = ( '-m3 -Rabc -N 132') set FOPTIM = ( '-O0' ) set NOOPTFLAGS = ( '-O0' ) set NOOPTFILES = ( 'barrier.F different_multiple.F external_fields_load.F') breaksw case SV1: case sn3002: set FC = ( 'f90' ) set LINK = ( 'f90' ) set LN = ( '/bin/ln -s' ) set CPP = ( '/opt/ctl/bin/cpp -N -P' ) set DEFINES = ( ${DEFINES} '-DTARGET_CRAY_VECTOR -DWORDLENGTH=4' ) set FFLAGS = ( '-m3 -Rabc -ei -eI -s cf77types -N 132') set FOPTIM = ( '-O0' ) set NOOPTFLAGS = ( '-O0' ) set NOOPTFILES = ( 'barrier.F different_multiple.F external_fields_load.F') breaksw default: echo "Error: platform not recognized: uname -p = " $platform$USEMPI exit breaksw endsw ############################################################################### ## ## ## Everything below here should not need to be changed. Platform specific ## ## changes and code specific changes should be configured above this line. ## ## ## ############################################################################### # Convert lists of directories into command-line options foreach inc ($INCLUDEDIRS) set INCLUDES = ($INCLUDES -I$inc) end # Search for source code rm -rf .links.tmp;mkdir .links.tmp echo "# This section creates symbolic links" > srclinks.tmp echo "" >> srclinks.tmp echo -n 'SRCFILES = ' > srclist.inc echo -n 'CSRCFILES = ' > csrclist.inc #echo -n 'HEADERFILES = ' > hlist.inc foreach dr ($SOURCEDIRS) set deplist=( ) foreach srcfile (`cd $dr; ls *.[hcF]`) if (! -r .links.tmp/$srcfile) then if (-f $dr/$srcfile) then switch ($srcfile:e) case F: touch .links.tmp/$srcfile set deplist=($deplist $srcfile) echo ' \' >> srclist.inc echo -n " " $srcfile >> srclist.inc breaksw case c: touch .links.tmp/$srcfile set deplist=($deplist $srcfile) echo ' \' >> csrclist.inc echo -n " " $srcfile >> csrclist.inc breaksw case h: # touch .links.tmp/$srcfile # set deplist=($deplist $srcfile) # echo ' \' >> hlist.inc # echo -n " " $srcfile >> hlist.inc breaksw endsw endif endif end if ($#deplist != 0) then echo "# These files are linked from $dr" >> srclinks.tmp echo $deplist':' >> srclinks.tmp echo ' $(LN) '$dr'/$@ $@' >> srclinks.tmp endif end rm -rf .links.tmp echo "" >> srclist.inc echo "" >> csrclist.inc #echo "" >> hlist.inc set THISHOSTNAME = ( `hostname` ) set THISCWD = ( `pwd` ) set THISDATE = ( `date` ) if (-r $mfile) mv -f $mfile $mfile.bak ########################################### ## This is the template for the makefile ## ########################################### echo Creating makefile: $mfile echo "# Multithreaded + multi-processing makefile for $mach" > ${mfile} echo "# This makefile was generated automatically on" >> ${mfile} echo "# $THISDATE" >> ${mfile} echo "# by the command:" >> ${mfile} echo "# ${0} $argv" >> ${mfile} echo "# executed by:" >> ${mfile} echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> ${mfile} cat >> ${mfile} <> ${mfile} <> ${mfile} <> ${mfile} cat csrclist.inc >> ${mfile} echo 'F77FILES = $(SRCFILES:.F=.f)' >> ${mfile} echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o)' >> ${mfile} rm -f srclist.inc csrclist.inc flist.tmp clist.tmp cat >> ${mfile} < \$@ .f.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain .F.p: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .p.f: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< EOF # Make list of "exceptions" that need ".p" files foreach sf ($KPPFILES) set fname=( ${sf:t} ) echo "${fname:r}.f: ${fname:r}.p" >> ${mfile} end foreach sf ($NOOPTFILES) set fname=( ${sf:t} ) echo "${fname:r}.o: ${fname:r}.f" >> ${mfile} echo ' $(FC) $(FFLAGS) $(NOOPTFLAGS) -c $<' >> ${mfile} end echo "" >> ${mfile} # Add rules for links cat srclinks.tmp >> ${mfile} rm -f srclinks.tmp echo "" >> ${mfile} echo "# DO NOT DELETE" >> ${mfile} exit