2014-01-14 52 views
1

我通過LLVM ocaml tutorial工作,並使用下面的命令行編譯:ocamlbuild包括額外的軟件包

ocamlbuild -cflags -g,-I,+llvm-3.4 -lflags -I,+llvm-3.4 toy.byte 

有沒有辦法轉移這些額外的CFLAGS和LFLAGS到_tags或myocamlbuild.ml文件,以便我不需要鍵入它們/可以將它們存儲在源代碼管理中/進行可重現的構建?

這裏是_tags文件:

<{lexer,parser}.ml>: use_camlp4, pp(camlp4of) 
<*.{byte,native}>: g++, use_llvm, use_llvm_analysis 
<*.{byte,native}>: use_llvm_executionengine, use_llvm_target 
<*.{byte,native}>: use_llvm_scalar_opts, use_bindings 

這裏是myocamlbuild.ml文件:

open Ocamlbuild_plugin;; 

ocaml_lib ~extern:true "llvm";; 
ocaml_lib ~extern:true "llvm_analysis";; 
ocaml_lib ~extern:true "llvm_executionengine";; 
ocaml_lib ~extern:true "llvm_target";; 
ocaml_lib ~extern:true "llvm_scalar_opts";; 

flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++ -rdynamic"]);; 
dep ["link"; "ocaml"; "use_bindings"] ["bindings.o"];; 
+0

看看GitHub上和其他地方其他「myocamlbuild.ml」文件。這個 - 和你的另一個問題 - 很容易從這些樣本中確定。 – nlucaroni

+0

你必須有不同的定義「容易確定」比我 – brooks94

回答

2

我做這樣的事情......

let mlflags = [] 
and cflags = [] 
and clibs = [] 

let rec arg_weave p = function 
    | x::xs -> (A p) :: (A x) :: arg_weave p xs 
    | [] -> [] 
and arg x = A x 
... 
let() = dispatch begin function 
    | After_rules -> 
    flag ["ocaml"; "compile"] (S (List.map arg mlflags)); 
    flag ["c"; "compile"]  (S (arg_weave "-ccopt" cflags)); 
    flag ["c"; "link"]  (S (arg_weave "-cclib" clibs)); 
    ... 
    end 

另一種選擇是標記其他選項。例如,在ocaml_specific.ml文件他們有一個建立用於調試和對其中的選擇是相關的標誌選項的所有組合。

flag ["ocaml"; "debug"; "compile"; "byte"] (A "-g");; 
flag ["ocaml"; "debug"; "link"; "byte"; "program"] (A "-g");; 
flag ["ocaml"; "debug"; "pack"; "byte"] (A "-g");; 
flag ["ocaml"; "debug"; "compile"; "native"] (A "-g");; 
flag ["ocaml"; "debug"; "link"; "native"; "program"] (A "-g");; 
flag ["ocaml"; "debug"; "pack"; "native"] (A "-g");; 

然後,在_tags文件,你可以有true : debug打開它的所有文件,或true可以通過圖案來限制選項所取代。所以,如果一個選項不存在,你可以創建你自己的,你會看到,它類似於完全myocamlbuild.ml解決方案,但對於每一個標籤,而不是包括所有這些在一次額外的標誌。

1

-g被替換爲true: debug_tags

-I選項理想情況下應該由對應ocamlfind包,例如取代調用ocamlbuild -use-ocamlfind_tags指定true: package(llvm,llvm_analysis)和/或任何其他包被稱爲(在myocamlbuild.ml刪除ocaml_lib調用)。

在邊注,只需創建與任何需要ocamlbuild調用一個Makefile和運行make建設。

+0

對不起,我真的不明白你的答案的前兩個部分。你可以給你一個關於你在說什麼的例子:-use-ocamlfind? – brooks94

+0

makefile技巧就是我現在所擁有的。這似乎很愚蠢。 – brooks94

+0

在_tags文件中,可以將行設置爲true:debug:真true:dtypes,true:profile,true:rectypes,true:bin_annot,true:output_obj,... to打開這些特定的選項。您還可以用特定文件的模式替換「true」。這些是ocaml/ocamlbuild/ocaml_specific.ml文件中的內置標誌。 – nlucaroni

相關問題