How to install the Perl module "JavaScript" on Unix

This page was created on Wed Sep 23 2009 and last changed on Sat Oct 05 2024.

This article deals with installing JavaScript on Unix, specifically FreeBSD. Although FreeBSD comes with a port of SpiderMonkey, in /usr/ports/lang/spidermonkey, it doesn't seem to work with the Perl JavaScript module. Following the advice given in the JavaScript module, I reinstalled the spidermonkey library myself and built against that.
  1. Download the Javascript source code from Mozilla:
    wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
    
  2. Unpack this file and go to the subdirectory js/src.
  3. Run the makefile like this:
    gmake -f Makefile.ref
    
  4. This produces an error message:
    config.mk:150: config/FreeBSD7.2-RELEASE.mk: No such file or directory
    cat: ../../dist/FreeBSD7.2-RELEASE_DBG.OBJ/nspr/Version: No such file or directory
    gmake: *** No rule to make target `config/FreeBSD7.2-RELEASE.mk'.  Stop.
    
  5. Copy the file config/Linux_All.mk to config/FreeBSD7.2-RELEASE.mk, or whatever it said in the equivalent message.
  6. Run gmake again.
  7. The output files are in the directory FreeBSD7.2-RELEASE_DBG.OBJ/.
  8. Copy the header files (*.h) and tables (*.tbl) from the src directory to the FreeBSD7.2-RELEASE_DBG.OBJ.
    [ben@mikan] src 575 $ cp *.tbl *.h FreeBSD7.2-RELEASE_DBG.OBJ/
    
    Note that the header file jsautocfg.h is only in the FreeBSD7.2-RELEASE_DBG.OBJ directory, so if you compile against the header files in src, you will get a huge number of errors from the C compiler, starting off with the line
    /home/ben/software/js/js/src/jstypes.h:245:71: error: jsautocfg.h: No such file or directory
    
  9. Set up the environment to link against the compiled library:
    export JS_LIB=/home/ben/software/js/js/src/FreeBSD7.2-RELEASE_DBG.OBJ/
    export JS_INC=/home/ben/software/js/js/src/FreeBSD7.2-RELEASE_DBG.OBJ/
    
  10. Run cpan to install JavaScript:
    cpan JavaScript
    
    In my case this required installing one prerequisite, Test::Exception. Remember that if cpan fails, you can always download the distribution from CPAN and install it with
    perl Makefile.PL
    make
    make test
    make install
    

  11. Copyright © Ben Bullock 2009-2024. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer