Linux - Compiling Mozilla Thunderbird from source
Page contents
Requirements
I started to read about setting up the environment and requirements for compiling Mozilla Thunderbird and thought it would be very difficult, but to be honest I just tried it first time without any additional work and ,much to my surprise, it worked first time. It seems that if you have Fedora Core 4 or 5 with all the latest updates you probably have all you need to compile Thunderbird. The biggest thing to be aware of is the amount of space required for compilation, the source tarball comes in at over 33Mb, and once uncompressed weighs in at 228Mb. Once compiled a debug build requires 2Gb and an optimized build about 500Mb. In my case I uncompressed the source into my $HOME directory but then compiled the program into a folder under /usr/lib (where the rest of my programs are located, including my default thunderbird not built by me).
This Linux Build Prerequisites page lists the requirements on Linux to build Mozilla applications. For the record I've listed the versions of each program installed on my Fedora Core 4 laptop, note that none of this I installed specially, they were already there.
gcc-4.0.2-8.fc4 perl-5.8.6-22 make-3.80-7 gtk2-2.6.10-2.fc4.4 libIDL-0.8.5-2 libIDL-devel-0.8.5-2 zip-2.3-30 freetype-2.1.9-2 fontconfig-2.2.3-13 pkgconfig-0.20-1.fc4.1
If you do need any of these then it's easy enough to run yum since they are all available in the Fedora base or extras depositories so no extra setting up is needed.
Get the source
There are 2 main ways to get the source, if you wish to get the latest build with all the latest checkins to the source code then you need to use CVS to pull the source, this is not covered here but if you wish to do this then you need to read Mozilla Source Code Via CVS. For most people like myself just interested in building a stable release it's much easier to just download a source tarball from here (this is the Thunderbird 1.5 source):
ftp://ftp.mozilla.org/pub/mozilla.org/thunderbird/releases/1.5/source
Next you need to decide where to build Thunderbird, I would recommend uncompressing the source into your $HOME directory but build it outside. This has 2 advantages, one is that the source and compiled code are not mixed together into the same directory and secondly by just changing your compiler options (which I'll explain later) you can build both a debug and optimized build from the same source but built into totally separate locations. To uncompress the tarball open a terminal and change to the directory you saved the tarball to, in my case a downloads directory in my $HOME:
$ cd $HOME/downloads $ tar xjvf thunderbird-1.5-source.tar.bz2 -C $HOME
This will uncompress the tarball into your $HOME directory, creating a new directory called mozilla in the process. Next change directory to the newly created mozilla:
$ cd $HOME/mozilla/
Compiler options
Depending on whether you wish to create a debug build or a optimized build you need to add various option into a text file for the compiler to pick up. In summary the differences between the two are:
Debug build
Thunderbird will be compiled with debugging symbols included, this will create a much larger file that runs much slower and should not be used for normal use. Only use this build if you wish to hack on Thunderbird and make your own modifications.
Optimized build
This creates a much smaller program that can be used for daily use, this creates a version much like is downloaded from the Mozilla site. Depending on the compilation options used it can create a personalized installation compiled for the specifics of your computer.
Creating a .mozconfig file
Next we need to create a text file using your favourite editor. The file must be called '.mozconfig', but can be placed either in the source directory you just uncompressed ('mozilla'), or in your $HOME directory and will contain our compiler options. I chose to use the source directory but the choice is yours. Once created open the file and enter (or paste) the following compiler options depending on whether you are building a debug, or optimized build.
optimized build
export BUILD_OFFICIAL=1 export MOZILLA_OFFICIAL=1 mk_add_options MOZ_THUNDERBIRD=1 mk_add_options MOZ_OBJDIR=/usr/lib/thunderbird_build/ mk_add_options BUILD_OFFICIAL=1 mk_add_options MOZILLA_OFFICIAL=1 ac_add_options --enable-application=mail ac_add_options --enable-optimize=-O2 -march=i686 ac_add_options --disable-debug ac_add_options --enable-xft ac_add_options --enable-freetype2 ac_add_options --enable-default-toolkit=gtk2
Debug build
export BUILD_OFFICIAL=1 export MOZILLA_OFFICIAL=1 mk_add_options MOZ_THUNDERBIRD=1 mk_add_options MOZ_OBJDIR=/usr/lib/thunderbird_build/ mk_add_options BUILD_OFFICIAL=1 mk_add_options MOZILLA_OFFICIAL=1 ac_add_options --enable-application=mail ac_add_options --disable-optimize ac_add_options --enable-debug ac_add_options --enable-xft ac_add_options --enable-freetype2 ac_add_options --enable-default-toolkit=gtk2
NOTE - the above options will mostly work just fine but you may need to alter the line ac_add_options --enable-optimize=-O2 -march=i686
to suit your processor, -O2 is how optimized the build will be, choose -O1 for less optimization and -O3 for most optimization. Note that an -O3 setting will
probably produce very specific code for your computer and probably won't work on a different computer so don't use this if you need you build to be portable.
If you wish to see more compiler options and a handy tool to create the .mozconfig file for you see the
Unix Build Configurator (only for those that really know what they're doing).
The option MOZ_OBJDIR should also be changed to where you wish to compile your program to, this can really be anywhere. If you do not include this line then
by default it will be compiled in the same directory as the source code, this will still work OK but it's a bit neater to use a different directory. Remember to
also create the build directory, in my case I need to do this as root since normal users cannot create directories in /usr/lib/, in the terminal type:
$ su - [enter password] $ mkdir /usr/lib/thunderbird_build
Compiling
Next we just need to start the compile process, change directory to the location of your source code and start the compilation. If you are compiling Thunderbird in your $HOME directory then you can do this as a normal user, however, if like me you decide to do this in /usr/lib or some other place then you will have to run this as root:
$ cd $HOME/mozilla/ $ su - $ [enter password] $ gmake -f client.mk build_all
About now it's time to take a break since the compile process will take quite a while, my laptop is a 1.3GHz Centrino with 512Mb of RAM and it took almost exactly 1 hour! During this time check back periodically to see that all is going well, the process outputs to the terminal so if an error occurs you will see various error and the compilation will stop. If all goes to plan you will have Thunderbird compiled into your chosen directory.
It is possible to run Thunderbird immediately after compilation, if you go to the compile directory and go to /dist/bin, in there you will see an executable called 'thunderbird', if you run this then your newly compiled Thunderbird will run, congratulations! A better way is to create a tarball from this directory, by doing this you can untar this into any directory and then delete the compile directory if you so wish. The tarball is exactly as if you had downloaded a tarball from the Mozilla site and uncompressed it into your usual location.
Creating an installation tarball
To make a tarball from this you need to change directory to your compile location, in my case /usr/lib/thunderbird_build and then run:
$ gmake -C mail/installer
After this has run you will see a new tarball called thunderbird-1.5.en-US.linux-i686.tar.gz located in the root of the compile location. This can then be installed on a different computer, if desired, or installed on you own computer in the usual way just by uncompressing the file into a directory and running the executable called 'thunderbird'. If you wish to save disk space you can now delete the compile directory and the source directory. Since you still have the source tarball this whole process can be repeated if you wish to create a debug build or change the compile options for example.







