create-exports-NetworkManager.sh 2.64 KB
Newer Older
1 2 3
#!/bin/bash

set -e
4
set -o pipefail
5

6 7 8 9 10
die() {
    echo "$@"
    exit 1
}

11 12 13 14 15 16 17 18 19 20 21
# generates the linker version script src/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.
#
# _build re-builds NetworkManager with relevant compile time
# options to yield the most symbols.
_build() {
    git clean -fdx
    ./autogen.sh --enable-ld-gc --enable-ifcfg-rh --enable-ifupdown \
22
        --enable-config-plugin-ibft --enable-teamdctl --enable-wifi \
23 24 25 26 27 28 29 30 31 32
        --with-modem-manager-1 --with-ofono --with-more-asserts \
        --with-more-logging
    make -j20
}

_sort() {
    LANG=C sort -u
}

call_nm() {
33
    "${NM:-nm}" "$1" |
34
        sed -n 's/.* \([^ ]\) \([^ ]*\)$/\1 \2/p'
35 36 37
}

get_symbols_nm () {
38 39 40 41 42 43
    if [ -z "$from_meson" ]; then
        base=./src/.libs/libNetworkManager.a
    else
        base=./src/nm-full-symbols
    fi
    call_nm "$base" |
44
        sed -n 's/^[tTDGRBS] //p' |
45 46 47 48 49 50 51 52 53 54
        _sort
}

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

get_symbols_missing() {
55
    (for f in $(find ./src/settings/plugins/*/${libs} \
56 57
                     ./src/devices/*/${libs} \
                     ./src/ppp/${libs} -name '*.so' 2>/dev/null); do
58
        call_nm "$f" |
59
            sed -n 's/^\([U]\) \(\(nm_\|nmp_\|_nm\|NM\|_NM\|c_siphash_\).*\)$/\2/p'
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
    done) |
        _sort |
        grep -Fx -f <(get_symbols_explict) -v |
        grep -Fx -f <(get_symbols_nm)
}

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

do_build() {
    do_update
    make
}

do_rebuild() {
    _build
    do_build
}

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

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

$(get_symbols_explict | pretty)
local:
	*;
};
EOF
}

98 99 100 101 102 103 104 105
if [ -f "build.ninja" ]; then
    from_meson=1
    libs=
else
    libs=.libs/
fi

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

case "$1" in
    rebuild)
109
        [ -n "$from_meson" ] && die "can't do a build when called from meson"
110 111 112
        do_rebuild
        ;;
    build)
113
        [ -n "$from_meson" ] && die "can't do a build when called from meson"
114 115
        do_build
        ;;
116
    --called-from-build)
117 118 119 120 121 122 123 124
        if test -z "${NM_BUILD_NO_CREATE_EXPORTS+x}"; then
            do_update
        else
            if test -f "./src/NetworkManager.ver"; then
                touch ./src/NetworkManager.ver
            fi
        fi
        ;;
125 126 127 128 129 130 131 132
    update)
        do_update
        ;;
    *)
        do_generate
        ;;
esac