2008-10-31 18:38:05 +00:00
|
|
|
--
|
2017-06-14 23:38:10 +00:00
|
|
|
-- gmake.lua
|
2008-10-31 18:38:05 +00:00
|
|
|
-- Define the makefile action(s).
|
2015-07-29 19:40:20 +00:00
|
|
|
-- Copyright (c) 2002-2015 Jason Perkins and the Premake project
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
|
2015-08-10 17:05:26 +00:00
|
|
|
local p = premake
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2017-06-14 23:38:10 +00:00
|
|
|
p.modules.gmake = {}
|
|
|
|
p.modules.gmake._VERSION = p._VERSION
|
2013-05-22 15:15:48 +00:00
|
|
|
|
2017-06-14 23:38:10 +00:00
|
|
|
-- for backwards compatibility.
|
|
|
|
p.make = p.modules.gmake
|
2012-04-30 20:42:03 +00:00
|
|
|
|
2017-06-14 23:38:10 +00:00
|
|
|
local make = p.make
|
|
|
|
local project = p.project
|
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 default configuration rule for a workspace or project.
|
|
|
|
--
|
2012-05-08 22:08:42 +00:00
|
|
|
-- @param target
|
2015-08-12 18:53:12 +00:00
|
|
|
-- The workspace or project object for which a makefile is being generated.
|
2012-05-04 20:38:21 +00:00
|
|
|
--
|
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
function make.defaultconfig(target)
|
2012-09-27 14:16:42 +00:00
|
|
|
-- find the right configuration iterator function for this object
|
2015-08-10 17:05:26 +00:00
|
|
|
local eachconfig = iif(target.project, project.eachconfig, p.workspace.eachconfig)
|
2017-11-23 14:07:26 +00:00
|
|
|
local defaultconfig = nil
|
|
|
|
|
|
|
|
-- find the right default configuration platform, grab first configuration that matches
|
|
|
|
if target.defaultplatform then
|
|
|
|
for cfg in eachconfig(target) do
|
|
|
|
if cfg.platform == target.defaultplatform then
|
|
|
|
defaultconfig = cfg
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-12-31 18:45:22 +00:00
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
-- grab the first configuration and write the block
|
2017-11-23 14:07:26 +00:00
|
|
|
if not defaultconfig then
|
|
|
|
local iter = eachconfig(target)
|
|
|
|
defaultconfig = iter()
|
|
|
|
end
|
|
|
|
|
|
|
|
if defaultconfig then
|
2012-05-04 20:38:21 +00:00
|
|
|
_p('ifndef config')
|
2017-11-23 14:07:26 +00:00
|
|
|
_x(' config=%s', defaultconfig.shortname)
|
2012-05-04 20:38:21 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-05-22 15:15:48 +00:00
|
|
|
---
|
2012-05-04 20:38:21 +00:00
|
|
|
-- Escape a string so it can be written to a makefile.
|
2013-05-22 15:15:48 +00:00
|
|
|
---
|
2012-05-04 20:38:21 +00:00
|
|
|
|
|
|
|
function make.esc(value)
|
2013-05-22 15:15:48 +00:00
|
|
|
result = value:gsub("\\", "\\\\")
|
2016-05-02 17:18:36 +00:00
|
|
|
result = result:gsub("\"", "\\\"")
|
2013-05-22 15:15:48 +00:00
|
|
|
result = result:gsub(" ", "\\ ")
|
2015-09-02 21:01:10 +00:00
|
|
|
result = result:gsub("%(", "\\(")
|
|
|
|
result = result:gsub("%)", "\\)")
|
2013-05-22 15:15:48 +00:00
|
|
|
|
|
|
|
-- leave $(...) shell replacement sequences alone
|
2015-09-02 21:01:10 +00:00
|
|
|
result = result:gsub("$\\%((.-)\\%)", "$(%1)")
|
2013-05-22 15:15:48 +00:00
|
|
|
return result
|
2012-05-04 20:38:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-04-30 20:42:03 +00:00
|
|
|
--
|
2015-08-12 18:53:12 +00:00
|
|
|
-- Get the makefile file name for a workspace or a project. If this object is the
|
2012-04-30 20:42:03 +00:00
|
|
|
-- only one writing to a location then I can use "Makefile". If more than one object
|
|
|
|
-- writes to the same location I use name + ".make" to keep it unique.
|
|
|
|
--
|
|
|
|
|
|
|
|
function make.getmakefilename(this, searchprjs)
|
|
|
|
local count = 0
|
2015-08-12 18:56:06 +00:00
|
|
|
for wks in p.global.eachWorkspace() do
|
|
|
|
if wks.location == this.location then
|
2012-12-31 18:45:22 +00:00
|
|
|
count = count + 1
|
2012-04-30 20:42:03 +00:00
|
|
|
end
|
2012-12-31 18:45:22 +00:00
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
if searchprjs then
|
2015-08-12 18:56:06 +00:00
|
|
|
for _, prj in ipairs(wks.projects) do
|
2012-04-30 20:42:03 +00:00
|
|
|
if prj.location == this.location then
|
|
|
|
count = count + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-12-31 18:45:22 +00:00
|
|
|
|
2012-04-30 20:42:03 +00:00
|
|
|
if count == 1 then
|
|
|
|
return "Makefile"
|
|
|
|
else
|
2012-12-31 18:45:22 +00:00
|
|
|
return ".make"
|
2012-04-30 20:42:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-09-27 14:16:42 +00:00
|
|
|
--
|
|
|
|
-- Output a makefile header.
|
|
|
|
--
|
|
|
|
-- @param target
|
2015-08-12 18:53:12 +00:00
|
|
|
-- The workspace or project object for which the makefile is being generated.
|
2012-09-27 14:16:42 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
function make.header(target)
|
2015-08-12 18:53:12 +00:00
|
|
|
local kind = iif(target.project, "project", "workspace")
|
2012-12-31 18:45:22 +00:00
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
_p('# %s %s makefile autogenerated by Premake', p.action.current().shortname, kind)
|
2012-09-27 14:16:42 +00:00
|
|
|
_p('')
|
|
|
|
|
2015-08-12 18:53:12 +00:00
|
|
|
if kind == "workspace" then
|
2016-11-22 15:44:03 +00:00
|
|
|
local haspch = false
|
|
|
|
for _, prj in ipairs(target.projects) do
|
|
|
|
for cfg in project.eachconfig(prj) do
|
|
|
|
if cfg.pchheader then
|
|
|
|
haspch = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if haspch then
|
|
|
|
_p('.NOTPARALLEL:')
|
|
|
|
_p('')
|
|
|
|
end
|
2014-06-05 16:11:03 +00:00
|
|
|
end
|
|
|
|
|
2012-09-27 14:16:42 +00:00
|
|
|
make.defaultconfig(target)
|
|
|
|
|
|
|
|
_p('ifndef verbose')
|
|
|
|
_p(' SILENT = @')
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-06-22 21:15:17 +00:00
|
|
|
--
|
|
|
|
-- Rules for file ops based on the shell type. Can't use defines and $@ because
|
2015-08-12 18:53:12 +00:00
|
|
|
-- it screws up the escaping of spaces and parethesis (anyone know a fix?)
|
2012-06-22 21:15:17 +00:00
|
|
|
--
|
|
|
|
|
2017-01-05 14:33:51 +00:00
|
|
|
function make.mkdir(dirname)
|
2012-06-22 21:15:17 +00:00
|
|
|
_p('ifeq (posix,$(SHELLTYPE))')
|
|
|
|
_p('\t$(SILENT) mkdir -p %s', dirname)
|
|
|
|
_p('else')
|
|
|
|
_p('\t$(SILENT) mkdir $(subst /,\\\\,%s)', dirname)
|
|
|
|
_p('endif')
|
2012-12-31 18:45:22 +00:00
|
|
|
end
|
2012-06-22 21:15:17 +00:00
|
|
|
|
2017-01-05 14:33:51 +00:00
|
|
|
function make.mkdirRules(dirname)
|
|
|
|
_p('%s:', dirname)
|
|
|
|
_p('\t@echo Creating %s', dirname)
|
|
|
|
make.mkdir(dirname)
|
|
|
|
_p('')
|
|
|
|
end
|
2012-06-22 21:15:17 +00:00
|
|
|
|
2013-01-23 16:50:54 +00:00
|
|
|
--
|
|
|
|
-- Format a list of values to be safely written as part of a variable assignment.
|
|
|
|
--
|
|
|
|
|
2016-08-17 15:48:41 +00:00
|
|
|
function make.list(value, quoted)
|
|
|
|
quoted = false
|
2013-01-23 16:50:54 +00:00
|
|
|
if #value > 0 then
|
2016-08-17 15:48:41 +00:00
|
|
|
if quoted then
|
|
|
|
local result = ""
|
|
|
|
for _, v in ipairs (value) do
|
|
|
|
if #result then
|
|
|
|
result = result .. " "
|
|
|
|
end
|
2017-04-25 05:44:13 +00:00
|
|
|
result = result .. p.quoted(v)
|
2016-08-17 15:48:41 +00:00
|
|
|
end
|
|
|
|
return result
|
|
|
|
else
|
|
|
|
return " " .. table.concat(value, " ")
|
|
|
|
end
|
2013-01-23 16:50:54 +00:00
|
|
|
else
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-06-13 22:29:51 +00:00
|
|
|
--
|
2013-08-11 18:22:24 +00:00
|
|
|
-- Convert an arbitrary string (project name) to a make variable name.
|
|
|
|
--
|
|
|
|
|
|
|
|
function make.tovar(value)
|
|
|
|
value = value:gsub("[ -]", "_")
|
|
|
|
value = value:gsub("[()]", "")
|
|
|
|
return value
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Handlers for the individual makefile elements that can be shared
|
|
|
|
-- between the different language projects.
|
2012-06-13 22:29:51 +00:00
|
|
|
--
|
2013-08-11 18:22:24 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function make.objdir(cfg)
|
2017-04-25 05:44:13 +00:00
|
|
|
_x(' OBJDIR = %s', p.esc(project.getrelative(cfg.project, cfg.objdir)))
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.objDirRules(prj)
|
|
|
|
make.mkdirRules("$(OBJDIR)")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.phonyRules(prj)
|
|
|
|
_p('.PHONY: clean prebuild prelink')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-01-15 21:12:29 +00:00
|
|
|
function make.buildCmds(cfg, event)
|
|
|
|
_p(' define %sCMDS', event:upper())
|
|
|
|
local steps = cfg[event .. "commands"]
|
|
|
|
local msg = cfg[event .. "message"]
|
|
|
|
if #steps > 0 then
|
2017-04-18 16:37:29 +00:00
|
|
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
2014-01-15 21:12:29 +00:00
|
|
|
msg = msg or string.format("Running %s commands", event)
|
|
|
|
_p('\t@echo %s', msg)
|
|
|
|
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
_p(' endef')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-01-15 21:12:29 +00:00
|
|
|
function make.preBuildCmds(cfg, toolset)
|
|
|
|
make.buildCmds(cfg, "prebuild")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function make.preBuildRules(prj)
|
|
|
|
_p('prebuild:')
|
|
|
|
_p('\t$(PREBUILDCMDS)')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.preLinkCmds(cfg, toolset)
|
2014-01-15 21:12:29 +00:00
|
|
|
make.buildCmds(cfg, "prelink")
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.preLinkRules(prj)
|
|
|
|
_p('prelink:')
|
|
|
|
_p('\t$(PRELINKCMDS)')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.postBuildCmds(cfg, toolset)
|
2014-01-15 21:12:29 +00:00
|
|
|
make.buildCmds(cfg, "postbuild")
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
2012-06-13 22:29:51 +00:00
|
|
|
|
|
|
|
function make.settings(cfg, toolset)
|
|
|
|
if #cfg.makesettings > 0 then
|
|
|
|
for _, value in ipairs(cfg.makesettings) do
|
|
|
|
_p(value)
|
|
|
|
end
|
|
|
|
end
|
2012-09-28 16:07:18 +00:00
|
|
|
|
|
|
|
local value = toolset.getmakesettings(cfg)
|
|
|
|
if value then
|
|
|
|
_p(value)
|
2012-06-13 22:29:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-30 20:42:03 +00:00
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function make.shellType()
|
2018-05-31 22:33:08 +00:00
|
|
|
_p('SHELLTYPE := posix')
|
|
|
|
_p('ifeq (.exe,$(findstring .exe,$(ComSpec)))')
|
|
|
|
_p('\tSHELLTYPE := msdos')
|
2013-08-11 18:22:24 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2012-09-28 14:35:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function make.target(cfg)
|
|
|
|
_x(' TARGETDIR = %s', project.getrelative(cfg.project, cfg.buildtarget.directory))
|
|
|
|
_x(' TARGET = $(TARGETDIR)/%s', cfg.buildtarget.name)
|
|
|
|
end
|
2012-07-24 20:54:11 +00:00
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
|
|
|
|
function make.targetDirRules(prj)
|
|
|
|
make.mkdirRules("$(TARGETDIR)")
|
2012-07-24 20:54:11 +00:00
|
|
|
end
|
2017-06-14 23:38:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
include("gmake_cpp.lua")
|
|
|
|
include("gmake_csharp.lua")
|
|
|
|
include("gmake_makefile.lua")
|
|
|
|
include("gmake_utility.lua")
|
|
|
|
include("gmake_workspace.lua")
|
|
|
|
|
|
|
|
return p.modules.gmake
|