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;
|
1996-05-22 05:41:36 -07:00
|
|
|
objfiles := (Filename.chop_extension name ^ ".cmx") :: !objfiles
|
|
|
|
|
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"
|
|
|
|
or Filename.check_suffix name ".mlt" then begin
|
2000-03-06 21:02:33 -08:00
|
|
|
Optcompile.implementation ppf name;
|
1995-10-24 08:37:23 -07:00
|
|
|
objfiles := (Filename.chop_extension name ^ ".cmx") :: !objfiles
|
1995-07-02 09:51:07 -07:00
|
|
|
end
|
1998-05-27 07:10:14 -07:00
|
|
|
else if Filename.check_suffix name !Config.interface_suffix then
|
2000-03-06 21:02:33 -08:00
|
|
|
Optcompile.interface ppf name
|
1995-07-02 09:51:07 -07:00
|
|
|
else if Filename.check_suffix name ".cmx"
|
|
|
|
or Filename.check_suffix name ".cmxa" then
|
|
|
|
objfiles := name :: !objfiles
|
1996-02-15 08:19:09 -08:00
|
|
|
else if Filename.check_suffix name ext_obj
|
|
|
|
or 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))
|
|
|
|
|
|
|
|
let print_version_number () =
|
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
|
|
|
|
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-03-06 21:02:33 -08:00
|
|
|
let ppf = Format.err_formatter in
|
1995-07-02 09:51:07 -07:00
|
|
|
try
|
1996-10-24 07:17:48 -07:00
|
|
|
Arg.parse [
|
|
|
|
"-a", Arg.Set make_archive, " Build a library";
|
|
|
|
"-c", Arg.Set compile_only, " Compile only (do not link)";
|
1998-11-06 07:39:43 -08:00
|
|
|
"-cc", Arg.String(fun s -> c_compiler := s),
|
|
|
|
"<comp> Use <comp> as the C compiler and linker";
|
1996-10-24 07:17:48 -07:00
|
|
|
"-cclib", Arg.String(fun s -> ccobjs := s :: !ccobjs),
|
|
|
|
"<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";
|
1998-08-06 06:27:38 -07:00
|
|
|
"-i", Arg.Set print_types, " Print the inferred types";
|
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),
|
1998-05-27 07:10:14 -07:00
|
|
|
"<file> Suffix for interface file (default: .mli)";
|
1998-11-04 02:56:01 -08:00
|
|
|
"-intf_suffix", Arg.String (fun s -> Config.interface_suffix := s),
|
|
|
|
"<file> same as -intf-suffix";
|
1997-02-19 08:10:33 -08:00
|
|
|
"-linkall", Arg.Set link_everything,
|
|
|
|
" Link all modules, even unused ones";
|
1999-11-30 08:07:38 -08:00
|
|
|
"-modern", Arg.Clear classic, " Use strict label syntax";
|
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";
|
1996-11-08 06:46:18 -08:00
|
|
|
"-o", Arg.String(fun s -> exec_name := s;
|
|
|
|
archive_name := s;
|
|
|
|
object_name := s),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<file> Set output file name to <file> (default a.out)";
|
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)";
|
1996-10-24 07:17:48 -07:00
|
|
|
"-pp", Arg.String(fun s -> preprocessor := Some s),
|
|
|
|
"<command> Pipe sources through preprocessor <command>";
|
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";
|
1997-11-18 09:14:54 -08:00
|
|
|
"-thread", Arg.Set thread_safe, " Use thread-safe standard library";
|
1997-05-13 11:28:25 -07:00
|
|
|
"-unsafe", Arg.Set fast,
|
|
|
|
" No bounds checking on array and string access";
|
1996-10-24 07:17:48 -07:00
|
|
|
"-v", Arg.Unit print_version_number, " Print compiler version number";
|
1997-05-15 06:26:34 -07:00
|
|
|
"-verbose", Arg.Set verbose, " Print calls to external commands";
|
1998-11-05 10:53:15 -08:00
|
|
|
"-w", Arg.String Warnings.parse_options,
|
|
|
|
"<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\
|
|
|
|
\032 F/f enable/disable partially applied function\n\
|
|
|
|
\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\
|
1998-11-05 10:53:15 -08:00
|
|
|
\032 default setting is A (all warnings enabled)";
|
1996-10-24 07:17:48 -07:00
|
|
|
|
|
|
|
"-nopervasives", Arg.Set nopervasives, " (undocumented)";
|
|
|
|
"-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 `-')"
|
2000-03-06 21:02:33 -08:00
|
|
|
] (process_file ppf) usage;
|
1995-07-02 09:51:07 -07:00
|
|
|
if !make_archive then begin
|
|
|
|
Optcompile.init_path();
|
1995-07-11 11:07:53 -07:00
|
|
|
Asmlibrarian.create_archive (List.rev !objfiles) !archive_name
|
1995-07-02 09:51:07 -07: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();
|
|
|
|
Asmlink.link (List.rev !objfiles)
|
|
|
|
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
|
|
|
|
|
|
|
|
let _ = Printexc.catch main ()
|