Back to home page

MITgcm

 
 

    


Warning, /optim/prep_make is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit 5cf43646 on 2024-03-01 18:50:49 UTC
5cf4364659 Mart*0001 #! /usr/bin/env bash
                0002 
                0003 usage()
                0004 {
                0005    echo
                0006    echo "Script to generate Makefile to build Executable 'optim.x'"
                0007    echo " from local '$template' + Makefile and header files from BUILD_DIR"
                0008    echo
                0009    echo "Usage:  $0  BUILD_DIR [OPTIONS]"
                0010    echo
                0011    echo "where BUILD_DIR is Directory where MITgcm executable was created"
                0012    echo "and possible OPTIONS are:"
                0013    echo " (-help|-h)      : print usage"
                0014    echo " (-dbug) NUMBER  : set 'debug' level to NUMBER (def=0, use 1 or 2)"
                0015    echo " (-fake)         : Fake Makefile to just check reading Input without 'lsopt'"
                0016    echo
                0017    exit 1
                0018 }
                0019 
                0020 template='makefile_templ'
                0021 newMkF='Makefile'
                0022 tmpFil=TTT.$$
                0023 fake=0
                0024 debug=0
                0025 
                0026 if test $# = 0 ; then usage ; else arg=$1 ; fi
                0027 if test $arg = '-h' -o $arg = '-help' ; then usage
                0028 else bldDir=$arg ; shift ; fi
                0029 
                0030 if test ! -f $template ; then
                0031    echo "Error: no template file '$template'"
                0032    usage
                0033 fi
                0034 if test -d $bldDir ; then
                0035    mkFile=$bldDir/Makefile
                0036    if test -f $mkFile ; then
                0037       echo " using Makefile and Included files from '$bldDir'"
                0038    else
                0039       echo "Error: no Makefile in dir '$bldDir'"
                0040       usage
                0041    fi
                0042 else
                0043    echo "Error: no directory '$bldDir'"
                0044    usage
                0045 fi
                0046 if [ $# -ge 1 ] ; then
                0047    prev_arg=
                0048    for arg in $* ; do
                0049       # If the previous option needs an argument, assign it.
                0050       if test -n "$prev_arg"; then
                0051          eval "$prev_arg=\$arg"
                0052          prev_arg=
                0053          continue
                0054       fi
                0055       optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'`
                0056       case $arg in
                0057          -help | -h ) usage ;;
                0058          -fake ) fake=1  ;;
                0059          -dbug ) prev_arg=debug ;;
                0060          -dbug=* ) debug=$optarg ;;
                0061          *) echo "Error: unrecognized option '$arg'" ; usage ;;
                0062       esac
                0063    done
                0064 fi
                0065 
                0066 #-- do sym-link of these S/R files:
                0067 LNK_LIST=ctrl_convert_header.F
                0068 for ff in $LNK_LIST ; do
                0069    if test ! -f $ff -a -f $bldDir/$ff ; then
                0070       echo " - link '$ff' from $bldDir"
                0071       ln -s $bldDir/$ff .
                0072    fi
                0073 done
                0074 
                0075 #-- make a local Makefile from template and account for this script options:
                0076 rm -f $newMkF
                0077 if test $fake = 1 ; then
                0078    EXTRA_OPT='EXCLUDE_LSOPT_TO_CHECK'
                0079    sed '/^LIB/s/ *-L..\/lsopt.*$//' $template | sed 's/^LIBS *=.*$/LIBS       =/' > $newMkF
                0080 else
                0081    EXTRA_OPT='OFFLINE'
                0082    cp $template $newMkF
                0083 fi
                0084 sed "s|_GET_BLD_DIR|${bldDir}|" $newMkF > $tmpFil
                0085 sed "s/_GET_EXTRA_OPT/${EXTRA_OPT}/" $tmpFil > $newMkF
                0086 
                0087 #-- Get setting from MITgcm Makefile:
                0088 SFX=`grep '^\.F\..*:$' $mkFile | head -1 | sed 's/\.F\.//' | sed 's/:$//'`
                0089 if test "x$SFX" = x ; then SFX=f
                0090   echo " Failed to get Suffix 'SFX' ; continue with default SFX='${SFX}'"
                0091 fi
                0092 sed "s/_GET_SFX_/${SFX}/" $newMkF > $tmpFil
                0093 mv -f $tmpFil $newMkF
                0094 
                0095 for KEY in CPPCMD FC FFLAGS FOPTIM
                0096 do
                0097    nc=`sed -n "/_GET_$KEY/=" $newMkF` ;
                0098    nm=`expr $nc - 1` ; np=`expr $nc + 1`
                0099    sed -n "1,$nm p" $newMkF > $tmpFil
                0100    grep "^$KEY =" $mkFile >> $tmpFil
                0101    sed -n "$np,$ p" $newMkF >> $tmpFil
                0102    if test $debug = 2 ; then
                0103       echo "-- KEY= '$KEY' : nm, nc, np= $nm , $nc , $np"
                0104       diff $tmpFil $newMkF
                0105    fi
                0106    mv -f $tmpFil $newMkF
                0107 done
                0108 
                0109 echo " new $newMkF generated:"
                0110 ls -l $newMkF
                0111 if [ $debug -ge 1 ] ; then
                0112    echo " diff $newMkF $template :"
                0113    diff $newMkF $template
                0114 fi