2012-10-04 202 views

回答

1

使用修改後的配置「鏈」可以生成文件。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}中,大多數使用setValuegetValueExit進行檢索,兩者都在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

7

我幾年來一直在構建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.hconfig/m.h,並config/Makefile,正如你提到的都是重要的文件。如果您的目標有模擬器,您可以在模擬器中運行configure - 這就是我爲iOS所做的。否則,你必須自己弄清楚合理的內容。 (也許在類Unix系統上運行配置,儘可能與目標類似)

+0

感謝您的回答。我使用ipkg提供的gcc在DiskStation上生成了這些文件,我認爲這些文件儘可能接近目標系統。我也讀過你的劇本,這讓我感到困擾。首先一個簡單的觀察:您可以通過在兩個配置調用中輸入「-prefix $ XARMTARGET/v7」來保存4行。此外,我有點不知所措。這個'build1'中的'ocamlopt'是什麼?將ocaml編譯爲ARM,但沒有正確的工具鏈環境?這是用'build2'修復的?你是否隱含地使用ARM環境和i386差別不大? –

+0

您需要構建一個爲您的目標生成代碼的編譯器。作爲一個OCaml程序,這個編譯器需要一個運行在主機上的運行時(特別是一個字節碼解釋器)。但是,您還需要一個由編譯器編譯的程序的運行時。該運行時在目標上運行。既然你需要兩次運行時,你必須建立兩次。 (在OCaml的老版本中,'-prefix'不適用於我,如果它現在可用,很好。) –

+0

我修改了配置腳本,以便可以用兩次運行生成文件(併發布它,你會給它請稍微看一下)。我有幾個問題:我注意到,在腳本的第二階段中,您不會修改Makefile中的'RANLIB *','ARCMD'和'MKLIB'行,所以這些只在主機上使用機器(第一階段)?對於'utils/config.ml'的修改,只需要提供正確的交叉編譯器?在第二階段,如果提供了正確的環境,就不能修改任何東西? (也許這次我應該問一個新的SO問題) –