Merge pull request #959 from Blizzard/multiple-gmake2-fixes

Multiple gmake2 fixes
This commit is contained in:
Manu Evans 2017-11-30 15:58:22 -08:00 committed by GitHub
commit 02f5a75fc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 115 additions and 25 deletions

View File

@ -15,6 +15,7 @@
trigger = "gmake2",
shortname = "Alternative GNU Make",
description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin",
toolset = "gcc",
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile" },

View File

@ -231,17 +231,31 @@
p.outln('')
end
local first = true
for cfg in project.eachconfig(prj) do
local settings = table.difference(root[cfg], root.settings)
if #settings > 0 then
_x('ifeq ($(config),%s)', cfg.shortname)
if first then
_x('ifeq ($(config),%s)', cfg.shortname)
first = false
else
_x('else ifeq ($(config),%s)', cfg.shortname)
end
for k, v in ipairs(settings) do
p.outln(v)
end
p.outln('endif')
p.outln('')
_p('')
end
end
if not first then
p.outln('else')
p.outln(' $(error "invalid configuration $(config)")')
p.outln('endif')
p.outln('')
end
end

View File

@ -57,20 +57,20 @@
function cpp.initialize()
rule 'cpp'
fileExtension {".cc", ".cpp", ".cxx", ".mm"}
buildoutputs {'$(OBJDIR)/%{file.objname}.o'}
fileExtension { ".cc", ".cpp", ".cxx", ".mm" }
buildoutputs { "$(OBJDIR)/%{premake.modules.gmake2.cpp.makeUnique(cfg, file.objname)}.o" }
buildmessage '$(notdir $<)'
buildcommands {'$(CXX) $(%{premake.modules.gmake2.cpp.fileFlags(cfg, file)}) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}
rule 'cc'
fileExtension {".c", ".s", ".m"}
buildoutputs {'$(OBJDIR)/%{file.objname}.o'}
buildoutputs { "$(OBJDIR)/%{premake.modules.gmake2.cpp.makeUnique(cfg, file.objname)}.o" }
buildmessage '$(notdir $<)'
buildcommands {'$(CC) $(%{premake.modules.gmake2.cpp.fileFlags(cfg, file)}) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}
rule 'resource'
fileExtension ".rc"
buildoutputs {'$(OBJDIR)/%{file.objname}.res'}
buildoutputs { "$(OBJDIR)/%{premake.modules.gmake2.cpp.makeUnique(cfg, file.objname)}.res" }
buildmessage '$(notdir $<)'
buildcommands {'$(RESCOMP) $< -O coff -o "$@" $(ALL_RESFLAGS)'}
@ -124,6 +124,7 @@
cfg._gmake = cfg._gmake or {}
cfg._gmake.filesets = {}
cfg._gmake.fileRules = {}
cfg._gmake.bases = {}
local files = table.shallowcopy(prj._.files)
table.foreachi(files, function(node)
@ -729,6 +730,18 @@
-- Output the file compile targets.
--
function cpp.makeUnique(cfg, f)
local cache = cfg._gmake.bases
local seq = cache[f]
if seq == nil then
cache[f] = 1
return f
else
cache[f] = seq + 1
return f .. tostring(seq)
end
end
cpp.elements.fileRules = function(cfg)
local funcs = {}
for _, fileRule in ipairs(cfg._gmake.fileRules) do

View File

@ -47,6 +47,7 @@
end
function makefile.configs(prj)
local first = true
for cfg in project.eachconfig(prj) do
-- identify the toolset used by this configurations (would be nicer if
-- this were computed and stored with the configuration up front)
@ -56,8 +57,20 @@
error("Invalid toolset '" .. cfg.toolset .. "'")
end
_x('ifeq ($(config),%s)', cfg.shortname)
if first then
_x('ifeq ($(config),%s)', cfg.shortname)
first = false
else
_x('else ifeq ($(config),%s)', cfg.shortname)
end
p.callarray(make, makefile.elements.configuration, cfg, toolset)
_p('')
end
if not first then
_p('else')
_p(' $(error "invalid configuration $(config)")')
_p('endif')
_p('')
end

View File

@ -37,17 +37,31 @@
--
function gmake2.configmap(wks)
local first = true
for cfg in p.workspace.eachconfig(wks) do
_p('ifeq ($(config),%s)', cfg.shortname)
if first then
_p('ifeq ($(config),%s)', cfg.shortname)
first = false
else
_p('else ifeq ($(config),%s)', cfg.shortname)
end
for prj in p.workspace.eachproject(wks) do
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
if prjcfg then
_p(' %s_config = %s', gmake2.tovar(prj.name), prjcfg.shortname)
end
end
_p('endif')
_p('')
end
if not first then
_p('else')
_p(' $(error "invalid configuration $(config)")')
_p('endif')
_p('')
end
_p('')
end

View File

@ -121,13 +121,15 @@ obj/Debug/hello.obj: hello.x
@echo Compiling hello.x
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
endif
ifeq ($(config),release)
else ifeq ($(config),release)
obj/Release/hello.obj: hello.x
@echo Compiling hello.x
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
else
$(error "invalid configuration $(config)")
endif
]]
end
@ -152,13 +154,15 @@ obj/Debug/hello.obj: hello.x hello.x.inc hello.x.inc2
@echo Compiling hello.x
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
endif
ifeq ($(config),release)
else ifeq ($(config),release)
obj/Release/hello.obj: hello.x hello.x.inc hello.x.inc2
@echo Compiling hello.x
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
else
$(error "invalid configuration $(config)")
endif
]]
end

View File

@ -86,10 +86,12 @@ OBJECTS :=
ifeq ($(config),debug)
OBJECTS += $(OBJDIR)/hello_debug.o
endif
ifeq ($(config),release)
else ifeq ($(config),release)
OBJECTS += $(OBJDIR)/hello_release.o
else
$(error "invalid configuration $(config)")
endif
]]
@ -138,10 +140,12 @@ CUSTOM :=
ifeq ($(config),debug)
CUSTOM += obj/Debug/hello.luac
endif
ifeq ($(config),release)
else ifeq ($(config),release)
CUSTOM += obj/Release/hello.luac
else
$(error "invalid configuration $(config)")
endif
]]
end
@ -170,10 +174,12 @@ OBJECTS :=
ifeq ($(config),debug)
OBJECTS += obj/Debug/hello.obj
endif
ifeq ($(config),release)
else ifeq ($(config),release)
OBJECTS += obj/Release/hello.obj
else
$(error "invalid configuration $(config)")
endif
]]
end
@ -203,10 +209,12 @@ OBJECTS :=
ifeq ($(config),debug)
OBJECTS += obj/Debug/hello.obj
endif
ifeq ($(config),release)
else ifeq ($(config),release)
OBJECTS += obj/Release/hello.obj
else
$(error "invalid configuration $(config)")
endif
]]
end
@ -236,10 +244,12 @@ CUSTOM :=
ifeq ($(config),debug)
CUSTOM += obj/Debug/hello.obj
endif
ifeq ($(config),release)
else ifeq ($(config),release)
CUSTOM += obj/Release/hello.obj
else
$(error "invalid configuration $(config)")
endif
]]
end
@ -262,6 +272,9 @@ OBJECTS :=
ifeq ($(config),release)
OBJECTS += $(OBJDIR)/hello.o
else
$(error "invalid configuration $(config)")
endif
]]
@ -280,6 +293,9 @@ OBJECTS :=
ifeq ($(config),release)
OBJECTS += $(OBJDIR)/hello.o
else
$(error "invalid configuration $(config)")
endif
]]

View File

@ -101,6 +101,21 @@
--
-- Remove extension from path.
--
function path.removeextension(p)
local i = p:findlast(".", true)
if (i) then
if i > 1 then i = i - 1 end
return p:sub(1, i)
else
return ""
end
end
--
-- Retrieve the filename portion of a path.
--