premake/src/actions/make/make_solution.lua

62 lines
2.2 KiB
Lua
Raw Normal View History

--
-- make_solution.lua
-- Generate a solution-level makefile.
-- Copyright (c) 2002-2009 Jason Perkins and the Premake project
--
function premake.make_solution(sln)
-- create a shortcut to the compiler interface
local cc = premake[_OPTIONS.cc]
-- write a header showing the build options
_p('# %s solution makefile autogenerated by Premake', premake.actions[_ACTION].shortname)
_p('# Usage: make [ config=config_name ]')
_p('# Where {config_name} is one of: %s.', table.implode(sln.configurations, '"', '"', ', '):lower())
_p('')
-- set a default configuration
_p('ifndef config')
_p(' config=%s', _MAKE.esc(sln.configurations[1]:lower()))
_p('endif')
_p('export config')
_p('')
-- list the projects included in the solution
_p('PROJECTS := %s', table.concat(_MAKE.esc(table.extract(sln.projects, "name")), " "))
_p('')
_p('.PHONY: all clean $(PROJECTS)')
_p('')
_p('all: $(PROJECTS)')
_p('')
-- build a list of supported target platforms that also includes a generic build
local platforms = premake.filterplatforms(sln, cc.platforms)
table.insert(platforms, 1, "")
-- write the project build rules
for _, prj in ipairs(sln.projects) do
-- before each project rule, build a list of dependencies for the project. If any of
-- these dependencies change, the project needs to be rebuilt
for _, platform in ipairs(platforms) do
for cfg in premake.eachconfig(prj, platform) do
_p('ifeq ($(config),%s)', table.concat({ _MAKE.esc(cfg.name:lower()), cfg.platform}, ":"))
_p(' DEPENDENCIES := %s', table.concat(_MAKE.esc(table.extract(premake.getdependencies(cfg), "name")), " "))
_p('endif')
end
end
_p('')
_p('%s: ${DEPENDENCIES}', _MAKE.esc(prj.name))
_p('\t@echo ==== Building %s ====', prj.name)
_p('\t@${MAKE} --no-print-directory -C %s -f %s', _MAKE.esc(path.getrelative(sln.location, prj.location)), _MAKE.esc(_MAKE.getmakefilename(prj, true)))
_p('')
end
-- clean rules
_p('clean:')
for _ ,prj in ipairs(sln.projects) do
_p(' @${MAKE} --no-print-directory -C %s -f %s clean', _MAKE.esc(path.getrelative(sln.location, prj.location)), _MAKE.esc(_MAKE.getmakefilename(prj, true)))
end
end