Created
December 1, 2009 19:53
-
-
Save jon/246586 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Builds an iPhoneOS/Simulator compatible version of BoehmGC and packages | |
# it up into a "static framework" as per Landon Fuller's suggestion at | |
# http://landonf.bikemonkey.org/code/iphone/iPhone_Framework_Support.20081202.html | |
fail() { | |
echo $1 >&2 | |
exit 1 | |
} | |
clean() { | |
rm -rf BoehmGC.framework | |
rm -rf .iphone | |
} | |
apply_patch() { | |
if ! [ -f darwin_stop_world.c.orig ]; then | |
patch -F 0 --forward -f -p1 <<EOF | |
diff -ur gc-7.1/darwin_stop_world.c gc-7.1-iphone/darwin_stop_world.c | |
--- gc-7.1/darwin_stop_world.c 2008-01-10 15:38:23.000000000 -0500 | |
+++ gc-7.1-iphone/darwin_stop_world.c 2009-12-01 09:27:30.000000000 -0500 | |
@@ -323,6 +323,34 @@ | |
GC_push_one(info . THREAD_FLD (fs)); | |
GC_push_one(info . THREAD_FLD (gs)); | |
+# elif defined(ARM32) || defined(ARM64) | |
+ GC_THREAD_STATE_T state; | |
+ mach_msg_type_number_t outCount = THREAD_STATE_MAX; | |
+ r = thread_get_state(thread, GC_MACH_THREAD_STATE, (natural_t *)&state, | |
+ &outCount); | |
+ if(r != KERN_SUCCESS) | |
+ ABORT("task_get_state failed"); | |
+ | |
+ lo = (void*)state.__sp; | |
+ | |
+ GC_push_one(state.__r[0]); | |
+ GC_push_one(state.__r[1]); | |
+ GC_push_one(state.__r[2]); | |
+ GC_push_one(state.__r[3]); | |
+ GC_push_one(state.__r[4]); | |
+ GC_push_one(state.__r[5]); | |
+ GC_push_one(state.__r[6]); | |
+ GC_push_one(state.__r[7]); | |
+ GC_push_one(state.__r[8]); | |
+ GC_push_one(state.__r[9]); | |
+ GC_push_one(state.__r[10]); | |
+ GC_push_one(state.__r[11]); | |
+ GC_push_one(state.__r[12]); | |
+ /* GC_push_one(state.__sp); */ | |
+ GC_push_one(state.__lr); | |
+ GC_push_one(state.__pc); | |
+ GC_push_one(state.__cpsr); | |
+ | |
# else | |
# error FIXME for non-x86 || ppc architectures | |
# endif | |
EOF | |
fi | |
if ! [ -f include/private/gc_priv.h.orig ]; then | |
patch -F 0 --forward -f -p1 <<EOF | |
diff -ur gc-7.1/include/private/gc_priv.h gc-7.1-iphone/include/private/gc_priv.h | |
--- gc-7.1/include/private/gc_priv.h 2008-02-06 19:23:39.000000000 -0500 | |
+++ gc-7.1-iphone/include/private/gc_priv.h 2009-12-01 09:22:16.000000000 -0500 | |
@@ -398,10 +398,26 @@ | |
# define GC_MACH_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT | |
# define GC_MACH_HEADER mach_header_64 | |
# define GC_MACH_SECTION section_64 | |
# define GC_GETSECTBYNAME getsectbynamefromheader_64 | |
# endif | |
+# elif defined(ARM32) || defined(ARM64) | |
+# if CPP_WORDSZ == 32 | |
+# define GC_THREAD_STATE_T arm_thread_state_t | |
+# define GC_MACH_THREAD_STATE ARM_THREAD_STATE | |
+# define GC_MACH_THREAD_STATE_COUNT ARM_THREAD_STATE_COUNT | |
+# define GC_MACH_HEADER mach_header | |
+# define GC_MACH_SECTION section | |
+# define GC_GETSECTBYNAME getsectbynamefromheader | |
+# else | |
+# define GC_THREAD_STATE_T arm_thread_state64_t | |
+# define GC_MACH_THREAD_STATE ARM_THREAD_STATE64 | |
+# define GC_MACH_THREAD_STATE_COUNT ARM_THREAD_STATE64_COUNT | |
+# define GC_MACH_HEADER mach_header_64 | |
+# define GC_MACH_SECTION section_64 | |
+# define GC_GETSECTBYNAME getsectbynamefromheader_64 | |
+# endif | |
# else | |
# error define GC_THREAD_STATE_T | |
# define GC_MACH_THREAD_STATE MACHINE_THREAD_STATE | |
# define GC_MACH_THREAD_STATE_COUNT MACHINE_THREAD_STATE_COUNT | |
# endif | |
EOF | |
fi | |
} | |
setup() { | |
mkdir -p .iphone | |
} | |
configure() { | |
PLATFORM=iPhone$1.platform | |
SDK=iPhone$13.0.sdk | |
HOST=$2 | |
ARCH=$3 | |
./configure \ | |
--host=$HOST \ | |
--target=$HOST \ | |
--disable-shared \ | |
--enable-static \ | |
CC="/Developer/Platforms/$PLATFORM/Developer/usr/bin/gcc-4.0" \ | |
CPP="/Developer/Platforms/$PLATFORM/Developer/usr/bin/cpp" \ | |
CXXCPP="/Developer/Platforms/$PLATFORM/Developer/usr/bin/cpp" \ | |
CXX="/Developer/Platforms/$PLATFORM/Developer/usr/bin/gcc-4.0" \ | |
AR="/Developer/Platforms/$PLATFORM/Developer/usr/bin/ar" \ | |
RANLIB="/Developer/Platforms/$PLATFORM/Developer/usr/bin/ranlib" \ | |
NM="/Developer/Platforms/$PLATFORM/Developer/usr/bin/nm" \ | |
CFLAGS="-arch $ARCH \ | |
-O2 \ | |
-miphoneos-version-min=3.0 \ | |
-I/Library/iPhone/include \ | |
-isysroot /Developer/Platforms/$PLATFORM/Developer/SDKs/$SDK" \ | |
LDFLAGS="-arch $ARCH \ | |
-I/Library/iPhone/include \ | |
-isysroot /Developer/Platforms/$PLATFORM/Developer/SDKs/$SDK" | |
} | |
build() { | |
if [ -f Makefile ]; then | |
make distclean | |
fi | |
configure $* || fail "Unable to configure for $1 build" | |
make || fail "Unable to build $1 static library" | |
cp .libs/libgc.a .iphone/libgc-$3.a || fail "Unable to copy libgc.a to staging directory" | |
} | |
headers() { | |
make install prefix=`pwd`/.iphone/root | |
} | |
package() { | |
BUNDLE=.iphone/BoehmGC.framework | |
mkdir -p $BUNDLE/Headers | |
cp -R .iphone/root/include/ $BUNDLE/Headers | |
echo "#import <BoehmGC/gc.h>" >$BUNDLE/Headers/BoehmGC.h | |
lipo -create -arch armv6 .iphone/libgc-armv6.a -arch i386 .iphone/libgc-i386.a -output $BUNDLE/BoehmGC | |
} | |
finish() { | |
if [ -d .iphone/BoehmGC.framework ]; then | |
rm -rf BoehmGC.framework | |
mv .iphone/BoehmGC.framework . | |
echo "All done. You should now have BoehmGC.framework in the current directory" | |
fi | |
} | |
go() { | |
clean | |
apply_patch || fail "Unable to apply ARM patch" | |
setup || fail "Unable to create target directory" | |
build OS arm-apple-darwin9 armv6 || fail "Unable to build for iPhone OS" | |
build Simulator i386-apple-darwin i386 || fail "Unable to build for iPhone Simulator" | |
headers || fail "Unable to install libgc headers" | |
package || fail "Unable to create BoehmGC framework" | |
finish | |
} | |
if [ "$1" != "" ]; then | |
$* | |
else | |
go | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment