-
Notifications
You must be signed in to change notification settings - Fork 3
/
dependmodule.sh
executable file
·52 lines (49 loc) · 1.41 KB
/
dependmodule.sh
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
#!/bin/bash
#This file is part of SuperNu. SuperNu is released under the terms of the GNU GPLv3, see COPYING.
#Copyright (c) 2013-2022 Ryan T. Wollaeger and Daniel R. van Rossum. All rights reserved.
if [ $# != 0 ]; then
files=$*
else
return 1
fi
#
#-- collect the filenames belonging to each module
declare -A modnarr
for i in $files; do
fname=${i/%.o/.f}
if [[ ! -f $fname ]]; then fname=${i/%.o/.f90}; fi
[[ -s $fname ]] || continue
modnames=$(egrep '^ *module ' $fname |awk '{print $2}')
for modname in $modnames; do
modnarr[${modname}]=${i/%.f*/.o}
done
done
#
for i in $files; do
#-- filename
fname=${i/%.o/.f}
if [[ ! -f $fname ]]; then fname=${i/%.o/.f90}; fi
[[ -s $fname ]] || continue
#-- module name
modname=$(egrep -m 1 '^ *module ' $fname |awk '{print $2}')
#-- extract dependencies
depraw=($(egrep '^ +(use |include )' $fname | tr '"' ' '|tr "'" ' '| sed -e "s/ *,.*$//;s/ *!.*$//"))
#-- translate module dependencies to module filename
deps=()
for ((j=0;j<${#depraw[*]};j=j+2)); do
typ=${depraw["$j"],,} #-- lowercase
dep=${depraw["$((j+1))"]}
#-- include file
if [[ $typ == 'include' ]]; then
deps+=($dep)
#-- module
else
dep2=${modnarr["$dep"]}
[[ -z $dep2 ]] && printf "\nin file ($fname) unknown module: $dep\n" >&2 && exit 1
deps+=($dep2)
fi
done
#-- uniq
dep=$(echo ${deps[@]} |tr ' ' '\n' |sort |uniq |tr '\n' ' ')
printf "${i/%.f*/.o} $modname.mod: $fname $dep\n"
done