From: Stephane Glondu <steph@glondu.net>
Date: Thu, 30 Jan 2020 08:37:51 +0100
Subject: Adjust myocamlbuild to use cppo and ppx

---
 myocamlbuild.ml.in | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/myocamlbuild.ml.in b/myocamlbuild.ml.in
index 8686bae..9855800 100644
--- a/myocamlbuild.ml.in
+++ b/myocamlbuild.ml.in
@@ -47,17 +47,18 @@ let gen_def_string () =
 
 let string_flatten l = List.fold_left (fun acc s -> acc ^ " " ^ s) "" l
 
-let syntaxes () =
+let syntaxes_ppx () =
   let bitstring_entry =
-    let cmd = "@CAMLP4O@ -I @BITSTRINGLIB@ bitstring.cma \
-                bitstring_persistent.cma pa_bitstring.cmo" in
+    let cmd = "/usr/lib/ocaml/bitstring/ppx/ppx.exe --as-ppx" in
      "bitstring", cmd, cmd in
+  [ bitstring_entry ]
+
+let syntaxes_pp () =
   let s = string_flatten (gen_def_string ()) in
-  let compile_cmd = "@CAMLP4O@ Camlp4MacroParser.cmo " ^ s in
-  let doc_cmd = "./myocamlmacroparser.byte " ^ s in
-  let mymacroparser_entry = "mymacroparser",compile_cmd, doc_cmd in
+  let compile_cmd = "cppo " ^ s in
+  let mymacroparser_entry = "mymacroparser", compile_cmd, compile_cmd in
   let macro_entry = "macro", compile_cmd, compile_cmd in
-  [ bitstring_entry ; mymacroparser_entry ; macro_entry ]
+  [ macro_entry; mymacroparser_entry ]
 
 let img_doc_prod = ["circle";"rect";"ellipse";"round_rect";
                     "patatoid";"tex";"ctr";"north";"south";
@@ -206,6 +207,12 @@ let _ = dispatch begin function
         flag ["ocaml"; "compile";  "syntax_"^syntax] & S[A"-pp"; A pp];
         flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-pp"; A pp];
         flag ["ocaml"; "doc";      "syntax_"^syntax] & S[A"-pp"; A doc];)
-      (syntaxes ());
+      (syntaxes_pp ());
+
+      List.iter (fun (syntax,pp, doc) ->
+        flag ["ocaml"; "compile";  "syntax_"^syntax] & S[A"-ppx"; A pp];
+        flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-ppx"; A pp];
+        flag ["ocaml"; "doc";      "syntax_"^syntax] & S[A"-ppx"; A doc];)
+      (syntaxes_ppx ());
    | _ -> ()
 end
