configure: initial support for an iOS build

A new `--enable-ios=<sdk-path>` flag in combination with `--host=...`
sets up the right compiler options for compiling the Racket runtime
system as a framework to use in an iOS application.

I don't know whether the resulting framework actually works, but
compiling and linking is a step forward.
This commit is contained in:
Matthew Flatt 2015-02-22 08:32:40 -07:00
parent 52ca80a7ab
commit af6c39611d
10 changed files with 172 additions and 25 deletions

View File

@ -309,6 +309,30 @@ of Android (such as 14), and
is in your PATH (so that a suitable `gcc', `ar', etc., are found) for
the [comp] of your choice and the [platform] used to compile.
========================================================================
Cross-compiling for iOS
========================================================================
To compile the Racket runtime system as a Framework for iOS, use (all
on one line)
configure --host=[arch]-apple-darwin
--enable-ios="[sdk]"
--enable-racket=racket
where [arch] is one of
- armv7, armv7s, or aarch64: to run on iOS
- i386 or x86_64: to run on the simulator
The [sdk] argument is a path to an iOS SDK, but if it is "iPhoneOS" or
"iPhoneSimulator", then the corresponding SDK is located in the
standard place within the XCode application. For example, "iPhoneOS"
becomes the path (all on one line)
/Applications/Xcode.app/Contents/Developer/Platforms/
iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
========================================================================
CGC versus 3m
========================================================================

46
racket/src/configure vendored
View File

@ -1451,6 +1451,7 @@ Optional Features:
--enable-sdk=<path> use Mac OS X 10.4 SDK directory
--enable-sdk5=<path> use Mac OS X 10.5 SDK directory
--enable-sdk6=<path> use Mac OS X 10.6 SDK directory
--enable-ios=<path> use iOS SDK directory
--enable-sysroot=<path> use sysroot directory (e.g., for Android)
--enable-xonx use Unix style (e.g., use Gtk) for Mac OS X
--enable-libfw install Mac OS X frameworks to /Library/Frameworks
@ -2710,6 +2711,11 @@ if test "${enable_sdk+set}" = set; then :
enableval=$enable_sdk;
fi
# Check whether --enable-sdk was given.
if test "${enable_sdk+set}" = set; then :
enableval=$enable_sdk;
fi
# Check whether --enable-xonx was given.
if test "${enable_xonx+set}" = set; then :
enableval=$enable_xonx;
@ -3052,17 +3058,29 @@ if test "${enable_sdk}" != "" ; then
if test "${enable_sdk6}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk and --enable-sdk6"
fi
if test "${enable_ios}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk and --enable-ios"
fi
echo "=== Using Mac OS X 10.4 SDK directory ${enable_sdk}"
fi
if test "${enable_sdk5}" != "" ; then
if test "${enable_sdk6}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk5 and --enable-sdk6"
fi
if test "${enable_ios}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk5 and --enable-ios"
fi
echo "=== Using Mac OS X 10.5 SDK directory ${enable_sdk}"
fi
if test "${enable_sdk6}" != "" ; then
if test "${enable_ios}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk6 and --enable-ios"
fi
echo "=== Using Mac OS X 10.6 SDK directory ${enable_sdk6}"
fi
if test "${enable_ios}" != "" ; then
echo "=== Using ios SDK directory ${enable_ios}"
fi
if test "${enable_sysroot}" != "" ; then
echo "=== Using sysroot directory ${enable_sysroot}"
@ -3222,6 +3240,34 @@ if test "${enable_sysroot}" != "" ; then
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} LDFLAGS="'"'"${LDFLAGS}"'"'
fi
if test "${enable_ios}" != "" ; then
case "$host_cpu" in
aarch64)
IOS_ARCH=arm64
;;
*)
IOS_ARCH=$host_cpu
;;
esac
case "${enable_ios}" in
iPhoneOS|iPhoneSimulator)
ios_sdk=/Applications/Xcode.app/Contents/Developer/Platforms/${enable_ios}.platform/Developer/SDKs/${enable_ios}.sdk
;;
*)
ios_sdk="${enable_ios}"
;;
esac
IOS_PHONE_VERS="6.0"
PREFLAGS="$PREFLAGS -DTARGET_OS_IPHONE"
CPPFLAGS="$CPPFLAGS -DTARGET_OS_IPHONE"
PREFLAGS="$PREFLAGS -arch ${IOS_ARCH} -isysroot ${ios_sdk} -miphoneos-version-min=${IOS_PHONE_VERS}"
CPPFLAGS="$CPPFLAGS -arch ${IOS_ARCH} -isysroot ${ios_sdk} -miphoneos-version-min=${IOS_PHONE_VERS}"
LDFLAGS="$LDFLAGS -arch ${IOS_ARCH} -isysroot ${ios_sdk} -miphoneos-version-min=${IOS_PHONE_VERS} -liconv"
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} CFLAGS="'"'"${CFLAGS}"'"'
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} CPPFLAGS="'"'"${PREFLAGS}"'"'
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} LDFLAGS="'"'"${LDFLAGS}"'"'
fi
if test "${enable_oskit}" = "no" ; then
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'

View File

@ -123,7 +123,7 @@ END_XFORM_SKIP;
#ifdef OS_X
static long get_segment_offset()
{
# ifdef __x86_64__
# if defined(__x86_64__) || defined(__arm64__)
const struct segment_command_64 *seg;
# else
const struct segment_command *seg;

View File

@ -60,6 +60,7 @@ AC_ARG_ENABLE(libffi, [ --enable-libffi use installed libffi (enabled
AC_ARG_ENABLE(sdk, [ --enable-sdk=<path> use Mac OS X 10.4 SDK directory])
AC_ARG_ENABLE(sdk, [ --enable-sdk5=<path> use Mac OS X 10.5 SDK directory])
AC_ARG_ENABLE(sdk, [ --enable-sdk6=<path> use Mac OS X 10.6 SDK directory])
AC_ARG_ENABLE(sdk, [ --enable-ios=<path> use iOS SDK directory])
AC_ARG_ENABLE(sdk, [ --enable-sysroot=<path> use sysroot directory (e.g., for Android)])
AC_ARG_ENABLE(xonx, [ --enable-xonx use Unix style (e.g., use Gtk) for Mac OS X])
AC_ARG_ENABLE(libfw, [ --enable-libfw install Mac OS X frameworks to /Library/Frameworks])
@ -335,17 +336,29 @@ if test "${enable_sdk}" != "" ; then
if test "${enable_sdk6}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk and --enable-sdk6"
fi
if test "${enable_ios}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk and --enable-ios"
fi
echo "=== Using Mac OS X 10.4 SDK directory ${enable_sdk}"
fi
if test "${enable_sdk5}" != "" ; then
if test "${enable_sdk6}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk5 and --enable-sdk6"
fi
if test "${enable_ios}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk5 and --enable-ios"
fi
echo "=== Using Mac OS X 10.5 SDK directory ${enable_sdk}"
fi
if test "${enable_sdk6}" != "" ; then
if test "${enable_ios}" != "" ; then
echo "ERROR: cannot specify both --enable-sdk6 and --enable-ios"
fi
echo "=== Using Mac OS X 10.6 SDK directory ${enable_sdk6}"
fi
if test "${enable_ios}" != "" ; then
echo "=== Using ios SDK directory ${enable_ios}"
fi
if test "${enable_sysroot}" != "" ; then
echo "=== Using sysroot directory ${enable_sysroot}"
@ -499,6 +512,34 @@ if test "${enable_sysroot}" != "" ; then
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} LDFLAGS="'"'"${LDFLAGS}"'"'
fi
if test "${enable_ios}" != "" ; then
case "$host_cpu" in
aarch64)
IOS_ARCH=arm64
;;
*)
IOS_ARCH=$host_cpu
;;
esac
case "${enable_ios}" in
iPhoneOS|iPhoneSimulator)
ios_sdk=/Applications/Xcode.app/Contents/Developer/Platforms/${enable_ios}.platform/Developer/SDKs/${enable_ios}.sdk
;;
*)
ios_sdk="${enable_ios}"
;;
esac
IOS_PHONE_VERS="6.0"
PREFLAGS="$PREFLAGS -DTARGET_OS_IPHONE"
CPPFLAGS="$CPPFLAGS -DTARGET_OS_IPHONE"
PREFLAGS="$PREFLAGS -arch ${IOS_ARCH} -isysroot ${ios_sdk} -miphoneos-version-min=${IOS_PHONE_VERS}"
CPPFLAGS="$CPPFLAGS -arch ${IOS_ARCH} -isysroot ${ios_sdk} -miphoneos-version-min=${IOS_PHONE_VERS}"
LDFLAGS="$LDFLAGS -arch ${IOS_ARCH} -isysroot ${ios_sdk} -miphoneos-version-min=${IOS_PHONE_VERS} -liconv"
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} CFLAGS="'"'"${CFLAGS}"'"'
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} CPPFLAGS="'"'"${PREFLAGS}"'"'
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} LDFLAGS="'"'"${LDFLAGS}"'"'
fi
if test "${enable_oskit}" = "no" ; then
AC_PROG_CC
AC_PROG_CPP
@ -774,7 +815,7 @@ case "$host_os" in
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} CPPFLAGS="'"'"${PREFLAGS}"'"'
SUB_CONFIGURE_EXTRAS="${SUB_CONFIGURE_EXTRAS} LDFLAGS="'"'"${LDFLAGS}"'"'
fi
case "$host_cpu" in
i386|x86_64)
enable_parallel_by_default=yes

View File

@ -124,6 +124,10 @@ static void unregister_mach_thread() {
# define ARCH_thread_state_t ppc_thread_state_t
# define ARCH_THREAD_STATE PPC_THREAD_STATE
# define ARCH_THREAD_STATE_COUNT PPC_THREAD_STATE_COUNT
#elif defined(__arm__) || defined(__arm64__)
# define ARCH_thread_state_t arm_thread_state_t
# define ARCH_THREAD_STATE ARM_THREAD_STATE
# define ARCH_THREAD_STATE_COUNT ARM_THREAD_STATE_COUNT
#elif defined(__x86_64__)
# define ARCH_thread_state_t x86_thread_state64_t
# define ARCH_THREAD_STATE x86_THREAD_STATE64

View File

@ -805,27 +805,25 @@
# if defined(OS_X) || defined(XONX)
#ifdef XONX
# ifdef __POWERPC__
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "ppc-darwin"
# if defined(XONX)
# define SPLS_MAC "darwin"
# elif defined(TARGET_OS_IPHONE)
# define SPLS_MAC "ios"
# else
# ifdef __x86_64__
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "x86_64-darwin"
# else
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "i386-darwin"
# endif
# define SPLS_MAC "macosx"
# endif
#else
# ifdef __POWERPC__
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "ppc-macosx"
# if defined(__POWERPC__)
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "ppc-"SPLS_MAC
# elif defined(__arm__)
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "arm-"SPLS_MAC
# elif defined(__arm64__)
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "arm64-"SPLS_MAC
# elif defined(__x86_64__)
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "x86_64-"SPLS_MAC
# else
# ifdef __x86_64__
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "x86_64-macosx"
# else
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "i386-macosx"
# endif
# define SCHEME_PLATFORM_LIBRARY_SUBPATH "i386-"SPLS_MAC
# endif
#endif
# include "uconfig.h"
@ -870,7 +868,10 @@
# define OS_X 1
#endif
#if defined(__POWERPC__)
#if defined(__arm__)
# define MZ_USE_JIT_ARM
#elif defined(__arm64__)
#elif defined(__POWERPC__)
# define MZ_USE_JIT_PPC
#else
# if defined(__x86_64__)

View File

@ -75,7 +75,7 @@ struct {
} jit_cpu;
#endif
struct {
static struct {
/* prevent using thumb instructions that set flags? */
_ui no_set_flags : 1;
} jit_flags;

View File

@ -53,8 +53,19 @@ jit_v_order[JIT_V_NUM] = {
#define jit_no_set_flags() jit_flags.no_set_flags
#ifdef TARGET_OS_IPHONE
# define USE_SEPARATE_DIV_AND_MOD
#endif
#ifdef USE_SEPARATE_DIV_AND_MOD
extern int __divsi3(int, int);
extern int __udivsi3(int, int);
extern int __modsi3(int, int);
extern int __umodsi3(int, int);
#else
extern int __aeabi_idivmod(int, int);
extern unsigned __aeabi_uidivmod(unsigned, unsigned);
#endif
#define jit_nop(n) arm_nop(_jitp, n)
__jit_inline void
@ -855,8 +866,18 @@ arm_divmod(jit_state_t _jitp, int div, int sign,
jit_movr_i(_R0, r1);
jit_movr_i(_R1, r2);
}
#ifdef USE_SEPARATE_DIV_AND_MOD
if (div) {
if (sign) p = __divsi3;
else p = __udivsi3;
} else {
if (sign) p = __modsi3;
else p = __umodsi3;
}
#else
if (sign) p = __aeabi_idivmod;
else p = __aeabi_uidivmod;
#endif
{
jit_movi_i(JIT_FTMP, (int)p);
if (jit_thumb_p())
@ -864,10 +885,14 @@ arm_divmod(jit_state_t _jitp, int div, int sign,
else
_BLX(JIT_FTMP);
}
#ifdef USE_SEPARATE_DIV_AND_MOD
jit_movr_i(r0, _R0);
#else
if (div)
jit_movr_i(r0, _R0);
else
jit_movr_i(r0, _R1);
#endif
if (jit_thumb_p())
T1_POP(l);
else

View File

@ -42,7 +42,13 @@
#define jit_notify_freed_code() /* empty */
extern void __clear_cache(void*, void*);
#ifdef TARGET_OS_IPHONE
void sys_icache_invalidate(void *start, size_t len);
# define CLEAR_ICACHE(s, e) sys_icache_invalidate(s, ((char *)e) - ((char *)s));
#else
extern void _clear_cache(void*, void*);
# define CLEAR_ICACHE(s, e) __clear_cache(s, e)
#endif
__jit_inline void
jit_flush_code(void *start, void *end)
@ -54,10 +60,10 @@ jit_flush_code(void *start, void *end)
void *e;
e = (void *)(((uintptr_t)start + 4096) & ~4095);
if (e < end) {
__clear_cache(start, e);
CLEAR_ICACHE(start, e);
start = e;
} else {
__clear_cache(start, end);
CLEAR_ICACHE(start, end);
break;
}
}

View File

@ -2157,7 +2157,7 @@ int scheme_any_string_has_null(Scheme_Object *o)
/* Environment Variables */
/***********************************************************************/
#ifdef OS_X
#if defined(OS_X) && !defined(TARGET_OS_IPHONE)
# include <crt_externs.h>
# define GET_ENVIRON_ARRAY *_NSGetEnviron()
#endif