--- MITgcm/tools/genmake 2000/11/30 19:58:13 1.22 +++ MITgcm/tools/genmake 2001/05/29 14:01:40 1.35 @@ -1,10 +1,20 @@ #!/bin/csh -f # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/Attic/genmake,v 1.22 2000/11/30 19:58:13 adcroft Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/Attic/genmake,v 1.35 2001/05/29 14:01:40 adcroft Exp $ +# $Name: $ # # Makefile generator for MITgcm UV codes -# created by cnh 03/98 -# adapted by aja 06/98 +# 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 ) +set ENABLE = ( ) +set MODS = ( ) + +# Grab variables/lists from .genmakerc +if (-r .genmakerc) source .genmakerc # Process command-line arguments set allargs=( $argv ) @@ -24,8 +34,52 @@ 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 @@ -35,7 +89,30 @@ echo "Including paths to JAM libraries" breaksw case -help: - echo "usage: $0 [-help] [-makefile[=...]] [-platform=...] [-mpi]" + 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: @@ -47,28 +124,149 @@ shift allargs end -if ($?platform == 0) then +# Default actions/options + +# If platform wasn't specified then determine platform type of the host +if (! $?platform) then set platform = (`uname`) endif -if ($?mfile == 0) set mfile = ( Makefile.$platform ) +# 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 -# Note -# o If you prefer/need everything under a single directory -# copy everything in ../eesupp/src, ../model/src, -# ../eesupp/inc and ../model/inc into a directory and then -# edit the paths below to ./ -set SOURCEDIRS = ( ../eesupp/src/ ../model/src/ ../diags/src/ ../pkg/*/ ) -set INCLUDEDIRS = ( ./ ../eesupp/inc/ ../model/inc/ ../diags/inc/ ../pkg/*/ ) -set BUILDDIR = ( ../bin/ ) -set EXEDIR = ( ../exe/ ) -set EXECUTABLE = ( mitgcmuv ) +# +# 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 -sf' ) +set LN = ( 'ln -s' ) set CPP = ( '/lib/cpp -P' ) set KPP = ( ) set FC = ( 'f77' ) @@ -105,7 +303,7 @@ set KPPFILES = ( 'main.F' ) set KFLAGS1 = ( '-scan=132 -noconc -cmp=' ) set FC = ( 'f77' ) - set FFLAGS = ( '-convert big_endian -r8 -extend_source -u -automatic -call_shared -notransform_loops -align dcommons' ) + 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' ) @@ -126,7 +324,7 @@ 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' ) + set FFLAGS = ( '-extend_source -mp -mpio -bytereclen -r10000 -mips4 -r8 -static' ) set FOPTIM = ( '-O3' ) # set NOOPTFLAGS = ( '-O0' ) # set NOOPTFILES = ( 'barrier.F different_multiple.F ' \ @@ -172,7 +370,7 @@ set LIBS = ( '-lmpi' ) breaksw case SunOS: - set LN = ( '/usr/bin/ln -fs' ) + 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') @@ -181,7 +379,7 @@ set NOOPTFILES = ( 'barrier.F different_multiple.F external_fields_load.F ini_vertical_grid.F') breaksw case SunOS+mpi: - set LN = ( '/usr/bin/ln -fs' ) + 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' ) @@ -222,7 +420,7 @@ set LIBS = ( '-L/usr/local/lib/LINUX/ch_p4/ -lfmpich -lmpich' ) set INCLUDES = ( '-I/usr/local/include' ) case Linux: - set LN = ( '/bin/ln -fs' ) + set LN = ( '/bin/ln -s' ) set CPP = ( '/lib/cpp -traditional -P' ) set DEFINES = ( ${DEFINES} '-D_BYTESWAPIO -DWORDLENGTH=4' ) set FC = ( 'g77' ) @@ -232,18 +430,18 @@ breaksw case Linux+pgi+mpi: if ($?include_jam_libs) then - set INCLUDES = ( '-I/usr/local//mpich-cnh-install/include' ) - set LIBS = ( '-L/usr/local/mpich-cnh-install/lib/LINUX/ch_p4/ -lfmpich -lmpich' ) + 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 -fs' ) + set LN = ( '/bin/ln -s' ) set CPP = ( '/lib/cpp -traditional -P' ) set DEFINES = ( ${DEFINES} '-DWORDLENGTH=4' ) set FC = ( 'pgf77' ) - set FFLAGS = ( '-byteswapio' ) + set FFLAGS = ( '-byteswapio -r8 -Mnodclchk -Mextend' ) set FOPTIM = ( '-tp p6 -v -O2 -Munroll -Mvect=cachesize:512000,transform -Kieee' ) set LINK = ( 'pgf77' ) breaksw @@ -259,7 +457,7 @@ case sn7113: set FC = ( 'f90' ) set LINK = ( 'f90' ) - set LN = ( '/bin/ln -fs' ) + 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') @@ -271,7 +469,7 @@ case sn3002: set FC = ( 'f90' ) set LINK = ( 'f90' ) - set LN = ( '/bin/ln -fs' ) + 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') @@ -292,52 +490,68 @@ ## ## ############################################################################### -# Create list of files -set flist = `ls -1 ${SOURCEDIRS} | grep '.*\.[F]$'` -if ( $#flist ) then - echo -n 'SRCFILES = ' > srclist.inc - foreach ff ( ${flist} ) - set fname = ( ${ff:t} ) - echo ' \' >> srclist.inc - echo -n " " ${fname:r}.F >> srclist.inc - end -else - echo No source files found...\! - exit -endif -echo " " >> srclist.inc - -set flist = `ls -1 ${SOURCEDIRS} | grep '.*\.[c]$'` -if ( $#flist ) then - echo -n 'CSRCFILES = ' > csrclist.inc - foreach ff ( ${flist} ) - set fname = ( ${ff:t} ) - echo ' \' >> csrclist.inc - echo -n " " ${fname} >> csrclist.inc -else - echo -n 'CSRCFILES =' > csrclist.inc -endif -echo " " >> csrclist.inc - # Convert lists of directories into command-line options foreach inc ($INCLUDEDIRS) set INCLUDES = ($INCLUDES -I$inc) end -set SRCSTARS = ( ) + +# 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 SRCSTARS = ("${SRCSTARS}" $dr\*.\[Fc\] ) + 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 pn" >> ${mfile} +echo "# This makefile was generated automatically on" >> ${mfile} echo "# $THISDATE" >> ${mfile} echo "# by the command:" >> ${mfile} echo "# ${0} $argv" >> ${mfile} @@ -362,11 +576,13 @@ # LINK : Command for link editor program # LIBS : Library flags /or/ additional optimization/debugging flags -BUILDDIR = ${BUILDDIR} -SOURCEDIRS = ${SOURCEDIRS} +ROOTDIR = ${ROOTDIR} +BUILDDIR = ${BUILDDIR} +SOURCEDIRS = ${SOURCEDIRS} INCLUDEDIRS = ${INCLUDEDIRS} -EXEDIR = ${EXEDIR} -EXECUTABLE = \$(EXEDIR)${EXECUTABLE} +EXEDIR = ${EXEDIR} +EXECUTABLE = \$(EXEDIR)/${EXECUTABLE} +TOOLSDIR = ${TOOLSDIR} EOF @@ -377,6 +593,7 @@ # extra stuff for Hyades ............................................ HYADES_DIR = /u/u0/cnh/jam-lib/software HYADES_DIR = /u/u0/cnh/jam-lib-twoproc +HYADES_DIR = /usr/local/jamlib/current/dual_proc WORK_DIR = \$(HYADES_DIR) DEPOSIT_DIR = linux_bin @@ -408,7 +625,7 @@ # Unix ln (link) LN = ${LN} # C preprocessor -CPP = cat \$< | ../tools/set64bitConst.sh | ${CPP} +CPP = cat \$< | \$(TOOLSDIR)/set64bitConst.sh | ${CPP} # Special preprocessor (KAP on DECs, FPP on Crays) KPP = ${KPP} # Fortran compiler @@ -439,7 +656,7 @@ echo 'F77FILES = $(SRCFILES:.F=.f)' >> ${mfile} echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o)' >> ${mfile} -rm -f srclist.inc csrclist.inc +rm -f srclist.inc csrclist.inc flist.tmp clist.tmp cat >> ${mfile} <> ${mfile} echo ' $(FC) $(FFLAGS) $(NOOPTFLAGS) -c $<' >> ${mfile} end -echo >> ${mfile} +echo "" >> ${mfile} + +# Add rules for links +cat srclinks.tmp >> ${mfile} +rm -f srclinks.tmp + +echo "" >> ${mfile} echo "# DO NOT DELETE" >> ${mfile} exit