Compiling on Mac OS X
(→Installing libraries with MacPorts: Added pkgconfig requirement)
(→Installing libraries with MacPorts)
|Line 55:||Line 55:|
<code>sudo port selfupdate</code>
<code>sudo port selfupdate</code>
Install ''libpng'' and possibly ''libiconv'' (the required ''zlib'' will be installed as dependency automatically). For lzma to be detected by the OpenTTD configure script, pkgconfig must also be added.
Install ''libpng'' and possibly ''libiconv'' (the required ''zlib'' will be installed as dependency automatically). For lzma to be detected by the OpenTTD configure script, pkgconfigmust also be added.
<code>sudo port install libpng
<code>sudo port install libpng
sudo port install liblzma
sudo port install liblzma
Revision as of 07:40, 29 December 2011
Compiling and developing OpenTTD on MacOSX
A quick guide to get started with OpenTTD development on OSX. Note: if you have not installed any of this, it will take a while and there will be a lot to download, but you will get access to a lot more software than just OpenTTD.
Compiling OpenTTD requires use of the command line, so before you start, you should make yourself familiar with the Terminal.app if you aren't already. A very brief terminal tutorial can be found here.
Installing Developer Tools/Xcode
First you need to install a compiler. You should do this by installing Xcode (10.3+) They should be on the CD / DVD when you got your OS. You can also download it from the Apple Developer Connection web site (free registration required), although it is over 3gb in size. This includes, amongst many other things, gcc (in the UNIX Dev Support package), which is the compiler that are used by most opensource projects, including OpenTTD.
Installing required libraries
In order to build OpenTTD from source you need to have installed some libraries which it depends upon. Depending upon your local installation you maybe also want to install a(nother) version control system like svn or mercurial in order to obtain the latest trunk source of OpenTTD.
The minimum requirements for OpenTTD on mac are:
and optionally you want also:
For getting the openttd source, you will need:
All of the above are installable using MacPorts, svn is installable using Fink.
On OSX 10.6.1 it may also be necessary to install:
The easiest solution in order to obtain these libraries is to have either Homebrew, macports, or fink install them for you. Alternatively, you may compile and install it from source for yourself. As another alternative you may visit the pages of those libraries and see whether they provide ready-compiled binary versions. At least libpng does so.
Please refer to the Homebrew website for instructions on how to install Homebrew.
The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system. As you will install libraries in your system directories, you'll need to do so as administrator via the command sudo - which will require you to enter the administrator password. Further information regarding
sudo can be found on wikipedia.
Installing libraries with MacPorts
Before installing any libraries, make sure you have access to the latest ports by updating the local repository:
sudo port selfupdate
Install libpng and possibly libiconv (the required zlib will be installed as dependency automatically). For lzma to be detected by the OpenTTD configure script, "pkgconfig" must also be added.
sudo port install libpng sudo port install liblzma sudo port install pkgconfig sudo port install libiconv
You will be asked to confirm required additional packages (like libz, zip libraries) as well.
At least in order to compile a static binary (for redistribution), but also for your convenience, you might want these as well:
sudo port install fontconfig sudo port install freetype sudo port install icu
If you've gone through these steps you'll have watched your computer compile libraries for some time, but now you'll have installed all prerequisites for compiling OpenTTD for yourself.
Getting the source
svn checkout svn://svn.openttd.org/trunk
This will install OpenTTD in a folder called trunk.
This will install OpenTTD in a folder. (The name varies with every version.)
git clone git://git.openttd.org/openttd/trunk.git
This will install OpenTTD in a folder.
Some further notes on MacPorts
If you would like to compile binaries which you want to distribute to other people, you want to compile universal binaries. All macport packages mentioned above offer the option to be installed as universal libaries, but it has to be requested for each install:
sudo port install zlib +universal
If you wish to install lzo2 use:
sudo port install lzo2
Fun fact: if you have installed yourself libraries and build them for other architectures than x86_64 i386 ppc and ppc64 it might fail. Those four seem to be accepted, but macports might bitch, if others are found like ppc970.
fink is basically the same as macports, but it may not be as well supported on newer OSX; this part of the documentation is also very outdated and has not been checked to work in several years.
Note: fink is only used for installing svn and libpng. Even though it's recommended, it's not mandatory anymore.
Fink is a nice tool to install open-source software with simple commands. You can get fink here http://fink.sourceforge.net/.
Before installing anything with fink, you should update fink (even if you just installed it). This is because fink have some local files, where it looks up what version of the software it should install. If a new version is out, it's stupid to install an already outdated version. You can update fink with the command fink selfupdate
Installing the svn client with fink
Like you installed the libs, you can now install the svn client with the command:
fink install svn-client
If you have Mac OS X Leopard, you already have svn. In a terminal window type
svn --version to check it.
Installing libraries with fink
You need some libraries to link to when compiling. You can use fink to install them with the following commands in terminal:
fink install libpng3
libpng3 is needed for making screenshots in png. Not really needed now, but there are future plans, so you might as well get it now. In each case, fink will tell that you that you need to install a lot of other stuff too, just hit enter (answering yes) and fink will download and install all of it. The docs telling about how to compile OpenTTD tells about zlib. Zlib is needed by OSX itself, so you already have it and there is no need to install it.
If you want truly universal libraries it might be needed that you compile the libraries yourself, especially as newer versions (e.g. Snow Leopard) only support 'universal' binaries and libraries with the i386 and x86_64 architectures while OpenTTD's universal binaries can also include ppc, ppc64 and ppc970.
There's no build script to get the required universal libraries, but some steps which can be followed will get you there.
- get the source of the library
- make sure it compiles with your usual settings w/o modification
- build all different architectures. This short shell script gives you an idea how to do it analogously for all libraries, this is made to build libz 1.2.5, you might need to adopt it accordingly:
#!/bin/bash export archs="ppc ppc64 ppc970 i386 x86_64" #export archs="ppc" export sdk="/Developer/SDKs/MacOSX10.4u.sdk" export file="libz.1.2.5.dylib" for this in $archs; do echo "$this" flags="-arch $this -isysroot $sdk -I$sdk/usr/include -mmacosx-version-min=10.3" export CFLAGS="$flags" export CXXFLAGS="$flags" export CPPFLAGS="$flags" export LDFLAGS="$flags" make clean ./configure make cp $file $this.$file done lipo -create *.$file -output $file
- subsequently install the resulting libz.1.2.5.dylib into your library dir, either /usr/lib or /opt/local/lib
Repeat similar steps for the other libraries.
Homebrew is a very simple package management system for Mac OS X. If you have Homebrew installed, you can have it build OpenTTD for you with a simple:
brew install openttd
Getting the newest source from the svn server
Now you need to make a "working copy" of the source with your new svn client. To do this, use your terminal and write:
svn checkout svn://svn.openttd.org/trunk Folder_name
Folder_name will be the folder you place the source into. If the folder doesn't exist, it will be created. Note you might have to type rehash after you installed svn to be able to do this.
You can also choose as specific revision to download by adding -r##### after svn checkout.
Compiling the source
For those just wanting a working copy for themselves, enter the following into a terminal window:
cd ~/Downloads/directory_containing_downloaded_sources ./configure make make bundle
For more detailed instructions, and options, read on...
Applying a patch
If you want to use a patch/diff file then you have to apply it before using configure. This is done in the same way as on Linux so you should read this: GNU/Linux#Applying_a_patch
There is a configure script. This is used to figure out what your system is like and generate a makefile to compile a binary designed for your system. To run it, just write
./configure and it will figure everything out on its own.
If you have a special request for your compilation, then you need to give arguments to configure. To see a full list of available settings, use the help system (
Example: if you want to make a static build (the binary will contain the needed parts of the libraries so they do not have to be installed on the computer playing the game), you will have to type
./configure --enable-static. Multiple arguments can be added like
./configure --enable-static --enable-dedicated.
If you don't have svn, and are trying to compile a nightly, configure with
./configure --revision=rXXXXX (where XXXXX is the revision number).
When configure has made a makefile for you, all you need to do to compile is to type
make. The binary is then placed in the "bin" subdirectory.
If needed, make can accept arguments as well. Commonly used arguments will be (all of them will start by compiling the game if needed):
make run: will start the game
make bundle: this will create a bundle inside the bundle directory (created if needed). This means that the game will be executable from finder and not only terminal
make bundle_dmg: as above, but will create a dmg
make help: lists all "targets" available (like make run and make bundle)
Make also accepts standard make arguments. The most interesting is the
-j option. By default GCC compiles one file at a time and it can only use one CPU/core to compile a single file. If you want to compile as fast as possible, you can tell it to compile more files at once with the
-j option. Example:
make bundle -j 4 will compile 4 files at once, making good use of a dualcore computer. Usually having two files compiling on each core is the fastest as one compile while the other one waits for read/write to the disk.
Note: the makefile dependencies has to be set up correctly for this to work. While they are for OpenTTD, don't assume this for other projects or nasty stuff can happen, like weird compilation errors.
If it comes to frequent compiles, it might be worth to look for alternative compilers. Newer OSX bring also llvm-gcc binaries which offer a speed gain during compilation for the cost of a bit slower binaries. In order to activate the set the environment variables CC=/Developer/usr/bin/llvm-gcc and CXX=/Developer/usr/bin/llvm-g++
Compiling universal binaries
Compiling a universal binary is done by adding
--enable-universal to configure:
This is all if your system is set up correctly. Make will then compile for intel, PPC and PPC970 (optimized for this particular CPU. Apple renamed it to G5), so setting G5 flags and such shouldn't be needed. Static is also enabled by default as it's assumed that the binary is to be moved to another computer.
For this to work, you will need universal libraries. For more info, read universal_libraries