Tuesday, February 14, 2012

Cross-compiling Perl for MIPS/ARM etc.

Here's me trying to cross-compile Perl for MIPS. I gave up eventually, but you may have better luck.


  1. Save patch file to my-compile-perl-001.patch
  2. Save script to, say, my-compile-perl.sh
  3. ./my-compile-perl.sh
When asked for Any additional cc flags? [none], enter -fno-strict-aliasing
When asked Do you wish to use dynamic loading? [y], enter n
Tweak a few more answers, but you can hit Enter and accept the
default for most. It still asks for remote root password
sometimes, not sure why.

How it fails

In file included from globals.c:32:
perl.h:4315:20: uudmap.h: No such file or directory
In file included from globals.c:32:
perl.h:4316: error: parse error before ';' token
perl.h:4318:24: bitcount.h: No such file or directory
perl.h:4319: error: parse error before ';' token
make: *** [globals.o] Error 1
I had to copy generate_uudmap to the remote system and run it there.
After copying back the header files, it failed with::
perl.h:40:28: xconfig.h: No such file or directory
At that point I gave up realizing that Perl was not meant to be cross-compiled.

Disabling caching (patch)

When running remote tests, Perl tries to be clever and not run the test twice. But a few tests have the same name and this fails.
--- orig/perl-5.14.2/Configure  2011-09-26 05:44:34.000000000 -0400+++ perl-5.14.2/Configure       2012-02-14 13:10:03.000000000 -0500
@@ -2892,10 +2892,10 @@
-if $test ! -f \$exe.xok; then
+#if $test ! -f \$exe.xok; then
   $to \$exe
-  $touch \$exe.xok
+#  $touch \$exe.xok
 $targetrun -l $targetuser $targethost "cd \$cwd && ./\$exe \$@"

Shell script to do it all

set -e
set -x
test -f perl-5.14.2.tar.gz || \
    wget http://www.cpan.org/src/5.0/perl-5.14.2.tar.gz
test -d perl-5.14.2 || \
    tar xzf perl-5.14.2.tar.gz
cd perl-5.14.2
test -f .my.patched || {
    patch -p1 < ../my-compile-perl-001.patch
    touch .my.patched
test -f .configured || {
    # setup for remote compilation
    # i've put dropbear SSH server on my remote system
    test -f .my.keyfile.copied || {
        scp ~/.ssh/authorized_keys2 root@${TARGET_HOST}:/tmp/keyfile.pub
        ssh root@${TARGET_HOST} 'mkdir -p /root/.ssh; cp /tmp/keyfile.pub /root/.ssh/authorized_keys; chmod 0600 /root/.ssh /root/.ssh/authorized_keys;'
        touch .my.keyfile.copied
test -f .my.configured || {
    # http://stackoverflow.com/questions/5464538/cross-compile-perl-for-arm
    test -d ${INSTALL_DIR} || mkdir -p ${INSTALL_DIR}
    test -d ${INSTALL_DIR}/bin || mkdir -p ${INSTALL_DIR}/bin
    # TODO: try -des switch
    ./Configure \
        -Dusecrosscompile \
        -Dtargethost=${TARGET_HOST}  \
        -Dtargetuser=root \
        -Dtargetarch=mipsel-linux  \
        -Duserelocatableinc \
        -Uusenm \
        -Dcc=${CROSS_PREFIX}gcc  \
        -Dusrinc=${CROSS_BASE}/include  \
        -Dincpth=${CROSS_BASE}/include  \
        -Dlibpth=${CROSS_BASE}/lib  \
    touch .my.configured


Post a Comment