1#!/bin/sh 2 3PLATFORM_IOS=/Developer/Platforms/iPhoneOS.platform/ 4PLATFORM_IOS_SIM=/Developer/Platforms/iPhoneSimulator.platform/ 5SDK_IOS_VERSION="4.2" 6MIN_IOS_VERSION="3.0" 7OUTPUT_DIR="universal-ios" 8 9build_target () { 10 local platform=$1 11 local sdk=$2 12 local arch=$3 13 local triple=$4 14 local builddir=$5 15 16 mkdir -p "${builddir}" 17 pushd "${builddir}" 18 export CC="${platform}"/Developer/usr/bin/gcc-4.2 19 export CFLAGS="-arch ${arch} -isysroot ${sdk} -miphoneos-version-min=${MIN_IOS_VERSION}" 20 ../configure --host=${triple} && make 21 popd 22} 23 24# Build all targets 25build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv6 arm-apple-darwin10 armv6-ios 26build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv7 arm-apple-darwin10 armv7-ios 27build_target "${PLATFORM_IOS_SIM}" "${PLATFORM_IOS_SIM}/Developer/SDKs/iPhoneSimulator${SDK_IOS_VERSION}.sdk/" i386 i386-apple-darwin10 i386-ios-sim 28 29# Create universal output directories 30mkdir -p "${OUTPUT_DIR}" 31mkdir -p "${OUTPUT_DIR}/include" 32mkdir -p "${OUTPUT_DIR}/include/armv6" 33mkdir -p "${OUTPUT_DIR}/include/armv7" 34mkdir -p "${OUTPUT_DIR}/include/i386" 35 36# Create the universal binary 37lipo -create armv6-ios/.libs/libffi.a armv7-ios/.libs/libffi.a i386-ios-sim/.libs/libffi.a -output "${OUTPUT_DIR}/libffi.a" 38 39# Copy in the headers 40copy_headers () { 41 local src=$1 42 local dest=$2 43 44 # Fix non-relative header reference 45 sed 's/<ffitarget.h>/"ffitarget.h"/' < "${src}/include/ffi.h" > "${dest}/ffi.h" 46 cp "${src}/include/ffitarget.h" "${dest}" 47} 48 49copy_headers armv6-ios "${OUTPUT_DIR}/include/armv6" 50copy_headers armv7-ios "${OUTPUT_DIR}/include/armv7" 51copy_headers i386-ios-sim "${OUTPUT_DIR}/include/i386" 52 53# Create top-level header 54( 55cat << EOF 56#ifdef __arm__ 57 #include <arm/arch.h> 58 #ifdef _ARM_ARCH_6 59 #include "include/armv6/ffi.h" 60 #elif _ARM_ARCH_7 61 #include "include/armv7/ffi.h" 62 #endif 63#elif defined(__i386__) 64 #include "include/i386/ffi.h" 65#endif 66EOF 67) > "${OUTPUT_DIR}/ffi.h" 68