Created
October 22, 2017 14:41
-
-
Save palmerc/7719967b4512ce4aad456632ffdc4547 to your computer and use it in GitHub Desktop.
A script meant to remove unwanted architectures from static libraries and report missing ones
This file contains hidden or 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/bash | |
contains() { | |
local match="$1" | |
shift | |
local list=( "${@}" ) | |
for item in "${list[@]}"; do | |
if [[ "${item}" == "${match}" ]]; then | |
echo true | |
return 1 | |
fi | |
done | |
echo false | |
return 0 | |
} | |
read -r -a libraries <<< "$1" | |
read -r -a valid_architectures <<< "$2" | |
echo "Libraries to check ${libraries[*]}" | |
echo "Required architectures ${valid_architectures[*]}" | |
# Check each static library for the included architectures and toss anything that shouldn't be included | |
for library in "${libraries[@]}"; do | |
declare -a archive_library_architectures=() | |
# Handle finding the architectures in a static library, fat or not. | |
read -r -a archive_library_architectures <<< "$( lipo -detailed_info "${library}" | | |
grep architecture | | |
sed -e 's/.*architecture:\{0,1\} \{0,1\}//' | | |
tr '\r\n' ' ' | | |
xargs echo -n )" | |
echo "${library} contains ${archive_library_architectures[*]}" | |
missing_architectures=() | |
for valid_architecture in "${valid_architectures[@]}"; do | |
has_architecture=$( contains "${valid_architecture}" "${archive_library_architectures[@]}" ) | |
if [[ "${has_architecture}" = false ]]; then | |
missing_architectures+=( "${valid_architecture}" ) | |
fi | |
done | |
if [ "${#missing_architectures[@]}" -gt 0 ]; then | |
echo "${library} missing ${missing_architectures[*]}" | |
fi | |
invalid_architectures=() | |
for archive_library_architecture in "${archive_library_architectures[@]}"; do | |
has_architecture=$( contains "${archive_library_architecture}" "${valid_architectures[@]}" ) | |
if [[ "${has_architecture}" = false ]]; then | |
invalid_architectures+=( "${archive_library_architecture}" ) | |
fi | |
done | |
for invalid_architecture in "${invalid_architectures[@]}"; do | |
echo "lipo -remove ${invalid_architecture} -output ${library} $library" | |
# lipo -remove "${invalid_architecture}" -output "${library}" "$library" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment