1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22# Generate an exported symbols list out of a map file (as use on Linux/Solaris) in order to
23# build shared libraries on Mac OS X
24#
25# The below code fails may fail with 'perverted' mapfiles (using a strange line layout etc.)
26
27# Skip 'SECTION_NAME {' lines
28/^[\t ]*.*[\t ]*\{/ { next }
29
30# Skip 'global:' or 'local:' lines
31/global:/ || /local:/ { next }
32
33# Skip '*;' lines
34/^[\t ]*\*;[\t ]*/ { next }
35
36# Skip section end '}?;' lines
37/^[\t ]*\}[\t ]*.*[;]*/ { next }
38
39# Skip comment or empty lines
40/^[\t ]*#.*/ || /^[\t ]*$/ || /^$/ { next }
41
42# Echo all lines containing symbol names and prefix them with '_'
43# because symbols on Mac OS X start always with '__'
44{
45    # There may appear multiple symbols in one line
46    # e.g. "sym1; sym2; # and finally a comment"
47    # take this into account
48    for (i = 1; i <= NF ; i++) {
49	if ($i !~ /^[\t ]*#.*/) { # as long as the current field doesn't start with '#'
50	    gsub(/[\t ;]/, "", $i) # Remove leading spaces and trailing ';'
51	    printf("_%s\n",$i)
52	}
53	else { # ignore everything after a '#' (comment) sign
54	    break
55	}
56    }
57}
58