========================= Compiling Perl on Android ========================= :CreationDate: 2012-09-01 09:19:00 :Id: SW/perl-on-android :tags: - software - perl .. admonition:: use Termux In the years since this page was written, a much better alternative has emerged: `Termux `_. It gives you a Debian chroot, with Perl, Rakudo, Python, Ruby, EMACS… At `YAPC::EU 2012`_, I only had my Asus TF101, and I wanted to play with some of the modules that the speakers were talking about. The Google-provided "Perl for Android" (part of the `Android Scripting Environment`_) is nearly useless, since you don't get the whole Perl core, the CPAN shell does not work, and you don't have a compiler for XS modules. Another option would be to cross-compile from a normal computer, but apart from the fact that I did not another computer with me, you still would not be able to install XS modules directly from the cross-compiled Perl. So I did what any self-respecting programmer would do: tried to build my own. I haven't yet managed to completely build the Perl distribution, but I have come some way, and I thought that it would be nice to write things down. Prerequisites ============= First of all, you need root access on your device: we have to create filesystems, change owners and permissions, mount images. Then, you need quite some RAM, storage, and processor. I wouldn't try it on a phone or a low-powered tablet. Finally, you need ``busybox``: the bare-bones command line tools shipped with most Android images are so limited that not even the very conservative Perl ``Configure`` can use them. You'll want to execute this (or something similar) to get ``busybox`` binaries in preference to the built-in ones:: export PATH=/system/xbin:$PATH Preparations ============ We need a native compiler. I found a well-built ``gcc`` on a wiki about ``R``: http://rwiki.sciviews.org/doku.php?id=getting-started:installation:android Get the two ``gcc`` tarballs. We're going to build a filesystem image, mount it via the loopback device, and install everything there: this way, the image can be moved between devices (we'll make sure everything is as relocatable as possible). I stored everything under ``/data/media/native`` (I created that directory). ``/data/media`` is, on my device, the actual store that is exposed (via a sort of bind-mount) as ``/sdcard``, with the difference that the latter has ``noexec``, the former doesn't. We want a rather large image, let's say 3 GB. I tried to make a sparse file with ``dd if=/dev/zero of=native.e2.diskimg bs=1024 seek=3000000 count=1`` but it failed. I ended up creating two smaller files and concatenating them. Then:: # cd /data/media/native # mke2fs -f native.e2.diskimg # cat > /data/media/native/start < /data/media/native/stop < /Removable/bin/true <