Created
August 30, 2013 04:53
-
-
Save mpurbo/6386432 to your computer and use it in GitHub Desktop.
XCode .framework build script for xcodeproj based projects.
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
# adapted from following sources: | |
# https://github.com/jverkoey/iOS-Framework | |
# http://codefriend.blogspot.jp/2011/09/creating-ios-framework-with-xcode4.html | |
# http://www.cocoanetics.com/2010/04/making-your-own-iphone-frameworks/ | |
# "No architecture.." error resolved by trying some of these: | |
# http://stackoverflow.com/questions/6151549/how-can-i-build-a-specific-architecture-using-xcodebuild | |
set -e | |
set +u | |
# Avoid recursively calling this script. | |
if [[ $FW_SCRIPT_RUNNING ]] | |
then | |
exit 0 | |
fi | |
set -u | |
export FW_SCRIPT_RUNNING=1 | |
FW_TARGET_NAME=${PROJECT_NAME} | |
FW_BIN_NAME="lib${FW_TARGET_NAME}.a" | |
FW_WRAPPER_NAME="${FW_TARGET_NAME}.framework" | |
FW_WORK_DIR=build | |
FW_OUT_DIR="${FW_WORK_DIR}/${FW_WRAPPER_NAME}" | |
FW_BUILD_IPHONEOS_PATH="${FW_WORK_DIR}/${CONFIGURATION}-iphoneos" | |
FW_BUILD_IPHONESIM_PATH="${FW_WORK_DIR}/${CONFIGURATION}-iphonesimulator" | |
# Public header path | |
# e.g. build/Debug-iphoneos/GeocoreHeaders/ | |
FW_PUBLIC_HEADERS_PATH="${FW_BUILD_IPHONEOS_PATH}/${FW_TARGET_NAME}Headers" | |
# ==== Build binary | |
# Building both architectures. | |
xcodebuild -configuration "${CONFIGURATION}" -target "${FW_TARGET_NAME}" -sdk iphoneos | |
xcodebuild VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=YES -arch i386 -configuration "${CONFIGURATION}" -target "${FW_TARGET_NAME}" -sdk iphonesimulator | |
# ==== Build .framework directory structure | |
# Clean framework output dir | |
if [ -d "${FW_OUT_DIR}" ] | |
then | |
rm -rf "${FW_OUT_DIR}" | |
fi | |
mkdir -p "${FW_OUT_DIR}/Versions/A/Headers" | |
# Link the "Current" version to "A" | |
/bin/ln -sfh A "${FW_OUT_DIR}/Versions/Current" | |
/bin/ln -sfh Versions/Current/Headers "${FW_OUT_DIR}/Headers" | |
/bin/ln -sfh "Versions/Current/${FW_TARGET_NAME}" "${FW_OUT_DIR}/${FW_TARGET_NAME}" | |
# Copy header files | |
# The -a ensures that the headers maintain the source modification date so that we don't constantly | |
# cause propagating rebuilds of files that import these headers. | |
/bin/cp -a "${FW_PUBLIC_HEADERS_PATH}/" "${FW_OUT_DIR}/Versions/A/Headers" | |
# Smash the two static libraries into one fat binary and store it in the .framework | |
lipo -create "${FW_BUILD_IPHONEOS_PATH}/${FW_BIN_NAME}" "${FW_BUILD_IPHONESIM_PATH}/${FW_BIN_NAME}" -output "${FW_OUT_DIR}/Versions/A/${FW_TARGET_NAME}" | |
# TODO: copy resources if necessary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment