summaryrefslogtreecommitdiffstats
path: root/Modules/Platform/AIX/ExportImportList
blob: 4f67ef546e8f353777e56e91b605c119ffa7873f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

# This script is internal to CMake and meant only to be
# invoked by CMake-generated build systems on AIX.

usage='usage: ExportImportList -o <out-file> [-l <lib>] [--] <objects>...'

die() {
    echo "$@" 1>&2; exit 1
}

# Process command-line arguments.
out=''
lib=''
while test "$#" != 0; do
    case "$1" in
    -l) shift; lib="$1" ;;
    -o) shift; out="$1" ;;
    --) shift; break ;;
    -*) die "$usage" ;;
    *)  break ;;
    esac
    shift
done
test -n "$out" || die "$usage"

# Collect symbols exported from all object files.
out_tmp="$out.tmp$$"
trap 'rm -f "$out_tmp"' EXIT INT TERM
for f in "$@"; do
    dump -tov -X 32_64 "$f" |
    awk '
        BEGIN {
            V["EXPORTED"]=" export"
            V["PROTECTED"]=" protected"
        }
        /^\[[0-9]+\]\tm +[^ ]+ +\.(text|data|bss) +[^ ]+ +(extern|weak) +(EXPORTED|PROTECTED| ) / {
            if (!match($NF,/^(\.|__sinit|__sterm|__[0-9]+__)/)) {
                print $NF V[$(NF-1)]
            }
        }
    '
done > "$out_tmp"

# Generate the export/import file.
{
    if test -n "$lib"; then
        echo "#! $lib"
    fi
    sort -u "$out_tmp"
} > "$out"