Last active
June 18, 2023 05:36
-
-
Save zqqf16/1eb6649a68aeb1ee27fabd8a05ea8f1d to your computer and use it in GitHub Desktop.
Remove an object from a static library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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