This document illustrates how to build OS X Bundle (FlightGear.app) with cvs-head on Mac OS 10.4.x/10.5.x with Xcode 3.0 or later
Requirements
System Requirements
- Mac OS 10.5.x (Leopard) or higher
- Xcode 3.0 or higher as of Oct-18-2008
- PPC / Intel Mac
Faster machine (G5 or Intel) is recommended as FlightGear-cvs with OSG is heavier than 0.9.9 or 0.9.10. Compiling all the files may also take hours in slower G4 machines. FYI, It takes approximately 45 mins to compile everything on MacBook Pro 2.33GHz.
Required Skills
We assume you have some basic knowledge about using:
- terminal (/Applications/Utilities/Terminal.app) - must
- Xcode (inlcuding gcc etc)
- Unix commands
If you are not familiar with the tools above, we highly recommend you consult some web articles and/or books about these before you get started. Please DO NOT ask project members about the use of these tools.
Instruction
Here is the step-by-step instruction of building FlightGear.
Required files
Mac OS X project files contains shell scripts that semi-automatically download all required files so you don't have to find these files. However, required files can be frequently changed so it's good to know where you can get those. Most recent information about required source files are listed here so keep an eye on that page. F.Y.I., This page also shows the required files as of June 17th, 2009.
- Xcode project files and patches (Mac OS X specific)
You can download the latest project files with:
$ LC_ALL=C /usr/local/bin/svn co \ https://macflightgear.svn.sourceforge.net/svnroot/macflightgear/trunk
If you don't have a subversion client, download a binary package from Subversion Project. I use svn that comes with Leopard (as of June 18, 2009).
Preparation
- Download and install subversion (only if you don't have one. Leopard has one by default).
- Add the following lines to ~/.bashrc (only for those who installed svn from subversion.trigris.org):
alias svn='LC_ALL=C /usr/local/bin/svn'
and run:$ source ~/.bashrc
- Download Xcode project files
- run download.sh - fetches everything you need
- when asked cvs password, type 'guest' or 'cvsguest' as requested.
- run patch.sh
- patch -N -p0 < patches/alc.patch
- This will fix the broken OpenAL.framework/Headers/alc.h that causes compilation errors
Compilation
It's easy to build. Use build.sh to build everything from Terminal.app.
You can also manually build these files (if you want). Open and build Xcode projects in this order:
- OpenSceneGraph/Xcode/OpenSceneGraph/OpenSceneGraph.xcodeproj
- FlightGear needs only two targets: "osgFrameworks" and "osgPlugins"
- PLIB/PLIB.xcodeproj
- SimGear/SimGear.xcodeproj
- FlightGear/FlightGear.xcodeproj
- FlightGearOSX/FlightGearOSX.xcodeproj (GUI launcher)
Note
- "Active Build Configuration" in three OpenSceneGraph related Xcode projects must be set to "Deployment" before pressing the Build button, otherwise the FlightGear Xcode project cannot find OSG frameworks and plugins.
- Building FlightGearOSX/FlightGearOSX.xcodeproj on PPC Macs causes an error saying there's no i386 arch for Cocoa.framework. This is because your PPC Mac doesn't have universal binary version of Cocoa.framework. Change the "Architecture" configuration on Xcode from 'i386 ppc' to ppc. Since fgfs is compiled as a universal binary, the launcher doesn't have to be a universal binary.
Tips
You might encounter "undefined symbols" when linking. This happens when new files are added into CVS repository but Xcode project file is not updated. In this case, open Xcode for the project and add the files manually. The easiest way to find the files to add is:
- use grep to find a file that contains the method/function that dyld cannot find.
- add the file to an appropriate group in Xcode project
- usually you can find the group by the path to the file
- check the target of the file
- usually you can find the target by the path to the file
As this source package (FlightGearOSX/CVS) uses OpenSceneGraph/svn, you may be in trouble with some unexpecting BUS error or Segmentation fault (EXE_BAD_ACCESS or KERN_PROTECTION FAILURE in a crash log). to build more stable FlightGear, you should download OpenSceneGraph as of the same date of the FlightGearMacOSX-DevOSG package. You can download the files at OpenSceneGraph/Producer/OpenThreads nightly tarballs. Download three tar.gz files released on the same date and extract these at FlightGearMacOSX/OpenSceneGraph/. Don't forget to rename folder names to original ones (without version-date postfix ; e.g. mv OpenSceneGraph-1.5.0-200612082325 OpenSceneGraph ). See also FlightGear CVS/OSG build results for some detail information.
Optimizing FlightGear on Intel Macs
There are some compiler flags you can use on Intel Macs. (It's hard to find the common optimization flags for PPC Macs...)
- PER_ARCH_CCFLAGS_i386 = -mtune=prescott -mfpmath=sse
- PER_ARCH_CFLAGS_i386 = -mtune=prescott -mfpmath=sse
You can specify these flags from "Project" -> "Edit Project Settings" -> "Customized Options" for Deployment (or one of FlightGear, SimGear, or Release) configuration.
Note
- Core 2 Duo users can use -mtune=core2 instread of prescott.
It enables you to use ssse3 extension + 64bit extension. I haven't trid it so give me your feedback. Specifying this flag makes FlightGear run only on Core 2 Duo Macs and Mac Pros so it's better not distribute it. - Optimization flags may cause Illegal operation exceptions.
This is caused by either wrong optimization flags for you CPU or a bug in Mac OS kernel (darwin). If you get this type of error, clear the optimization flag (e.g. -mtune=core2, -mfpmath=sse) and try again. - Using -O2, -O3, or -Os with gcc4.0 (comes with Xcode 3.1/3.1.1) causes FlightGear crash. Do not use these optimization flags for FlightGear. edit build.sh and change GCC_OPTIMIZATION_LEVEL to 0 or 1. You can also use gcc 4.2 for enabling full optimization.
- Using gcc 4.2 on Xcode will give you some compilation errors around ALUT or OpenAL/alc.h. In this case, you need to edit SDK's OpenAL/alc.h and alut.h to change both ALCvoid and ALvoid to void if it is the only argument of a prototype declaration. Moreover, gcc 4.2 doesn't contain SDKs for Mac OS X 10.4. However, specifying SDKROOT=MacOSX10.5.sdk and TARGET_MAC_OSX=10.4 can build a binary for both Tiger and Leopard.
- Using your own ALUT.framework (if you build FlightGear without using my Xcode project files) might get linker error. In this case, specify linker to link ALUT.framework before OpenAL.framework. This is because Apple's OpenAL.framework contains ALUT implementation so linker complains the duplicated symbols (but no alut.h inside framework).
Have a test flight
Launch FlightGear.app at FlightGearOSX/build/Deployment.
You can also fly without the launcher by running the following command:
$ cd FlightGearOSX/build/Deoployment/Flightgear.app/Contents/Resources $ ./fgfs.sh
You can change aircraft and airport as you want.
Enjoy!
Author
Tat Nishioka <tat "dot" fgmacosx 'at' gmail "dot" com>
December 7th, 2006 at 3:26 pm Got past the first build failure by adding SGMaterialAnimation.cxx/.hxx to the sgmodel target in the SimGear xcode project, now getting another failure when trying to compile main.m in FlightGearOSX; it fails to find included file RubyCocoa/RBRuntime.h This file (RBRuntime.h) doesn't exist on my system, so it appears that RubyCocoa is needed but not installed. I downloaded and installed the RubyCocoa dmg (perhaps download.sh should do this automatically?), but now I'm getting link errors, regarding architectures etc. (I'm building on a G4 by the way.) I can email the errors or post them here, but they're quite long.
December 7th, 2006 at 5:05 pm I guess you're going a bit ahead of my updating the repository :-) I updated the repository a few minutes ago, so you can update your local working copy to the latest revision. RubyCocoa downloader is already included in 0.9.10 package so I updated the one in DevOSG package. The downloader will launch the installer. You can compile FlightGearOSX for ppc only. FlightGearOSX.xcodeproj only compiles the launcher so you can cut off i386 if Xcode coplains about missing i386 arch in Framework or ruby library. Important thing is that you already made a universal binary version of fgfs. Don't care about the architecture of the launcher.
December 7th, 2006 at 6:06 pm Minor suggestion: make the download.sh script use compression when doing a CVS or SVN checkout; for example, add a "-z9" flag.
December 7th, 2006 at 10:48 pm Though I don't know if 9 is the best compression level in terms of overall performance, specifying -z option is a good idea. Let me change that later. We can change the level if there's any problem.
December 8th, 2006 at 12:45 am Yep, the build completes on the G4, albeit with i386-related linker warnings. However, the download.sh script fails to check out the flightgear data. ie, simgear source and flightgear source are ok, but flightgear data fails to check out. This is because when we first checkout the macflightgear stuff from subversion, this creates the (empty) directory FlightGearOSX/data. And download.sh then notices that the directory exists, so instead of doing a CVS checkout, it does a CVS update, which fails because there are no CVS control files in that directory. Also, (once the data is put in the right place), running the testfly.sh script results in a runtime error, with fgfs failing doing a vm_allocate(). I haven't yet tried to debug this, I will do so soon.
December 8th, 2006 at 5:07 pm Yeah, I also encountered this CVS update problem -) I'm gonna remove the data folder from svn repository. That should not be there. I haven't tried fgfs-cvs/osg on ppc Macs so I can't help you, but I hope you can solve the problem.
December 9th, 2006 at 1:51 pm No luck debugging the runtime error; I tried it again and now it works fine.
December 12th, 2006 at 4:37 pm That's great to hear that you successfully built it. I removed data folder from the svn repository so you can checkout the data for the first time.
January 19th, 2007 at 5:57 pm In build FlightGear, in build fgfs can't locate -lsgbucket /usr/bin/ld: warning -L: directory name (/FlightGearMacOSX/flightgear/../SimGear/build/SimGear) does not exist. Set project Framework Search Paths for simgear how?
January 20th, 2007 at 6:35 am setting plib and simgear links fixes that.
March 3rd, 2007 at 11:39 am hluv glqbca dyqknwho esralbmvk khvdpousb kvpn zekojlw