Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/gmake/gmake_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
fileExtension { ".cc", ".cpp", ".cxx", ".mm" }
buildoutputs { "$(OBJDIR)/%{file.objname}.o" }
buildmessage '$(notdir $<)'
buildcommands {'$(CXX) %{premake.modules.gmake.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}
buildcommands {'$(CXX) %{premake.modules.gmake.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -c "$<"'}

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

rule 'resource'
fileExtension ".rc"
Expand Down Expand Up @@ -703,7 +703,7 @@
_p('$(GCH): $(PCH) | prebuild')
_p('\t@echo $(notdir $<)')
local cmd = iif(p.languages.isc(cfg.language), "$(CC) -x c-header $(ALL_CFLAGS)", "$(CXX) -x c++-header $(ALL_CXXFLAGS)")
_p('\t$(SILENT) %s -o "$@" -MF "$(@:%%.gch=%%.d)" -c "$<"', cmd)
_p('\t$(SILENT) %s -o "$@" -c "$<"', cmd)
_p('$(PCH_PLACEHOLDER): $(GCH) | $(OBJDIR)')
_p('ifeq (posix,$(SHELLTYPE))')
_p('\t$(SILENT) touch "$@"')
Expand Down
18 changes: 9 additions & 9 deletions modules/gmake/tests/test_gmake_file_rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@

$(OBJDIR)/hello.o: src/greetings/hello.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
$(OBJDIR)/hello1.o: src/hello.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"

]]
end
Expand All @@ -116,10 +116,10 @@ $(OBJDIR)/hello1.o: src/hello.cpp

$(OBJDIR)/hello.o: src/hello.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
$(OBJDIR)/test.o: src/test.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"

]]
end
Expand All @@ -139,10 +139,10 @@ $(OBJDIR)/test.o: src/test.cpp

$(OBJDIR)/hello.o: src/hello.c
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
$(OBJDIR)/test.o: src/test.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
]]
end

Expand All @@ -161,17 +161,17 @@ $(OBJDIR)/test.o: src/test.c

$(OBJDIR)/test.o: src/test.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"

ifeq ($(config),debug)
$(OBJDIR)/hello.o: src/hello.c
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"

else ifeq ($(config),release)
$(OBJDIR)/hello.o: src/hello.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"

endif
]]
Expand Down
20 changes: 20 additions & 0 deletions modules/gmake/tests/test_gmake_flags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ INCLUDES += -Isrc/include -I../include
]]
end

--
-- Dependency flags in ALL_CPPFLAGS shouldn't appear for MSC
--

function suite.dependencyFlags_onDefault()
local cfg = test.getconfig(prj, "Debug")
local res = cpp.cppFlags(cfg, p.tools.gcc)
test.capture [[
ALL_CPPFLAGS += $(CPPFLAGS) -MD -MP -MF "$(@:%.o=%.d)" $(DEFINES) $(INCLUDES)
]]
end

function suite.dependencyFlags_onMSC()
local cfg = test.getconfig(prj, "Debug")
cpp.cppFlags(cfg, p.tools.msc)
test.capture [[
ALL_CPPFLAGS += $(CPPFLAGS) $(DEFINES) $(INCLUDES)
]]
end

--
-- symbols "on" should produce -g
--
Expand Down
16 changes: 8 additions & 8 deletions modules/gmake/tests/test_gmake_pch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@

$(OBJDIR)/a.o: a.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
$(OBJDIR)/b.o: b.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
]]
end

Expand Down Expand Up @@ -134,7 +134,7 @@ ifneq (,$(PCH))
$(OBJECTS): $(GCH) | $(PCH_PLACEHOLDER)
$(GCH): $(PCH) | prebuild
@echo $(notdir $<)
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -c "$<"
$(PCH_PLACEHOLDER): $(GCH) | $(OBJDIR)
ifeq (posix,$(SHELLTYPE))
$(SILENT) touch "$@"
Expand All @@ -161,7 +161,7 @@ ifneq (,$(PCH))
$(OBJECTS): $(GCH) | $(PCH_PLACEHOLDER)
$(GCH): $(PCH) | prebuild
@echo $(notdir $<)
$(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
$(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -o "$@" -c "$<"
$(PCH_PLACEHOLDER): $(GCH) | $(OBJDIR)
ifeq (posix,$(SHELLTYPE))
$(SILENT) touch "$@"
Expand Down Expand Up @@ -191,10 +191,10 @@ endif

$(OBJDIR)/a.o: a.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
$(OBJDIR)/b.o: b.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
]]
end

Expand All @@ -213,9 +213,9 @@ $(OBJDIR)/b.o: b.cpp

$(OBJDIR)/a.o: a.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
$(OBJDIR)/b.o: b.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
]]
end
4 changes: 2 additions & 2 deletions modules/gmakelegacy/gmakelegacy_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
local iscfile = node and path.iscfile(node.abspath) or false
flags = iif(prj.language == "C" or iscfile, '$(CC) $(ALL_CFLAGS)', '$(CXX) $(ALL_CXXFLAGS)')
end
_p('\t$(SILENT) %s $(FORCE_INCLUDE) -o "$@" -MF "$(@:%%.%s=%%.d)" -c "$<"', flags, objext)
_p('\t$(SILENT) %s $(FORCE_INCLUDE) -o "$@" -c "$<"', flags, objext)
end


Expand Down Expand Up @@ -584,7 +584,7 @@ end
_p('\t@echo $(notdir $<)')

local cmd = iif(prj.language == "C", "$(CC) -x c-header $(ALL_CFLAGS)", "$(CXX) -x c++-header $(ALL_CXXFLAGS)")
_p('\t$(SILENT) %s -o "$@" -MF "$(@:%%.gch=%%.d)" -c "$<"', cmd)
_p('\t$(SILENT) %s -o "$@" -c "$<"', cmd)

_p('else')
_p('$(OBJECTS): | $(OBJDIR)')
Expand Down
20 changes: 10 additions & 10 deletions modules/gmakelegacy/tests/cpp/test_file_rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
test.capture [[
$(OBJDIR)/hello.o: src/greetings/hello.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
$(OBJDIR)/hello1.o: src/hello.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"

]]
end
Expand All @@ -56,10 +56,10 @@ $(OBJDIR)/hello1.o: src/hello.cpp
test.capture [[
$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
$(OBJDIR)/test.o: src/test.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"

]]
end
Expand All @@ -77,14 +77,14 @@ $(OBJDIR)/test.o: src/test.cpp
$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
ifeq ($(config),debug)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
endif
ifeq ($(config),release)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
endif
$(OBJDIR)/test.o: src/test.c
@echo $(notdir $<)
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
]]
end

Expand All @@ -101,14 +101,14 @@ $(OBJDIR)/test.o: src/test.c
$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
ifeq ($(config),debug)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
endif
ifeq ($(config),release)
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
endif
$(OBJDIR)/test.o: src/test.c
@echo $(notdir $<)
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
]]
end

Expand Down
4 changes: 2 additions & 2 deletions modules/gmakelegacy/tests/cpp/test_make_pch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ ifneq (,$(PCH))
$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)
$(GCH): $(PCH) | $(OBJDIR)
@echo $(notdir $<)
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -c "$<"
else
$(OBJECTS): | $(OBJDIR)
endif
Expand All @@ -133,7 +133,7 @@ ifneq (,$(PCH))
$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)
$(GCH): $(PCH) | $(OBJDIR)
@echo $(notdir $<)
$(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
$(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -o "$@" -c "$<"
else
$(OBJECTS): | $(OBJDIR)
endif
Expand Down
2 changes: 1 addition & 1 deletion modules/gmakelegacy/tests/cpp/test_wiidev.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
function suite.writesCorrectCppFlags()
make.cppFlags(cfg, p.tools.gcc)
test.capture [[
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -I$(LIBOGC_INC) $(MACHDEP) $(DEFINES) $(INCLUDES)
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -I$(LIBOGC_INC) $(MACHDEP) -MF "$(@:%.o=%.d)" $(DEFINES) $(INCLUDES)
]]
end

Expand Down
4 changes: 4 additions & 0 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

function gcc.getcppflags(cfg)
local flags = config.mapFlags(cfg, gcc.cppflags)

-- Request that dependencies be written out
table.insert(flags, '-MF "$(@:%.o=%.d)"')
Copy link
Contributor

@Jarod42 Jarod42 Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't $(@:%.o=%.d) Makefile specific? :-(

In premake-ninja, we hard code the rule with -MF $out.d

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, overlooked that. Thanks for pointing that out, going to close this, need to come up with a different approach.


return flags
end

Expand Down
Loading