2017-06-13 16:51:58 +00:00
|
|
|
--
|
|
|
|
-- gmake2_makefile.lua
|
|
|
|
-- Generate a C/C++ project makefile.
|
|
|
|
-- (c) 2016-2017 Jason Perkins, Blizzard Entertainment and the Premake project
|
|
|
|
--
|
|
|
|
|
|
|
|
local p = premake
|
|
|
|
local gmake2 = p.modules.gmake2
|
|
|
|
|
|
|
|
gmake2.makefile = {}
|
|
|
|
local makefile = gmake2.makefile
|
|
|
|
|
|
|
|
local project = p.project
|
|
|
|
local config = p.config
|
|
|
|
local fileconfig = p.fileconfig
|
|
|
|
|
|
|
|
---
|
2018-04-02 18:25:57 +00:00
|
|
|
-- Add namespace for element definition lists for p.callArray()
|
2017-06-13 16:51:58 +00:00
|
|
|
---
|
|
|
|
makefile.elements = {}
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Generate a GNU make makefile project makefile.
|
|
|
|
--
|
|
|
|
|
|
|
|
makefile.elements.makefile = function(prj)
|
|
|
|
return {
|
|
|
|
gmake2.header,
|
|
|
|
gmake2.phonyRules,
|
|
|
|
makefile.configs,
|
|
|
|
makefile.targetRules
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function makefile.generate(prj)
|
|
|
|
p.eol("\n")
|
2018-04-02 18:25:57 +00:00
|
|
|
p.callArray(makefile.elements.makefile, prj)
|
2017-06-13 16:51:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
makefile.elements.configuration = function(cfg)
|
|
|
|
return {
|
|
|
|
gmake2.target,
|
|
|
|
gmake2.buildCommands,
|
|
|
|
gmake2.cleanCommands,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function makefile.configs(prj)
|
2017-10-30 18:56:56 +00:00
|
|
|
local first = true
|
2017-06-13 16:51:58 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
local toolset = p.tools[cfg.toolset or "gcc"]
|
|
|
|
if not toolset then
|
|
|
|
error("Invalid toolset '" .. cfg.toolset .. "'")
|
|
|
|
end
|
|
|
|
|
2017-10-30 18:56:56 +00:00
|
|
|
if first then
|
|
|
|
_x('ifeq ($(config),%s)', cfg.shortname)
|
|
|
|
first = false
|
|
|
|
else
|
|
|
|
_x('else ifeq ($(config),%s)', cfg.shortname)
|
|
|
|
end
|
|
|
|
|
2018-04-02 18:25:57 +00:00
|
|
|
p.callArray(makefile.elements.configuration, cfg, toolset)
|
2017-10-30 18:56:56 +00:00
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
if not first then
|
|
|
|
_p('else')
|
|
|
|
_p(' $(error "invalid configuration $(config)")')
|
2017-06-13 16:51:58 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function makefile.targetRules(prj)
|
|
|
|
_p('$(TARGET):')
|
|
|
|
_p('\t$(BUILDCMDS)')
|
|
|
|
_p('')
|
|
|
|
_p('clean:')
|
|
|
|
_p('\t$(CLEANCMDS)')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function gmake2.buildCommands(cfg)
|
|
|
|
_p(' define BUILDCMDS')
|
|
|
|
local steps = cfg.buildcommands
|
|
|
|
if #steps > 0 then
|
|
|
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
|
|
|
_p('\t@echo Running build commands')
|
|
|
|
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function gmake2.cleanCommands(cfg)
|
|
|
|
_p(' define CLEANCMDS')
|
|
|
|
local steps = cfg.cleancommands
|
|
|
|
if #steps > 0 then
|
|
|
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
|
|
|
_p('\t@echo Running clean commands')
|
|
|
|
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
|
|
|
end
|
|
|
|
|