Gmake elseif (#161)

* gmake2 elseif pattern for configurations.
https://ghosthub.corp.blizzard.net/premake/premake-core/issues/131

* fix error message.

* don't output else if there is no if statements.
This commit is contained in:
Tom van Dijck 2017-10-30 11:56:56 -07:00
parent 0b4659cf1e
commit 431cba5c6a
5 changed files with 82 additions and 21 deletions

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

@ -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
]]