Skip to content

Instantly share code, notes, and snippets.

@haikusw
Created November 21, 2011 19:41
Show Gist options
  • Save haikusw/1383680 to your computer and use it in GitHub Desktop.
Save haikusw/1383680 to your computer and use it in GitHub Desktop.
Run Script build phase script to make a universal static library.
#!/bin/sh
# makeuniversalstaticlib.sh
# SAMPLELib
#
#################[ Tests: helps workaround any future bugs in Xcode ]########
DEBUG_THIS_SCRIPT="false"
if [ $DEBUG_THIS_SCRIPT = "true" ]
then
echo "########### TESTS #############"
echo "Use the following variables when debugging this script; note that they may change on recursions"
echo "BUILD_DIR = $BUILD_DIR"
echo "BUILD_ROOT = $BUILD_ROOT"
echo "CONFIGURATION_BUILD_DIR = $CONFIGURATION_BUILD_DIR"
echo "BUILT_PRODUCTS_DIR = $BUILT_PRODUCTS_DIR"
echo "SYMROOT = $SYMROOT"
echo "CONFIGURATION_TEMP_DIR = $CONFIGURATION_TEMP_DIR"
echo "TARGET_BUILD_DIR = $TARGET_BUILD_DIR"
echo "ACTION = $ACTION"
echo "EXECUTABLE_NAME = ${EXECUTABLE_NAME}"
fi
EXECUTABLE_NAME="${EXECUTABLE_PREFIX}${PRODUCT_NAME}.${EXECUTABLE_EXTENSION}"
echo "EXECUTABLE_NAME = ${EXECUTABLE_NAME}"
UNIVERSAL_DIR="${BUILD_DIR}/${CONFIGURATION}-universal"
PHONE_PLATFORM_NAME="iphoneos"
SIMULATOR_PLATFORM_NAME="iphonesimulator"
echo ""
echo "Building iphone version..."
echo ""
TARGET_NAME="SAMPLELib-device"
xcodebuild -project "${PROJECT}.xcodeproj" -configuration "${CONFIGURATION}" -target "${TARGET_NAME}" -sdk "${PHONE_PLATFORM_NAME}" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
####################
echo ""
echo "Building simulator version..."
echo ""
TARGET_NAME="SAMPLELib-sim"
xcodebuild -project "${PROJECT}.xcodeproj" -configuration "${CONFIGURATION}" -target "${TARGET_NAME}" -sdk "${SIMULATOR_PLATFORM_NAME}" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
####################
echo ""
echo "Combining xcode and simulator versions..."
echo ""
if [ ! -d ${UNIVERSAL_DIR} ]; then
mkdir ${UNIVERSAL_DIR}
fi
echo "lipo -create -output \"${UNIVERSAL_DIR}/${EXECUTABLE_NAME}\" \"${BUILD_DIR}/${CONFIGURATION}-${PHONE_PLATFORM_NAME}/${EXECUTABLE_NAME}\" \"${BUILD_DIR}/${CONFIGURATION}-${SIMULATOR_PLATFORM_NAME}/${EXECUTABLE_NAME}\""
lipo -create -output "${UNIVERSAL_DIR}/${EXECUTABLE_NAME}" "${BUILD_DIR}/${CONFIGURATION}-${PHONE_PLATFORM_NAME}/${EXECUTABLE_NAME}" "${BUILD_DIR}/${CONFIGURATION}-${SIMULATOR_PLATFORM_NAME}/${EXECUTABLE_NAME}"
####################
echo ""
echo "Copying public headers to Universal library..."
echo ""
ditto -v --nocache "${BUILD_DIR}/${CONFIGURATION}-${PHONE_PLATFORM_NAME}/Headers" "${UNIVERSAL_DIR}/SAMPLEHeaders/"
echo ""
echo "Done"
echo ""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment