drd: Add a consistency check
[valgrind.git] / tests / check_makefile_consistency
blob3e0ae4cbc68fa8b4715159b703b0e0c1a9fcc733
1 #!/bin/sh
3 # Verify consistency of the regression test files present in a directory with
4 # the contents of the EXTRA_DIST Makefile.am variable.
6 # Expand variables in a Makefile ($(NAME) syntax), evaluate $(add_suffix ...)
7 # and ignore $(noinst_SCRIPTS).
8 parse_makefile() {
9 cat "$1" |
10 awk '/\\$/ {
11 n = $0
12 sub("\\\\$", "", n)
13 if (line != "")
14 line = line " " n
15 else
16 line = n
18 /[^\\]$/ {
19 if (line != "") {
20 print line " " $0
21 line = ""
22 } else {
23 print
25 }' |
26 awk '{
27 if (match($0, "^ *[A-Za-z_]* *= *.*$")) {
28 varname = $0
29 gsub("^ *", "", varname)
30 gsub(" *=.*", "", varname)
31 value = $0
32 gsub("^ *[A-Za-z_]* *= *", "", value)
33 var[varname] = value
35 for (v in var)
36 gsub("\\$\\( *" v " *\\)", var[v])
37 while ((pos = match($0, "\\$\\( *addsuffix *[^,)]*, *[^)]*\\)")) >= 1) {
38 suffix = substr($0, pos)
39 gsub("^\\$\\( *addsuffix *", "", suffix)
40 gsub(",.*", "", suffix)
41 names = substr($0, pos)
42 gsub("^\\$\\( *addsuffix *[^,)]*, *", "", names)
43 gsub("\\).*", "", names)
44 split(names, name)
45 name_and_suff=""
46 for (n in name)
47 name_and_suff = name_and_suff " " name[n] suffix
48 sub("\\$\\( *addsuffix *[^,)]*, *[^)]*\\)", name_and_suff)
50 print
51 }' |
52 sed 's/\$(noinst_SCRIPTS)//'
55 if [ $# = 0 ]; then
56 echo "Error: tool name argument is missing."
57 exit 1
60 rc=0
62 # For all directories specified as an argument, find the Makefile.am files
63 # beneath and check the consistency of the files *.vgtest and *.exp* files
64 # in that directory with the filenames specified in EXTRA_DIST in Makefile.am.
65 for t in "$@"
67 find $t -name Makefile.am |
68 while read m; do
69 d="$(dirname "$m")"
71 rc=0
72 if cd $d; then
73 parsed_makefile="$(parse_makefile Makefile.am)"
74 for f in $(ls -d *.exp* *.gdb *.vgtest 2>/dev/null)
76 if [ "$f" = "*.exp*" -o "$f" = "*.gdb" -o "$f" = "*.vgtest" ]; then
77 continue
79 if ! echo "${parsed_makefile}" 2>/dev/null | grep '^ *EXTRA_DIST *=' |
80 grep -qw "$f"
81 then
82 echo "$m:1: error: $f is missing in EXTRA_DIST"
83 rc=1
85 done
87 for f in $(ls -d filter* 2>/dev/null)
89 if ! echo "${parsed_makefile}" 2>/dev/null | grep '^ *dist_noinst_SCRIPTS *=' |
90 grep -qw "$f"
91 then
92 echo "$m:1: error: $f is missing in dist_noinst_SCRIPTS"
93 rc=1
95 done
97 for f in $(parse_makefile Makefile.am | sed -n 's/^ *EXTRA_DIST *=//p')
99 if [ ! -e "$f" ]; then
100 echo "$m:1: error: $f is in EXTRA_DIST but doesn't exist"
101 rc=1
103 done
105 for f in $(parse_makefile Makefile.am | sed -n 's/^ *dist_noinst_SCRIPTS *=//p')
107 if [ ! -e "$f" ]; then
108 echo "$m:1: error: $f is in dist_noinst_SCRIPTS but doesn't exist"
109 rc=1
111 done
113 [ $rc = 0 ]
115 if [ $? != 0 ]; then
116 rc=1
118 [ $rc = 0 ]
119 done
120 if [ $? != 0 ]; then
121 rc=1
123 [ $rc = 0 ]
124 done
125 exit $?