Monday, May 19, 2014

[Ruby] Cross-Compile Ruby to MIPS platform

I have spent several days to deal with cross-compiling Ruby to MIPS platform and have encountered some problems that bother me for a while. Hopefully I finish all the problems and get work done. Awesome!
For the sake of avoiding these kind of problems, I give the steps and scripts about how to do it:

  • Cross Compile OpenSSL

>./config --prefix=$PWD/build --cross-compile-prefix=/home/liudanny/git/NL/toolchains_bin/mipscross/linux/bin/mips64-nlm-linux-elf32btsmip- shared no-asm

We need to check the Makefile with “PLATFORM=mips” and without “-m64”

>make 2>&1 | tee make.out; make install

  • Cross Compile zlib
>CC=your_cross_compile_gcc ./configure --prefix=$PWD/build
>make 2>&1 | tee make.out; make install


  • Cross Compile Berkeley DB

>CC=your_cross_compile_gcc ../dist/configure --prefix=$PWD/build
>make 2>&1 | tee make.out; make install


  • Cross Compile OpenLDAP

>CC=your_cross_compile_gcc LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/liudanny/git/db-6.0.30.NC/build_unix/build/lib:/home/liudanny/git/openssl-1.0.1e/build/ssl/lib LDFLAGS=" -L/home/liudanny/git/db-6.0.30.NC/build_unix/build/lib -L/home/liudanny/git/openssl-1.0.1e/build/ssl/lib" CPPFLAGS=" -I/usr/local/include -I/home/liudanny/git/db-6.0.30.NC/build_unix/build/include -I/home/liudanny/git/openssl-1.0.1e/build/ssl/include" ./configure --prefix=$PWD/mybuild/ --enable-bdb --enable-crypt --host=mips64-nlm-linux --with-yielding_select=yes –with-tls=openssl

Before calling make, commenting out the line in include/portable.h ?
// #define NEED_MEMCMP_REPLACEMENT 1

Modify build/shtool to avoid from stripping error ?
Goto line 980 and find:

if [ “.$opt_s” = .yes ]; then
    if [ “.$opt_t” = .yes ]; then
    echo “strip $dsttmp” 1>&2
    fi
    strip $dsttmp || shtool_exit $?
    fi
 
    Change to the following ?
 
    if [ “.$opt_s” = .yes ]; then
    if [ “.$opt_t” = .yes ]; then
    echo “arm-none-linux-gnueabi-strip $dsttmp” 1>&2
    fi
    arm-none-linux-gnueabi-strip $dsttmp || shtool_exit $?
    fi

>make depend; make; make install


  • Cross Compile Ruby 1.8.7

Before cross-compiling Ruby, it must compiles and builds on the server first, then cross-compiling will use its own Ruby to generate the Makefile and other important steps.
Due to Ruby can have many extension libraries, we need to modify Setup.emx to enable the ext libs that we need. And also, copy the needed ruby-ext-libs into ext/ directory In the picture, we add and enable “shadow”, “openssl”, “socket”, “zlib”, and “ldap” ext libs as follows:

>export ac_cv_func_getpgrp_void=yes
>export ac_cv_func_setpgrp_void=yes
>export PATH=/home/liudanny/ruby-1.8.7-p352/build/bin:$PATH
>CC=your_cross_compile_gcc ./configure --prefix=$PWD/build/ --host=mips64-nlm-linux --with-openssl-dir=/home/liudanny/git/openssl-1.0.1e/build --disable-ipv6 --with-openssl-dir=/home/liudanny/git/openssl-1.0.1e/build --with-zlib-dir=/home/liudanny/git/zlib-1.2.5/build --with-ldap-dir=/home/liudanny/git/openldap-2.4.39/mybuild 2>&1 | tee config.out
>make 2>&1 | tee make.out; make install

No comments: