]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitadep.ml
test branch
[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 (* $Id$ *)
27
28 module GA = GrafiteAst 
29 module U = UriManager
30
31 let main () =
32   (* all are maps from "file" to "something" *)
33   let include_deps = Hashtbl.create (Array.length Sys.argv) in
34   let baseuri_of = Hashtbl.create (Array.length Sys.argv) in
35   let uri_deps = Hashtbl.create (Array.length Sys.argv) in
36   let buri alias = U.buri_of_uri (U.uri_of_string alias) in
37   let resolve alias current_buri =
38     let buri = buri alias in
39     if buri <> current_buri then Some buri else None in
40   MatitaInit.load_configuration_file ();
41   MatitaInit.parse_cmdline ();
42   let include_paths =
43    Helm_registry.get_list Helm_registry.string "matita.includes" in
44   let basedir = Helm_registry.get "matita.basedir" in
45   List.iter
46    (fun ma_file -> 
47     let ic = open_in ma_file in
48     let istream = Ulexing.from_utf8_channel ic in
49     let dependencies = DependenciesParser.parse_dependencies istream in
50     close_in ic;
51     List.iter 
52      (function
53        | DependenciesParser.UriDep uri -> 
54           let uri = UriManager.string_of_uri uri in
55           if not (Http_getter_storage.is_legacy uri) then
56             Hashtbl.add uri_deps ma_file uri
57        | DependenciesParser.BaseuriDep uri -> 
58           let uri = Http_getter_misc.strip_trailing_slash uri in
59           Hashtbl.add baseuri_of ma_file uri
60        | DependenciesParser.IncludeDep path -> 
61           try 
62             let baseuri =
63               DependenciesParser.baseuri_of_script ~include_paths path in
64             if not (Http_getter_storage.is_legacy baseuri) then
65               let moo_file =
66                 LibraryMisc.obj_file_of_baseuri ~basedir ~baseuri in
67               Hashtbl.add include_deps ma_file moo_file
68           with Sys_error _ -> 
69             HLog.warn 
70               ("Unable to find " ^ path ^ " that is included in " ^ ma_file)
71      ) dependencies
72    ) (Helm_registry.get_list Helm_registry.string "matita.args");
73   Hashtbl.iter 
74     (fun file alias -> 
75       let dep = resolve alias (Hashtbl.find baseuri_of file) in
76       match dep with 
77       | None -> ()
78       | Some u -> 
79          Hashtbl.add include_deps file
80           (LibraryMisc.obj_file_of_baseuri ~basedir ~baseuri:u))
81   uri_deps;
82   List.iter
83    (fun ma_file -> 
84     let deps = Hashtbl.find_all include_deps ma_file in
85     let deps = List.fast_sort Pervasives.compare deps in
86     let deps = HExtlib.list_uniq deps in
87     let deps = ma_file :: deps in
88     let baseuri = Hashtbl.find baseuri_of ma_file in
89     let moo = LibraryMisc.obj_file_of_baseuri ~basedir ~baseuri in
90      Printf.printf "%s: %s\n" moo (String.concat " " deps);
91      Printf.printf "%s: %s\n" (Pcre.replace ~pat:"ma$" ~templ:"mo" ma_file) moo)
92    (Helm_registry.get_list Helm_registry.string "matita.args")
93