Compiling Mozilla’s SpiderMonkey 1.8.5 and building an RPM out of it for CentOS 6.x

Hey Squirrels,

We recently came across a situation where we wanted to install CouchDB on CentOS 6.x

As you can imagine from the title of this post, one of the requirements was to install SpiderMonkey 1.8.5 – “Mozilla’s JavaScript engine written in C/C++“.

Here’s how we compiled it and made an RPM package out of it – you can find this package in our Squirrel5 RPM repository here.

1. Create a target directory – we’ll use this as a target for the files that will make up our RPM package.

mkdir /target

2. Get the prerequisites to compile the package:

yum -y install make gcc gcc-c++ perl zip rpm-build

3. Download, configure, compile the source and install it to our target directory

cd /tmp
wget http://ftp.mozilla.org/pub/js/js185-1.0.0.tar.gz
tar -xzf js185-1.0.0.tar.gz
cd js-1.8.5/js/src/
./configure --prefix=/target
time make -j`nproc`
# this took about 5 minutes on our 2 core VPS
make install

4. Now the source is compiled and installed under /target – let’s go take a look:

cd /target/lib
ls -al
[root@squirrel5test lib]# ls -al
total 9040
drwxr-xr-x 3 root root    4096 Dec 12 05:28 .
drwxr-xr-x 5 root root    4096 Dec 12 05:28 ..
-rwxr-xr-x 1 root root 5571078 Dec 12 05:24 libmozjs185-1.0.a
lrwxrwxrwx 1 root root      30 Dec 12 05:28 libmozjs185.so -> /target/lib/libmozjs185.so.1.0
lrwxrwxrwx 1 root root      32 Dec 12 05:28 libmozjs185.so.1.0 -> /target/lib/libmozjs185.so.1.0.0
-rwxr-xr-x 1 root root 3667244 Dec 12 05:24 libmozjs185.so.1.0.0
drwxr-xr-x 2 root root    4096 Dec 12 05:28 pkgconfig

5. See those symlinks? they’re not going to work ! if we pack this up the symlinks will keep pointing to a /target directory which will no longer exist. We’ll delete the symlinks and replace them with relative ones:

rm -f libmozjs185.so
rm -f libmozjs185.so.1.0
#recreate the symlinks
ln -s libmozjs185.so.1.0.0 libmozjs185.so.1.0
ln -s libmozjs185.so.1.0 libmozjs185.so

So now the output of ls -al should look like this:

[root@squirrel5test lib]# ls -al
total 9040
drwxr-xr-x 3 root root    4096 Dec 12 06:19 .
drwxr-xr-x 5 root root    4096 Dec 12 06:18 ..
-rwxr-xr-x 1 root root 5571078 Dec 12 06:18 libmozjs185-1.0.a
lrwxrwxrwx 1 root root      18 Dec 12 06:19 libmozjs185.so -> libmozjs185.so.1.0
lrwxrwxrwx 1 root root      20 Dec 12 06:19 libmozjs185.so.1.0 -> libmozjs185.so.1.0.0
-rwxr-xr-x 1 root root 3667244 Dec 12 06:18 libmozjs185.so.1.0.0
drwxr-xr-x 2 root root    4096 Dec 12 06:18 pkgconfig

6. Now install Ruby and fpm – we need those to create the RPM package:

yum -y install http://rpm.squirrel5.com/squirrel5-repo-1.0-1.x86_64.rpm
yum -y install ruby
gem install fpm --no-ri --no-rdoc

7. Use fpm to create an RPM out of the current directory:

cd /target
fpm --verbose -v 0.1 -n libmozjs185-dev -s dir -t rpm .=/usr/

You’ll see output like this:

Executing(%clean): /bin/sh -e /tmp/rpm-tmp.UIOsJQ {:level=>:info}
Created package {:path=>"libmozjs185-dev-0.1-1.x86_64.rpm"}

8. You can install the RPM package by typing:

yum -y install /target/libmozjs185-dev-0.1-1.x86_64.rpm

Done!

Sources:

Leave a Reply

Your email address will not be published. Required fields are marked *