diff options
author | Nicolás Ojeda Bär <n.oje.bar@gmail.com> | 2023-03-07 10:26:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-07 10:26:25 +0100 |
commit | dcf9181b56f1b08989b878110114dbe184576495 (patch) | |
tree | 36f673a0700e6367c14164f40a3ccc6395041a29 | |
parent | 694e9506e54c2c4f4126273784a4abf483325f09 (diff) | |
download | ocaml-dcf9181b56f1b08989b878110114dbe184576495.tar.gz |
configure: check whether ar supports response files (#12075)
-rw-r--r-- | Changes | 6 | ||||
-rwxr-xr-x | configure | 11 | ||||
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | tools/ocamlmktop.ml | 4 | ||||
-rw-r--r-- | utils/ccomp.ml | 33 | ||||
-rw-r--r-- | utils/ccomp.mli | 2 | ||||
-rw-r--r-- | utils/config.fixed.ml | 1 | ||||
-rw-r--r-- | utils/config.generated.ml.in | 2 | ||||
-rw-r--r-- | utils/config.mli | 2 |
9 files changed, 52 insertions, 16 deletions
@@ -629,6 +629,12 @@ Working version - #12046: Flush stderr when tracing the parser (Hugo Heuzard, review by David Allsopp and Nicolás Ojeda Bär) +- #12075: auto-detect whether `ar` support @FILE arguments at + configure-time to avoid using this feature with toolchains + that do not support it (eg FreeBSD/Darwin). + (Nicolás Ojeda Bär, review by Xavier Leroy, David Allsop, Javier + Chávarri, Anil Madhavapeddy) + OCaml 5.0.0 (15 December 2022) ------------------------------ @@ -777,6 +777,7 @@ build_os build_vendor build_cpu build +ar_supports_response_files QS ocaml_libdir ocaml_bindir @@ -3395,6 +3396,7 @@ OCAML_VERSION_SHORT=5.1 + ## Generated files ac_config_files="$ac_config_files Makefile.build_config" @@ -13520,6 +13522,15 @@ esac ocamlsrcdir=$(unset CDPATH; cd -- "$srcdir" && printf %sX "$PWD") || fail ocamlsrcdir=${ocamlsrcdir%X} +# Whether ar supports @FILE arguments + +case lt_cv_ar_at_file in #( + no) : + ar_supports_response_files=false ;; #( + *) : + ar_supports_response_files=true ;; +esac + # Libraries to build depending on the host case $host in #( diff --git a/configure.ac b/configure.ac index 2da8b27860..231d690e12 100644 --- a/configure.ac +++ b/configure.ac @@ -213,6 +213,7 @@ AC_SUBST([compute_deps]) AC_SUBST([ocaml_bindir]) AC_SUBST([ocaml_libdir]) AC_SUBST([QS]) +AC_SUBST([ar_supports_response_files]) ## Generated files @@ -593,6 +594,12 @@ AS_CASE([$ocaml_cv_cc_vendor], ocamlsrcdir=$(unset CDPATH; cd -- "$srcdir" && printf %sX "$PWD") || fail ocamlsrcdir=${ocamlsrcdir%X} +# Whether ar supports @FILE arguments + +AS_CASE([lt_cv_ar_at_file], + [no], [ar_supports_response_files=false], + [ar_supports_response_files=true]) + # Libraries to build depending on the host AS_CASE([$host], diff --git a/tools/ocamlmktop.ml b/tools/ocamlmktop.ml index 78fbeacdfe..cc3aeb23ef 100644 --- a/tools/ocamlmktop.ml +++ b/tools/ocamlmktop.ml @@ -14,7 +14,9 @@ (**************************************************************************) let main () = - let args = Ccomp.quote_files (List.tl (Array.to_list Sys.argv)) in + let args = + Ccomp.quote_files ~response_files:true (List.tl (Array.to_list Sys.argv)) + in let ocamlmktop = Sys.executable_name in (* On Windows Sys.command calls system() which in turn calls 'cmd.exe /c'. cmd.exe has special quoting rules (see 'cmd.exe /?' for details). diff --git a/utils/ccomp.ml b/utils/ccomp.ml index d23c3f2baa..33a4c9d0b4 100644 --- a/utils/ccomp.ml +++ b/utils/ccomp.ml @@ -38,26 +38,27 @@ let run_command cmdline = ignore(command cmdline) between 70000 and 80000 for macOS). *) -let build_diversion lst = +let build_response_file lst = let (responsefile, oc) = Filename.open_temp_file "camlresp" "" in List.iter (fun f -> Printf.fprintf oc "%s\n" f) lst; close_out oc; at_exit (fun () -> Misc.remove_file responsefile); "@" ^ responsefile -let quote_files lst = +let quote_files ~response_files lst = let lst = List.filter (fun f -> f <> "") lst in let quoted = List.map Filename.quote lst in let s = String.concat " " quoted in - if String.length s >= 65536 - || (String.length s >= 4096 && Sys.os_type = "Win32") - then build_diversion quoted + if response_files && + (String.length s >= 65536 + || (String.length s >= 4096 && Sys.os_type = "Win32")) + then build_response_file quoted else s -let quote_prefixed pr lst = +let quote_prefixed ~response_files pr lst = let lst = List.filter (fun f -> f <> "") lst in let lst = List.map (fun f -> pr ^ f) lst in - quote_files lst + quote_files ~response_files lst let quote_optfile = function | None -> "" @@ -112,7 +113,7 @@ let compile_file ?output ?(opt="") ?stable_name name = opt (if !Clflags.debug && Config.ccomp_type <> "msvc" then "-g" else "") (String.concat " " (List.rev !Clflags.all_ccopts)) - (quote_prefixed "-I" + (quote_prefixed ~response_files:true "-I" (List.map (Misc.expand_directory Config.standard_library) (List.rev !Clflags.include_dirs))) (Clflags.std_include_flag "-I") @@ -137,11 +138,14 @@ let create_archive archive file_list = match Config.ccomp_type with "msvc" -> command(Printf.sprintf "link /lib /nologo /out:%s %s" - quoted_archive (quote_files file_list)) + quoted_archive + (quote_files ~response_files:true file_list)) | _ -> assert(String.length Config.ar > 0); command(Printf.sprintf "%s rc %s %s" - Config.ar quoted_archive (quote_files file_list)) + Config.ar quoted_archive + (quote_files ~response_files:Config.ar_supports_response_files + file_list)) let expand_libname cclibs = cclibs |> List.map (fun cclib -> @@ -180,8 +184,9 @@ let call_linker mode output_name files extra = Printf.sprintf "%s%s %s %s %s" Config.native_pack_linker (Filename.quote output_name) - (quote_prefixed l_prefix (Load_path.get_paths ())) - (quote_files (remove_Wl files)) + (quote_prefixed ~response_files:true + l_prefix (Load_path.get_paths ())) + (quote_files ~response_files:true (remove_Wl files)) extra else Printf.sprintf "%s -o %s %s %s %s %s %s" @@ -194,9 +199,9 @@ let call_linker mode output_name files extra = ) (Filename.quote output_name) "" (*(Clflags.std_include_flag "-I")*) - (quote_prefixed "-L" (Load_path.get_paths ())) + (quote_prefixed ~response_files:true "-L" (Load_path.get_paths ())) (String.concat " " (List.rev !Clflags.all_ccopts)) - (quote_files files) + (quote_files ~response_files:true files) extra in command cmd diff --git a/utils/ccomp.mli b/utils/ccomp.mli index 46f58a982e..84f5041871 100644 --- a/utils/ccomp.mli +++ b/utils/ccomp.mli @@ -25,7 +25,7 @@ val run_command: string -> unit val compile_file: ?output:string -> ?opt:string -> ?stable_name:string -> string -> int val create_archive: string -> string list -> int -val quote_files: string list -> string +val quote_files: response_files:bool -> string list -> string val quote_optfile: string option -> string (*val make_link_options: string list -> string*) diff --git a/utils/config.fixed.ml b/utils/config.fixed.ml index 1299aa682f..e0ca8d4aca 100644 --- a/utils/config.fixed.ml +++ b/utils/config.fixed.ml @@ -68,3 +68,4 @@ let host = "zinc-boot-ocaml" let target = host let systhread_supported = false let flexdll_dirs = [] +let ar_supports_response_files = true diff --git a/utils/config.generated.ml.in b/utils/config.generated.ml.in index c6c9114465..6aaf2a1f06 100644 --- a/utils/config.generated.ml.in +++ b/utils/config.generated.ml.in @@ -108,3 +108,5 @@ let target = {@QS@|@target@|@QS@} let systhread_supported = @systhread_support@ let flexdll_dirs = [@flexdll_dir@] + +let ar_supports_response_files = @ar_supports_response_files@ diff --git a/utils/config.mli b/utils/config.mli index 07e99457b8..800d23c477 100644 --- a/utils/config.mli +++ b/utils/config.mli @@ -248,6 +248,8 @@ val native_dynlink: bool val afl_instrument : bool (** Whether afl-fuzz instrumentation is generated by default *) +val ar_supports_response_files: bool +(** Whether ar supports @FILE arguments. *) (** Access to configuration values *) val print_config : out_channel -> unit |