Thursday, April 26, 2007

mozilla / firefox 2 / bonecho build under FreeBSD 6.2

BonEcho!

I thought I'd share my experiences of building a fresh BonEcho/Firefox/2.0 from the Mozilla sauces on a cleanly built FreeBSD 6.2 system.

The reason for this entry is so I can help other people who may be hitting the same issues I did..

Here goes..

Firstly, I'll detail the steps I took to gather all the required data before we begin to think about building.

This link to the official mozilla build guide is invaluable, closely reading the pages there will help make your life easier.

I fetch'd the latest source from:- ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest-2.0/source.

You should now have a 35mb (ish) bz2 file, make sure you untar this to a mount point with at least 500mb free as this is how much space you'll need for a full build (as of 2.0 anyway)..

Before we proceed any further; the Mozilla build system has been developed with GNU make, so make sure you have that installed on your system (ports/devel/gmake).

Next step is to configure your individual make files, before going ahead and executing "./configure" you need to create a .mozconfig file (see the official build guide for more info).

There are various places you can stick the .mozconfig file, I put mine in the root of my home dir.
Here is mine for reference:-

mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@
. $topsrcdir/browser/config/mozconfig
ac_add_options --enable-optimize
ac_add_options --enable-default-toolkit=gtk2
ac_add_options --enable-xft
ac_add_options --disable-tests
Now go to the root of your fresh sauce dir and run ./configure.

If you get error messages at this point, then go Google, because I didn't :-).

You should now have a new dir called obj-i386-unknown-freebsd6.2/ (or similair).

There's a couple of BSD type things to do before we build:-

Number 1; The nsprpub tree won't build correctly under 6.2 kernel, if you look into devel/nspr under ports you'll notice a patch file (/usr/ports/devel/nspr/files/patch-.._pr_include_md__freebsd.h). You can apply this, or you can do as I did and manually edit the _freebsd.h file under your mozilla source tree (pr/include/md/_freebsd.h) and make sure the following two #defines are actually defined:-
#define _PR_HAVE_GETPROTO_R
#define _PR_HAVE_5_ARG_GETPROTO_R
What this basically does is force the use of the reentrant versions of getprotobyname() / etc. which in a nutshell means certain functions are then thread safe, and thus our final build can be as optimised as possible..

Number 2; The generated makefiles (via ./configure) only link against the re-entrant lib c and not the standard lib c, thus if you try and build you'll get lots of undefined references to memcpy() / etc. The easy fix for this is to edit obj-i386-unknown-freebsd6.2/config/autoconf.mk and change the OS_LIBS variable so it contains -lc:-

OS_LIBS = -lm -lc_r -lc

If you already have this data, then your ./configure worked differently to mine -- congratulations.

Now as per the build instructions go to the root of your sauce dir and execute the following command:-

gmake -f client.mk build

Depending on your box, the time taken for the build will obviously vary. I'd say leave it for a bit and come back!

Assuming success you should now have a working binary!

Follow the build instructions for proper installation, but to test it out make sure you've got an X session running, cd to obj-i386-unknown-freebsd6.2/dist/bin, and execute:-
./firefox

Nicely done!