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 let paths_to_search_in = ref [];;
28 let add_l l = fun s -> l := s :: !l ;;
31 "-I", Arg.String (add_l paths_to_search_in),
32 "<path> Adds path to the list of searched paths for the include command";
35 Printf.sprintf "MatitaDep v%s\nUsage: matitadep [options] file...\nOptions:"
38 module TA = GrafiteAst
41 let deps = Hashtbl.create (Array.length Sys.argv)
43 let aliases = Hashtbl.create (Array.length Sys.argv)
46 let uri_of_alias = function
47 | Ident_alias (_, uri)
48 | Symbol_alias (_, _, uri)
49 | Number_alias (_, uri) -> uri
53 U.buri_of_uri (U.uri_of_string alias)
57 Some (snd(List.find (fun (u, f) -> u = (buri alias)) !baseuri))
61 (*** TODO MANCANO LE URI VERBATIM DENTRO GLI AST DEI TERMINI ****)
64 let rec aux = function
65 | [] -> close_in (open_in path); path
68 close_in (open_in (p ^ "/" ^ path)); p ^ "/" ^ path
69 with Sys_error _ -> aux tl
71 let paths = !paths_to_search_in in
74 with Sys_error _ as exc ->
75 MatitaLog.error ("Unable to read " ^ path);
76 MatitaLog.error ("opts.include_paths was " ^ String.concat ":" paths);
81 Helm_registry.load_from BuildTimeConf.matita_conf;
82 CicNotation.load_notation BuildTimeConf.core_notation_script;
84 Arg.parse arg_spec (add_l files) usage;
85 List.iter (fun file ->
86 let ic = open_in file in
87 let istream = Stream.of_channel ic in
91 match GrafiteParser.parse_statement istream with
92 | TA.Executable (_, TA.Command (_, TA.Set (_, "baseuri", uri))) ->
93 let uri = MatitaMisc.strip_trailing_slash uri in
94 baseuri := (uri, file) :: !baseuri
95 | TA.Executable (_, TA.Command
96 (_, TA.Alias (_, TA.Ident_alias(_, uri)))) ->
97 Hashtbl.add aliases file uri
98 | TA.Executable (_, TA.Command (_, TA.Include (_, path))) ->
99 Hashtbl.add deps file (find path)
102 CicNotationParser.Parse_error _ as exn ->
103 prerr_endline ("Unable to parse: " ^ file);
104 prerr_endline (MatitaExcPp.to_string exn);
108 | End_of_file -> close_in ic);
111 let dep = resolve alias in
114 | Some d -> Hashtbl.add deps file d)
117 List.iter (fun file ->
118 let deps = Hashtbl.find_all deps file in
119 let deps = List.fast_sort Pervasives.compare deps in
120 let deps = MatitaMisc.list_uniq deps in
122 List.map (fun x -> Pcre.replace ~pat:"ma$" ~templ:"moo" x) deps
124 let deps = file :: deps in
125 Printf.printf "%s: %s\n" (MatitaMisc.obj_file_of_script file)
126 (String.concat " " deps))