Merge branch 'maint-0.4.8'
[tor.git] / scripts / build / combine_libs
blob9dec483602482f0aa42526687b466a8c1683fe3f
1 #!/bin/sh
3 set -e
5 TMPDIR="$(mktemp -d -t tor_lib_combining.XXXXXX)"
6 ORIGDIR="$(pwd)"
8 trap 'cd "$ORIGDIR" && rm -rf "$TMPDIR"' 0
10 abspath() {
11 echo "$(cd "$(dirname "$1")" >/dev/null && pwd)/$(basename "$1")"
14 apple_symdef_fix() {
15 # On modern macOS and iOS we need to remove the "__.SYMDEF" and "__.SYMDEF
16 # SORTED" before we repack the archive.
17 # See: tor#40683.
18 if [ "$(uname -s)" = "Darwin" ] ; then
19 find . -name "__.SYMDEF*" -delete
23 TARGET=$(abspath "$1")
25 shift
27 for input in "$@"; do
28 cd "$ORIGDIR"
29 abs=$(abspath "$input")
30 dir="$TMPDIR"/$(basename "$input" .a)
31 mkdir "$dir"
32 cd "$dir" >/dev/null
33 "${AR:-ar}" x "$abs"
34 done
36 cd "$TMPDIR" >/dev/null
37 apple_symdef_fix
38 "${AR:-ar}" "${ARFLAGS:-cru}" library.tmp.a ./*/**
39 "${RANLIB:-ranlib}" library.tmp.a
40 mv -f library.tmp.a "$TARGET"