How to pass -S flag for ocamlopt with ocamlbuild?

I would like to pass the -S flag to ocamlopt when creating using the ocamlbuild and corebuild commands.

I understand that ocamlbuild -cflag -S ... will not work, because the -S flag exists only for ocamlopt, not ocamlc.

How can I do this using _tags files?

+6
source share
1 answer

Here is one way to do this using myocamlbuild.ml and _tags.

In myocamlbuild.ml add the flag statement so ocamlbuild recognizes the new tag - here keep_asm - which will include -S for the selected files when compiling in native:

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

Without the "native" in the list passed to flag , the flag will be enabled for any compilation step using ocaml (as indicated by the "ocaml" and "compile" lines), and will be run when ocamlc is called, which you don’t want.

So, for a complete standalone myocamlbuild.ml that does just the above, it will turn out like:

 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 

Once you have this new tag installed, you can use it in your _tags file, like any other tag, for example:

 <myfile.ml>: use_bigarray, keep_asm 
+4
source

Source: https://habr.com/ru/post/979221/


All Articles