After finding a way to generate the fitting configuration files for the target machine, the cross compiler itself must still be built. The approach using the 1 1/2 build described here (and, with more details, here) does not seem to work if the host and target systems differ too much. Here is the changed part of the build script (which can be obtained with $ 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/s.h # 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 gets stuck in the stdlib subfolder, where an assertion on calling conventions fails.
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 even get to this point, amsrun/Makefile had to be modified to use the cross compile toolchain, and the HAS_STACK_OVERFLOW_DETECTION
had to be removed from config/s.h since amsrun/signals_asm.c could not be compiled otherwise.
So is there a way to make this work, or are other approaches in this manner better suited (and work with the 4.00.0 release of OCaml)?
The question has answered itself... in a rather weird way. What it was really asking for (in 2012) was a cross-compiler targeting (an unspecified version of) iOS for version 4.x of Ocaml. And the code dump in the question was trying to use Jeffrey Scofield's cross-compiling instructions and script (ocamlxarm/3.1) for Ocaml 3.1.x, which didn't quite work for Ocaml 4.0. But Scofield's web page, which the question links to, has been updated in the meantime (last in Dec 2014) to actually provide a solution for Ocaml 4.0 (currently ocaml-4.01.0+xarm-4.0.2-v7), thus making the question as asked here ("is there a way to make this work") moot or fairly trivial. Either:
But I think nevertheless that the question asked here is basically resolved in the general sense of "is there a way to make this work" by downloading the pre-built 4.0.1 binaries from Scofield's webpage... linked right in the question. Problems with Scofield's ocamlxarm build system version 3.1 not being able to cross-compile Ocaml 4.0 should be the proverbial stuff nobody cares about at this point. If there are problems with Scofield's instructions or patches for 4.0 not working, they should be asked separately, I think, because the nitty gritty errors from the question here seem irrelevant for that scenario.
(And if the above seems overly pedantic, it was mostly by mods' request that I've expanded my answer to its present state.)
Although the OP probably doesn't care about what I'm going to say in this paragraph, given how generic his question title is, I'll point out there's also exists a fairly recent project maintaining an OCaml cross-compiler targeting Android, called opam-android. And this one has all its building bits as scripts in a git repo, so it may be easier to steal-how-it's-done from. Comparing the patches of these two cross-compilers, there's not much that can be said in general how to make OCaml work as cross-compiler other than: you need to hack it for the specific target platform. One thing I will say is that Scofield's iOS patch is a lot more invasive (and far longer) than the Android patches. A lot of Scofield's patch has to do with register-level code generation. I don't know enough about iOS internals to say why those changes were needed for iOS but not for Android, even they basically employ the same ARM CPU family. Maybe someone should ask this as an actually interesting/non-trivial question that Jeffrey Scofield himself would probably be happy to answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With