74 lines
1.4 KiB
Bash
Executable File
74 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# This wrapper script takes a given archive (static library) and processes it,
|
|
# either removing/renaming symbols according to the provided arguments.
|
|
|
|
BAZEL_EXECROOT=
|
|
ARCHIVE_TOOL=
|
|
OBJCOPY_TOOL=
|
|
INPUT_FILE=
|
|
OUTPUT_FILE=
|
|
STAGE_NUMBER=0
|
|
|
|
RENAME_FILE=
|
|
|
|
ARGS=()
|
|
|
|
set -e
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--archive)
|
|
ARCHIVE_TOOL="$2"
|
|
shift; shift; ;;
|
|
--objcopy)
|
|
OBJCOPY_TOOL="$2"
|
|
shift; shift; ;;
|
|
--input)
|
|
INPUT_FILE="$2"
|
|
shift; shift; ;;
|
|
--output)
|
|
OUTPUT_FILE="$2"
|
|
shift; shift; ;;
|
|
--remove|--redefine)
|
|
ARGS+=("$1")
|
|
shift ; ;;
|
|
-*)
|
|
echo "Unknown option $1"
|
|
exit 1 ; ;;
|
|
*)
|
|
ARGS+=("$1")
|
|
shift ; ;;
|
|
esac
|
|
done
|
|
|
|
set -- "${ARGS[@]}"
|
|
|
|
if [[ $# -eq 0 ]]; then
|
|
echo "No modification to be performed."
|
|
exit 2;
|
|
fi
|
|
|
|
IN=${INPUT_FILE}
|
|
while [[ $# -gt 0 ]]; do
|
|
OUT=${OUTPUT_FILE}.stage${STAGE_NUMBER}
|
|
case $1 in
|
|
--remove)
|
|
# Avoid read-only input file.
|
|
cat $IN > $OUT && $ARCHIVE_TOOL d $OUT @$2
|
|
|
|
shift; shift; ;;
|
|
--redefine)
|
|
$OBJCOPY_TOOL --redefine-syms $2 --weaken $IN $OUT
|
|
shift; shift; ;;
|
|
*)
|
|
echo "Bad argument: $1"
|
|
exit 3 ; ;;
|
|
esac
|
|
STAGE_NUMBER=$((STAGE_NUMBER+1))
|
|
IN=$OUT
|
|
done
|
|
|
|
|
|
mv $IN $OUTPUT_FILE
|