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 ->
|
2012-01-22 02:54:10 +00:00
|
|
|
(* Copy tags from *.byte to *.top *)
|
2012-02-11 09:21:07 +00:00
|
|
|
tag_file
|
|
|
|
"src/top/uTop_top.top"
|
|
|
|
(List.filter
|
|
|
|
(* Remove the "file:..." tag and syntax extensions. *)
|
|
|
|
(fun tag -> not (String.is_prefix "file:" tag) && not (String.is_suffix tag ".syntax"))
|
|
|
|
(Tags.elements (tags_of_pathname "src/top/uTop_top.byte")));
|
2012-01-22 02:54:10 +00:00
|
|
|
|
2011-07-25 13:30:42 +00:00
|
|
|
(* Use -linkpkg for creating toplevels *)
|
|
|
|
flag ["ocaml"; "link"; "toplevel"] & A"-linkpkg";
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-08-07 16:10:10 +00:00
|
|
|
let findlib_version = BaseEnvLight.var_get "findlib_version" env in
|
|
|
|
let findlib_version =
|
|
|
|
Scanf.sscanf findlib_version "%d.%d" (Printf.sprintf "findlib_version=(%d, %d)")
|
|
|
|
in
|
|
|
|
|
|
|
|
(* Optcomp *)
|
|
|
|
let args =
|
|
|
|
S[A"-ppopt"; A"syntax/pa_optcomp.cmo";
|
|
|
|
A"-ppopt"; A"-let"; A"-ppopt"; A findlib_version]
|
|
|
|
in
|
|
|
|
flag ["ocaml"; "compile"; "pa_optcomp"] args;
|
|
|
|
flag ["ocaml"; "ocamldep"; "pa_optcomp"] args;
|
|
|
|
flag ["ocaml"; "doc"; "pa_optcomp"] args;
|
|
|
|
dep ["ocaml"; "ocamldep"; "pa_optcomp"] ["syntax/pa_optcomp.cmo"];
|
|
|
|
|
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
|
2012-01-22 02:54:10 +00:00
|
|
|
let paths = List.map (fun path -> S [A "-I"; A path]) paths in
|
|
|
|
flag ["ocaml"; "compile"; "use_compiler_libs"] & S paths;
|
|
|
|
flag ["ocaml"; "ocamldep"; "use_compiler_libs"] & S paths;
|
|
|
|
flag ["ocaml"; "doc"; "use_compiler_libs"] & S paths;
|
2011-07-25 13:30:42 +00:00
|
|
|
|
2012-03-21 03:15:30 +00:00
|
|
|
let paths = [A "-I"; A "+camlp5"] in
|
|
|
|
flag ["ocaml"; "compile"; "use_camlp5"] & S paths;
|
|
|
|
flag ["ocaml"; "ocamldep"; "use_camlp5"] & S paths;
|
|
|
|
flag ["ocaml"; "doc"; "use_camlp5"] & S paths;
|
|
|
|
|
2011-07-25 13:30:42 +00:00
|
|
|
(* Expunge compiler modules *)
|
|
|
|
rule "toplevel expunge"
|
2012-07-31 15:09:40 +00:00
|
|
|
~dep:"src/top/uTop_top.top"
|
|
|
|
~prod:"src/top/uTop_top.byte"
|
|
|
|
(fun _ _ ->
|
2012-01-22 02:54:10 +00:00
|
|
|
(* Build the list of explicit dependencies. *)
|
|
|
|
let packages =
|
|
|
|
Tags.fold
|
|
|
|
(fun tag packages ->
|
2012-01-22 14:36:43 +00:00
|
|
|
if String.is_prefix "pkg_" tag && not (String.is_suffix tag ".syntax") then
|
2012-01-22 02:54:10 +00:00
|
|
|
String.after tag 4 :: packages
|
|
|
|
else
|
|
|
|
packages)
|
2012-07-31 15:09:40 +00:00
|
|
|
(tags_of_pathname "src/top/uTop_top.byte")
|
2012-01-22 02:54:10 +00:00
|
|
|
[]
|
|
|
|
in
|
2011-07-25 13:30:42 +00:00
|
|
|
(* Build the list of dependencies. *)
|
2012-01-22 02:54:10 +00:00
|
|
|
let deps = Findlib.topological_closure (List.rev_map Findlib.query packages) 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
|
2012-07-31 14:53:22 +00:00
|
|
|
(* These are not in the stdlib path since 4.00 *)
|
|
|
|
let modules = StringSet.add "Toploop" modules in
|
|
|
|
let modules = StringSet.add "Topmain" modules in
|
2012-01-22 02:54:10 +00:00
|
|
|
Cmd (S [A (stdlib / "expunge");
|
2012-07-31 15:09:40 +00:00
|
|
|
A "src/top/uTop_top.top";
|
|
|
|
A "src/top/uTop_top.byte";
|
|
|
|
A "UTop"; A "UTop_private"; S(List.map (fun x -> A x) (StringSet.elements modules))]));
|
|
|
|
|
|
|
|
rule "full toplevel (not expunged)"
|
|
|
|
~dep:"src/top/uTop_top.top"
|
|
|
|
~prod:"src/top/uTop_top_full.byte"
|
|
|
|
(fun _ _ -> cp "src/top/uTop_top.top" "src/top/uTop_top_full.byte")
|
2011-07-25 13:30:42 +00:00
|
|
|
| _ ->
|
|
|
|
())
|