3

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.

Jon Smark
  • 2,528
  • 24
  • 31

1 Answers1

5

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)
ygrek
  • 6,656
  • 22
  • 29
  • Note that if you pass `-pp` and `-ppopt` to ocamlfind then it seems to ignore the value of `-ppopt`. So I had to remove the "camlp4of" tags from my ocamlbuild `_tags` file and set `-pp` in my `myocamlbuild.ml` file. – Thomas Leonard Jul 03 '13 at 15:41