1 (* Copyright (C) 2005, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
34 let out_comment och s =
35 let s = if s <> "" && s.[0] = '*' then "#" ^ s else s in
36 Printf.fprintf och "%s%s%s\n\n" "(*" s "*)"
38 let out_line_comment och s =
39 let l = 70 - String.length s in
40 let s = Printf.sprintf " %s %s" s (String.make l '*') in
43 let out_preamble och (path, lines) =
44 let ich = open_in path in
47 let s = input_line ich in
48 begin Printf.fprintf och "%s\n" s; print (pred i) end
51 out_line_comment och "This file was automatically generated: do not edit"
53 let pp_ast_statement st =
54 GrafiteAstPp.pp_statement ~term_pp:CicNotationPp.pp_term
55 ~map_unicode_to_tex:(Helm_registry.get_bool
56 "matita.paste_unicode_as_tex")
57 ~lazy_term_pp:CicNotationPp.pp_term ~obj_pp:(CicNotationPp.pp_obj CicNotationPp.pp_term) st
60 Helm_registry.set_bool "matita.moo" false;
61 let floc = H.dummy_floc in
62 let nl_ast = G.Comment (floc, G.Note (floc, "")) in
63 let och = open_out f in
64 let atexit () = close_out och in
65 let nl () = output_string och (pp_ast_statement nl_ast) in
66 let rt_base_dir = Filename.dirname Sys.argv.(0) in
67 let path = Filename.concat rt_base_dir "matita.ma.templ" in
69 out_preamble och (path, lines);
70 let grafite_parser_cb fname =
71 let ast = G.Executable (floc, G.Command (floc, G.Include (floc, fname))) in
72 output_string och (pp_ast_statement ast); nl (); nl ()
74 let matita_engine_cb = function
75 | G.Executable (_, G.Macro (_, G.Inline _))
76 | G.Executable (_, G.Command (_, G.Include _)) -> ()
78 output_string och (pp_ast_statement ast); nl (); nl ()
80 let matitac_lib_cb = output_string och in
81 GrafiteParser.set_callback grafite_parser_cb;
82 MatitaEngine.set_callback matita_engine_cb;
83 MatitacLib.set_callback matitac_lib_cb;
87 (* compiler ala pascal/java using make *)
88 let main_compiler () =
89 MatitaInit.initialize_all ();
90 (* targets and deps *)
91 let targets = Helm_registry.get_list Helm_registry.string "matita.args" in
95 (match Librarian.find_roots_in_dir (Sys.getcwd ()) with
96 | [x] -> [], Filename.dirname x
98 prerr_endline "No targets and no root found"; exit 1
100 let roots = List.map (HExtlib.chop_prefix (Sys.getcwd()^"/")) roots in
101 prerr_endline ("Too many roots found:\n\t" ^ String.concat "\n\t" roots);
102 prerr_endline ("\nEnter one of these directories and retry");
105 let root, buri, file, target =
106 Librarian.baseuri_of_script ~include_paths:[] hd
109 | _ -> prerr_endline "Only one target (or none) can be specified.";exit 1
111 (* must be called after init since args are set by cmdline parsing *)
112 let system_mode = Helm_registry.get_bool "matita.system" in
113 if system_mode then HLog.message "Compiling in system space";
115 if not (Helm_registry.get_bool "matita.verbose") then MatitaMisc.shutup ();
116 if MatitacLib.Make.make root target then
117 HLog.message "Compilation successful"
119 HLog.message "Compilation failed"
123 let bin = Filename.basename Sys.argv.(0) in
124 if Pcre.pmatch ~pat:"^matitadep" bin then Matitadep.main ()
125 else if Pcre.pmatch ~pat:"^matitaclean" bin then Matitaclean.main ()
126 else if Pcre.pmatch ~pat:"^matitawiki" bin then MatitaWiki.main ()
128 let dump_msg = "<filename> Dump with expanded macros to <filename>" in
129 MatitaInit.add_cmdline_spec ["-dump", Arg.String dump, dump_msg];