1

我正在学习 LLVM ocaml 教程,并使用以下命令行进行编译:

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"];;
4

2 回答 2

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 解决方案类似,但每个标签都有额外的标志,而不是一次包含所有标签。

于 2014-01-14T17:10:22.670 回答
1

-g替换为true: debugin _tags

-I理想情况下,选项应该由相应的 ocamlfind 包替换,例如调用ocamlbuild -use-ocamlfind和指定true: package(llvm,llvm_analysis)in_tags和/或调用任何其他包(并删除ocaml_lib调用 in myocamlbuild.ml)。

在旁注中,只需使用所需的Makefile任何ocamlbuild调用创建一个并运行make构建。

于 2014-01-15T05:47:41.000 回答