====== Perl on Android, 2nd try ======
After [[publications:perl-on-android|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 [[http://plausible.org/andy/agcc|agcc]] by Andrew Ross.
I opened a [[http://code.google.com/p/perldroid/|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).
- Follow the instructions [[http://source.android.com/download|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.
- Put the directory ''$HOME/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin'' in your ''$PATH''.
- Download and install the [[http://developer.android.com/sdk/1.1_r1/index.html|Android SDK]] (actually not useful for the moment).
- Download the [[http://www.cpan.org/src/perl-5.10.0.tar.gz|perl 5.10.0 source]] and untar it in your ''$HOME'' with « ''cd; tar xzf perl-5.10.0.tar.gz'' ».
- Download the home made [[http://dbx.gtmp.org/android/perl-5.10.0.android.patch.gz|perl patch]] and apply it to the perl source with « ''cd; gunzip -c perl-5.10.0.android.patch.gz | patch -p0'' »
- Download the perl script [[http://plausible.org/andy/agcc|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 [[http://brouits.free.fr|Benoît Rouits]] for bundling the patch, writing the ''README.android'' file and for some tweakings on the ''Cross/config.sh-arm-eabi'' file.