build with ocamlbuild by default
[deriving.git] / myocamlbuild.ml
blob6938493d8e41afce397aa9d144342d7716ae9fe4
1 open Printf
2 open Ocamlbuild_plugin;;
4 let mkcamlp4 prod deps =
5 let mode = match Pathname.get_extension (Pathname.mk prod) with
6 | "byte" -> `Byte
7 | "native" -> `Native
8 | _ -> failwith "mkcamlp4 can build only .byte and .native targets"
9 in
10 let ocaml = match mode with `Byte -> !Options.ocamlc | `Native -> !Options.ocamlopt in
11 let cm name = A (name ^ match mode with `Byte -> ".cmo" | `Native -> ".cmx") in
13 rule (sprintf "mkcamlp4 %s" prod) ~deps ~prod begin fun _ _ ->
14 Cmd (S[
15 ocaml;
16 A "-linkall";
17 T(tags_of_pathname prod++"link");
18 cm "Camlp4Parsers/Camlp4OCamlRevisedParser";
19 cm "Camlp4Parsers/Camlp4OCamlParser";
20 cm "Camlp4Printers/Camlp4AutoPrinter";
21 Command.atomize_paths deps;
22 A"-o"; A prod;
23 cm "Camlp4Bin";
25 end
27 let _ = dispatch begin function
28 | After_rules ->
29 flag ["pp"; "camlp4of"] & S[A"-loc"; A"loc"];
30 flag ["pp"; "camlp4orf"] & S[A"-loc"; A"loc"];
31 flag ["ocaml";"pp";"pa_deriving"] (P"pa_deriving.cma");
32 dep ["pa_deriving"] ["pa_deriving.cma"];
34 ocaml_lib "deriving";
36 mkcamlp4 "deriving.byte" ["pa_deriving.cma"];
37 mkcamlp4 "deriving.native" ["pa_deriving.cmxa"];
39 | _ -> ()
40 end;;