2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- _make.lua
|
|
|
|
-- Define the makefile action(s).
|
2011-09-15 20:45:48 +00:00
|
|
|
-- Copyright (c) 2002-2011 Jason Perkins and the Premake project
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
|
2008-11-19 02:17:43 +00:00
|
|
|
_MAKE = { }
|
2010-10-19 11:14:46 +00:00
|
|
|
premake.make = { }
|
2011-09-15 20:45:48 +00:00
|
|
|
local make = premake.make
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Escape a string so it can be written to a makefile.
|
|
|
|
--
|
|
|
|
|
2008-11-19 02:17:43 +00:00
|
|
|
function _MAKE.esc(value)
|
2010-10-04 10:43:19 +00:00
|
|
|
local result
|
2008-10-31 18:38:05 +00:00
|
|
|
if (type(value) == "table") then
|
2010-10-04 10:43:19 +00:00
|
|
|
result = { }
|
2008-10-31 18:38:05 +00:00
|
|
|
for _,v in ipairs(value) do
|
2008-11-19 02:17:43 +00:00
|
|
|
table.insert(result, _MAKE.esc(v))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
return result
|
|
|
|
else
|
2010-10-04 10:43:19 +00:00
|
|
|
-- handle simple replacements
|
2009-05-29 17:45:37 +00:00
|
|
|
result = value:gsub("\\", "\\\\")
|
|
|
|
result = result:gsub(" ", "\\ ")
|
|
|
|
result = result:gsub("%(", "\\%(")
|
|
|
|
result = result:gsub("%)", "\\%)")
|
2010-10-04 10:43:19 +00:00
|
|
|
|
|
|
|
-- leave $(...) shell replacement sequences alone
|
|
|
|
result = result:gsub("$\\%((.-)\\%)", "$%(%1%)")
|
2008-10-31 18:38:05 +00:00
|
|
|
return result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-21 16:37:24 +00:00
|
|
|
|
|
|
|
|
2009-05-29 17:45:37 +00:00
|
|
|
--
|
|
|
|
-- Rules for file ops based on the shell type. Can't use defines and $@ because
|
|
|
|
-- it screws up the escaping of spaces and parethesis (anyone know a solution?)
|
|
|
|
--
|
|
|
|
|
|
|
|
function premake.make_copyrule(source, target)
|
|
|
|
_p('%s: %s', target, source)
|
|
|
|
_p('\t@echo Copying $(notdir %s)', target)
|
|
|
|
_p('ifeq (posix,$(SHELLTYPE))')
|
|
|
|
_p('\t$(SILENT) cp -fR %s %s', source, target)
|
|
|
|
_p('else')
|
|
|
|
_p('\t$(SILENT) copy /Y $(subst /,\\\\,%s) $(subst /,\\\\,%s)', source, target)
|
|
|
|
_p('endif')
|
|
|
|
end
|
|
|
|
|
|
|
|
function premake.make_mkdirrule(var)
|
|
|
|
_p('\t@echo Creating %s', var)
|
|
|
|
_p('ifeq (posix,$(SHELLTYPE))')
|
|
|
|
_p('\t$(SILENT) mkdir -p %s', var)
|
|
|
|
_p('else')
|
|
|
|
_p('\t$(SILENT) mkdir $(subst /,\\\\,%s)', var)
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- Get the makefile file name for a solution or a project. If this object is the
|
|
|
|
-- 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.
|
|
|
|
--
|
|
|
|
|
2008-11-19 02:17:43 +00:00
|
|
|
function _MAKE.getmakefilename(this, searchprjs)
|
2008-10-31 18:38:05 +00:00
|
|
|
-- how many projects/solutions use this location?
|
|
|
|
local count = 0
|
2009-11-04 18:44:13 +00:00
|
|
|
for sln in premake.solution.each() do
|
2008-10-31 18:38:05 +00:00
|
|
|
if (sln.location == this.location) then count = count + 1 end
|
|
|
|
if (searchprjs) then
|
|
|
|
for _,prj in ipairs(sln.projects) do
|
|
|
|
if (prj.location == this.location) then count = count + 1 end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (count == 1) then
|
|
|
|
return "Makefile"
|
|
|
|
else
|
|
|
|
return this.name .. ".make"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Returns a list of object names, properly escaped to be included in the makefile.
|
|
|
|
--
|
|
|
|
|
2008-11-19 02:17:43 +00:00
|
|
|
function _MAKE.getnames(tbl)
|
2008-10-31 18:38:05 +00:00
|
|
|
local result = table.extract(tbl, "name")
|
|
|
|
for k,v in pairs(result) do
|
2008-11-19 02:17:43 +00:00
|
|
|
result[k] = _MAKE.esc(v)
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2011-09-15 20:45:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out the raw settings blocks.
|
|
|
|
--
|
|
|
|
|
|
|
|
function make.settings(cfg, cc)
|
|
|
|
if #cfg.makesettings > 0 then
|
|
|
|
for _, value in ipairs(cfg.makesettings) do
|
|
|
|
_p(value)
|
|
|
|
end
|
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2011-09-15 20:45:48 +00:00
|
|
|
local toolsettings = cc.platforms[cfg.platform].cfgsettings
|
|
|
|
if toolsettings then
|
|
|
|
_p(toolsettings)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- Register the "gmake" action
|
|
|
|
--
|
|
|
|
|
2008-11-25 00:32:49 +00:00
|
|
|
newaction {
|
|
|
|
trigger = "gmake",
|
2008-10-31 18:38:05 +00:00
|
|
|
shortname = "GNU Make",
|
2009-09-29 20:06:06 +00:00
|
|
|
description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin",
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2008-11-13 00:54:41 +00:00
|
|
|
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" },
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2008-12-05 21:18:47 +00:00
|
|
|
valid_languages = { "C", "C++", "C#" },
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
valid_tools = {
|
2008-12-05 21:18:47 +00:00
|
|
|
cc = { "gcc" },
|
2009-05-08 20:18:47 +00:00
|
|
|
dotnet = { "mono", "msnet", "pnet" },
|
2008-10-31 18:38:05 +00:00
|
|
|
},
|
|
|
|
|
2009-08-12 01:16:15 +00:00
|
|
|
onsolution = function(sln)
|
|
|
|
premake.generate(sln, _MAKE.getmakefilename(sln, false), premake.make_solution)
|
|
|
|
end,
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2009-08-12 01:16:15 +00:00
|
|
|
onproject = function(prj)
|
|
|
|
local makefile = _MAKE.getmakefilename(prj, true)
|
|
|
|
if premake.isdotnetproject(prj) then
|
|
|
|
premake.generate(prj, makefile, premake.make_csharp)
|
|
|
|
else
|
|
|
|
premake.generate(prj, makefile, premake.make_cpp)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
oncleansolution = function(sln)
|
|
|
|
premake.clean.file(sln, _MAKE.getmakefilename(sln, false))
|
|
|
|
end,
|
|
|
|
|
|
|
|
oncleanproject = function(prj)
|
|
|
|
premake.clean.file(prj, _MAKE.getmakefilename(prj, true))
|
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
}
|