Landon Fuller | a82e6c3 | 2010-09-18 14:44:24 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | PLATFORM_IOS=/Developer/Platforms/iPhoneOS.platform/ |
| 4 | PLATFORM_IOS_SIM=/Developer/Platforms/iPhoneSimulator.platform/ |
Anthony Green | 90af15e | 2011-02-12 12:29:36 -0500 | [diff] [blame] | 5 | SDK_IOS_VERSION="4.2" |
| 6 | MIN_IOS_VERSION="3.0" |
| 7 | OUTPUT_DIR="universal-ios" |
Landon Fuller | a82e6c3 | 2010-09-18 14:44:24 -0700 | [diff] [blame] | 8 | |
Anthony Green | 90af15e | 2011-02-12 12:29:36 -0500 | [diff] [blame] | 9 | build_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 |
| 25 | build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv6 arm-apple-darwin10 armv6-ios |
| 26 | build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv7 arm-apple-darwin10 armv7-ios |
| 27 | build_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 |
| 30 | mkdir -p "${OUTPUT_DIR}" |
| 31 | mkdir -p "${OUTPUT_DIR}/include" |
| 32 | mkdir -p "${OUTPUT_DIR}/include/armv6" |
| 33 | mkdir -p "${OUTPUT_DIR}/include/armv7" |
| 34 | mkdir -p "${OUTPUT_DIR}/include/i386" |
| 35 | |
| 36 | # Create the universal binary |
| 37 | lipo -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 |
| 40 | copy_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 | |
| 49 | copy_headers armv6-ios "${OUTPUT_DIR}/include/armv6" |
| 50 | copy_headers armv7-ios "${OUTPUT_DIR}/include/armv7" |
| 51 | copy_headers i386-ios-sim "${OUTPUT_DIR}/include/i386" |
| 52 | |
| 53 | # Create top-level header |
| 54 | ( |
| 55 | cat << 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 |
| 66 | EOF |
| 67 | ) > "${OUTPUT_DIR}/ffi.h" |