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
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let process_interface_file ppf name =
|
|
|
|
Compile.interface ppf name
|
1996-05-22 05:41:36 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let process_implementation_file ppf name =
|
|
|
|
Compile.implementation ppf name;
|
1996-05-22 05:41:36 -07:00
|
|
|
objfiles := (Filename.chop_extension name ^ ".cmo") :: !objfiles
|
|
|
|
|
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
|
2000-03-06 14:12:09 -08:00
|
|
|
Compile.implementation ppf name;
|
1995-10-24 08:37:23 -07:00
|
|
|
objfiles := (Filename.chop_extension name ^ ".cmo") :: !objfiles
|
1995-05-04 03:15:53 -07:00
|
|
|
end
|
1998-05-27 07:10:14 -07:00
|
|
|
else if Filename.check_suffix name !Config.interface_suffix then
|
2000-03-06 14:12:09 -08:00
|
|
|
Compile.interface ppf name
|
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
|
1996-02-15 08:19:09 -08:00
|
|
|
else if Filename.check_suffix name ext_obj
|
2001-08-28 07:47:48 -07:00
|
|
|
|| Filename.check_suffix name ext_lib
|
|
|
|
|| Filename.check_suffix name ext_dll then
|
1995-05-04 03:15:53 -07:00
|
|
|
ccobjs := name :: !ccobjs
|
|
|
|
else if Filename.check_suffix name ".c" then begin
|
|
|
|
Compile.c_file name;
|
2000-01-07 08:35:15 -08:00
|
|
|
match Sys.os_type with
|
|
|
|
| "MacOS" -> ccobjs := (name ^ ".o") :: (name ^ ".x") :: !ccobjs
|
|
|
|
| _ ->
|
1999-11-29 11:03:24 -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))
|
|
|
|
|
|
|
|
let print_version_number () =
|
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
|
|
|
|
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;;
|
|
|
|
|
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
|
1998-04-06 09:32:57 -07:00
|
|
|
let _cclib s = ccobjs := s :: !ccobjs
|
|
|
|
let _ccopt s = ccopts := s :: !ccopts
|
|
|
|
let _custom = set custom_runtime
|
2001-08-28 07:47:48 -07:00
|
|
|
let _dllpath s = dllpaths := !dllpaths @ [s]
|
1998-04-06 09:32:57 -07:00
|
|
|
let _g = set debug
|
|
|
|
let _i = set print_types
|
|
|
|
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
|
1998-04-06 09:32:57 -07:00
|
|
|
let _o s = exec_name := s; archive_name := s; object_name := s
|
|
|
|
let _output_obj () = output_c_object := true; custom_runtime := true
|
|
|
|
let _pp s = preprocessor := Some s
|
1999-11-08 15:45:01 -08:00
|
|
|
let _rectypes = set recursive_types
|
1998-04-06 09:32:57 -07:00
|
|
|
let _thread = set thread_safe
|
|
|
|
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
|
1998-04-06 09:32:57 -07:00
|
|
|
let _v = print_version_number
|
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)
|
|
|
|
|
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();
|
1995-07-11 11:07:53 -07:00
|
|
|
Bytelibrarian.create_archive (List.rev !objfiles) !archive_name
|
1995-05-04 03:15:53 -07: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();
|
1995-07-02 09:45:41 -07:00
|
|
|
Bytelink.link (List.rev !objfiles)
|
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
|
|
|
|
|
|
|
|
let _ = Printexc.catch main ()
|