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-05-04 03:15:53 -07:00
|
|
|
open Clflags
|
|
|
|
|
2004-06-13 05:46:41 -07:00
|
|
|
let output_prefix name =
|
|
|
|
let oname =
|
|
|
|
match !output_name with
|
|
|
|
| None -> name
|
|
|
|
| Some n -> if !compile_only then (output_name := None; n) else name in
|
|
|
|
Misc.chop_extension_if_any oname
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let process_interface_file ppf name =
|
2004-06-13 05:46:41 -07:00
|
|
|
Compile.interface ppf name (output_prefix name)
|
1996-05-22 05:41:36 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let process_implementation_file ppf name =
|
2004-06-13 05:46:41 -07:00
|
|
|
let opref = output_prefix name in
|
|
|
|
Compile.implementation ppf name opref;
|
|
|
|
objfiles := (opref ^ ".cmo") :: !objfiles
|
1996-05-22 05:41:36 -07:00
|
|
|
|
2000-03-06 14:12:09 -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
|
2004-06-13 05:46:41 -07:00
|
|
|
let opref = output_prefix name in
|
|
|
|
Compile.implementation ppf name opref;
|
|
|
|
objfiles := (opref ^ ".cmo") :: !objfiles
|
1995-05-04 03:15:53 -07:00
|
|
|
end
|
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
|
|
|
|
Compile.interface ppf name opref;
|
|
|
|
if !make_package then objfiles := (opref ^ ".cmi") :: !objfiles
|
2004-04-09 06:32:28 -07:00
|
|
|
end
|
2000-01-07 08:35:15 -08:00
|
|
|
else if Filename.check_suffix name ".cmo"
|
2000-12-28 05:07:42 -08:00
|
|
|
|| Filename.check_suffix name ".cma" then
|
1995-05-04 03:15:53 -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
|
2001-10-30 01:32:32 -08:00
|
|
|
|| Filename.check_suffix name ext_lib then
|
1995-05-04 03:15:53 -07:00
|
|
|
ccobjs := name :: !ccobjs
|
2001-10-30 01:32:32 -08:00
|
|
|
else if Filename.check_suffix name ext_dll then
|
|
|
|
dllibs := name :: !dllibs
|
1995-05-04 03:15:53 -07:00
|
|
|
else if Filename.check_suffix name ".c" then begin
|
|
|
|
Compile.c_file name;
|
2004-01-16 07:24:03 -08:00
|
|
|
ccobjs := (Filename.chop_suffix (Filename.basename name) ".c" ^ ext_obj)
|
|
|
|
:: !ccobjs
|
1995-05-04 03:15:53 -07:00
|
|
|
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 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-05-04 03:15:53 -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
|
|
|
|
|
1997-02-19 08:10:33 -08:00
|
|
|
let usage = "Usage: ocamlc <options> <files>\nOptions are:"
|
1996-10-24 07:17:48 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
(* Error messages to standard error formatter *)
|
|
|
|
let anonymous = process_file Format.err_formatter;;
|
|
|
|
let impl = process_implementation_file Format.err_formatter;;
|
|
|
|
let intf = process_interface_file Format.err_formatter;;
|
|
|
|
|
2005-05-09 06:39:17 -07:00
|
|
|
let show_config () =
|
|
|
|
Config.print_config stdout;
|
|
|
|
exit 0;
|
|
|
|
;;
|
|
|
|
|
1998-04-06 09:32:57 -07:00
|
|
|
module Options = Main_args.Make_options (struct
|
|
|
|
let set r () = r := true
|
1999-11-30 08:07:38 -08:00
|
|
|
let unset r () = r := false
|
1998-04-06 09:32:57 -07:00
|
|
|
let _a = set make_archive
|
|
|
|
let _c = set compile_only
|
2000-04-16 07:34:58 -07:00
|
|
|
let _cc s = c_compiler := s; c_linker := s
|
2002-05-07 06:16:57 -07:00
|
|
|
let _cclib s = ccobjs := Misc.rev_split_words s @ !ccobjs
|
1998-04-06 09:32:57 -07:00
|
|
|
let _ccopt s = ccopts := s :: !ccopts
|
2005-05-09 06:39:17 -07:00
|
|
|
let _config = show_config
|
1998-04-06 09:32:57 -07:00
|
|
|
let _custom = set custom_runtime
|
2002-05-07 06:16:57 -07:00
|
|
|
let _dllib s = dllibs := Misc.rev_split_words s @ !dllibs
|
2001-08-28 07:47:48 -07:00
|
|
|
let _dllpath s = dllpaths := !dllpaths @ [s]
|
2003-04-03 05:59:38 -08:00
|
|
|
let _dtypes = set save_types
|
1998-04-06 09:32:57 -07:00
|
|
|
let _g = set debug
|
2003-06-23 06:22:09 -07:00
|
|
|
let _i () = print_types := true; compile_only := true
|
1998-04-06 09:32:57 -07:00
|
|
|
let _I s = include_dirs := s :: !include_dirs
|
2000-03-06 14:12:09 -08:00
|
|
|
let _impl = impl
|
|
|
|
let _intf = intf
|
1998-05-27 07:10:14 -07:00
|
|
|
let _intf_suffix s = Config.interface_suffix := s
|
2000-03-24 11:31:25 -08:00
|
|
|
let _labels = unset classic
|
1998-04-06 09:32:57 -07:00
|
|
|
let _linkall = set link_everything
|
1998-04-14 07:48:34 -07:00
|
|
|
let _make_runtime () =
|
|
|
|
custom_runtime := true; make_runtime := true; link_everything := true
|
1998-04-06 09:32:57 -07:00
|
|
|
let _noassert = set noassert
|
2001-09-06 01:52:32 -07:00
|
|
|
let _nolabels = set classic
|
2000-03-09 01:12:28 -08:00
|
|
|
let _noautolink = set no_auto_link
|
2002-02-14 07:17:11 -08:00
|
|
|
let _nostdlib = set no_std_include
|
2002-06-11 07:15:12 -07:00
|
|
|
let _o s = output_name := Some s
|
1998-04-06 09:32:57 -07:00
|
|
|
let _output_obj () = output_c_object := true; custom_runtime := true
|
2002-02-08 08:55:44 -08:00
|
|
|
let _pack = set make_package
|
1998-04-06 09:32:57 -07:00
|
|
|
let _pp s = preprocessor := Some s
|
2002-04-18 00:27:47 -07:00
|
|
|
let _principal = set principal
|
1999-11-08 15:45:01 -08:00
|
|
|
let _rectypes = set recursive_types
|
2003-07-17 01:38:28 -07:00
|
|
|
let _thread = set use_threads
|
|
|
|
let _vmthread = set use_vmthreads
|
1998-04-06 09:32:57 -07:00
|
|
|
let _unsafe = set fast
|
1998-10-02 05:40:44 -07:00
|
|
|
let _use_prims s = use_prims := s
|
1998-04-14 07:48:34 -07:00
|
|
|
let _use_runtime s = use_runtime := s
|
2002-08-01 08:18:03 -07:00
|
|
|
let _v = print_version_and_library
|
|
|
|
let _version = print_version_string
|
2000-08-23 10:13:17 -07:00
|
|
|
let _w = (Warnings.parse_options false)
|
|
|
|
let _warn_error = (Warnings.parse_options true)
|
2000-11-07 06:41:12 -08:00
|
|
|
let _where = print_standard_library
|
1998-04-06 09:32:57 -07:00
|
|
|
let _verbose = set verbose
|
|
|
|
let _nopervasives = set nopervasives
|
1999-09-08 10:42:13 -07:00
|
|
|
let _dparsetree = set dump_parsetree
|
1998-04-06 09:32:57 -07:00
|
|
|
let _drawlambda = set dump_rawlambda
|
|
|
|
let _dlambda = set dump_lambda
|
|
|
|
let _dinstr = set dump_instr
|
2000-03-06 14:12:09 -08:00
|
|
|
let anonymous = anonymous
|
1998-04-06 09:32:57 -07:00
|
|
|
end)
|
|
|
|
|
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
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let main () =
|
|
|
|
try
|
2000-03-06 14:12:09 -08:00
|
|
|
Arg.parse Options.list anonymous usage;
|
1995-05-04 03:15:53 -07:00
|
|
|
if !make_archive then begin
|
|
|
|
Compile.init_path();
|
2002-06-11 07:15:12 -07:00
|
|
|
Bytelibrarian.create_archive (List.rev !objfiles)
|
|
|
|
(extract_output !output_name)
|
1995-05-04 03:15:53 -07:00
|
|
|
end
|
2002-02-08 08:55:44 -08:00
|
|
|
else if !make_package then begin
|
|
|
|
Compile.init_path();
|
2002-06-11 07:15:12 -07:00
|
|
|
Bytepackager.package_files (List.rev !objfiles)
|
|
|
|
(extract_output !output_name)
|
2002-02-08 08:55:44 -08:00
|
|
|
end
|
2000-03-06 14:12:09 -08:00
|
|
|
else if not !compile_only && !objfiles <> [] then begin
|
1995-05-04 03:15:53 -07:00
|
|
|
Compile.init_path();
|
2002-06-11 07:15:12 -07:00
|
|
|
Bytelink.link (List.rev !objfiles) (default_output !output_name)
|
1995-05-04 03:15:53 -07:00
|
|
|
end;
|
|
|
|
exit 0
|
|
|
|
with x ->
|
2000-03-06 14:12:09 -08:00
|
|
|
Errors.report_error Format.err_formatter x;
|
1995-05-04 03:15:53 -07:00
|
|
|
exit 2
|
|
|
|
|
2002-02-08 08:55:44 -08:00
|
|
|
let _ = main ()
|