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