diff --git a/tools/ar_tempfile.py b/tools/ar_tempfile.py index 8dfbe0f26..601530cfb 100644 --- a/tools/ar_tempfile.py +++ b/tools/ar_tempfile.py @@ -18,12 +18,9 @@ def tempfile_arg_esc_func(arg): # writing the command to a response file. Refer to the engine equivalent in # https://github.com/godotengine/godot/blob/master/platform/windows/detect.py def configure(env): - if "ARCOM_ORIG" in env: - return # Already configured, don't wrap ARCOM in TEMPFILE twice. - - env["ARCOM_ORIG"] = env["ARCOM"] # This is SCons lazy evaluation syntax, only switching to a file when the command is actually too long. - env["ARCOM"] = "${TEMPFILE('$ARCOM_ORIG', '$ARCOMSTR')}" + # The flags must stay in the command (not in the file) to work with GCC 13 or older. + env["ARCOM"] = "$AR $ARFLAGS ${TEMPFILE('$TARGET $SOURCES', '$ARCOMSTR')}" env["TEMPFILESUFFIX"] = ".rsp" if os.name == "nt": env["TEMPFILEARGESCFUNC"] = tempfile_arg_esc_func diff --git a/tools/common_compiler_flags.py b/tools/common_compiler_flags.py index 9a0a60a6a..a7c8613b2 100644 --- a/tools/common_compiler_flags.py +++ b/tools/common_compiler_flags.py @@ -25,6 +25,18 @@ def exists(env): return True +def configure_gcc_ar(env, prefix=""): + if env.Detect(prefix + "gcc-ar"): + env["AR"] = prefix + "gcc-ar" + env["RANLIB"] = prefix + "gcc-ranlib" + return + + if env["lto"] != "none": + print("WARNING: Couldn't find `{0}gcc-ar`; falling back to `{0}ar`. LTO builds might fail.".format(prefix)) + env["AR"] = prefix + "ar" + env["RANLIB"] = prefix + "ranlib" + + def generate(env): assert env["lto"] in ["thin", "full", "none"], "Unrecognized lto: {}".format(env["lto"]) if env["lto"] != "none": diff --git a/tools/linux.py b/tools/linux.py index 56d7bb872..4e78ee6cd 100644 --- a/tools/linux.py +++ b/tools/linux.py @@ -62,6 +62,9 @@ def generate(env): if env["lto"] == "auto": env["lto"] = "full" + if not env["use_llvm"]: + common_compiler_flags.configure_gcc_ar(env) + # Configure ARCOM response file in case the command line call to AR is too long. ar_tempfile.configure(env) diff --git a/tools/windows.py b/tools/windows.py index 1eaeb88bb..27c3aa61c 100644 --- a/tools/windows.py +++ b/tools/windows.py @@ -89,6 +89,8 @@ def exists(env): def generate(env): + gcc_tool_prefix = None + if not env["use_mingw"] and msvc.exists(env): if env["arch"] == "x86_64": env["TARGET_ARCH"] = "amd64" @@ -133,6 +135,7 @@ def generate(env): elif (sys.platform == "win32" or sys.platform == "msys") and not env["mingw_prefix"]: env["use_mingw"] = True + gcc_tool_prefix = "" mingw.generate(env) # Don't want lib prefixes env["IMPLIBPREFIX"] = "" @@ -180,11 +183,10 @@ def generate(env): env["RANLIB"] = prefix + "-w64-mingw32-ranlib" env["LINK"] = prefix + "-w64-mingw32-clang" else: - env["CXX"] = prefix + "-w64-mingw32-g++" - env["CC"] = prefix + "-w64-mingw32-gcc" - env["AR"] = prefix + "-w64-mingw32-gcc-ar" - env["RANLIB"] = prefix + "-w64-mingw32-ranlib" - env["LINK"] = prefix + "-w64-mingw32-g++" + gcc_tool_prefix = prefix + "-w64-mingw32-" + env["CXX"] = gcc_tool_prefix + "g++" + env["CC"] = gcc_tool_prefix + "gcc" + env["LINK"] = gcc_tool_prefix + "g++" # Want dll suffix env["SHLIBSUFFIX"] = ".dll" @@ -218,4 +220,7 @@ def generate(env): else: # Release env["lto"] = "full" + if gcc_tool_prefix is not None: + common_compiler_flags.configure_gcc_ar(env, gcc_tool_prefix) + common_compiler_flags.generate(env)