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.
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.
If you would like to get your hands on the code directly, use either File Transfer Protocol (FTP) or Concurrent Versioning System (CVS) to grab the source from the Mozilla site. Many people prefer to start by grabbing an archive of the source code by FTP and then working with CVS as they modify the code.
If you're sure you won't check your work back into Mozilla and you just want to get the source, using FTP is the easiest way to do so. The main FTP server is at ftp://ftp.mozilla.org/ (a list of FTP mirrors is available on the mozilla.org site). To download a particular version of Mozilla, go to either /pub/mozilla/nightly/latest/ or /pub/mozilla/releases/, depending on which build you would like to have.
When you download the source from the releases directory, you get the code for the most recent Mozilla milestone. These releases are versions of Mozilla that have been tested and approved by developers at mozilla.org. Milestones come out about once a month and have some implied stability. The code in the "latest" directory is for the version of Mozilla currently under development. This code is not tested and stability is not guaranteed. In fact, the latest code may not even work if something that was checked in recently breaks Mozilla.
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:
Set the CVSROOT variable:
$ export CVSROOT=:pserver:[email protected]:/cvsroot
Log in using the password "anonymous":
$ cvs login CVS password: anonymous
Check out the build Makefile:
$ cvs checkout mozilla/client.mk U mozilla/client.mk
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:
Set the CVSROOT variable:
> set CVSROOT=:pserver:[email protected]:/cvsroot
Log in using the password "anonymous":
> cvs login CVS password: anonymous
Check out the build Makefile:
> cvs checkout mozilla/client.mk U mozilla/client.mk
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.
Building using nmake is no longer supported on the Mozilla development trunk, though there is a document describing this process for developers using older branches at http://www.mozilla.org/build/win32-nmake.html. |
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.
Branches are distinct Mozilla source code trees that are "cut" to carry out a specific purpose or used for a milestone release. Developers cut branches when making large architectural changes that could make the main tree unstable. Branches in this context allow freer changing and testing off the main trunk. To work with branches, set the MOZ_BRANCH environment variable:
> setenv MOZ_BRANCH=MOZILLA_1_0_BRANCH
The value changes according to the repository with which you work. All other steps can remain the same in the process.
To find out more about using CVS to get Mozilla source and to learn about what else you can do with CVS, go to http://www.mozilla.org/cvs.html.