|
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;stop_early;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) as p) -> |
63 | | - assert (P.is_compilation_pass p); |
64 | | - Printf.ksprintf fatal |
65 | | - "Options -i and -stop-after (%s) \ |
66 | | - are incompatible with -pack, -a, -output-obj" |
67 | | - (String.concat "|" |
68 | | - (Clflags.Compiler_pass.available_pass_names ~native:false)) |
69 | | - | Some P.Scheduling -> assert false (* native only *) |
70 | | - end; |
71 | | - if !make_archive then begin |
72 | | - Compmisc.init_path (); |
73 | | - |
74 | | - Bytelibrarian.create_archive |
75 | | - (Compenv.get_objfiles ~with_ocamlparam:false) |
76 | | - (extract_output !output_name); |
77 | | - Warnings.check_fatal (); |
78 | | - end |
79 | | - else if !make_package then begin |
80 | | - Compmisc.init_path (); |
81 | | - let extracted_output = extract_output !output_name in |
82 | | - let revd = get_objfiles ~with_ocamlparam:false in |
83 | | - Compmisc.with_ppf_dump ~file_prefix:extracted_output (fun ppf_dump -> |
84 | | - Bytepackager.package_files ~ppf_dump (Compmisc.initial_env ()) |
85 | | - revd (extracted_output)); |
86 | | - Warnings.check_fatal (); |
87 | | - end |
88 | | - else if not !stop_early && !objfiles <> [] then begin |
89 | | - let target = |
90 | | - if !output_c_object && not !output_complete_executable then |
91 | | - let s = extract_output !output_name in |
92 | | - if (Filename.check_suffix s Config.ext_obj |
93 | | - || Filename.check_suffix s Config.ext_dll |
94 | | - || Filename.check_suffix s ".c") |
95 | | - then s |
96 | | - else |
97 | | - fatal |
98 | | - (Printf.sprintf |
99 | | - "The extension of the output file must be .c, %s or %s" |
100 | | - Config.ext_obj Config.ext_dll |
101 | | - ) |
102 | | - else |
103 | | - default_output !output_name |
104 | | - in |
105 | | - Compmisc.init_path (); |
106 | | - Bytelink.link (get_objfiles ~with_ocamlparam:true) target; |
107 | | - Warnings.check_fatal (); |
108 | | - end; |
109 | | - with x -> |
110 | | - Location.report_exception ppf x; |
111 | | - exit 2 |
112 | | - |
113 | 1 | let () = |
114 | | - main (); |
115 | | - Profile.print Format.std_formatter !Clflags.profile_columns; |
116 | | - exit 0 |
| 2 | + exit (Maindriver.main Sys.argv Format.err_formatter) |
0 commit comments