Mac OS X Universal Binaries
From MDC
It is possible to build Mozilla applications as a universal binary that runs natively on both PowerPC and Intel processors running Mac OS X. Universal binaries contain:
- Compiled executable code for both architectures, such as:
- the main executable (for example,
firefox-bin) - shared libraries and binary plugins (for example,
libxpcom.dylib)
- the main executable (for example,
- A single copy of all other non-executable files, including:
- application resources (for example,
browser.jar) - localization packages (for example,
en-US.jar)
- application resources (for example,
Universal binaries of Mozilla applications can be built on both PowerPC and Intel-based Macs.
Contents |
[edit] Prerequisites
You should be familiar with the Mac OS X build prerequisites before attempting to build a universal binary of a Mozilla product. In addition to the standard Mac prerequisites, universal builds have the following requirements:
- Mozilla Source: The universal build system is supported on the trunk, the
MOZILLA_1_8_BRANCH, and theMOZILLA_1_8_0_BRANCHas of late February 2006. There are no plans to port the system to earlier branches. - Operating System: Mac OS X 10.4 (“Tiger”) or later. This is a requirement to build Mozilla, not run it. Mozilla will continue to run on PowerPC processors with Mac OS X versions as early as 10.2.
- Development Environment: Xcode Tools 2.2.1 or later. Apple provides downloadable Xcode updates.
- libIDL and GLib. At the present time, these do not need to be installed as universal binaries. It is sufficient to install libIDL and GLib for the build system only, according to the normal build prerequisites. This is a temporary workaround that will remain in place only until universal binaries of libIDL and GLib can reasonably be built.
[edit] Configuration
This section describes how to check out the necessary files and configure Mozilla to build as a universal binary.
[edit] Preparation
A mozconfig fragment is provided in the Mozilla source tree that configures the universal build appropriately. It is located at mozilla/build/macosx/universal/mozconfig. If you are using CVS, you must check this file out before attempting to build, along with client.mk and any other mozconfig files that your build requires.
This command is sufficient to prepare for a universal binary of Firefox on the Mozilla trunk:
cvs -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot co mozilla/client.mk mozilla/browser/config/mozconfig mozilla/build/macosx/universal/mozconfig
[edit] Your .mozconfig File
When preparing your own .mozconfig file, you must source the $topsrcdir/build/macosx/universal/mozconfig fragment. It should be sourced after any product-specific mozconfig, in case it needs to override any options.
Universal binaries must be built as objdir builds, so MOZ_OBJDIR must be set. The location of your objdir is unimportant, so long as you provide one.
Here is a sample .mozconfig suitable for building a universal binary of Firefox in a release configuration:
. $topsrcdir/browser/config/mozconfig . $topsrcdir/build/macosx/universal/mozconfig ac_add_options --enable-optimize ac_add_options --disable-tests mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../build
In this example, the objdir is placed adjacent to the mozilla directory, in a directory called build.
Options specified with ac_add_options are used to configure both the PowerPC and Intel builds. Options specified with ac_add_app_options will only apply to the listed processor. ppc or i386 must follow ac_add_app_options.
[edit] About the Configuration
The universal binary configuration sets several options to tune the PowerPC and Intel builds separately. Most notably:
- On the 1.9 branch (trunk):
- Compiler: Both builds will use GCC 4.0. Firefox 3 supports only OS X 10.4 or newer.
- Mac OS X SDK: Both builds will use the 10.4u (“Universal”) SDK.
- On the 1.8.0 and 1.8.1 branches:
- Compiler: The PowerPC build will be produced with GCC 3.3, and the Intel build will be produced with GCC 4.0. This will always happen automatically, and will completely override the system default compiler selected with
gcc_select.- GCC 4.0 is only capable of producing executable code from C++ source that runs on Mac OS X 10.3.9 and later. Mozilla supports earlier releases of Mac OS X on PowerPC, so GCC 3.3 must be used on PowerPC.
- GCC 4.0 is the only compiler able to build applications for Mac OS X on Intel.
- Mac OS X SDK: The PowerPC build will be produced with the Mac OS X 10.2.8 SDK to ensure that it will run on Mac OS X releases as early as 10.2. The Intel build will be produced with the Mac OS X 10.4u (“Universal”) SDK, the only SDK that supports Intel on Mac OS X.
- Compiler: The PowerPC build will be produced with GCC 3.3, and the Intel build will be produced with GCC 4.0. This will always happen automatically, and will completely override the system default compiler selected with
[edit] Building
Once the configuration is in place, building Mozilla as a universal binary is as easy as performing an ordinary build. Type:
make -w -f client.mk
The source code required for your build will be checked out and compiled. Two build passes are made: one to compile Mozilla for PowerPC, and another for Intel processors. Understandably, this process takes approximately twice as long as compiling for a single processor. After both passes are complete, the results are automatically merged into a single universal binary.
[edit] Results of a Build
Two subdirectories are created in your objdir: ppc and i386. Each of these directories contains a complete processor-specific build. The merged universal binary is placed in your objdir, at ppc/dist/universal with a symbolic link at i386/dist/universal.
[edit] Packaging
For most products, when configured as a universal binary, the packaging phase will produce a disk image containing the merged universal binary. In order to perform the packaging phase, you must keep the new objdir structure in mind. If you had used the sample .mozconfig above, you would build a universal disk image of Firefox by typing:
make -C ../build/ppc/browser/installer
The disk image will be produced in ../build/ppc/dist. You could just as easily substitute i386 for ppc, this only affects the location that the disk image is produced in.
To bypass universal packaging, and create a disk image containing the application for a single processor only, you can override the UNIVERSAL_BINARY variable, setting it to empty. This will package Firefox for Intel processors into a disk image, the result will not launch at all on PowerPC:
make -C ../build/i386/browser/installer UNIVERSAL_BINARY=
[edit] Appendices
[edit] Cross-Compilation
The universal build process is implemented as a PowerPC build followed by an Intel build. Whichever build is not native is performed as a cross-compilation. If desired, it is also possible to use Mozilla’s cross-compilation support to cross-compile on Mac OS X without doing a full universal build. The prerequisites are the same as for a universal build, but instead of configuring for a universal binary, the following settings are added to the .mozconfig:
# Use the next section if cross-compiling for Intel on a PowerPC: CC="gcc-4.0 -arch i386" CXX="g++-4.0 -arch i386" ac_add_options --target=i386-apple-darwin8.0.0 ac_add_options --with-macos-sdk=/Developer/SDKs/MacOSX10.4u.sdk # Use the next section if cross-compiling for PowerPC on an Intel, on the # 1.9 branch or higher: # CC="gcc-4.0 -arch ppc" # CXX="g++-4.0 -arch ppc" # ac_add_options --target=powerpc-apple-darwin8.0.0 # ac_add_options --with-macos-sdk=/Developer/SDKs/MacOSX10.4u.sdk # Use the next section if cross-compiling for PowerPC on an Intel, on the # 1.8.0 or 1.8.1 branches only: # CC="gcc-3.3 -arch ppc" # CXX="g++-3.3 -arch ppc" # ac_add_options --target=powerpc-apple-darwin8.0.0 # ac_add_options --with-macos-sdk=/Developer/SDKs/MacOSX10.2.8.sdk # This section remains the same for any type of cross-compilation. HOST_CC="gcc-4.0" HOST_CXX="g++-4.0" RANLIB=ranlib AR=ar AS=$CC LD=ld STRIP="strip -x -S" CROSS_COMPILE=1 ac_add_options --disable-libIDLtest ac_add_options --disable-glibtest
[edit] Intel Release History
- Firefox 1.5.0.2, released as a universal binary on 2006-04-13
- Thunderbird 1.5.0.4, released as a universal binary on 2006-06-01
- SeaMonkey 1.0.2, released as a universal binary on 2006-06-01
- Camino 1.0, released as a universal binary on 2006-02-14