-
Notifications
You must be signed in to change notification settings - Fork 73
/
runcocoa.sh
executable file
·85 lines (79 loc) · 2.3 KB
/
runcocoa.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
# runcocoa.sh - Run any Cocoa code from the command line
#
# Michael Tyson, A Tasty Pixel <[email protected]>
#
ccflags="";
includes="";
usegdb=;
ios=;
includemain=yes;
while [ "${1:0:1}" = "-" ]; do
if [ "$1" = "-include" ]; then
shift;
includes="$includes
#import <$1>";
elif [ "$1" = "-gdb" ]; then
usegdb=yes;
elif [ "$1" = "-ios" ]; then
ios=yes;
elif [ "$1" = "-nomain" ]; then
includemain=;
else
ccflags="$ccflags $1 $2";
shift;
fi;
shift;
done;
commands=$*
if [ ! "$commands" ]; then
commands="`cat`"
fi
if [ "$ios" ]; then
includes="$includes
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>"
else
includes="$includes
#import <Cocoa/Cocoa.h>";
fi
if [ "$includemain" ]; then
cat > /tmp/runcocoa.m << EOF
$includes
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
$commands;
[pool drain];
return 0;
}
EOF
else
cat > /tmp/runcocoa.m << EOF
$includes
$commands;
EOF
fi
if [ "$ios" ]; then
export MACOSX_DEPLOYMENT_TARGET=10.6
export PATH="/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
gcc="/usr/bin/env llvm-gcc \
-x objective-c -arch i386 -fmessage-length=0 -pipe -std=c99 -fpascal-strings -O0 \
-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -fexceptions -fasm-blocks \
-mmacosx-version-min=10.6 -gdwarf-2 -fvisibility=hidden -fobjc-abi-version=2 -fobjc-legacy-dispatch -D__IPHONE_OS_VERSION_MIN_REQUIRED=40000 \
-Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -framework CoreText";
else
gcc="/usr/bin/env gcc -O0 -framework Foundation -framework Cocoa";
fi
if ! $gcc /tmp/runcocoa.m $ccflags -o /tmp/runcocoa-output; then
exit 1;
fi
if [ "$ios" ]; then
DYLD_ROOT_PATH="/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk" /tmp/runcocoa-output
elif [ "$usegdb" ]; then
echo 'run; bt;' > /tmp/runcocoa-gdb
gdb -x /tmp/runcocoa-gdb -e /tmp/runcocoa-output
rm /tmp/runcocoa-gdb
else
/tmp/runcocoa-output
fi
rm /tmp/runcocoa-output /tmp/runcocoa.m 2>/dev/null