File: create-exports-NetworkManager.sh

package info (click to toggle)
network-manager 1.54.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 71,432 kB
  • sloc: ansic: 483,661; python: 11,632; xml: 8,546; sh: 5,552; perl: 596; cpp: 178; javascript: 130; ruby: 107; makefile: 64; lisp: 22
file content (108 lines) | stat: -rwxr-xr-x 2,275 bytes parent folder | download | duplicates (3)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash

set -e
set -o pipefail

die() {
    echo "$@"
    exit 1
}

# generates the linker version script src/core/NetworkManager.ver
# by looking at the symbols needed by the device and settings
# plugins. Note that this depends on how NetworkManager and
# the plugins are build. For example, compiling without
# --with-more-asserts will yield less symbols.
_sort() {
    LANG=C sort -u
}

call_nm() {
    if [ -n "$from_meson" ]; then
        "${NM:-nm}" "$1" |
            sed -n 's/.* \([^ ]\) \([^ ]*\)$/\1 \2/p'
    else
        libtool=(${LIBTOOL:-libtool})
        ${libtool[@]} --mode=execute "${NM:-nm}" "$1" |
            sed -n 's/.* \([^ ]\) \([^ ]*\)$/\1 \2/p'
    fi
}

get_symbols_nm () {
    base=./src/core/NetworkManager-all-sym
    call_nm "$base" |
        sed -n 's/^[tTDGRBS] //p' |
        _sort
}

get_symbols_explicit() {
    cat <<EOF | _sort
_IO_stdin_used
EOF
}

get_symbols_missing() {
    (for f in $(find ./src/core/settings/plugins/*/${libs} \
                     ./src/core/devices/*/${libs} \
                     ./src/core/ppp/${libs} -name '*.so' 2>/dev/null); do
        call_nm "$f" |
            sed -n 's/^\([U]\) \(\(nm_\|nmp_\|_nm\|NM\|_NM\|nmtst_\|c_siphash_\|c_list_\).*\)$/\2/p'
    done) |
        _sort |
        grep -Fx -f <(get_symbols_explicit) -v |
        grep -Fx -f <(get_symbols_nm)
}

pretty() {
    sed 's/.*/\t&;/'
}

do_update() {
    do_generate > ./src/core/NetworkManager.ver
}

if [ -f "build.ninja" ]; then
    from_meson=1
    libs=
else
    from_meson=
    libs=.libs/
fi

SYMBOLS_MISSING="$(get_symbols_missing | pretty)"
SYMBOLS_EXPLICIT="$(get_symbols_explicit | pretty)"

do_generate() {
    cat <<EOF
# this file is generated by $0
{
global:
$SYMBOLS_MISSING

$SYMBOLS_EXPLICIT
local:
	*;
};
EOF
}

test -f ./src/core/${libs}libNetworkManager.a || die "must be called from NetworkManager top build dir after building the tree"

case "$1" in
    --called-from-build)
        if test -z "${NM_BUILD_NO_CREATE_EXPORTS+x}"; then
            do_update
        else
            if test -f "./src/core/NetworkManager.ver"; then
                touch ./src/core/NetworkManager.ver
            fi
        fi
        ;;
    update)
        do_update
        ;;
    *)
        do_generate
        ;;
esac