====== Installation of Perl on Android ======
**NOTE:** This is work in progress
These are the steps I've done to install Perl on Google Android emulator platform. Some of the steps I've done come from the French magazine "Gnu Linux Magazine France #112". If you can get one and understand French you can refer to it to have a better explanation of some of these steps.
My system is an up to date Ubuntu Intrepid (8.10). I've added some packages from the Ubuntu repositories, like ''git-core''. I don't remember the list (and some were already installed before) so if you follow the steps I've put on this page and miss one package, install it and report that fact to me please.
Feel free to report whatever you want to me on my [[mid@gtmp.org|mail]].
**Update:** I noticed that by doing this, all the Android platform is slowed down... I don't know why for the moment... Anyway, I opened a [[http://code.google.com/p/perldroid/|Google code site]] to host my project that goes far beyond this experiment (not available for the moment, see [[publications:perl-on-android-2|this page]]).
===== Installation of SDKs and tools =====
==== Install Sun's Java 6 SDK ====
Not useful for the moment but maybe for later.
Just do:
sudo apt-get install sun-java6-jdk
==== Install the Android SDK ====
Then you need, of course, to install the Android SDK to get the environment and the emulator. For this, follow the instructions on the [[http://code.google.com/intl/fr/android/intro/installing.html|Android SDK]] page.
These can be summed up by:
wget -nd http://dl.google.com/android/android-sdk-linux_x86-1.0_r2.zip
unzip android-sdk-linux_x86-1.0_r2.zip
Add the tools directory in your path:
PATH=~/android-sdk-linux_x86-1.0_r2/tools:$PATH
You may want to do this in your ''.bashrc''.
==== Installation of ScratchBox ====
I use Scratchbox v1.0.12 for the moment.
wget -nd http://www.scratchbox.org/download/files/sbox-releases/stable/deb/scratchbox-libs_1.0.12_i386.deb
wget -nd http://www.scratchbox.org/download/files/sbox-releases/stable/deb/scratchbox-core_1.0.12_i386.deb
wget -nd http://www.scratchbox.org/download/files/sbox-releases/stable/deb/scratchbox-devkit-cputransp_1.0.8_i386.deb
wget -nd http://www.scratchbox.org/download/files/sbox-releases/stable/deb/scratchbox-toolchain-arm-linux-2007q1-21_1.0.7_i386.deb
sudo dpkg -i scratchbox-libs_1.0.12_i386.deb scratchbox-core_1.0.12_i386.deb scratchbox-devkit-cputransp_1.0.8_i386.deb scratchbox-toolchain-arm-linux-2007q1-21_1.0.7_i386.deb
==== Log into ScratchBox ====
You need first to declare your current user in Scratchbox. I am ''mid'' (nice to meet you 8-) ) so I do:
sudo /scratchbox/sbin/sbox_adduser mid
Then you need to add your user to the ''sbox'' group, if not already done. Edit ''/etc/group'' to do so. Verify that you are in the ''sbox'' group with ''groups''. You may need to restart your graphical interface.
Then log into scratchbox:
/scratchbox/login
If you get the following message:
Host kernel has vdso support (which is uncompatible with SB)
You can fix this with either:
echo 0 > /proc/sys/vm/vdso_enabled
or
add 'vdso=0' to the kernel parameters
just do what it says:
sudo bash -c "echo 0 > /proc/sys/vm/vdso_enabled"
and reissue the ''/scratchbox/login'' procedure.
Before going further, set the compilation environment:
sb-menu
A text menu will appear. Choose ''Setup a target'' then ''Create a new target''. Give ''android'' as target name and ''arm-linux-2007q1-21'' as compiler. In the next menu, select ''cputransp'', then ''qemu-arm-0.8.2-sb2''. To the question "Do you wish to extract a rootstrap on the target?", answer "No". Answer "Yes" to the next question: "Do you wish to install files to the target?".
This environment setting is done only once.
Keep this terminal open and open another one (to avoid scratchbox logins and logouts).
==== Download and install busybox on Android emulator ====
=== Download and compile busybox===
This is not necessary but simplify work on the emulator.
Do this in a normal terminal, not logged into scratchbox:
cd /scratchbox/users/mid/home/mid
wget -nd http://busybox.net/downloads/busybox-1.10.1.tar.bz2
tar xjvf busybox-1.10.1.tar.bz2
cd busybox-1.10.1
make menuconfig
(change both occurences of ''mid'' in the first line with your logname)
In the ''Busybox Settings/Build Options'', select ''build a static binary''.
Then, from the previous terminal, the one logged into scratchbox:
cd busybox-1.10.1
make
=== Install busybox on the emulator ===
To install the freshly compiled executable in the emulator, we need to extract the ramdisk from the Android SDK and create a new one. Do this in a normal terminal:
mkdir androidrd; cd androidrd
cp ~/android-sdk-linux_x86-1.0_r2/tools/lib/images/ramdisk.img .
gunzip -S.img ramdisk.img
cpio -i -F ramdisk
cpio -t -F ramdisk >ramdisk_list
Now we are going to install the busybox executable and the applets:
mkdir bin; cd bin
cp /scratchbox/users/mid/home/mid/busybox-1.10.1/busybox .
awk -F\" '/applet_names/,/;/ { if ($2) printf("ln -s busybox %s\n", $2) }' /scratchbox/users/mid/home/mid/busybox-1.10.1/include/applet_tables.h >../create_bb_links.sh
. ../create_bb_links.sh
The last 2 commands extracts the busybox applets and create the symlinks.
Next, we have to rebuild the ramdisk:
find bin >>ramdisk_list
cat ramdisk_list | cpio -o -H newc -O mydisk
gzip -S.img mydisk
==== Test of busybox on emulator ====
Start the emulator with the command:
emulator -ramdisk ~/androidrd/mydisk.img &
Wait for it to be up and running.
Then, to log on:
adb forward tcp:4444 tcp:23
adb shell telnetd &
telnet localhost 4444
You should then be on the emulator. Then setup a little things and test busybox:
PATH=/bin:$PATH
ash
and feel free to inspect and test things...
Close the emulator window when you're done.
===== Installation of Perl =====
Now the interesting part: the installation of the perl executable and its core modules.
This installation won't use the Android ''bionic'' C library because it is too limited. I prefer to upload the toolchain libs on the emulator.
==== Download perl from git and install it in ScratchBox ====
Use a normal terminal first to issue the following commands:
cd /scratchbox/users/mid/home/mid
git clone git://perl5.git.perl.org/perl.git perl
then, in the scratchbox terminal:
cd perl
As we are using a develoment version (5.11, odd minor number), we won't be able to use the -d flag of Configure unless we edit this script to change line 2170 to ''dflt='y'''.
Then, do this:
./Configure -des -Dprefix=/
Wait for this command to end then type:
cp -p `which pwd` /usr/bin/
make
''perl'' won't build correctly if you don't copy the ''pwd'' executable to ''/usr/bin''. Don't worry it's the ''/usr/bin'' of your specific scratchbox environment.
After some time, the compilation is over.
FIXME: You would like to try ''make test'' but don't. For the moment some tests eat up 100% CPU and never end.
Now, do this:
make install
This will install perl in the scratchbox environment.
==== Install perl and dependencies in emulator ====
Now we have to move everything we built into the emulator. In a normal terminal, type:
cd ~/androidrd
cp -p /scratchbox/users/mid/targets/android/bin/* bin/
mkdir lib
cp -rp /scratchbox/users/mid/targets/android/lib/perl5 lib/
Before rebuilding the ramdisk, let's copy the necessary libraries:
cp -p /scratchbox/users/mid/targets/android/lib/ld-* lib/
cp -p /scratchbox/users/mid/targets/android/lib/libc* lib/
cp -p /scratchbox/users/mid/targets/android/lib/libdl* lib/
cp -p /scratchbox/users/mid/targets/android/lib/libgcc* lib/
cp -p /scratchbox/users/mid/targets/android/lib/libm* lib/
cp -p /scratchbox/users/mid/targets/android/lib/libnsl* lib/
cp -p /scratchbox/users/mid/targets/android/lib/libutil* lib/
Now, we rebuild the ramdisk. We have to extract again the initial content of the ramdisk because we don't want to add twice busybox. So do:
cpio -t -F ramdisk >ramdisk_list
find bin lib >>ramdisk_list
rm -f mydisk.img
cat ramdisk_list | cpio -o -H newc -O mydisk
gzip -S.img mydisk
===== Enjoy! =====
Start the emulator again, connect to it, and then try:
perl -V
You should see:
Summary of my perl5 (revision 5 version 11 subversion 0) configuration:
Commit id:
Platform:
osname=linux, osvers=2.6.27-11-generic, archname=arm-linux
uname='linux shut 2.6.27-11-generic #1 smp thu jan 15 11:03:58 utc 2009 arm gnulinux '
config_args='-des -Dprefix=/'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags =' -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags=''
ccversion='', gccversion='4.2.0 20070413 (prerelease)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=/lib/libc-2.5.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.5'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
USE_LARGE_FILES USE_PERLIO
Built under linux
Compiled at Jan 22 2009 20:52:18
@INC:
//lib/perl5/5.11.0/arm-linux
//lib/perl5/5.11.0
//lib/perl5/site_perl/5.11.0/arm-linux
//lib/perl5/site_perl/5.11.0
.
A lot of things should be perfectible. But anyway, I have a running perl on my emulator! :-)
===== Next steps =====
The next steps I'm currently working on are, in that order:
- See if it is possible to have a perl android application.
- See if it is possible to have bindings to the android framework.