2 http://devs.openttd.org/~truebrain/compile-farm/apple-darwin9.txt
4 Cross-Compiling on Linux for
5 Mac OS X 10.3 - 10.5 (PPC and Intel)
6 ====================================
7 Last Updated: 2009-03-29
9 It often is wroten down as impossible, but it can be done (and our nightlies
10 are the living proof of that). You can make OSX binaries on a Linux based
11 system. But, the process is not easy. Even worse, in the years we are
12 supplying this, we had to change this documentation more often than any other
13 target. This is mostly because you can't use a mainstream GCC, but you need
14 the one from Apple. When you figured this out, and where to get the
15 binutils tools, it in fact is very straight forward.
18 - Mac OS X SDK Framework 10.4u.
19 - 7zip 4.61+ to extract DMG files.
20 - A fast computer, or a lots of time.
21 - A working 32bit linux compiler (on 64bit, use -m32 ;)).
22 - Bison installed (else it configures, but compile fails).
25 - A i686-apple-darwin9 compiler (gcc and g++)
26 For Mac OS X 10.4 - 10.5 Intel
27 - A powerpc-apple-darwin9 compiler (gcc and g++)
28 For Mac OS X 10.3 - 10.5 PPC
29 - A x86_64-apple-darwin9 compiler (gcc and g++)
30 For Mac OS X 10.5 Intel (64bit)
33 - Even on 64bit systems, compile 32bit binaries. It avoids a lot of errors.
36 - I can't guarantee you this will work, nor that it won't break your system.
37 - Please, don't complain to me or ask me about this documentation. It is
38 more meant as internal reference for when ever I want to reinstall the
39 system. If it doesn't work for you, too bad, nothing to see here, find
43 - Yes, this also works with Mac OS X 10.5 Intel.
44 - Yes, you can also make a x86_64 compiler.
50 Pick which compiler you want to compile. Either one should do:
52 - powerpc-apple-darwin9
53 - x86_64-apple-darwin9
55 Now put that in a variable:
57 export TARGET=i686-apple-darwin9
59 We will use this a lot later on, to simplify this documentation, and show you
60 it works for any target you pick.
66 To start, you need tools like 'ld', 'ar', ... this you can find in the package
67 named 'odcctools'. I used various of sources over the years, the last one
68 which seems to produce valid linux binaries, is located here:
70 http://iphone-dev.googlecode.com/svn/
72 A bit good comes of the iPhone development after all ;) To install it, you
73 need some minor modifications. Also, I used the 'branches' version, which
74 has 9.2 ld version (well, I thought the name was just more cool!)
76 The current odcctools (r280) seems to contain a bug in the 'as'. It registers
77 'word' twice, which gives an error. Sadly enough, both definitions are
78 different. But, this patch fixes the problem by commenting one out, hoping
79 the value of the other (older) one is correct. The odcctools also contain a
80 few other bugs and problems. So load all the patches. After that, it seems to
83 # svn checkout http://iphone-dev.googlecode.com/svn/branches/odcctools-9.2-ld/
86 # wget http://devs.openttd.org/~truebrain/compile-farm/odcctools_as.patch
87 # patch -p0 < odcctools_as.patch
89 # wget http://devs.openttd.org/~truebrain/compile-farm/odcctools_qsort.patch
90 # patch -p0 < odcctools_qsort.patch
92 # wget http://devs.openttd.org/~truebrain/compile-farm/odcctools_lipo.patch
93 # patch -p0 < odcctools_lipo.patch
95 # wget http://devs.openttd.org/~truebrain/compile-farm/odcctools_ld64.patch
96 # patch -p0 < odcctools_ld64.patch
98 # ./configure --prefix=/usr/$TARGET --target=$TARGET --with-sysroot=/usr/$TARGET --enable-ld64
100 In case you run x86_64-pc-linux-gnu, you might want to consider running this instead:
102 # LDFLAGS="-m32" CFLAGS="-m32" ./configure --prefix=/usr/$TARGET --target=$TARGET --with-sysroot=/usr/$TARGET --enable-ld64
108 On the line 'COMPONENTS = ', remove 'otool'. If you want this tool, make sure
109 you have a objc++ compiler .. I don't, and I don't care about this tool.
114 Now you should have a few useful tools in /usr/$TARGET/bin directory. If not,
115 take a step back, and try again.
121 Nowedays 7zip support .dmg files too (4.61+ I believe; I used 4.65). So now you
122 can extract the files without access to a Mac. First, download xcode 3.1.2
123 from the Apple website (you need an account!). Feel free to use any other
124 version. The newer the better I guess.
126 For most targets, you want to extract the 10.4u SDK. This allows your binary
127 to run from 10.3 to 10.5. But if you want to go for the x86_64 compiler, you
128 need to go for the 10.5 SDK. As 10.4 can't run 64bit code anyway, it shouldn't
131 After downloading, you can extract it with (a long tree of compressed objects
132 in other compressed objects):
135 # 7z x ../xcode312_2621_developerdvd.dmg
137 # 7z x Xcode\ Tools/Packages/MacOSX10.4.Universal.pkg
140 # cp -R SDKs/MacOSX10.4u.sdk/* /usr/$TARGET/
141 # ln -sf /usr/$TARGET/System/Library/Frameworks /usr/$TARGET/Library/Frameworks
143 This should give you enough files to continue the compile. You need to use
144 'cpio' on the last step, as 7z eats symlinks.
149 Now the most important part: GCC, your compiler.
151 Download the latest GCC From the Apple website. I used:
153 http://www.opensource.apple.com/darwinsource/tarballs/other/gcc-5490.tar.gz
155 Feel free to use any newer. Extract the file somewhere.
158 # tar zxvf gcc-5490.tar.gz
160 gcc works nicely out-of-the-box, but Apple introduced one stupid thing: they
161 use 'lipo' to check if the host is 32bit or 64bit. Of course it should be
162 checking against the target. So we need a patch to force either 32bit
163 (which also happens when you don't patch) or 64bit (which you need if you
164 want to use x86_64-apple-darwin9). So apply either of those patches:
167 # wget http://devs.openttd.org/~truebrain/compile-farm/gcc-32bit.patch
168 # wget http://devs.openttd.org/~truebrain/compile-farm/gcc-64bit.patch
169 # patch -p0 < gcc-??bit.patch
171 Also apply this patch, to avoid some weirdness with CFLAGS:
173 # wget http://devs.openttd.org/~truebrain/compile-farm/gcc-cflags.patch
174 # patch -p0 < gcc-cflags.patch
176 Apply this patch if you don't want /usr/$TARGET/$TARGET dir (it annoys me ..
177 it is nothing really ground-breaking or code-changing):
179 # wget http://devs.openttd.org/~truebrain/compile-farm/gcc-tooldir.patch
180 # patch -p0 < gcc-tooldir.patch
183 Now you can compile, like:
187 # export PATH=$PATH:/usr/$TARGET/bin
188 # ../gcc-5490/configure --prefix=/usr/$TARGET --disable-checking --enable-languages=c,objc,c++,obj-c++ --with-as=/usr/$TARGET/bin/$TARGET-as --with-ld=/usr/$TARGET/bin/$TARGET-ld --target=$TARGET --with-sysroot=/usr/$TARGET --enable-static --enable-shared --disable-nls --disable-multilib
190 If you are on a 64bit system, you can run the following (avoids -lm errors):
192 # CFLAGS="-m32" LDFLAGS="-m32" ../gcc-5490/configure --prefix=/usr/$TARGET --disable-checking --enable-languages=c,objc,c++,obj-c++ --with-as=/usr/$TARGET/bin/${TARGET}-as --with-ld=/usr/$TARGET/bin/${TARGET}-ld --target=$TARGET --with-sysroot=/usr/$TARGET --enable-static --enable-shared --disable-nls --disable-multilib
194 If you are compiling x86_64-apple-darwin9, make sure to replace 'ld' with
195 'ld64' in the above configure. It isn't doing this on its own. Also, it looks
196 like if you want to use 10.5 SDK for any other target, you need to use 'ld64'
197 too. It seems 'ld' is slightly too old to understand a certain section in a
198 library of the 10.5 SDK.
205 On a 32bit system, you most likely run into a problem with libstdc++v3. It
206 tries to compile something while it is not allowed, or so it tells. I have
207 yet no idea why this happens, I just know on a 64bit system this problem
208 does not exist. If you solve it, please email me, and I will add your
211 Now you should have a working gcc and g++ binary in your
212 /usr/$TARGET/bin directory. As I said, it is very simple if you
213 know which tools to use and what to use for configure flags.
219 If you need libraries like libpng or libz, please start up your Mac OS X, and
220 just copy them from there. Make sure that you use the right versions, and if
221 possible universal build versions (those with multiple versions in them). It
222 is almost impossible to compile such libraries yourself on your
223 cross-compiler, and I would advise against it. Copying from a real Mac OS X
224 is much easier, and shows much better results. But that is just my advise ;)
230 There is not really much more to it. If this worked for you, and you want to
231 thank me, please donate some money to OpenTTD. It is always very welcome.