Danilo's Tech Blog

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 10 January 2013

How to port Mozilla SpiderMonkey 1.7 to Android

Posted on 07:47 by Unknown
Another third-party package I needed to cross-compile for Android was Mozilla's SpiderMonkey 1.7 Javascript engine. I found two issues here:

  1. When configuring SpiderMonkey the makefile tries to build two executables (jscpucfg and jskwgen) and then runs them to generate two  configuration header files (jsautocfg.h and jsautokw.h, respectively). The problem when using the Android NDK cross-compiler is that these two executables can only be run on the Android target (for example an ARM processor), while I'm cross-compiling my build from a Linux Ubuntu 12.04 machine with an x86_64 processor architecture. So you get an error that you cannot execute these files on the host machine.
    I solved this problem by copying the two executables to an Android device (Samsung Galaxy S III) using scp and the SSHDroid application, and generating the two header files there:

    $ jscpucfg > jsautocfg.h
    $ jskwgen > jsautokw.h

    then I copied the two files back to my node on my Ubuntu machine and saved in the source trunk under the config sub-directory. Then I changed the makefile to skip generating these two header files when cross-compiling for Android and get them instead from the config sub-directory.
  2. The SpiderMonkey jsnum.c file generates the following error when cross-compiled for Android:

    js-1.7/jsnum.c: In function 'js_InitRuntimeNumberState':
    js-1.7/jsnum.c:578: error: 'struct lconv' has no member named 'thousands_sep'
    js-1.7/jsnum.c:578: error: 'struct lconv' has no member named 'thousands_sep'
    js-1.7/jsnum.c:580: error: 'struct lconv' has no member named 'decimal_point'
    js-1.7/jsnum.c:580: error: 'struct lconv' has no member named 'decimal_point'
    js-1.7/jsnum.c:582: error: 'struct lconv' has no member named 'grouping'
    js-1.7/jsnum.c:582: error: 'struct lconv' has no member named 'grouping'
    gmake[2]: *** [js-1.7.dir/jsnum.c.o] Error 1

    This is caused by the fact that the lconv structure in locale.h shipped with the Android NDK is stubbed with the following comment:

    #if 1 /* MISSING FROM BIONIC - DEFINED TO MAKE libstdc++-v3 happy */
    struct lconv { };
    struct lconv *localeconv(void);
    #endif /* MISSING */

    To solve this problem I applied the following patch to jsnum.c and I was able to successfully cross-compile SpiderMonkey 1.7 for Android.

    --- a/jsnum.c   2013-01-10 10:37:54.413800695 -0500
    +++ b/jsnum.c   2013-01-10 10:06:49.432752061 -0500
    @@ -573,13 +573,28 @@ js_InitRuntimeNumberState(JSContext *cx)
         u.s.lo = 1;
         number_constants[NC_MIN_VALUE].dval = u.d;
     
    -    locale = localeconv();
    -    rt->thousandsSeparator =
    -        JS_strdup(cx, locale->thousands_sep ? locale->thousands_sep : "'");
    -    rt->decimalSeparator =
    -        JS_strdup(cx, locale->decimal_point ? locale->decimal_point : ".");
    -    rt->numGrouping =
    -        JS_strdup(cx, locale->grouping ? locale->grouping : "\3\0");
    +    /* Copy locale-specific separators into the runtime strings. */
    +    const char *thousandsSeparator, *decimalPoint, *grouping;
    +#ifdef HAVE_LOCALECONV
    +    locale = localeconv();
    +    thousandsSeparator = locale->thousands_sep;
    +    decimalPoint = locale->decimal_point;
    +    grouping = locale->grouping;
    +#else
    +    thousandsSeparator = getenv("LOCALE_THOUSANDS_SEP");
    +    decimalPoint = getenv("LOCALE_DECIMAL_POINT");
    +    grouping = getenv("LOCALE_GROUPING");
    +#endif
    +    if (!thousandsSeparator)
    +        thousandsSeparator = "'";
    +    if (!decimalPoint)
    +        decimalPoint = ".";
    +    if (!grouping)
    +        grouping = "\3\0";
    +
    +    rt->thousandsSeparator = JS_strdup(cx, thousandsSeparator);
    +    rt->decimalSeparator = JS_strdup(cx, decimalPoint);
    +    rt->numGrouping = JS_strdup(cx, grouping);
     
         return rt->thousandsSeparator && rt->decimalSeparator && rt->numGrouping;
     }

    Of course you would define HAVE_LOCALECONV only for regular builds but not for Android cross-compilations, so that you could either pass your own definitions for the locale thousands separator, decimal point or locale grouping via environment variables, or use the above defaults.
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Android, GNU, Javascript | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Problems with new version of rpmbuild
    The Problem With the new version of rpmbuild installed on CentOS 6.x, if you try to use an old RPM spec file, you will get an error like the...
  • Python For Android (Py4A)
    A better solution for cross-compiling Python for Android is to use the Py4A project which is made to be used together with SL4A (Scripting L...
  • Configuring the Apple Airport Extreme with Verizon FIOS
    I have Verizon FIOS triple-play service and I love the TV picture quality and internet speed and reliability, but I don't like Verizon...
  • Transferring Files from a computer to your Android device
    Android devices have file systems similar to regular computers. Subject to permissions restrictions, we can transfer files from a computer t...
  • Arduino and 7-segment LED counter driven by two tactile switches
    I have posted on YouTube a couple of videos about a project I made with the Arduino prototype board. The circuit uses an Arduino mini and ...
  • How to Cross-Compile libiconv for Android
    If your legacy C/C++ code includes <iconv.h> to convert the encoding of characters from one coded character set to another, and you ne...
  • Welcome
    After many years of searching the web for tips and tricks about computers, operating systems and programming languages, it's finally tim...
  • How to cross-compile Python for Android
    When it comes to cross-compiling Python for Android, I've followed Gabriel's blog post @ http://mdqinc.com/blog/2011/09/cross-compil...
  • Porting your Legacy C/C++ project to Android
    This is a recurring problem people have often: trying to port a big C/C++ project to the Android platform. You have thousands of lines of te...
  • Installing the Android NDK
    These instructions refer to a Ubuntu 12.04.1 LTS system running on an Intel processor. Head to the  http://developer.android.com/tools/sdk/n...

Categories

  • Android
  • Apple
  • Arduino
  • ARM
  • busybox
  • CentOS
  • DHCP
  • Fortran
  • GNU
  • GPON
  • iMac
  • Javascript
  • ksh
  • Linux
  • MacOSX
  • Mips
  • Network
  • Python
  • Router
  • UNIX
  • Windows
  • x86

Blog Archive

  • ▼  2013 (12)
    • ►  October (1)
    • ►  August (1)
    • ►  May (1)
    • ►  February (3)
    • ▼  January (6)
      • How to build Python-4-Android for the ARM Neon
      • How to build Python-4-Android for the x86
      • Android: Trying to load native library results in ...
      • How to port Mozilla SpiderMonkey 1.7 to Android
      • How to inspect expanded C macros with gcc/gcc+
      • Upgrading mid-2007 24in iMac with an SSD and a 2.5...
  • ►  2012 (11)
    • ►  December (2)
    • ►  November (2)
    • ►  October (7)
Powered by Blogger.

About Me

Unknown
View my complete profile