[ObjectiveC] Build fat static library (device + simulator)

Hi all,
a promemoria to MERGE  + Simulator libraries in a “” lib with XCODE.

Usage:

1. Create a lib project
2. Select the Target
3. right-click and “Add … New Build Phase … New Run Script Build Phase”
4. Copy/paste the script below into the box

After that, customize script as you want!

In your BUILD folder you can see Release-Universal folder that contains merged libs with headers file!

Ref: albertopasca.it

Here the code:

### EXECUTED ONLY WITH SIMULATOR->RELEASE->MyTarget

#!/bin/sh

### CONFIG VARS
MY_TARGET="MyTarget"
IS_VALID="FALSE"
SDK_VERSION=$(echo ${SDK_NAME} | grep -o '.\{3\}$')
ALREADYINVOKED="false"
UNIVERSAL_NAME="Release-universal"
BUILD_DEV_PATH=${BUILD_DIR}/${UNIVERSAL_NAME}/tmp-dev/
BUILD_SIM_PATH=${BUILD_DIR}/${UNIVERSAL_NAME}/tmp-sim/

### CONF CHECK
CheckConfig() {
# YOUR COMPILE RULES
if [ ${CONFIGURATION} == "Release" ] &&
  [ ${ACTION} == "build" ] &&
  [ ${TARGET_NAME} == ${MY_TARGET} ] &&
  [ ${PLATFORM_NAME} == "iphonesimulator" ]
then
  IS_VALID="TRUE"
fi
}

### MKDIRS
CreateFolders() {
  mkdir -p "${SYMROOT}/${UNIVERSAL_NAME}/"
  mkdir -p  ${BUILD_DEV_PATH}
  mkdir -p  ${BUILD_SIM_PATH}
  mkdir -p "${SYMROOT}/${UNIVERSAL_NAME}/include"
}

### MULTIPLE BUILDS
BuildLibs() {
  # BUILD DEVICE
  xcodebuild -configuration "Release" -target "PGLib" -    sdk "iphoneos4.3" build RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DEV_PATH}" BUILD_ROOT="${BUILD_DEV_PATH}"
  # BUILD SIMULATOR
  xcodebuild -configuration "Release" -target "PGLib_Simulator" -  sdk "iphonesimulator4.3" build RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_SIM_PATH}" BUILD_ROOT="${BUILD_SIM_PATH}"
}

### MERGE LIBS
FatLibs() {
  LIB_DEV="${BUILD_DEV_PATH}/Release-iphoneos/libPGLib-DEV.a"
  LIB_SIM="${BUILD_SIM_PATH}/Release-iphonesimulator/libPGLib-SIM.a"
  LIB_UNI="${SYMROOT}/${UNIVERSAL_NAME}/libPGLib.a"
  HEADERS="${BUILD_DEV_PATH}/Release-iphoneos/usr/local/include/"

  cp "${HEADERS}"/* "${SYMROOT}/${UNIVERSAL_NAME}/include"

  lipo -create "${LIB_DEV}" "${LIB_SIM}" -output "${LIB_UNI}"
}

### CLEAN WORKING DATA
ClearTemporary() {
  rm -rf "${BUILD_DEV_PATH}"
  rm -rf "${BUILD_SIM_PATH}"
}

#
### MAIN
#
if [ "true" != ${ALREADYINVOKED:-false} ]; then  # SKIP  RECURSION
CheckConfig
ALREADYINVOKED="true"

if [ ${IS_VALID} == "TRUE" ]; then  # DO WORK
CreateFolders
BuildLibs
FatLibs
ClearTemporary

echo "Custom script on RELEASE/SIMULATOR/${MY_TARGET} executed!";
else
echo "Custom script SKIPPED execution!";
fi
fi

enjoy coding!!!

Ref: albertopasca.it