I'm using camlp4.macro to enable conditional compilation. I'm having problems informing OCamlbuild that certain files tagged with "use_jscore" must be preprocessed with a given camlp4 option. Here's what I have currently:
let _ = dispatch begin function
| After_rules ->
flag ["ocaml"; "use_jscore"] (S[A"-package"; A"camlp4.macro"; A"-syntax"; A"camlp4o"; A"-ppopt"; A"-DUSE_JSCORE"]);
But this gets escaped all wrong by OCamlbuild. I'm using ocamlfind, so basically what I want to tell OCamlbuild is that all OCaml files tagged with "use_jscore" must be preprocessed by camlp4.macro which is also given the -DUSE_JSCORE option.
A _tags and command line approach should work as well, although it won't target individual files.
Contents of _tags:
<*.*>: syntax(camlp4o), package(camlp4.macro)
Command line:
ocamlbuild -use-ocamlfind -cflags -ppopt,-DUSE_JSCORE ...
You are missing an flag in the list of flag you are matching with:
let options = S[...] in
flag ["ocaml"; "compile"; "use_jscore"] options;
flag ["ocaml"; "ocamldep"; "use_jscore"] options
Indeed, you want to use your camlp4 options only when you compute the dependencies (where the "ocamldep" flag is enabled) and compile (where the "compile" flag is enabled), but not when you use a preprocessor (where the "pp" flag is enabled) or when you link (when the "link" flag is enabled).
So now if you use ocamlbuild -use-ocamlfind <target>
it should work correctly.
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