]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitamake.ml
ocaml 3.09 transition
[helm.git] / helm / 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 module MK = MatitamakeLib ;;
27
28 let main () =
29   MatitaInit.load_configuration_file ();
30   MK.initialize ();
31   let usage = ref (fun () -> ()) in
32   let dev_of_name name = 
33     match MK.development_for_name name with
34     | None -> 
35         prerr_endline ("Unable to find a development called " ^ name);
36         exit 1
37     | Some d -> d
38   in
39   let dev_for_dir dir =
40     match MK.development_for_dir dir with
41     | None -> 
42         prerr_endline ("Unable to find a development holding directory: "^ dir);
43         exit 1
44     | Some d -> d
45   in
46   let init_dev_doc = "
47 \tParameters: name (the name of the development, required)
48 \tDescription: tells matitamake that a new development radicated 
49 \t\tin the current working directory should be handled."
50   in
51   let init_dev args =
52     if List.length args <> 1 then !usage ();
53     match MK.initialize_development (List.hd args) (Unix.getcwd ()) with
54     | None -> exit 2
55     | Some _ -> exit 0
56   in
57   let list_dev_doc = "
58 \tParameters: 
59 \tDescription: lists the known developments and their roots."
60   in
61   let list_dev args =
62     if List.length args <> 0 then !usage ();
63     match MK.list_known_developments () with
64     | [] -> print_string "No developments found.\n"; exit 0
65     | l ->
66         List.iter 
67           (fun (name, root) -> 
68             print_string (Printf.sprintf "%-10s\trooted in %s\n" name root)) 
69           l;
70         exit 0
71   in
72   let destroy_dev_doc = "
73 \tParameters: name (the name of the development to destroy, required)
74 \tDescription: deletes a development (only from matitamake metadat, no
75 \t\t.ma files will be deleted)."
76   in
77   let destroy_dev args = 
78     if List.length args <> 1 then !usage ();
79     let name = (List.hd args) in
80     let dev = dev_of_name name in
81     MK.destroy_development dev; 
82     exit 0
83   in
84   let clean_dev_doc = "
85 \tParameters: name (the name of the development to destroy, optional)
86 \t\tIf omitted the development that holds the current working 
87 \t\tdirectory is used (if any).
88 \tDescription: clean the develpoment."
89   in
90   let clean_dev args = 
91     let dev = 
92       match args with
93       | [] -> dev_for_dir (Unix.getcwd ())
94       | [name] -> dev_of_name name
95       | _ -> !usage (); exit 1
96     in
97     match MK.clean_development dev with
98     | true -> exit 0
99     | false -> exit 1
100   in
101   let build_dev_doc = "
102 \tParameters: name (the name of the development to build, required)
103 \tDescription: completely builds the develpoment."
104   in
105   let build_dev args = 
106     if List.length args <> 1 then !usage ();
107     let name = (List.hd args) in
108     let dev = dev_of_name name in
109     match MK.build_development dev with
110     | true -> exit 0
111     | false -> exit 1
112   in
113   let nodb_doc = "
114 \tParameters:
115 \tDescription: avoid using external database connection."
116   in
117   let nodb _ = Helm_registry.set_bool "db.nodb" true in
118   let target args = 
119     if List.length args < 1 then !usage ();
120     let dev = dev_for_dir (Unix.getcwd ()) in
121     List.iter 
122       (fun t -> 
123         ignore(MK.build_development ~target:t dev)) 
124       args
125   in
126   let params = [
127     "-init", init_dev, init_dev_doc;
128     "-clean", clean_dev, clean_dev_doc;
129     "-list", list_dev, list_dev_doc;
130     "-destroy", destroy_dev, destroy_dev_doc;
131     "-build", build_dev, build_dev_doc;
132     "-nodb", nodb, nodb_doc;
133     "-h", (fun _ -> !usage()), "print this help screen";
134     "-help", (fun _ -> !usage()), "print this help screen";
135   ]
136   in
137   usage := (fun () -> 
138     let p = prerr_endline in 
139     p "\nusage:";
140     p "\tmatitamake(.opt) [command [options]]\n";
141     p "\tmatitamake(.opt) [target]\n";
142     p "commands:";
143     List.iter (fun (n,_,d) -> p (Printf.sprintf "    %-10s%s" n d)) params;
144     p "\nIf target is omitted a 'all' will be used as the default.";
145     p "With -build you can build a development wherever it is.";
146     p "If you specify a target it implicitly refers to the development that";
147     p "holds the current working directory (if any).\n"; 
148     exit 1);
149   let rec parse args = 
150     match args with
151     | [] -> target ["all"]
152     | s::tl ->
153         try
154           let _,f,_ = List.find (fun (n,_,_) -> n = s) params in
155           f tl;
156           parse tl
157         with Not_found -> if s.[0] = '-' then !usage () else target args
158   in
159   parse (List.tl (Array.to_list Sys.argv))
160