Skip to content

Instantly share code, notes, and snippets.

@NachoMan NachoMan/architectures
Last active Mar 21, 2019

Embed
What would you like to do?
Multi-Architecture helper scripts
#!/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
#!/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
#!/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
You can’t perform that action at this time.