]> matita.cs.unibo.it Git - helm.git/blobdiff - matita/matitac.ml
fixed error message
[helm.git] / matita / matitac.ml
index 179a0ba8e8e508e413f22958cef5c20cc1039fbc..c31c22874e2038dccd675f1c5cfd2c394a4d6841 100644 (file)
@@ -50,16 +50,12 @@ let out_preamble och (path, lines) =
    print lines;
    out_line_comment och "This file was automatically generated: do not edit"
 
-(* from matitacLib *)
-
 let pp_ast_statement st =
   GrafiteAstPp.pp_statement ~term_pp:CicNotationPp.pp_term
     ~map_unicode_to_tex:(Helm_registry.get_bool
       "matita.paste_unicode_as_tex")
     ~lazy_term_pp:CicNotationPp.pp_term ~obj_pp:(CicNotationPp.pp_obj CicNotationPp.pp_term) st
 
-(**)
-
 let dump f =
    Helm_registry.set_bool "matita.moo" false;
    let floc = H.dummy_floc in
@@ -86,25 +82,54 @@ let dump f =
    MatitaEngine.set_callback matita_engine_cb;
    MatitacLib.set_callback matitac_lib_cb;
    at_exit atexit
-   
+;;
+
+(* compiler ala pascal/java using make *)
+let main_compiler () =
+  MatitaInit.initialize_all ();
+  (* targets and deps *)
+  let targets = Helm_registry.get_list Helm_registry.string "matita.args" in
+  let target, root = 
+    match targets with
+    | [] ->
+      (match Librarian.find_roots_in_dir (Sys.getcwd ()) with
+      | [x] -> [], x
+      | [] -> 
+         prerr_endline "No targets and no root found"; exit 1
+      | roots -> 
+         let roots = List.map (HExtlib.chop_prefix (Sys.getcwd()^"/")) roots in
+         prerr_endline ("Too many roots found:\n\t" ^ String.concat "\n\t" roots);
+         prerr_endline ("\nEnter one of these directories and retry");
+         exit 1);
+    | [hd] -> 
+      let root, buri, file, target =
+        Librarian.baseuri_of_script ~include_paths:[] hd 
+      in
+      [target], root
+    | _ -> prerr_endline "Only one target (or none) can be specified.";exit 1
+  in
+  (* must be called after init since args are set by cmdline parsing *)
+  let system_mode =  Helm_registry.get_bool "matita.system" in
+  if system_mode then HLog.message "Compiling in system space";
+  (* here we go *)
+  if not (Helm_registry.get_bool "matita.verbose") then MatitaMisc.shutup ();
+  if MatitacLib.Make.make root target then 
+    HLog.message "Compilation successful"
+  else
+    HLog.message "Compilation failed"
+;;
+
 let main () =
- Helm_registry.set_bool "matita.moo" true;
- match Filename.basename Sys.argv.(0) with
- |"gragrep"    |"gragrep.opt"    |"gragrep.opt.static"    ->Gragrep.main()
- |"matitadep"  |"matitadep.opt"  |"matitadep.opt.static"  ->Matitadep.main()
- |"matitaclean"|"matitaclean.opt"|"matitaclean.opt.static"->Matitaclean.main()
- |"matitamake" |"matitamake.opt" |"matitamake.opt.static" ->Matitamake.main()
- |"matitaprover"|"matitaprover.opt"
- |"matitaprover.opt.static" ->Matitaprover.main()
- |"matitawiki"|"matitawiki.opt" ->MatitaWiki.main()
- | _ ->
-(*
-      let _ = Paramodulation.Saturation.init () in  *)
-(* ALB to link paramodulation *)
-      let dump_msg = "<filename> Dump source with expanded macros to <filename>" in
-      MatitaInit.add_cmdline_spec ["-dump", Arg.String dump, dump_msg];
-      let _ = MatitacLib.main `COMPILER in
-      ()
+  let bin = Filename.basename Sys.argv.(0) in
+  if      Pcre.pmatch ~pat:"^matitadep"    bin then Matitadep.main ()
+  else if Pcre.pmatch ~pat:"^matitaclean"  bin then Matitaclean.main ()
+  else if Pcre.pmatch ~pat:"^matitaprover" bin then Matitaprover.main ()
+  else if Pcre.pmatch ~pat:"^matitawiki"   bin then MatitaWiki.main ()
+  else
+    let dump_msg = "<filename> Dump with expanded macros to <filename>" in
+    MatitaInit.add_cmdline_spec ["-dump", Arg.String dump, dump_msg];
+    main_compiler ()
+;;
 
 let _ = main ()