/
gcc-fat.sh
executable file
·185 lines (171 loc) · 5.13 KB
1
2
3
4
#!/bin/sh
#
# Build Universal binaries on Mac OS X, thanks Ryan!
#
5
# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc ppc64 x86 x64
6
7
8
9
# PowerPC 32-bit compiler flags (10.4 runtime compatibility)
GCC_COMPILE_PPC32="gcc-4.0 -arch ppc -mmacosx-version-min=10.4 \
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
10
-nostdinc \
11
12
13
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/include \
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
14
15
16
17
18
19
20
21
22
23
24
25
GCC_LINK_PPC32="\
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1 \
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
# PowerPC 64-bit compiler flags (10.5 runtime compatibility)
GCC_COMPILE_PPC64="gcc-4.0 -arch ppc64 -mmacosx-version-min=10.5 \
-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
-nostdinc \
-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
-I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/include \
-isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
26
27
28
29
30
31
GCC_LINK_PPC64="\
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/ppc64 \
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
# Intel 32-bit compiler flags (10.4 runtime compatibility)
32
33
34
35
GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
-nostdinc \
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
36
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
37
38
39
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
GCC_LINK_X86="\
40
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1 \
41
42
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
43
44
45
46
47
48
49
50
51
52
53
54
# Intel 64-bit compiler flags (10.5 runtime compatibility)
GCC_COMPILE_X64="gcc-4.0 -arch x86_64 -mmacosx-version-min=10.5 \
-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
-nostdinc \
-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
-I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
-isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
GCC_LINK_X64="\
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/x86_64 \
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
55
56
57
58
59
60
61
62
63
64
65
# Output both PowerPC and Intel object files
args="$*"
compile=yes
link=yes
while test x$1 != x; do
case $1 in
--version) exec gcc $1;;
-v) exec gcc $1;;
-V) exec gcc $1;;
-print-prog-name=*) exec gcc $1;;
-print-search-dirs) exec gcc $1;;
66
-E) GCC_COMPILE_PPC32="$GCC_COMPILE_PPC32 -E"
67
GCC_COMPILE_PPC64="$GCC_COMPILE_PPC64 -E"
68
GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
69
GCC_COMPILE_X64="$GCC_COMPILE_X64 -E"
70
71
72
compile=no; link=no;;
-c) link=no;;
-o) output=$2;;
73
*.c|*.cc|*.cpp|*.S) source=$1;;
74
75
76
77
esac
shift
done
if test x$link = xyes; then
78
79
GCC_COMPILE_PPC32="$GCC_COMPILE_PPC32 $GCC_LINK_PPC32"
GCC_COMPILE_PPC64="$GCC_COMPILE_PPC64 $GCC_LINK_PPC64"
80
GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
81
GCC_COMPILE_X64="$GCC_COMPILE_X64 $GCC_LINK_X64"
82
83
84
85
86
fi
if test x"$output" = x; then
if test x$link = xyes; then
output=a.out
elif test x$compile = xyes; then
87
output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
88
89
90
fi
fi
91
# Compile PPC 32-bit
92
93
94
95
96
97
98
99
100
101
if test x"$output" != x; then
dir=ppc/`dirname $output`
if test -d $dir; then
:
else
mkdir -p $dir
fi
fi
set -- $args
while test x$1 != x; do
102
if test -f "ppc/$1" && test "$1" != "$output"; then
103
104
105
106
107
108
ppc_args="$ppc_args ppc/$1"
else
ppc_args="$ppc_args $1"
fi
shift
done
109
$GCC_COMPILE_PPC32 $ppc_args || exit $?
110
111
112
113
if test x"$output" != x; then
cp $output ppc/$output
fi
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Compile PPC 64-bit
if test x"$output" != x; then
dir=ppc64/`dirname $output`
if test -d $dir; then
:
else
mkdir -p $dir
fi
fi
set -- $args
while test x$1 != x; do
if test -f "ppc64/$1" && test "$1" != "$output"; then
ppc64_args="$ppc64_args ppc64/$1"
else
ppc64_args="$ppc64_args $1"
fi
shift
done
$GCC_COMPILE_PPC64 $ppc64_args || exit $?
if test x"$output" != x; then
cp $output ppc64/$output
fi
# Compile X86 32-bit
138
139
140
141
142
143
144
145
146
147
if test x"$output" != x; then
dir=x86/`dirname $output`
if test -d $dir; then
:
else
mkdir -p $dir
fi
fi
set -- $args
while test x$1 != x; do
148
if test -f "x86/$1" && test "$1" != "$output"; then
149
150
151
152
153
154
155
156
157
158
159
x86_args="$x86_args x86/$1"
else
x86_args="$x86_args $1"
fi
shift
done
$GCC_COMPILE_X86 $x86_args || exit $?
if test x"$output" != x; then
cp $output x86/$output
fi
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Compile X86 32-bit
if test x"$output" != x; then
dir=x64/`dirname $output`
if test -d $dir; then
:
else
mkdir -p $dir
fi
fi
set -- $args
while test x$1 != x; do
if test -f "x64/$1" && test "$1" != "$output"; then
x64_args="$x64_args x64/$1"
else
x64_args="$x64_args $1"
fi
shift
done
$GCC_COMPILE_X64 $x64_args || exit $?
if test x"$output" != x; then
cp $output x64/$output
fi
183
if test x"$output" != x; then
184
lipo -create -o $output ppc/$output ppc64/$output x86/$output x64/$output
185
fi