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.
|
|
|
|
--
|
|
|
|
|
|
|
|
cs.elements.makefile = {
|
|
|
|
"header",
|
|
|
|
"phonyRules",
|
|
|
|
"csConfigs",
|
|
|
|
"csProjectConfig",
|
|
|
|
"csSources",
|
|
|
|
"csEmbedFiles",
|
|
|
|
"csCopyFiles",
|
|
|
|
"shellType",
|
|
|
|
"csAllRules",
|
|
|
|
"csTargetRules",
|
|
|
|
"targetDirRules",
|
|
|
|
"objDirRules",
|
|
|
|
"csCleanRules",
|
|
|
|
"preBuildRules",
|
|
|
|
"preLinkRules",
|
|
|
|
"csFileRules",
|
|
|
|
}
|
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
|
2013-09-06 14:23:17 +00:00
|
|
|
premake.callarray(make, cs.elements.makefile, prj, toolset)
|
|
|
|
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
|
|
|
|
2013-09-06 14:23:17 +00:00
|
|
|
cs.elements.configuration = {
|
|
|
|
"csTools",
|
|
|
|
"target",
|
|
|
|
"objdir",
|
|
|
|
"csFlags",
|
|
|
|
"csLinkCmd",
|
|
|
|
"preBuildCmds",
|
|
|
|
"preLinkCmds",
|
|
|
|
"postBuildCmds",
|
|
|
|
"settings",
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
premake.callarray(make, cs.elements.configuration, cfg, toolset)
|
|
|
|
_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
|
|
|
|
|
|
|
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)
|
|
|
|
_p('$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS)')
|
|
|
|
_p('\t$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) $(SOURCES) $(patsubst %%,/resource:%%,$(EMBEDFILES))')
|
|
|
|
_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
|