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?
Here's one way to do it using myocamlbuild.ml and _tags.
In myocamlbuild.ml, add a flag
instruction to let ocamlbuild recognize a new tag - here keep_asm - which will enable -S
for selected files when compiling to native:
flag ["ocaml";"compile";"native";"keep_asm"] (S [A "-S"]);
Without the "native"
string in the list passed to flag
, the flag would be enabled for any compilation stage using ocaml (as indicated by the strings "ocaml"
and "compile"
), and would trigger when ocamlc is invoked, which you don't want.
So, for a complete stand alone myocamlbuild.ml doing only the above, this would turn out as:
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've got that new tag defined, you may use it in your _tags file as with any other tag, for instance:
<myfile.ml>: use_bigarray, keep_asm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With