#!/bin/bash
# Build and package the SDK for iOS
# Assumes that you are in the SDK/iOS directory
LIPO=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/lipo
START_DIR=`pwd`
echo START_DIR = $START_DIR
cd ../../../build/ios
OGRE_BUILD_DIR=`pwd`
SDK_DIR=$OGRE_BUILD_DIR/sdk
echo OGRE_BUILD_DIR = $OGRE_BUILD_DIR
echo SDK_DIR = $SDK_DIR
if [ "$1" = "test" ];then
echo Test ends...
exit
fi
if [ "$1" = "copy" ];then
COPY_DIR=$OGRE_BUILD_DIR/../../sdks/ios/$2
rm -rf $COPY_DIR
echo Copy from $SDK_DIR to $COPY_DIR
mkdir -p $COPY_DIR
echo Created dir
cp -r $SDK_DIR/include $COPY_DIR
echo Copied headers
mkdir $COPY_DIR/lib
cp -r $SDK_DIR/lib/Debug $COPY_DIR/lib
echo copied Debug libs
cp -r $SDK_DIR/lib/Release $COPY_DIR/lib
echo copied Release libs
echo DONE
cd $COPY_DIR
pwd
exit
fi
# Clean up files from previous builds
if [ "$1" = "clean" ];then
echo Cleaning previous builds...
rm -R $SDK_DIR
exit
fi
# Read version number
OGRE_VERSION=`cat version.txt`
echo OGRE_VERSION = $OGRE_VERSION
# Invoke Xcode build for device and simulator
# Install targets will fail because they can't find libraries. So we've added a post build phase to copy them to the
# location that the target expects them then copy them to the correct location
function build_single_target {
echo Building for $CONFIG/$TARGET
LIB_DIR=$SDK_DIR/lib/$CONFIG-$TARGET
echo LIB_DIR = $LIB_DIR
#rm lib/$CONFIG/*.a
rm -R $LIB_DIR
mkdir -p $LIB_DIR
xcodebuild -project OGRE.xcodeproj -target install -parallelizeTargets -configuration $CONFIG -sdk $TARGET IPHONEOS_DEPLOYMENT_TARGET=4.0
cp lib/$CONFIG/*.a $LIB_DIR
}
function lipo {
mkdir $OGRE_BUILD_DIR/sdk/lib/$CONFIG
for LIBNAME in $OGRE_BUILD_DIR/sdk/lib/$CONFIG-iphoneos/lib*
do
echo lipo $LIBNAME
BASELIBNAME=`basename $LIBNAME`
$LIPO $SDK_DIR/lib/$CONFIG-iphoneos/$BASELIBNAME -arch i386 $SDK_DIR/lib/$CONFIG-iphonesimulator/$BASELIBNAME -create -output $SDK_DIR/lib/$CONFIG/$BASELIBNAME
done
}
CONFIG=Release
TARGET=iphoneos
build_single_target
TARGET=iphonesimulator
build_single_target
CONFIG=Debug
TARGET=iphoneos
build_single_target
TARGET=iphonesimulator
build_single_target
# Cram them together so we have a 'fat' library for device and simulator
CONFIG=Debug
#lipo
CONFIG=Release
lipo
cd $START_DIR