-
Notifications
You must be signed in to change notification settings - Fork 1
/
libbuild
executable file
·37 lines (31 loc) · 976 Bytes
/
libbuild
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
#!/bin/sh
dir="$(dirname "$0")"
. "$dir"/cflags
tmp=$(mktemp -d)
hide_unnecessary_symbols() {
[ ! -d "$tmp" ] && echo "W: couldn't find tmp dir" && return
gcc_syms="$tmp/gcc_exports.sym"
clang_syms="$tmp/clang_exports.list"
code="$tmp/main.c"
echo "int main() { return 0; }" >> "$code"
exports='ezpp ezpp_ errstr oppai_'
( printf '{global:'
for e in $exports; do
printf '%s;' "$e"
done
printf 'local:*;};' ) | sed 's/_;/_*;/g' >"$gcc_syms"
echo "$exports" | tr ' ' '\n' | sed s/_$/_*/g > "$clang_syms"
for flags in "-Wl,--version-script=$gcc_syms" \
"-Wl,-exported_symbols_list,$clang_syms"
do
if "$cc" $flags "$code" -o /dev/null >/dev/null 2>&1; then
ldflags="$ldflags $flags"
return
fi
done
echo "W: can't figure out how to hide unnecessary symbols"
}
hide_unnecessary_symbols
$cc -shared $cflags -DOPPAI_EXPORT \
"$@" oppai.c $ldflags -fpic -o liboppai.so
[ -d "$tmp" ] && rm -rf "$tmp"