Cross-Compiling Mozilla

  • Revision slug: Cross-Compiling_Mozilla
  • Revision title: Cross-Compiling Mozilla
  • Revision id: 57759
  • Created:
  • Creator: GavinSharp
  • Is current revision? No
  • Comment one or more formatting changes

Revision Content

For information on cross-compiling in general, see the chapter titled Cross Compilation Tools in The GNU configure and build system document.

If you are trying to compile 32-bit Firefox on a 64-bit Linux OS, you don't need to do a full cross-compile... see these simpler instructions.

Setting up a cross-compilation build environment

This isn't the end-all-be-all guide to setting up a cross-compilation build environment. WFM; YMMV. (If you have to ask "where do I get... or why doesn't 'X' work", then this isn't for you.)

For all of these examples, the following definitions are used:

xtarget_arch name of the target system (e.g., i686-linux)
xprefix location of cross-compilation directory heiarchy (e.g. /usr/sparc-linux)

You should add ${xprefix}/bin to your PATH.

Cross-compile binutils

Download binutils and apply the binutils-cross-libpath.patch, which will make installing prebuilt libraries easier. Run configure using the following command:

env CROSS_LIB_PATH="${xprefix}/${xtarget_arch}/lib:${xprefix}/${xtarget_arch}/usr/lib" ./configure --prefix=${xprefix} --target=${xtarget_arch}

Build and install the package on the system.

Install target system headers and libraries

GCC and binutils will expect to find the system headers and libraries under ${xprefix}/${xtarget_arch} so you will need to copy those files from the target system, preserving directory structure and modify any scripts as necessary. You should copy over the X11 lib and include dirs as well.

{{ Note("If your target system uses glibc, you must take special care to modify the local copy of the target\'s /usr/lib/libc.so file (which is actually a script) so that it looks for its files under $xprefix/$target_arch rather than /usr.") }}

If you already have rpms for the target system and rpm installed on the build system, then you can use this shortcut script which should install the rpms into $xprefix/$xtarget_arch using rpm2cpio.

Also, if you use Debian or Ubuntu, you can use dpkg-cross or apt-cross to install the headers and libraries for target system.

Cross-compile gcc

Download gcc and run configure with the following command:

./configure --prefix=${xprefix} --with-gnu-ld --with-gnu-as --target=${xtarget_arch} --disable-nls --enable-languages=c++,objc

Build and install the package on the system.

Verification

At this point, your cross-compilation environment should be completely set up. You should verify that it works. Start with Hello World and work your way up to a basic X11-based application.

For most packages, ./configure --target=${xtarget_arch} should be sufficient to build.

For others, you may have to explicitly set the build tools:

env AR=${xtarget_arch}-ar CC=${xtarget_arch}-gcc CXX=${xtarget_arch}-g++ LD=${xtarget_arch}-ld AS=${xtarget_arch}-as ./configure --prefix=${xprefix} --target=${xtarget_arch}

Cross-compile glib, libIDL & gtk+

This step is only necessary if you did not install pre-built versions of these packages. Use the steps outlined above to build and install them.

Cross-compiling the lizard

Assuming that you properly setup your cross-compilation build environment as outlined above, cross-compiling Mozilla is fairly straightforward although NSS isn't properly setup to cross-compile ({{ Bug("104541") }}).

The main thing to remember is that when --target=${xtarget_arch} is passed to configure, configure expects to find the compiler toolchain as ${xtarget_arch}-TOOL where TOOL is gcc, g++, ranlib, etc.

You must pass the following environment arguments to configure:

CROSS_COMPILE=1
HOST_LIBIDL_CONFIG='libIDL-config-2 --prefix=/path/to/build/system'
HOST_LIBIDL_CFLAGS='-I/path/to/build/system/include/libIDL-2.0 -I/path/to/build/system/include/glib-2.0 -I/path/to/build/system/include'
HOST_LIBIDL_LIBS='-L/path/to/build/system/lib -lIDL-2 -lglib-2.0'
LIBIDL_CONFIG='libIDL-config-2 --prefix=/path/to/target/system'
export PKG_CONFIG_PATH=/path/to/target/system/lib/pkgconfig

and the follwing command line arguments to configure:

--target=${xtarget_arch}

Here's a sample mozconfig file used to cross-compile to the mipsEEel-linux target:

# sh
# Build configuration script
#
# See http://www.mozilla.org/build/unix.html for build instructions.
#
CROSS_COMPILE=1
HOST_LIBIDL_CONFIG='/usr/bin/libIDL-config-2 --prefix=/usr'
HOST_LIBIDL_CFLAGS='-I/usr/include/libIDL-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include'
HOST_LIBIDL_LIBS='-L/usr/lib -lIDL-2 -lglib-2.0'
LIBIDL_CONFIG='/usr/bin/libIDL-config-2 --prefix=/usr/mipsEEel-linux'
export PKG_CONFIG_PATH=/usr/mipsEEel-linux/lib/pkgconfig

# don't use pkg-config for host libIDL
ac_add_options --without-libIDL
ac_add_options --prefix=/usr/mipsEEel-linux
ac_add_options --target=mipsEEel-linux

# Options for 'configure' (same as command-line options). 
# all are listed so that one can manually tweak this config file.
ac_add_options --enable-application=browser
ac_add_options --enable-mathml
ac_add_options --enable-extensions
#ac_add_options --enable-crypto
ac_add_options --enable-logrefcnt

ac_add_options --without-system-nspr
ac_add_options --without-system-zlib
ac_add_options --without-system-jpeg
ac_add_options --without-system-png

Original Document Information

  • Author(s): Chris Seawood
  • Last Updated Date: June 22, 2002
  • Copyright Information: Portions of this content are © 1998–2007 by individual mozilla.org contributors; content available under a Creative Commons license | Details.

{{ languages( { "ja": "ja/Cross-Compiling_Mozilla" } ) }}

Revision Source

<p>For information on cross-compiling in general, see the chapter titled <a class="external" href="http://www.airs.com/ian/configure/configure_5.html#SEC28">Cross Compilation Tools</a> in <a class="external" href="http://www.airs.com/ian/configure/">The GNU configure and build system</a> document.</p>
<p>If you are trying to compile 32-bit Firefox on a 64-bit Linux OS, you don't need to do a full cross-compile... see <a href="/en/Compiling_32-bit_Firefox_on_a_Linux_64-bit_OS" title="en/Compiling_32-bit_Firefox_on_a_Linux_64-bit_OS">these simpler instructions</a>.</p>
<h3 id="Setting_up_a_cross-compilation_build_environment" name="Setting_up_a_cross-compilation_build_environment">Setting up a cross-compilation build environment</h3>
<p>This isn't the end-all-be-all guide to setting up a cross-compilation build environment. WFM; YMMV. (If you have to ask "where do I get... or why doesn't 'X' work", then this isn't for you.)</p>
<p>For all of these examples, the following definitions are used:</p>
<table> <tbody> <tr> <td><strong><code>xtarget_arch</code></strong></td> <td>name of the target system (e.g., i686-linux)</td> </tr> <tr> <td><strong><code>xprefix</code></strong></td> <td>location of cross-compilation directory heiarchy (e.g. /usr/sparc-linux)</td> </tr> </tbody>
</table>
<p>You should add <code>${xprefix}/bin</code> to your PATH.</p>
<h4 id="Cross-compile_binutils" name="Cross-compile_binutils">Cross-compile binutils</h4>
<p>Download binutils and apply the <a class="external" href="http://www.mozilla.org/build/binutils-cross-libpath.patch">binutils-cross-libpath.patch</a>, which will make installing prebuilt libraries easier. Run configure using the following command:</p>
<pre class="eval">env CROSS_LIB_PATH="${xprefix}/${xtarget_arch}/lib:${xprefix}/${xtarget_arch}/usr/lib" ./configure --prefix=${xprefix} --target=${xtarget_arch}
</pre>
<p>Build and install the package on the system.</p>
<h4 id="Install_target_system_headers_and_libraries" name="Install_target_system_headers_and_libraries">Install target system headers and libraries</h4>
<p>GCC and binutils will expect to find the system headers and libraries under ${xprefix}/${xtarget_arch} so you will need to copy those files from the target system, preserving directory structure and modify any scripts as necessary. You should copy over the X11 lib and include dirs as well.</p>
<p>{{ Note("If your target system uses glibc, you must take special care to modify the local copy of the target\'s <code>/usr/lib/libc.so</code> file (which is actually a script) so that it looks for its files under $xprefix/$target_arch rather than /usr.") }}</p>
<p>If you already have rpms for the target system and rpm installed on the build system, then you can use this <a class="external" href="http://www.mozilla.org/build/setup-xrpms.sh.txt">shortcut script</a> which should install the rpms into $xprefix/$xtarget_arch using rpm2cpio.</p>
<p>Also, if you use Debian or Ubuntu, you can use dpkg-cross or apt-cross to install the headers and libraries for target system.</p>
<h4 id="Cross-compile_gcc" name="Cross-compile_gcc">Cross-compile gcc</h4>
<p>Download gcc and run configure with the following command:</p>
<pre class="eval">./configure --prefix=${xprefix} --with-gnu-ld --with-gnu-as --target=${xtarget_arch} --disable-nls --enable-languages=c++,objc
</pre>
<p>Build and install the package on the system.</p>
<h4 id="Verification" name="Verification">Verification</h4>
<p>At this point, your cross-compilation environment should be completely set up. You should verify that it works. Start with <a class="link-ftp" href="ftp://ftp.gnu.org/gnu/hello/">Hello World</a> and work your way up to a basic X11-based application.</p>
<p>For most packages, <code>./configure --target=${xtarget_arch}</code> should be sufficient to build.</p>
<p>For others, you may have to explicitly set the build tools:</p>
<pre class="eval">env AR=${xtarget_arch}-ar CC=${xtarget_arch}-gcc CXX=${xtarget_arch}-g++ LD=${xtarget_arch}-ld AS=${xtarget_arch}-as ./configure --prefix=${xprefix} --target=${xtarget_arch}
</pre>
<h4 id="Cross-compile_glib.2C_libIDL_&amp;_gtk.2B" name="Cross-compile_glib.2C_libIDL_&amp;_gtk.2B">Cross-compile glib, libIDL &amp; gtk+</h4>
<p>This step is only necessary if you did not install pre-built versions of these packages. Use the steps outlined above to build and install them.</p>
<h3 id="Cross-compiling_the_lizard" name="Cross-compiling_the_lizard">Cross-compiling the lizard</h3>
<p>Assuming that you properly setup your cross-compilation build environment as outlined above, cross-compiling Mozilla is fairly straightforward although NSS isn't properly setup to cross-compile ({{ Bug("104541") }}).</p>
<p>The main thing to remember is that when --target=${xtarget_arch} is passed to configure, configure expects to find the compiler toolchain as ${xtarget_arch}-TOOL where TOOL is gcc, g++, ranlib, etc.</p>
<p>You must pass the following environment arguments to configure:</p>
<pre>CROSS_COMPILE=1
HOST_LIBIDL_CONFIG='libIDL-config-2 --prefix=/path/to/build/system'
HOST_LIBIDL_CFLAGS='-I/path/to/build/system/include/libIDL-2.0 -I/path/to/build/system/include/glib-2.0 -I/path/to/build/system/include'
HOST_LIBIDL_LIBS='-L/path/to/build/system/lib -lIDL-2 -lglib-2.0'
LIBIDL_CONFIG='libIDL-config-2 --prefix=/path/to/target/system'
export PKG_CONFIG_PATH=/path/to/target/system/lib/pkgconfig
</pre>
<p>and the follwing command line arguments to configure:</p>
<pre>--target=${xtarget_arch}
</pre>
<p>Here's a sample <span class="external">mozconfig</span> file used to cross-compile to the mipsEEel-linux target:</p>
<pre># sh
# Build configuration script
#
# See http://www.mozilla.org/build/unix.html for build instructions.
#
CROSS_COMPILE=1
HOST_LIBIDL_CONFIG='/usr/bin/libIDL-config-2 --prefix=/usr'
HOST_LIBIDL_CFLAGS='-I/usr/include/libIDL-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include'
HOST_LIBIDL_LIBS='-L/usr/lib -lIDL-2 -lglib-2.0'
LIBIDL_CONFIG='/usr/bin/libIDL-config-2 --prefix=/usr/mipsEEel-linux'
export PKG_CONFIG_PATH=/usr/mipsEEel-linux/lib/pkgconfig

# don't use pkg-config for host libIDL
ac_add_options --without-libIDL
ac_add_options --prefix=/usr/mipsEEel-linux
ac_add_options --target=mipsEEel-linux

# Options for 'configure' (same as command-line options). 
# all are listed so that one can manually tweak this config file.
ac_add_options --enable-application=browser
ac_add_options --enable-mathml
ac_add_options --enable-extensions
#ac_add_options --enable-crypto
ac_add_options --enable-logrefcnt

ac_add_options --without-system-nspr
ac_add_options --without-system-zlib
ac_add_options --without-system-jpeg
ac_add_options --without-system-png
</pre>
<div class="originaldocinfo"> <h2 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h2> <ul> <li>Author(s): <a class="link-mailto" href="mailto:seawood@netscape.com">Chris Seawood</a></li> <li>Last Updated Date: June 22, 2002</li> <li>Copyright Information: Portions of this content are © 1998–2007 by individual mozilla.org contributors; content available under a Creative Commons license | <a class="external" href="http://www.mozilla.org/foundation/licensing/website-content.html">Details</a>.</li> </ul>
</div>
<p>{{ languages( { "ja": "ja/Cross-Compiling_Mozilla" } ) }}</p>
Revert to this revision