OCamlbuild and camlp4 options
Asked Answered
U

2

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.

Unlearn answered 18/4, 2012 at 14:18 Comment(0)
L
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 ...
Ledge answered 18/4, 2012 at 21:31 Comment(0)
C
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.

Curve answered 18/4, 2012 at 17:6 Comment(2)
But won't I have to repeat the exact same statement but with s/compile/dep/ ? Is there a way to avoid the repetition?Unlearn
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.Curve

© 2022 - 2024 — McMap. All rights reserved.