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
|
2012-09-27 16:18:03 +00:00
|
|
|
local project = premake5.project
|
2012-09-28 16:07:18 +00:00
|
|
|
local config = premake5.config
|
2012-04-30 20:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Generate a GNU make C# project makefile, with support for the new platforms API.
|
|
|
|
--
|
|
|
|
|
|
|
|
function make.generate_csharp(prj)
|
2012-09-28 16:07:18 +00:00
|
|
|
-- I've only got one .NET toolset right now
|
2013-02-25 15:47:22 +00:00
|
|
|
local toolset = premake.tools.dotnet
|
|
|
|
|
2012-09-27 14:16:42 +00:00
|
|
|
make.header(prj)
|
|
|
|
|
2012-09-27 16:18:03 +00:00
|
|
|
-- main build rule(s)
|
|
|
|
_p('.PHONY: clean prebuild prelink')
|
|
|
|
_p('')
|
|
|
|
|
|
|
|
for cfg in project.eachconfig(prj) do
|
2012-09-28 16:07:18 +00:00
|
|
|
cs.config(cfg, toolset)
|
|
|
|
end
|
|
|
|
|
|
|
|
local firstcfg = project.getfirstconfig(prj)
|
|
|
|
cs.prj_config(firstcfg, toolset)
|
|
|
|
|
|
|
|
-- list source files
|
|
|
|
_p('SOURCES += \\')
|
|
|
|
cs.listsources(prj, function(node)
|
|
|
|
if toolset.getbuildaction(node) == "Compile" then
|
|
|
|
return node.relpath
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
_p('')
|
|
|
|
|
|
|
|
_p('EMBEDFILES += \\')
|
|
|
|
cs.listsources(prj, function(node)
|
|
|
|
if toolset.getbuildaction(node) == "EmbeddedResource" then
|
|
|
|
return cs.getresourcefilename(firstcfg, node.relpath)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
_p('')
|
|
|
|
|
|
|
|
--[[
|
|
|
|
_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
|
|
|
|
_p('')
|
|
|
|
--]]
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
make.detectshell()
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)')
|
|
|
|
_p('')
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS)')
|
|
|
|
_p('\t$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) $(SOURCES) $(patsubst %%,/resource:%%,$(EMBEDFILES))')
|
|
|
|
_p('\t$(POSTBUILDCMDS)')
|
|
|
|
_p('')
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
make.mkdirrule("$(TARGETDIR)")
|
|
|
|
make.mkdirrule("$(OBJDIR)")
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
-- clean target
|
2012-10-08 22:31:12 +00:00
|
|
|
local target = firstcfg.buildtarget
|
2013-02-25 15:47:22 +00:00
|
|
|
|
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-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
-- custom build step targets
|
|
|
|
_p('prebuild:')
|
|
|
|
_p('\t$(PREBUILDCMDS)')
|
|
|
|
_p('')
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('prelink:')
|
|
|
|
_p('\t$(PRELINKCMDS)')
|
|
|
|
_p('')
|
|
|
|
|
|
|
|
--[[
|
|
|
|
-- per-file rules
|
|
|
|
_p('# Per-configuration copied file rules')
|
|
|
|
for cfg in premake.eachconfig(prj) do
|
|
|
|
_p('ifneq (,$(findstring %s,$(config)))', _MAKE.esc(cfg.name:lower()))
|
|
|
|
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
|
|
|
|
_p('%s: %s', getresourcefilename(prj, fname), _MAKE.esc(fname))
|
|
|
|
_p('\t$(SILENT) $(RESGEN) $^ $@')
|
|
|
|
end
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
--]]
|
2012-04-30 20:42:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-09-27 16:18:03 +00:00
|
|
|
--
|
|
|
|
-- Write out the settings for a particular configuration.
|
|
|
|
--
|
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
function cs.config(cfg, toolset)
|
2012-09-27 16:18:03 +00:00
|
|
|
_p('ifeq ($(config),%s)', make.esc(cfg.shortname))
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-27 16:18:03 +00:00
|
|
|
-- write toolset specific configurations
|
|
|
|
cs.toolconfig(cfg, toolset)
|
2012-09-28 14:35:13 +00:00
|
|
|
|
|
|
|
-- write target information (target dir, name, obj dir)
|
|
|
|
make.targetconfig(cfg)
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 14:35:13 +00:00
|
|
|
-- write flags
|
2012-09-28 16:07:18 +00:00
|
|
|
cs.flags(cfg, toolset)
|
2012-09-28 14:35:13 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
-- write the linking information
|
|
|
|
cs.linking(cfg, toolset)
|
2012-09-28 14:35:13 +00:00
|
|
|
|
2013-02-25 15:47:22 +00:00
|
|
|
-- write the custom build commands
|
2012-09-28 14:35:13 +00:00
|
|
|
_p(' define PREBUILDCMDS')
|
|
|
|
if #cfg.prebuildcommands > 0 then
|
|
|
|
_p('\t@echo Running pre-build commands')
|
|
|
|
_p('\t%s', table.implode(cfg.prebuildcommands, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 14:35:13 +00:00
|
|
|
_p(' define PRELINKCMDS')
|
|
|
|
if #cfg.prelinkcommands > 0 then
|
|
|
|
_p('\t@echo Running pre-link commands')
|
|
|
|
_p('\t%s', table.implode(cfg.prelinkcommands, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 14:35:13 +00:00
|
|
|
_p(' define POSTBUILDCMDS')
|
|
|
|
if #cfg.postbuildcommands > 0 then
|
|
|
|
_p('\t@echo Running post-build commands')
|
|
|
|
_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 14:35:13 +00:00
|
|
|
-- write out config-level makesettings blocks
|
|
|
|
make.settings(cfg, toolset)
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-27 16:18:03 +00:00
|
|
|
_p('endif')
|
2013-02-25 15:47:22 +00:00
|
|
|
_p('')
|
2012-09-27 16:18:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
--
|
|
|
|
-- Compile flags
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs.flags(cfg, toolset)
|
2013-02-25 15:47:22 +00:00
|
|
|
_p(' FLAGS =%s', make.list(toolset.getflags(cfg)))
|
2012-09-28 16:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Given a .resx resource file, builds the path to corresponding .resource
|
|
|
|
-- file, matching the behavior and naming of Visual Studio.
|
|
|
|
--
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
function cs.getresourcefilename(cfg, fname)
|
|
|
|
if path.getextension(fname) == ".resx" then
|
|
|
|
local name = cfg.buildtarget.basename .. "."
|
|
|
|
local dir = path.getdirectory(fname)
|
2013-02-25 15:47:22 +00:00
|
|
|
if dir ~= "." then
|
2012-09-28 16:07:18 +00:00
|
|
|
name = name .. path.translate(dir, ".") .. "."
|
|
|
|
end
|
|
|
|
return "$(OBJDIR)/" .. make.esc(name .. path.getbasename(fname)) .. ".resources"
|
|
|
|
else
|
|
|
|
return fname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Linker arguments
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs.linking(cfg, toolset)
|
2012-10-08 22:31:12 +00:00
|
|
|
local deps = make.esc(config.getlinks(cfg, "dependencies", "fullpath"))
|
|
|
|
_p(' DEPENDS = %s', table.concat(deps))
|
|
|
|
_p(' REFERENCES = %s', table.implode(deps, "/r:", "", " "))
|
2012-09-28 16:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- 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
|
|
|
|
_p('\t%s \\', make.esc(path.translate(value)))
|
|
|
|
end
|
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
})
|
2012-09-28 16:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- To maintain compatibility with Visual Studio, these values must
|
|
|
|
-- be set on the project level, and not per-configuration.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs.prj_config(cfg, toolset)
|
|
|
|
local kindflag = "/t:" .. toolset.getkind(cfg):lower()
|
2013-02-25 15:47:22 +00:00
|
|
|
local libdirs = table.implode(make.esc(cfg.libdirs), "/lib:", "", " ")
|
2012-09-28 16:07:18 +00:00
|
|
|
_p('FLAGS += %s', table.concat(table.join(kindflag, libdirs), " "))
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-09-28 16:07:18 +00:00
|
|
|
local refs = make.esc(config.getlinks(cfg, "system", "fullpath"))
|
|
|
|
_p('REFERENCES += %s', table.implode(refs, "/r:", "", " "))
|
|
|
|
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-09-27 16:18:03 +00:00
|
|
|
--
|
|
|
|
-- System specific toolset configuration.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs.toolconfig(cfg, toolset)
|
2012-09-28 14:35:13 +00:00
|
|
|
_p(' CSC = %s', toolset.gettoolname(cfg, "csc"))
|
|
|
|
_p(' RESGEN = %s', toolset.gettoolname(cfg, "resgen"))
|
2012-09-27 16:18:03 +00:00
|
|
|
end
|