mozilla原代码编译

来源:互联网 发布:公司域名申请 编辑:程序博客网 时间:2024/05/21 18:46

参考文档:https://developer.mozilla.org/en-US/docs/Simple_Firefox_build

Hardware requirements

Mozilla takes time to build. You need a development-class system:

  • A fast processor, ideally with several cores.  
  • More than 2 GB of RAM for recent Firefox builds, 4 GB or higher recommended. 至少2G内存,建议4G以上
  • 1.5 GB NTFS or 3 GB FAT disk space, or more  1.5G的磁盘空间,本人实际使用了5.33G
  • Windows Vista or later recommended (the build should work on Windows XP though). 系统要求,本人使用的是WIN7 64

Overview

The Mozilla build process requires many tools that are not installed on most Windows systems. In addition to Visual Studio, you must install MozillaBuild, which is a bundle of software including just the right versions of bash, GNU make, autoconf, Mercurial, and much more.

The Mozilla codebase works with the following compilers ("Official" means this is what we use for the builds we release as the Firefox product):

 VC8 (Visual Studio 2005)VC9 (Visual Studio 2008)VC10 (Visual Studio 2010)VC11 (Visual Studio 2012)FirefoxYesYesYes (Official)Yes

Note that installing both Visual Studio 2010 and Visual Studio 2012 on Windows 64-bit currently breaks the build. Also installing .NET Framework 4.5 when using Visual Studio 2010 breaks the builds. SeeBug 772989 Comments 15 and 17 on this, according to http://support.microsoft.com/kb/2757355 installing Visual Studio 2010 SP1 should fix this problem.

本人安装的是VC10SP1,刚开始安装的是VC10,发现编译报错。

Install build prerequisites

Complete each of these steps otherwise you may not be able to build successfully, there are notes on these software requirements below.

  1. Make sure your system is up-to-date through Windows Update. (Windows XP needs at leastService Pack 2 and.NET Framework 2.0.)
  2. You may need to install one or more Windows SDKs. See Windows SDK versions for a quick guide.
  3. Install the June 2010 DirectX SDK (even VS 2012 requires this).
  4. Install a version of Visual Studio that supports C++ development: VS 2012 for Windows Desktop Pro or Express (free), or VC++ 2010 Pro or Express (free).
  5. Install MozillaBuild, a package of additional build tools. (If you see a Windows error dialog giving you the option to re-install with the 'correct settings', choose that option and after that all should be well.) If you have cygwin installed read the note is the tips section.
  6. Add the folders with relevant .dlls to your PATH (in advanced system settings). When you get errors about missing .dll files, you will need to find the folder containing the dll and add it to the PATH environment variable.

Mozilla will not build if some of the tools are installed at a path that containsspaces or other breaking characters such as pluses, quotation marks, or meta characters. But the Visual C++ tools are an exception -- they may be installed in a directory which contains spaces, and the default install location is preferred.

本人NET Framework安装到4.5,Windows SDK v7.1版本,June 2010 DirectX SDK,MozillaBuild网上下载

Opening a Build Command Prompt

After the prerequisites are installed, launch one of the following batch files from thec:\mozilla-build directory:

  • start-msvc8.bat  (VS 2005)
  • start-msvc9.bat  (VS 2008)
  • start-msvc10.bat (VS 2010)
  • start-msvc11.bat (VS 2012)
Even if you are on 64-bit Windows, do not use the start-msvcX-x64.bat files (unless you know what you're doing). Those files areexperimental and unsupported. See the Build:MozillaBuild For x64 wiki page. 

This will launch a MSYS / BASH command prompt properly configured to build one of the aforementioned code bases. All further commands should be executed in this command prompt window. (Note that this is not the same as what you get with the Windows CMD.EXE shell).

This must be launched with administrator privileges. If you have User Account Control (UAC) turned on, it may not be granted automatically. Right click the .BAT file and select "Run as Administrator".

本人这边使用的是start-msvc10.bat (VS 2010)(windows CMD执行),这里不要使用start-msvc10-x64.bat,即使你的系统是64位的。

Create a directory for the source

Note: You won't be able to build the Firefox source code if it's under a directory with spaces in the path (e.g. don't use "Documents and Settings"). You can pick any other location, such as a new directory C:\mozilla-central

It's a sensible idea to create a new directory dedicated solely to the code.

cd /c; mkdir mozilla-source; cd mozilla-source

Now you are ready to get the Firefox source and build, continue on to Simple Firefox build (Get_the_source).

本人这边在D盘建了 D:\mozilla-central

Common problems, hints and restrictions

  • Debugging Mozilla on Windows FAQ: Tips on how to debug Mozilla on Windows.
  • Note that in Windows you need to build with Administrator privileges. If you have User Account Control (UAC) turned on, it may not automatically grant that to you.
  • The build may fail if your PATH environment variable contains quotes ("). Quotes are not properly translated when passed down to MozillaBuild sub-shells. Quotes are usually not needed so they can be removed.
  • The build may fail if you have a PYTHON environment variable set. You will see an error almost immediately that says "The system cannot find the file specified". In a cmd-shell typing "SET PYTHON=" before running mozilla build tools in that same shell should fix this.
  • The build may fail if you have cygwin installed. Make sure that the MozillaBuild directories (c:\mozilla-build and subdirectories) come before any cygwin directories in your PATH environment variable. If this does not help, remove the cygwin directories from PATH, or try building on a clean PC with no cygwin.
  • Building with versions of NSIS other than the version that comes with the latest supported version of MozillaBuild is not supported and will likely fail.
  • If you're building on VS2005 and the build fails with the error message "C2118: negative subscript" on win_util.cc, you need to install the VS2005 Service Pack 1. Furthermore, if you get "LNK1103: debugging information corrupt", try installing this hotfix:http://support.microsoft.com/kb/949009
  • If you intend to distribute your build to others, you will need to set WIN32_REDIST_DIR=$VCINSTALLDIR\redist\x86\Microsoft.VC80.CRT in your mozconfig to get the Microsoft CRT DLLs packaged along with the application.
  • The Microsoft Antimalware service can interfere with compilation, often manifesting as an error related toconftest.exe during build.  To remedy this, add at least your object directory to theexclusion settings.
  • If you encounter an error that atlbase.h cannot be found and you have installed Visual Studio 10 Express together with the platform SDK, you may have to delete a registry entry so that guess-msvc.bat doesn't detect VC10 installed. The key is HKLM\SOFTWARE\Microsoft\VisualStudio\10.0\Setup\VC.
  • If you encounter an error like "second C linkage of overloaded function '_interlockedbittestandset' not allowed", it happens when intrin.h and windows.h are included together. Use a #define to redefine one instance of the function's name. See more onusing intrin.h.

Warning: If you follow the below advice, your computer will not be protected against attacks that exploit this vulnerability. Make sure you take adequate precautions.

  • If you still get random crashes when running MAKE, you may be encountering interference from Windows Security Updates that prevent proper operation of the Bash shell on some Windows systems.  In this case, if you're on Windows XP, you will need to uninstall Windows XP Security Updates KB933729 and KB970238 using Add or Remove Programs from the Control Panel.  The first of these Security Updates is also incorporated into Windows XP Service Pack 3 (KB936929), so if you have already installed SP3 you'll need to uninstall it and then make sure that Service Pack 2, including all Windows updates (EXCEPT KB933729, KB936929 and KB970238) get installed.  To prevent these updates from being installed automatically, select "Notify me but don't automatically download or install them" in the Control Panel's "Automatic Updates" dialog.  Then de-select them when any of these items appear in the list of recommended updates, and when asked, indicate that you don't want to be asked about these de-selected updates in the future.
  • Parallel builds (-jN) do not work with GNU make on Windows. You need to use pymake instead.
本人:这边的注意点

1、如果已经安装过python,在执行mozilla build工具前需要在md-shell 执行"SET PYTHON=" 

2、把你项目的路径添加打 Microsoft Antimalware service排除文件路径列表中

3、在Windows 用GNU不支持参数Parallel builds (-jN)多线程编译,需要使用pymake替换make

     步骤:

      cd ~

      echo "alias pymake=C:/mozilla-central/build/pymake/make.py">>.profile

      重启服务

       pymake -f client.mk 

Get the source

Get the latest source code from Mozilla's Mercurial code repository. This may take a while; it's a lot of code!

hg clone https://hg.mozilla.org/mozilla-central
On some types of network connections, "hg clone" might fail because it gets interrupted.  If your "hg clone" command won't finish, try using aMercurial bundle instead.

这边是下载源码的路径

Build configuration (optional)

By default, the build system creates a release build of Firefox roughly equivalent to the official Firefox release builds. If that's not exactly what you want, there are many build configuration options to choose from, although it'sstrongly recommended that you only use options that you fully understand.

The normal way to specify build options is to place them in a file named .mozconfig at the root of your mozilla source tree (that is, directly under themozilla-central directory created by the hg clone command). The file name starts with a dot. On Windows, you can create the file from the MozillaBuild command-line:

cd /path/to/mozilla-centraltouch .mozconfig

For example, to create a debug build instead of a release build, that file would contain:

ac_add_options --enable-debug

For more on configuration options, see the page on configuring build options.

本人.mozconfig配置如下:

# Setup a basic mozconfig file
. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-ff-release
mk_add_options MOZ_MAKE_FLAGS="-j4"
# Build

Building

To start the build, cd into the mozilla-central subdirectory (created automatically by thehg clone command), and run:

./mach build

mach is our command-line tool to streamline common developer tasks. See the mach article for more.

Building can take a significant amount of time, depending on your system, OS and chosen build options. Linux builds on a fast box may take under 15 minutes, but Windows builds on a slow box may take several hours. Seetips for making builds faster.

Running

Various temporary files, libraries, and the Firefox executable will be found in yourobject directory (under mozilla-central/), which is prefixed withobj-. The exact name depends on your system and OS. For example, a Mac user may get an object directory name ofobj-x86_64-apple-darwin10.7.3/.

The Firefox executable in particular, and its dependencies, are located under thedist/bin folder under the object directory. To run the executable from yourmozilla-central working directory:

  • Windows: obj-.../dist/bin/firefox.exe
  • Linux: obj-.../dist/bin/firefox
  • OS X: obj-.../dist/Nightly.app/Contents/MacOS/firefox

How to update and build again

To pull the latest changes and update the code in your mozilla-central working directory, run the command:

hg pull -u

Then just re-run the mach command above. This will only recompile files that changed, but it's still a long haul. Anincremental build can be faster.


本人通过以上步骤成功编译






原创粉丝点击