1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1996-02-15 08:19:09 -08:00
|
|
|
open Config
|
1995-07-02 09:51:07 -07:00
|
|
|
open Clflags
|
|
|
|
|
2000-03-06 21:02:33 -08:00
|
|
|
let process_interface_file ppf name =
|
|
|
|
Optcompile.interface ppf name
|
1996-05-22 05:41:36 -07:00
|
|
|
|
2000-03-06 21:02:33 -08:00
|
|
|
let process_implementation_file ppf name =
|
|
|
|
Optcompile.implementation ppf name;
|
2002-01-28 09:25:26 -08:00
|
|
|
objfiles := (Misc.chop_extension_if_any name ^ ".cmx") :: !objfiles
|
1996-05-22 05:41:36 -07:00
|
|
|
|
2000-03-06 21:02:33 -08:00
|
|
|
let process_file ppf name =
|
1995-10-24 08:37:23 -07:00
|
|
|
if Filename.check_suffix name ".ml"
|
2000-12-28 05:07:42 -08:00
|
|
|
|| Filename.check_suffix name ".mlt" then begin
|
2000-03-06 21:02:33 -08:00
|
|
|
Optcompile.implementation ppf name;
|
2002-01-28 09:25:26 -08:00
|
|
|
objfiles := (Misc.chop_extension_if_any name ^ ".cmx") :: !objfiles
|
1995-07-02 09:51:07 -07:00
|
|
|
end
|
2004-04-09 06:32:28 -07:00
|
|
|
else if Filename.check_suffix name !Config.interface_suffix then begin
|
|
|
|
Optcompile.interface ppf name;
|
|
|
|
if !make_package then objfiles := name :: !objfiles
|
|
|
|
end
|
1995-07-02 09:51:07 -07:00
|
|
|
else if Filename.check_suffix name ".cmx"
|
2000-12-28 05:07:42 -08:00
|
|
|
|| Filename.check_suffix name ".cmxa" then
|
1995-07-02 09:51:07 -07:00
|
|
|
objfiles := name :: !objfiles
|
2004-04-09 06:32:28 -07:00
|
|
|
else if Filename.check_suffix name ".cmi" && !make_package then
|
|
|
|
objfiles := name :: !objfiles
|
1996-02-15 08:19:09 -08:00
|
|
|
else if Filename.check_suffix name ext_obj
|
2000-12-28 05:07:42 -08:00
|
|
|
|| Filename.check_suffix name ext_lib then
|
1995-07-02 09:51:07 -07:00
|
|
|
ccobjs := name :: !ccobjs
|
|
|
|
else if Filename.check_suffix name ".c" then begin
|
|
|
|
Optcompile.c_file name;
|
1996-02-15 08:19:09 -08:00
|
|
|
ccobjs := (Filename.chop_suffix (Filename.basename name) ".c" ^ ext_obj)
|
1995-07-02 09:51:07 -07:00
|
|
|
:: !ccobjs
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise(Arg.Bad("don't know what to do with " ^ name))
|
|
|
|
|
2002-08-01 08:18:03 -07:00
|
|
|
let print_version_and_library () =
|
1996-04-30 07:53:58 -07:00
|
|
|
print_string "The Objective Caml native-code compiler, version ";
|
1997-02-19 08:10:33 -08:00
|
|
|
print_string Config.version; print_newline();
|
|
|
|
print_string "Standard library directory: ";
|
2000-01-13 11:03:50 -08:00
|
|
|
print_string Config.standard_library; print_newline();
|
|
|
|
exit 0
|
1995-07-02 09:51:07 -07:00
|
|
|
|
2002-08-01 08:18:03 -07:00
|
|
|
let print_version_string () =
|
|
|
|
print_string Config.version; print_newline(); exit 0
|
|
|
|
|
2000-11-07 06:41:12 -08:00
|
|
|
let print_standard_library () =
|
|
|
|
print_string Config.standard_library; print_newline(); exit 0
|
|
|
|
|
2002-06-11 07:15:12 -07:00
|
|
|
let extract_output = function
|
|
|
|
| Some s -> s
|
|
|
|
| None ->
|
|
|
|
prerr_endline
|
|
|
|
"Please specify the name of the output file, using option -o";
|
|
|
|
exit 2
|
|
|
|
|
|
|
|
let default_output = function
|
|
|
|
| Some s -> s
|
|
|
|
| None -> Config.default_executable_name
|
|
|
|
|
1997-02-19 08:10:33 -08:00
|
|
|
let usage = "Usage: ocamlopt <options> <files>\nOptions are:"
|
1996-10-24 07:17:48 -07:00
|
|
|
|
1995-07-02 09:51:07 -07:00
|
|
|
let main () =
|
1999-02-16 10:29:28 -08:00
|
|
|
native_code := true;
|
1998-11-06 07:39:43 -08:00
|
|
|
c_compiler := Config.native_c_compiler;
|
2000-04-16 07:34:58 -07:00
|
|
|
c_linker := Config.native_c_linker;
|
2000-03-06 21:02:33 -08:00
|
|
|
let ppf = Format.err_formatter in
|
1995-07-02 09:51:07 -07:00
|
|
|
try
|
2002-11-29 07:03:37 -08:00
|
|
|
Arg.parse (Arch.command_line_options @ [
|
1996-10-24 07:17:48 -07:00
|
|
|
"-a", Arg.Set make_archive, " Build a library";
|
|
|
|
"-c", Arg.Set compile_only, " Compile only (do not link)";
|
2000-04-16 07:34:58 -07:00
|
|
|
"-cc", Arg.String(fun s -> c_compiler := s; c_linker := s),
|
1998-11-06 07:39:43 -08:00
|
|
|
"<comp> Use <comp> as the C compiler and linker";
|
2002-05-07 06:16:57 -07:00
|
|
|
"-cclib", Arg.String(fun s ->
|
|
|
|
ccobjs := Misc.rev_split_words s @ !ccobjs),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<opt> Pass option <opt> to the C linker";
|
1996-10-26 13:47:34 -07:00
|
|
|
"-ccopt", Arg.String(fun s -> ccopts := s :: !ccopts),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<opt> Pass option <opt> to the C compiler and linker";
|
|
|
|
"-compact", Arg.Clear optimize_for_speed,
|
|
|
|
" Optimize code size rather than speed";
|
2003-04-03 05:59:38 -08:00
|
|
|
"-dtypes", Arg.Set save_types,
|
2003-06-12 05:52:17 -07:00
|
|
|
" Save type information in <filename>.annot";
|
2003-06-23 06:22:09 -07:00
|
|
|
"-i", Arg.Unit (fun () -> print_types := true; compile_only := true),
|
|
|
|
" Print inferred interface";
|
1996-10-26 13:47:34 -07:00
|
|
|
"-I", Arg.String(fun dir -> include_dirs := dir :: !include_dirs),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<dir> Add <dir> to the list of include directories";
|
2000-03-06 21:02:33 -08:00
|
|
|
"-impl", Arg.String (process_implementation_file ppf),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<file> Compile <file> as a .ml file";
|
1997-02-19 08:10:33 -08:00
|
|
|
"-inline", Arg.Int(fun n -> inline_threshold := n * 8),
|
1997-02-16 09:20:11 -08:00
|
|
|
"<n> Set aggressiveness of inlining to <n>";
|
2000-03-06 21:02:33 -08:00
|
|
|
"-intf", Arg.String (process_interface_file ppf),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<file> Compile <file> as a .mli file";
|
1998-11-04 02:56:01 -08:00
|
|
|
"-intf-suffix", Arg.String (fun s -> Config.interface_suffix := s),
|
2000-03-20 12:23:07 -08:00
|
|
|
"<file> Suffix for interface files (default: .mli)";
|
1998-11-04 02:56:01 -08:00
|
|
|
"-intf_suffix", Arg.String (fun s -> Config.interface_suffix := s),
|
2000-03-20 12:23:07 -08:00
|
|
|
"<file> (deprecated) same as -intf-suffix";
|
2000-03-24 11:31:25 -08:00
|
|
|
"-labels", Arg.Clear classic, " Use commuting label mode";
|
1997-02-19 08:10:33 -08:00
|
|
|
"-linkall", Arg.Set link_everything,
|
|
|
|
" Link all modules, even unused ones";
|
1997-05-13 11:28:25 -07:00
|
|
|
"-noassert", Arg.Set noassert, " Don't compile assertion checks";
|
2000-03-09 01:12:28 -08:00
|
|
|
"-noautolink", Arg.Set no_auto_link,
|
|
|
|
" Don't automatically link C libraries specified in .cma files";
|
2001-09-06 01:52:32 -07:00
|
|
|
"-nolabels", Arg.Set classic, " Ignore non-optional labels in types";
|
2002-02-14 07:17:11 -08:00
|
|
|
"-nostdlib", Arg.Set no_std_include,
|
|
|
|
" do not add standard directory to the list of include directories";
|
2002-06-11 07:15:12 -07:00
|
|
|
"-o", Arg.String(fun s -> output_name := Some s),
|
2000-03-20 12:23:07 -08:00
|
|
|
"<file> Set output file name to <file>";
|
1996-11-08 06:46:18 -08:00
|
|
|
"-output-obj", Arg.Unit(fun () -> output_c_object := true),
|
1998-08-06 06:27:38 -07:00
|
|
|
" Output a C object file instead of an executable";
|
|
|
|
"-p", Arg.Set gprofile,
|
|
|
|
" Compile and link with profiling support for \"gprof\"\n\
|
|
|
|
\t(not supported on all platforms)";
|
2002-02-08 08:55:44 -08:00
|
|
|
"-pack", Arg.Set make_package,
|
2002-07-25 08:52:54 -07:00
|
|
|
" Package the given .cmx files into one .cmx";
|
1996-10-24 07:17:48 -07:00
|
|
|
"-pp", Arg.String(fun s -> preprocessor := Some s),
|
|
|
|
"<command> Pipe sources through preprocessor <command>";
|
2002-04-18 00:27:47 -07:00
|
|
|
"-principal", Arg.Set principal,
|
|
|
|
" Check principality of type inference";
|
1999-11-19 01:11:02 -08:00
|
|
|
"-rectypes", Arg.Set recursive_types,
|
|
|
|
" Allow arbitrary recursive types";
|
1997-02-19 08:10:33 -08:00
|
|
|
"-S", Arg.Set keep_asm_file, " Keep intermediate assembly file";
|
2003-07-17 01:38:28 -07:00
|
|
|
"-thread", Arg.Set use_threads, " Generate code that supports the system threads library";
|
1997-05-13 11:28:25 -07:00
|
|
|
"-unsafe", Arg.Set fast,
|
|
|
|
" No bounds checking on array and string access";
|
2002-08-01 08:18:03 -07:00
|
|
|
"-v", Arg.Unit print_version_and_library,
|
|
|
|
" Print compiler version and standard library location and exit";
|
|
|
|
"-version", Arg.Unit print_version_string,
|
|
|
|
" Print compiler version and exit";
|
1997-05-15 06:26:34 -07:00
|
|
|
"-verbose", Arg.Set verbose, " Print calls to external commands";
|
2000-08-23 10:13:17 -07:00
|
|
|
"-w", Arg.String (Warnings.parse_options false),
|
1998-11-05 10:53:15 -08:00
|
|
|
"<flags> Enable or disable warnings according to <flags>:\n\
|
1998-11-05 00:01:50 -08:00
|
|
|
\032 A/a enable/disable all warnings\n\
|
2000-03-20 12:23:07 -08:00
|
|
|
\032 C/c enable/disable suspicious comment\n\
|
2001-09-25 02:27:17 -07:00
|
|
|
\032 D/d enable/disable deprecated features\n\
|
2003-05-02 01:47:34 -07:00
|
|
|
\032 E/e enable/disable fragile match\n\
|
1998-11-05 00:01:50 -08:00
|
|
|
\032 F/f enable/disable partially applied function\n\
|
2001-09-06 01:52:32 -07:00
|
|
|
\032 L/l enable/disable labels omitted in application\n\
|
1998-11-05 00:01:50 -08:00
|
|
|
\032 M/m enable/disable overriden methods\n\
|
|
|
|
\032 P/p enable/disable partial match\n\
|
|
|
|
\032 S/s enable/disable non-unit statement\n\
|
|
|
|
\032 U/u enable/disable unused match case\n\
|
|
|
|
\032 V/v enable/disable hidden instance variables\n\
|
|
|
|
\032 X/x enable/disable all other warnings\n\
|
2003-05-02 05:52:11 -07:00
|
|
|
\032 default setting is \"Ale\"\n\
|
|
|
|
\032 (all warnings but labels and fragile match enabled)";
|
2000-08-23 10:13:17 -07:00
|
|
|
"-warn-error" , Arg.String (Warnings.parse_options true),
|
2002-11-04 04:40:51 -08:00
|
|
|
"<flags> Treat the warnings enabled by <flags> as errors.\n\
|
|
|
|
\032 See option -w for the list of flags.\n\
|
|
|
|
\032 Default setting is \"a\" (warnings are not errors)";
|
|
|
|
"-where", Arg.Unit print_standard_library,
|
|
|
|
" Print location of standard library and exit";
|
1996-10-24 07:17:48 -07:00
|
|
|
|
|
|
|
"-nopervasives", Arg.Set nopervasives, " (undocumented)";
|
2000-03-20 12:23:07 -08:00
|
|
|
"-dparsetree", Arg.Set dump_parsetree, " (undocumented)";
|
1996-10-24 07:17:48 -07:00
|
|
|
"-drawlambda", Arg.Set dump_rawlambda, " (undocumented)";
|
|
|
|
"-dlambda", Arg.Set dump_lambda, " (undocumented)";
|
|
|
|
"-dcmm", Arg.Set dump_cmm, " (undocumented)";
|
|
|
|
"-dsel", Arg.Set dump_selection, " (undocumented)";
|
1999-05-15 08:10:00 -07:00
|
|
|
"-dcombine", Arg.Set dump_combine, " (undocumented)";
|
1995-07-13 10:17:20 -07:00
|
|
|
"-dlive", Arg.Unit(fun () -> dump_live := true;
|
1996-10-24 07:17:48 -07:00
|
|
|
Printmach.print_live := true),
|
|
|
|
" (undocumented)";
|
|
|
|
"-dspill", Arg.Set dump_spill, " (undocumented)";
|
|
|
|
"-dsplit", Arg.Set dump_split, " (undocumented)";
|
|
|
|
"-dinterf", Arg.Set dump_interf, " (undocumented)";
|
|
|
|
"-dprefer", Arg.Set dump_prefer, " (undocumented)";
|
|
|
|
"-dalloc", Arg.Set dump_regalloc, " (undocumented)";
|
|
|
|
"-dreload", Arg.Set dump_reload, " (undocumented)";
|
|
|
|
"-dscheduling", Arg.Set dump_scheduling, " (undocumented)";
|
|
|
|
"-dlinear", Arg.Set dump_linear, " (undocumented)";
|
|
|
|
"-dstartup", Arg.Set keep_startup_file, " (undocumented)";
|
2000-03-06 21:02:33 -08:00
|
|
|
"-", Arg.String (process_file ppf),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<file> Treat <file> as a file name (even if it starts with `-')"
|
2002-11-29 07:03:37 -08:00
|
|
|
]) (process_file ppf) usage;
|
1995-07-02 09:51:07 -07:00
|
|
|
if !make_archive then begin
|
|
|
|
Optcompile.init_path();
|
2002-06-11 07:15:12 -07:00
|
|
|
Asmlibrarian.create_archive (List.rev !objfiles)
|
|
|
|
(extract_output !output_name)
|
1995-07-02 09:51:07 -07:00
|
|
|
end
|
2002-02-08 08:55:44 -08:00
|
|
|
else if !make_package then begin
|
|
|
|
Optcompile.init_path();
|
2002-06-11 07:15:12 -07:00
|
|
|
Asmpackager.package_files ppf (List.rev !objfiles)
|
|
|
|
(extract_output !output_name)
|
2002-02-08 08:55:44 -08:00
|
|
|
end
|
2000-01-24 08:20:57 -08:00
|
|
|
else if not !compile_only && !objfiles <> [] then begin
|
1995-07-02 09:51:07 -07:00
|
|
|
Optcompile.init_path();
|
2002-06-11 07:15:12 -07:00
|
|
|
Asmlink.link ppf (List.rev !objfiles) (default_output !output_name)
|
1995-07-02 09:51:07 -07:00
|
|
|
end;
|
|
|
|
exit 0
|
|
|
|
with x ->
|
2000-03-06 21:02:33 -08:00
|
|
|
Opterrors.report_error ppf x;
|
1995-07-02 09:51:07 -07:00
|
|
|
exit 2
|
|
|
|
|
2002-02-08 08:55:44 -08:00
|
|
|
let _ = main ()
|