1 | #!/usr/bin/gawk -f
|
---|
2 |
|
---|
3 | # This program should generate Maketests
|
---|
4 |
|
---|
5 | BEGIN {
|
---|
6 | # read the list of files
|
---|
7 | for (i = 2; i < ARGC; i++)
|
---|
8 | files[ARGV[i]]
|
---|
9 |
|
---|
10 | # throw it away
|
---|
11 | ARGC = 2
|
---|
12 |
|
---|
13 | ntests = 0
|
---|
14 | }
|
---|
15 |
|
---|
16 | # process the file Makefile.am:
|
---|
17 |
|
---|
18 | /^[A-Z_]*_TESTS *=/,/[^\\]$/ {
|
---|
19 | gsub(/(^[A-Z_]*_TESTS *=|\\$)/,"")
|
---|
20 | for (i = 1; i <= NF; i++)
|
---|
21 | tests[++ntests] = $i
|
---|
22 | next
|
---|
23 | }
|
---|
24 |
|
---|
25 | /^NEED_LINT *=/,/[^\\]$/ {
|
---|
26 | gsub(/(^NEED_LINT *=|\\$)/,"")
|
---|
27 | for (i = 1; i <= NF; i++)
|
---|
28 | lint[$i]
|
---|
29 | next
|
---|
30 | }
|
---|
31 |
|
---|
32 | /^GENTESTS_UNUSED *=/,/[^\\]$/ {
|
---|
33 | gsub(/(^GENTESTS_UNUSED *=|\\$)/,"")
|
---|
34 | for (i = 1; i <= NF; i++)
|
---|
35 | unused[$i]
|
---|
36 | next
|
---|
37 | }
|
---|
38 |
|
---|
39 | /^[a-zA-Z][a-zA-Z0-9]*:/ {
|
---|
40 | # remember all targets from Makefile.am
|
---|
41 | sub(/:.*/,"")
|
---|
42 | targets[$0]
|
---|
43 | }
|
---|
44 |
|
---|
45 | # Now write the output file:
|
---|
46 | END {
|
---|
47 | # this line tells automake to keep the comment with the rules:
|
---|
48 | print "Gt-dummy:"
|
---|
49 | print "# file Maketests, generated from Makefile.am by the Gentests program"
|
---|
50 |
|
---|
51 | for (i = 1; i <= ntests; i++) {
|
---|
52 | x = tests[i]
|
---|
53 | if (!(x in targets))
|
---|
54 | generate(x)
|
---|
55 | }
|
---|
56 |
|
---|
57 | print "# end of file Maketests"
|
---|
58 | }
|
---|
59 |
|
---|
60 | function generate(x, s)
|
---|
61 | {
|
---|
62 | if (!(x".awk" in files))
|
---|
63 | printf "WARNING: file `%s.awk' not found.\n", x > "/dev/stderr"
|
---|
64 | else
|
---|
65 | delete files[x".awk"]
|
---|
66 |
|
---|
67 | print x ":"
|
---|
68 |
|
---|
69 | s = ""
|
---|
70 | if (x in lint) {
|
---|
71 | s = s " --lint"
|
---|
72 | delete lint[x]
|
---|
73 | }
|
---|
74 | if (x".in" in files) {
|
---|
75 | s = s " < $(srcdir)/$@.in"
|
---|
76 | delete files[x".in"]
|
---|
77 | }
|
---|
78 |
|
---|
79 | printf "\t@echo %s\n", x
|
---|
80 | printf "\t@AWKPATH=$(srcdir) $(AWK) -f $@.awk %s >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@\n", s
|
---|
81 | printf "\t@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@\n\n"
|
---|
82 | }
|
---|
83 |
|
---|
84 | END {
|
---|
85 | for (x in lint)
|
---|
86 | if (!(x in targets))
|
---|
87 | printf "WARNING: --lint target `%s' is missing.\n", x > "/dev/stderr"
|
---|
88 | for (x in files)
|
---|
89 | if (!(x in unused) && \
|
---|
90 | !(gensub(/\.(awk|in)$/,"","",x) in targets))
|
---|
91 | printf "WARNING: unused file `%s'.\n", x > "/dev/stderr"
|
---|
92 | }
|
---|