]> matita.cs.unibo.it Git - helm.git/blob - matita/matitamake.ml
modifications to make matita behave reasonably, removed some useless windows
[helm.git] / matita / matitamake.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 MK = MatitamakeLib ;;
29
30 let main () =
31   MatitaInit.parse_cmdline_and_configuration_file ();
32   MK.initialize ();
33   let usage = ref (fun () -> ()) in
34   let dev_of_name name = 
35     match MK.development_for_name name with
36     | None -> 
37         prerr_endline ("Unable to find a development called " ^ name);
38         exit 1
39     | Some d -> d
40   in
41   let dev_for_dir dir =
42     match MK.development_for_dir dir with
43     | None -> 
44         prerr_endline ("Unable to find a development holding directory: "^ dir);
45         exit 1
46     | Some d -> d
47   in
48   let init_dev args =
49     let name, path =
50       match args with
51       | [ name; path ] when path.[0] = '/' -> name, path
52       | [ name; path ] -> name, Unix.getcwd () ^ "/" ^ path
53       | [ name ] -> name, Unix.getcwd ()
54       | _ -> !usage (); (* should not be reached *) assert false
55     in
56     match MK.initialize_development name path with
57     | None -> exit 2
58     | Some _ -> exit 0
59   in
60   let list_dev args =
61     if List.length args <> 0 then !usage ();
62     match MK.list_known_developments () with
63     | [] -> print_string "No developments found.\n"; exit 0
64     | l ->
65         List.iter 
66           (fun (name, root) -> 
67             print_string (Printf.sprintf "%-10s\trooted in %s\n" name root)) 
68           l;
69         exit 0
70   in
71   let destroy_dev args = 
72     if List.length args <> 1 then !usage ();
73     let name = (List.hd args) in
74     let dev = dev_of_name name in
75     MK.destroy_development dev; 
76     exit 0
77   in
78   let clean_dev args = 
79     let dev = 
80       match args with
81       | [] -> dev_for_dir (Unix.getcwd ())
82       | [name] -> dev_of_name name
83       | _ -> !usage (); exit 1
84     in
85     match MK.clean_development dev with
86     | true -> exit 0
87     | false -> exit 1
88   in
89   let build_dev args = 
90     if List.length args <> 1 then !usage ();
91     let name = (List.hd args) in
92     let dev = dev_of_name name in
93     match MK.build_development dev with
94     | true -> exit 0
95     | false -> exit 1
96   in
97   let publish_dev args = 
98     if List.length args <> 1 then !usage ();
99     let name = (List.hd args) in
100     let dev = dev_of_name name in
101     match MK.publish_development dev with
102     | true -> exit 0
103     | false -> exit 1
104   in
105   let target args = 
106     if List.length args < 1 then !usage ();
107     let dev = dev_for_dir (Unix.getcwd ()) in
108     List.iter 
109       (fun t -> 
110         ignore(MK.build_development ~target:t dev)) 
111       args
112   in
113   let params = [
114     "init", init_dev;
115     "clean", clean_dev;
116     "list", list_dev;
117     "destroy", destroy_dev;
118     "build", build_dev;
119     "publish", publish_dev;
120   ]
121   in
122   usage := MatitaInit.die_usage;
123   let parse args = 
124     match args with
125     | [] -> target [ "all" ]
126     | s :: tl ->
127         let f, args = 
128           try 
129             (List.assoc s params), tl
130           with Not_found -> 
131             if s.[0] = '-' then (!usage ();assert false) else target, args
132         in
133         f args
134   in
135   parse (Helm_registry.get_list Helm_registry.string "matita.args")