Jon Smark
Jon Smark

Reputation: 2608

Passing options to camlp4 with ocamlbuild

I'm using ocamlbuild's native support for ocamlfind to simplify my project's build process. File foo.ml relies on conditional compilation using camlp4's macros. The _tags file contains the following:

<foo.ml>: package(camlp4.macro), syntax(camlp4o)

This works well, but I'm having trouble passing options to camlp4. Without using the ocamlbuild+ocamlfind automation, the command line would be something as this:

camlp4o pa_macro.cmo -DFOO file.ml

But how can I pass camlp4 the -DFOO variable when using ocamlbuild+ocamlfind? I feel there should be a simple command line option, instead of having to mess with myocamlbuild.ml.

Upvotes: 3

Views: 487

Answers (1)

ygrek
ygrek

Reputation: 6697

You gonna mess with myocamlbuild.ml. There is no builtin rule to insert -ppopt so it is rather verbose, but simple.

myocamlbuild.ml :

open Ocamlbuild_plugin ;;
dispatch begin function
| After_rules ->
pflag ["ocaml";"compile";] "define" (fun s -> S [A"-ppopt"; A ("-D"^s)]);
pflag ["ocaml";"ocamldep";] "define" (fun s -> S [A"-ppopt"; A ("-D"^s)])
| _ -> ()
end;;

In _tags:

"foo.ml": syntax(camlp4o), package(camlp4.macro), define(FOO)

Upvotes: 5

Related Questions