Table of contents
- 1. Using a .mozconfig configuration file
- 2. Building with an objdir
- 3. Parallel compilation
- 4. Choose an application
- 5. Selecting build options
- 6. Example .mozconfig Files
- 7. Building multiple applications from the same source tree
Starting with Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2)
, building Firefox has become extremely simple. The default application is now Firefox, so you can build Firefox by simply doing
configure && make (for downloaded code) or
make -f client.mk (for code from the Mercurial repository); this will build something roughly the same as the shipped version of Firefox corresponding to the code you have. You only need to follow the steps below if you want to customize the build (e.g. to create a debug build, or a release build with debug symbols), you want to build something other than Firefox, or you want to build pre-gecko 5.0 source.
If you are building Mozilla source code from before Firefox 5, then you must first select the Mozilla application that you want to build (see below), and you will probably also need to set at least some of the other basic configuration options (such as whether to build a debug build or not) to get the type of build that you need.
Please read the following directions carefully before building, and follow them in order. If you skip any steps, you may find that you can't build the software, or that the build result isn't usable. Note that build options, including options not usable from the command-line, may appear in "confvars.sh" files in the source tree.
Using a .mozconfig configuration file
The choice of which Mozilla application to build and other configuration options should be set in a
.mozconfig file. (It is possible to manually call
configure with command-line options, but this is not recommended.) The
.mozconfig file should be in your source directory (that is,
This will also help when troubleshooting as people will want to know which build options you have selected and will assume that you have put them in your
echo "# My first mozilla config" > .mozconfig
mozconfig(without the leading dot) for this file, which has the advantage that the file will be visible in directory listings.
.mozconfig contains two types of options:
- Options prefixed with
mk_add_optionsare passed to
client.mk. The most important of these is MOZ_OBJDIR, which controls where your application gets built (also known as the object directory).
- If you are building from an older project branch that still uses CVS, you will need to set MOZ_CO_PROJECT to the appropriate value or values, using a comma-separated list, such as "
mk_add_options MOZ_CO_PROJECT=browser,mail,calendar,suite,xulrunner". This setting is ignored by most Mozilla project branches, which now use mercurial instead of CVS for source control.
- Options prefixed with
ac_add_optionsare passed to
configure, and affect the build process.
These options will be automatically used when
make -f client.mk are run.
At the bottom of this page are several example
You can also use the
MOZCONFIG environment variable to specify the path to your
.mozconfig, but the path you specify must be an absolute path or else
client.mk will not find it:
This is useful if you choose to have multiple
.mozconfig files for different applications or configurations. Note that in this
export example the filename was not
.mozconfig. Regardless of the name of the actual file you use, we refer to this file as the
.mozconfig file in the examples below.
Building with an objdir
It is highly recommended that you use an objdir when building Mozilla. This means that the source code and object files are not intermingled in your directory system. If you use an objdir, you can build multiple applications (e.g. Firefox and Thunderbird) from the same source tree.
The act of using an objdir means that every Makefile.in file in your source tree will be turned into a Makefile in the objdir. The parent directories of the Makefile.in will be the same parent directories in objdir. For example, for the file
mozilla/modules/plugin/base/src/Makefile.in, with an objdir value of
@TOPSRCDIR@/obj-debug, the file and directory path
mozilla/obj-debug/modules/plugin/base/src/Makefile will be created. This Makefile will magically refer to source files in the
If you need to re-run configure, the easiest way to do it is using
make -f client.mk configure but if you want to run configure manually please do so from within your object directory, and do it by giving the absolute path to the configure script. For example, if you are running on Win32, and your source tree is in
/c/Projects/FIREFOX/mozilla, then, from within your objdir you would need to run
/c/Projects/FIREFOX/mozilla/configure whenever you need to manually run configure.
Adding the following line to your
.mozconfig enables an objdir:
It is a good idea to have your objdir name start with
obj so that Mercurial ignores it.
Starting in Gecko 2.0, objdir builds are enabled by default. If you do not specify a MOZ_OBJDIR it will be automatically set to @TOPSRCDIR@/obj-@CONFIG_GUESS@
Alternatively, you can run
client.mk directly from your objdir, using
make -f <path_to_srcdir>/client.mk
Most modern systems have multiple cores and/or CPUs, and they can be optionally used concurrently to make the build faster. The "-j" flag controls how many parallel builds will run concurrently. You will see (diminishing) returns up to a value approximately 1.5x to 2.0x the number of cores on your system.
Choose an application
--enable-application=application flag is used to select an application to build.
Starting in Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2)
, if you don't specify an application,
--enable-application=browser is assumed, thereby building Firefox.
Choose one of the following options to add to your mozconfig file:
- Browser (Firefox)
- Mail (Thunderbird)
- Mozilla Suite (SeaMonkey)
- Standalone Calendar (Sunbird)
Selecting build options
The build options you choose depends on what application you are building and what you will be using the build for. If you want to use the build regularly, you will want a release build without extra debugging information; if you are a developer who wants to hack the source code, you probably want a non-optimized build with extra debugging macros.
There are many options recognized by the configure script which are special-purpose options intended for embedders or other special situations, and should not be used to build the full suite/XUL applications. The full list of options can be obtained by running
The following build options are very common:
- ac_add_options --enable-optimize
- Enables the default compiler optimization options
- ac_add_options --enable-optimize=-O2
- Choose particular compiler optimization options. In most cases, this will not give the desired results, unless you know the Mozilla codebase very well; note however that if you are building with the Microsoft compilers, you probably do want this as
-O1will optimise for size, unlike GCC.
- ac_add_options --enable-debug
- Enables assertions and other debug-only code. This can significantly slow a build, but it is invaluable when writing patches. People developing patches should generally use this option.
- ac_add_options --disable-optimize
- Disables compiler optimization. This makes it much easier to step through code in a debugger.
You can make an optimized build with debugging symbols. See Building Firefox with Debug Symbols.
extensions/. Many of these extensions are now considered an integral part of the browsing experience. There is a default list of extensions for the suite, and each app-specific mozconfig specifies a different default set. Some extensions are not compatible with all apps, for example:
- cookie is not compatible with thunderbird
- typeaheadfind is not compatible with any toolkit app (Firefox, Thunderbird, Sunbird)
Unless you know which extensions are compatible with which apps, do not use the --enable-extensions option; the build system will automatically select the proper default set of extensions.
On the 1.7 and aviary branches, cryptography was off by default. You need to specify
--enable-crypto if you want SSL, SMIME, or other software features that require cryptography.
Example .mozconfig Files
Mozilla's official builds use mozconfig files from the appropriate directory within http://hg.mozilla.org/build/buildbot-configs/file/ such as win32/mozilla-2.0/nightly for the Firefox 4 (mozilla-2.0) nightly build.
Firefox, Default Release Configuration
. $topsrcdir/browser/config/mozconfig mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/ff-opt mk_add_options MOZ_MAKE_FLAGS="-j4" ac_add_options --disable-tests
Firefox, Debugging Build
. $topsrcdir/browser/config/mozconfig mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/ff-dbg mk_add_options MOZ_MAKE_FLAGS="-j4" ac_add_options --disable-optimize ac_add_options --enable-debug ac_add_options --enable-tests
Thunderbird, Debugging Build
. $topsrcdir/mail/config/mozconfig mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/tbird-debug mk_add_options MOZ_MAKE_FLAGS="-j4" ac_add_options --disable-optimize ac_add_options --enable-debug
SeaMonkey, Optimized (but not static)
ac_add_options --enable-application=suite mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/suite-opt mk_add_options MOZ_MAKE_FLAGS="-j4" ac_add_options --enable-optimize ac_add_options --disable-debug
XULRunner, Minimal Release Build
mk_add_options MOZ_OBJDIR=@topsrcdir@/obj-xulrunner mk_add_options MOZ_MAKE_FLAGS="-j4" ac_add_options --enable-application=xulrunner
Building multiple applications from the same source tree
It is possible to build multiple applications from the same source tree, as long as you have checked out all the necessary sources and you use a different objdir for each application.
You can either create multiple mozconfig files, or alternatively, use the
MOZ_BUILD_PROJECTS make option.
Using MOZ_BUILD_PROJECTS in a single mozconfig
MOZ_BUILD_PROJECTS, you must specify a
MOZ_OBJDIR, and a
MOZ_BUILD_PROJECTS make option, containing space separated names. Each name can be an arbitrary directory name. For each name, a subdirectory is created under the toplevel objdir. You then need to use the
ac_add_app_options with the specified names to enable different applications in each object directory.
ac_add_options --disable-optimize --enable-debug mk_add_options MOZ_OBJDIR=/mozilla/src/obj-@CONFIG_GUESS@ mk_add_options MOZ_BUILD_PROJECTS="xulrunner browser mail" ac_add_app_options browser --enable-application=browser ac_add_app_options xulrunner --enable-application=xulrunner ac_add_app_options mail --enable-application=mail
If you want to build only one project using this
mozconfig, use the following commandline:
make -f client.mk build MOZ_CURRENT_PROJECT=browser
This will build only browser.
Using multiple mozconfig files
Alternatively, you may want to create separate
As an example, the following steps can be used to build Firefox and Thunderbird. You should first create three
# add common options here, such as making an optimised release build and # disabling tests mk_add_options MOZ_MAKE_FLAGS="-j4" ac_add_options --enable-optimize --disable-debug ac_add_options --disable-tests
# include the common mozconfig . ./mozconfig-common # Build Firefox mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/firefox-static ac_add_options --enable-application=browser
# include the common mozconfig . ./mozconfig-common # Build Thunderbird mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/thunderbird-static ac_add_options --enable-application=mail
To checkout, run the following commands:
export MOZCONFIG=/path/to/mozilla/mozconfig-common make -f client.mk checkout
To build Firefox, run the following commands:
export MOZCONFIG=/path/to/mozilla/mozconfig-firefox make -f client.mk build
To build Thunderbird, run the following commands:
export MOZCONFIG=/path/to/mozilla/mozconfig-thunderbird make -f client.mk build