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

  • How to build Python-4-Android for the ARM Neon
    Currently the Py4A project does not compile for the ARM Neon architecture. If you try to run ndk-build on the project by setting the APP_A...
  • 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...
  • How to build the gcc Fortran cross-compiler for Android (ARM and x86)
    If you need to cross-compile for Android a program written in Fortran, you know already that the official Android NDK does not come with the...
  • Upgrading mid-2007 24in iMac with an SSD and a 2.5in HDD in the optical bay
    I own a mid-2007 24in iMac with a 2.4 GHz Intel Core 2 Duo processor, 4GB of DDR2 DRAM, running Mac OS Mountain Lion, and for the past few m...
  • 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...
  • How to inspect expanded C macros with gcc/gcc+
    Sometimes you get compilation errors in gcc/g++ and you'd like to inspect the output from the C compiler pre-processor to figure out why...
  • Android: Trying to load native library results in a process terminated by signal (11)
    Symptoms You are trying to load your native C/C++ library in an Android application and when at runtime your app calls the System.loadLibrar...
  • 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 build Python-4-Android for the x86
    Currently the Py4A project only compiles for the ARM architecture. The following patch for the python-build sub-directory allows you to cros...
  • How to port Mozilla SpiderMonkey 1.7 to Android
    Another third-party package I needed to cross-compile for Android was Mozilla's SpiderMonkey 1.7 Javascript engine. I found two issues h...

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