From 76c9254dec599df2394de33f49a726901dec60f5 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 4 Nov 2014 15:21:09 +0100 Subject: [PATCH] thanks to @whitequark, could use cppo for preprocessing files --- AUTHORS.md | 2 +- _oasis | 2 +- configure | 4 ++-- myocamlbuild.ml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 myocamlbuild.ml diff --git a/AUTHORS.md b/AUTHORS.md index 0e5a2e95..61fe076f 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -4,4 +4,4 @@ - Drup (Gabriel Radanne) - Jacques-Pascal Deplaix - Nicolas Braud-Santoni - +- Whitequark (Peter Zotov) diff --git a/_oasis b/_oasis index 23032165..ff9b90c0 100644 --- a/_oasis +++ b/_oasis @@ -8,7 +8,7 @@ LicenseFile: LICENSE Plugins: META (0.3), DevFiles (0.3) OCamlVersion: >= 4.00.1 BuildTools: ocamlbuild -AlphaFeatures: compiled_setup_ml +AlphaFeatures: ocamlbuild_more_args, compiled_setup_ml Synopsis: A modular standard library focused on data structures. Description: diff --git a/configure b/configure index 42fb4c31..d2a26d17 100755 --- a/configure +++ b/configure @@ -1,7 +1,7 @@ #!/bin/sh # OASIS_START -# DO NOT EDIT (digest: 82230d61386befb40bc7377608e1f16e) +# DO NOT EDIT (digest: 6f7b8221311e800a7093dc3b793f67ca) set -e FST=true @@ -23,5 +23,5 @@ for i in "$@"; do esac done -make configure CONFIGUREFLAGS="$@" +make configure CONFIGUREFLAGS="$*" # OASIS_STOP diff --git a/myocamlbuild.ml b/myocamlbuild.ml new file mode 100644 index 00000000..06976423 --- /dev/null +++ b/myocamlbuild.ml @@ -0,0 +1,47 @@ +(* OASIS_START *) +(* OASIS_STOP *) + +open Ocamlbuild_plugin;; + +dispatch + (MyOCamlbuildBase.dispatch_combine [ + begin function + | After_rules -> + (* replace with Ocamlbuild_cppo.dispatch when 4.00 is not supported + anymore *) + let dep = "%(name).cppo.ml" in + let prod1 = "%(name: <*> and not <*.cppo>).ml" in + let prod2 = "%(name: <**/*> and not <**/*.cppo>).ml" in + let f 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 "cppo1" ~dep ~prod:prod1 (f prod1) ; + rule "cppo2" ~dep ~prod:prod2 (f prod2) ; + 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]); + (* end replace *) + + let major, minor = Scanf.sscanf Sys.ocaml_version "%d.%d.%d" + (fun major minor patchlevel -> major, minor) + in + let ocaml_major = "OCAML_MAJOR " ^ string_of_int major in + let ocaml_minor = "OCAML_MINOR " ^ string_of_int minor in + + flag ["cppo"] & S[A"-D"; A ocaml_major; A"-D"; A ocaml_minor] + | _ -> () + end; + dispatch_default + ])