我希望添加编译 Ragel 的功能LLVM Ocaml tutorial 上下文中的源文件转换为 Ocaml 源文件。具体来说,对于具有“.rl”扩展名的源文件,我希望它执行:
ragel -O source.rl
构建系统当然应该照常编译生成的 Ocaml 文件。有什么简单的方法可以做到这一点?
这是 _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"];;
最佳答案
如果不摆弄整个源目录,就很难确定,但您必须创建一个规则来调用 ragel
编译器。 dep
告诉 ocamlbuild 将这些文件复制到 _build 目录 - 根据您的需要,此标记可能会有所不同。比如,
let ragel_files = ["file1.rl"; ... ]
let () = dispatch begin function
| After_rules ->
rule "Build RL files with Ragel"
~prod:"%.ml"
~dep:"%.rl"
begin fun env _build ->
let rl = env "%.rl" in
Cmd(S[A"ragel"; A"-0"; A rl;])
end;
dep ["compile"; "ocaml"] ragel_files;
end
查看 rules on OCaml files 的 ocamlbuild
源代码。这应该是一个非常好的开始。
关于ocaml - 将构建工具添加到 ocamlbuild 项目 (Ragel),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21115335/