# 编译firefox38全过程 firefox编译过程需时较久,建议在服务器上搭建最小环境进行编译。此处创建最小环境(4.2.41-20160506)。 挂载dev proc sys后,chroot到最小环境中。 编译流程:(在环境配置、源码、及依赖包均已准备就绪的情况下) ``` # 进入编译目录 cd gecko-dev # 添加及修改firefox自带编译配置 vi .mozconfig # 开始编译 ./mach build # 本地化包 # compare-locales easy_install -U compare-locales # build en_US package first cd obj-linux-unknow-linux-gnu make package # import zh_CN files cd obj-linux-unknow-linux-gnu/browser/locales make merge-zh-CN LOCALE_MERGEDIR=$(pwd)/mergedir # build zh_CN package make installers-zh-CN LOCALE_MEGEDIR=$(pwd)/mergedir # build zh-CN langpack not use make langpack-zh-CN LOCALE_MERGEDIR=$(pwd)/mergedir ``` ## 1 获取firefox源码 ### 1.1 浏览器代码库 公司内部git库镜像: ``` git@gitlab.rd.in.linx:mozilla/gecko-dev.git ``` 或者github上的git库只读镜像 ``` https://github.com/mozilla/gecko-dev.git ``` 或者官方hg代码库 ``` https://hg.mozilla.org/mozilla-central/ ``` 本次使用公司内部git库镜像,将master分支git clone下来后,选择切换到38版的最后一个esr版本。 切换到origin/GECKO3880esr_2016042017_RELBRANCH分支。 ``` git checkout -b GECKO3880esr origin/GECKO3880esr_2016042017_RELBRANCH ``` 注:GECKO38即为firefox38。 Fierfox有两种版本:普通版和ESR(Extended Support Release,延长支持)版。 ESR版本是Mozilla专门为那些无法或不愿每隔六周就升级一次的企业打造。Firefox ESR版的升级周期为42周。普通Firefox的升级周期为6周。 ### 1.2 汉化包支持 由于下载后,需要使用hg进行管理。 编译mercurial(hg的源码包)。 Mercurial requires Python 2.6 or later. 需安装python2.6或以上版本。 编译Python2.7.12编译安装到/usr/local下,配置环境变量后,可编译通过mercurial。本次配置直接将Python2.7和之后所述的gcc5.2相关环境配置添加到.bashrc中。 ``` export PATH=/usr/local/bin:$PATH export LD_LIBRARY_PATH=/usr/local/lib ``` 使用hg clone http://hg.mozilla.org/releases/l10n/mozilla-release/zh-CN 克隆下汉化包,然后切换到对应的分支。 查找对应firefox38esr的zh_CN ``` cd zh_CN hg tags | grep -i firefox | grep -i esr | grep 38 ``` ## 2 firefox编译配置 ### 2.1 配置文件.mozconfig 编译firefox之前,需要先配置firefox的编译配置(配置文件名称.mozconfig)。确定编译选项配置。 此处为编译使用的配置文件,拷贝到gecko-dev目录下即可。配置文件示例: ``` bash #!/bin/bash if [ "x$IS_NIGHTLY" = "xyes" ]; then # Some nightlies (eg: Mulet) don't want these set. MOZ_AUTOMATION_UPLOAD_SYMBOLS=${MOZ_AUTOMATION_UPLOAD_SYMBOLS-1} MOZ_AUTOMATION_UPDATE_PACKAGING=${MOZ_AUTOMATION_UPDATE_PACKAGING-1} MOZ_AUTOMATION_SDK=${MOZ_AUTOMATION_SDK-1} fi . "$topsrcdir/build/mozconfig.common" # some b2g desktop builds still happen on i686 machines, and the tooltool # toolchain is x86_64 only. # We also deal with valgrind builds here, they don't use tooltool manifests at # all yet. #if [ -z "$no_tooltool" ] #then # CC="$topsrcdir/gcc/bin/gcc" # CXX="$topsrcdir/gcc/bin/g++" # # # We want to make sure we use binutils and other binaries in the tooltool # # package. # mk_add_options PATH="$topsrcdir/gcc/bin:$PATH" #else # CC="/tools/gcc-4.7.3-0moz1/bin/gcc" # CXX="/tools/gcc-4.7.3-0moz1/bin/g++" #fi #禁用破解,禁止为节省几毫秒而减少二进制的大小 ac_add_options --disable-elf-hack #禁用编译选项pluseaudio ac_add_options --disable-pulseaudio # Avoid dependency on libstdc++ 4.7 ac_add_options --enable-stdcxx-compat #指定编译本地化汉化包目录 ac_add_options --with-l10n-base=$topsrcdir/../zh-CN ac_add_options --with-google-api-keyfile=/builds/gapi.data # 关闭升级 ac_add_options --disable-updater # 指定编译 firefox ac_add_options --enable-application=browser #add this application name will be firefox not nightly #avliable are #aurora #nightly #official #unofficial # 指定编译的版本 export MOZILLA_OFFICIAL=1 export MOZ_APP_DISPLAYNAME=firefox mk_add_options MOZ_MAKE_FLAGS="-j16" mk_add_options AUTOCONF=autoconf2.13 # $topsrcdir/gtk3 comes from tooltool, when the tooltool manifest contains it. if [ -d "$topsrcdir/gtk3" ]; then # PKG_CONFIG_LIBDIR is appropriately overridden in mozconfig.linux32 export PKG_CONFIG_LIBDIR=/usr/lib64/pkgconfig:/usr/share/pkgconfig export PKG_CONFIG_SYSROOT_DIR="$topsrcdir/gtk3" export PKG_CONFIG_PATH="$topsrcdir/gtk3/usr/local/lib/pkgconfig" export PATH="$topsrcdir/gtk3/usr/local/bin:${PATH}" # Ensure cairo, gdk-pixbuf, etc. are not taken from the system installed packages. LDFLAGS="-L$topsrcdir/gtk3/usr/local/lib" mk_add_options "export LD_LIBRARY_PATH=$topsrcdir/gtk3/usr/local/lib" ac_add_options --enable-default-toolkit=cairo-gtk3 fi export SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE=/builds/crash-stats-api.token mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@ #选择编译器2级优化. 在大多数情况下, 这个选项可能不会得到预期的结果, 除非你对 Mozilla 的代码非常了解. ac_add_options --enable-optimize=-O2 #使能调试宏和其它用于调试的代码. 这个选项会显著的拉长编译时间, 但是在写补丁程序的时候会非常有用 ac_add_options --enable-debug #在源码树上还有许多可选的代码, 这些代码放在 目录下. 许多扩展现在被认为使浏览器的一部分. 对每一个suit有一个默认的extetions清单,并且对每一个应用细节mozconfig都会指定一个不同的设置。一些extensions不是对每一个应用都是兼容的。举例说明:cookie 和thunderbird是不兼容的。typeaheadfind和任何toolkit应用都不兼容。除非你知道哪个extensions和哪个应用相兼容,否则不要用--enable-extensions选项;build系统将会为extensions自动的选择合适的设置. ac_add_options --enable-extensions=default #禁止编译pulseaudio相关 ac_add_options --disable-pulseaudio #禁止升级 ac_add_options --disable-updater # ac_add_options --enable-strip ac_add_options --enable-install-strip ac_add_options --enable-official-branding ac_add_options --enable-safe-browsing ac_add_options --enable-system-cairo ac_add_options --enable-system-ffi ac_add_options --enable-system-pixman ac_add_options --with-pthreads #启用ccache,便于编译调试 ac_add_options --with-ccache=/usr/bin/ccache ac_add_options --with-system-bz2 ac_add_options --with-system-zlib # Package js shell. export MOZ_PACKAGE_JSSHELL=1 . "$topsrcdir/build/mozconfig.common.override" ``` ### 2.2 配置ccache 由于firefox编译过程用时较长,建议配置ccache,可更快调试编译firefox。 首先配置环境变量: ``` export CCACHE_COMPRESS="" ``` 然后配置firefox编译配置文件.mozconfig,打开ccache配置选项。 ``` #启用ccache,便于编译调试 ac_add_options --with-ccache=/usr/bin/ccache ``` ## 3 编译过程及报错解决办法 此段详细记录了编译过程中遇到的报错及解决报错问题的方法。 ### 3.1 autoconf-2.13问题 准备好环境和源码包后 ``` linx:~/gecko-dev # ./mach build/ We're assuming the 'build/' command is 'build' and we're executing it for you. 0:00.73 /usr/bin/make -f client.mk -s 0:01.26 client.mk:201: /root/gecko-dev/obj-x86_64-unknown-linux-gnu/.mozconfig.mk: 没有那个文件或目录 0:01.73 Clobber not needed. 0:03.21 Adding client.mk options from : 0:03.21 MOZ_OBJDIR=/root/gecko-dev/obj-x86_64-unknown-linux-gnu 0:03.21 OBJDIR=/root/gecko-dev/obj-x86_64-unknown-linux-gnu 0:03.23 /root/gecko-dev/client.mk:304: *** Could not find autoconf 2.13。 停止。 0:03.23 make: *** [build] 错误 2 0:03.25 0 compiler warnings present. 0:03.25 Failed to parse ccache stats output: cache hit 0 linx:~/gecko-dev # ./mach build 0:00.31 /usr/bin/make -f client.mk -s 0:01.79 Adding client.mk options from : 0:01.79 MOZ_OBJDIR=/root/gecko-dev/obj-x86_64-unknown-linux-gnu 0:01.79 OBJDIR=/root/gecko-dev/obj-x86_64-unknown-linux-gnu 0:01.81 /root/gecko-dev/client.mk:304: *** Could not find autoconf 2.13。 停止。 0:01.81 make: *** [build] 错误 2 0:01.83 0 compiler warnings present. 0:01.84 Failed to parse ccache stats output: cache hit 0 linx:~/gecko-dev # ls build/ ``` 解决: 借鉴如下,网上资料: ``` wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.13.tar.gz tar -xvzf autoconf-2.13.tar.gz cd autoconf-2.13/ ./configure --program-suffix=2.13 make sudo make install You may need to export AUTOCONF=autoconf2.13 in your environment (e.g. put it in .profile in your home directory) or add this line to your .mozconfig file: ``` 修改为autoconf2.13进行编译,安装到/usr/local下,并在安装目录创建软链接 ln -s autoconf2.13 autoconf 在.mozconfig中配置autoconf2.13 ``` mk_add_options AUTOCONF=autoconf2.13 ``` ### 3.2 .mozconfig 里设置字体位置 ``` configure:1177: checking host system type 0:06.68 configure:1198: checking target system type 0:06.68 configure:1216: checking build system type 0:06.68 configure:1295: checking for mawk 0:06.68 configure:1295: checking for gawk 0:06.68 configure:1380: checking for python2.7 0:06.68 configure:1490: checking Python environment is Mozilla virtualenv 0:06.68 configure: error: Invalid value --with-l10n-base, /root/gecko-dev/../l10n-central doesn't exist 0:06.68 *** Fix above errors and then restart with\ 0:06.68 "/usr/bin/make -f client.mk build" 0:06.68 make[2]: *** [configure] Error 1 0:06.69 make[1]: *** [/root/gecko-dev/obj-x86_64-unknown-linux-gnu/Makefile] Error 2 0:06.69 make: *** [build] Error 2 0:06.72 0 compiler warnings present. 0:06.72 Failed to parse ccache stats output: cache hit 0 linx:~/gecko-dev # ls ``` 解决: 注意字体包目录的位置,以下为例:(gecko-dev在/root下,zh-CN在/root/zh-CN下) ``` linx:~/gecko-dev # pwd /root/gecko-dev linx:~/gecko-dev # cd ../zh-CN/zh-CN/ linx:~/zh-CN/zh-CN # pwd /root/zh-CN/zh-CN ``` 在.mozconfig中配置指定字体位置 ``` ac_add_options --with-l10n-base=$topsrcdir/../zh-CN ``` ### 3.3. gcc版本升级 ``` 0:04.04 configure:3787: checking for otool 0:04.04 configure: error: Only GCC 4.7 or newer supported 0:04.04 *** Fix above errors and then restart with\ 0:04.04 "/usr/bin/make -f client.mk build" 0:04.04 make[2]: *** [configure] Error 1 0:04.04 make[1]: *** [/root/gecko-dev/obj-x86_64-unknown-linux-gnu/Makefile] Error 2 0:04.04 make: *** [build] Error 2 0:04.09 0 compiler warnings present. 0:05.09 Failed to parse ccache stats output: cache hit ``` 解决: 由于有编译好的可用的gcc-5.2,故安装gcc-5.2。并配置环境变量。 安装gcc-5.2到/usr/lolcal下,需要配置环境变量。 ``` export PATH=/usr/local/gcc-5.2/bin:$PATH export LD_LIBRARY_PATH=/usr/local/gcc-5.2/lib64:$LD_LIBRARY_PATH ``` ### 3.4 libffi >= 3.0.9 (编译依赖,运行依赖) ``` 0:11.11 configure:15516: checking for BZ2_bzread in -lbz2 0:11.11 configure:15535: /usr/bin/ccache gcc -o conftest -std=gnu99 -fgnu89-inline -fno-strict-aliasing -ffunction-sections -fdata-sections -fno-math-errno -pthread -lpthread -Wl,-z,noexecstack -Wl,-z,text -Wl,--build-id conftest.c -lbz2 -ldl 1>&5 0:11.11 configure:15967: checking for pkg-config 0:11.11 configure:16011: checking for libffi >= 3.0.9 0:11.11 configure: error: Library requirements (libffi >= 3.0.9) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them. 0:11.11 *** Fix above errors and then restart with\ 0:11.11 "/usr/bin/make -f client.mk build" 0:11.11 make[2]: *** [configure] 错误 1 0:11.11 make[1]: *** [/root/gecko-dev/obj-x86_64-unknown-linux-gnu/Makefile] 错误 2 0:11.11 make: *** [build] 错误 2 0:11.14 0 compiler warnings present. 0:12.14 Failed to parse ccache stats output: cache hit 0 linx:~/gecko-dev # ``` 解决: 直接在当前最小环境下编译即可。 创建libffi目录,在目录下,下载源码libffi-3.2.1.tar.gz,然后mkpkgfile,再进行编译即可。 安装需要 -f 参数安装。 ``` linx:~/libffi # pkgadd libffi#3.2.1-x86_64-linx-Rocky4.2.pkg.tar.gz usr/lib64/libffi.a usr/lib64/libffi.la usr/lib64/libffi.so usr/share/info/dir pkgadd: listed file(s) already installed (use -f to ignore and overwrite) ``` ### 3.5 gtk-2.18 (编译依赖,运行依赖) ``` 0:09.46 configure:16018: checking MOZ_FFI_CFLAGS 0:09.46 configure:16023: checking MOZ_FFI_LIBS 0:09.46 configure:16236: checking for application to build 0:09.46 configure:16394: checking if app-specific confvars.sh exists 0:09.46 configure:17404: checking for gtk+-2.0 >= 2.18.0 gtk+-unix-print-2.0 glib-2.0 >= 2.22 gobject-2.0 gdk-x11-2.0 0:09.46 configure: error: Library requirements (gtk+-2.0 >= 2.18.0 gtk+-unix-print-2.0 glib-2.0 >= 2.22 gobject-2.0 gdk-x11-2.0) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them. 0:09.46 *** Fix above errors and then restart with\ 0:09.46 "/usr/bin/make -f client.mk build" 0:09.46 make[2]: *** [configure] 错误 1 0:09.46 make[1]: *** [/root/gecko-dev/obj-x86_64-unknown-linux-gnu/Makefile] 错误 2 0:09.46 make: *** [build] 错误 2 0:09.49 0 compiler warnings present. 0:10.49 Failed to parse ccache stats output: cache hit 45 linx:~/gecko-dev # ls ``` 需直接在当前环境下进行编译gtk2-2.18.9 注意需使用我们的applications.git库中的编译目录及方法进行。去掉Pkgfile中gtkclipboard.patch pkgadd -u gtk2... 安装。 注意:此包的lib64下的库文件,在最后打包firefox时,需要添加到firefox包中。 ### 3.6 pango >= 1.22.0(编译依赖,运行依赖) ``` 0:09.45 configure:17411: checking MOZ_GTK2_CFLAGS 0:09.45 configure:17416: checking MOZ_GTK2_LIBS 0:09.45 configure:18883: checking for pango >= 1.22.0 0:09.45 configure: error: Library requirements (pango >= 1.22.0) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them. 0:09.45 *** Fix above errors and then restart with\ 0:09.45 "/usr/bin/make -f client.mk build" 0:09.45 make[2]: *** [configure] 错误 1 0:09.45 make[1]: *** [/root/gecko-dev/obj-x86_64-unknown-linux-gnu/Makefile] 错误 2 0:09.45 make: *** [build] 错误 2 0:09.48 0 compiler warnings present. 0:10.49 Failed to parse ccache stats output: cache hit 90 linx:~/gecko-dev # pkginfo -i |grep pango ``` 此包编译方法与上述gtk2编译相同。此处编译pango-1.26.2 注意:此包的lib64下的库文件,在最后打包firefox时,需要添加到firefox包中。 ### 3.7 cairo >= 1.10 ``` 0:09.52 ------ config.log ------ 0:09.52 configure:26618: checking _FONTCONFIG_LIBS 0:09.52 configure:26764: checking for pixman-1 >= 0.19.2 0:09.52 configure:26771: checking PIXMAN_CFLAGS 0:09.53 configure:26776: checking PIXMAN_LIBS 0:09.53 configure:26817: checking for stdint.h 0:09.53 configure:26830: /usr/bin/ccache gcc -c -std=gnu99 -fgnu89-inline -fno-strict-aliasing -ffunction-sections -fdata-sections -fno-math-errno -pthread -pipe conftest.c 1>&5 0:09.53 configure:26817: checking for inttypes.h 0:09.53 configure:26830: /usr/bin/ccache gcc -c -std=gnu99 -fgnu89-inline -fno-strict-aliasing -ffunction-sections -fdata-sections -fno-math-errno -pthread -pipe conftest.c 1>&5 0:09.53 configure:26817: checking for sys/int_types.h 0:09.53 configure:26830: /usr/bin/ccache gcc -c -std=gnu99 -fgnu89-inline -fno-strict-aliasing -ffunction-sections -fdata-sections -fno-math-errno -pthread -pipe conftest.c 1>&5 0:09.53 configure:26824:27: fatal error: sys/int_types.h: No such file or directory 0:09.53 compilation terminated. 0:09.53 configure: failed program was: 0:09.53 #line 26822 "configure" 0:09.53 #include "confdefs.h" 0:09.53 0:09.53 #include 0:09.53 int main() { 0:09.53 0:09.53 ; return 0; } 0:09.53 configure:27084: checking for cairo >= 1.10 0:09.53 configure:27091: checking CAIRO_CFLAGS 0:09.53 configure:27096: checking CAIRO_LIBS 0:09.53 configure:27177: checking for cairo-tee >= 1.10 0:09.53 configure: error: Library requirements (cairo-tee >= 1.10) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them. 0:09.53 *** Fix above errors and then restart with\ 0:09.53 "/usr/bin/make -f client.mk build" 0:09.53 make[2]: *** [configure] Error 1 0:09.53 make[1]: *** [/root/gecko-dev/obj-x86_64-unknown-linux-gnu/Makefile] Error 2 0:09.53 make: *** [build] Error 2 0:09.54 0 compiler warnings present. 0:10.54 Failed to parse ccache stats output: cache hit 191 linx:~/gecko-dev # echo $PATH ``` 需在干净的虚拟机环境下编译此包,在编firefox的环境中编译失败。 使用git库中的cairo包即可,在configure的选项后添加"--enable-tee"进行编译。然后升级安装。 ### 3.8 需修改源码内容的编译失败报错 ``` 0:09.49 host_stdc++compat.o 0:09.80 /root/gecko-dev/build/unix/stdc++compat/stdc++compat.cpp:49:86: error: no member function '_S_construct_aux_2' declared in 'std::__cxx11::basic_string' 0:09.80 template char *string::_S_construct_aux_2(size_type, char, allocator const&); 0:09.80 ^ 0:09.80 /root/gecko-dev/build/unix/stdc++compat/stdc++compat.cpp:51:96: error: no member function '_S_construct_aux_2' declared in 'std::__cxx11::basic_string' 0:09.80 template wchar_t *wstring::_S_construct_aux_2(size_type, wchar_t, allocator const&); 0:09.80 ^ 0:09.88 In the directory /root/gecko-dev/obj-x86_64-unknown-linux-gnu/build/unix/stdc++compat 0:09.88 The following command failed to execute properly: 0:09.88 c++ -o host_stdc++compat.o -c -std=gnu++0x -MD -MP -MF .deps/host_stdc++compat.o.pp -DMOZ_LIBSTDCXX_VERSION=197653 -I/root/gecko-dev/build/unix/stdc++compat -I. -I../../../dist/include -I/root/gecko-dev/obj-x86_64-unknown-linux-gnu/dist/include/nspr /root/gecko-dev/build/unix/stdc++compat/stdc++compat.cpp 0:09.88 make[5]: *** [host_stdc++compat.o] Error 1 0:09.88 make[4]: *** [build/unix/stdc++compat/host] Error 2 0:09.88 make[3]: *** [export] Error 2 0:09.88 make[2]: *** [default] Error 2 0:09.88 make[1]: *** [realbuild] Error 2 0:09.88 make: *** [build] Error 2 0:09.93 0 compiler warnings present. 0:10.93 Failed to parse ccache stats output: cache hit 359 linx:~/gecko-dev # ``` 解决: 参考链接:https://bugzilla.mozilla.org/show_bug.cgi?id=1153109 修改方法 ``` diff --git a/configure.in b/configure.in index ef7a2b5..b529002 100644 --- a/configure.in +++ b/configure.in @@ -7431,6 +7431,8 @@ if test -n "$STDCXX_COMPAT"; then eval $(CXX="$CXX" HOST_CXX="$HOST_CXX" $PYTHON -m mozbuild.configure.libstdcxx) AC_SUBST(MOZ_LIBSTDCXX_TARGET_VERSION) AC_SUBST(MOZ_LIBSTDCXX_HOST_VERSION) + CXXFLAGS="$CXXFLAGS -D_GLIBCXX_USE_CXX11_ABI=0" + HOST_CXXFLAGS="$HOST_CXXFLAGS -D_GLIBCXX_USE_CXX11_ABI=0" fi dnl ======================================================== ``` ### 3.9 需修改源码内容的编译失败报错 ``` 0:21.89 In file included from /root/gecko-dev/obj-x86_64-unknown-linux-gnu/tools/profiler/Unified_cpp_tools_profiler0.cpp:56:0: 0:21.89 /root/gecko-dev/tools/profiler/LulElf.cpp: In function 'bool lul::ElfClassBuildIDNoteIdentifier(const void*, int, uint8_t*)': 0:21.89 /root/gecko-dev/tools/profiler/LulElf.cpp:923:32: error: 'NT_GNU_BUILD_ID' was not declared in this scope 0:21.89 if (note_header->n_type == NT_GNU_BUILD_ID) 0:21.89 ^ 0:21.90 In the directory /root/gecko-dev/obj-x86_64-unknown-linux-gnu/tools/profiler 0:21.90 The following command failed to execute properly: 0:21.91 /usr/bin/ccache c++ -o Unified_cpp_tools_profiler0.o -c -I../../dist/stl_wrappers -I../../dist/system_wrappers -include /root/gecko-dev/config/gcc_hidden.h -DSTATIC_EXPORTABLE_JS_API -DMOZILLA_INTERNAL_API -DIMPL_LIBXUL -DMOZ_GLUE_IN_PROGRAM -DAB_CD=en-US -DNO_NSPR_10_SUPPORT -I/root/gecko-dev/tools/profiler -I. -I/root/gecko-dev/docshell/base -I/root/gecko-dev/ipc/chromium/src -I/root/gecko-dev/mozglue/linker -I/root/gecko-dev/toolkit/crashreporter/google-breakpad/src -I/root/gecko-dev/xpcom/base -I../../dist/include -I/root/gecko-dev/obj-x86_64-unknown-linux-gnu/dist/include/nspr -I/root/gecko-dev/obj-x86_64-unknown-linux-gnu/dist/include/nss -I/usr/include/pixman-1 -fPIC -DMOZILLA_CLIENT -include ../../mozilla-config.h -MD -MP -MF .deps/Unified_cpp_tools_profiler0.o.pp -Wall -Wempty-body -Woverloaded-virtual -Wsign-compare -Wwrite-strings -Wno-invalid-offsetof -Wcast-align -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -fno-math-errno -std=gnu++0x -pthread -D_GLIBCXX_USE_CXX11_ABI=0 -pipe -DDEBUG -DTRACING -g -O2 -fno-omit-frame-pointer /root/gecko-dev/obj-x86_64-unknown-linux-gnu/tools/profiler/Unified_cpp_tools_profiler0.cpp 0:21.91 make[5]: *** [Unified_cpp_tools_profiler0.o] Error 1 0:21.91 make[4]: *** [tools/profiler/target] Error 2 0:21.91 make[4]: *** Waiting for unfinished jobs.... ``` 解决: 修改方法 ``` --- a/tools/profiler/LulElf.cpp +++ b/tools/profiler/LulElf.cpp @@ -899,6 +899,10 @@ bool FindElfSegment(const void *elf_mapped_base, return false; } +#ifndef NT_GNU_BUILD_ID +# define NT_GNU_BUILD_ID 3 +#endif + // (derived from) // file_id.cc: Return a unique identifier for a file ``` ### 3.10 需修改源码内容的编译失败报错 ``` 0:17.35 cd params; /usr/bin/make libs 0:17.35 /root/gecko-dev/security/sandbox/linux/Sandbox.cpp: In function 'void mozilla::SetMediaPluginSandbox(const char*)': 0:17.35 /root/gecko-dev/security/sandbox/linux/Sandbox.cpp:463:54: error: 'O_CLOEXEC' was not declared in this scope 0:17.36 gMediaPluginFileDesc = open(aFilePath, O_RDONLY | O_CLOEXEC); 0:17.36 ^ 0:17.37 In the directory /root/gecko-dev/obj-x86_64-unknown-linux-gnu/security/sandbox/linux 0:17.37 The following command failed to execute properly: 0:17.37 /usr/bin/ccache c++ -o Sandbox.o -c -I../../../dist/system_wrappers -include /root/gecko-dev/config/gcc_hidden.h -DNS_NO_XPCOM -DMOZ_GLUE_IN_PROGRAM -DAB_CD=en-US -DNO_NSPR_10_SUPPORT -I/root/gecko-dev/security/sandbox/linux -I. -I/root/gecko-dev/security/sandbox/chromium-shim -I/root/gecko-dev/security/sandbox/chromium -I/root/gecko-dev/nsprpub -I../../../dist/include -I/root/gecko-dev/obj-x86_64-unknown-linux-gnu/dist/include/nspr -I/root/gecko-dev/obj-x86_64-unknown-linux-gnu/dist/include/nss -I/usr/include/pixman-1 -fPIC -DMOZILLA_CLIENT -include ../../../mozilla-config.h -MD -MP -MF .deps/Sandbox.o.pp -Wall -Wempty-body -Woverloaded-virtual -Wsign-compare -Wwrite-strings -Wno-invalid-offsetof -Wcast-align -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -fno-math-errno -std=gnu++0x -pthread -D_GLIBCXX_USE_CXX11_ABI=0 -pipe -DDEBUG -DTRACING -g -O2 -fno-omit-frame-pointer /root/gecko-dev/security/sandbox/linux/Sandbox.cpp 0:17.37 make[5]: *** [Sandbox.o] Error 1 0:17.37 make[4]: *** [security/sandbox/linux/target] Error 2 0:17.37 make[4]: *** Waiting for unfinished jobs.... ``` 解决: 修改方法 ``` --- a/security/sandbox/linux/Sandbox.cpp +++ b/security/sandbox/linux/Sandbox.cpp @@ -32,6 +32,10 @@ #include "sandbox/linux/services/android_ucontext.h" #endif +#ifndef O_CLOEXEC +#define O_CLOEXEC 0x1000000 +#endif + #ifdef MOZ_ASAN // Copy libsanitizer declarations to avoid depending on ASAN headers. // See also bug 1081242 comment #4. ``` ### 3.11 升级binutils到2.21以及升级libtool-2.4.6 ``` 0:11.63 /root/gecko-dev/config/rules.mk:1512: warning: overriding commands for target `../../../dist/bin/modules/LoginManagerParent.jsm' 0:11.63 /root/gecko-dev/config/rules.mk:1447: warning: ignoring old commands for target `../../../dist/bin/modules/LoginManagerParent.jsm' 0:15.16 make[6]: warning: -jN forced in submake: disabling jobserver mode. 0:15.16 Note: rebuild with "/usr/bin/make VERBOSE=1 " to show all compiler parameters. 0:15.17 /usr/bin/make[6]: Making `all' in `stubdata' 0:15.17 /usr/bin/make[6]: Making `all' in `common' 0:15.24 /usr/bin/make[6]: Making `all' in `i18n' 0:15.34 /usr/bin/make[6]: Making `all' in `tools' 0:15.35 /usr/bin/make[7]: Making `all' in `toolutil' 0:15.37 /usr/bin/make[7]: Making `all' in `ctestfw' 0:15.38 /usr/bin/make[7]: Making `all' in `makeconv' 0:15.39 /usr/bin/make[7]: Making `all' in `genrb' 0:15.41 /usr/bin/make[7]: Making `all' in `genbrk' 0:15.42 /usr/bin/make[7]: Making `all' in `gencnval' 0:15.43 /usr/bin/make[7]: Making `all' in `gensprep' 0:15.43 /usr/bin/make[7]: Making `all' in `icuinfo' 0:15.45 /usr/bin/make[7]: Making `all' in `genccode' 0:15.45 /usr/bin/make[7]: Making `all' in `gencmn' 0:15.46 /usr/bin/make[7]: Making `all' in `icupkg' 0:15.47 /usr/bin/make[7]: Making `all' in `pkgdata' 0:15.48 /usr/bin/make[7]: Making `all' in `gentest' 0:15.48 /usr/bin/make[7]: Making `all' in `gennorm2' 0:15.49 /usr/bin/make[7]: Making `all' in `gencfu' 0:15.50 /usr/bin/make[7]: Making `all' in `gendict' 0:15.52 /usr/bin/make[6]: Making `all' in `data' 0:15.65 SkBlitRow_opts_SSE4_x64_asm.o 0:15.66 SkBitmapProcState_matrixProcs.o 0:15.67 SkBlitter_A8.o 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S: Assembler messages: 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:103: Error: suffix or operands invalid for `pblendvb' 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:132: Error: suffix or operands invalid for `pblendvb' 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:184: Error: suffix or operands invalid for `pblendvb' 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:225: Error: suffix or operands invalid for `pblendvb' 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:289: Error: suffix or operands invalid for `pblendvb' 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:314: Error: suffix or operands invalid for `pblendvb' 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:350: Error: suffix or operands invalid for `pblendvb' 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:387: Error: suffix or operands invalid for `pblendvb' 0:15.68 SkBlitter_ARGB32.o 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:412: Error: suffix or operands invalid for `pblendvb' 0:15.68 /root/gecko-dev/gfx/skia/trunk/src/opts/SkBlitRow_opts_SSE4_x64_asm.S:448: Error: suffix or operands invalid for `pblendvb' 0:15.68 make[5]: *** [SkBlitRow_opts_SSE4_x64_asm.o] Error 1 0:15.68 make[5]: *** Waiting for unfinished jobs.... ``` 解决: 升级binutils和libtool。 编译binutils-2.21到/usr/local/下,改名为binutils2.11#2.11-...tar.gz libtool-2.4.6直接在本环境下mkpkgfile然后pkgmk编译即可。 ### 3.12 编译完成 综上,成功编译完成。 ## 4 打包及本地化 编译完成后,需先将编译结果打包成en_US版firefox,然后再将其添加zh_CN并打包成zh_CN版的firefox包,最后需将包解压并修改启动文件库和替换gtk/pango的库,打包制作成我们的pkg包。 ## 4.1 打包en_US版firefox ### 4.1.1 compare-locales ``` easy_install -U compare-locales ``` 默认会使用Python2.5对应的easy_install,但是本环境配置使用Python2.7,故需在本环境配置下,重新编译python-setuptools。即,使用applications库中的源码在本环境下编译即可,注意需修改包名并将其编译安装到/usr/local下。 由于执行easy_install连接不到python的官网,故手动编译compare-locales安装包。在本环境下,下载compare-locales-1.0,然后mkpkgfile,在Pkgfile中python setup.py install指定编译安装到/usr/local中。 安装python-setuptools和compare-locales后,执行如下: ``` linx:~/python-setuptools # easy_install -U compare-locales Searching for compare-locales Reading http://pypi.python.org/simple/compare-locales/ Download error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) -- Some packages may not be found! Reading http://pypi.python.org/simple/compare-locales/ Download error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) -- Some packages may not be found! Couldn't retrieve index page for 'compare-locales' Scanning index of all packages (this may take a while) Reading http://pypi.python.org/simple/ Download error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) -- Some packages may not be found! Best match: compare-locales 1.0 Adding compare-locales 1.0 to easy-install.pth file Installing compare-web-app script to /usr/local/bin Installing compare-dirs script to /usr/local/bin Installing compare-locales script to /usr/local/bin Using /usr/local/lib/python2.7/site-packages Processing dependencies for compare-locales Finished processing dependencies for compare-locales linx:~/python-setuptools # ``` ### 4.1.2 生成en_US版firefox 执行如下命令,打包。 ``` cd obj-x86_64-unknown-linux-gnu make package ``` 执行过后,在obj-x86_64-unknown-linux-gnu/dist中会生成firefox-38.8.0.en-US.linux-x86_64.tar.bz2,但是查看发现此包大小不对,打包失败。当前目录下已经生成firefox的目录。 查看make package的打包过程。找到如下打包命令: ``` cd ../../dist && (cd firefox && /root/gecko-dev/obj-x86_64-unknown-linux-gnu/_virtualenv/bin/python /root/gecko-dev/config/createprecomplete.py) && gnutar -c --owner=0 --group=0 --numeric-owner --mode=go-w --exclude=.mkdir.done -f - firefox | bzip2 -vf > firefox-38.8.0.en-US.linux-x86_64.tar.bz2 # ``` 即,打包使用的是gnutar的命令。此命令打包失败。备份此命令,然后创建软件接指向tar命令,然后重新打包。 ``` mv /bin/gnutar{,.bak} ln -s /bin/tar /bin/gnutar cd obj-x86_64-unknown-linux-gnu make package ``` 打包成功。 ## 4.2 制作zh_CN版firefox 打包en_US后,即可打包制作zh_CN版。执行如下: ``` cd obj-x86_64-unknown-linux-gnu/browser/locales #import zh-CN files make merge-zh-CN LOCALE_MERGEDIR=$(pwd)/mergedir #build zh-CN package make installers-zh-CN LOCALE_MERGEDIR=$(pwd)/mergedir #build zh-CN langpack not use make langpack-zh-CN LOCALE_MERGEDIR=$(pwd)/mergedir ``` 此处,制作过程中曾出现报错,原因时easy_install那一步寻找使用的python2.5中的模块,导致此时报错,如下: ``` linx:~/gecko-dev/obj-x86_64-unknown-linux-gnu/browser/locales # make merge-zh-CN LOCALE_MERGEDIR=$(pwd)/mergedir rm -f -rf /root/gecko-dev/obj-x86_64-unknown-linux-gnu/browser/locales/mergedir MACOSX_DEPLOYMENT_TARGET= compare-locales -m /root/gecko-dev/obj-x86_64-unknown-linux-gnu/browser/locales/mergedir /root/gecko-dev/browser/locales/l10n.ini /root/zh-CN zh-CN Traceback (most recent call last): File "/usr/bin/compare-locales", line 8, in load_entry_point('compare-locales==1.0', 'console_scripts', 'compare-locales')() File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 277, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 2180, in load_entry_point return ep.load() File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 1913, in load entry = __import__(self.module_name, globals(),globals(), ['__name__']) File "/usr/lib/python2.5/commands.py", line 11, in A trailing newline is removed from the output string. File "build/bdist.linux-x86_64/egg/compare_locales/compare.py", line 18, in ImportError: No module named simplejson make: *** [merge-zh-CN] Error 1 linx:~/gecko-dev/obj-x86_64-unknown-linux-gnu/browser/locales # make merge zh-CN LOCALE_MERGEDIR=$(pwd)/mergedir make: *** No rule to make target `merge'. Stop. linx:~/gecko-dev/obj-x86_64-unknown-linux-gnu/browser/locales # ``` 解决,即如4.1.1所述,进行修改。 ## 4.3 测试并制作rocky6.0.42系统的firefox38安装包 制作完成zh_CN版的firefox后,接下来就可以整理打包成我们的rocky6.0.42系统中的安装包。 我们接下来要用到的包及库等内容有: 1.firefox—zh_CN编译完成包:firefox-38.8.0.zh-CN.linux-x86_64.tar.bz2 2.在编译过程中需要的依赖包(同时是运行依赖的包):libffi gtk2 pango ### 4.3.1 添加运行依赖库并测试运行 解压firefox-38.8.0.zh-CN.linux-x86_64.tar.bz2到20160513版测试虚拟机的root下。 添加运行依赖库,在解压后的目录firefox中创建新目录lib,分别拷贝libffi-3.2.1/gtk2-2.18.9/pango-1.26.2的/usr/lib64/下的*.a/*.so库文件到firefox/lib下。使用如下命令拷贝软链接: ``` rsync -l lib firefox/ ``` 修改firefox启动脚本中的运行依赖库,修改firefox/run-mozilla.sh ``` --- run-mozilla.sh~ 2016-10-20 13:25:33.000000000 +0800 +++ run-mozilla.sh 2016-11-02 13:36:03.000000000 +0800 @@ -276,7 +276,7 @@ moz_should_set_ld_library_path() } if moz_should_set_ld_library_path then - LD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"} + LD_LIBRARY_PATH=${MOZ_DIST_BIN}/lib:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"} fi if [ -n "$LD_LIBRARYN32_PATH" ] ``` 然后可以运行./run-mozilla.sh ./firefox启动测试,并测试输入中文可用。 ### 4.3.2 制作rocky6.0.42系统安装包 创建工作目录work,然后首先在其中创建opt目录,并将4.3.1修改过的目录firefox放到opt目录下。 然后,创建如下所需目录:注意此处只是需要创建目录,文件在后续会有说明。 ``` etc/ etc/ld.so.conf.d etc/ld.so.conf.d/firefox.ld.conf opt/ opt/firefox/ ... ... usr/ usr/bin usr/bin/firefox usr/share usr/share/applications usr/share/applications/firefox.desktop usr/lib usr/lib/mozilla usr/lib/mozilla/plugins usr/lib/mozilla/plugins/libnpjp2.so var/ var/lib var/lib/pkg var/lib/pkg/firefox.post_add ``` firefox.ld.conf依赖库配置: ``` #cat etc/ld.so.conf.d/firefox.ld.conf /opt/firefox ``` firefox启动命令,菜单软链接启动项及软链接库创建 ``` linx:~/work/$ cat usr/bin/firefox #!/bin/bash /opt/firefox/run-mozilla.sh /opt/firefox/firefox linx:~/work/$ ls -l usr/lib/mozilla/plugins/libnpjp2.so lrwxrwxrwx 1 sxx sxx 40 5月 13 14:04 usr/lib/mozilla/plugins/libnpjp2.so -> /usr/lib64/jdk/jre/lib/amd64/libnpjp2.so linx:~/work/$ cat usr/share/applications/firefox.desktop [Desktop Entry] Encoding=UTF-8 Name=Mozilla Firefox 40.0.3 Comment=Web Browser Exec=/opt/firefox/run-mozilla.sh /opt/firefox/firefox Icon=/opt/firefox/browser/icons/mozicon128.png Terminal=false Type=Application Categories=Application;Network; ``` 还需添加安装包的安装后执行的ldconfig ``` linx:~/work/$ cat var/lib/pkg/firefox.post_add #!/bin/bash ldconfig ``` 按以上配置修改后,查看文件的属组及权限,并进行打包。 1.添加的脚本需要运行权限。 2.work目录下的各文件属组均为root.root 3.特别注意:因work目录下的所有文件会安装到系统的/目录下,故注意在work目录下执行ls -la时"."".."两个的属组为root.root权限均为755。 最后,可以在work目录下执行打包命令: ``` tar cfz ../firefox#38.8.0-x86_64-linx-Rocky4.3.pkg.tar.gz ./* ``` ## 5 结束 最后获得的firefox#38.8.0-x86_64-linx-Rocky4.3.pkg.tar.gz安装包可直接用pkgadd命令进行安装。