Reputation: 2839
I'm trying to unleash power of two preprocessors in ocamlbuild. I tried
flag ["ocaml"; "use_m4"] (S [ A"-pp"; Px"m4 macro.m4"
; A"-pp"; Px"camlp5o pr_o.cmo camlp5/pa_gt.cmo"
]);
but for some reason it repeats options once again with -pp
option. And it is wrong.
/home/kakadu/.opam/4.03.0/bin/ocamldep.opt -pp 'm4 macro.m4' \
-pp 'camlp5o pr_o.cmo camlp5/pa_gt.cmo' \
-pp '-pp '\''m4 macro.m4'\'' -pp '\''camlp5o pr_o.cmo camlp5/pa_gt.cmo'\''' -modules test.ml > test.ml.depends
How to set flags right? And why additional option is being added?
Repo: https://github.com/Kakadu/ocamlbuild-two-pp
Upvotes: 1
Views: 81
Reputation: 35210
You didn't specify a particular stage, so you flag was applied in a wrong place. Probably this can be considered as an issue on ocamlbuild
side.
The following spell will work:
List.iter (fun stage ->
flag ["ocaml"; stage; "use_m4"]
(S [A"-pp"; A"m4 macro.m4";
A"-pp"; Px"camlp5o pr_o.cmo camlp5/pa_gt.cmo"
]))
["ocamldep"; "compile"];
At least, m4
part is working, the camlp5 file fails with an absence of the cmo
files, but this is beyond the scope of the question.
There is a kind of hackish function in Ocaml_utils
module, with the following implementation:
let ocaml_ppflags tags =
let flags = Flags.of_tags (tags++"ocaml"++"pp") in
let reduced = Command.reduce flags in
if reduced = N then N else S[A"-pp"; Quote reduced]
The function literally is doing the following: add "ocaml" and "pp" to the set of tags and get flags. If anything matched then quote the result and add it to -pp
flag)
And it is called in many rules, just in case if pp flags will jump in. I'm not sure, why it is needed at all, as the flags must be injected in one particular place with the hook. Maybe this is some local hack, that survived for too long.
So, your flag was too unconstrained and matched with this rules, as a result your parameters were pre-pp
-ed. To solve this, I added a stage to the flag constraints, so that it will be now applied only in proper time and place.
Upvotes: 1