develooper Front page | perl.perl5.porters | Postings from September 2013

Re: Question on porting perl 5.16 to Android (no /bin/sh)

Thread Previous | Thread Next
From:
Ben Greear
Date:
September 4, 2013 18:17
Subject:
Re: Question on porting perl 5.16 to Android (no /bin/sh)
Message ID:
52277921.2010507@candelatech.com
On 09/04/2013 10:21 AM, Brian Fraser wrote:
> On Wed, Sep 4, 2013 at 1:50 PM, Ben Greear <greearb@candelatech.com <mailto:greearb@candelatech.com>> wrote:
>
>     I used the perldroid project to cross-compile perl 5.16 for android (ARM) using
>     the latest Android NDK stand-alone toolchain.  After hacking on perldroid to
>     fix a few things I got a mostly-working perl binary & libraries.
>
>     One problem remains however.  If I have perl code that does something like this,
>     it will not work:
>
>     my @foo =  `ls run_*.PID 2>/dev/null`;
>
>     I think this might be because Android has no /bin/sh.  Instead, it puts the shell
>     at /system/bin/sh.
>
>     Maybe lacking /bin/sh perl uses some interal minimal fake shell and thus fails to handle
>     more advanced system calls?
>
>     Anyone know if perl can be configured to use a different shell by default, or where
>     the code is that could be changed to use /system/bin/sh?
>
>     Thanks,
>     Ben
>
>
> Rather than using perldroid, try using castaway's branch here:
> https://github.com/castaway/perl/tree/jrobinson/configure-for-cross
>
> Which solves that and several other issues with perl on android, such as making 'system "echo", "foo"' work, even though "echo" is a shell builtin in Android,
> or being able to use both List::Util and Hash::Util in the same program, which fails on perldroid due to some limitations in the android linker.
> Also, for the time being, perhaps considering using https://github.com/Hugmeir/utf8mess/tree/configure-for-cross instead, at least until that's merged into the
> main branch, if you want to run a successful 'make test' after building, to ensure that your perl is working properly.
>
> With that branch, building perl on android is pretty simple:

I took a look at the jrobinson stuff yesterday, but I'd rather not use
an emulator, and I want the end result to be a foo/perl/lib and foo/perl/bin
(or similar) directory structure that I can copy over to my phone via
sftp or some other external means.

I also have a stand-alone toolchain set up already, so it seems I can skip
some of these steps.

I'll try based on your instructions below and see what I can see.

For your instructions below, is there a particular place on the
droid file system at which perl is expecting to be installed?  I
can fiddle with @INC if needed, but easier if I don't have to.

Thanks,
Ben

>
> # Change these two accordingly
> $ export ANDROID_NDK=$HOME/Downloads/android-ndk-r8e
> $ export ANDROID_SDK=`echo $HOME/Downloads/adt-bundle-*`
>
> $ export PATH="$ANDROID_SDK/sdk/platform-tools:$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/`uname | tr '[A-Z]' '[a-z]'`-x86_64/bin:$PATH"
> $ $ANDROID_NDK/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=/tmp/my-toolchain --system=`uname | tr '[A-Z]' '[a-z]'`-x86_64
> --toolchain=arm-linux-androideabi-4.4.3
>
> # Turn on the emulator, obviously optional:
> $ $ANDROID_SDK/sdk/tools/android avd &
>
> $ adb devices
> # Grab the device name, then
> $ export DEVICE=emulator-5554
>
> # if you have a rooted device/emulator:
>
>      $ export TARGETDIR=/mnt/asec/perl
>      $ adb -s $DEVICE shell "echo sh -c '\"mkdir $TARGETDIR\"' | su --"
>
> # else
>      # You might have a /data that is writeable by the 'shell' user,
>      # which is what adb logs in as. if you do, you could
>      # put all of perl and the test files there, but for most phones
>      # you'll run out of space first.
>      # WARNING! You'll have to remove the test files from
>      # the target dir once you are done! Unlike /mnt/asec,
>      # /data/local/tmp may not get automatically garbage
>      # collected once you shut off the phone
>
>      $ export TARGETDIR=/data/local/tmp/perl
>      $ adb -s $DEVICE shell "mkdir $TARGETDIR"
>
> $ adb -s $DEVICE pull /system/lib /tmp/tmpandroidlib
>
> $ ./Configure -des -Dusedevel -DDEBUGGING -Dusecrosscompile -Dcc=arm-linux-androideabi-gcc -Dtargethost=$DEVICE -Dsysroot=/tmp/my-toolchain/sysroot
> -Dtargetdir=$TARGETDIR
> $ perl -i -wlnpe "s{^libpth=\K.+}{'/tmp/tmpandroidlib'}" config.sh
> $ make -j30
> $ make test
> $ make DESTDIR=/tmp/android-perl install
>
> Then copy the perl installed into /tmp/android-perl to your device
>


-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About