Appendix A. Getting and Building the Mozilla Source

One of the best things about using Mozilla as an application development framework is that you don't need to get involved with the Mozilla source code to create a Mozilla application. A simple Mozilla binary that you download and install is the only development platform you need. You can create and use most procedures and samples described in this book with a precompiled version of the browser.

The best way to get a working version of Mozilla quickly is to download a precompiled binary for your platform. If you go to the mozilla.org homepage, you will find links to Mozilla's most recent stable milestone build for each platform and a link to the nightly development snapshot builds. These binaries come as compressed archives or with an installer, and you can use either to run Mozilla on your computer within a few minutes. These binaries don't include the source for Mozilla (unless you count the XUL, CSS, and JavaScript that made up the front end, which are always available), so read on if you want to obtain the code.

Under the relevant license terms, the Mozilla source code is freely available to anyone who has an Internet connection and a desire to explore. You may want to look at this code out of curiosity or dive into the code as you figure out how it works and can be improved. Whatever your reasons are for looking at the Mozilla source, it is not much more difficult to get the code and build it yourself than it is to download the precompiled binaries. To get started, you need to know a few things about how to get and use the source.

A.1. Getting the Source Code

You can get the Mozilla source code in a few different ways. Depending on what you are interested in doing, one method may work better for you than another. This appendix provides basic information about how to get the source, but you can also find information about this topic on the Mozilla site at http://www.mozilla.org/source.html.

If you want to look at the source code and don't intend to recompile it, experiment with it, or update it at all, the best way to get at the source is to browse the Mozilla code base with Mozilla Cross Reference (LXR). As you can see in Figure A-1, LXR is a web-based source code browsing tool located at http://lxr.mozilla.org. LXR is also hooked up to other tools, such as Bonsai (http://bonsai.mozilla.org) and the various tinderboxen (http://tinderbox.mozilla.org/showbuilds.cgi). Together, these tools create a powerful code maintenance system that is used widely by Mozilla developers.

A.1.2. Downloading the Source with CVS

Grabbing the source with CVS requires additional steps to get things set up properly, but for many, it's worth the effort. If you would like to contribute your own changes back to the community, you must understand how CVS works. Pulling the source in this manner is a good way to start learning about Mozilla development.

For a quick understanding of CVS, you can obtain a copy of the CVS Pocket Reference (O'Reilly). To pick up a binary distribution of CVS if it isn't already installed, go to http://www.cvshome.org/downloads.html, where you'll also find links to documentation.

Using CVS requires logging into the Mozilla site by using a CVS client, checking out the source code, modifying the source code locally, and then checking the code back into the tree. Anyone is free to check out the code, but you need special permission to check in the changes you make to the source. This chapter discusses only how to check out the source with CVS.

You first need a CVS client. Free CVS clients are available for most operating systems, including WinCVS on Windows and MacCVS for the Mac. Linux has a command-line CVS client that should come standard on most Linux distributions. Here are instructions for using the Linux command-line client to check out the source code:

  1. Set the CVSROOT variable:

$ export CVSROOT=:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot

  1. Log in using the password "anonymous":

$ cvs login
CVS password: anonymous

  1. Check out the build Makefile:

$ cvs checkout mozilla/client.mk
U mozilla/client.mk

  1. Run the Makefile script to get the files:

$ cd mozilla
$ make -f client.mk checkout

On Windows, the command-line interface used to obtain the Mozilla source is very similar. You just need to make a few small changes to the steps above for a Windows install. Here are the steps listed for comparison:

  1. Set the CVSROOT variable:

> set CVSROOT=:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot

  1. Log in using the password "anonymous":

> cvs login
CVS password: anonymous

  1. Check out the build Makefile:

> cvs checkout mozilla/client.mk
U mozilla/client.mk

  1. Run the Makefile script to get the files:

> cd mozilla
> make -f client.mk checkout

In Step 1, set the CVSROOT environment variable using the set command. Use the GNU make utility (make) on Windows just as you would on Unix.

Before you pull the source code, check the tree status in the relevant Tinderbox. Grab the source only if the tree is green (success) or yellow (building). Do not pull the source on red, which indicates that the build is broken.

To pull the Mozilla source code on Macintosh, use a client like MacCVS, which automates much of the CVS process for you. Mac OSX users can use the standard command-line CVS client and pull the source using a method similar to checking out the source in a Unix environment. Also be sure to include the required resources -- XML Perl modules, MacPerl, or the CodeWarrior development environment -- which are all listed later in Table A-1.

The MacCVS client works with session files, which have all the information and settings you need to pull Mozilla. The settings are listed on the mozilla.org Mac build page, which even has a ready-made session file that you can download into the client. Once you set your tools up and configure your session file for MacCVS, you can pull the Mozilla source by choosing "Check Out Default Module" from the MacCVS Action menu. Like the Macintosh build process, pulling the source on Macintosh involves the interaction of a series of Perl scripts. The PullMozilla.pl script, located with the other Macintosh build scripts in mozilla/build/mac/build_scripts, can drive your MacCVS client -- starting it up and pointing to the right source, setting the proper variables, and so on. For more information on the Macintosh build scripts, see http://www.mozilla.org/build/mac-build-system.html.