2014-01-14 56 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

相关问题