From b5cf5fb0c4aba45fdf2b698855afba14ca439521 Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Wed, 17 Sep 2025 17:56:25 +1000 Subject: [PATCH] Added ability for toolsets to specify tool output extensions --- modules/gmake/gmake_cpp.lua | 14 +++++-- modules/gmake/tests/test_gmake_file_rules.lua | 40 +++++++++++++++++++ src/tools/clang.lua | 4 ++ src/tools/gcc.lua | 4 ++ src/tools/msc.lua | 3 ++ 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/modules/gmake/gmake_cpp.lua b/modules/gmake/gmake_cpp.lua index 0297f3ff2e..7c8624ed33 100644 --- a/modules/gmake/gmake_cpp.lua +++ b/modules/gmake/gmake_cpp.lua @@ -58,25 +58,33 @@ function cpp.initialize() rule 'cpp' fileExtension { ".cc", ".cpp", ".cxx", ".mm" } - buildoutputs { "$(OBJDIR)/%{file.objname}.o" } + buildoutputs { "$(OBJDIR)/%{file.objname}%{premake.modules.gmake.cpp.gettooloutputext('cxx', cfg)}" } buildmessage '$(notdir $<)' buildcommands {'$(CXX) %{premake.modules.gmake.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'} rule 'cc' fileExtension {".c", ".s", ".m"} - buildoutputs { "$(OBJDIR)/%{file.objname}.o" } + buildoutputs { "$(OBJDIR)/%{file.objname}%{premake.modules.gmake.cpp.gettooloutputext('cc', cfg)}" } buildmessage '$(notdir $<)' buildcommands {'$(CC) %{premake.modules.gmake.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'} rule 'resource' fileExtension ".rc" - buildoutputs { "$(OBJDIR)/%{file.objname}.res" } + buildoutputs { "$(OBJDIR)/%{file.objname}%{premake.modules.gmake.cpp.gettooloutputext('rc', cfg)}" } buildmessage '$(notdir $<)' buildcommands {'$(RESCOMP) $< -O coff -o "$@" $(ALL_RESFLAGS)'} global(nil) end + function cpp.gettooloutputext(tool, cfg) + local toolset = gmake.getToolSet(cfg) + if toolset.gettooloutputext ~= nil then + return toolset.gettooloutputext(tool) + end + + return iif(tool == "rc", ".res", ".o") + end function cpp.createRuleTable(prj) local rules = {} diff --git a/modules/gmake/tests/test_gmake_file_rules.lua b/modules/gmake/tests/test_gmake_file_rules.lua index d8f7bc9760..13f608746d 100644 --- a/modules/gmake/tests/test_gmake_file_rules.lua +++ b/modules/gmake/tests/test_gmake_file_rules.lua @@ -81,6 +81,46 @@ end +-- +-- Object filenames use correct extension based on toolset +-- + + function suite.objectNameExtensions_onDefault() + files { "src/hello.cpp", "src/test.c" } + prepare() + test.capture [[ +# File Rules +# ############################################# + +$(OBJDIR)/hello.o: src/hello.cpp + @echo "$(notdir $<)" + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" +$(OBJDIR)/test.o: src/test.c + @echo "$(notdir $<)" + $(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" + +]] + end + + function suite.objectNameExtensions_onMSC() + toolset "msc" + files { "src/hello.cpp", "src/test.c" } + prepare() + test.capture [[ +# File Rules +# ############################################# + +$(OBJDIR)/hello.obj: src/hello.cpp + @echo "$(notdir $<)" + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" +$(OBJDIR)/test.obj: src/test.c + @echo "$(notdir $<)" + $(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" + +]] + end + + -- -- Two files with the same base name should have different object files. -- diff --git a/src/tools/clang.lua b/src/tools/clang.lua index 8839b8259c..4971ecd507 100644 --- a/src/tools/clang.lua +++ b/src/tools/clang.lua @@ -364,3 +364,7 @@ end return value end + + function clang.gettooloutputext(tool) + return gcc.gettooloutputext(tool) + end diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 87ddadf606..fb7c908573 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -724,3 +724,7 @@ end return (cfg.gccprefix or "") .. gcc.tools[tool] .. version end + + function gcc.gettooloutputext(tool) + return iif(tool == "rc", ".res", ".o") + end diff --git a/src/tools/msc.lua b/src/tools/msc.lua index b916fc4c3d..bd648d0f89 100644 --- a/src/tools/msc.lua +++ b/src/tools/msc.lua @@ -494,6 +494,9 @@ return msc.tools[tool] end + function msc.gettooloutputext(tool) + return iif(tool == "rc", ".res", ".obj") + end function msc.getwarnings(cfg)