Refactored handling of configuration names

This commit is contained in:
starkos 2009-04-24 14:34:54 +00:00
parent 457744c27e
commit edc74bc237
12 changed files with 68 additions and 49 deletions

View File

@ -25,12 +25,7 @@
_p('\t\t<Build>') _p('\t\t<Build>')
for _, platform in ipairs(platforms) do for _, platform in ipairs(platforms) do
for cfg in premake.eachconfig(prj, platform) do for cfg in premake.eachconfig(prj, platform) do
_p('\t\t\t<Target title="%s">', premake.esc(cfg.longname))
local name = cfg.name
if platform ~= "Native" then
name = name .. "|" .. platform
end
_p('\t\t\t<Target title="%s">', premake.esc(name))
_p('\t\t\t\t<Option output="%s" prefix_auto="0" extension_auto="0" />', premake.esc(cfg.buildtarget.fullpath)) _p('\t\t\t\t<Option output="%s" prefix_auto="0" extension_auto="0" />', premake.esc(cfg.buildtarget.fullpath))
_p('\t\t\t\t<Option object_output="%s" />', premake.esc(cfg.objectsdir)) _p('\t\t\t\t<Option object_output="%s" />', premake.esc(cfg.objectsdir))

View File

@ -22,11 +22,8 @@
local platforms = premake.filterplatforms(prj.solution, premake.gcc.platforms, "Native") local platforms = premake.filterplatforms(prj.solution, premake.gcc.platforms, "Native")
for _, platform in ipairs(platforms) do for _, platform in ipairs(platforms) do
for cfg in premake.eachconfig(prj) do for cfg in premake.eachconfig(prj, platform) do
local name = premake.esc(cfg.name) local name = premake.esc(cfg.longname)
if platform ~= "Native" then
name = name .. "|" .. platform
end
local compiler = iif(cfg.language == "C", "gcc", "g++") local compiler = iif(cfg.language == "C", "gcc", "g++")
_p(' <Configuration Name="%s" CompilerType="gnu %s" DebuggerType="GNU gdb debugger" Type="%s">', name, compiler, types[cfg.kind]) _p(' <Configuration Name="%s" CompilerType="gnu %s" DebuggerType="GNU gdb debugger" Type="%s">', name, compiler, types[cfg.kind])
@ -110,12 +107,8 @@
_p(' </Settings>') _p(' </Settings>')
for _, platform in ipairs(platforms) do for _, platform in ipairs(platforms) do
for _,cfgname in ipairs(prj.configurations) do for cfg in premake.eachconfig(prj, platform) do
local name = premake.esc(cfgname) _p(' <Dependencies name="%s">', cfg.longname)
if platform ~= "Native" then
name = name .. "|" .. platform
end
_p(' <Dependencies name="%s">', name)
for _,dep in ipairs(premake.getdependencies(prj)) do for _,dep in ipairs(premake.getdependencies(prj)) do
_p(' <Project Name="%s"/>', dep.name) _p(' <Project Name="%s"/>', dep.name)
end end

View File

@ -21,16 +21,11 @@
_p(' <BuildMatrix>') _p(' <BuildMatrix>')
for _, platform in ipairs(platforms) do for _, platform in ipairs(platforms) do
for _, cfgname in ipairs(sln.configurations) do for _, cfgname in ipairs(sln.configurations) do
local name = cfgname local name = premake.getconfigname(cfgname, platform)
if platform ~= "Native" then
name = name .. "|" .. platform
end
_p(' <WorkspaceConfiguration Name="%s" Selected="yes">', name) _p(' <WorkspaceConfiguration Name="%s" Selected="yes">', name)
for _,prj in ipairs(sln.projects) do for _,prj in ipairs(sln.projects) do
_p(' <Project Name="%s" ConfigName="%s"/>', prj.name, name) _p(' <Project Name="%s" ConfigName="%s"/>', prj.name, name)
end end
_p(' </WorkspaceConfiguration>') _p(' </WorkspaceConfiguration>')
end end
end end

View File

@ -16,7 +16,7 @@
-- set up the environment -- set up the environment
_p('ifndef config') _p('ifndef config')
_p(' config=%s%s', _MAKE.esc(prj.configurations[1]:lower()), cc.platforms[platforms[1]].suffix) _p(' config=%s', _MAKE.esc(premake.getconfigname(prj.configurations[1], platforms[1], true)))
_p('endif') _p('endif')
_p('') _p('')
@ -28,7 +28,7 @@
-- list the configurations -- list the configurations
for _, platform in ipairs(platforms) do for _, platform in ipairs(platforms) do
for cfg in premake.eachconfig(prj, platform) do for cfg in premake.eachconfig(prj, platform) do
premake.gmake_cpp_config(cfg) premake.gmake_cpp_config(cfg, cc)
end end
end end
@ -151,11 +151,9 @@
-- Write a block of configuration settings. -- Write a block of configuration settings.
-- --
function premake.gmake_cpp_config(cfg) function premake.gmake_cpp_config(cfg, cc)
local cc = premake[_OPTIONS.cc]
local platform = cc.platforms[cfg.platform or "Native"].suffix
_p('ifeq ($(config),%s%s)', _MAKE.esc(cfg.name:lower()), platform) _p('ifeq ($(config),%s)', _MAKE.esc(cfg.shortname))
_p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory)) _p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory))
_p(' TARGET = $(TARGETDIR)/%s', _MAKE.esc(cfg.buildtarget.name)) _p(' TARGET = $(TARGETDIR)/%s', _MAKE.esc(cfg.buildtarget.name))
_p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir)) _p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir))

View File

@ -14,18 +14,18 @@
-- write a header showing the build options -- write a header showing the build options
local cfgpairs = { } local cfgpairs = { }
for _, platform in ipairs(platforms) do for _, platform in ipairs(platforms) do
for _, cfg in ipairs(sln.configurations) do for _, cfgname in ipairs(sln.configurations) do
table.insert(cfgpairs, cfg .. cc.platforms[platform].suffix) table.insert(cfgpairs, premake.getconfigname(cfgname, platform, true))
end end
end end
_p('# %s solution makefile autogenerated by Premake', premake.actions[_ACTION].shortname) _p('# %s solution makefile autogenerated by Premake', premake.actions[_ACTION].shortname)
_p('# Usage: make [ config=config_name ]') _p('# Usage: make [ config=config_name ]')
_p('# Where {config_name} is one of: %s.', table.implode(cfgpairs, '"', '"', ', '):lower()) _p('# Where {config_name} is one of: %s.', table.implode(cfgpairs, '"', '"', ', '))
_p('') _p('')
-- set a default configuration -- set a default configuration
_p('ifndef config') _p('ifndef config')
_p(' config=%s%s', _MAKE.esc(sln.configurations[1]:lower()), cc.platforms[platforms[1]].suffix) _p(' config=%s', _MAKE.esc(premake.getconfigname(sln.configurations[1], platforms[1], true)))
_p('endif') _p('endif')
_p('export config') _p('export config')
_p('') _p('')
@ -45,7 +45,7 @@
-- these dependencies change, the project needs to be rebuilt -- these dependencies change, the project needs to be rebuilt
for _, platform in ipairs(platforms) do for _, platform in ipairs(platforms) do
for cfg in premake.eachconfig(prj, platform) do for cfg in premake.eachconfig(prj, platform) do
_p('ifeq ($(config),%s%s)', _MAKE.esc(cfg.name:lower()), cc.platforms[platform].suffix) _p('ifeq ($(config),%s)', _MAKE.esc(cfg.shortname))
_p(' DEPENDENCIES := %s', table.concat(_MAKE.esc(table.extract(premake.getdependencies(cfg), "name")), " ")) _p(' DEPENDENCIES := %s', table.concat(_MAKE.esc(table.extract(premake.getdependencies(cfg), "name")), " "))
_p('endif') _p('endif')
end end

View File

@ -206,6 +206,15 @@
"Universal32", "Universal32",
"Universal64", "Universal64",
"Xbox360" "Xbox360"
},
shortnames = {
Native = "",
x32 = "32",
x64 = "64",
Universal = "univ",
Universal32 = "univ32",
Universal64 = "univ64",
Xbox360 = "360",
} }
}, },

View File

@ -197,10 +197,12 @@
terms.platform = pltname:lower() terms.platform = pltname:lower()
terms.config = (cfgname or ""):lower() terms.config = (cfgname or ""):lower()
local cfg = buildconfig(prj, terms) local cfg = buildconfig(prj, terms)
cfg.name = cfgname cfg.name = cfgname
cfg.platform = pltname cfg.platform = pltname
cfg.project = prj cfg.shortname = premake.getconfigname(cfgname, pltname, true)
cfg.longname = premake.getconfigname(cfgname, pltname)
cfg.project = prj
-- set the project location, if not already set -- set the project location, if not already set
cfg.location = cfg.location or cfg.basedir cfg.location = cfg.location or cfg.basedir

View File

@ -187,6 +187,28 @@
--
-- Build a name from a build configuration/platform pair. The short name
-- is good for makefiles or anywhere a user will have to type it in. The
-- long name is more readable.
--
function premake.getconfigname(cfgname, platform, useshortname)
if cfgname then
local name = cfgname
if platform and platform ~= "Native" then
if useshortname then
name = name .. premake.fields.platforms.shortnames[platform]
else
name = name .. "|" .. platform
end
end
return iif(useshortname, name:lower(), name)
end
end
-- --
-- Returns a list of sibling projects on which the specified -- Returns a list of sibling projects on which the specified
-- configuration depends. This is used to specify project -- configuration depends. This is used to specify project

View File

@ -32,39 +32,33 @@
-- --
-- Support platforms, mapped to build configuration suffix -- Map platforms to flags
-- --
premake.gcc.platforms = premake.gcc.platforms =
{ {
Native = { Native = {
suffix = "",
cppflags = "-MMD", cppflags = "-MMD",
}, },
x32 = { x32 = {
suffix = "32",
cppflags = "-MMD", cppflags = "-MMD",
flags = "-m32", flags = "-m32",
ldflags = "-L/usr/lib32", ldflags = "-L/usr/lib32",
}, },
x64 = { x64 = {
suffix = "64",
cppflags = "-MMD", cppflags = "-MMD",
flags = "-m64", flags = "-m64",
ldflags = "-L/usr/lib64", ldflags = "-L/usr/lib64",
}, },
Universal = { Universal = {
suffix = "univ",
cppflags = "", cppflags = "",
flags = "-arch i386 -arch x86_64 -arch ppc -arch ppc64", flags = "-arch i386 -arch x86_64 -arch ppc -arch ppc64",
}, },
Universal32 = { Universal32 = {
suffix = "univ32",
cppflags = "", cppflags = "",
flags = "-arch i386 -arch ppc", flags = "-arch i386 -arch ppc",
}, },
Universal64 = { Universal64 = {
suffix = "univ64",
cppflags = "", cppflags = "",
flags = "-arch x86_64 -arch ppc64", flags = "-arch x86_64 -arch ppc64",
}, },

View File

@ -36,7 +36,9 @@
premake.ow.platforms = premake.ow.platforms =
{ {
Native = { suffix="", cflags="" }, Native = {
flags = ""
},
} }

View File

@ -63,4 +63,14 @@
test.isequal("Native", r) test.isequal("Native", r)
end end
function T.configs.BuildsShortName()
local r = premake.getconfig(prj, "Debug", "x32").shortname
test.isequal("debug32", r)
end
function T.configs.BuildsLongName()
local r = premake.getconfig(prj, "Debug", "x32").longname
test.isequal("Debug|x32", r)
end

View File

@ -21,7 +21,6 @@
kind "ConsoleApp" kind "ConsoleApp"
_ACTION = "gmake" _ACTION = "gmake"
_OPTIONS.cc = "gcc"
_OPTIONS.os = "linux" _OPTIONS.os = "linux"
end end
@ -35,7 +34,7 @@
function T.gmake_cpp.BasicCfgBlock() function T.gmake_cpp.BasicCfgBlock()
prepare() prepare()
local cfg = premake.getconfig(prj, "Debug") local cfg = premake.getconfig(prj, "Debug")
premake.gmake_cpp_config(cfg) premake.gmake_cpp_config(cfg, premake.gcc)
test.capture [[ test.capture [[
ifeq ($(config),debug) ifeq ($(config),debug)
TARGETDIR = . TARGETDIR = .
@ -65,7 +64,7 @@ endif
function T.gmake_cpp.PlatformSpecificBlock() function T.gmake_cpp.PlatformSpecificBlock()
prepare() prepare()
local cfg = premake.getconfig(prj, "Debug", "x64") local cfg = premake.getconfig(prj, "Debug", "x64")
premake.gmake_cpp_config(cfg) premake.gmake_cpp_config(cfg, premake.gcc)
test.capture [[ test.capture [[
ifeq ($(config),debug64) ifeq ($(config),debug64)
TARGETDIR = . TARGETDIR = .