Debian Codegraph @

pc/GenMakefileTst.awk

raw
1 #!/usr/bin/gawk -f
2
3 # This program generates pc/Makefile.tst
4
5 # Skip the first part of Makefile.in
6 /Get rid of core files/ { process = 1 }
7
8 ! process { next }
9
10 # Skip stuff that PC doesn't need
11 /^CMP =/, /^\.PRECIOUS/ { next }
12
13 # Process the bits in Makefile.in we need to generate the tests properly
14
15 # Tests that fail on MinGW
16 /^EXPECTED_FAIL_MINGW *=/,/[^\\]$/ {
17 print
18 gsub(/(^EXPECTED_FAIL_MINGW *=|\\$)/,"")
19 for (i = 1; i <= NF; i++)
20 mingw[$i]
21
22 next
23 }
24
25 # Tests that need a different cmp program
26 /^NEED_TESTOUTCMP *=/,/[^\\]$/ {
27 print
28 gsub(/(^NEED_TESTOUTCMP *=|\\$)/,"")
29 for (i = 1; i <= NF; i++)
30 testoutcmp[$i]
31
32 next
33 }
34
35 # Start of a target
36 ! in_recipe && /^[[:alpha:]_][-[:alnum:]_]*:/ {
37 in_recipe = 1
38 start_new_recipe()
39 next
40 }
41
42 # Empty targets, one after the other
43 in_recipe && /^[[:alpha:]_][-[:alnum:]_]*:/ {
44 print_recipe()
45 start_new_recipe()
46 next
47 }
48
49 # Collect recipe lines
50 in_recipe && /^\t/ {
51 recipe_lines[++line] = substitutions(name, $0)
52 next
53 }
54
55 # End of collected recipe, print it out
56 in_recipe && /(^[^\t])|(^$)/ {
57 in_recipe = 0
58 fix_recipe_for_cmp(name)
59 print_recipe()
60
61 print
62 next
63 }
64
65 # Default is to print input lines
66 process { print }
67
68 # substitutions --- replace *nix values with what's needed on Windows
69
70 function substitutions(test, string)
71 {
72 # locales
73 gsub(/en_US.UTF-8/, "ENU_USA.1252", string)
74 gsub(/fr_FR.UTF-8/, "FRA_FRA.1252", string)
75 gsub(/ja_JP.UTF-8/, "JPN_JPN.932", string)
76 gsub(/el_GR.iso88597/, "ell_GRC.1253", string)
77 gsub(/ru_RU.UTF-8/, "RUS_RUS.1251", string)
78
79 # command for `ls'
80 gsub(/@-ls/, "@-$(LS)", string)
81
82 # MSYS needs "/" to be doubled
83 gsub(/-F\//, "-F$(SLASH)", string)
84 gsub(/=@\//, "=@$(SLASH)", string)
85
86 return string
87 }
88
89 # fix_recipe_for_cmp --- fix $(CMP) in all lines of a recipe
90
91 function fix_recipe_for_cmp(test, i, string)
92 {
93 if (! (test in testoutcmp))
94 return
95
96 for (i in recipe_lines) {
97 string = recipe_lines[i]
98 if (string ~ /\$\(CMP\)/ && test in testoutcmp) {
99 gsub(/\$\(CMP\)/, "$(TESTOUTCMP)", string)
100 recipe_lines[i] = string
101 }
102 }
103 delete testoutcmp[test]
104 }
105
106 # print_recipe --- print out the recipe
107
108 function print_recipe( i, start)
109 {
110 print recipe_lines[1] # target:
111 if (line == 1)
112 return
113
114 # First line if it's @echo $@
115 if (recipe_lines[2] ~ /\t@echo [$]@/) {
116 start = 3
117 print recipe_lines[2]
118 } else
119 start = 2
120
121 # print the right warning
122 if (name in mingw) {
123 print "\t@echo Expect $@ to fail with MinGW."
124 }
125
126 # find first line from the end that starts with @
127 # make sure it starts with @-
128 for (i = line; i >= start; i--) {
129 if (recipe_lines[i] !~ /^\t@/)
130 continue
131
132 if (recipe_lines[i] ~ /^\t@-/)
133 break
134 else if (recipe_lines[i] ~ /^\t@/) {
135 recipe_lines[i] = "\t@-" substr(recipe_lines[i], 3)
136 break
137 }
138 }
139
140 # Print all the lines but the last
141 for (i = start; i <= line; i++)
142 print recipe_lines[i]
143 }
144
145 # start_new_recipe --- start collecting data from scratch
146
147 function start_new_recipe()
148 {
149 # get the name of the target
150 # use match(), not gensub(), so that this script is fully portable
151 match($0, /^[[:alpha:]_][-[:alnum:]_]*:/)
152 name = substr($0, RSTART, RLENGTH - 1) # leave out the colon
153
154 delete recipe_lines
155 line = 0
156 recipe_lines[++line] = $0
157 }