2009-04-11 11:33:32 +00:00
|
|
|
--
|
|
|
|
-- make_csharp.lua
|
|
|
|
-- Generate a C# project makefile.
|
|
|
|
-- Copyright (c) 2002-2009 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Given a .resx resource file, builds the path to corresponding .resource
|
|
|
|
-- file, matching the behavior and naming of Visual Studio.
|
|
|
|
--
|
|
|
|
|
|
|
|
local function 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
|
2009-05-29 17:45:37 +00:00
|
|
|
return "$(OBJDIR)/" .. _MAKE.esc(name .. path.getbasename(fname)) .. ".resources"
|
2009-04-11 11:33:32 +00:00
|
|
|
else
|
|
|
|
return fname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-05-29 17:45:37 +00:00
|
|
|
|
2009-04-11 11:33:32 +00:00
|
|
|
--
|
|
|
|
-- Main function
|
|
|
|
--
|
|
|
|
|
|
|
|
function premake.make_csharp(prj)
|
2009-05-08 20:18:47 +00:00
|
|
|
local csc = premake.dotnet
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- Do some processing up front: build a list of configuration-dependent libraries.
|
|
|
|
-- Libraries that are built to a location other than $(TARGETDIR) will need to
|
|
|
|
-- be copied so they can be found at runtime.
|
|
|
|
local cfglibs = { }
|
|
|
|
local cfgpairs = { }
|
|
|
|
local anycfg
|
|
|
|
for cfg in premake.eachconfig(prj) do
|
|
|
|
anycfg = cfg
|
|
|
|
cfglibs[cfg] = premake.getlinks(cfg, "siblings", "fullpath")
|
|
|
|
cfgpairs[cfg] = { }
|
|
|
|
for _, fname in ipairs(cfglibs[cfg]) do
|
|
|
|
if path.getdirectory(fname) ~= cfg.buildtarget.directory then
|
2009-05-29 17:45:37 +00:00
|
|
|
cfgpairs[cfg]["$(TARGETDIR)/" .. _MAKE.esc(path.getname(fname))] = _MAKE.esc(fname)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- sort the files into categories, based on their build action
|
|
|
|
local sources = {}
|
|
|
|
local embedded = { }
|
|
|
|
local copypairs = { }
|
|
|
|
|
|
|
|
for fcfg in premake.eachfile(prj) do
|
|
|
|
local action = csc.getbuildaction(fcfg)
|
|
|
|
if action == "Compile" then
|
|
|
|
table.insert(sources, fcfg.name)
|
|
|
|
elseif action == "EmbeddedResource" then
|
|
|
|
table.insert(embedded, fcfg.name)
|
|
|
|
elseif action == "Content" then
|
2009-05-29 17:45:37 +00:00
|
|
|
copypairs["$(TARGETDIR)/" .. _MAKE.esc(path.getname(fcfg.name))] = _MAKE.esc(fcfg.name)
|
2009-04-11 11:33:32 +00:00
|
|
|
elseif path.getname(fcfg.name):lower() == "app.config" then
|
2009-05-29 17:45:37 +00:00
|
|
|
copypairs["$(TARGET).config"] = _MAKE.esc(fcfg.name)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Any assemblies that are on the library search paths should be copied
|
|
|
|
-- to $(TARGETDIR) so they can be found at runtime
|
|
|
|
local paths = table.translate(prj.libdirs, function(v) return path.join(prj.basedir, v) end)
|
|
|
|
paths = table.join({prj.basedir}, paths)
|
|
|
|
for _, libname in ipairs(premake.getlinks(prj, "system", "fullpath")) do
|
|
|
|
local libdir = os.pathsearch(libname..".dll", unpack(paths))
|
|
|
|
if (libdir) then
|
2009-05-29 17:45:37 +00:00
|
|
|
local target = "$(TARGETDIR)/" .. _MAKE.esc(path.getname(libname))
|
2009-04-11 11:33:32 +00:00
|
|
|
local source = path.getrelative(prj.basedir, path.join(libdir, libname))..".dll"
|
2009-05-29 17:45:37 +00:00
|
|
|
copypairs[target] = _MAKE.esc(source)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- end of preprocessing --
|
|
|
|
|
|
|
|
|
|
|
|
-- set up the environment
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('# %s project makefile autogenerated by Premake', premake.actions[_ACTION].shortname)
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('ifndef config')
|
|
|
|
_p(' config=%s', _MAKE.esc(prj.configurations[1]:lower()))
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('ifndef verbose')
|
|
|
|
_p(' SILENT = @')
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('ifndef CSC')
|
|
|
|
_p(' CSC=%s', csc.getcompilervar(prj))
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('ifndef RESGEN')
|
|
|
|
_p(' RESGEN=resgen')
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-14 19:41:30 +00:00
|
|
|
-- Platforms aren't support for .NET projects, but I need the ability to match
|
|
|
|
-- the buildcfg:platform identifiers with a block of settings. So enumerate the
|
|
|
|
-- pairs the same way I do for C/C++ projects, but always use the generic settings
|
|
|
|
local platforms = premake.filterplatforms(prj.solution, premake[_OPTIONS.cc].platforms)
|
|
|
|
table.insert(platforms, 1, "")
|
|
|
|
|
2009-04-11 11:33:32 +00:00
|
|
|
-- write the configuration blocks
|
2009-04-23 18:51:01 +00:00
|
|
|
for cfg in premake.eachconfig(prj) do
|
|
|
|
_p('ifneq (,$(findstring %s,$(config)))', _MAKE.esc(cfg.name:lower()))
|
|
|
|
_p(' TARGETDIR := %s', _MAKE.esc(cfg.buildtarget.directory))
|
|
|
|
_p(' OBJDIR := %s', _MAKE.esc(cfg.objectsdir))
|
|
|
|
_p(' DEPENDS := %s', table.concat(_MAKE.esc(premake.getlinks(cfg, "dependencies", "fullpath")), " "))
|
|
|
|
_p(' REFERENCES := %s', table.implode(_MAKE.esc(cfglibs[cfg]), "/r:", "", " "))
|
|
|
|
_p(' FLAGS += %s %s', table.concat(csc.getflags(cfg), " "), table.implode(cfg.defines, "/d:", "", " "))
|
|
|
|
|
|
|
|
_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')
|
|
|
|
|
|
|
|
_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')
|
|
|
|
|
|
|
|
_p(' define POSTBUILDCMDS')
|
|
|
|
if #cfg.postbuildcommands > 0 then
|
|
|
|
_p('\t@echo Running post-build commands')
|
|
|
|
_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-23 18:51:01 +00:00
|
|
|
_p(' endef')
|
|
|
|
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- set project level values
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('# To maintain compatibility with VS.NET, these values must be set at the project level')
|
2009-04-23 18:51:01 +00:00
|
|
|
_p('TARGET := $(TARGETDIR)/%s', _MAKE.esc(prj.buildtarget.name))
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('FLAGS += /t:%s %s', csc.getkind(prj):lower(), table.implode(_MAKE.esc(prj.libdirs), "/lib:", "", " "))
|
|
|
|
_p('REFERENCES += %s', table.implode(_MAKE.esc(premake.getlinks(prj, "system", "basename")), "/r:", ".dll", " "))
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- list source files
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('SOURCES := \\')
|
2009-04-11 11:33:32 +00:00
|
|
|
for _, fname in ipairs(sources) do
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\t%s \\', _MAKE.esc(path.translate(fname)))
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('EMBEDFILES := \\')
|
2009-04-11 11:33:32 +00:00
|
|
|
for _, fname in ipairs(embedded) do
|
2009-05-29 17:45:37 +00:00
|
|
|
_p('\t%s \\', getresourcefilename(prj, fname))
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('COPYFILES += \\')
|
2009-04-11 11:33:32 +00:00
|
|
|
for target, source in pairs(cfgpairs[anycfg]) do
|
2009-05-29 17:45:37 +00:00
|
|
|
_p('\t%s \\', target)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
for target, source in pairs(copypairs) do
|
2009-05-29 17:45:37 +00:00
|
|
|
_p('\t%s \\', target)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-05-29 17:45:37 +00:00
|
|
|
-- identify the shell type
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('SHELLTYPE := msdos')
|
|
|
|
_p('ifeq (,$(ComSpec)$(COMSPEC))')
|
|
|
|
_p(' SHELLTYPE := posix')
|
|
|
|
_p('endif')
|
|
|
|
_p('ifeq (/bin,$(findstring /bin,$(SHELL)))')
|
|
|
|
_p(' SHELLTYPE := posix')
|
|
|
|
_p('endif')
|
2009-05-29 17:45:37 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- main build rule(s)
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('.PHONY: clean prebuild prelink')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS)')
|
|
|
|
_p('\t$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) $(SOURCES) $(patsubst %%,/resource:%%,$(EMBEDFILES))')
|
|
|
|
_p('\t$(POSTBUILDCMDS)')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-05-29 17:45:37 +00:00
|
|
|
-- Create destination directories. Can't use $@ for this because it loses the
|
|
|
|
-- escaping, causing issues with spaces and parenthesis
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('$(TARGETDIR):')
|
2009-05-29 17:45:37 +00:00
|
|
|
premake.make_mkdirrule("$(TARGETDIR)")
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('$(OBJDIR):')
|
2009-05-29 17:45:37 +00:00
|
|
|
premake.make_mkdirrule("$(OBJDIR)")
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- clean target
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('clean:')
|
|
|
|
_p('\t@echo Cleaning %s', prj.name)
|
|
|
|
_p('ifeq (posix,$(SHELLTYPE))')
|
|
|
|
_p('\t$(SILENT) rm -f $(TARGETDIR)/%s.* $(COPYFILES)', prj.buildtarget.basename)
|
|
|
|
_p('\t$(SILENT) rm -rf $(OBJDIR)')
|
|
|
|
_p('else')
|
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGETDIR)/%s.*) del $(subst /,\\\\,$(TARGETDIR)/%s.*)', prj.buildtarget.basename, prj.buildtarget.basename)
|
2009-04-11 11:33:32 +00:00
|
|
|
for target, source in pairs(cfgpairs[anycfg]) do
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,%s) del $(subst /,\\\\,%s)', target, target)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
for target, source in pairs(copypairs) do
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,%s) del $(subst /,\\\\,%s)', target, target)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))')
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- custom build step targets
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('prebuild:')
|
|
|
|
_p('\t$(PREBUILDCMDS)')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('prelink:')
|
|
|
|
_p('\t$(PRELINKCMDS)')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- per-file rules
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('# Per-configuration copied file rules')
|
2009-04-11 11:33:32 +00:00
|
|
|
for cfg in premake.eachconfig(prj) do
|
2009-04-23 18:53:35 +00:00
|
|
|
_p('ifneq (,$(findstring %s,$(config)))', _MAKE.esc(cfg.name:lower()))
|
2009-04-11 11:33:32 +00:00
|
|
|
for target, source in pairs(cfgpairs[cfg]) do
|
2009-05-29 17:45:37 +00:00
|
|
|
premake.make_copyrule(source, target)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('endif')
|
2009-06-02 19:40:59 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('# Copied file rules')
|
2009-04-11 11:33:32 +00:00
|
|
|
for target, source in pairs(copypairs) do
|
2009-05-29 17:45:37 +00:00
|
|
|
premake.make_copyrule(source, target)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('# Embedded file rules')
|
2009-04-11 11:33:32 +00:00
|
|
|
for _, fname in ipairs(embedded) do
|
|
|
|
if path.getextension(fname) == ".resx" then
|
2009-05-29 17:45:37 +00:00
|
|
|
_p('%s: %s', getresourcefilename(prj, fname), _MAKE.esc(fname))
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\t$(SILENT) $(RESGEN) $^ $@')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|