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