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
|
|
|
|
|
1996-05-22 05:41:36 -07:00
|
|
|
let process_interface_file name =
|
|
|
|
Compile.interface name
|
|
|
|
|
|
|
|
let process_implementation_file name =
|
|
|
|
Compile.implementation name;
|
|
|
|
objfiles := (Filename.chop_extension name ^ ".cmo") :: !objfiles
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let process_file name =
|
1995-10-24 08:37:23 -07:00
|
|
|
if Filename.check_suffix name ".ml"
|
|
|
|
or Filename.check_suffix name ".mlt" then begin
|
1995-05-04 03:15:53 -07:00
|
|
|
Compile.implementation 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
|
1995-05-04 03:15:53 -07:00
|
|
|
Compile.interface name
|
|
|
|
else if Filename.check_suffix name ".cmo"
|
|
|
|
or Filename.check_suffix name ".cma" 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-05-04 03:15:53 -07:00
|
|
|
ccobjs := name :: !ccobjs
|
|
|
|
else if Filename.check_suffix name ".c" then begin
|
|
|
|
Compile.c_file name;
|
1999-11-29 11:03:24 -08:00
|
|
|
match Sys.os_type with
|
|
|
|
| "MacOS" -> ccobjs := (name ^ ".o") :: (name ^ ".x") :: !ccobjs
|
|
|
|
| _ ->
|
|
|
|
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: ";
|
|
|
|
print_string Config.standard_library; print_newline()
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-02-19 08:10:33 -08:00
|
|
|
let usage = "Usage: ocamlc <options> <files>\nOptions are:"
|
1996-10-24 07:17:48 -07:00
|
|
|
|
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
|
1998-11-06 07:39:43 -08:00
|
|
|
let _cc s = c_compiler := 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
|
|
|
|
let _g = set debug
|
|
|
|
let _i = set print_types
|
|
|
|
let _I s = include_dirs := s :: !include_dirs
|
|
|
|
let _impl = process_implementation_file
|
|
|
|
let _intf = process_interface_file
|
1998-05-27 07:10:14 -07:00
|
|
|
let _intf_suffix s = Config.interface_suffix := s
|
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
|
1999-11-30 08:07:38 -08:00
|
|
|
let _modern = unset classic
|
1998-04-06 09:32:57 -07:00
|
|
|
let _noassert = set noassert
|
|
|
|
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
|
1998-11-05 00:01:50 -08:00
|
|
|
let _w = Warnings.parse_options
|
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
|
|
|
|
let anonymous = process_file
|
|
|
|
end)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let main () =
|
1999-11-08 09:06:33 -08:00
|
|
|
Formatmsg.set_output Format.err_formatter;
|
1995-05-04 03:15:53 -07:00
|
|
|
try
|
1998-04-06 09:32:57 -07:00
|
|
|
Arg.parse Options.list process_file 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
|
|
|
|
else if not !compile_only & !objfiles <> [] then begin
|
|
|
|
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 ->
|
|
|
|
Errors.report_error x;
|
|
|
|
exit 2
|
|
|
|
|
|
|
|
let _ = Printexc.catch main ()
|