2011-07-25 13:30:42 +00:00
|
|
|
(*
|
|
|
|
* myocamlbuild.ml
|
|
|
|
* ---------------
|
|
|
|
* Copyright : (c) 2011, Jeremie Dimino <jeremie@dimino.org>
|
|
|
|
* Licence : BSD3
|
|
|
|
*
|
|
|
|
* This file is a part of utop.
|
|
|
|
*)
|
|
|
|
|
|
|
|
(* OASIS_START *)
|
|
|
|
(* OASIS_STOP *)
|
|
|
|
|
|
|
|
let () =
|
|
|
|
dispatch
|
|
|
|
(fun hook ->
|
|
|
|
dispatch_default hook;
|
|
|
|
match hook with
|
|
|
|
| Before_options ->
|
|
|
|
Options.make_links := false
|
|
|
|
|
|
|
|
| After_rules ->
|
|
|
|
(* Use -linkpkg for creating toplevels *)
|
|
|
|
flag ["ocaml"; "link"; "toplevel"] & A"-linkpkg";
|
|
|
|
|
2011-08-03 17:55:30 +00:00
|
|
|
(* Optcomp *)
|
|
|
|
flag ["ocaml"; "compile"; "pa_optcomp"] & S[A"-ppopt"; A "syntax/pa_optcomp.cmo"];
|
|
|
|
flag ["ocaml"; "ocamldep"; "pa_optcomp"] & S[A"-ppopt"; A "syntax/pa_optcomp.cmo"];
|
|
|
|
flag ["ocaml"; "doc"; "pa_optcomp"] & S[A"-ppopt"; A "syntax/pa_optcomp.cmo"];
|
|
|
|
dep ["ocaml"; "ocamldep"; "pa_optcomp"] ["syntax/pa_optcomp.cmo"];
|
|
|
|
|
2011-07-25 13:30:42 +00:00
|
|
|
let env = BaseEnvLight.load () in
|
2011-08-03 17:00:52 +00:00
|
|
|
let path = BaseEnvLight.var_get "compiler_libs" env in
|
|
|
|
let stdlib = BaseEnvLight.var_get "standard_library" env in
|
2011-07-25 13:30:42 +00:00
|
|
|
|
|
|
|
(* Add directories for compiler-libraries: *)
|
2011-08-03 17:31:44 +00:00
|
|
|
let paths = List.filter Sys.file_exists [path; path / "typing"; path / "parsing"; path / "utils"] in
|
|
|
|
let paths = List.map (fun path -> S[A "-I"; A path]) paths in
|
2011-07-25 13:30:42 +00:00
|
|
|
List.iter
|
|
|
|
(fun stage -> flag ["ocaml"; stage; "use_compiler_libs"] & S paths)
|
|
|
|
["compile"; "ocamldep"; "doc"; "link"];
|
|
|
|
|
|
|
|
(* Expunge compiler modules *)
|
|
|
|
rule "toplevel expunge"
|
2011-07-26 18:43:10 +00:00
|
|
|
~dep:"%.top"
|
|
|
|
~prod:"%.byte"
|
|
|
|
(fun env _ ->
|
2011-07-25 13:30:42 +00:00
|
|
|
(* Build the list of dependencies. *)
|
|
|
|
let deps = Findlib.topological_closure [Findlib.query "lambda-term";
|
2011-07-31 16:50:14 +00:00
|
|
|
Findlib.query "findlib";
|
|
|
|
Findlib.query "threads"] in
|
2011-07-25 13:30:42 +00:00
|
|
|
(* Build the set of locations of dependencies. *)
|
|
|
|
let locs = List.fold_left (fun set pkg -> StringSet.add pkg.Findlib.location set) StringSet.empty deps in
|
|
|
|
(* Directories to search for .cmi: *)
|
2011-08-03 17:00:52 +00:00
|
|
|
let directories = StringSet.add stdlib (StringSet.add (stdlib / "threads") locs) in
|
2011-07-25 13:30:42 +00:00
|
|
|
(* Construct the set of modules to keep by listing
|
|
|
|
.cmi files: *)
|
|
|
|
let modules =
|
|
|
|
StringSet.fold
|
|
|
|
(fun directory set ->
|
|
|
|
List.fold_left
|
|
|
|
(fun set fname ->
|
|
|
|
if Pathname.check_extension fname "cmi" then
|
|
|
|
StringSet.add (module_name_of_pathname fname) set
|
|
|
|
else
|
|
|
|
set)
|
|
|
|
set
|
|
|
|
(Array.to_list (Pathname.readdir directory)))
|
|
|
|
directories StringSet.empty
|
|
|
|
in
|
2011-08-03 17:00:52 +00:00
|
|
|
Cmd(S[A(stdlib / "expunge");
|
2011-07-26 18:43:10 +00:00
|
|
|
A(env "%.top");
|
|
|
|
A(env "%.byte");
|
|
|
|
A"UTop"; A"Outcometree"; A"Topdirs"; A"Toploop";
|
2011-07-25 13:30:42 +00:00
|
|
|
S(List.map (fun x -> A x) (StringSet.elements modules))]))
|
|
|
|
| _ ->
|
|
|
|
())
|
|
|
|
|