2009-04-11 11:33:32 +00:00
|
|
|
--
|
2015-08-12 18:53:12 +00:00
|
|
|
-- make_workspace.lua
|
|
|
|
-- Generate a workspace-level makefile.
|
|
|
|
-- Copyright (c) 2002-2015 Jason Perkins and the Premake project
|
2009-04-11 11:33:32 +00:00
|
|
|
--
|
|
|
|
|
2015-08-12 18:53:12 +00:00
|
|
|
local p = premake
|
|
|
|
local make = p.make
|
|
|
|
local tree = p.tree
|
|
|
|
local project = p.project
|
2012-04-30 20:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
2015-08-12 18:53:12 +00:00
|
|
|
-- Generate a GNU make "workspace" makefile, with support for the new platforms API.
|
2012-04-30 20:42:03 +00:00
|
|
|
--
|
|
|
|
|
2015-08-24 21:08:09 +00:00
|
|
|
function make.generate_workspace(wks)
|
|
|
|
p.eol("\n")
|
2014-02-08 15:44:57 +00:00
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
make.header(wks)
|
2012-05-04 20:38:21 +00:00
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
make.configmap(wks)
|
|
|
|
make.projects(wks)
|
2012-05-04 20:38:21 +00:00
|
|
|
|
2015-08-24 21:08:09 +00:00
|
|
|
make.workspacePhonyRule(wks)
|
2015-08-12 18:56:06 +00:00
|
|
|
make.groupRules(wks)
|
2012-05-04 20:38:21 +00:00
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
make.projectrules(wks)
|
|
|
|
make.cleanrules(wks)
|
|
|
|
make.helprule(wks)
|
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
|
|
|
|
2012-07-24 20:54:11 +00:00
|
|
|
--
|
2015-08-12 18:53:12 +00:00
|
|
|
-- Write out the workspace's configuration map, which maps workspace
|
2012-07-24 20:54:11 +00:00
|
|
|
-- level configurations to the project level equivalents.
|
|
|
|
--
|
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
function make.configmap(wks)
|
|
|
|
for cfg in p.workspace.eachconfig(wks) do
|
2012-07-24 20:54:11 +00:00
|
|
|
_p('ifeq ($(config),%s)', cfg.shortname)
|
2015-08-12 18:56:06 +00:00
|
|
|
for prj in p.workspace.eachproject(wks) 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.
|
|
|
|
--
|
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
function make.cleanrules(wks)
|
2012-05-04 20:38:21 +00:00
|
|
|
_p('clean:')
|
2015-08-12 18:56:06 +00:00
|
|
|
for prj in p.workspace.eachproject(wks) do
|
2017-04-25 05:44:13 +00:00
|
|
|
local prjpath = p.filename(prj, make.getmakefilename(prj, true))
|
2015-08-12 18:56:06 +00:00
|
|
|
local prjdir = path.getdirectory(path.getrelative(wks.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.
|
|
|
|
--
|
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
function make.helprule(wks)
|
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:"')
|
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
for cfg in p.workspace.eachconfig(wks) 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"')
|
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
for prj in p.workspace.eachproject(wks) 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
|
|
|
--
|
2015-08-12 18:53:12 +00:00
|
|
|
-- Write out the list of projects that comprise the workspace.
|
2012-05-08 22:08:42 +00:00
|
|
|
--
|
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
function make.projects(wks)
|
2017-04-25 05:44:13 +00:00
|
|
|
_p('PROJECTS := %s', table.concat(p.esc(table.extract(wks.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
|
|
|
--
|
2015-08-12 18:53:12 +00:00
|
|
|
-- Write out the workspace PHONY rule
|
2014-04-26 20:11:17 +00:00
|
|
|
--
|
|
|
|
|
2015-08-24 21:08:09 +00:00
|
|
|
function make.workspacePhonyRule(wks)
|
2014-04-26 20:11:17 +00:00
|
|
|
local groups = {}
|
2015-08-12 18:56:06 +00:00
|
|
|
local tr = p.workspace.grouptree(wks)
|
2014-04-26 20:11:17 +00:00
|
|
|
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
|
|
|
|
--
|
2015-08-12 18:56:06 +00:00
|
|
|
function make.groupRules(wks)
|
2015-08-12 18:53:12 +00:00
|
|
|
-- Transform workspace groups into target aggregate
|
2015-08-12 18:56:06 +00:00
|
|
|
local tr = p.workspace.grouptree(wks)
|
2014-04-26 20:11:17 +00:00
|
|
|
tree.traverse(tr, {
|
|
|
|
onbranch = function(n)
|
|
|
|
local rule = n.path .. ":"
|
2014-04-26 20:27:02 +00:00
|
|
|
local projectTargets = {}
|
|
|
|
local groupTargets = {}
|
2014-04-26 20:11:17 +00:00
|
|
|
for i, c in pairs(n.children)
|
|
|
|
do
|
|
|
|
if type(i) == "string"
|
|
|
|
then
|
|
|
|
if c.project
|
|
|
|
then
|
2014-04-26 20:27:02 +00:00
|
|
|
table.insert(projectTargets, c.name)
|
2014-04-26 20:11:17 +00:00
|
|
|
else
|
2014-04-26 20:27:02 +00:00
|
|
|
table.insert(groupTargets, c.path)
|
2014-04-26 20:11:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-26 20:27:02 +00:00
|
|
|
if #groupTargets > 0 then
|
2016-03-02 00:09:40 +00:00
|
|
|
table.sort(groupTargets)
|
2014-04-26 20:27:02 +00:00
|
|
|
rule = rule .. " " .. table.concat(groupTargets, " ")
|
|
|
|
end
|
|
|
|
if #projectTargets > 0 then
|
2016-03-02 00:09:40 +00:00
|
|
|
table.sort(projectTargets)
|
2014-04-26 20:27:02 +00:00
|
|
|
rule = rule .. " " .. table.concat(projectTargets, " ")
|
|
|
|
end
|
2014-04-26 20:11:17 +00:00
|
|
|
_p(rule)
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2012-04-30 20:42:03 +00:00
|
|
|
|
2012-05-04 20:38:21 +00:00
|
|
|
--
|
2015-08-12 18:53:12 +00:00
|
|
|
-- Write out the rules to build each of the workspace's projects.
|
2012-05-04 20:38:21 +00:00
|
|
|
--
|
|
|
|
|
2015-08-12 18:56:06 +00:00
|
|
|
function make.projectrules(wks)
|
|
|
|
for prj in p.workspace.eachproject(wks) 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")
|
2017-04-25 05:44:13 +00:00
|
|
|
_p('%s:%s', p.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
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
local prjpath = p.filename(prj, make.getmakefilename(prj, true))
|
2015-08-12 18:56:06 +00:00
|
|
|
local prjdir = path.getdirectory(path.getrelative(wks.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
|