Perl on Android, 2nd try

After tweaking with Scratchbox, I could not build a perl linked with bionic with it.

However, it is possible to build perl with bionic using the standard Android toolchain, something I was thinking not possible. Here is how I did.

To facilitate the procedure (and even make it possible), I used the script agcc by Andrew Ross.

I opened a Google code project named perldroid.

Installation of prerequisites

Let's start from scratch. I'm still on an Ubuntu Intrepid (8.10), I'll try to build perl 5.10.0, the same version as on Intrepid (this is not a coincidence).

  1. Follow the instructions here to install the Android source for Ubuntu. Please use the same directory they use ($HOME/mydroid). There is a small mistake on the page, you should install libreadline5-dev instead of lib32readline5-dev that does not exists on Ubuntu 32 bit. Also, we don't need valgrind. Don't forget to build the code with make because it builds some files we need.
  2. Put the directory $HOME/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin in your $PATH.
  3. Download and install the Android SDK (actually not useful for the moment).
  4. Download the perl 5.10.0 source and untar it in your $HOME with « cd; tar xzf perl-5.10.0.tar.gz ».
  5. Download the home made perl patch and apply it to the perl source with « cd; gunzip -c perl-5.10.0.android.patch.gz | patch -p0 »
  6. Download the perl script agcc and place it somewhere in your $PATH. A good place is $HOME/bin.

Compilation

cd ~/perl-5.10.0/Cross
less README.android # always useful
make -f Makefile.android patch
make -f Makefile.android perl

If everything is OK, the resulting executables, libraries and modules should be installed in $HOME/perl-5.10.0/install_me_here/.

Installing and running on emulator

Unfortunately, it is not (yet) possible to install it on the real phone because the Android source (and the bionic libc it provides) is too recent and not compatible. When I (or someone else) find a way to download the bionic version that is on the phone, I will mention it.

Follow this procedure to create a custom ramdisk with perl inside it:

cd
mkdir androidrd.perl; cd androidrd.perl
cp ~/mydroid/out/target/product/generic/ramdisk.img .
gunzip -S.img ramdisk.img
cpio -i -F ramdisk
cpio -t -F ramdisk >ramdisk_list
rm -rf usr
cp -r ~/perl-5.10.0/install_me_here/usr .
find usr >>ramdisk_list
cat ramdisk_list | cpio -o -H newc -O mydisk
gzip -S.img mydisk

Now start the Android source emulator with:

export ANDROID_PRODUCT_OUT=$HOME/mydroid/out/target/product/generic
~/mydroid/out/host/linux-x86/bin/emulator -ramdisk ~/androidrd.perl/mydisk.img &

and log in to try perl:

adb shell
/usr/bin/perl -I /usr/lib/perl -V

should output:

FIXME output of perl -V

The -I switch is necessary because the config file to build perl is designed ot put /data/data/org.gtmp.perl/lib/perl in @INC, not /usr/lib/perl. This was done because of the packaging foreseen for the perl executable. More on this when it will be done.

Feel free to try whatever perl script you like but be aware that everything is not available on the Android platform. FIXME precise what is not available.

Credits

Thanks to Benoît Rouits for bundling the patch, writing the README.android file and for some tweakings on the Cross/config.sh-arm-eabi file.

 
publications/perl-on-android-2.txt · Last modified: 2009/02/20 18:49 by mid
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki