From fa84034e8019d8c24615e4e743f43644f1751b5b Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Wed, 3 Aug 2011 19:00:52 +0200 Subject: [PATCH] search for compiler libraries at configure time Ignore-this: 69791ad05709149e95a034f2a84be5a3 darcs-hash:20110803170052-c41ad-44393df785313f3e6fb832189d4fc9f0e05f7bc2 --- myocamlbuild.ml | 29 ++++++++--------------------- setup.ml | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/myocamlbuild.ml b/myocamlbuild.ml index 605588d..77ce12b 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -23,27 +23,14 @@ let () = flag ["ocaml"; "link"; "toplevel"] & A"-linkpkg"; let env = BaseEnvLight.load () in - let stdlib_path = BaseEnvLight.var_get "standard_library" env in - - (* Try to find the path where compiler libraries are: *) - let compiler_libs = - let stdlib = String.chomp stdlib_path in - try - let path = - List.find Pathname.exists [ - stdlib / "compiler-libs"; - stdlib / "compiler-lib"; - stdlib / ".." / "compiler-libs"; - stdlib / ".." / "compiler-lib"; - ] - in - path :: List.filter Pathname.exists [ path / "typing"; path / "utils"; path / "parsing" ] - with Not_found -> - [] - in + let path = BaseEnvLight.var_get "compiler_libs" env in + let stdlib = BaseEnvLight.var_get "standard_library" env in (* Add directories for compiler-libraries: *) - let paths = List.map (fun path -> S[A"-I"; A path]) compiler_libs in + let paths = [A "-I"; A path; + A "-I"; A (path / "typing"); + A "-I"; A (path / "parsing"); + A "-I"; A (path / "utils")] in List.iter (fun stage -> flag ["ocaml"; stage; "use_compiler_libs"] & S paths) ["compile"; "ocamldep"; "doc"; "link"]; @@ -60,7 +47,7 @@ let () = (* 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: *) - let directories = StringSet.add stdlib_path (StringSet.add (stdlib_path / "threads") locs) in + let directories = StringSet.add stdlib (StringSet.add (stdlib / "threads") locs) in (* Construct the set of modules to keep by listing .cmi files: *) let modules = @@ -76,7 +63,7 @@ let () = (Array.to_list (Pathname.readdir directory))) directories StringSet.empty in - Cmd(S[A(stdlib_path / "expunge"); + Cmd(S[A(stdlib / "expunge"); A(env "%.top"); A(env "%.byte"); A"UTop"; A"Outcometree"; A"Topdirs"; A"Toploop"; diff --git a/setup.ml b/setup.ml index 0ccbb3c..ff46868 100644 --- a/setup.ml +++ b/setup.ml @@ -17,4 +17,26 @@ let () = (* OASIS_STOP *) -let () = setup ();; +let search_compiler_libs () = + OASISContext.printf `Info "Searching for OCaml compiler libraries"; + let stdlib = BaseEnv.var_get "standard_library" in + let ( / ) = Filename.concat in + try + List.find (fun path -> Sys.file_exists (path / "types.cmi") || Sys.file_exists (path / "typing" / "types.cmi")) [ + stdlib; + stdlib / "compiler-libs"; + stdlib / "compiler-lib"; + stdlib / ".." / "compiler-libs"; + stdlib / ".." / "compiler-lib"; + ] + with Not_found -> + OASISContext.printf `Error "Cannot find compiler libraries! See the README for details."; + exit 1 + +let compiler_libs = + BaseEnv.var_define + ~short_desc:(fun () -> "compiler libraries") + "compiler_libs" + (Lazy.lazy_from_fun search_compiler_libs) + +let () = setup ()