1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
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
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
1996-02-15 08:19:09 -08:00
|
|
|
open Config
|
1995-07-02 09:51:07 -07:00
|
|
|
open Clflags
|
2013-06-05 09:34:40 -07:00
|
|
|
open Compenv
|
2004-06-13 05:46:41 -07:00
|
|
|
|
2012-01-20 06:23:34 -08:00
|
|
|
let process_interface_file ppf name =
|
|
|
|
Optcompile.interface ppf name (output_prefix name)
|
1996-05-22 05:41:36 -07:00
|
|
|
|
2012-01-20 06:23:34 -08:00
|
|
|
let process_implementation_file ppf name =
|
2004-06-13 05:46:41 -07:00
|
|
|
let opref = output_prefix name in
|
2012-01-20 06:23:34 -08:00
|
|
|
Optcompile.implementation ppf name opref;
|
2004-06-13 05:46:41 -07:00
|
|
|
objfiles := (opref ^ ".cmx") :: !objfiles
|
1996-05-22 05:41:36 -07:00
|
|
|
|
2012-02-06 08:44:43 -08:00
|
|
|
let cmxa_present = ref false;;
|
|
|
|
|
2012-01-20 06:23:34 -08:00
|
|
|
let process_file ppf name =
|
1995-10-24 08:37:23 -07:00
|
|
|
if Filename.check_suffix name ".ml"
|
2008-12-03 10:09:09 -08:00
|
|
|
|| Filename.check_suffix name ".mlt" then
|
2012-01-20 06:23:34 -08:00
|
|
|
process_implementation_file ppf name
|
2004-04-09 06:32:28 -07:00
|
|
|
else if Filename.check_suffix name !Config.interface_suffix then begin
|
2004-06-13 05:46:41 -07:00
|
|
|
let opref = output_prefix name in
|
2012-01-20 06:23:34 -08:00
|
|
|
Optcompile.interface ppf name opref;
|
2004-06-13 05:46:41 -07:00
|
|
|
if !make_package then objfiles := (opref ^ ".cmi") :: !objfiles
|
2004-04-09 06:32:28 -07:00
|
|
|
end
|
2012-02-06 08:44:43 -08:00
|
|
|
else if Filename.check_suffix name ".cmx" then
|
|
|
|
objfiles := name :: !objfiles
|
|
|
|
else if Filename.check_suffix name ".cmxa" then begin
|
|
|
|
cmxa_present := true;
|
1995-07-02 09:51:07 -07:00
|
|
|
objfiles := name :: !objfiles
|
2012-02-06 08:44:43 -08:00
|
|
|
end else if Filename.check_suffix name ".cmi" && !make_package then
|
2004-04-09 06:32:28 -07:00
|
|
|
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)
|
2004-06-13 05:46:41 -07:00
|
|
|
:: !ccobjs
|
1995-07-02 09:51:07 -07:00
|
|
|
end
|
|
|
|
else
|
|
|
|
raise(Arg.Bad("don't know what to do with " ^ 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
|
|
|
|
2013-06-03 12:13:24 -07:00
|
|
|
let ppf = Format.err_formatter
|
|
|
|
|
2010-04-13 03:44:25 -07:00
|
|
|
(* Error messages to standard error formatter *)
|
2013-06-03 12:13:24 -07:00
|
|
|
let anonymous filename =
|
2013-06-05 09:34:40 -07:00
|
|
|
readenv Before_compile; process_file ppf filename;;
|
2013-06-03 12:13:24 -07:00
|
|
|
let impl filename =
|
2013-06-05 09:34:40 -07:00
|
|
|
readenv Before_compile; process_implementation_file ppf filename;;
|
2013-06-03 12:13:24 -07:00
|
|
|
let intf filename =
|
2013-06-05 09:34:40 -07:00
|
|
|
readenv Before_compile; process_interface_file ppf filename;;
|
2010-04-13 03:44:25 -07:00
|
|
|
|
2005-05-09 06:39:17 -07:00
|
|
|
let show_config () =
|
|
|
|
Config.print_config stdout;
|
|
|
|
exit 0;
|
|
|
|
;;
|
|
|
|
|
2010-04-13 03:44:25 -07:00
|
|
|
module Options = Main_args.Make_optcomp_options (struct
|
|
|
|
let set r () = r := true
|
|
|
|
let clear r () = r := false
|
|
|
|
|
|
|
|
let _a = set make_archive
|
2011-12-20 02:35:43 -08:00
|
|
|
let _absname = set Location.absname
|
2010-04-13 03:44:25 -07:00
|
|
|
let _annot = set annotations
|
2012-05-30 07:52:37 -07:00
|
|
|
let _binannot = set binary_annotations
|
2010-04-13 03:44:25 -07:00
|
|
|
let _c = set compile_only
|
|
|
|
let _cc s = c_compiler := Some s
|
|
|
|
let _cclib s = ccobjs := Misc.rev_split_words s @ !ccobjs
|
2013-06-05 09:34:40 -07:00
|
|
|
let _ccopt s = first_ccopts := s :: !first_ccopts
|
2010-04-13 03:44:25 -07:00
|
|
|
let _compact = clear optimize_for_speed
|
|
|
|
let _config () = show_config ()
|
|
|
|
let _for_pack s = for_package := Some s
|
|
|
|
let _g = set debug
|
|
|
|
let _i () = print_types := true; compile_only := true
|
|
|
|
let _I dir = include_dirs := dir :: !include_dirs
|
|
|
|
let _impl = impl
|
|
|
|
let _inline n = inline_threshold := n * 8
|
|
|
|
let _intf = intf
|
|
|
|
let _intf_suffix s = Config.interface_suffix := s
|
|
|
|
let _labels = clear classic
|
|
|
|
let _linkall = set link_everything
|
|
|
|
let _no_app_funct = clear applicative_functors
|
|
|
|
let _noassert = set noassert
|
|
|
|
let _noautolink = set no_auto_link
|
|
|
|
let _nodynlink = clear dlcode
|
|
|
|
let _nolabels = set classic
|
|
|
|
let _nostdlib = set no_std_include
|
|
|
|
let _o s = output_name := Some s
|
|
|
|
let _output_obj = set output_c_object
|
|
|
|
let _p = set gprofile
|
|
|
|
let _pack = set make_package
|
|
|
|
let _pp s = preprocessor := Some s
|
2013-06-05 09:34:40 -07:00
|
|
|
let _ppx s = first_ppx := s :: !first_ppx
|
2010-04-13 03:44:25 -07:00
|
|
|
let _principal = set principal
|
2013-01-29 06:21:12 -08:00
|
|
|
let _short_paths = clear real_paths
|
2010-04-13 03:44:25 -07:00
|
|
|
let _rectypes = set recursive_types
|
2011-03-17 09:18:05 -07:00
|
|
|
let _runtime_variant s = runtime_variant := s
|
2010-04-13 03:44:25 -07:00
|
|
|
let _strict_sequence = set strict_sequence
|
|
|
|
let _shared () = shared := true; dlcode := true
|
|
|
|
let _S = set keep_asm_file
|
|
|
|
let _thread = set use_threads
|
|
|
|
let _unsafe = set fast
|
2013-06-05 09:34:40 -07:00
|
|
|
let _v () = print_version_and_library "native-code compiler"
|
2010-04-13 03:44:25 -07:00
|
|
|
let _version () = print_version_string ()
|
2010-05-20 07:06:29 -07:00
|
|
|
let _vnum () = print_version_string ()
|
2010-04-13 03:44:25 -07:00
|
|
|
let _verbose = set verbose
|
|
|
|
let _w s = Warnings.parse_options false s
|
|
|
|
let _warn_error s = Warnings.parse_options true s
|
2010-05-08 13:11:27 -07:00
|
|
|
let _warn_help = Warnings.help_warnings
|
2010-04-13 03:44:25 -07:00
|
|
|
let _where () = print_standard_library ()
|
|
|
|
|
|
|
|
let _nopervasives = set nopervasives
|
2012-10-17 09:09:38 -07:00
|
|
|
let _dsource = set dump_source
|
2010-04-13 03:44:25 -07:00
|
|
|
let _dparsetree = set dump_parsetree
|
2012-12-18 09:19:53 -08:00
|
|
|
let _dtypedtree = set dump_typedtree
|
2010-04-13 03:44:25 -07:00
|
|
|
let _drawlambda = set dump_rawlambda
|
|
|
|
let _dlambda = set dump_lambda
|
2012-02-21 09:41:02 -08:00
|
|
|
let _dclambda = set dump_clambda
|
2010-04-13 03:44:25 -07:00
|
|
|
let _dcmm = set dump_cmm
|
|
|
|
let _dsel = set dump_selection
|
|
|
|
let _dcombine = set dump_combine
|
|
|
|
let _dlive () = dump_live := true; Printmach.print_live := true
|
|
|
|
let _dspill = set dump_spill
|
|
|
|
let _dsplit = set dump_split
|
|
|
|
let _dinterf = set dump_interf
|
|
|
|
let _dprefer = set dump_prefer
|
|
|
|
let _dalloc = set dump_regalloc
|
|
|
|
let _dreload = set dump_reload
|
|
|
|
let _dscheduling = set dump_scheduling
|
|
|
|
let _dlinear = set dump_linear
|
|
|
|
let _dstartup = set keep_startup_file
|
|
|
|
|
|
|
|
let anonymous = anonymous
|
|
|
|
end);;
|
|
|
|
|
1995-07-02 09:51:07 -07:00
|
|
|
let main () =
|
1999-02-16 10:29:28 -08:00
|
|
|
native_code := true;
|
2012-01-20 06:23:34 -08:00
|
|
|
let ppf = Format.err_formatter in
|
1995-07-02 09:51:07 -07:00
|
|
|
try
|
2013-06-05 09:34:40 -07:00
|
|
|
readenv Before_args;
|
2010-04-13 03:44:25 -07:00
|
|
|
Arg.parse (Arch.command_line_options @ Options.list) anonymous usage;
|
2013-06-05 09:34:40 -07:00
|
|
|
readenv Before_link;
|
2007-11-15 08:09:57 -08:00
|
|
|
if
|
|
|
|
List.length (List.filter (fun x -> !x)
|
2009-11-19 04:27:15 -08:00
|
|
|
[make_package; make_archive; shared;
|
|
|
|
compile_only; output_c_object]) > 1
|
2007-11-15 08:09:57 -08:00
|
|
|
then
|
|
|
|
fatal "Please specify at most one of -pack, -a, -shared, -c, -output-obj";
|
1995-07-02 09:51:07 -07:00
|
|
|
if !make_archive then begin
|
2012-02-06 08:44:43 -08:00
|
|
|
if !cmxa_present then
|
|
|
|
fatal "Option -a cannot be used with .cmxa input files.";
|
2013-06-05 09:34:40 -07:00
|
|
|
Compmisc.init_path true;
|
2007-11-06 07:16:56 -08:00
|
|
|
let target = extract_output !output_name in
|
|
|
|
Asmlibrarian.create_archive (List.rev !objfiles) target;
|
2012-03-07 03:07:21 -08:00
|
|
|
Warnings.check_fatal ();
|
1995-07-02 09:51:07 -07:00
|
|
|
end
|
2002-02-08 08:55:44 -08:00
|
|
|
else if !make_package then begin
|
2013-06-05 09:34:40 -07:00
|
|
|
Compmisc.init_path true;
|
2007-11-06 07:16:56 -08:00
|
|
|
let target = extract_output !output_name in
|
2012-01-20 06:23:34 -08:00
|
|
|
Asmpackager.package_files ppf (List.rev !objfiles) target;
|
2012-03-07 03:07:21 -08:00
|
|
|
Warnings.check_fatal ();
|
2007-11-06 07:16:56 -08:00
|
|
|
end
|
|
|
|
else if !shared then begin
|
2013-06-05 09:34:40 -07:00
|
|
|
Compmisc.init_path true;
|
2007-11-06 07:16:56 -08:00
|
|
|
let target = extract_output !output_name in
|
2012-01-20 06:23:34 -08:00
|
|
|
Asmlink.link_shared ppf (List.rev !objfiles) target;
|
2012-03-07 03:07:21 -08:00
|
|
|
Warnings.check_fatal ();
|
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
|
2007-11-15 08:09:57 -08:00
|
|
|
let target =
|
|
|
|
if !output_c_object then
|
|
|
|
let s = extract_output !output_name in
|
|
|
|
if (Filename.check_suffix s Config.ext_obj
|
|
|
|
|| Filename.check_suffix s Config.ext_dll)
|
|
|
|
then s
|
|
|
|
else
|
|
|
|
fatal
|
|
|
|
(Printf.sprintf
|
|
|
|
"The extension of the output file must be %s or %s"
|
|
|
|
Config.ext_obj Config.ext_dll
|
|
|
|
)
|
|
|
|
else
|
|
|
|
default_output !output_name
|
|
|
|
in
|
2013-06-05 09:34:40 -07:00
|
|
|
Compmisc.init_path true;
|
2012-03-07 03:07:21 -08:00
|
|
|
Asmlink.link ppf (List.rev !objfiles) target;
|
|
|
|
Warnings.check_fatal ();
|
1995-07-02 09:51:07 -07:00
|
|
|
end;
|
|
|
|
exit 0
|
|
|
|
with x ->
|
2012-01-20 06:23:34 -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 ()
|