2009-04-11 11:33:32 +00:00
|
|
|
--
|
|
|
|
-- make_csharp.lua
|
|
|
|
-- Generate a C# project makefile.
|
2013-02-25 15:47:22 +00:00
|
|
|
-- Copyright (c) 2002-2013 Jason Perkins and the Premake project
|
2009-04-11 11:33:32 +00:00
|
|
|
--
|
|
|
|
|
2012-09-27 14:16:42 +00:00
|
|
|
premake.make.cs = {}
|
2012-04-30 20:42:03 +00:00
|
|
|
local make = premake.make
|
2012-09-27 14:16:42 +00:00
|
|
|
local cs = premake.make.cs
|
2013-09-13 15:15:36 +00:00
|
|
|
local project = premake.project
|
|
|
|
local config = premake.config
|
|
|
|
local fileconfig = premake.fileconfig
|
2013-09-06 14:23:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Add namespace for element definition lists for premake.callarray()
|
|
|
|
--
|
|
|
|
|
|
|
|
cs.elements = {}
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Generate a GNU make C++ project makefile, with support for the new platforms API.
|
|
|
|
--
|
|
|
|
|
2015-07-27 13:14:32 +00:00
|
|
|
cs.elements.makefile = function(prj)
|
|
|
|
return {
|
|
|
|
make.header,
|
|
|
|
make.phonyRules,
|
|
|
|
make.csConfigs,
|
|
|
|
make.csProjectConfig,
|
|
|
|
make.csSources,
|
|
|
|
make.csEmbedFiles,
|
|
|
|
make.csCopyFiles,
|
|
|
|
make.csResponseFile,
|
|
|
|
make.shellType,
|
|
|
|
make.csAllRules,
|
|
|
|
make.csTargetRules,
|
|
|
|
make.targetDirRules,
|
|
|
|
make.csResponseRules,
|
|
|
|
make.objDirRules,
|
|
|
|
make.csCleanRules,
|
|
|
|
make.preBuildRules,
|
|
|
|
make.preLinkRules,
|
|
|
|
make.csFileRules,
|
|
|
|
}
|
|
|
|
end
|
2012-04-30 20:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Generate a GNU make C# project makefile, with support for the new platforms API.
|
|
|
|
--
|
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.cs.generate(prj)
|
2014-02-08 15:44:57 +00:00
|
|
|
premake.eol("\n")
|
2013-02-25 15:47:22 +00:00
|
|
|
local toolset = premake.tools.dotnet
|
2015-07-27 13:14:32 +00:00
|
|
|
premake.callArray(cs.elements.makefile, prj, toolset)
|
2013-09-06 14:23:17 +00:00
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-27 14:16:42 +00:00
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
--
|
|
|
|
-- Write out the settings for a particular configuration.
|
|
|
|
--
|
2012-09-27 16:18:03 +00:00
|
|
|
|
2015-07-27 13:14:32 +00:00
|
|
|
cs.elements.configuration = function(cfg)
|
|
|
|
return {
|
|
|
|
make.csTools,
|
|
|
|
make.target,
|
|
|
|
make.objdir,
|
|
|
|
make.csFlags,
|
|
|
|
make.csLinkCmd,
|
|
|
|
make.preBuildCmds,
|
|
|
|
make.preLinkCmds,
|
|
|
|
make.postBuildCmds,
|
|
|
|
make.settings,
|
|
|
|
}
|
|
|
|
end
|
2013-09-06 14:23:17 +00:00
|
|
|
|
|
|
|
function make.csConfigs(prj, toolset)
|
2012-09-27 16:18:03 +00:00
|
|
|
for cfg in project.eachconfig(prj) do
|
2013-09-06 14:23:17 +00:00
|
|
|
_x('ifeq ($(config),%s)', cfg.shortname)
|
2015-07-27 13:14:32 +00:00
|
|
|
premake.callArray(cs.elements.configuration, cfg, toolset)
|
2013-09-06 14:23:17 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2012-09-28 16:07:18 +00:00
|
|
|
end
|
2013-09-06 14:23:17 +00:00
|
|
|
end
|
2012-09-28 16:07:18 +00:00
|
|
|
|
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
--
|
|
|
|
-- Given a .resx resource file, builds the path to corresponding .resource
|
|
|
|
-- file, matching the behavior and naming of Visual Studio.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs.getresourcefilename(cfg, fname)
|
|
|
|
if path.getextension(fname) == ".resx" then
|
|
|
|
local name = cfg.buildtarget.basename .. "."
|
|
|
|
local dir = path.getdirectory(fname)
|
|
|
|
if dir ~= "." then
|
|
|
|
name = name .. path.translate(dir, ".") .. "."
|
2012-09-28 16:07:18 +00:00
|
|
|
end
|
2013-09-06 14:23:17 +00:00
|
|
|
return "$(OBJDIR)/" .. premake.esc(name .. path.getbasename(fname)) .. ".resources"
|
|
|
|
else
|
|
|
|
return fname
|
|
|
|
end
|
|
|
|
end
|
2012-09-28 16:07:18 +00:00
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Iterate and output some selection of the source code files.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs.listsources(prj, selector)
|
|
|
|
local tr = project.getsourcetree(prj)
|
|
|
|
premake.tree.traverse(tr, {
|
|
|
|
onleaf = function(node, depth)
|
|
|
|
local value = selector(node)
|
|
|
|
if value then
|
2013-10-17 05:04:23 +00:00
|
|
|
_x('\t%s \\', value)
|
2013-09-06 14:23:17 +00:00
|
|
|
end
|
2012-09-28 16:07:18 +00:00
|
|
|
end
|
2013-09-06 14:23:17 +00:00
|
|
|
})
|
|
|
|
end
|
2012-09-28 16:07:18 +00:00
|
|
|
|
2013-02-25 15:47:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Handlers for individual makefile elements
|
|
|
|
--
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function make.csAllRules(prj, toolset)
|
|
|
|
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)')
|
|
|
|
_p('')
|
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
|
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.csCleanRules(prj, toolset)
|
|
|
|
--[[
|
|
|
|
-- porting from 4.x
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('clean:')
|
|
|
|
_p('\t@echo Cleaning %s', prj.name)
|
|
|
|
_p('ifeq (posix,$(SHELLTYPE))')
|
2012-10-08 22:31:12 +00:00
|
|
|
_p('\t$(SILENT) rm -f $(TARGETDIR)/%s.* $(COPYFILES)', target.basename)
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('\t$(SILENT) rm -rf $(OBJDIR)')
|
|
|
|
_p('else')
|
2012-10-08 22:31:12 +00:00
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGETDIR)/%s) del $(subst /,\\\\,$(TARGETDIR)/%s.*)', target.name, target.basename)
|
2012-09-28 16:07:18 +00:00
|
|
|
for target, source in pairs(cfgpairs[anycfg]) do
|
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,%s) del $(subst /,\\\\,%s)', target, target)
|
|
|
|
end
|
|
|
|
for target, source in pairs(copypairs) do
|
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,%s) del $(subst /,\\\\,%s)', target, target)
|
2012-09-27 16:18:03 +00:00
|
|
|
end
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))')
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2013-09-06 14:23:17 +00:00
|
|
|
--]]
|
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
|
|
|
|
function make.csCopyFiles(prj, toolset)
|
|
|
|
--[[
|
|
|
|
-- copied from 4.x; needs more porting
|
|
|
|
_p('COPYFILES += \\')
|
|
|
|
for target, source in pairs(cfgpairs[anycfg]) do
|
|
|
|
_p('\t%s \\', target)
|
|
|
|
end
|
|
|
|
for target, source in pairs(copypairs) do
|
|
|
|
_p('\t%s \\', target)
|
|
|
|
end
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('')
|
2013-09-06 14:23:17 +00:00
|
|
|
--]]
|
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
|
2014-07-01 20:35:31 +00:00
|
|
|
function make.cs.getresponsefilename(prj)
|
|
|
|
return '$(OBJDIR)/' .. prj.filename .. '.rsp'
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.csResponseFile(prj, toolset)
|
|
|
|
_x('RESPONSE += ' .. make.cs.getresponsefilename(prj))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.csResponseRules(prj)
|
|
|
|
local toolset = premake.tools.dotnet
|
|
|
|
local ext = make.getmakefilename(prj, true)
|
2014-08-11 21:28:51 +00:00
|
|
|
local makefile = path.getname(premake.filename(prj, ext))
|
2015-11-27 23:46:06 +00:00
|
|
|
local response = make.cs.getresponsefilename(prj)
|
2014-07-01 20:35:31 +00:00
|
|
|
|
|
|
|
_p('$(RESPONSE): %s', makefile)
|
|
|
|
_p('\t@echo Generating response file', prj.name)
|
|
|
|
|
|
|
|
_p('ifeq (posix,$(SHELLTYPE))')
|
|
|
|
_x('\t$(SILENT) rm -f $(RESPONSE)')
|
|
|
|
_p('else')
|
2015-11-27 23:46:06 +00:00
|
|
|
_x('\t$(SILENT) if exist $(RESPONSE) del %s', path.translate(response, '\\'))
|
2014-07-01 20:35:31 +00:00
|
|
|
_p('endif')
|
|
|
|
|
2017-04-11 20:39:25 +00:00
|
|
|
local sep = os.istarget("windows") and "\\" or "/"
|
2014-07-01 20:35:31 +00:00
|
|
|
local tr = project.getsourcetree(prj)
|
|
|
|
premake.tree.traverse(tr, {
|
|
|
|
onleaf = function(node, depth)
|
|
|
|
if toolset.fileinfo(node).action == "Compile" then
|
2015-11-27 23:46:06 +00:00
|
|
|
_x('\t@echo %s >> $(RESPONSE)', path.translate(node.relpath, sep))
|
2014-07-01 20:35:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.csEmbedFiles(prj, toolset)
|
|
|
|
local cfg = project.getfirstconfig(prj)
|
|
|
|
|
|
|
|
_p('EMBEDFILES += \\')
|
|
|
|
cs.listsources(prj, function(node)
|
|
|
|
local fcfg = fileconfig.getconfig(node, cfg)
|
|
|
|
local info = toolset.fileinfo(fcfg)
|
|
|
|
if info.action == "EmbeddedResource" then
|
|
|
|
return cs.getresourcefilename(cfg, node.relpath)
|
|
|
|
end
|
|
|
|
end)
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('')
|
2013-09-06 14:23:17 +00:00
|
|
|
end
|
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.csFileRules(prj, toolset)
|
2012-09-28 16:07:18 +00:00
|
|
|
--[[
|
2013-09-06 14:23:17 +00:00
|
|
|
-- porting from 4.x
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('# Per-configuration copied file rules')
|
|
|
|
for cfg in premake.eachconfig(prj) do
|
2013-05-22 15:15:48 +00:00
|
|
|
_x('ifneq (,$(findstring %s,$(config)))', cfg.name:lower())
|
2012-09-28 16:07:18 +00:00
|
|
|
for target, source in pairs(cfgpairs[cfg]) do
|
|
|
|
premake.make_copyrule(source, target)
|
|
|
|
end
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('# Copied file rules')
|
|
|
|
for target, source in pairs(copypairs) do
|
|
|
|
premake.make_copyrule(source, target)
|
|
|
|
end
|
|
|
|
|
|
|
|
_p('# Embedded file rules')
|
2013-02-25 15:47:22 +00:00
|
|
|
for _, fname in ipairs(embedded) do
|
2012-09-28 16:07:18 +00:00
|
|
|
if path.getextension(fname) == ".resx" then
|
2013-05-22 15:15:48 +00:00
|
|
|
_x('%s: %s', getresourcefilename(prj, fname), fname)
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('\t$(SILENT) $(RESGEN) $^ $@')
|
|
|
|
end
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
--]]
|
2012-04-30 20:42:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.csFlags(cfg, toolset)
|
|
|
|
_p(' FLAGS =%s', make.list(toolset.getflags(cfg)))
|
2012-09-28 16:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.csLinkCmd(cfg, toolset)
|
2013-05-22 15:15:48 +00:00
|
|
|
local deps = premake.esc(config.getlinks(cfg, "dependencies", "fullpath"))
|
2013-10-24 15:30:05 +00:00
|
|
|
_p(' DEPENDS =%s', make.list(deps))
|
2012-10-08 22:31:12 +00:00
|
|
|
_p(' REFERENCES = %s', table.implode(deps, "/r:", "", " "))
|
2012-09-28 16:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.csProjectConfig(prj, toolset)
|
|
|
|
-- To maintain compatibility with Visual Studio, these values must
|
|
|
|
-- be set on the project level, and not per-configuration.
|
|
|
|
local cfg = project.getfirstconfig(prj)
|
2012-09-28 16:07:18 +00:00
|
|
|
|
|
|
|
local kindflag = "/t:" .. toolset.getkind(cfg):lower()
|
2013-05-22 15:15:48 +00:00
|
|
|
local libdirs = table.implode(premake.esc(cfg.libdirs), "/lib:", "", " ")
|
2013-09-06 14:23:17 +00:00
|
|
|
_p('FLAGS += %s', table.concat(table.join(kindflag, libdirs), " "))
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2013-05-22 15:15:48 +00:00
|
|
|
local refs = premake.esc(config.getlinks(cfg, "system", "fullpath"))
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('REFERENCES += %s', table.implode(refs, "/r:", "", " "))
|
2013-09-06 14:23:17 +00:00
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.csSources(prj, toolset)
|
|
|
|
local cfg = project.getfirstconfig(prj)
|
|
|
|
|
|
|
|
_p('SOURCES += \\')
|
|
|
|
cs.listsources(prj, function(node)
|
|
|
|
local fcfg = fileconfig.getconfig(node, cfg)
|
|
|
|
local info = toolset.fileinfo(fcfg)
|
|
|
|
if info.action == "Compile" then
|
|
|
|
return node.relpath
|
|
|
|
end
|
|
|
|
end)
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.csTargetRules(prj, toolset)
|
2014-07-01 20:35:31 +00:00
|
|
|
_p('$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS) $(RESPONSE)')
|
|
|
|
_p('\t$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) @$(RESPONSE) $(patsubst %%,/resource:%%,$(EMBEDFILES))')
|
2013-09-06 14:23:17 +00:00
|
|
|
_p('\t$(POSTBUILDCMDS)')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
2012-09-27 16:18:03 +00:00
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
function make.csTools(cfg, toolset)
|
|
|
|
_p(' CSC = %s', toolset.gettoolname(cfg, "csc"))
|
|
|
|
_p(' RESGEN = %s', toolset.gettoolname(cfg, "resgen"))
|
2012-09-27 16:18:03 +00:00
|
|
|
end
|