]> granicus.if.org Git - apache/blob - build/make_var_export.awk
apply Apache License, Version 2.0
[apache] / build / make_var_export.awk
1 # Copyright 2001-2004 Apache Software Foundation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 #
16 # Based on apr's make_export.awk, which is
17 # based on Ryan Bloom's make_export.pl
18
19 /^#[ \t]*if(def)? (AP[RU]?_|!?defined).*/ {
20         if (old_filename != FILENAME) {
21                 if (old_filename != "") printf("%s", line)
22                 macro_no = 0
23                 found = 0
24                 count = 0
25                 old_filename = FILENAME
26                 line = ""
27         }
28         macro_stack[macro_no++] = macro
29         macro = substr($0, length($1)+2)
30         count++
31         line = line "#ifdef " macro "\n"
32         next
33 }
34
35 /^#[ \t]*endif/ {
36         if (count > 0) {
37                 count--
38                 line = line "#endif /* " macro " */\n"
39                 macro = macro_stack[--macro_no]
40         }
41         if (count == 0) {
42                 if (found != 0) {
43                         printf("%s", line)
44                 }
45                 line = ""
46         }
47         next
48 }
49
50 function add_symbol (sym_name) {
51         if (count) {
52                 found++
53         }
54         for (i = 0; i < count; i++) {
55                 line = line "\t"
56         }
57         line = line sym_name "\n"
58
59         if (count == 0) {
60                 printf("%s", line)
61                 line = ""
62         }
63 }
64
65 /^[ \t]*(extern[ \t]+)?AP[RU]?_DECLARE_DATA .*;$/ {
66        varname = $NF;
67        gsub( /[*;]/, "", varname);
68        gsub( /\[.*\]/, "", varname);
69        add_symbol(varname);
70 }
71
72 END {
73         printf("%s", line)
74 }