Added configuration map to solution makefiles

This commit is contained in:
Jason Perkins 2012-07-24 16:54:11 -04:00
parent 00d7bfc0da
commit f2063245f8
6 changed files with 197 additions and 3 deletions

View File

@ -70,7 +70,6 @@
_p('ifndef config')
_p(' config=%s', make.esc(cfg.shortname))
_p('endif')
_p('export config')
_p('')
end
end
@ -177,6 +176,16 @@
end
--
-- Convert an arbitrary string (project name) to a make variable name.
--
function make.tovar(value)
value = value:gsub("[ -]", "_")
value = value:gsub("[()]", "")
return value
end
-----------------------------------------------------------------------------

View File

@ -20,6 +20,7 @@
_p('')
make.defaultconfig(sln)
make.configmap(sln)
make.projects(sln)
_p('.PHONY: all clean help $(PROJECTS)')
@ -33,6 +34,26 @@
end
--
-- Write out the solution's configuration map, which maps solution
-- level configurations to the project level equivalents.
--
function make.configmap(sln)
for cfg in solution.eachconfig(sln) do
_p('ifeq ($(config),%s)', cfg.shortname)
for prj in solution.eachproject_ng(sln) do
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
if prjcfg then
_p(' %s_config = %s', make.tovar(prj.name), prjcfg.shortname)
end
end
_p('endif')
end
_p('')
end
--
-- Write out the rules for the `make clean` action.
--
@ -97,12 +118,17 @@
deps = table.extract(deps, "name")
_p('%s: %s', make.esc(prj.name), table.concat(deps, " "))
_p(1,'@echo "==== Building %s ($(config)) ===="', prj.name)
local cfgvar = make.tovar(prj.name)
_p('ifneq (,$(%s_config))', cfgvar)
_p(1,'@echo "==== Building %s ($(%s_config)) ===="', prj.name, cfgvar)
local slnpath = solution.getlocation(sln)
local prjpath = path.getrelative(slnpath, project.getlocation(prj))
_p(1,'@${MAKE} --no-print-directory -C %s -f %s', make.esc(prjpath), make.esc(make.getmakefilename(prj, true)))
local filename = make.getmakefilename(prj, true)
_p(1,'@${MAKE} --no-print-directory -C %s -f %s config=$(%s_config)', make.esc(prjpath), make.esc(filename), cfgvar)
_p('endif')
_p('')
end
end

View File

@ -0,0 +1,78 @@
--
-- tests/actions/make/test_config_maps.lua
-- Validate handling of configuration maps in makefiles.
-- Copyright (c) 2012 Jason Perkins and the Premake project
--
T.make_config_maps = {}
local suite = T.make_config_maps
local make = premake.make
--
-- Setup/teardown
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
make.configmap(sln)
end
--
-- If no map is present, the configurations should pass through
-- to the projects unchanged.
--
function suite.passesThroughConfigs_onNoMap()
prepare()
test.capture [[
ifeq ($(config),debug)
MyProject_config = debug
endif
ifeq ($(config),release)
MyProject_config = release
endif
]]
end
--
-- If a map is present, the configuration change should be applied.
--
function suite.passesThroughConfigs_onNoMap()
configmap { Debug = "Development" }
prepare()
test.capture [[
ifeq ($(config),debug)
MyProject_config = development
endif
ifeq ($(config),release)
MyProject_config = release
endif
]]
end
--
-- If a configuration is not included in a particular project,
-- no mapping should be created.
--
function suite.passesThroughConfigs_onNoMap()
removeconfigurations { "Debug" }
prepare()
test.capture [[
ifeq ($(config),debug)
endif
ifeq ($(config),release)
MyProject_config = release
endif
]]
end

View File

@ -0,0 +1,43 @@
--
-- tests/actions/make/solution/test_project_rule.lua
-- Validate generation of project rules in solution makefile.
-- Copyright (c) 2012 Jason Perkins and the Premake project
--
T.make_project_rule = {}
local suite = T.make_project_rule
local make = premake.make
local solution = premake.solution
--
-- Setup/teardown
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
sln = solution.bake(sln)
make.projectrules(sln)
end
--
-- Verify a simple project with no dependencies.
--
function suite.projectRule_onNoDependencies()
prepare()
test.capture [[
MyProject:
ifneq (,$(MyProject_config))
@echo "==== Building MyProject ($(MyProject_config)) ===="
@${MAKE} --no-print-directory -C . -f MyProject.make config=$(MyProject_config)
endif
]]
end

View File

@ -0,0 +1,35 @@
--
-- tests/actions/make/test_make_tovar.lua
-- Test translation of strings to make variable names.
-- Copyright (c) 2012 Jason Perkins and the Premake project
--
T.make_tovar = { }
local suite = T.make_tovar
local make = premake.make
--
-- Convert spaces to underscores.
--
function suite.removesSpaces()
test.isequal("My_Project", make.tovar("My Project"))
end
--
-- Convert dashes to underscores.
--
function suite.removesDashes()
test.isequal("My_Project", make.tovar("My-Project"))
end
--
-- Remove parenthesis.
--
function suite.removesDashes()
test.isequal("MyProject_x86", make.tovar("MyProject (x86)"))
end

View File

@ -157,10 +157,13 @@
-- Makefile tests
dofile("actions/make/test_make_escaping.lua")
dofile("actions/make/test_make_tovar.lua")
-- Makefile solutions
dofile("actions/make/solution/test_config_maps.lua")
dofile("actions/make/solution/test_default_config.lua")
dofile("actions/make/solution/test_help_rule.lua")
dofile("actions/make/solution/test_project_rule.lua")
-- Makefile C/C++ projects
dofile("actions/make/cpp/test_file_rules.lua")