install with ocamlfind
[deriving.git] / myocamlbuild.ml
blob96ee37526f4ad64f937592da8ee7032da1778367
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 ["ocaml";"pp";"pa_deriving"] (P"pa_deriving.cma");
31 dep ["pa_deriving"] ["pa_deriving.cma"];
33 ocaml_lib "deriving";
35 mkcamlp4 "deriving.byte" ["pa_deriving.cma"];
36 mkcamlp4 "deriving.native" ["pa_deriving.cmxa"];
38 | _ -> ()
39 end;;