]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/matita/matitadep.ml
- MatitaMisc: we factorized here the function out_preamble used in matitadep
[helm.git] / helm / software / matita / matitadep.ml
index 050fa220e87d84fd3bf2c54329d2d81c21b02090..514147bd17cb502a1421b966e76eb7731456b382 100644 (file)
@@ -25,6 +25,8 @@
 
 (* $Id$ *)
 
+module S = Set.Make (String)
+
 module GA = GrafiteAst 
 module U = UriManager
 module HR = Helm_registry
@@ -46,10 +48,27 @@ let exclude excluded_files files =
    let map file = not (List.mem (fix_name file) excluded_files) in
    List.filter map files
 
+let generate_theory theory_file deps =
+   let map (files, deps) (t, d) =
+      if t = theory_file then files, deps else
+      S.add t files, List.fold_left (fun deps dep -> S.add dep deps) deps d
+   in
+   let out_include och dep = 
+      Printf.fprintf och "include \"%s\".\n\n" dep  
+   in
+   let fileset, depset = List.fold_left map (S.empty, S.empty) deps in
+   let top_depset = S.diff fileset depset in
+   let och = open_out theory_file in
+   MatitaMisc.out_preamble och;
+   S.iter (out_include och) top_depset; 
+   close_out och;
+   (theory_file, S.elements top_depset) :: deps
+
 let main () =
 (*  let _ = print_times "inizio" in *)
   let include_paths = ref [] in
   let use_stdout = ref false in
+  let theory_file = ref "theory.ma" in
   (* all are maps from "file" to "something" *)
   let include_deps = Hashtbl.create 13 in
   let baseuri_of = Hashtbl.create 13 in
@@ -57,6 +76,7 @@ let main () =
   let dot_name = "depends" in 
   let dot_file = ref "" in
   let set_dot_file () = dot_file := dot_name^".dot" in
+  let set_theory_file s = theory_file := s ^ ".ma" in
   (* helpers *)
   let rec baseuri_of_script s = 
      try Hashtbl.find baseuri_of s 
@@ -91,7 +111,9 @@ let main () =
     ["-dot", Arg.Unit set_dot_file,
         "Save dependency graph in dot format and generate a png";
      "-stdout", Arg.Set use_stdout,
-        "Print dependences on stdout"
+        "Print dependences on stdout";
+     "-theory", Arg.String set_theory_file,
+        "Set the name of the theory file (it includes all other files)"
     ];
   MatitaInit.parse_cmdline_and_configuration_file ();
   MatitaInit.initialize_environment ();
@@ -195,9 +217,14 @@ let main () =
       [] deps
   in
   let where = if !use_stdout then None else Some (Sys.getcwd()) in
-  Librarian.write_deps_file where
-   (deps@HExtlib.list_uniq (List.sort Pervasives.compare (List.map (fun x ->
-           x,[]) extern)));
+  let all_deps = 
+     deps @ 
+     HExtlib.list_uniq (List.sort Pervasives.compare (List.map (fun x -> x,[]) extern))
+  in  
+  (* theory generation *)
+  let all_deps_and_theory = generate_theory !theory_file all_deps in 
+  (* matita depend file generation *)
+  Librarian.write_deps_file where all_deps_and_theory;
   (* dot generation *)
   if !dot_file <> "" then
     begin