1 (***********************************************************************)
4 (* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
6 (* Copyright 2001 Institut National de Recherche en Informatique et *)
7 (* en Automatique. All rights reserved. This file is distributed *)
8 (* under the terms of the Q Public License version 1.0. *)
10 (***********************************************************************)
14 (** Main module for bytecode. *)
22 module M
= Odoc_messages
24 let print_DEBUG s
= print_string s
; print_newline
()
26 (* we check if we must load a module given on the command line *)
27 let arg_list = Array.to_list
Sys.argv
28 let (cmo_or_cma_opt
, paths
) =
29 let rec iter (f_opt
, inc
) = function
30 [] | _
:: [] -> (f_opt
, inc
)
31 | "-g" :: file
:: q
when
32 ((Filename.check_suffix file
"cmo") or
33 (Filename.check_suffix file
"cma")) &
35 iter (Some file
, inc
) q
37 iter (f_opt
, inc
@ [dir
]) q
41 iter (None
, []) arg_list
43 let _ = print_DEBUG "Fin analyse des arguments pour le dynamic load"
45 (** Return the real name of the file to load,
46 searching it in the paths if it is
47 a simple name and not in the current directory. *)
48 let get_real_filename name
=
49 if Filename.basename name
<> name
then
53 let paths = Filename.current_dir_name
:: paths @ [Odoc_config.custom_generators_path
] in
56 (fun d -> Sys.file_exists
(Filename.concat
d name
))
59 Filename.concat
d name
62 failwith
(M.file_not_found_in_paths
paths name
)
66 match cmo_or_cma_opt
with
70 (* initializations for dynamic loading *)
72 Dynlink.allow_unsafe_modules
true;
74 let real_file = get_real_filename file
in
75 ignore
(Dynlink.loadfile
real_file)
78 prerr_endline
(Odoc_messages.load_file_error file
(Dynlink.error_message e
)) ;
81 prerr_endline
(Odoc_messages.load_file_error file
"Not_found");
85 prerr_endline
(Odoc_messages.load_file_error file s
);
88 let _ = print_DEBUG "Fin du chargement dynamique éventuel"
90 let default_html_generator = new Odoc_html.html
91 let default_latex_generator = new Odoc_latex.latex
92 let default_texi_generator = new Odoc_texi.texi
93 let default_man_generator = new Odoc_man.man
94 let default_dot_generator = new Odoc_dot.dot
95 let _ = Odoc_args.parse
96 (default_html_generator :> Odoc_args.doc_generator
)
97 (default_latex_generator :> Odoc_args.doc_generator
)
98 (default_texi_generator :> Odoc_args.doc_generator
)
99 (default_man_generator :> Odoc_args.doc_generator
)
100 (default_dot_generator :> Odoc_args.doc_generator
)
107 Odoc_info.verbose
(Odoc_messages.loading f
);
109 let l = Odoc_analyse.load_modules f
in
110 Odoc_info.verbose
Odoc_messages.ok
;
114 incr
Odoc_global.errors
;
120 let modules = Odoc_analyse.analyse_files ~init
: loaded_modules !Odoc_args.files
123 match !Odoc_args.dump
with
126 try Odoc_analyse.dump_modules f
modules
129 incr
Odoc_global.errors
132 match !Odoc_args.doc_generator
with
136 Odoc_info.verbose
Odoc_messages.generating_doc
;
137 gen#generate
modules;
138 Odoc_info.verbose
Odoc_messages.ok
141 if !Odoc_global.errors
> 0 then
143 prerr_endline
(Odoc_messages.errors_occured
!Odoc_global.errors
) ;