Skip to content

Commit f0f2f8a

Browse files
committed
Added ability for toolsets to specify tool output extensions
1 parent c3bdf5b commit f0f2f8a

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-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/msc.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,14 @@
431431
}
432432
end
433433

434+
--
435+
-- Return tool output extension
436+
--
437+
438+
function msc.gettooloutputext(tool)
439+
return iif(tool == "rc", "res", "obj")
440+
end
441+
434442
--
435443
-- Return the list of libraries to link, decorated with flags as needed.
436444
--

0 commit comments

Comments
 (0)