]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitadep.ml
1. matitaEngine splitted into disambiguation (now in grafite_parser) and
[helm.git] / helm / matita / matitadep.ml
1 (* Copyright (C) 2005, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 module GA = GrafiteAst 
27 module U = UriManager
28
29 let main () =
30   (* all are maps from "file" to "something" *)
31   let include_deps = Hashtbl.create (Array.length Sys.argv) in
32   let baseuri_of = Hashtbl.create (Array.length Sys.argv) in
33   let uri_deps = Hashtbl.create (Array.length Sys.argv) in
34   let buri alias = U.buri_of_uri (U.uri_of_string alias) in
35   let resolve alias current_buri =
36     let buri = buri alias in
37     if buri <> current_buri then Some buri else None
38   in
39   let find path = 
40     let rec aux = function
41     | [] -> close_in (open_in path); path
42     | p :: tl ->
43         try
44           close_in (open_in (p ^ "/" ^ path)); p ^ "/" ^ path
45         with Sys_error _ -> aux tl
46     in
47     let paths = Helm_registry.get_list Helm_registry.string "matita.includes" in
48     try
49       aux paths
50     with Sys_error _ as exc ->
51       HLog.error ("Unable to read " ^ path);
52       HLog.error ("opts.include_paths was " ^ String.concat ":" paths);
53       raise exc
54   in
55   MatitaInit.load_configuration_file ();
56   MatitaInit.parse_cmdline ();
57   let basedir = Helm_registry.get "matita.basedir" in
58   List.iter
59    (fun file -> 
60     let ic = open_in file in
61     let istream = Ulexing.from_utf8_channel ic in
62     let dependencies = GrafiteParser.parse_dependencies istream in
63     close_in ic;
64     List.iter 
65       (function
66       | GrafiteAst.UriDep uri -> 
67           let uri = UriManager.string_of_uri uri in
68           Hashtbl.add uri_deps file uri
69       | GrafiteAst.BaseuriDep uri -> 
70           let uri = Http_getter_misc.strip_trailing_slash uri in
71           Hashtbl.add baseuri_of file uri
72       | GrafiteAst.IncludeDep path -> 
73           try 
74             let ma_file = if path <> "coq.ma" then find path else path in
75             let moo_file = GrafiteMisc.obj_file_of_script ~basedir ma_file in
76             Hashtbl.add include_deps file moo_file
77           with Sys_error _ -> 
78             HLog.warn 
79               ("Unable to find " ^ path ^ " that is included in " ^ file))
80     dependencies)
81   (Helm_registry.get_list Helm_registry.string "matita.args");
82   Hashtbl.iter 
83     (fun file alias -> 
84       let dep = resolve alias (Hashtbl.find baseuri_of file) in
85       match dep with 
86       | None -> ()
87       | Some u -> 
88          Hashtbl.add include_deps file
89           (LibraryMisc.obj_file_of_baseuri ~basedir ~baseuri:u))
90   uri_deps;
91   List.iter
92    (fun file -> 
93     let deps = Hashtbl.find_all include_deps file in
94     let deps = List.fast_sort Pervasives.compare deps in
95     let deps = HExtlib.list_uniq deps in
96     let deps = file :: deps in
97     let moo = GrafiteMisc.obj_file_of_script ~basedir file in
98      Printf.printf "%s: %s\n" moo (String.concat " " deps);
99      Printf.printf "%s: %s\n" (Pcre.replace ~pat:"ma$" ~templ:"mo" file) moo)
100    (Helm_registry.get_list Helm_registry.string "matita.args")
101