Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass -S flag to ocamlopt with ocamlbuild?

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?

like image 648
Antoine Avatar asked Dec 06 '14 15:12

Antoine


1 Answers

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 
like image 186
didierc Avatar answered Sep 22 '22 05:09

didierc