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
|
2012-05-08 22:08:42 +00:00
|
|
|
local project = premake5.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-05-04 20:38:21 +00:00
|
|
|
-- a little guidance for the uninitiated
|
|
|
|
_p('# %s solution makefile autogenerated by Premake', premake.action.current().shortname)
|
|
|
|
_p('# Type "make help" for usage help')
|
|
|
|
_p('')
|
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
make.defaultconfig(sln)
|
2012-07-24 20:54:11 +00:00
|
|
|
make.configmap(sln)
|
2012-05-08 22:08:42 +00:00
|
|
|
make.projects(sln)
|
2012-05-04 20:38:21 +00:00
|
|
|
|
|
|
|
_p('.PHONY: all clean help $(PROJECTS)')
|
|
|
|
_p('')
|
|
|
|
_p('all: $(PROJECTS)')
|
|
|
|
_p('')
|
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
|
|
|
|
|
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:')
|
2012-05-08 22:08:42 +00:00
|
|
|
for prj in solution.eachproject_ng(sln) do
|
|
|
|
local slnpath = solution.getlocation(sln)
|
|
|
|
local prjpath = path.getrelative(slnpath, project.getlocation(prj))
|
|
|
|
_p(1,'@${MAKE} --no-print-directory -C %s -f %s clean', make.esc(prjpath), make.esc(make.getmakefilename(prj, true)))
|
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
|
|
|
|
_p(1, '@echo " %s"', make.esc(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"')
|
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
for prj in solution.eachproject_ng(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)
|
|
|
|
_p('PROJECTS := %s', table.concat(make.esc(table.extract(sln.projects, "name")), " "))
|
|
|
|
_p('')
|
2012-04-30 20:42:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
for prj in solution.eachproject_ng(sln) do
|
|
|
|
local deps = project.getdependencies(prj)
|
|
|
|
deps = table.extract(deps, "name")
|
2012-07-04 18:44:32 +00:00
|
|
|
_p('%s: %s', make.esc(prj.name), table.concat(deps, " "))
|
2012-05-08 22:08:42 +00:00
|
|
|
|
2012-07-24 20:54:11 +00:00
|
|
|
local cfgvar = make.tovar(prj.name)
|
|
|
|
_p('ifneq (,$(%s_config))', cfgvar)
|
|
|
|
|
|
|
|
_p(1,'@echo "==== Building %s ($(%s_config)) ===="', prj.name, cfgvar)
|
2012-05-08 22:08:42 +00:00
|
|
|
|
|
|
|
local slnpath = solution.getlocation(sln)
|
|
|
|
local prjpath = path.getrelative(slnpath, project.getlocation(prj))
|
2012-07-24 20:54:11 +00:00
|
|
|
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)
|
2012-05-08 22:08:42 +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
|
|
|
|
|
2012-04-30 20:42:03 +00:00
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
|
2012-04-30 20:42:03 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- Everything below this point is a candidate for deprecation
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
2009-04-11 11:33:32 +00:00
|
|
|
function premake.make_solution(sln)
|
2009-04-14 19:33:11 +00:00
|
|
|
-- create a shortcut to the compiler interface
|
|
|
|
local cc = premake[_OPTIONS.cc]
|
|
|
|
|
2009-04-20 19:06:48 +00:00
|
|
|
-- build a list of supported target platforms that also includes a generic build
|
2009-04-21 20:00:17 +00:00
|
|
|
local platforms = premake.filterplatforms(sln, cc.platforms, "Native")
|
2009-04-20 19:06:48 +00:00
|
|
|
|
2009-04-11 11:33:32 +00:00
|
|
|
-- write a header showing the build options
|
2009-08-11 00:11:48 +00:00
|
|
|
_p('# %s solution makefile autogenerated by Premake', premake.action.current().shortname)
|
2009-12-28 16:34:39 +00:00
|
|
|
_p('# Type "make help" for usage help')
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- set a default configuration
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('ifndef config')
|
2009-04-24 14:34:54 +00:00
|
|
|
_p(' config=%s', _MAKE.esc(premake.getconfigname(sln.configurations[1], platforms[1], true)))
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('export config')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- list the projects included in the solution
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('PROJECTS := %s', table.concat(_MAKE.esc(table.extract(sln.projects, "name")), " "))
|
|
|
|
_p('')
|
2009-12-28 16:34:39 +00:00
|
|
|
_p('.PHONY: all clean help $(PROJECTS)')
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
|
|
|
_p('all: $(PROJECTS)')
|
2009-04-14 19:25:48 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- write the project build rules
|
|
|
|
for _, prj in ipairs(sln.projects) do
|
2009-06-15 15:50:20 +00:00
|
|
|
_p('%s: %s', _MAKE.esc(prj.name), table.concat(_MAKE.esc(table.extract(premake.getdependencies(prj), "name")), " "))
|
2010-05-07 14:41:16 +00:00
|
|
|
_p('\t@echo "==== Building %s ($(config)) ===="', prj.name)
|
2012-04-30 20:42:03 +00:00
|
|
|
_p('\t@${MAKE} --no-print-directory -C %s -f %s', _MAKE.esc(path.getrelative(sln.location, prj.location)), _MAKE.esc(make.getmakefilename(prj, true)))
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- clean rules
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('clean:')
|
2009-04-11 11:33:32 +00:00
|
|
|
for _ ,prj in ipairs(sln.projects) do
|
2012-04-30 20:42:03 +00:00
|
|
|
_p('\t@${MAKE} --no-print-directory -C %s -f %s clean', _MAKE.esc(path.getrelative(sln.location, prj.location)), _MAKE.esc(make.getmakefilename(prj, true)))
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-21 19:38:16 +00:00
|
|
|
_p('')
|
|
|
|
|
2009-12-28 16:34:39 +00:00
|
|
|
-- help rule
|
|
|
|
_p('help:')
|
|
|
|
_p(1,'@echo "Usage: make [config=name] [target]"')
|
|
|
|
_p(1,'@echo ""')
|
|
|
|
_p(1,'@echo "CONFIGURATIONS:"')
|
|
|
|
|
|
|
|
local cfgpairs = { }
|
|
|
|
for _, platform in ipairs(platforms) do
|
|
|
|
for _, cfgname in ipairs(sln.configurations) do
|
|
|
|
_p(1,'@echo " %s"', premake.getconfigname(cfgname, platform, true))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
_p(1,'@echo ""')
|
|
|
|
_p(1,'@echo "TARGETS:"')
|
|
|
|
_p(1,'@echo " all (default)"')
|
|
|
|
_p(1,'@echo " clean"')
|
|
|
|
|
|
|
|
for _, prj in ipairs(sln.projects) do
|
|
|
|
_p(1,'@echo " %s"', prj.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
_p(1,'@echo ""')
|
|
|
|
_p(1,'@echo "For more information, see http://industriousone.com/premake/quick-start"')
|
|
|
|
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|