Last active
May 9, 2020 13:55
-
-
Save AlexAstroCat/d1e0e8fccfc196722095488f77aa980d to your computer and use it in GitHub Desktop.
Multi-Architecture helper scripts
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 | |
function architectures() { | |
if $(lipo -info $1 | grep -q 'not a fat file'); then | |
lipo -info $1 | awk -F ': ' '/Non-fat file/ { print $3 }' | |
else | |
lipo -detailed_info $1 | awk '/^architecture / { print $2 }' | |
fi | |
} | |
if [[ $(basename $0) == 'architectures' ]]; then | |
architectures $1 | |
fi |
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 | |
source $(dirname "$0")/architectures | |
usage() { | |
[ $# -eq 0 ] || echo "$*" >&2 | |
cat <<EOF >&2 | |
usage: $0 [options] <files_or_directories>... | |
options: | |
-s=<symbol> Symbol to look for | |
-b Check for bitcode | |
-h Help | |
EOF | |
exit 1 | |
} | |
OPT_HELP= | |
OPT_SYMBOL= | |
OPT_BITCODE= | |
while getopts "hbs:" opt; do | |
case $opt in | |
h) OPT_HELP=1 ;; | |
b) OPT_BITCODE=1 ;; | |
s) OPT_SYMBOL=$OPTARG ;; | |
\?) usage "Invalid option: -$opt" ;; | |
:) usage "Option -$opt requires an argument." ;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[[ $OPT_HELP ]] && usage | |
if [[ -n $OPT_SYMBOL ]]; then | |
for file in "$@"; do | |
if [[ $# > 1 ]]; then | |
echo $file | |
fi | |
archs=$(architectures "$file") | |
if [[ $(echo $archs | wc -w) -eq 1 ]]; then | |
nm "$file" | grep -q $OPT_SYMBOL && echo "\$archs\tYES" || echo "$archs\tNO" | |
else | |
for arch in $archs; do | |
nm -arch $arch "$file" | grep -q $OPT_SYMBOL && echo "$arch\tYES" || echo "$arch\tNO" | |
done | |
fi | |
done | |
elif [[ $OPT_BITCODE ]]; then | |
for file in "$@"; do | |
if [[ $# > 1 ]]; then | |
echo $file | |
fi | |
archs=$(architectures "$file") | |
if [[ $(echo $archs | wc -w) -eq 1 ]]; then | |
otool -l "$file" | grep -q __LLVM && echo "\$archs\tYES" || echo "$archs\tNO" | |
else | |
for arch in $archs; do | |
otool -arch $arch -l "$file" | grep -q __LLVM && echo "$arch\tYES" || echo "$arch\tNO" | |
done | |
fi | |
done | |
else | |
usage "You must specify either the -b or -s arguments" | |
fi |
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 | |
source $(dirname "$0")/architectures | |
archs=$(architectures $1) | |
if [[ $(echo $archs | wc -w) -eq 1 ]]; then | |
echo "Only a single architecture: $archs" | |
else | |
for arch in $archs; do | |
lipo -extract $arch $1 -output $1-$arch; | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment