ocaml - 将构建工具添加到 ocamlbuild 项目 (Ragel)

标签 ocaml ocamlbuild

我希望添加编译 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 filesocamlbuild 源代码。这应该是一个非常好的开始。

关于ocaml - 将构建工具添加到 ocamlbuild 项目 (Ragel),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21115335/

相关文章:

haskell - 如何从功能上计算未知大小列表的连续元素之间的差异?

ocaml - 使用 Ocamlbuild 使用配置文件信息构建 native 可执行文件

ocaml - 忽略 OCaml 与 OCamlbuild 的接口(interface)

ocaml - 如何使用 Jane Street 的 Core with Reason?

windows - 奇怪的错误,我无法在 Windows 上构建 OCaml 程序

ocaml - 如何轻松地从标准输入读取行?

queue - OCaml - 如何创建队列

ocaml - 编译 ocaml-websocket 失败

compiler-construction - 用 Ocaml 编写的编译器中的表达式类型

ocaml - OCaml 中 Array.create 的奇怪之处