Simple C# builds and cleans now working

This commit is contained in:
Jason Perkins 2012-09-28 12:07:18 -04:00
parent 27493cd10c
commit 0f56ca513b
8 changed files with 280 additions and 35 deletions

View File

@ -75,6 +75,23 @@
end
--
-- Output logic to detect the shell type at runtime.
--
function make.detectshell()
-- identify the shell type
_p('SHELLTYPE := msdos')
_p('ifeq (,$(ComSpec)$(COMSPEC))')
_p(' SHELLTYPE := posix')
_p('endif')
_p('ifeq (/bin,$(findstring /bin,$(SHELL)))')
_p(' SHELLTYPE := posix')
_p('endif')
_p('')
end
--
-- Escape a string so it can be written to a makefile.
--
@ -192,9 +209,9 @@
end
end
local sysflags = toolset.sysflags[cfg.architecture] or toolset.sysflags[cfg.system] or {}
if sysflags.cfgsettings then
_p(sysflags.cfgsettings)
local value = toolset.getmakesettings(cfg)
if value then
_p(value)
end
end

View File

@ -29,15 +29,7 @@
-- list intermediate files
cpp.objects(prj)
-- identify the shell type
_p('SHELLTYPE := msdos')
_p('ifeq (,$(ComSpec)$(COMSPEC))')
_p(' SHELLTYPE := posix')
_p('endif')
_p('ifeq (/bin,$(findstring /bin,$(SHELL)))')
_p(' SHELLTYPE := posix')
_p('endif')
_p('')
make.detectshell()
-- common build target rules
_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')

View File

@ -8,6 +8,7 @@
local make = premake.make
local cs = premake.make.cs
local project = premake5.project
local config = premake5.config
--
@ -15,6 +16,9 @@
--
function make.generate_csharp(prj)
-- I've only got one .NET toolset right now
local toolset = premake.dotnet
make.header(prj)
-- main build rule(s)
@ -22,9 +26,111 @@
_p('')
for cfg in project.eachconfig(prj) do
cs.config(cfg)
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('')
--]]
make.detectshell()
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)')
_p('')
_p('$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS)')
_p('\t$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) $(SOURCES) $(patsubst %%,/resource:%%,$(EMBEDFILES))')
_p('\t$(POSTBUILDCMDS)')
_p('')
make.mkdirrule("$(TARGETDIR)")
make.mkdirrule("$(OBJDIR)")
-- clean target
local targetbase = firstcfg.buildtarget.basename
_p('clean:')
_p('\t@echo Cleaning %s', prj.name)
_p('ifeq (posix,$(SHELLTYPE))')
_p('\t$(SILENT) rm -f $(TARGETDIR)/%s.* $(COPYFILES)', targetbase)
_p('\t$(SILENT) rm -rf $(OBJDIR)')
_p('else')
_p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGETDIR)/%s.*) del $(subst /,\\\\,$(TARGETDIR)/%s.*)', targetbase, targetbase)
--[[
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)
end
--]]
_p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))')
_p('endif')
_p('')
-- custom build step targets
_p('prebuild:')
_p('\t$(PREBUILDCMDS)')
_p('')
_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
_p('# Copied file rules')
for target, source in pairs(copypairs) do
premake.make_copyrule(source, target)
end
_p('# Embedded file rules')
for _, fname in ipairs(embedded) do
if path.getextension(fname) == ".resx" then
_p('%s: %s', getresourcefilename(prj, fname), _MAKE.esc(fname))
_p('\t$(SILENT) $(RESGEN) $^ $@')
end
_p('')
end
--]]
print("** Warning: GMake C# projects have not been ported yet")
end
@ -33,10 +139,7 @@
-- Write out the settings for a particular configuration.
--
function cs.config(cfg)
-- I've only got one .NET toolset right now
local toolset = premake.dotnet
function cs.config(cfg, toolset)
_p('ifeq ($(config),%s)', make.esc(cfg.shortname))
-- write toolset specific configurations
@ -45,16 +148,11 @@
-- write target information (target dir, name, obj dir)
make.targetconfig(cfg)
--[[
-- write flags
cpp.flags(cfg, toolset)
cs.flags(cfg, toolset)
-- set up precompiled headers
cpp.pchconfig(cfg)
-- write the link step
cpp.linkconfig(cfg, toolset)
-- write the linking information
cs.linking(cfg, toolset)
-- write the custom build commands
_p(' define PREBUILDCMDS')
@ -77,20 +175,94 @@
_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
end
_p(' endef')
_p('')
-- write the target building rule
cpp.targetrules(cfg)
-- write out config-level makesettings blocks
make.settings(cfg, toolset)
--]]
_p('endif')
_p('')
end
--
-- Compile flags
--
function cs.flags(cfg, toolset)
local defines = table.implode(cfg.defines, "/d:", "", " ")
local flags = table.join(defines, toolset.getflags(cfg), cfg.buildoptions)
_p(' FLAGS = %s', table.concat(flags, " "))
end
--
-- 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, ".") .. "."
end
return "$(OBJDIR)/" .. make.esc(name .. path.getbasename(fname)) .. ".resources"
else
return fname
end
end
--
-- Linker arguments
--
function cs.linking(cfg, toolset)
local deps = config.getlinks(cfg, "dependencies", "fullpath")
_p(' DEPENDS = %s', table.concat(make.esc(deps)))
_p(' REFERENCES = ')
--[[
_p(' REFERENCES := %s', table.implode(_MAKE.esc(cfglibs[cfg]), "/r:", "", " "))
--]]
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
})
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()
local libdirs = table.implode(make.esc(cfg.libdirs), "/lib:", "", " ")
_p('FLAGS += %s', table.concat(table.join(kindflag, libdirs), " "))
local refs = make.esc(config.getlinks(cfg, "system", "fullpath"))
_p('REFERENCES += %s', table.implode(refs, "/r:", "", " "))
_p('')
end
--
-- System specific toolset configuration.
--

View File

@ -100,3 +100,12 @@
return "Library"
end
end
--
-- Returns makefile-specific configuration rules.
--
function dotnet.getmakesettings(cfg)
return nil
end

View File

@ -246,6 +246,16 @@
end
--
-- Returns makefile-specific configuration rules.
--
function gcc.getmakesettings(cfg)
local sysflags = gcc.sysflags[cfg.architecture] or gcc.sysflags[cfg.system] or {}
return sysflags.cfgsettings
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment.

View File

@ -132,6 +132,34 @@
end
--
-- Returns makefile-specific configuration rules.
--
function msc.getmakesettings(cfg)
return nil
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment.
--
-- @param cfg
-- The configuration to query.
-- @param tool
-- The tool to fetch, one of "cc" for the C compiler, "cxx" for
-- the C++ compiler, or "ar" for the static linker.
-- @return
-- The executable command name for a tool, or nil if the system's
-- default value should be used.
--
function msc.gettoolname(cfg, tool)
return nil
end
-----------------------------------------------------------------------------
-- Everything below this point is a candidate for deprecation

View File

@ -133,6 +133,15 @@
end
--
-- Returns makefile-specific configuration rules.
--
function ow.getmakesettings(cfg)
return nil
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment.

View File

@ -90,6 +90,14 @@
snc.getlinks = gcc.getlinks
--
-- Returns makefile-specific configuration rules.
--
function snc.getmakesettings(cfg)
return nil
end
--
-- Retrieves the executable command name for a tool, based on the