-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include embedded BoringSSL into libsoter.a #681
Changes from all commits
3d5c400
467d674
63c78bc
c241a4c
10a2e9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Merge multiple static libraries into one. | ||
# | ||
# scripts/merge-static-libs.sh libtarget.a [libdep1.a ...] | ||
# | ||
# Libraries libdep1.a are merged into libtarget.a. That is, all object files | ||
# from those libraries are copied into the target library. | ||
# | ||
# Note that no deduplication is performed so use this script only once. | ||
|
||
set -euo pipefail | ||
|
||
AR=${AR:-ar} | ||
|
||
help() { | ||
cat $0 | awk 'NR == 3, /^$/ { print substr($0, 3) }' | ||
} | ||
|
||
while [[ $# -gt 0 ]] | ||
do | ||
case "$1" in | ||
-h|--help) help; exit;; | ||
--) shift; break;; | ||
-*) | ||
echo >&2 "Unknown option: $1" | ||
echo >&2 | ||
help | ||
exit 1 | ||
;; | ||
*) | ||
break | ||
;; | ||
esac | ||
done | ||
|
||
if [[ $# -lt 1 ]] | ||
then | ||
echo >&2 "Invalid command-line: missing target library name" | ||
echo >&2 | ||
help | ||
exit 1 | ||
fi | ||
|
||
target="$1" | ||
shift | ||
|
||
tempdir="$(mktemp -d)" | ||
trap 'rm -rf "$tempdir"' EXIT | ||
|
||
while [[ $# -gt 0 ]] | ||
do | ||
if [[ ! -f "$1" ]] | ||
then | ||
echo >&2 "No such file: $1" | ||
exit 1 | ||
fi | ||
# Cast a possibly relative path to the absolute one. | ||
src="$(cd "$(dirname "$1")" >/dev/null 2>&1 && pwd)/$(basename "$1")" | ||
cd "$tempdir" | ||
"$AR" x "$src" | ||
cd "$OLDPWD" | ||
# Actually merge the contents of the library into the target one. | ||
find "$tempdir" -type f -name '*.o' -print0 | xargs -0 "$AR" rs "$target" | ||
# Clean up and go on. | ||
rm -rf "$tempdir"/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are there any possible corner cases when this line will remove the whole user dir There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't unless There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should add a log message here? Something like "Preparing to remove $tempdir", and then "$tempdir is successfully removed". even if we are 99.9% sure that this line won't destroy the universe, in a very bad case, people will see the log message to understand what went wrong. |
||
shift | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../../scripts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😁 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the script is useless without at least two arguments: a target and minimum one source library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so useless, it is intentionally made a no op if there are no libraries to merge into the target library. This makes its behavior similar to sum function. It is useful because the case when there are no embedded libraries is no longer a special case.
The makefile filters out
*.a
files from dependencies oflibsoter.a
and passes them to this script. If there are no*.a
files in dependencies (e.g., when system OpenSSL is used) thenmerge-static-libs.sh
is invoked with onlybuild/libsoter.a
and does nothing.If this case is treated as an error, the Makefile will need to have a conditonal to avoid using
merge-static-libs.sh
which is unnecessary complexity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation.