2 open Command (* no longer needed for OCaml >= 3.10.2 *)
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
8 (* this lists all supported packages *)
12 run_and_read "ocamlfind list | cut -d' ' -f1"
14 (* this is supposed to list available syntaxes, but I don't know how to do it. *)
15 let find_syntaxes () = ["camlp4o"; "camlp4r"]
17 (* ocamlfind command *)
18 let ocamlfind x = S[A"ocamlfind"; x]
20 let _ = dispatch begin function
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 *)
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"
34 (* When one link an OCaml library/binary/package, one should use -linkpkg *)
35 flag ["ocaml"; "link"] & A"-linkpkg";
37 (* For each ocamlfind package one inject the -package option when
38 * compiling, computing dependencies, generating documentation and
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 ());
47 (* Like -package but for extensions syntax. Morover -syntax is useless
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 ());
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.
60 To solve this, one approach is to add the "-thread" option when using
61 the "threads" package using the previous plugin.
63 flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
64 flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"])