xref: /aosp_15_r20/external/cronet/third_party/apache-portable-runtime/src/build/make_nw_export.awk (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Licensed to the Apache Software Foundation (ASF) under one or more
2# contributor license agreements.  See the NOTICE file distributed with
3# this work for additional information regarding copyright ownership.
4# The ASF licenses this file to You under the Apache License, Version 2.0
5# (the "License"); you may not use this file except in compliance with
6# the License.  You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# Based on apr's make_export.awk, which is
17# based on Ryan Bloom's make_export.pl
18#
19
20BEGIN {
21    add_symbol("apr_wait_for_io_or_timeout")
22}
23
24function add_symbol(sym_name) {
25    sub(" ", "", sym_name)
26    exports[++idx] = sym_name
27}
28
29# List of functions that we don't support, yet??
30#/apr_##name##_set_inherit/{next}
31#/apr_##name##_unset_inherit/{next}
32
33/^[ \t]*AP[RUI]?_DECLARE[^(]*[(][^)]*[)]([^ ]* )*[^(]+[(]/ {
34    sub("[ \t]*AP[RUI]?_DECLARE[^(]*[(][^)]*[)][ \t]*", "")
35    sub("[(].*", "")
36    sub("([^ ]* (^([ \t]*[(])))+", "")
37    add_symbol($0)
38    next
39}
40
41/^[ \t]*AP_DECLARE_HOOK[^(]*[(][^)]*/ {
42    split($0, args, ",")
43    symbol = args[2]
44    sub("^[ \t]+", "", symbol)
45    sub("[ \t]+$", "", symbol)
46    add_symbol("ap_hook_" symbol)
47    add_symbol("ap_hook_get_" symbol)
48    add_symbol("ap_run_" symbol)
49    next
50}
51
52/^[ \t]*APR_POOL_DECLARE_ACCESSOR[^(]*[(][^)]*[)]/ {
53    sub("[ \t]*APR_POOL_DECLARE_ACCESSOR[^(]*[(]", "", $0)
54    sub("[)].*$", "", $0)
55    add_symbol("apr_" $0 "_pool_get")
56    next
57}
58
59/^[ \t]*APR_DECLARE_INHERIT_SET[^(]*[(][^)]*[)]/ {
60    sub("[ \t]*APR_DECLARE_INHERIT_SET[^(]*[(]", "", $0)
61    sub("[)].*$", "", $0)
62    add_symbol("apr_" $0 "_inherit_set")
63    next
64}
65
66/^[ \t]*APR_DECLARE_INHERIT_UNSET[^(]*[(][^)]*[)]/ {
67    sub("[ \t]*APR_DECLARE_INHERIT_UNSET[^(]*[(]", "", $0)
68    sub("[)].*$", "", $0)
69    add_symbol("apr_" $0 "_inherit_unset")
70    next
71}
72
73/^[ \t]*AP[RUI]?_DECLARE_DATA .*;/ {
74    gsub(/[*;\n\r]/, "", $NF)
75    gsub(/\[.*\]/, "", $NF)
76    add_symbol($NF)
77}
78
79
80END {
81    printf("Added %d symbols to export list.\n", idx) > "/dev/stderr"
82    # sort symbols with shell sort
83    increment = int(idx / 2)
84    while (increment > 0) {
85        for (i = increment+1; i <= idx; i++) {
86            j = i
87            temp = exports[i]
88            while ((j >= increment+1) && (exports[j-increment] > temp)) {
89                exports[j] = exports[j-increment]
90                j -= increment
91            }
92            exports[j] = temp
93        }
94        if (increment == 2)
95            increment = 1
96        else
97            increment = int(increment*5/11)
98    }
99    # print the array
100    printf(" (%s)\n", EXPPREFIX)
101    while (x < idx - 1) {
102        printf(" %s,\n", exports[++x])
103    }
104    printf(" %s\n", exports[++x])
105}
106
107