2009-04-11 11:33:32 +00:00
|
|
|
--
|
|
|
|
-- make_solution.lua
|
|
|
|
-- Generate a solution-level makefile.
|
2012-04-30 20:42:03 +00:00
|
|
|
-- Copyright (c) 2002-2012 Jason Perkins and the Premake project
|
2009-04-11 11:33:32 +00:00
|
|
|
--
|
|
|
|
|
2012-04-30 20:42:03 +00:00
|
|
|
local make = premake.make
|
2012-05-04 20:38:21 +00:00
|
|
|
local solution = premake.solution
|
2013-12-05 19:41:35 +00:00
|
|
|
local tree = premake.tree
|
2013-09-13 15:15:36 +00:00
|
|
|
local project = premake.project
|
2012-04-30 20:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Generate a GNU make "solution" makefile, with support for the new platforms API.
|
|
|
|
--
|
|
|
|
|
|
|
|
function make.generate_solution(sln)
|
2012-09-27 14:16:42 +00:00
|
|
|
make.header(sln)
|
2012-05-04 20:38:21 +00:00
|
|
|
|
2012-07-24 20:54:11 +00:00
|
|
|
make.configmap(sln)
|
2012-05-08 22:08:42 +00:00
|
|
|
make.projects(sln)
|
2014-04-26 20:11:17 +00:00
|
|
|
|
|
|
|
make.solutionPhonyRule(sln)
|
|
|
|
make.groupRules(sln)
|
2012-05-04 20:38:21 +00:00
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
make.projectrules(sln)
|
|
|
|
make.cleanrules(sln)
|
|
|
|
make.helprule(sln)
|
|
|
|
end
|
2012-05-04 20:38:21 +00:00
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
|
2012-07-24 20:54:11 +00:00
|
|
|
--
|
|
|
|
-- 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)
|
2013-09-13 15:52:00 +00:00
|
|
|
for prj in solution.eachproject(sln) do
|
2012-07-24 20:54:11 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
--
|
|
|
|
-- Write out the rules for the `make clean` action.
|
|
|
|
--
|
|
|
|
|
|
|
|
function make.cleanrules(sln)
|
2012-05-04 20:38:21 +00:00
|
|
|
_p('clean:')
|
2013-09-13 15:52:00 +00:00
|
|
|
for prj in solution.eachproject(sln) do
|
2012-12-31 18:45:22 +00:00
|
|
|
local prjpath = project.getfilename(prj, make.getmakefilename(prj, true))
|
2013-09-30 14:16:56 +00:00
|
|
|
local prjdir = path.getdirectory(path.getrelative(sln.location, prjpath))
|
2012-12-31 18:45:22 +00:00
|
|
|
local prjname = path.getname(prjpath)
|
2013-05-22 15:15:48 +00:00
|
|
|
_x(1,'@${MAKE} --no-print-directory -C %s -f %s clean', prjdir, prjname)
|
2012-05-04 20:38:21 +00:00
|
|
|
end
|
|
|
|
_p('')
|
2012-05-08 22:08:42 +00:00
|
|
|
end
|
2012-05-04 20:38:21 +00:00
|
|
|
|
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
--
|
|
|
|
-- Write out the make file help rule and configurations list.
|
|
|
|
--
|
|
|
|
|
|
|
|
function make.helprule(sln)
|
2012-05-04 20:38:21 +00:00
|
|
|
_p('help:')
|
|
|
|
_p(1,'@echo "Usage: make [config=name] [target]"')
|
|
|
|
_p(1,'@echo ""')
|
|
|
|
_p(1,'@echo "CONFIGURATIONS:"')
|
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
for cfg in solution.eachconfig(sln) do
|
2013-05-22 15:15:48 +00:00
|
|
|
_x(1, '@echo " %s"', cfg.shortname)
|
2012-05-04 20:38:21 +00:00
|
|
|
end
|
2012-05-08 22:08:42 +00:00
|
|
|
|
2012-05-04 20:38:21 +00:00
|
|
|
_p(1,'@echo ""')
|
2012-05-08 22:08:42 +00:00
|
|
|
|
2012-05-04 20:38:21 +00:00
|
|
|
_p(1,'@echo "TARGETS:"')
|
|
|
|
_p(1,'@echo " all (default)"')
|
|
|
|
_p(1,'@echo " clean"')
|
|
|
|
|
2013-09-13 15:52:00 +00:00
|
|
|
for prj in solution.eachproject(sln) do
|
2012-05-04 20:38:21 +00:00
|
|
|
_p(1,'@echo " %s"', prj.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
_p(1,'@echo ""')
|
|
|
|
_p(1,'@echo "For more information, see http://industriousone.com/premake/quick-start"')
|
2012-05-08 22:08:42 +00:00
|
|
|
end
|
2012-05-04 20:38:21 +00:00
|
|
|
|
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
--
|
|
|
|
-- Write out the list of projects that comprise the solution.
|
|
|
|
--
|
|
|
|
|
|
|
|
function make.projects(sln)
|
2013-05-22 15:15:48 +00:00
|
|
|
_p('PROJECTS := %s', table.concat(premake.esc(table.extract(sln.projects, "name")), " "))
|
2012-05-08 22:08:42 +00:00
|
|
|
_p('')
|
2012-04-30 20:42:03 +00:00
|
|
|
end
|
|
|
|
|
2014-04-26 20:11:17 +00:00
|
|
|
--
|
|
|
|
-- Write out the solution PHONY rule
|
|
|
|
--
|
|
|
|
|
|
|
|
function make.solutionPhonyRule(sln)
|
|
|
|
local groups = {}
|
|
|
|
local tr = solution.grouptree(sln)
|
|
|
|
tree.traverse(tr, {
|
|
|
|
onbranch = function(n)
|
|
|
|
table.insert(groups, n.path)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
_p('.PHONY: all clean help $(PROJECTS) ' .. table.implode(groups, '', '', ' '))
|
|
|
|
_p('')
|
|
|
|
_p('all: $(PROJECTS)')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out the phony rules representing project groups
|
|
|
|
--
|
|
|
|
function make.groupRules(sln)
|
|
|
|
-- Transform solution groups into target aggregate
|
|
|
|
local tr = solution.grouptree(sln)
|
|
|
|
tree.traverse(tr, {
|
|
|
|
onbranch = function(n)
|
|
|
|
local rule = n.path .. ":"
|
|
|
|
for i, c in pairs(n.children)
|
|
|
|
do
|
|
|
|
if type(i) == "string"
|
|
|
|
then
|
|
|
|
if c.project
|
|
|
|
then
|
|
|
|
rule = rule .. " " .. c.name
|
|
|
|
else
|
|
|
|
rule = rule .. " " .. c.path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
_p(rule)
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2012-04-30 20:42:03 +00:00
|
|
|
|
2012-05-04 20:38:21 +00:00
|
|
|
--
|
2012-05-08 22:08:42 +00:00
|
|
|
-- Write out the rules to build each of the solution's projects.
|
2012-05-04 20:38:21 +00:00
|
|
|
--
|
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
function make.projectrules(sln)
|
2013-09-13 15:52:00 +00:00
|
|
|
for prj in solution.eachproject(sln) do
|
2012-05-08 22:08:42 +00:00
|
|
|
local deps = project.getdependencies(prj)
|
2012-12-31 18:45:22 +00:00
|
|
|
deps = table.extract(deps, "name")
|
2013-11-14 13:52:55 +00:00
|
|
|
_p('%s:%s', premake.esc(prj.name), make.list(deps))
|
2012-12-31 18:45:22 +00:00
|
|
|
|
2012-07-24 20:54:11 +00:00
|
|
|
local cfgvar = make.tovar(prj.name)
|
|
|
|
_p('ifneq (,$(%s_config))', cfgvar)
|
2012-12-31 18:45:22 +00:00
|
|
|
|
2012-07-24 20:54:11 +00:00
|
|
|
_p(1,'@echo "==== Building %s ($(%s_config)) ===="', prj.name, cfgvar)
|
2012-05-08 22:08:42 +00:00
|
|
|
|
2012-12-31 18:45:22 +00:00
|
|
|
local prjpath = project.getfilename(prj, make.getmakefilename(prj, true))
|
2013-09-30 14:16:56 +00:00
|
|
|
local prjdir = path.getdirectory(path.getrelative(sln.location, prjpath))
|
2012-12-31 18:45:22 +00:00
|
|
|
local prjname = path.getname(prjpath)
|
|
|
|
|
2013-05-22 15:15:48 +00:00
|
|
|
_x(1,'@${MAKE} --no-print-directory -C %s -f %s config=$(%s_config)', prjdir, prjname, cfgvar)
|
2012-12-31 18:45:22 +00:00
|
|
|
|
2012-07-24 20:54:11 +00:00
|
|
|
_p('endif')
|
2012-05-08 22:08:42 +00:00
|
|
|
_p('')
|
2012-05-04 20:38:21 +00:00
|
|
|
end
|
|
|
|
end
|