Skip to content

Instantly share code, notes, and snippets.

@zqqf16
Last active June 18, 2023 05:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zqqf16/1eb6649a68aeb1ee27fabd8a05ea8f1d to your computer and use it in GitHub Desktop.
Save zqqf16/1eb6649a68aeb1ee27fabd8a05ea8f1d to your computer and use it in GitHub Desktop.
Remove an object from a static library
#!/bin/sh
# Remove an object from a static library.
LIB_SRC=${1}
OBJ=${2}
if [ -z ${OBJ} ]; then
echo "Usage: $0 source.a target.o"
exit 0
fi
if [ ! -f ${LIB_SRC} ]; then
echo "File ${LIB_SRC} not found"
exit 1
fi
EXTRACT_FAT(){
SUBS=""
for ARCH in `echo $LIB_INFO | sed -n -e 's/Architectures in the fat file:.*are: \(.*\)/\1/p'`; do
SUB=${1}_${ARCH}.a
lipo -thin ${ARCH} ${1} -output ${SUB}
EXTRACT ${SUB} ${2}
SUBS="${SUBS} ${SUB}"
done
lipo -create ${SUBS} -output ${1}
rm ${SUBS}
}
EXTRACT(){
ar -d ${1} ${2}
}
LIB_INFO=`lipo -info ${LIB_SRC}`
if [ `echo $LIB_INFO | grep -c "Architectures in the fat file" ` -gt 0 ]; then
EXTRACT_FAT ${LIB_SRC} ${OBJ}
else
EXTRACT ${LIB_SRC} ${OBJ}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment