This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1 @@
true: package(ocamlbuild)

View file

@ -0,0 +1,6 @@
(library
(name cppo_ocamlbuild)
(public_name cppo_ocamlbuild)
(wrapped false)
(synopsis "Cppo ocamlbuild plugin")
(libraries ocamlbuild))

View file

@ -0,0 +1,35 @@
open Ocamlbuild_plugin
let cppo_rules ext =
let dep = "%(name).cppo"-.-ext
and prod1 = "%(name: <*> and not <*.cppo>)"-.-ext
and prod2 = "%(name: <**/*> and not <**/*.cppo>)"-.-ext in
let cppo_rule prod env _build =
let dep = env dep in
let prod = env prod in
let tags = tags_of_pathname prod ++ "cppo" in
Cmd (S[A "cppo"; T tags; S [A "-o"; P prod]; P dep ])
in
rule ("cppo: *.cppo."-.-ext^" -> *."-.-ext) ~dep ~prod:prod1 (cppo_rule prod1);
rule ("cppo: **/*.cppo."-.-ext^" -> **/*."-.-ext) ~dep ~prod:prod2 (cppo_rule prod2)
let dispatcher = function
| After_rules -> begin
List.iter cppo_rules ["ml"; "mli"; "mlpack"];
pflag ["cppo"] "cppo_D" (fun s -> S [A "-D"; A s]) ;
pflag ["cppo"] "cppo_U" (fun s -> S [A "-U"; A s]) ;
pflag ["cppo"] "cppo_I" (fun s ->
if Pathname.is_directory s then S [A "-I"; P s]
else S [A "-I"; P (Pathname.dirname s)]
) ;
pdep ["cppo"] "cppo_I" (fun s ->
if Pathname.is_directory s then [] else [s]) ;
flag ["cppo"; "cppo_q"] (A "-q") ;
flag ["cppo"; "cppo_s"] (A "-s") ;
flag ["cppo"; "cppo_n"] (A "-n") ;
pflag ["cppo"] "cppo_x" (fun s -> S [A "-x"; A s]);
pflag ["cppo"] "cppo_V" (fun s -> S [A "-V"; A s]);
flag ["cppo"; "cppo_V_OCAML"] & S [A "-V"; A ("OCAML:" ^ Sys.ocaml_version)]
end
| _ -> ()

View file

@ -0,0 +1,9 @@
(** [cppo_rules extension] will add rules to Ocamlbuild so that
cppo is applied to files ending in "cppo.[extension]".
By default rules are inserted for files ending with "ml", "mli" and
"mlpack". *)
val cppo_rules : string -> unit
val dispatcher : Ocamlbuild_plugin.hook -> unit