6

I'd like to pass the -S flag to ocamlopt when building with the ocamlbuild and corebuild commands.

I understand doing ocamlbuild -cflag -S ... won't work since -S flag does only exist for ocamlopt and not ocamlc.

How can I do this using _tags files?

4

1 回答 1

4

这是使用myocamlbuild.ml_tags的一种方法。

myocamlbuild.ml中,添加一条flag指令,让 ocamlbuild 识别一个新标签 - 这里是 keep_asm - 这将在编译为native时启用-S所选文件:

flag ["ocaml";"compile";"native";"keep_asm"] (S [A "-S"]);

如果没有将"native"列表中的字符串传递给flag,则该标志将为使用ocaml的任何编译阶段启用(如字符串和所示),并且会在调用ocamlc时触发,这是您不想要的。 "ocaml""compile"

因此,对于仅执行上述操作的完整独立myocamlbuild.ml,结果如下:

open Ocamlbuild_plugin;;
open Command;;

dispatch begin function
  | Before_rules -> 
    begin
    end
  | After_rules ->
    begin
      flag ["ocaml";"compile";"native";"keep_asm"] (S [ A "-S"]);
    end
  | _ -> ()
end

一旦定义了新标签,就可以在_tags文件中使用它,就像使用任何其他标签一样,例如:

<myfile.ml>: use_bigarray, keep_asm 
于 2014-12-06T20:48:25.767 回答