我需要构建一个OCaml交叉编译器。可悲的是,它似乎不支持开箱即用,需要一些小小的工作,as described用于旧版OCaml compiler。
我的第一个问题是:什么是生成的文件配置/莫氏硬度,配置/ S.H和配置/ Makefile文件的好方法?构建OCaml交叉编译器 - 配置零件
回答
使用修改后的配置“链”可以生成文件。Ocamls配置脚本假定它可以在同一次运行中编译和执行结果,这在交叉编译环境中是不可能的。
因此必须修改配置过程,以便编译结果(包括可执行文件)被存储并可以在目标机器的第二次运行中使用。这是显示修改(〜200行)的diff文件。
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
配置脚本获取新的-cross
选项。当cc
是它的参数时,它只编译,当它是run
时,它只执行编译的东西。中间结果存储在config/auto-aux/map_ {hasgot,runtest}中,大多数使用setValue
和getValueExit
进行检索,两者都在config/auto-aux/keyval.sh中定义。如果一个与供给交工具链数据
-cc
,-as
,-aspp
,-partialld
,-libs
,-dllibs
,-dldefs
生成文件应该是可用的。最后,文件keyval.sh
,其内容是不是在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
}
如果使用tk
,一个必须修改配置/自动AUX /的runTest,并与它的版本号替换0.0
。此外,如果将solaris用作目标机器或主机器,则可能需要修改文件config/auto-aux/solaris-ld。
我几年来一直在构建OCaml交叉编译器。 (请参阅我的个人资料以获取到我的网站的链接。)我所做的是构建编译器1.5倍。第一次是主持人(有一些目标设定)。第二部分构建是为目标构建运行时。
我的用于构建从OS X到ARM/iOS的交叉编译器的脚本名为xarm-build
。如果你有颠覆,你可以从我的公共仓库中取得副本:
$ svn cat svn://svn.psellos.com/trunk/ocamlxarm/3.1/xarm-build
免责声明:现在,这个脚本只是构建编译器的字节码版本。也就是说,编译器本身是一个OCaml字节码可执行文件。但是它会为目标生成本机代码。
如果您尝试此操作并有任何问题,请告诉我。
为了回答您的具体问题,如果你的目标系统是类Unix,你可以尝试在目标上运行的configure
脚本生成config/s.h
,config/m.h
,并config/Makefile
,正如你提到的都是重要的文件。如果您的目标有模拟器,您可以在模拟器中运行configure
- 这就是我为iOS所做的。否则,你必须自己弄清楚合理的内容。 (也许在类Unix系统上运行配置,尽可能与目标类似)
- 1. 如何构建一个OCaml交叉编译器
- 2. 构建一个交叉编译器
- 3. 构建Raspberry Pi交叉编译器
- 4. 从窗口构建Qt交叉编译
- 5. Binutils在构建GCC交叉编译器时无法构建
- 6. 交叉编译器
- 7. glibc交叉编译配置错误
- 8. 关于为Xscale ARM构建交叉编译器的建议?
- 9. cuda nvcc交叉编译器
- 10. 交叉编译器d-bus
- 11. 构建交叉编译器:Intel Xeon E5649 >>> ARMv7 with libcURL
- 12. 编译警告 - ARM交叉编译器
- 13. 哪个交叉编译器?
- 14. Qt - 交叉编译
- 15. 交叉编译stunnel
- 16. Beaglebone交叉编译
- 17. 交叉编译libSDL
- 18. 交叉编译php
- 19. 构建交叉编译器的glibc在Cygwin上失败
- 20. 在debian上构建交叉编译器时出错
- 21. '构建gcc交叉编译器'是什么意思?
- 22. autotools - 交叉编译和构建本地中间构建程序
- 23. 如何使用--disable-multilib构建gcc交叉编译器
- 24. 如何配置QT创建者交叉编译
- 25. 如何使用DW2构建定制的MinGW交叉编译器
- 26. QTcreator交叉编译
- 27. 交叉编译QT
- 28. 交叉编译ldd
- 29. PowerPC架构的交叉编译Boost库
- 30. qt交叉编译
感谢您的回答。我使用ipkg提供的gcc在DiskStation上生成了这些文件,我认为这些文件尽可能接近目标系统。我也读过你的剧本,这让我感到困扰。首先一个简单的观察:您可以通过在两个配置调用中输入“-prefix $ XARMTARGET/v7”来保存4行。此外,我有点不知所措。这个'build1'中的'ocamlopt'是什么?将ocaml编译为ARM,但没有正确的工具链环境?这是用'build2'修复的?你是否隐含地使用ARM环境和i386差别不大? –
您需要构建一个为您的目标生成代码的编译器。作为一个OCaml程序,这个编译器需要一个运行在主机上的运行时(特别是一个字节码解释器)。但是,您还需要一个由编译器编译的程序的运行时。该运行时在目标上运行。既然你需要两次运行时,你必须建立两次。 (在OCaml的老版本中,'-prefix'不适用于我,如果它现在可用,很好。) –
我修改了配置脚本,以便可以用两次运行生成文件(并发布它,你会给它请稍微看一下)。我有几个问题:我注意到,在脚本的第二阶段中,您不会修改Makefile中的'RANLIB *','ARCMD'和'MKLIB'行,所以这些只在主机上使用机器(第一阶段)?对于'utils/config.ml'的修改,只需要提供正确的交叉编译器?在第二阶段,如果提供了正确的环境,就不能修改任何东西? (也许这次我应该问一个新的SO问题) –