1 (* Copyright (C) 2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 module GA = GrafiteAst
29 (* all are maps from "file" to "something" *)
30 let include_deps = Hashtbl.create (Array.length Sys.argv)
31 let baseuri_of = Hashtbl.create (Array.length Sys.argv)
32 let uri_deps = Hashtbl.create (Array.length Sys.argv)
35 U.buri_of_uri (U.uri_of_string alias)
37 let resolve alias current_buri=
38 let buri = buri alias in
39 if buri <> current_buri then Some buri else None
42 let rec aux = function
43 | [] -> close_in (open_in path); path
46 close_in (open_in (p ^ "/" ^ path)); p ^ "/" ^ path
47 with Sys_error _ -> aux tl
49 let paths = Helm_registry.get_list Helm_registry.string "matita.includes" in
52 with Sys_error _ as exc ->
53 MatitaLog.error ("Unable to read " ^ path);
54 MatitaLog.error ("opts.include_paths was " ^ String.concat ":" paths);
59 MatitaInit.load_configuration_file ();
60 MatitaInit.parse_cmdline ();
63 let ic = open_in file in
64 let istream = Ulexing.from_utf8_channel ic in
65 let dependencies = GrafiteParser.parse_dependencies istream in
69 | GrafiteAst.UriDep uri ->
70 let uri = UriManager.string_of_uri uri in
71 Hashtbl.add uri_deps file uri
72 | GrafiteAst.BaseuriDep uri ->
73 let uri = MatitaMisc.strip_trailing_slash uri in
74 Hashtbl.add baseuri_of file uri
75 | GrafiteAst.IncludeDep path ->
77 let ma_file = if path <> "coq.ma" then find path else path in
78 let moo_file = MatitaMisc.obj_file_of_script ma_file in
79 Hashtbl.add include_deps file moo_file
82 ("Unable to find " ^ path ^ " that is included in " ^ file))
84 (Helm_registry.get_list Helm_registry.string "matita.args");
87 let dep = resolve alias (Hashtbl.find baseuri_of file) in
91 Hashtbl.add include_deps file (MatitaMisc.obj_file_of_baseuri u))
95 let deps = Hashtbl.find_all include_deps file in
96 let deps = List.fast_sort Pervasives.compare deps in
97 let deps = HExtlib.list_uniq deps in
98 let deps = file :: deps in
99 let moo = MatitaMisc.obj_file_of_script file in
100 Printf.printf "%s: %s\n" moo (String.concat " " deps);
101 Printf.printf "%s: %s\n" (Pcre.replace ~pat:"ma$" ~templ:"mo" file) moo)
102 (Helm_registry.get_list Helm_registry.string "matita.args")