5

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.

Jon Smark
  • 2,528
  • 24
  • 31

2 Answers2

4

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 ...
hcarty
  • 1,671
  • 8
  • 8
3

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.

Thomas
  • 5,047
  • 19
  • 30
  • But won't I have to repeat the exact same statement but with s/compile/dep/ ? Is there a way to avoid the repetition? – Jon Smark Apr 18 '12 at 18:16
  • You are right, you may have to repeat the statement for `dep`. You can store the content of `S(...)` in a local variable if you don't want to repeat it. – Thomas Apr 18 '12 at 21:53