-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
check_makefile_consistency
executable file
·141 lines (132 loc) · 3.98 KB
/
check_makefile_consistency
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/sh
# Verify consistency of the regression test files present in a directory with
# the contents of the EXTRA_DIST Makefile.am variable.
# Expand variables in a Makefile ($(NAME) syntax), evaluate $(add_suffix ...)
# and ignore $(noinst_SCRIPTS).
parse_makefile() {
cat "$1" |
awk '/\\$/ {
n = $0
sub("\\\\$", "", n)
if (line != "")
line = line " " n
else
line = n
}
/[^\\]$/ {
if (line != "") {
print line " " $0
line = ""
} else {
print
}
}' |
awk '{
if (match($0, "^ *[A-Za-z_]* *= *.*$")) {
varname = $0
gsub("^ *", "", varname)
gsub(" *=.*", "", varname)
value = $0
gsub("^ *[A-Za-z_]* *= *", "", value)
var[varname] = value
}
for (v in var)
gsub("\\$\\( *" v " *\\)", var[v])
while ((pos = match($0, "\\$\\( *addsuffix *[^,)]*, *[^)]*\\)")) >= 1) {
suffix = substr($0, pos)
gsub("^\\$\\( *addsuffix *", "", suffix)
gsub(",.*", "", suffix)
names = substr($0, pos)
gsub("^\\$\\( *addsuffix *[^,)]*, *", "", names)
gsub("\\).*", "", names)
split(names, name)
name_and_suff=""
for (n in name)
name_and_suff = name_and_suff " " name[n] suffix
sub("\\$\\( *addsuffix *[^,)]*, *[^)]*\\)", name_and_suff)
}
print
}' |
sed 's/\$(noinst_SCRIPTS)//'
}
if [ $# = 0 ]; then
echo "Error: tool name argument is missing."
exit 1
fi
rc=0
# For all directories specified as an argument, find the Makefile.am files
# beneath and check the consistency of the files *.vgtest and *.exp* files
# in that directory with the filenames specified in EXTRA_DIST in Makefile.am.
for t in "$@"
do
find $t -name Makefile.am |
while read m; do
d="$(dirname "$m")"
(
rc=0
if cd $d; then
parsed_makefile="$(parse_makefile Makefile.am)"
for f in $(ls -d *.exp* *.gdb *.vgtest 2>/dev/null)
do
if [ "$f" = "*.exp*" -o "$f" = "*.gdb" -o "$f" = "*.vgtest" ]; then
continue
fi
if ! echo "${parsed_makefile}" 2>/dev/null | grep '^ *EXTRA_DIST *=' |
grep -qw "$f"
then
echo "$m:1: error: $f is missing in EXTRA_DIST"
rc=1
fi
done
# check that filter files (but nor ones derived from filter*.in and emacs backup files)
# are in dist_noinst_SCRIPTS
for f in $(ls -d filter* 2>/dev/null | grep -v -e \.in -e '.*~$')
do
if [ ! -e "$f".in ]; then
if ! echo "${parsed_makefile}" 2>/dev/null | grep '^ *dist_noinst_SCRIPTS *=' |
grep -qw "$f"
then
echo "$m:1: error: $f is missing in dist_noinst_SCRIPTS"
rc=1
fi
fi
done
# check that filter files derived from filter*.in are in noinst_SCRIPTS
for f in $(ls -d filter*\.in 2>/dev/null )
do
f2=`echo $f | sed 's/\.in//'`
if ! echo "${parsed_makefile}" 2>/dev/null | grep '^ *noinst_SCRIPTS *=' |
grep -qw "$f2"
then
echo "$m:1: error: $f2 is missing in noinst_SCRIPTS"
rc=1
fi
done
for f in $(parse_makefile Makefile.am | sed -n 's/^ *EXTRA_DIST *=//p')
do
if [ ! -e "$f" ]; then
echo "$m:1: error: $f is in EXTRA_DIST but doesn't exist"
rc=1
fi
done
for f in $(parse_makefile Makefile.am | sed -n 's/^ *dist_noinst_SCRIPTS *=//p')
do
if [ ! -e "$f" ]; then
echo "$m:1: error: $f is in dist_noinst_SCRIPTS but doesn't exist"
rc=1
fi
done
fi
[ $rc = 0 ]
)
if [ $? != 0 ]; then
rc=1
fi
[ $rc = 0 ]
done
if [ $? != 0 ]; then
rc=1
fi
[ $rc = 0 ]
done
exit $?