]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/matitac.ml
d0f5603e58a347655379f812d378fa34fb9483ee
[helm.git] / matita / matita / matitac.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 (* compiler ala pascal/java using make *)
29 let main_compiler () =
30   MatitaInit.initialize_all ();
31   (* targets and deps *)
32   let targets = Helm_registry.get_list Helm_registry.string "matita.args" in
33   let targets = 
34     match targets with
35     | [] ->
36       (match Librarian.find_roots_in_dir (Sys.getcwd ()) with
37       | [x] ->
38          let root = Filename.dirname x in
39           HExtlib.find ~test:(fun path -> Filename.check_suffix path ".ma") root
40       | [] -> 
41          prerr_endline "No targets and no root found"; exit 1
42       | roots -> 
43          let roots = List.map (HExtlib.chop_prefix (Sys.getcwd()^"/")) roots in
44          prerr_endline ("Too many roots found:\n\t" ^ String.concat "\n\t" roots);
45          prerr_endline ("\nEnter one of these directories and retry");
46          exit 1);
47     | _ ->
48       let map targets file =
49           if HExtlib.is_dir file then
50              let files = HExtlib.find ~test:(fun path -> Filename.check_suffix path ".ma") file in
51              files @ targets
52           else file :: targets
53       in
54       List.fold_left map [] (List.rev targets)
55   in
56   (* must be called after init since args are set by cmdline parsing *)
57   let system_mode =  Helm_registry.get_bool "matita.system" in
58   if system_mode then HLog.message "Compiling in system space";
59   (* here we go *)
60   if not (Helm_registry.get_bool "matita.verbose") then MatitaMisc.shutup ();
61   if List.fold_left
62    (fun b t ->
63      (try
64        ignore (MatitaEngine.assert_ng ~include_paths:[] t); true
65       with
66        MatitaEngine.FailureCompiling (_,exn) ->
67         HLog.error (snd (MatitaExcPp.to_string exn)); false) && b
68    ) true targets
69   then 
70     (HLog.message "Compilation successful"; 0)
71   else
72     (HLog.message "Compilation failed"; 1)
73 ;;
74
75 let main () =
76   Sys.catch_break true;
77   let bin = Filename.basename Sys.argv.(0) in
78   if Pcre.pmatch ~pat:"^matitaclean"  bin then Matitaclean.main ()
79   else exit (main_compiler ())
80 ;;
81
82 let _ = main ()
83