简体   繁体   中英

OCamlbuild and camlp4 options

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM