Create a gist now

Instantly share code, notes, and snippets.

@lepinsk /armv6-build-script.sh Secret
Last active Dec 15, 2015

xcode build script to manually generate and include armv6 machine code
# oh hey i didn't see you standing there dot sh
# adapted from jerome's script posted at http://stackoverflow.com/a/13529079/903936
# by julian lepinski; posted as part of http://lepinski.net/?p=159
# revised march 26, 2013
#####################
# configuration #
#####################
# change this to the full path where Xcode 4.4 (or below) puts your armv6 output
setenv ARMV6_OUTPUT_PATH "$BUILD_ROOT/Release-armv6-iphoneos/"
setenv ARMV6_EXECUTABLE_PATH "$ARMV6_OUTPUT_PATH$EXECUTABLE_PATH"
# you'll want to point this to xcodebuild inside your legacy xcode app bundle
setenv LEGACY_XCODE_PATH "/Applications/Xcode 4.4.1.app/Contents/Developer/usr/bin/xcodebuild"
# here we want to set our target (minimum) iOS version; we do this manually because
# xcode 4.5+ won't set this below 4.3, and ARMV6 devices cap out at iOS 4.2
# (set this lower if you're supporting older iOS versions)
setenv MINIMUM_OS 4.2
#####################
# end configuration #
#####################
echo CURRENT_ARCH = $CURRENT_ARCH
echo CONFIGURATION = $CONFIGURATION
echo MINIMUM_OS = $MINIMUM_OS
# abort the script for armv6 (built in older Xcode), simulator (i386), or debug builds
if ("$CURRENT_ARCH" == "armv6" || "$CURRENT_ARCH" == "i386" || "$CONFIGURATION" == "Debug") then
echo "Skipping ARMV6 build due to architecture or configuration"
exit 0
endif
# paths
setenv LIPO_PATH "$CODESIGNING_FOLDER_PATH/${EXECUTABLE_NAME}.lipo"
setenv FINAL_PATH "$CODESIGNING_FOLDER_PATH/$EXECUTABLE_NAME"
setenv FULL_INFO_PLIST_PATH "$CONFIGURATION_BUILD_DIR/$INFOPLIST_PATH"
# generating a log file for armv6 build
echo "------------------------- BUILDING ARMV6 NOW -------------------------"
setenv LOGFILE "$BUILD_ROOT/buildarmv6.txt"
setenv CONFIGURATION_ARMV6 "Release-armv6"
# remove previous log file, if one exists
rm -f $LOGFILE
# build armv6 version
echo "Building $FULL_PRODUCT_NAME armv6 CONFIG=Release-armv6 target=$TARGETNAME"
"$LEGACY_XCODE_PATH" -project "${PROJECT_FILE_PATH}" -target "${TARGETNAME}" -sdk "${PLATFORM_NAME}" -configuration "Release-armv6" CONFIGURATION_BUILD_DIR="$ARMV6_OUTPUT_PATH" >> "$LOGFILE"
# testing if the armv6 build succeeded
grep -Fxq "** BUILD SUCCEEDED **" "$LOGFILE"
if ("$status" == "1") then
echo "ARMV6 build error detected; opening log file"
open "$LOGFILE"
exit 1 #woah hang on you guys
else
echo "Looks like the ARMV6 build completed successfully"
echo "ARMV6 build log location: $LOGFILE"
endif
echo "---------------------------- ARMV6 BUILT -------------------------"
# this has been moved from the script-end; here we're manually inserting our minimum version
# into our app's plist
echo "Setting plist version to $MINIMUM_OS"
echo "plist path: $FULL_INFO_PLIST_PATH"
/usr/libexec/PlistBuddy -c "Set :MinimumOSVersion $MINIMUM_OS" "$FULL_INFO_PLIST_PATH"
plutil -convert binary1 "$FULL_INFO_PLIST_PATH"
# make sure something exists at $LIPO_PATH even if the next command fails
cp -pv "$FINAL_PATH" "$LIPO_PATH"
# if rebuilding without cleaning first, old armv6 might already be there so remove it
# if not, lipo won't output anything (thus the cp command just above)
lipo -remove armv6 -output "$LIPO_PATH" "$FINAL_PATH"
# add armv6 to the fat binary
lipo -create -output "$FINAL_PATH" "$ARMV6_EXECUTABLE_PATH" "$LIPO_PATH"
echo "------------------------- VERIFYING ARCHITECTURES -------------------------"
# (searching for these with trailing spaces so that "armv7" doesn't match the substring inside "armv7s")
set armv6index = `lipo -info "$FINAL_PATH" | awk '{print index($0,"armv6 ")}'`
set armv7index = `lipo -info "$FINAL_PATH" | awk '{print index($0,"armv7 ")}'`
set armv7sindex = `lipo -info "$FINAL_PATH" | awk '{print index($0,"armv7s ")}'`
if ("$armv6index" == "0") then
echo "WARNING: ARMV6 ARCHITECTURE MISSING FROM FINAL FILE; TERMINATING"
exit 1
else if ("$armv7index" == "0") then
echo "WARNING: ARMV7 ARCHITECTURE MISSING FROM FINAL FILE; TERMINATING"
exit 1
else if ("$armv7sindex" == "0") then
echo "WARNING: ARMV7S ARCHITECTURE MISSING FROM FINAL FILE; TERMINATING"
exit 1
endif
echo "Success: all architectures present in our binary"
lipo -info "$FINAL_PATH"
echo "---------------------------------------------------------------------------"
rm -f "$LIPO_PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment