2015-12-18 18:46:45 +00:00
|
|
|
--
|
|
|
|
-- make_makefile.lua
|
|
|
|
-- Generate a C/C++ project makefile.
|
|
|
|
-- Copyright (c) 2002-2014 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
|
|
|
local p = premake
|
|
|
|
p.make.makefile = {}
|
|
|
|
|
|
|
|
local make = p.make
|
|
|
|
local makefile = p.make.makefile
|
|
|
|
local project = p.project
|
|
|
|
local config = p.config
|
|
|
|
local fileconfig = p.fileconfig
|
|
|
|
|
|
|
|
---
|
2017-04-25 05:44:13 +00:00
|
|
|
-- Add namespace for element definition lists for p.callarray()
|
2015-12-18 18:46:45 +00:00
|
|
|
---
|
|
|
|
makefile.elements = {}
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Generate a GNU make makefile project makefile.
|
|
|
|
--
|
|
|
|
|
|
|
|
makefile.elements.makefile = {
|
|
|
|
"header",
|
|
|
|
"phonyRules",
|
|
|
|
"makefileConfigs",
|
|
|
|
"makefileTargetRules"
|
|
|
|
}
|
|
|
|
|
|
|
|
function make.makefile.generate(prj)
|
2017-04-25 05:44:13 +00:00
|
|
|
p.eol("\n")
|
|
|
|
p.callarray(make, makefile.elements.makefile, prj)
|
2015-12-18 18:46:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
makefile.elements.configuration = {
|
|
|
|
"target",
|
|
|
|
"buildCommands",
|
|
|
|
"cleanCommands",
|
|
|
|
}
|
|
|
|
|
|
|
|
function make.makefileConfigs(prj)
|
|
|
|
for cfg in project.eachconfig(prj) do
|
|
|
|
-- identify the toolset used by this configurations (would be nicer if
|
|
|
|
-- this were computed and stored with the configuration up front)
|
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
local toolset = p.tools[cfg.toolset or "gcc"]
|
2015-12-18 18:46:45 +00:00
|
|
|
if not toolset then
|
|
|
|
error("Invalid toolset '" .. cfg.toolset .. "'")
|
|
|
|
end
|
|
|
|
|
|
|
|
_x('ifeq ($(config),%s)', cfg.shortname)
|
2017-04-25 05:44:13 +00:00
|
|
|
p.callarray(make, makefile.elements.configuration, cfg, toolset)
|
2015-12-18 18:46:45 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function make.makefileTargetRules(prj)
|
|
|
|
_p('$(TARGET):')
|
|
|
|
_p('\t$(BUILDCMDS)')
|
|
|
|
_p('')
|
|
|
|
_p('clean:')
|
|
|
|
_p('\t$(CLEANCMDS)')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.buildCommands(cfg)
|
|
|
|
_p(' define BUILDCMDS')
|
|
|
|
local steps = cfg.buildcommands
|
|
|
|
if #steps > 0 then
|
2017-04-18 16:37:29 +00:00
|
|
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
2015-12-18 18:46:45 +00:00
|
|
|
_p('\t@echo Running build commands')
|
|
|
|
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.cleanCommands(cfg)
|
|
|
|
_p(' define CLEANCMDS')
|
|
|
|
local steps = cfg.cleancommands
|
|
|
|
if #steps > 0 then
|
2017-04-18 16:37:29 +00:00
|
|
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
2015-12-18 18:46:45 +00:00
|
|
|
_p('\t@echo Running clean commands')
|
|
|
|
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
|
|
|
end
|
|
|
|
|