1.准备MozillaBuild
在下面地址下载最新的MozillaBuild
http://ftp.mozilla.org/pub/mozilla/libraries/win32/
推荐安装到c:/mozilla-build,安装到其他目录也可
运行下面的命令,得到一个MinGW shell,下面的编译都要在这个shell中运行
start-msvc6.bat
start-msvc71.bat (VS 2003)
start-msvc8.bat (VS 2005)
start-msvc9.bat (VS 2008)
注意firefox 3以后的版本不能用msvc6编译
2.准备firefox源码
firefox的源码在
http://releases.mozilla.org/pub/mozilla.org/firefox/releases/
如果需要从Mercurial下载最新的代码,则需要通过start-msvc[x].bat进入MinGW shell,然后执行
hg clone http://hg.mozilla.org/mozilla-central/ firefox-src
如果需要签出其它版本的代码可以参考这里
https://developer.mozilla.org/En/Developer_Guide/Source_Code/Mercurial
3.以下都要在源码目录里操作
建立配置文件.mozconfig ,注意文件前面的".",最好在MozillaBuild的shell中touch一个,我没在windows上建
成这样的文件。在源码目录里建一个名字叫my-firfox的目录用来存放编译结果。
在源码目录下编写.mozconfig文件,
第一种编译组合:
--------------------------------------------------------
#以下两行表示编译browser,即firefox
mk_add_options MOZ_CO_PROJECT=browser
ac_add_options --enable-application=browser
#最终编译的结果放在这里
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/my-firefox
ac_add_options --disable-installer
#不编译测试
ac_add_options --disable-tests
ac_add_options --disable-mochitest
#不使用vista sdk,实在懒的安装这个
ac_add_options --with-windows-version=502
#debug/release
ac_add_options --disable-static --enable-shared
#如果不想调试改成--disable-debug即可
ac_add_options --disable-optimize --enable-debug
--------------------------------------------------------
第二种编译组合:
因为我们在“.mozconfig”文件里面使用了debug模式,编译出来的是一个debug模式下的名字叫做firefox.exe 的文件,如果你是用它进行网络连接的话,你会发现常常跳出错误窗口,这个是用来测试的(你需要每次点忽略才能继续执行)。会十分的麻烦的,所以,你可以把 “ac_add_options --enable-debug”这一行去掉,免得麻烦。换上:“ac_add_options --disable-debug”,记住,这样处理后能够加快编译的速度!加快速度的另外一个办法是加上:“ac_add_options --disable-tests”,这样就不会生成许多测试程序了。推荐的,编译firefox时,最好的“.mozconfig”是这样的:
--------------------------------------------------------
. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/my-firefox
ac_add_options --enable-optimize
ac_add_options --disable-debug
ac_add_options --disable-static
ac_add_options --enable-shared
ac_add_options --disable-tests
mk_add_options MOZ_CO_PROJECT=browser
--------------------------------------------------------
具体配置内容经常变化,可以参考
https://developer.mozilla.org/en/Configuring_Build_Options
4.make编译
make -f client.mk build
时间很长,耐心等待....
5.编译好了的文件在 源码目录/my-firefox/dist/bin 目录下,名字叫firefox.exe,如果选择了
带有--enable-optimize 和--enable-debug选项的第一种编译组合你就可以用Microsoft Visual Studio
打开自己的mozilla firefox并能够自己看着源代码调试了,快去试试吧。
6. 如果你想编译成一个安装的版本,你可以删除:“ac_add_options --disable-installer”。
参考链接
https://developer.mozilla.org/En/Developer_Guide/Build_Instructions