Visit Mozilla.org

Building only SpiderMonkey

From MDC

Contents

[edit] Warning

THIS PAGE DESCRIBES WORK IN PROGRESS THAT HAS NOT YET BEEN APPROVED FOR INCLUSION IN THE MOZILLA SOURCES. THE INSTRUCTIONS HERE MAY NOT WORK. EVERYTHING DESCRIBED HERE MAY CHANGE.

Please don't try this out unless you're very comfortable working with mostly-broken makefiles and configure scripts, and are ready to help out.

[edit] Building only SpiderMonkey

We would like to be able to build the SpiderMonkey source tree, js, independently of the rest of the Mozilla sources. This would allow us to distribute SpiderMonkey on its own, making it easier for people to embed JavaScript in their own applications. Furthermore, we would like to use the same set of configuration scripts and makefiles for both out-of-Mozilla-tree and in-tree builds, reducing maintenance costs.

Thus:

  • The js tree will have its own configure script. The top-level configure.in will call it, as it does nsprpub's now.
  • We will not use automake or libtool, or an autoconf newer than 2.13. If those are valuable changes, they can be a separate patch.
  • A SpiderMonkey install will provide a js-config script, in the style of nspr/config/nspr-config.in.
  • New js/config and js/build directories will hold copies of files from config and build needed by the SpiderMonkey sources.
  • js/src/config and js/src/Makefile.ref will probably go away completely.

[edit] Recent Changes

  • All patches for this work are now available in bug 97954.
  • SpiderMonkey can now be used in-tree, as part of Mozilla, and out-of-tree.
  • SpiderMonkey no longer depends on NSPR, unless configured with --enable-threadsafe.
  • Problems with symbol visibility are fixed. (This bug produced link errors referring to unresolveable relocs.)
  • Problems with building with -j are fixed.
  • make -f client.mk configure-files no longer produces errors that must be ignored.
  • js-config --cflags prints the right path for the SpiderMonkey header files.

[edit] Prerequisites

In order to build SpiderMonkey out-of-tree, you will need the following tools, in addition to the normal Build Prerequisites:

  • Mercurial, required to retrieve the sources.
  • autoconf 2.13, with autoconf installed as autoconf-2.13.
  • If you need support for multi-threaded operation, you'll also need the Netscape Portable Runtime (NSPR). NSPR is part of the Mozilla source tree; we explain how to build it stand-alone below.

[edit] Directories Used In These Instructions

We use the following variables to name the various directories involved in getting SpiderMonkey going:

Variable Meaning
$src The top of the source tree. This directory is created by the hg clone command below, and has subdirectories named js, toolkit, and many others.
$js_build An empty directory in which we'll compile SpiderMonkey.
$js_prefix The directory prefix under which we'll install SpiderMonkey. Libraries will go in $js_prefix/lib, headers in $js_prefix/include, and so on.
Needed only for multi-threaded builds:
$nspr_build An empty directory in which we'll compile NSPR.
$nspr_prefix The directory prefix under which we'll install NSPR.

[edit] Checking Out The Sources

You can check out the sources with Mercurial as follows:

 hg clone -r 9187161f308e http://hg.mozilla.org/users/jblandy_mozilla.com/jsuni/
 cd jsuni/js
 autoconf-2.13

This checks out a specific revision thought to work; the directory created is our $src, as mentioned above. The autoconf-2.13 command generates the SpiderMonkey configure script.

If you're familiar with Mercurial and already have a Mozilla repository lying around locally, you could certainly save some time by cloning the local repository, and then pulling from the above URL. Mozilla Central would be best, but anything will work. Until this work is merged into the main Mozilla sources, we'll continue to push it here, so you can follow along.

[edit] Building SpiderMonkey

You can build a single-threaded SpiderMonkey as follows:

 cd $js_obj
 $src/js/configure --prefix=$js_prefix
 make
 make install

If you don't want to install SpiderMonkey, you can omit the --prefix option.

If you want to build a multi-threaded SpiderMonkey, see below.

(If configure complains that --enable-application wasn't specified, you forgot to type the js, and ran $src/configure instead.)

[edit] Linking Against SpiderMonkey

The make install command above should place a script named js-config in the directory $js_prefix/bin, which you can run to find the appropriate flags to pass to the compiler and linker to use the installed SpiderMonkey header files and libraries. The command js-config --cflags prints flags to pass to the C compiler, and the command js-config --libs prints flags to pass to the linker to find and link against the SpiderMonkey shared library and its dependencies. Invoke js-config with no arguments to see a brief help message.

[edit] Building A Multi-Threaded SpiderMonkey

If you need a SpiderMonkey library that can handle multiple threads using a single runtime, you'll need to build and install a copy of NSPR before building SpiderMonkey itself. SpiderMonkey depends on NSPR for multi-threaded support.

The hg clone command given above checks out most of the Mozilla sources — everything a single-threaded SpiderMonkey needs — but it doesn't check out the NSPR sources. Check out the Mozilla sources as described above, and then get NSPR as follows:

 cd $src
 python client.py checkout
 make -f client.mk configure-files

Then, build NSPR as follows:

 cd $nspr_obj
 $src/nsprpub/configure --prefix=$nspr_prefix
 make
 make install

Then, follow the instructions for building SpiderMonkey above, passing the following additional flags to SpiderMonkey's configure script:

 --with-system-nspr --with-nspr-prefix=$nspr_prefix