OCaml cross-compiler for Android [patch]

News

- Check this: https://github.com/vouillon/opam-android-repository OCaml-Android in Opam repo (by Jerome Vouillon).

- The OCaml toplevel for Android by Romain Vernoux is out! It is an enhancement of my OCaml toplevel on Android (this).


Latest Version : OCaml 3.12.1 and Android NDK r7


Instructions

Please follow the instructions below ( simply translated from Japanese version http://www.itpl.co.jp/ocaml-nagoya/index.php?ocaml-android
Also, feel free to ask me on either email (addr is on the bottom of this page) or twitter (@keigoi)

  1. Prepare and adjust some NDK header files
    • Download the Android NDK r7 and extract it to somewhere (assume it to be <NDK_ROOT>)
    • [IMPORTANT] Remove the line #include <memory.h> in stdlib.h.
      For example, if you will support Android 1.5, remove that line in <NDK_ROOT>/platforms/android-3/arch-arm/usr/include/stdlib.h .
  2. Build the host's ocamlrun and ocamlyacc
    • Download ocaml-3.12.1 and expand it, then rename it
      tar jxf ocaml-3.12.1.tar.bz2 mv ocaml-3.12.1 ocaml-host
    • Build the host version of ocamlrun and ocamlyacc
      • Note that you must build 32 bit version even if you are using 64bit OS (Mac OS X Lion or Snow Leopard, for example).
        (see http://caml.inria.fr/pub/distrib/ocaml-3.12/notes/INSTALL)
      • Below are steps if you are using Snow Leopard. 
        cd ocaml-host ./configure -cc "gcc -m32" -as "as -arch i386" -aspp "gcc -m32 -c" pushd . cd byterun && make all && cp ocamlrun ../.. cd ../yacc && make all && cp ocamlyacc ../.. popd
  3. Patch the OCaml source tree
    • expand another source tree of OCaml, then rename it, and patch on it.
      tar jxf ocaml-3.12.1.tar.bz2 mv ocaml-3.12.1 ocaml-target cd ocaml-target patch -p1 <../ocaml-android-3.12.1-ndk_r7.patch
  4. Fix ocaml-target/config/Makefile to fit to your environment.
    ### 1. EDIT BELOW ------------------------------------ PREFIX=/usr/local/ocaml-android ## the directory where gcc stays ARM_EABI_GCC=/PATH/TO/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86 ## the directory where libgcc.a stays ARM_EABI_GCCLIB=$(ARM_EABI_GCC)/lib/gcc/arm-linux-androideabi/4.4.3 ## the directory where /usr/lib/libc.so stays ANDROID_PLATFORM=/PATH/TO/android-ndk-r7/platforms/android-3/arch-arm #ml let mklib out files opts = Printf.sprintf "/PATH/TO/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-ar rc %s %s %s; /PATH/TO/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-ranlib %s" out opts files out;; ### 1. EDIT ABOVE ------------------------------------
  5. Build the target version of ocamlrun and ocamlyacc. Then, rename it so that it does not affect the build process.
    pushd . cd byterun make all mv ocamlrun ocamlrun.target cd ../yacc make all mv ocamlyacc ocamlyacc.target popd
  6. Copy the native ocamlrun and ocamlyacc to byterun/ and yacc/, respectively.
    cp ../ocamlrun byterun/ cp ../ocamlyacc yacc/
  7. Build the rest.
    make world make opt
  8. Install it.
    make install


Test

Checking whether the bytecode interpreter works on Android

adb shell mkdir /data/local/tmp/ocaml adb push byterun/ocamlrun.target /data/local/tmp/ocaml adb push ocaml /data/local/tmp/ocaml for FILE in stdlib/*.cm[ia]; do adb push $FILE /data/local/tmp/ocaml; done adb shell cd /data/local/tmp/ocaml ./ocamlrun.target ./ocaml Objective Caml version 3.12.1 # 1. +. 1.;; - : float = 2. #

Checking native compiler

export PATH=/your/installation/path/bin:$PATH echo 'print_endline "Hello, OCaml-Android!";;' > hello.ml ocamlopt hello.ml -o hello adb push hello /data/local/tmp adb shell /data/local/tmp/hello > Hello, OCaml-Android!

Building Unison (text ui on console)

(will be reported soon. ATTN: NDK does not have pty.h.)


keigo.imai _AT_ gmail.com
Č
ċ
ď
ocaml-android-3.12.1-ndk_r7.patch
(13k)
Keigo Imai,
Feb 2, 2012, 9:42 AM
Comments