File: moduledep.sh

package info (click to toggle)
espresso 5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 114,160 kB
  • sloc: f90: 204,965; sh: 45,382; ansic: 27,570; tcl: 14,940; xml: 7,618; makefile: 2,860; perl: 1,944; fortran: 924; python: 178; awk: 57
file content (54 lines) | stat: -rwxr-xr-x 2,146 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# moduledep.sh -- script that computes dependencies on Fortran 90 modules

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

# files whose dependencies must be computed
sources=`echo *.f90 |
sed 's/\*\.f90//g'`   # remove the "*.f90" that remains
#                     # when there are no such files
if test "$sources" = "" ; then exit ; fi

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

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@
# cast all module names to lowercase because Fortran is case insensitive
egrep -i "^ *use " $sources |             # look for "USE name"
sed 's/f90:/o /
     s/,/ /' |                            # replace extension, insert space
#                                         #   and remove trailing comma
awk '{print $1 " : @" tolower($3) "@"}' | # create dependency entry
sort | uniq > moduledep.tmp1              # remove duplicates

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

# 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
sort  | uniq                         # remove duplicates

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