Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:49:48+00:00 2026-06-12T19:49:48+00:00

I need to build an OCaml cross-compiler. Sadly, it seems this is not supported

  • 0

I need to build an OCaml cross-compiler. Sadly, it seems this is not supported out of the box and needs a little work, as described for an older version of the OCaml compiler.
My first question is: What is a nice way to generate the files config/m.h, config/s.h and config/Makefile?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:49:50+00:00Added an answer on June 12, 2026 at 7:49 pm

    With a modified configure “chain” it is possible to generate the files.
    Ocamls configure script assumes that it can compile and execute the results on the same run, which can be impossible in a cross compile environment.
    Hence the configure procedure must be modified such that the results of the compilations (including the executables) are stored and can be used in a second run on the target machine. Here is the diff file showing the modification (~200 lines).

    diff -r -U 1 ocaml-4.00.0-orig/config/auto-aux/hasgot ocaml-4.00.0-cross/config/auto-aux/hasgot
    --- ocaml-4.00.0-orig/config/auto-aux/hasgot
    +++ ocaml-4.00.0-cross/config/auto-aux/hasgot
    @@ -15,2 +15,4 @@
    
    +. ./keyval.sh
    +
     opts=""
    @@ -36,7 +38,13 @@
    
    +key="$cc $args"
    +getValueExit "$key"
    +
     if test "$verbose" = yes; then
       echo "hasgot $args: $cc $opts -o tst hasgot.c $libs" >&2
    -  exec $cc $opts -o tst hasgot.c $libs > /dev/null
    +  `exec $cc $opts -o tst hasgot.c $libs > /dev/null`
     else
    -  exec $cc $opts -o tst hasgot.c $libs > /dev/null 2>/dev/null
    +  `exec $cc $opts -o tst hasgot.c $libs > /dev/null 2>/dev/null`
     fi
    +res=$?
    +setValue "$key" "$res"
    +exit "$res"
    diff -r -U 1 ocaml-4.00.0-orig/config/auto-aux/hasgot2 ocaml-4.00.0-cross/config/auto-aux/hasgot2
    --- ocaml-4.00.0-orig/config/auto-aux/hasgot2
    +++ ocaml-4.00.0-cross/config/auto-aux/hasgot2
    @@ -15,2 +15,4 @@
    
    +. ./keyval.sh
    +
     opts=""
    @@ -36,7 +38,13 @@
    
    +key="$cc $args"
    +getValueExit "$key"
    +
     if test "$verbose" = yes; then
       echo "hasgot2 $args: $cc $opts -o tst hasgot.c $libs" >&2
    -  exec $cc $opts -o tst hasgot.c $libs > /dev/null
    +  `exec $cc $opts -o tst hasgot.c $libs > /dev/null`
     else
    -  exec $cc $opts -o tst hasgot.c $libs > /dev/null 2>/dev/null
    +  `exec $cc $opts -o tst hasgot.c $libs > /dev/null 2>/dev/null`
     fi
    +res=$?
    +setValue "$key" "$res"
    +exit "$res"
    Only in ocaml-4.00.0-cross/config/auto-aux: keyval.sh
    diff -r -U 1 ocaml-4.00.0-orig/config/auto-aux/runtest ocaml-4.00.0-cross/config/auto-aux/runtest
    --- ocaml-4.00.0-orig/config/auto-aux/runtest
    +++ ocaml-4.00.0-cross/config/auto-aux/runtest
    @@ -17,6 +17,30 @@
     echo "runtest: $cc -o tst $* $cclibs" >&2
    -$cc -o tst $* $cclibs || exit 100
    +stream=/dev/stderr
     else
    -$cc -o tst $* $cclibs 2> /dev/null || exit 100
    +stream=/dev/null
    +#$cc -o tst $* $cclibs 2> /dev/null || exit 100
     fi
    +
    +key="$* $cclibs"
    +
    +if test "$crossmode" = cross-cc; then
    +   i=`cat ./counter`
    +   $cc -o tst"$i" $* $cclibs 2> "$stream" || exit 100
    +   echo "$key"'%%#%%'tst"$i" >> ./map_runtest
    +   i=`expr $i + 1`
    +   echo "$i" > ./counter
    +   if test "$*" = sizes.c; then
    +       echo "4 4 4 2"
    +   fi
    +   if test `expr "$*" : '.*tclversion.c'` -ne 0; then
    +       echo "8.5"
    +   fi
    +   exit 0
    +fi
    +if test "$crossmode" = cross-run; then
    +   tst=`awk -v ccargs="$key" 'BEGIN {FS="%%#%%"} $1 == ccargs {print $2}' ./map_runtest`
    +   exec ./"$tst"
    +fi
    +
    +$cc -o tst $* $cclibs 2> "$stream" || exit 100
     exec ./tst
    diff -r -U 1 ocaml-4.00.0-orig/config/auto-aux/tryassemble ocaml-4.00.0-cross/config/auto-aux/tryassemble
    --- ocaml-4.00.0-orig/config/auto-aux/tryassemble
    +++ ocaml-4.00.0-cross/config/auto-aux/tryassemble
    @@ -1,8 +1,16 @@
     #!/bin/sh
    +
    +. ./keyval.sh
    +
    +key="$aspp $*"
    +getValueExit "$key"
    +
     if test "$verbose" = yes; then
     echo "tryassemble: $aspp -o tst $*" >&2
    -$aspp -o tst $* || exit 100
    +`$aspp -o tst $* || exit 100`
     else
    -$aspp -o tst $* 2> /dev/null || exit 100
    +`$aspp -o tst $* 2> /dev/null || exit 100`
     fi
    +res=$?
    +setValue "$key" "$res"
    
    @@ -11,7 +19,14 @@
     if test "$verbose" = yes; then
    +key="$as $*"
    +getValueExit "$key"
     echo "tryassemble: $as -o tst $*" >&2
    -$as -o tst $* || exit 100
    +`$as -o tst $* || exit 100`
     else
    -$as -o tst $* 2> /dev/null || exit 100
    +`$as -o tst $* 2> /dev/null || exit 100`
     fi
    +res=$?
    +setValue "$key" "$res"
    +exit $res
    +else
    +exit $res
     fi
    diff -r -U 1 ocaml-4.00.0-orig/config/auto-aux/trycompile ocaml-4.00.0-cross/config/auto-aux/trycompile
    --- ocaml-4.00.0-orig/config/auto-aux/trycompile
    +++ ocaml-4.00.0-cross/config/auto-aux/trycompile
    @@ -15,7 +15,15 @@
    
    +. ./keyval.sh
    +
    +key="$cc $* $cclibs"
    +getValueExit "$key"
    +
     if test "$verbose" = yes; then
     echo "trycompile: $cc -o tst $* $cclibs" >&2
    -$cc -o tst $* $cclibs || exit 100
    +`$cc -o tst $* $cclibs || exit 100`
     else
    -$cc -o tst $* $cclibs 2> /dev/null || exit 100
    +`$cc -o tst $* $cclibs 2> /dev/null || exit 100`
     fi
    +res=$?
    +setValue "$key" "$res"
    +exit $res
    diff -r -U 1 ocaml-4.00.0-orig/configure ocaml-4.00.0-cross/configure
    --- ocaml-4.00.0-orig/configure
    +++ ocaml-4.00.0-cross/configure
    @@ -47,2 +47,3 @@
     withcamlp4=camlp4
    +crossmode=''
    
    @@ -119,2 +120,4 @@
             withcamlp4="";;
    +    -cross|--cross)
    +       crossmode="$2"; shift;;
         *) echo "Unknown option \"$1\"." 1>&2; exit 2;;
    @@ -158,2 +161,21 @@
    
    +case "$crossmode" in
    +   cc)
    +       crossmode=cross-cc
    +       echo 0 > ./counter
    +       rm -f ./map_runtest ./map_hasgot
    +       touch ./map_runtest ./map_hasgot;;
    +   run)
    +       crossmode=cross-run
    +       if test ! -e ./map_runtest -o ! -e ./map_hasgot; then
    +           echo 'Run with -cross cc first'
    +           exit 2
    +       fi
    +       rm -f ./counter;;
    +   none) crossmode=none;;
    +   "") crossmode=none ;;
    +   *)
    +       echo 'Unknown crossmode'>&2
    +       exit 2;;
    +esac
     # Write options to Makefile
    @@ -350,3 +372,3 @@
     cc="$bytecc -O $bytecclinkopts"
    -export cc cclibs verbose
    +export cc cclibs verbose crossmode
    
    @@ -1647,2 +1669,5 @@
    
    +if test "$crossmode" = cross-run; then
    +   rm -f tst* ./map_runtest ./map_hasgot
    +fi
     # Print a summary 
    

    The configure script gets a new -cross option. When cc is its argument, it only compiles, when it is run, it only executes the compiled stuff. Intermediate results are stored in config/auto-aux/map_{hasgot,runtest}, mostly using setValue and getValueExit for retrieval, both defined in config/auto-aux/keyval.sh. If one supplies the cross toolchain data with

    -cc, -as, -aspp, -partialld, -libs, -dllibs, -dldefs

    the Makefile should be usable. Finally the file keyval.sh whose content is not in the diff:

    getValueExit()
    {
    if test "$crossmode" = cross-run; then
        res=`awk -v ccargs="$1" 'BEGIN {FS="%%#%%"} $1 == ccargs {print $2; exit}' ./map_hasgot`
        exit "$res"
    fi
    }
    
    setValue()
    {
    if test "$crossmode" = cross-cc; then
        echo "$1"'%%#%%'"$2" >> ./map_hasgot
    fi
    }
    

    If tk is used, one must modify config/auto-aux/runtest and replace 0.0 with its version number. Further, it may be necessary to modify the file config/auto-aux/solaris-ld if solaris is used as target or host machine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This I'm trying for transfer my current Apache/Modperl site to Starman, and need build
I need to build app with user messages (dialogs). I've solved this problem by
I need to build some client side code which follows this use case: An
i don't work well with C++ but now i need build a function that
I need to build a Swing GUI like this GUI Mockup http://img199.imageshack.us/img199/7271/mockupl.png where there
I need to build an url like this: /products/myproductdescription/5; it works except when the
I need to build some JSON out from PHP. The structure of the JSON
I need to build a feature like most of the banks use. Where.. if
I need to build a push system in django, basicly its function is to
I need to build a keystore with all the needed SSL certificates to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.