Skip to content

Commit b5cf5fb

Browse files
committed
Added ability for toolsets to specify tool output extensions
1 parent 0e4040d commit b5cf5fb

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

modules/gmake/gmake_cpp.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,33 @@
5858
function cpp.initialize()
5959
rule 'cpp'
6060
fileExtension { ".cc", ".cpp", ".cxx", ".mm" }
61-
buildoutputs { "$(OBJDIR)/%{file.objname}.o" }
61+
buildoutputs { "$(OBJDIR)/%{file.objname}%{premake.modules.gmake.cpp.gettooloutputext('cxx', cfg)}" }
6262
buildmessage '$(notdir $<)'
6363
buildcommands {'$(CXX) %{premake.modules.gmake.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}
6464

6565
rule 'cc'
6666
fileExtension {".c", ".s", ".m"}
67-
buildoutputs { "$(OBJDIR)/%{file.objname}.o" }
67+
buildoutputs { "$(OBJDIR)/%{file.objname}%{premake.modules.gmake.cpp.gettooloutputext('cc', cfg)}" }
6868
buildmessage '$(notdir $<)'
6969
buildcommands {'$(CC) %{premake.modules.gmake.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}
7070

7171
rule 'resource'
7272
fileExtension ".rc"
73-
buildoutputs { "$(OBJDIR)/%{file.objname}.res" }
73+
buildoutputs { "$(OBJDIR)/%{file.objname}%{premake.modules.gmake.cpp.gettooloutputext('rc', cfg)}" }
7474
buildmessage '$(notdir $<)'
7575
buildcommands {'$(RESCOMP) $< -O coff -o "$@" $(ALL_RESFLAGS)'}
7676

7777
global(nil)
7878
end
7979

80+
function cpp.gettooloutputext(tool, cfg)
81+
local toolset = gmake.getToolSet(cfg)
82+
if toolset.gettooloutputext ~= nil then
83+
return toolset.gettooloutputext(tool)
84+
end
85+
86+
return iif(tool == "rc", ".res", ".o")
87+
end
8088

8189
function cpp.createRuleTable(prj)
8290
local rules = {}

modules/gmake/tests/test_gmake_file_rules.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,46 @@
8181
end
8282

8383

84+
--
85+
-- Object filenames use correct extension based on toolset
86+
--
87+
88+
function suite.objectNameExtensions_onDefault()
89+
files { "src/hello.cpp", "src/test.c" }
90+
prepare()
91+
test.capture [[
92+
# File Rules
93+
# #############################################
94+
95+
$(OBJDIR)/hello.o: src/hello.cpp
96+
@echo "$(notdir $<)"
97+
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
98+
$(OBJDIR)/test.o: src/test.c
99+
@echo "$(notdir $<)"
100+
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
101+
102+
]]
103+
end
104+
105+
function suite.objectNameExtensions_onMSC()
106+
toolset "msc"
107+
files { "src/hello.cpp", "src/test.c" }
108+
prepare()
109+
test.capture [[
110+
# File Rules
111+
# #############################################
112+
113+
$(OBJDIR)/hello.obj: src/hello.cpp
114+
@echo "$(notdir $<)"
115+
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
116+
$(OBJDIR)/test.obj: src/test.c
117+
@echo "$(notdir $<)"
118+
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
119+
120+
]]
121+
end
122+
123+
84124
--
85125
-- Two files with the same base name should have different object files.
86126
--

src/tools/clang.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,7 @@
364364
end
365365
return value
366366
end
367+
368+
function clang.gettooloutputext(tool)
369+
return gcc.gettooloutputext(tool)
370+
end

src/tools/gcc.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,3 +724,7 @@
724724
end
725725
return (cfg.gccprefix or "") .. gcc.tools[tool] .. version
726726
end
727+
728+
function gcc.gettooloutputext(tool)
729+
return iif(tool == "rc", ".res", ".o")
730+
end

src/tools/msc.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@
494494
return msc.tools[tool]
495495
end
496496

497+
function msc.gettooloutputext(tool)
498+
return iif(tool == "rc", ".res", ".obj")
499+
end
497500

498501

499502
function msc.getwarnings(cfg)

0 commit comments

Comments
 (0)