Back to home page

MITgcm

 
 

    


Warning, /tools/f90mkdepend is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit 95cd2ded on 2024-09-18 19:58:09 UTC
0d77d4e131 Oliv*0001 #!/bin/bash
27c9249c85 Chri*0002 #
                0003 # Generate some make file dependency entries for a Fortran 90 file that employs "use".
0d77d4e131 Oliv*0004 #
89959bb283 Oliv*0005 # For every "use" statement, generate a dependency on lowercase(modulename).o
0d77d4e131 Oliv*0006 #
27c9249c85 Chri*0007 # Note: We assume that the name of a module and the same of source are the same.
266c458241 Oliv*0008 #       The name of the source file should be all lower case (except for the extension).
                0009 
95cd2dedde Ivan*0010 # set defaults
                0011 FS=f
                0012 FS90=f90
                0013 
                0014 # process option arguments
                0015 key_prev=
                0016 for key in "$@" ; do
                0017 
                0018     # If the previous option needs an argument, assign it.
                0019     if test -n "$key_prev"; then
                0020             eval "$key_prev=\$key"
                0021             key_prev=
                0022             continue
                0023     fi
                0024 
                0025     case $key in
                0026     -fs)
                0027         key_prev='FS'
                0028         ;;
                0029     -fs=*)
                0030         FS="${key#*=}"
                0031         ;;
                0032     -fs90)
                0033         key_prev='FS90'
                0034         ;;
                0035     -fs90=*)
                0036         FS90="${key#*=}"
                0037         ;;
                0038     *)
                0039         echo "f90mkdepend: Unknown option: $key"
                0040         exit 1
                0041         ;;
                0042     esac
                0043 done
                0044 
0d77d4e131 Oliv*0045 # don't complain if *.F90 doesn't match any files
                0046 shopt -s nullglob
27c9249c85 Chri*0047 
0d77d4e131 Oliv*0048 cat /dev/null > f90mkdepend.log
                0049 
95cd2dedde Ivan*0050 # append module dependencies to Makefile
0d77d4e131 Oliv*0051 for filename in *.F90 *.F *.h; do
                0052   # quick check for "use" to speed up processing
ba586b2fa7 Oliv*0053   if grep -i '^ *use ' $filename > /dev/null; then
0d77d4e131 Oliv*0054     # extract module name in lower case
95cd2dedde Ivan*0055     modreflist=$(grep -i '^ *use ' $filename | awk '{print tolower($2)}' | sed -e 's/,.*$//' -e 's/\r$//')
27c9249c85 Chri*0056 
266c458241 Oliv*0057     echo "$filename => $modreflist" >> f90mkdepend.log
                0058 
95cd2dedde Ivan*0059     # change .F90 into .$FS90, .F into .$FS for target
                0060     preprocessed=$(echo $filename | sed -e "s/\.F$/.$FS/" -e "s/\.F90$/.$FS90/")
0d77d4e131 Oliv*0061 
                0062     depline="$preprocessed:"
                0063     for m in $modreflist; do
                0064       # ignore modules that don't have an appropriately named source file
                0065       if [ -f $m.F90 ] || [ -f $m.F ]; then
                0066         depline="$depline $m.o"
7b05f46bce Oliv*0067       elif [ -f ${m%_mod}.F90 ] || [ -f ${m%_mod}.F ]; then
                0068         # source file name is module name without "_mod"
                0069         depline="$depline ${m%_mod}.o"
                0070       else
95cd2dedde Ivan*0071         echo "WARNING: f90mkdepend: in $filename no source file found for module $m" 1>&2
0d77d4e131 Oliv*0072       fi
                0073     done
                0074     echo $depline
                0075   fi
                0076 done