combine_libs 847 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. set -e
  3. TMPDIR="$(mktemp -d -t tor_lib_combining.XXXXXX)"
  4. ORIGDIR="$(pwd)"
  5. trap 'cd "$ORIGDIR" && rm -rf "$TMPDIR"' 0
  6. abspath() {
  7. echo "$(cd "$(dirname "$1")" >/dev/null && pwd)/$(basename "$1")"
  8. }
  9. apple_symdef_fix() {
  10. # On modern macOS and iOS we need to remove the "__.SYMDEF" and "__.SYMDEF
  11. # SORTED" before we repack the archive.
  12. # See: tor#40683.
  13. if [ "$(uname -s)" = "Darwin" ] ; then
  14. find . -name "__.SYMDEF*" -delete
  15. fi
  16. }
  17. TARGET=$(abspath "$1")
  18. shift
  19. for input in "$@"; do
  20. cd "$ORIGDIR"
  21. abs=$(abspath "$input")
  22. dir="$TMPDIR"/$(basename "$input" .a)
  23. mkdir "$dir"
  24. cd "$dir" >/dev/null
  25. "${AR:-ar}" x "$abs"
  26. done
  27. cd "$TMPDIR" >/dev/null
  28. apple_symdef_fix
  29. "${AR:-ar}" "${ARFLAGS:-cru}" library.tmp.a ./*/**
  30. "${RANLIB:-ranlib}" library.tmp.a
  31. mv -f library.tmp.a "$TARGET"