How to pass -S flag to ocamlopt with ocamlbuild?
Asked Answered
D

1

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?

Doings answered 6/12, 2014 at 15:29 Comment(0)
J
4

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 
Jamnes answered 6/12, 2014 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.