Skip to content

Instantly share code, notes, and snippets.

@leovandriel
Created September 24, 2012 11:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leovandriel/3775603 to your computer and use it in GitHub Desktop.
Save leovandriel/3775603 to your computer and use it in GitHub Desktop.
Xcode Run Script for building static framework for Cocoa Touch iOS
# Xcode Run Script for building iOS static framework.
# Requires a preconfigured Cocoa Touch Static Library.
# Usage:
# 1. Open project > Add Target > iOS Aggregate > Finish
# 2. Add Build Phase > Add Run Script > Paste
# 3. Manually assign PROJECT, TARGET, HEADERS, PRODUCT, OUTPUT
# 4. Run outputs to ${SRCROOT}/build
#
# License: Public Domain
# Author: Leonard van Driel, 2012
#set -e
echo "Configure script"
PROJECT="<name-of-xcode-project>"
TARGET="<name-of-static-lib-target>"
HEADERS="<public-headers-folder-path-setting>"
PRODUCT="<product-name-setting>"
OUTPUT="<name-of-framework>"
echo "Remove previous products"
rm -rf "${SRCROOT}/build/$OUTPUT/"
rm -rf "${SRCROOT}/build/$OUTPUT.framework/"
echo "Build static lib for iphoneos and iphonesimulator"
xcodebuild -project "${SRCROOT}/$PROJECT.xcodeproj" -target $TARGET -configuration Release -arch "armv6 armv7 armv7s" -sdk iphoneos
xcodebuild -project "${SRCROOT}/$PROJECT.xcodeproj" -target $TARGET -configuration Release -arch i386 -sdk iphonesimulator
echo "Populate static library directory"
mkdir -p "${SRCROOT}/build/$OUTPUT/Resources"
lipo -create -output "${SRCROOT}/build/$OUTPUT/lib$OUTPUT.a" "${SRCROOT}/build/Release-iphoneos/lib$PRODUCT.a" "${SRCROOT}/build/Release-iphonesimulator/lib$PRODUCT.a"
cp -R "${SRCROOT}/build/Release-iphoneos/$HEADERS" "${SRCROOT}/build/$OUTPUT/Headers"
#cp -R "${SRCROOT}/<some-resource>" "${SRCROOT}/build/$OUTPUT/Resources"
echo "Populate static framework"
mkdir -p "${SRCROOT}/build/$OUTPUT.framework/Versions/A"
cp -R "${SRCROOT}/build/$OUTPUT/Headers" "${SRCROOT}/build/$OUTPUT.framework/Versions/A"
cp -R "${SRCROOT}/build/$OUTPUT/Resources" "${SRCROOT}/build/$OUTPUT.framework/Versions/A"
cp "${SRCROOT}/build/$OUTPUT/lib$OUTPUT.a" "${SRCROOT}/build/$OUTPUT.framework/Versions/A/$OUTPUT"
echo "Link framework skeleton"
ln -s "A" "${SRCROOT}/build/$OUTPUT.framework/Versions/Current"
ln -s "Versions/Current/Headers" "${SRCROOT}/build/$OUTPUT.framework/Headers"
ln -s "Versions/Current/Resources" "${SRCROOT}/build/$OUTPUT.framework/Resources"
ln -s "Versions/Current/$OUTPUT" "${SRCROOT}/build/$OUTPUT.framework/$OUTPUT"
echo "Clean up intermediates"
rm -rf "${SRCROOT}/build/Release-iphoneos/"
rm -rf "${SRCROOT}/build/Release-iphonesimulator/"
rm -rf "${SRCROOT}/build/$TARGET.build/"
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment