]> matita.cs.unibo.it Git - helm.git/blob - helm/software/myocamlbuild.ml
Preparing for 0.5.9 release.
[helm.git] / helm / software / myocamlbuild.ml
1 open Ocamlbuild_plugin
2 open Command (* no longer needed for OCaml >= 3.10.2 *)
3
4 (* these functions are not really officially exported *)
5 let run_and_read = Ocamlbuild_pack.My_unix.run_and_read
6 let blank_sep_strings = Ocamlbuild_pack.Lexers.blank_sep_strings
7
8 (* this lists all supported packages *)
9 let find_packages () =
10   blank_sep_strings &
11     Lexing.from_string &
12       run_and_read "ocamlfind list | cut -d' ' -f1"
13
14 (* this is supposed to list available syntaxes, but I don't know how to do it. *)
15 let find_syntaxes () = ["camlp4o"; "camlp4r"]
16
17 (* ocamlfind command *)
18 let ocamlfind x = S[A"ocamlfind"; x]
19
20 let _ = dispatch begin function
21    | Before_options ->
22        (* by using Before_options one let command line options have an higher priority *)
23        (* on the contrary using After_options will guarantee to have the higher priority *)
24
25        (* override default commands by ocamlfind ones *)
26        Options.ocamlc     := ocamlfind & A"ocamlc";
27        Options.ocamlopt   := ocamlfind & A"ocamlopt";
28        Options.ocamldep   := ocamlfind & A"ocamldep";
29        Options.ocamldoc   := ocamlfind & A"ocamldoc";
30        Options.ocamlmktop := ocamlfind & A"ocamlmktop"
31
32    | After_rules ->
33
34        (* When one link an OCaml library/binary/package, one should use -linkpkg *)
35        flag ["ocaml"; "link"] & A"-linkpkg";
36
37        (* For each ocamlfind package one inject the -package option when
38         * compiling, computing dependencies, generating documentation and
39         * linking. *)
40        List.iter begin fun pkg ->
41          flag ["ocaml"; "compile";  "pkg_"^pkg] & S[A"-package"; A pkg];
42          flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
43          flag ["ocaml"; "doc";      "pkg_"^pkg] & S[A"-package"; A pkg];
44          flag ["ocaml"; "link";     "pkg_"^pkg] & S[A"-package"; A pkg];
45        end (find_packages ());
46
47        (* Like -package but for extensions syntax. Morover -syntax is useless
48         * when linking. *)
49        List.iter begin fun syntax ->
50          flag ["ocaml"; "compile";  "syntax_"^syntax] & S[A"-syntax"; A syntax];
51          flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
52          flag ["ocaml"; "doc";      "syntax_"^syntax] & S[A"-syntax"; A syntax];
53        end (find_syntaxes ());
54        
55        (* The default "thread" tag is not compatible with ocamlfind.
56           Indeed, the default rules add the "threads.cma" or "threads.cmxa"
57           options when using this tag. When using the "-linkpkg" option with
58           ocamlfind, this module will then be added twice on the command line.
59        
60           To solve this, one approach is to add the "-thread" option when using
61           the "threads" package using the previous plugin.
62         *)
63        flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
64        flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"])
65        
66    | _ -> ()
67 end