Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 478
Jon Smark Avatar asked Apr 18 '12 14:04

Jon Smark


2 Answers

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 ...
like image 159
hcarty Avatar answered Oct 17 '22 15:10

hcarty


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.

like image 3
Thomas Avatar answered Oct 17 '22 15:10

Thomas