Commit 022f12eb9ad2264e838fa5fb453733f5177888f4

Zachary Waldowski 2013-11-30T12:21:38

Darwin: Freshen gen scripts, remove old build-ios.sh

diff --git a/build-ios.sh b/build-ios.sh
deleted file mode 100755
index 3dea242..0000000
--- a/build-ios.sh
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-
-PLATFORM_IOS=/Developer/Platforms/iPhoneOS.platform/
-PLATFORM_IOS_SIM=/Developer/Platforms/iPhoneSimulator.platform/
-SDK_IOS_VERSION="4.2"
-MIN_IOS_VERSION="3.0"
-OUTPUT_DIR="universal-ios"
-
-build_target () {
-    local platform=$1
-    local sdk=$2
-    local arch=$3
-    local triple=$4
-    local builddir=$5
-
-    mkdir -p "${builddir}"
-    pushd "${builddir}"
-    export CC="${platform}"/Developer/usr/bin/gcc-4.2
-    export CFLAGS="-arch ${arch} -isysroot ${sdk} -miphoneos-version-min=${MIN_IOS_VERSION}"
-    ../configure --host=${triple} && make
-    popd
-}
-
-# Build all targets
-build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv6 arm-apple-darwin10 armv6-ios
-build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv7 arm-apple-darwin10 armv7-ios
-build_target "${PLATFORM_IOS_SIM}" "${PLATFORM_IOS_SIM}/Developer/SDKs/iPhoneSimulator${SDK_IOS_VERSION}.sdk/" i386 i386-apple-darwin10 i386-ios-sim
-
-# Create universal output directories
-mkdir -p "${OUTPUT_DIR}"
-mkdir -p "${OUTPUT_DIR}/include"
-mkdir -p "${OUTPUT_DIR}/include/armv6"
-mkdir -p "${OUTPUT_DIR}/include/armv7"
-mkdir -p "${OUTPUT_DIR}/include/i386"
-
-# Create the universal binary
-lipo -create armv6-ios/.libs/libffi.a armv7-ios/.libs/libffi.a i386-ios-sim/.libs/libffi.a -output "${OUTPUT_DIR}/libffi.a"
-
-# Copy in the headers
-copy_headers () {
-    local src=$1
-    local dest=$2
-
-    # Fix non-relative header reference
-    sed 's/<ffitarget.h>/"ffitarget.h"/' < "${src}/include/ffi.h" > "${dest}/ffi.h"
-    cp "${src}/include/ffitarget.h" "${dest}"
-}
-
-copy_headers armv6-ios "${OUTPUT_DIR}/include/armv6"
-copy_headers armv7-ios "${OUTPUT_DIR}/include/armv7"
-copy_headers i386-ios-sim "${OUTPUT_DIR}/include/i386"
-
-# Create top-level header
-(
-cat << EOF
-#ifdef __arm__
-  #include <arm/arch.h>
-  #ifdef _ARM_ARCH_6
-    #include "include/armv6/ffi.h"
-  #elif _ARM_ARCH_7
-    #include "include/armv7/ffi.h"
-  #endif
-#elif defined(__i386__)
-  #include "include/i386/ffi.h"
-#endif
-EOF
-) > "${OUTPUT_DIR}/ffi.h"
diff --git a/generate-ios-source-and-headers.py b/generate-ios-source-and-headers.py
index 57c9736..4d4d0ae 100644
--- a/generate-ios-source-and-headers.py
+++ b/generate-ios-source-and-headers.py
@@ -4,8 +4,6 @@ import re
 import os
 import errno
 import collections
-#developer_path =
-
 
 class Platform(object):
     pass
@@ -57,11 +55,11 @@ class simulator_platform(Platform):
     sdk = 'iphonesimulator'
     arch = 'i386'
     short_arch = arch
-    triple = 'i386-apple-darwin10'
+    triple = 'i386-apple-darwin11'
     sdkroot = sim_sdk_info['Path']
-    version_min = '5.0'
+    version_min = '5.1.1'
 
-    prefix = "#if !defined(__arm__) && !defined(__arm64__) && !defined(__x86_64__) && defined(__i386__)\n\n"
+    prefix = "#ifdef __i386__\n\n"
     suffix = "\n\n#endif"
 
 
@@ -71,9 +69,9 @@ class simulator64_platform(Platform):
     short_arch = arch
     triple = 'x86_64-apple-darwin13'
     sdkroot = sim_sdk_info['Path']
-    version_min = '5.0'
+    version_min = '7.0'
 
-    prefix = "#if !defined(__arm__) && !defined(__arm64__) && !defined(__i386__) && defined(__x86_64__)\n\n"
+    prefix = "#ifdef __x86_64__\n\n"
     suffix = "\n\n#endif"
 
 
@@ -81,11 +79,11 @@ class device_platform(Platform):
     sdk = 'iphoneos'
     arch = 'armv7'
     short_arch = 'arm'
-    triple = 'arm-apple-darwin10'
+    triple = 'arm-apple-darwin11'
     sdkroot = device_sdk_info['Path']
-    version_min = '5.0'
+    version_min = '5.1.1'
 
-    prefix = "#if !defined(__arm64__) && defined(__arm__)\n\n"
+    prefix = "#ifdef __arm__\n\n"
     suffix = "\n\n#endif"
 
 
@@ -97,7 +95,7 @@ class device64_platform(Platform):
     sdkroot = device_sdk_info['Path']
     version_min = '7.0'
 
-    prefix = "#if !defined(__arm__) && defined(__arm64__)\n\n"
+    prefix = "#ifdef __arm64__\n\n"
     suffix = "\n\n#endif"
 
 
@@ -145,21 +143,21 @@ def move_source_tree(src_dir, dest_dir, dest_include_dir, arch=None, prefix=None
                      suffix=suffix)
         elif relroot == 'arm':
             move_dir(arch='arm',
-                     prefix="#if !defined(__arm64__) && defined(__arm__)\n\n",
+                     prefix="#ifdef __arm__\n\n",
                      suffix="\n\n#endif",
                      files=['sysv.S', 'trampoline.S', 'ffi.c'])
         elif relroot == 'aarch64':
             move_dir(arch='arm64',
-                     prefix="#if !defined(__arm__) && defined(__arm64__)\n\n",
+                     prefix="#ifdef __arm64__\n\n",
                      suffix="\n\n#endif",
                      files=['sysv.S', 'ffi.c'])
         elif relroot == 'x86':
             move_dir(arch='i386',
-                     prefix="#if !defined(__arm__) && !defined(__arm64__) && !defined(__x86_64__) && defined(__i386__)\n\n",
+                     prefix="#ifdef __i386__\n\n",
                      suffix="\n\n#endif",
                      files=['darwin.S', 'ffi.c'])
             move_dir(arch='x86_64',
-                     prefix="#if !defined(__arm__) && !defined(__arm64__) && !defined(__i386__) && defined(__x86_64__)\n\n",
+                     prefix="#ifdef __x86_64__\n\n",
                      suffix="\n\n#endif",
                      files=['darwin64.S', 'ffi64.c'])
 
diff --git a/generate-osx-source-and-headers.py b/generate-osx-source-and-headers.py
index c664ec7..97a732d 100644
--- a/generate-osx-source-and-headers.py
+++ b/generate-osx-source-and-headers.py
@@ -2,6 +2,7 @@
 import subprocess
 import re
 import os
+import errno
 import collections
 
 
@@ -20,6 +21,16 @@ def sdkinfo(sdkname):
             ret[k] = v
     return ret
 
+
+def mkdir_p(path):
+    try:
+        os.makedirs(path)
+    except OSError as exc:  # Python >2.5
+        if exc.errno == errno.EEXIST:
+            pass
+        else:
+            raise
+
 desktop_sdk_info = sdkinfo('macosx')
 
 
@@ -36,32 +47,32 @@ def latest_sdks():
 desktop_sdk = latest_sdks()
 
 
-class desktop_platform_32(Platform):
+class desktop32_platform(Platform):
     sdk = 'macosx'
     arch = 'i386'
     name = 'mac32'
-    triple = 'i386-apple-darwin10'
+    triple = 'i386-apple-darwin11'
     sdkroot = desktop_sdk_info['Path']
+    version_min = '10.7'
 
-    prefix = "#if defined(__i386__) && !defined(__x86_64__)\n\n"
+    prefix = "#ifdef __i386__\n\n"
     suffix = "\n\n#endif"
 
 
-class desktop_platform_64(Platform):
+class desktop64_platform(Platform):
     sdk = 'macosx'
     arch = 'x86_64'
     name = 'mac'
-    triple = 'x86_64-apple-darwin10'
+    triple = 'x86_64-apple-darwin11'
     sdkroot = desktop_sdk_info['Path']
+    version_min = '10.7'
 
-    prefix = "#if !defined(__i386__) && defined(__x86_64__)\n\n"
+    prefix = "#ifdef __x86_64__\n\n"
     suffix = "\n\n#endif"
 
 
 def move_file(src_dir, dst_dir, filename, file_suffix=None, prefix='', suffix=''):
-    if not os.path.exists(dst_dir):
-        os.makedirs(dst_dir)
-
+    mkdir_p(dst_dir)
     out_filename = filename
 
     if file_suffix:
@@ -104,11 +115,11 @@ def move_source_tree(src_dir, dest_dir, dest_include_dir, arch=None, prefix=None
                      suffix=suffix)
         elif relroot == 'x86':
             move_dir(arch='i386',
-                     prefix="#if defined(__i386__) && !defined(__x86_64__)\n\n",
+                     prefix="#ifdef __i386__\n\n",
                      suffix="\n\n#endif",
                      files=['darwin.S', 'ffi.c'])
             move_dir(arch='x86_64',
-                     prefix="#if !defined(__i386__) && defined(__x86_64__)\n\n",
+                     prefix="#ifdef __x86_64__\n\n",
                      suffix="\n\n#endif",
                      files=['darwin64.S', 'ffi64.c'])
 
@@ -122,7 +133,7 @@ def build_target(platform):
         os.makedirs(build_dir)
         env = dict(CC=xcrun_cmd('clang'),
                    LD=xcrun_cmd('ld'),
-                   CFLAGS='-arch %s -isysroot %s -mmacosx-version-min=10.6' % (platform.arch, platform.sdkroot))
+                   CFLAGS='-arch %s -isysroot %s -mmacosx-version-min=%s' % (platform.arch, platform.sdkroot, platform.version_min))
         working_dir = os.getcwd()
         try:
             os.chdir(build_dir)
@@ -145,8 +156,8 @@ def build_target(platform):
 def main():
     move_source_tree('src', 'osx/src', 'osx/include')
     move_source_tree('include', None, 'osx/include')
-    build_target(desktop_platform_32)
-    build_target(desktop_platform_64)
+    build_target(desktop32_platform)
+    build_target(desktop64_platform)
 
     for header_name, archs in headers_seen.iteritems():
         basename, suffix = os.path.splitext(header_name)