bart | 5d28863 | 2011-10-23 12:14:51 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Verify consistency of the regression test files present in a directory with |
| 4 | # the contents of the EXTRA_DIST Makefile.am variable. |
| 5 | |
| 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 |
| 17 | } |
| 18 | /[^\\]$/ { |
| 19 | if (line != "") { |
| 20 | print line " " $0 |
| 21 | line = "" |
| 22 | } else { |
| 23 | print |
| 24 | } |
| 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 |
| 34 | } |
| 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) |
| 49 | } |
| 50 | print |
| 51 | }' | |
| 52 | sed 's/\$(noinst_SCRIPTS)//' |
| 53 | } |
| 54 | |
| 55 | if [ $# = 0 ]; then |
| 56 | echo "Error: tool name argument is missing." |
| 57 | exit 1 |
| 58 | fi |
| 59 | |
| 60 | rc=0 |
| 61 | |
| 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 "$@" |
| 66 | do |
| 67 | find $t -name Makefile.am | |
| 68 | while read m; do |
| 69 | d="$(dirname "$m")" |
| 70 | ( |
| 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) |
| 75 | do |
| 76 | if [ "$f" = "*.exp*" -o "$f" = "*.gdb" -o "$f" = "*.vgtest" ]; then |
| 77 | continue |
| 78 | fi |
| 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 |
| 84 | fi |
| 85 | done |
| 86 | |
| 87 | for f in $(ls -d filter* 2>/dev/null) |
| 88 | do |
| 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 |
| 94 | fi |
| 95 | done |
| 96 | |
| 97 | for f in $(parse_makefile Makefile.am | sed -n 's/^ *EXTRA_DIST *=//p') |
| 98 | do |
| 99 | if [ ! -e "$f" ]; then |
| 100 | echo "$m:1: error: $f is in EXTRA_DIST but doesn't exist" |
| 101 | rc=1 |
| 102 | fi |
| 103 | done |
| 104 | |
| 105 | for f in $(parse_makefile Makefile.am | sed -n 's/^ *dist_noinst_SCRIPTS *=//p') |
| 106 | do |
| 107 | if [ ! -e "$f" ]; then |
| 108 | echo "$m:1: error: $f is in dist_noinst_SCRIPTS but doesn't exist" |
| 109 | rc=1 |
| 110 | fi |
| 111 | done |
| 112 | fi |
| 113 | [ $rc = 0 ] |
| 114 | ) |
| 115 | if [ $? != 0 ]; then |
| 116 | rc=1 |
| 117 | fi |
| 118 | [ $rc = 0 ] |
| 119 | done |
| 120 | if [ $? != 0 ]; then |
| 121 | rc=1 |
| 122 | fi |
| 123 | [ $rc = 0 ] |
| 124 | done |
| 125 | exit $? |