1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 open Clflags
17 open Compenv
18
19 let usage = "Usage: ocamlc <options> <files>\nOptions are:"
20
21 (* Error messages to standard error formatter *)
22 let ppf = Format.err_formatter
23
24 module Options = Main_args.Make_bytecomp_options (Main_args.Default.Main)
25
26 let main () =
27 Clflags.add_arguments __LOC__ Options.list;
28 Clflags.add_arguments __LOC__
29 ["-depend", Arg.Unit Makedepend.main_from_option,
30 "<options> Compute dependencies (use 'ocamlc -depend -help' for details)"];
31 try
32 readenv ppf Before_args;
33 Clflags.parse_arguments anonymous usage;
34 Compmisc.read_clflags_from_env ();
35 if !Clflags.plugin then
36 fatal "-plugin is only supported up to OCaml 4.08.0";
37 begin try
38 Compenv.process_deferred_actions
39 (ppf,
40 Compile.implementation,
41 Compile.interface,
42 ".cmo",
43 ".cma");
44 with Arg.Bad msg ->
45 begin
46 prerr_endline msg;
47 Clflags.print_arguments usage;
48 exit 2
49 end
50 end;
51 readenv ppf Before_link;
52 if
53 List.length
54 (List.filter (fun x -> !x)
55 [make_archive;make_package;compile_only;output_c_object])
56 > 1
57 then begin
58 let module P = Clflags.Compiler_pass in
59 match !stop_after with
60 | None ->
61 fatal "Please specify at most one of -pack, -a, -c, -output-obj";
62 | Some (P.Parsing | P.Typing) ->
63 Printf.ksprintf fatal
64 "Options -i and -stop-after (%s)\
65 are incompatible with -pack, -a, -output-obj"
66 (String.concat "|" P.pass_names)
67 end;
68 if !make_archive then begin
69 Compmisc.init_path ();
70
71 Bytelibrarian.create_archive
72 (Compenv.get_objfiles ~with_ocamlparam:false)
73 (extract_output !output_name);
74 Warnings.check_fatal ();
75 end
76 else if !make_package then begin
77 Compmisc.init_path ();
78 let extracted_output = extract_output !output_name in
79 let revd = get_objfiles ~with_ocamlparam:false in
80 Compmisc.with_ppf_dump ~file_prefix:extracted_output (fun ppf_dump ->
81 Bytepackager.package_files ~ppf_dump (Compmisc.initial_env ())
82 revd (extracted_output));
83 Warnings.check_fatal ();
84 end
85 else if not !compile_only && !objfiles <> [] then begin
86 let target =
87 if !output_c_object && not !output_complete_executable then
88 let s = extract_output !output_name in
89 if (Filename.check_suffix s Config.ext_obj
90 || Filename.check_suffix s Config.ext_dll
91 || Filename.check_suffix s ".c")
92 then s
93 else
94 fatal
95 (Printf.sprintf
96 "The extension of the output file must be .c, %s or %s"
97 Config.ext_obj Config.ext_dll
98 )
99 else
100 default_output !output_name
101 in
102 Compmisc.init_path ();
103 Bytelink.link (get_objfiles ~with_ocamlparam:true) target;
104 Warnings.check_fatal ();
105 end;
106 with x ->
107 Location.report_exception ppf x;
108 exit 2
109
110 let () =
111 main ();
112 Profile.print Format.std_formatter !Clflags.profile_columns;
113 exit 0
114