How to create an OCaml cross compiler

After finding a way to generate the appropriate configuration files for the target machine, the cross-compiler itself must still be built. The 1 1/2 build approach described here (and, in more detail, here ) does not seem to work if the host and target systems are too different. Here is the modified part of the script assembly (which can be obtained using $ svn cat svn://svn.psellos.com/trunk/ocamlxarm/3.1/xarm-build )

 # Small steps config1 () { # Configure for building bytecode interpreter to run on Intel OS X. # But specify * architecture for assembly and partial link. echo 'xarm-build: ----- configure phase 1 -----' ./configure \ -prefix "" \ -no-curses \ -no-tk \ -no-graph \ -as "" \ -aspp ""\ -partialld "" # Post-modify config/Makefile to select the * back end for # ocamlopt (to generate * assembly code). $SED -i'.bak'\ -e '1i\# modified by xarm-build for OCamlXARM' \ -e 's/^ARCH[ ]*=.*/ARCH=/' \ -e 's/^MODEL[ ]*=.*/MODEL=/' \ config/Makefile #-e 's/^SYSTEM[ ]*=.*/SYSTEM=/' \ $SED -i'.bak'\ -e '1i\/* modified by xarm-build for OCamlXARM*/' \ -e 's/^#define[ ][ ]*HAS_STACK_OVERFLOW_DETECTION.*$//' \ config/sh # Post-modify utils/config.ml to tell ocamlopt to create * # binaries for itself. Also tell ocamlc and ocamlopt to use * # architecture when compiling C files. make utils/config.ml $SED -i'.bak'\ -e 's#let[ ][ ]*mkexe[ ]*=.*#let mkexe ="'"$CC"'"#' \ -e 's#let[ ][ ]*bytecomp_c_compiler[ ]*=.*#let bytecomp_c_compiler ="'"$CC"'"#' \ -e 's#let[ ][ ]*native_c_compiler[ ]*=.*#let native_c_compiler ="'"$CC"'"#' \ utils/config.ml } build1 () { # Don't assemble asmrun/*.S for Phase 1 build. Modify Makefile # temporarily to disable. Be really sure to put back for Phase 2. echo 'xarm-build: ----- build phase 1 -----' trap 'mv -f asmrun/Makefile.aside asmrun/Makefile' EXIT mv -f asmrun/Makefile asmrun/Makefile.aside $SED -e '/^[ ]*ASMOBJS[ ]*=/s/^/#/' \ -e 's#^include[ ][ ]*../config/Makefile#include ../config/Target/Makefile#' \ asmrun/Makefile.aside > asmrun/Makefile make world && make opt mv -f asmrun/Makefile.aside asmrun/Makefile trap - EXIT } 

The compilation is stuck in the stdlib subfolder, where the call statement is not executed.

 let loc_external_arguments = match Config.system with | "rhapsody" -> poweropen_external_conventions 0 7 100 112 | "elf" | "bsd" -> calling_conventions 0 7 100 107 outgoing 8 | _ -> assert false 

To get to this point, amsrun / Makefile had to be modified to use toolchain cross-compilation, and HAS_STACK_OVERFLOW_DETECTION had to be removed from config / sh, since amsrun / signals_asm.c could not be compiled otherwise.

So, is there a way to make this work or other approaches in this way better suited (and work with 4.00.0 OCaml release)?

+48
ocaml cross-compiling
Oct. 14 '12 at 19:55
source share
1 answer

The question itself was answered ... in a rather strange way. What he really requested (in 2012) was cross-compiler targeting (unspecified version) iOS for version 4.x Ocaml. And the code dump in this question tried to use the cross-compilation commands of Jeffrey Scofield and the script (ocamlxarm / 3.1) for Ocaml 3.1.x, which didn’t quite work for Ocaml 4.0. But Scofield ’s contacted questions website was updated in the meantime (the last in December 2014) to actually provide a solution for Ocaml 4.0 (currently ocaml-4.01.0 + xarm-4.0.2-v7 ), thereby asking the question asked here ("is there a way to make this work") controversial or rather trivial. Or:

  • Download the pre-created ocaml-4.01.0 + xarm-4.0.2-v7.dmg package, which is currently provided on this web page. Be sure to read the instructions for use and simplify your life using your cross-compiling shell script , which allows you to switch between iOS 7 and 8 goals. Or if you somehow still need to build the Ocaml cross compiler from sources ...
  • Follow the instructions in the "Application: Building from Sources" section of the page (there seems to be no HTML anchor for it). Unfortunately, these instructions contain twelve paragraphs (9 KB of text), so I'm not going to copy them. They include a link to the necessary fixes for cross-compiling OCaml 4.0.1 on iOS. We hope that on this web page exactly those steps are written that were used to create the aforementioned ocaml-4.01.0 + xarm-4.0.2-v7.dmg. However, since this dmg package does not have the Apple RedHat-style SRPM equivalent (maybe Apple has equivalent technology?), It is not possible to fully verify that the steps used to create the above dmg are fully reproduced on this web page. I have not tried myself to follow these steps to make sure that they work.

But, nevertheless, I think that the question asked here is basically resolved in the general sense of β€œis there a way to do this work” by downloading pre-created versions 4.0.1 from the Scofield web page ... linked directly to the question . Problems with the Scofield ocamlxarm build system version 3.1 that are unable to cross-compile Ocaml 4.0 should be the proverbial stuff that no one cares about. If there are problems with Scofield instructions or fixes for 4.0 that do not work, they should be asked separately, I think, because the nitty gritty errors from the question here seem out of place for this scenario.

(And if the above seems too pedantic, basically at the request of the mods, I expanded my answer to its current state.)

Although the OP probably does not care about what I am going to say in this paragraph, given how general the title of the question is, I will also indicate that there is a fairly recent project supporting OCaml Android cross-compiler targeting called opam-android . And it has all of its building bits like scripts in the git repository, so it might be easier to steal-how-it-done. Comparing the patches of these two cross-compilers, not much can be said in general how to make OCaml work as a cross-compiler, except: you need to hack it for a specific target platform. One thing I will say is that the Scofield iOS patch is much more invasive (and much longer) than the Android patches. Many Scofield fixes are associated with register code generation. I don’t know enough about the internal components of iOS to say why these changes were necessary for iOS, but not for Android, even basically they use the same ARM processor family. Perhaps someone should ask about this as a really interesting / non-trivial question, which is likely to be happy to answer the question of Jeffrey Scofield.

+5
Jan 11 '15 at 7:48
source share



All Articles