Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/Changes b/Changes
- index d952260..3def852 100644
- --- a/Changes
- +++ b/Changes
- @@ -127,6 +127,9 @@ Compilers:
- incrementally (Jacques Garrigue)
- - PR#6642: replace $CAMLORIGIN in -ccopt with the path to cma or cmxa
- (Peter Zotov, Gabriel Scherer, review by Damien Doligez)
- +- PR#6797: accept ocaml{c,opt} -output-complete-obj
- + and link in the runtime and autolink libraries
- + (Peter Zotov)
- Toplevel and debugger:
- - PR#5958: generalized polymorphic #install_printer
- diff --git a/asmcomp/asmlink.ml b/asmcomp/asmlink.ml
- index 79f657e..5c4349b 100644
- --- a/asmcomp/asmlink.ml
- +++ b/asmcomp/asmlink.ml
- @@ -277,12 +277,13 @@ let link_shared ppf objfiles output_name =
- let call_linker file_list startup_file output_name =
- let main_dll = !Clflags.output_c_object
- && Filename.check_suffix output_name Config.ext_dll
- + and main_obj_runtime = !Clflags.output_complete_object
- in
- let files = startup_file :: (List.rev file_list) in
- let files, c_lib =
- - if (not !Clflags.output_c_object) || main_dll then
- + if (not !Clflags.output_c_object) || main_dll || main_obj_runtime then
- files @ (List.rev !Clflags.ccobjs) @ runtime_lib (),
- - (if !Clflags.nopervasives then "" else Config.native_c_libraries)
- + (if !Clflags.nopervasives || main_obj_runtime then "" else Config.native_c_libraries)
- else
- files, ""
- in
- diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml
- index c4c35bf..006c0a6 100644
- --- a/bytecomp/bytelink.ml
- +++ b/bytecomp/bytelink.ml
- @@ -574,7 +574,11 @@ let link ppf objfiles output_name =
- end else begin
- let basename = Filename.chop_extension output_name in
- let c_file = basename ^ ".c"
- - and obj_file = basename ^ Config.ext_obj in
- + and obj_file =
- + if !Clflags.output_complete_object
- + then Filename.temp_file "camlobj" Config.ext_obj
- + else basename ^ Config.ext_obj
- + in
- if Sys.file_exists c_file then raise(Error(File_exists c_file));
- let temps = ref [] in
- try
- @@ -583,13 +587,19 @@ let link ppf objfiles output_name =
- temps := c_file :: !temps;
- if Ccomp.compile_file ~output_name:(Some obj_file) c_file <> 0 then
- raise(Error Custom_runtime);
- - if not (Filename.check_suffix output_name Config.ext_obj) then begin
- + if not (Filename.check_suffix output_name Config.ext_obj) ||
- + !Clflags.output_complete_object then begin
- temps := obj_file :: !temps;
- + let mode, c_libs =
- + if Filename.check_suffix output_name Config.ext_obj
- + then Ccomp.Partial, ""
- + else Ccomp.MainDll, Config.bytecomp_c_libraries
- + in
- if not (
- let runtime_lib = "-lcamlrun" ^ !Clflags.runtime_variant in
- - Ccomp.call_linker Ccomp.MainDll output_name
- + Ccomp.call_linker mode output_name
- ([obj_file] @ List.rev !Clflags.ccobjs @ [runtime_lib])
- - Config.bytecomp_c_libraries
- + c_libs
- ) then raise (Error Custom_runtime);
- end
- end;
- diff --git a/driver/main.ml b/driver/main.ml
- index f8358a0..a390c7c 100644
- --- a/driver/main.ml
- +++ b/driver/main.ml
- @@ -106,6 +106,8 @@ module Options = Main_args.Make_bytecomp_options (struct
- let _o s = output_name := Some s
- let _open s = open_modules := s :: !open_modules
- let _output_obj () = output_c_object := true; custom_runtime := true
- + let _output_complete_obj () =
- + output_c_object := true; output_complete_object := true; custom_runtime := true
- let _pack = set make_package
- let _pp s = preprocessor := Some s
- let _ppx s = first_ppx := s :: !first_ppx
- diff --git a/driver/main_args.ml b/driver/main_args.ml
- index 7636abe..0f33e52 100644
- --- a/driver/main_args.ml
- +++ b/driver/main_args.ml
- @@ -214,7 +214,12 @@ let mk_open f =
- "-open", Arg.String f, "<module> Opens the module <module> before typing"
- let mk_output_obj f =
- - "-output-obj", Arg.Unit f, " Output a C object file instead of an executable"
- + "-output-obj", Arg.Unit f, " Output an object file instead of an executable"
- +;;
- +
- +let mk_output_complete_obj f =
- + "-output-complete-obj", Arg.Unit f,
- + " Output an object file, including runtime, instead of an executable"
- ;;
- let mk_p f =
- @@ -521,6 +526,7 @@ module type Compiler_options = sig
- val _noautolink : unit -> unit
- val _o : string -> unit
- val _output_obj : unit -> unit
- + val _output_complete_obj : unit -> unit
- val _pack : unit -> unit
- val _pp : string -> unit
- val _principal : unit -> unit
- @@ -668,6 +674,7 @@ struct
- mk_o F._o;
- mk_open F._open;
- mk_output_obj F._output_obj;
- + mk_output_complete_obj F._output_complete_obj;
- mk_pack_byt F._pack;
- mk_pp F._pp;
- mk_ppx F._ppx;
- @@ -783,6 +790,7 @@ struct
- mk_o F._o;
- mk_open F._open;
- mk_output_obj F._output_obj;
- + mk_output_complete_obj F._output_complete_obj;
- mk_p F._p;
- mk_pack_opt F._pack;
- mk_pp F._pp;
- diff --git a/driver/main_args.mli b/driver/main_args.mli
- index 18ade80..021a952 100644
- --- a/driver/main_args.mli
- +++ b/driver/main_args.mli
- @@ -67,6 +67,7 @@ module type Compiler_options = sig
- val _noautolink : unit -> unit
- val _o : string -> unit
- val _output_obj : unit -> unit
- + val _output_complete_obj : unit -> unit
- val _pack : unit -> unit
- val _pp : string -> unit
- val _principal : unit -> unit
- diff --git a/driver/optmain.ml b/driver/optmain.ml
- index 947d430..0e2eb3c 100644
- --- a/driver/optmain.ml
- +++ b/driver/optmain.ml
- @@ -104,6 +104,8 @@ module Options = Main_args.Make_optcomp_options (struct
- let _o s = output_name := Some s
- let _open s = open_modules := s :: !open_modules
- let _output_obj = set output_c_object
- + let _output_complete_obj s =
- + set output_c_object s; set output_complete_object s
- let _p = set gprofile
- let _pack = set make_package
- let _pp s = preprocessor := Some s
- diff --git a/tools/ocamlcp.ml b/tools/ocamlcp.ml
- index 51559ae..b5a124f 100644
- --- a/tools/ocamlcp.ml
- +++ b/tools/ocamlcp.ml
- @@ -74,6 +74,7 @@ module Options = Main_args.Make_bytecomp_options (struct
- let _o s = option_with_arg "-o" s
- let _open s = option_with_arg "-open" s
- let _output_obj = option "-output-obj"
- + let _output_complete_obj = option "-output-complete-obj"
- let _pack = option "-pack"
- let _pp _s = incompatible "-pp"
- let _ppx _s = incompatible "-ppx"
- diff --git a/tools/ocamloptp.ml b/tools/ocamloptp.ml
- index 0b78884..a0d20ed 100644
- --- a/tools/ocamloptp.ml
- +++ b/tools/ocamloptp.ml
- @@ -75,6 +75,7 @@ module Options = Main_args.Make_optcomp_options (struct
- let _o s = option_with_arg "-o" s
- let _open s = option_with_arg "-open" s
- let _output_obj = option "-output-obj"
- + let _output_complete_obj = option "-output-complete-obj"
- let _p = option "-p"
- let _pack = option "-pack"
- let _pp _s = incompatible "-pp"
- diff --git a/utils/ccomp.ml b/utils/ccomp.ml
- index 4bea268..a897ddc 100644
- --- a/utils/ccomp.ml
- +++ b/utils/ccomp.ml
- @@ -101,14 +101,22 @@ type link_mode =
- | MainDll
- | Partial
- +let remove_Wl cclibs =
- + cclibs |> List.map (fun cclib ->
- + (* -Wl,-foo,bar -> -foo bar *)
- + if String.length cclib >= 4 && "-Wl," = String.sub cclib 0 4 then
- + String.map (function ',' -> ' ' | c -> c)
- + (String.sub cclib 4 (String.length cclib - 4))
- + else cclib)
- +
- let call_linker mode output_name files extra =
- - let files = quote_files files in
- let cmd =
- if mode = Partial then
- - Printf.sprintf "%s%s %s %s"
- + Printf.sprintf "%s%s %s %s %s"
- Config.native_pack_linker
- (Filename.quote output_name)
- - files
- + (quote_prefixed "-L" !Config.load_path)
- + (quote_files (remove_Wl files))
- extra
- else
- Printf.sprintf "%s -o %s %s %s %s %s %s %s"
- @@ -124,7 +132,7 @@ let call_linker mode output_name files extra =
- "" (*(Clflags.std_include_flag "-I")*)
- (quote_prefixed "-L" !Config.load_path)
- (String.concat " " (List.rev !Clflags.all_ccopts))
- - files
- + (quote_files files)
- extra
- in
- command cmd = 0
- diff --git a/utils/clflags.ml b/utils/clflags.ml
- index c65790c..a7fc598 100644
- --- a/utils/clflags.ml
- +++ b/utils/clflags.ml
- @@ -28,6 +28,7 @@ and link_everything = ref false (* -linkall *)
- and custom_runtime = ref false (* -custom *)
- and bytecode_compatible_32 = ref false (* -compat-32 *)
- and output_c_object = ref false (* -output-obj *)
- +and output_complete_object = ref false (* -output-complete-obj *)
- and all_ccopts = ref ([] : string list) (* -ccopt *)
- and classic = ref false (* -nolabels *)
- and nopervasives = ref false (* -nopervasives *)
- diff --git a/utils/clflags.mli b/utils/clflags.mli
- index 59cbd3f..873e04f 100644
- --- a/utils/clflags.mli
- +++ b/utils/clflags.mli
- @@ -25,6 +25,7 @@ val link_everything : bool ref
- val custom_runtime : bool ref
- val bytecode_compatible_32 : bool ref
- val output_c_object : bool ref
- +val output_complete_object : bool ref
- val all_ccopts : string list ref
- val classic : bool ref
- val nopervasives : bool ref
Add Comment
Please, Sign In to add comment