moduledep.sh 2.1 KB
Newer Older
1 2 3
#!/bin/sh
# moduledep.sh -- script that computes dependencies on Fortran 90 modules

4 5 6 7
# make sure there is no locale setting creating unneeded differences.
LC_ALL=C
export LC_ALL

8
# files whose dependencies must be computed
9 10 11 12
sources=`echo *.f90 |
sed 's/\*\.f90//g'`   # remove the "*.f90" that remains
#                     # when there are no such files
if test "$sources" = "" ; then exit ; fi
13 14 15 16 17 18

# files that may contain modules
# extra directories can be specified on the command line
sources_all="$sources"
for dir in $*
do
19
  sources_all="$sources_all `echo $dir/*.f90`"
20
done
21 22 23
sources_all=`echo $sources_all |
sed 's/[^ ]*\*\.f90//g'`     # remove the "dir/*.f90" that remain
#                            # when there are no such files
24 25 26 27 28 29

rm -f moduledep.tmp1 moduledep.tmp2 # destroy previous contents

# create list of module dependencies
# each line is of the form:
# file_name.o : @module_name@
30
# cast all module names to lowercase because Fortran is case insensitive
31
egrep -H -i "^ *use " $sources |             # look for "USE name"
32
sed 's/f90:/o /
33 34 35 36
     s/,/ /' |                            # replace extension, insert space
#                                         #   and remove trailing comma
awk '{print $1 " : @" tolower($3) "@"}' | # create dependency entry
sort | uniq > moduledep.tmp1              # remove duplicates
37 38 39 40

# create list of available modules
# for each module, create a line of the form:
# s/@module_name@/file_name/g
41
egrep -H -i "^ *module " $sources_all |           # look for "MODULE name"
42
sed 's/f90:/o /
43 44 45 46
     s/\//\\\//g' |                            # replace extension, insert
#                                              #   space and escape slashes
awk '{print "s/@" tolower($3) "@/" $1 "/" }' | # create substitution line
sort | uniq > moduledep.tmp2                   # remove duplicates
47 48 49 50 51

# replace module names with file names
# by applying the file of substitution patterns just created
sed -f moduledep.tmp2 moduledep.tmp1 |
awk '{if ($1 != $3) print}' |          # remove self dependencies
52
sort  | uniq                         # remove duplicates
53

54
rm -f moduledep.tmp1 moduledep.tmp2 # remove temporary files