Monday, July 18, 2011

HowTo: Compile MediaTomb with JavaScript support on Ubuntu 11.04

--- UPDATE ---
Since Ubuntu 11.10 (Oneiric Ocelot) is now available, it was time for an update:
HowTo: Compile MediaTomb with JavaScript support on Ubuntu 11.10 Oneiric Ocelot
--- UPDATE END ---

Since some time in Ubuntu MediaTomb is compiled without JavaScript support. JavaScript support is needed for example to handle/import playlists. So I spent some time on the net looking for a howto. The best I found was this one targeted to Ubuntu 10.04.

To make long stories short: The problem is with SpiderMonkey, the Mozzila JavaScrip engine. MediaTomb needs a header called jsapi.h to compile. As Natty comes with packages providing these headers (libmozjs185-1.0, libmozjs185-dev, xulrunner-2.0-mozjs) I gave it a try, but I didn't manage. I also followed Gabriel's hints on how to build and install SpiderMonkey from source, but did still not succeed. 

After a little more of research I finally managed to build MediaTomb on my Ubuntu Natty. Here is a step-by-step walk trough of what worked for me:
  1. change to root or use sudo
  2. apt-get build-dep mediatomb
  3. apt-get source mediatomb
  4. vim mediatomb-0.12.1/debian/rules
  5. change --disable-libjs to --enable-libjs
  6. Now you should update the changelog file in the same directory
  7. get libmozjs2d and libmozjs-dev from the debian sid distibution: libmozjs2d_1.9.1.16-6_i386.deb and libmozjs-dev_1.9.1.16-6_i386.deb
  8. Now you can cd to mediatomb-0.12.1 and try a ./configure. You should see a line in the configuration summary that reads
    libjs                 : yes
  9. Now its time to install additional libs you might what to have for the build. Check the configuration summary. When you are done let's go!
  10. If you are not already there: cd mediatomb-0.12.1
  11. dpkg-buildpackage -rfakeroot -us -uc
That's it! If all went well you should now have three new .deb files in the directory you did the apt-get in. You can install them all in one go by dpkg -i mediatomb*.deb

My thanks go to Gabriel Burca for his solution for Ubuntu 10.04 that was the basis for my Natty solution.

--- UPDATE ---
Triggered by Viv's comment, I tried this also on a 64-bit Ubuntu 11.04 (amd64). 
The only difference is in step 7. Here you will have to use the amd64 libraries: libmozjs2d_1.9.1.16-6_amd64.deb and libmozjs-dev_1.9.1.16-6_amd64.deb
After  that there is one additional step:
7.1. apt-get install libjs-prototype
--- UPDATE END ---


  1. Tobias, I've tried following your instructions & end up with this:

    Viv@ubuntu:~/build/mediatomb-0.12.1$ sudo dpkg-buildpackage -rfakeroot -us -uc
    dpkg-buildpackage: warning: using a gain-root-command while being root
    dpkg-buildpackage: export CFLAGS from dpkg-buildflags (origin: vendor): -g -O2
    dpkg-buildpackage: export CPPFLAGS from dpkg-buildflags (origin: vendor):
    dpkg-buildpackage: export CXXFLAGS from dpkg-buildflags (origin: vendor): -g -O2
    dpkg-buildpackage: export FFLAGS from dpkg-buildflags (origin: vendor): -g -O2
    dpkg-buildpackage: export LDFLAGS from dpkg-buildflags (origin: vendor): -Wl,-Bsymbolic-functions
    dpkg-buildpackage: source package mediatomb
    dpkg-buildpackage: source version 0.12.1-0ubuntu1
    dpkg-buildpackage: source changed by Micah Gersten
    dpkg-buildpackage: host architecture amd64
    dpkg-source --before-build mediatomb-0.12.1
    fakeroot debian/rules clean
    /usr/bin/fakeroot: line 176: debian/rules: Permission denied
    dpkg-buildpackage: error: fakeroot debian/rules clean gave error exit status 126

    I've tried 'chmod +x debian/rules' to alter the file permission, but it's still not working. Can you help me please? :(


  2. Hi Viv,

    I have just set-up a vanilla VM with ubuntu 64-bit to reproduce your problem. I suspected your problem might have something to do with you using 64-bit architecture (amd64) instead of 32-bit (i386). But I was not able to reproduce this at all.

    I assume you already got the right version (amd64) of the libmozjs libraries as the i386 version would not install without massive complains.

    With that my test build ran smoothly without any problems. After the build, I only had to install libjs-prototype (apt-get install libjs-prototype) in addition by hand in order to install and run mediatomb.

    I doubt this helps you much, but it suggests that you have a more general problem with your system, that is not directly connected to building mediatomb.

    Apart from that it shows that this also works for 64-bit architectures.


  3. Thanks Tobias

    Works well on amd64 Natty according to your updated instructions (once dependencies were sorted).


  4. Thanks for these instructions. I'd like to add this works on Oneiric 12.04 (amd64) as well. There was one additional thing I needed to do though.

    I had "libmozjs185-dev" package installed as well (probably by me at some point), and it appeared to choose this over the newly instsalled one.

  5. Thanks! It still works on 12.10 as well. I only had to "apt-get install fakeroot" in addition.