2007-02-07 00:59:16 -08:00
|
|
|
(***********************************************************************)
|
2012-08-01 07:47:00 -07:00
|
|
|
(* *)
|
2007-02-07 00:59:16 -08:00
|
|
|
(* ocamlbuild *)
|
|
|
|
(* *)
|
|
|
|
(* Nicolas Pouillard, Berke Durak, projet Gallium, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2007 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2015-07-28 06:18:34 -07:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../LICENSE. *)
|
2007-02-07 00:59:16 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2009-03-03 08:54:58 -08:00
|
|
|
|
2007-02-07 00:59:16 -08:00
|
|
|
(* Original author: Nicolas Pouillard *)
|
|
|
|
open My_std
|
|
|
|
open Pathname.Operators
|
|
|
|
open Tags.Operators
|
|
|
|
open Tools
|
|
|
|
open Command
|
|
|
|
open Ocaml_utils
|
|
|
|
|
2007-11-21 12:46:46 -08:00
|
|
|
let add_suffix s = List.map (fun x -> x -.- s) ;;
|
|
|
|
|
2010-01-22 06:36:57 -08:00
|
|
|
let ocamldep_command' tags =
|
2007-11-21 13:07:18 -08:00
|
|
|
let tags' = tags++"ocaml"++"ocamldep" in
|
2010-01-22 06:36:57 -08:00
|
|
|
S [!Options.ocamldep; T tags'; ocaml_ppflags (tags++"pp:dep"); A "-modules"]
|
2007-11-21 12:46:46 -08:00
|
|
|
|
2010-01-22 06:36:57 -08:00
|
|
|
let menhir_ocamldep_command' tags ~menhir_spec out =
|
2007-11-21 12:46:46 -08:00
|
|
|
let menhir = if !Options.ocamlyacc = N then V"MENHIR" else !Options.ocamlyacc in
|
|
|
|
Cmd(S[menhir; T tags; A"--raw-depend";
|
2011-07-20 02:17:07 -07:00
|
|
|
A"--ocamldep"; Quote (ocamldep_command' Tags.empty);
|
2010-01-22 04:48:24 -08:00
|
|
|
menhir_spec ; Sh ">"; Px out])
|
2007-11-21 10:32:32 -08:00
|
|
|
|
|
|
|
let menhir_ocamldep_command arg out env _build =
|
|
|
|
let arg = env arg and out = env out in
|
|
|
|
let tags = tags_of_pathname arg++"ocaml"++"menhir_ocamldep" in
|
2010-01-22 06:36:57 -08:00
|
|
|
menhir_ocamldep_command' tags ~menhir_spec:(P arg) out
|
2007-11-21 12:46:46 -08:00
|
|
|
|
2007-11-22 10:46:18 -08:00
|
|
|
let import_mlypack build mlypack =
|
2007-11-21 12:46:46 -08:00
|
|
|
let tags1 = tags_of_pathname mlypack in
|
|
|
|
let files = string_list_of_file mlypack in
|
2007-11-22 10:46:18 -08:00
|
|
|
let include_dirs = Pathname.include_dirs_of (Pathname.dirname mlypack) in
|
|
|
|
let files_alternatives =
|
|
|
|
List.map begin fun module_name ->
|
|
|
|
expand_module include_dirs module_name ["mly"]
|
|
|
|
end files
|
|
|
|
in
|
|
|
|
let files = List.map Outcome.good (build files_alternatives) in
|
2007-11-22 10:49:49 -08:00
|
|
|
let tags2 =
|
|
|
|
List.fold_right
|
2007-11-21 12:46:46 -08:00
|
|
|
(fun file -> Tags.union (tags_of_pathname file))
|
|
|
|
files tags1
|
|
|
|
in
|
|
|
|
(tags2, files)
|
|
|
|
|
2007-11-22 10:46:18 -08:00
|
|
|
let menhir_modular_ocamldep_command mlypack out env build =
|
2007-11-21 12:46:46 -08:00
|
|
|
let mlypack = env mlypack and out = env out in
|
2007-11-22 10:46:18 -08:00
|
|
|
let (tags,files) = import_mlypack build mlypack in
|
2007-11-21 12:46:46 -08:00
|
|
|
let tags = tags++"ocaml"++"menhir_ocamldep" in
|
|
|
|
let menhir_base = Pathname.remove_extensions mlypack in
|
|
|
|
let menhir_spec = S[A "--base" ; P menhir_base ; atomize_paths files] in
|
2010-01-22 06:36:57 -08:00
|
|
|
menhir_ocamldep_command' tags ~menhir_spec out
|
2007-11-21 12:46:46 -08:00
|
|
|
|
|
|
|
let menhir_modular menhir_base mlypack mlypack_depends env build =
|
|
|
|
let menhir = if !Options.ocamlyacc = N then V"MENHIR" else !Options.ocamlyacc in
|
|
|
|
let menhir_base = env menhir_base in
|
|
|
|
let mlypack = env mlypack in
|
|
|
|
let mlypack_depends = env mlypack_depends in
|
2007-11-22 10:46:18 -08:00
|
|
|
let (tags,files) = import_mlypack build mlypack in
|
2007-11-21 12:46:46 -08:00
|
|
|
let () = List.iter Outcome.ignore_good (build [[mlypack_depends]]) in
|
|
|
|
Ocaml_compiler.prepare_compile build mlypack;
|
2008-07-25 07:26:36 -07:00
|
|
|
let ocamlc_tags = tags++"ocaml"++"byte"++"compile" in
|
2007-11-21 12:46:46 -08:00
|
|
|
let tags = tags++"ocaml"++"parser"++"menhir" in
|
|
|
|
Cmd(S[menhir ;
|
2008-07-25 07:26:36 -07:00
|
|
|
A "--ocamlc"; Quote(S[!Options.ocamlc; T ocamlc_tags; ocaml_include_flags mlypack]);
|
2014-11-18 01:35:41 -08:00
|
|
|
T tags ; A "--base" ; Px menhir_base ; atomize_paths files])
|
2007-11-21 10:32:32 -08:00
|
|
|
|
|
|
|
let ocamldep_command arg out env _build =
|
|
|
|
let arg = env arg and out = env out in
|
2007-11-21 12:46:46 -08:00
|
|
|
let tags = tags_of_pathname arg in
|
2010-01-22 06:36:57 -08:00
|
|
|
Cmd(S[ocamldep_command' tags; P arg; Sh ">"; Px out])
|
2007-11-21 10:32:32 -08:00
|
|
|
|
2007-02-07 00:59:16 -08:00
|
|
|
let ocamlyacc mly env _build =
|
|
|
|
let mly = env mly in
|
2007-10-08 07:19:34 -07:00
|
|
|
let ocamlyacc = if !Options.ocamlyacc = N then V"OCAMLYACC" else !Options.ocamlyacc in
|
2010-01-22 06:36:57 -08:00
|
|
|
Cmd(S[ocamlyacc; T(tags_of_pathname mly++"ocaml"++"parser"++"ocamlyacc"); Px mly])
|
2007-02-07 00:59:16 -08:00
|
|
|
|
|
|
|
let ocamllex mll env _build =
|
|
|
|
let mll = env mll in
|
2010-01-22 06:36:57 -08:00
|
|
|
Cmd(S[!Options.ocamllex; T(tags_of_pathname mll++"ocaml"++"lexer"++"ocamllex"); Px mll])
|
2007-02-07 00:59:16 -08:00
|
|
|
|
|
|
|
let infer_interface ml mli env build =
|
|
|
|
let ml = env ml and mli = env mli in
|
2007-10-08 07:19:34 -07:00
|
|
|
let tags = tags_of_pathname ml++"ocaml" in
|
2007-02-07 00:59:16 -08:00
|
|
|
Ocaml_compiler.prepare_compile build ml;
|
2007-10-08 07:19:34 -07:00
|
|
|
Cmd(S[!Options.ocamlc; ocaml_ppflags tags; ocaml_include_flags ml; A"-i";
|
2011-08-08 02:39:10 -07:00
|
|
|
(if Tags.mem "thread" tags then A"-thread" else N);
|
2007-10-08 07:19:34 -07:00
|
|
|
T(tags++"infer_interface"); P ml; Sh">"; Px mli])
|
2007-02-07 00:59:16 -08:00
|
|
|
|
|
|
|
let menhir mly env build =
|
|
|
|
let mly = env mly in
|
2015-04-11 10:40:27 -07:00
|
|
|
let ml = Pathname.update_extension "ml" mly in
|
2007-10-08 07:19:34 -07:00
|
|
|
let menhir = if !Options.ocamlyacc = N then V"MENHIR" else !Options.ocamlyacc in
|
2015-04-11 10:40:27 -07:00
|
|
|
let ocamlc_tags = tags_of_pathname ml ++"ocaml"++"byte"++"compile" in
|
|
|
|
let menhir_tags = tags_of_pathname mly ++"ocaml"++"parser"++"menhir" in
|
2007-02-07 00:59:16 -08:00
|
|
|
Ocaml_compiler.prepare_compile build mly;
|
2007-10-08 07:19:34 -07:00
|
|
|
Cmd(S[menhir;
|
2012-09-21 08:16:24 -07:00
|
|
|
A"--ocamlc"; Quote(S[!Options.ocamlc; T ocamlc_tags; ocaml_include_flags mly]);
|
2014-11-18 01:35:41 -08:00
|
|
|
T menhir_tags; Px mly])
|
2007-02-07 00:59:16 -08:00
|
|
|
|
|
|
|
let ocamldoc_c tags arg odoc =
|
|
|
|
let tags = tags++"ocaml" in
|
|
|
|
Cmd (S [!Options.ocamldoc; A"-dump"; Px odoc; T(tags++"doc");
|
2010-01-22 06:36:57 -08:00
|
|
|
ocaml_ppflags (tags++"pp:doc");
|
2007-02-07 00:59:16 -08:00
|
|
|
ocaml_include_flags arg; P arg])
|
|
|
|
|
2007-02-08 08:53:39 -08:00
|
|
|
let ocamldoc_l_dir tags deps _docout docdir =
|
|
|
|
Seq[Cmd (S[A"rm"; A"-rf"; Px docdir]);
|
|
|
|
Cmd (S[A"mkdir"; A"-p"; Px docdir]);
|
|
|
|
Cmd (S [!Options.ocamldoc;
|
|
|
|
S(List.map (fun a -> S[A"-load"; P a]) deps);
|
|
|
|
T(tags++"doc"++"docdir"); A"-d"; Px docdir])]
|
|
|
|
|
|
|
|
let ocamldoc_l_file tags deps docout _docdir =
|
|
|
|
Seq[Cmd (S[A"rm"; A"-rf"; Px docout]);
|
|
|
|
Cmd (S[A"mkdir"; A"-p"; Px (Pathname.dirname docout)]);
|
2007-02-07 00:59:16 -08:00
|
|
|
Cmd (S [!Options.ocamldoc;
|
|
|
|
S(List.map (fun a -> S[A"-load"; P a]) deps);
|
2007-02-08 08:53:39 -08:00
|
|
|
T(tags++"doc"++"docfile"); A"-o"; Px docout])]
|
2007-02-07 00:59:16 -08:00
|
|
|
|
|
|
|
let document_ocaml_interf mli odoc env build =
|
|
|
|
let mli = env mli and odoc = env odoc in
|
|
|
|
Ocaml_compiler.prepare_compile build mli;
|
|
|
|
ocamldoc_c (tags_of_pathname mli++"interf") mli odoc
|
|
|
|
|
2007-11-21 10:20:41 -08:00
|
|
|
let document_ocaml_implem ml odoc env build =
|
|
|
|
let ml = env ml and odoc = env odoc in
|
|
|
|
Ocaml_compiler.prepare_compile build ml;
|
|
|
|
ocamldoc_c (tags_of_pathname ml++"implem") ml odoc
|
|
|
|
|
2007-02-08 08:53:39 -08:00
|
|
|
let document_ocaml_project ?(ocamldoc=ocamldoc_l_file) odocl docout docdir env build =
|
|
|
|
let odocl = env odocl and docout = env docout and docdir = env docdir in
|
2007-02-07 00:59:16 -08:00
|
|
|
let contents = string_list_of_file odocl in
|
|
|
|
let include_dirs = Pathname.include_dirs_of (Pathname.dirname odocl) in
|
|
|
|
let to_build =
|
|
|
|
List.map begin fun module_name ->
|
|
|
|
expand_module include_dirs module_name ["odoc"]
|
|
|
|
end contents in
|
|
|
|
let module_paths = List.map Outcome.good (build to_build) in
|
2007-02-08 08:53:39 -08:00
|
|
|
let tags = (Tags.union (tags_of_pathname docout) (tags_of_pathname docdir))++"ocaml" in
|
|
|
|
ocamldoc tags module_paths docout docdir
|
2008-07-25 08:06:47 -07:00
|
|
|
|
|
|
|
let camlp4 ?(default=A"camlp4o") tag i o env build =
|
|
|
|
let ml = env i and pp_ml = env o in
|
|
|
|
let tags = tags_of_pathname ml++"ocaml"++"pp"++tag in
|
|
|
|
let _ = Rule.build_deps_of_tags build tags in
|
|
|
|
let pp = Command.reduce (Flags.of_tags tags) in
|
|
|
|
let pp =
|
|
|
|
match pp with
|
|
|
|
| N -> default
|
|
|
|
| _ -> pp
|
|
|
|
in
|
|
|
|
Cmd(S[pp; P ml; A"-printer"; A"o"; A"-o"; Px pp_ml])
|