Initial community commit

This commit is contained in:
Jef 2024-09-24 14:54:57 +02:00
parent 537bcbc862
commit fc06254474
16440 changed files with 4239995 additions and 2 deletions

View file

@ -0,0 +1,9 @@
return {
"_preload.lua",
"gmake.lua",
"gmake_cpp.lua",
"gmake_csharp.lua",
"gmake_makefile.lua",
"gmake_utility.lua",
"gmake_workspace.lua",
}

View file

@ -0,0 +1,64 @@
--
-- _preload.lua
-- Define the makefile action(s).
-- Copyright (c) 2002-2015 Jason Perkins and the Premake project
--
local p = premake
local project = p.project
---
-- The GNU make action, with support for the new platforms API
---
newaction {
trigger = "gmake",
shortname = "GNU Make",
description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin",
toolset = "gcc",
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile" },
valid_languages = { "C", "C++", "C#" },
valid_tools = {
cc = { "clang", "gcc" },
dotnet = { "mono", "msnet", "pnet" }
},
onWorkspace = function(wks)
p.escaper(p.make.esc)
p.generate(wks, p.make.getmakefilename(wks, false), p.make.generate_workspace)
end,
onProject = function(prj)
p.escaper(p.make.esc)
local makefile = p.make.getmakefilename(prj, true)
if prj.kind == p.UTILITY then
p.generate(prj, makefile, p.make.utility.generate)
elseif prj.kind == p.MAKEFILE then
p.generate(prj, makefile, p.make.makefile.generate)
else
if project.isdotnet(prj) then
p.generate(prj, makefile, p.make.cs.generate)
elseif project.isc(prj) or project.iscpp(prj) then
p.generate(prj, makefile, p.make.cpp.generate)
end
end
end,
onCleanWorkspace = function(wks)
p.clean.file(wks, p.make.getmakefilename(wks, false))
end,
onCleanProject = function(prj)
p.clean.file(prj, p.make.getmakefilename(prj, true))
end
}
--
-- Decide when the full module should be loaded.
--
return function(cfg)
return (_ACTION == "gmake")
end

View file

@ -0,0 +1,302 @@
--
-- gmake.lua
-- Define the makefile action(s).
-- Copyright (c) 2002-2015 Jason Perkins and the Premake project
--
local p = premake
p.modules.gmake = {}
p.modules.gmake._VERSION = p._VERSION
-- for backwards compatibility.
p.make = p.modules.gmake
local make = p.make
local project = p.project
--
-- Write out the default configuration rule for a workspace or project.
--
-- @param target
-- The workspace or project object for which a makefile is being generated.
--
function make.defaultconfig(target)
-- find the right configuration iterator function for this object
local eachconfig = iif(target.project, project.eachconfig, p.workspace.eachconfig)
local defaultconfig = nil
-- find the right default configuration platform, grab first configuration that matches
if target.defaultplatform then
for cfg in eachconfig(target) do
if cfg.platform == target.defaultplatform then
defaultconfig = cfg
break
end
end
end
-- grab the first configuration and write the block
if not defaultconfig then
local iter = eachconfig(target)
defaultconfig = iter()
end
if defaultconfig then
_p('ifndef config')
_x(' config=%s', defaultconfig.shortname)
_p('endif')
_p('')
end
end
---
-- Escape a string so it can be written to a makefile.
---
function make.esc(value)
result = value:gsub("\\", "\\\\")
result = result:gsub("\"", "\\\"")
result = result:gsub(" ", "\\ ")
result = result:gsub("%(", "\\(")
result = result:gsub("%)", "\\)")
-- leave $(...) shell replacement sequences alone
result = result:gsub("$\\%((.-)\\%)", "$(%1)")
return result
end
--
-- Get the makefile file name for a workspace or a project. If this object is the
-- only one writing to a location then I can use "Makefile". If more than one object
-- writes to the same location I use name + ".make" to keep it unique.
--
function make.getmakefilename(this, searchprjs)
local count = 0
for wks in p.global.eachWorkspace() do
if wks.location == this.location then
count = count + 1
end
if searchprjs then
for _, prj in ipairs(wks.projects) do
if prj.location == this.location then
count = count + 1
end
end
end
end
if count == 1 then
return "Makefile"
else
return ".make"
end
end
--
-- Output a makefile header.
--
-- @param target
-- The workspace or project object for which the makefile is being generated.
--
function make.header(target)
local kind = iif(target.project, "project", "workspace")
_p('# %s %s makefile autogenerated by Premake', p.action.current().shortname, kind)
_p('')
if kind == "workspace" then
local haspch = false
for _, prj in ipairs(target.projects) do
for cfg in project.eachconfig(prj) do
if cfg.pchheader then
haspch = true
end
end
end
if haspch then
_p('.NOTPARALLEL:')
_p('')
end
end
make.defaultconfig(target)
_p('ifndef verbose')
_p(' SILENT = @')
_p('endif')
_p('')
end
--
-- Rules for file ops based on the shell type. Can't use defines and $@ because
-- it screws up the escaping of spaces and parethesis (anyone know a fix?)
--
function make.mkdir(dirname)
_p('ifeq (posix,$(SHELLTYPE))')
_p('\t$(SILENT) mkdir -p %s', dirname)
_p('else')
_p('\t$(SILENT) mkdir $(subst /,\\\\,%s)', dirname)
_p('endif')
end
function make.mkdirRules(dirname)
_p('%s:', dirname)
_p('\t@echo Creating %s', dirname)
make.mkdir(dirname)
_p('')
end
--
-- Format a list of values to be safely written as part of a variable assignment.
--
function make.list(value, quoted)
quoted = false
if #value > 0 then
if quoted then
local result = ""
for _, v in ipairs (value) do
if #result then
result = result .. " "
end
result = result .. p.quoted(v)
end
return result
else
return " " .. table.concat(value, " ")
end
else
return ""
end
end
--
-- Convert an arbitrary string (project name) to a make variable name.
--
function make.tovar(value)
value = value:gsub("[ -]", "_")
value = value:gsub("[()]", "")
return value
end
---------------------------------------------------------------------------
--
-- Handlers for the individual makefile elements that can be shared
-- between the different language projects.
--
---------------------------------------------------------------------------
function make.objdir(cfg)
_x(' OBJDIR = %s', p.esc(project.getrelative(cfg.project, cfg.objdir)))
end
function make.objDirRules(prj)
make.mkdirRules("$(OBJDIR)")
end
function make.phonyRules(prj)
_p('.PHONY: clean prebuild prelink')
_p('')
end
function make.buildCmds(cfg, event)
_p(' define %sCMDS', event:upper())
local steps = cfg[event .. "commands"]
local msg = cfg[event .. "message"]
if #steps > 0 then
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
msg = msg or string.format("Running %s commands", event)
_p('\t@echo %s', msg)
_p('\t%s', table.implode(steps, "", "", "\n\t"))
end
_p(' endef')
end
function make.preBuildCmds(cfg, toolset)
make.buildCmds(cfg, "prebuild")
end
function make.preBuildRules(prj)
_p('prebuild:')
_p('\t$(PREBUILDCMDS)')
_p('')
end
function make.preLinkCmds(cfg, toolset)
make.buildCmds(cfg, "prelink")
end
function make.preLinkRules(prj)
_p('prelink:')
_p('\t$(PRELINKCMDS)')
_p('')
end
function make.postBuildCmds(cfg, toolset)
make.buildCmds(cfg, "postbuild")
end
function make.settings(cfg, toolset)
if #cfg.makesettings > 0 then
for _, value in ipairs(cfg.makesettings) do
_p(value)
end
end
local value = toolset.getmakesettings(cfg)
if value then
_p(value)
end
end
function make.shellType()
_p('SHELLTYPE := posix')
_p('ifeq (.exe,$(findstring .exe,$(ComSpec)))')
_p('\tSHELLTYPE := msdos')
_p('endif')
_p('')
end
function make.target(cfg)
_x(' TARGETDIR = %s', project.getrelative(cfg.project, cfg.buildtarget.directory))
_x(' TARGET = $(TARGETDIR)/%s', cfg.buildtarget.name)
end
function make.targetDirRules(prj)
make.mkdirRules("$(TARGETDIR)")
end
include("gmake_cpp.lua")
include("gmake_csharp.lua")
include("gmake_makefile.lua")
include("gmake_utility.lua")
include("gmake_workspace.lua")
return p.modules.gmake

View file

@ -0,0 +1,599 @@
--
-- make_cpp.lua
-- Generate a C/C++ project makefile.
-- Copyright (c) 2002-2014 Jason Perkins and the Premake project
--
local p = premake
p.make.cpp = {}
local make = p.make
local cpp = p.make.cpp
local project = p.project
local config = p.config
local fileconfig = p.fileconfig
---
-- Add namespace for element definition lists for p.callarray()
---
cpp.elements = {}
--
-- Generate a GNU make C++ project makefile, with support for the new platforms API.
--
cpp.elements.makefile = function(prj)
return {
make.header,
make.phonyRules,
make.cppConfigs,
make.cppObjects,
make.shellType,
make.cppTargetRules,
make.cppCustomFilesRules,
make.cppTargetDirRules,
make.cppObjDirRules,
make.cppCleanRules,
make.preBuildRules,
make.preLinkRules,
make.pchRules,
make.cppFileRules,
make.cppDependencies,
}
end
-- should be part of the toolset?
function make.fileTypeExtensions()
return {
["objects"] = "o",
["resources"] = "res",
}
end
-- should be part of the toolset?
function make.fileType(node)
local kind
if path.iscppfile(node.abspath) then
kind = "objects"
elseif path.isresourcefile(node.abspath) then
kind = "resources"
end
return kind
end
function make.fileDependency(prj, node)
local filetype = make.fileType(node)
_x('$(OBJDIR)/%s.%s: %s', node.objname, make.fileTypeExtensions()[filetype], node.relpath)
_p('\t@echo $(notdir $<)')
end
function make.cpp.generate(prj)
p.eol("\n")
p.callArray(cpp.elements.makefile, prj)
end
--
-- Write out the commands for compiling a file
--
cpp.elements.standardFileRules = function(prj, node)
return {
make.fileDependency,
cpp.standardFileRules,
}
end
cpp.elements.customFileRules = function(prj, node)
return {
make.fileDependency,
cpp.customFileRules,
}
end
cpp.elements.customBuildRules = function(prj, node)
return {
cpp.customFileRules
}
end
--
-- Write out the settings for a particular configuration.
--
cpp.elements.configuration = function(cfg, toolset)
return {
make.configBegin,
make.cppTools,
make.target,
make.objdir,
make.pch,
make.defines,
make.includes,
make.forceInclude,
make.cppFlags,
make.cFlags,
make.cxxFlags,
make.resFlags,
make.libs,
make.ldDeps,
make.ldFlags,
make.linkCmd,
make.exePaths,
make.preBuildCmds,
make.preLinkCmds,
make.postBuildCmds,
make.cppAllRules,
make.settings,
make.configEnd,
}
end
function make.cppConfigs(prj)
for cfg in project.eachconfig(prj) do
-- identify the toolset used by this configurations (would be nicer if
-- this were computed and stored with the configuration up front)
local toolset = p.tools[_OPTIONS.cc or cfg.toolset or "gcc"]
if not toolset then
error("Invalid toolset '" .. cfg.toolset .. "'")
end
p.callArray(cpp.elements.configuration, cfg, toolset)
_p('')
end
end
function make.exePaths(cfg)
local dirs = project.getrelative(cfg.project, cfg.bindirs)
if #dirs > 0 then
_p(' EXECUTABLE_PATHS = "%s"', table.concat(dirs, ":"))
_p(' EXE_PATHS = export PATH=$(EXECUTABLE_PATHS):$$PATH;')
end
end
--
-- Return the start of the compilation string that corresponds to the 'compileas' enum if set
--
function cpp.compileas(prj, node)
local result
if node["compileas"] then
if p.languages.isc(node.compileas) or node.compileas == p.OBJECTIVEC then
result = '$(CC) $(ALL_CFLAGS)'
elseif p.languages.iscpp(node.compileas) or node.compileas == p.OBJECTIVECPP then
result = '$(CXX) $(ALL_CXXFLAGS)'
end
end
return result
end
--
-- Build command for a single file.
--
function cpp.buildcommand(prj, objext, node)
local flags = cpp.compileas(prj, node)
if not flags then
local iscfile = node and path.iscfile(node.abspath) or false
flags = iif(prj.language == "C" or iscfile, '$(CC) $(ALL_CFLAGS)', '$(CXX) $(ALL_CXXFLAGS)')
end
_p('\t$(SILENT) %s $(FORCE_INCLUDE) -o "$@" -MF "$(@:%%.%s=%%.d)" -c "$<"', flags, objext)
end
--
-- Output the list of file building rules.
--
function make.cppFileRules(prj)
local tr = project.getsourcetree(prj)
p.tree.traverse(tr, {
onleaf = function(node, depth)
-- check to see if this file has custom rules
local rules
for cfg in project.eachconfig(prj) do
local filecfg = fileconfig.getconfig(node, cfg)
if fileconfig.hasCustomBuildRule(filecfg) then
rules = cpp.elements.customBuildRules(prj, node)
break
end
if fileconfig.hasFileSettings(filecfg) then
rules = cpp.elements.customFileRules(prj, node)
break
end
end
if not rules and make.fileType(node) then
rules = cpp.elements.standardFileRules(prj, node)
end
if rules then
p.callArray(rules, prj, node)
end
end
})
_p('')
end
function cpp.standardFileRules(prj, node)
local kind = make.fileType(node)
-- C/C++ file
if kind == "objects" then
cpp.buildcommand(prj, make.fileTypeExtensions()[kind], node)
-- resource file
elseif kind == "resources" then
_p('\t$(SILENT) $(RESCOMP) $< -O coff -o "$@" $(ALL_RESFLAGS)')
end
end
function cpp.customFileRules(prj, node)
for cfg in project.eachconfig(prj) do
local filecfg = fileconfig.getconfig(node, cfg)
if filecfg then
make.configBegin(cfg)
if fileconfig.hasCustomBuildRule(filecfg) then
local output = project.getrelative(prj, filecfg.buildoutputs[1])
local dependencies = filecfg.relpath
if filecfg.buildinputs and #filecfg.buildinputs > 0 then
local inputs = project.getrelative(prj, filecfg.buildinputs)
dependencies = dependencies .. " " .. table.concat(p.esc(inputs), " ")
end
_p('%s: %s', output, dependencies)
_p('\t@echo "%s"', filecfg.buildmessage or ("Building " .. filecfg.relpath))
local cmds = os.translateCommandsAndPaths(filecfg.buildcommands, cfg.project.basedir, cfg.project.location)
for _, cmd in ipairs(cmds) do
if cfg.bindirs and #cfg.bindirs > 0 then
_p('\t$(SILENT) $(EXE_PATHS) %s', cmd)
else
_p('\t$(SILENT) %s', cmd)
end
end
else
cpp.standardFileRules(prj, filecfg)
end
make.configEnd(cfg)
end
end
end
--
-- List the objects file for the project, and each configuration.
--
function make.cppObjects(prj)
-- create lists for intermediate files, at the project level and
-- for each configuration
local root = { objects={}, resources={}, customfiles={} }
local configs = {}
for cfg in project.eachconfig(prj) do
configs[cfg] = { objects={}, resources={}, customfiles={} }
end
-- now walk the list of files in the project
local tr = project.getsourcetree(prj)
p.tree.traverse(tr, {
onleaf = function(node, depth)
-- figure out what configurations contain this file, and
-- if it uses custom build rules
local incfg = {}
local inall = true
local custom = false
for cfg in project.eachconfig(prj) do
local filecfg = fileconfig.getconfig(node, cfg)
if filecfg and not filecfg.flags.ExcludeFromBuild then
incfg[cfg] = filecfg
custom = fileconfig.hasCustomBuildRule(filecfg)
else
inall = false
end
end
if not custom then
-- identify the file type
local kind
if path.iscppfile(node.abspath) then
kind = "objects"
elseif path.isresourcefile(node.abspath) then
kind = "resources"
end
-- skip files that aren't compiled
if not custom and not kind then
return
end
-- assign a unique object file name to avoid collisions
objectname = "$(OBJDIR)/" .. node.objname .. iif(kind == "objects", ".o", ".res")
-- if this file exists in all configurations, write it to
-- the project's list of files, else add to specific cfgs
if inall then
table.insert(root[kind], objectname)
else
for cfg in project.eachconfig(prj) do
if incfg[cfg] then
table.insert(configs[cfg][kind], objectname)
end
end
end
else
for cfg in project.eachconfig(prj) do
local filecfg = incfg[cfg]
if filecfg then
local output = project.getrelative(prj, filecfg.buildoutputs[1])
if path.isobjectfile(output) and (filecfg.linkbuildoutputs == true or filecfg.linkbuildoutputs == nil) then
table.insert(configs[cfg].objects, output)
else
table.insert(configs[cfg].customfiles, output)
end
end
end
end
end
})
-- now I can write out the lists, project level first...
function listobjects(var, list)
_p('%s \\', var)
for _, objectname in ipairs(list) do
_x('\t%s \\', objectname)
end
_p('')
end
listobjects('OBJECTS :=', root.objects, 'o')
listobjects('RESOURCES :=', root.resources, 'res')
listobjects('CUSTOMFILES :=', root.customfiles)
-- ...then individual configurations, as needed
for cfg in project.eachconfig(prj) do
local files = configs[cfg]
if #files.objects > 0 or #files.resources > 0 or #files.customfiles > 0 then
make.configBegin(cfg, toolset)
if #files.objects > 0 then
listobjects(' OBJECTS +=', files.objects)
end
if #files.resources > 0 then
listobjects(' RESOURCES +=', files.resources)
end
if #files.customfiles > 0 then
listobjects(' CUSTOMFILES +=', files.customfiles)
end
make.configEnd(cfg, toolset)
_p('')
end
end
end
---------------------------------------------------------------------------
--
-- Handlers for individual makefile elements
--
---------------------------------------------------------------------------
function make.configBegin(cfg, toolset)
if cfg then
_x('ifeq ($(config),%s)', cfg.shortname)
end
end
function make.configEnd(cfg, toolset)
if cfg then
_p('endif')
end
end
function make.cFlags(cfg, toolset)
_p(' ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS)%s', make.list(table.join(toolset.getcflags(cfg), cfg.buildoptions)))
end
function make.cppAllRules(cfg, toolset)
if cfg.system == p.MACOSX and cfg.kind == p.WINDOWEDAPP then
_p('all: prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
_p('\t@:')
_p('')
_p('$(dir $(TARGETDIR))PkgInfo:')
_p('$(dir $(TARGETDIR))Info.plist:')
else
_p('all: prebuild prelink $(TARGET)')
_p('\t@:')
end
end
function make.cppFlags(cfg, toolset)
_p(' ALL_CPPFLAGS += $(CPPFLAGS)%s $(DEFINES) $(INCLUDES)', make.list(toolset.getcppflags(cfg)))
end
function make.cxxFlags(cfg, toolset)
_p(' ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS)%s', make.list(table.join(toolset.getcxxflags(cfg), cfg.buildoptions)))
end
function make.cppCleanRules(prj)
_p('clean:')
_p('\t@echo Cleaning %s', prj.name)
_p('ifeq (posix,$(SHELLTYPE))')
_p('\t$(SILENT) rm -f $(TARGET)')
_p('\t$(SILENT) rm -rf $(OBJDIR)')
_p('else')
_p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGET)) del $(subst /,\\\\,$(TARGET))')
_p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))')
_p('endif')
_p('')
end
function make.cppDependencies(prj)
-- include the dependencies, built by GCC (with the -MMD flag)
_p('-include $(OBJECTS:%%.o=%%.d)')
_p('ifneq (,$(PCH))')
_p(' -include $(OBJDIR)/$(notdir $(PCH)).d')
_p('endif')
end
function make.cppTargetRules(prj)
_p('$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES) | $(TARGETDIR)')
_p('\t@echo Linking %s', prj.name)
_p('\t$(SILENT) $(LINKCMD)')
_p('\t$(POSTBUILDCMDS)')
_p('')
end
function make.cppCustomFilesRules(prj)
_p('$(CUSTOMFILES): | $(OBJDIR)')
_p('')
end
function make.cppTargetDirRules(prj)
_p('$(TARGETDIR):')
_p('\t@echo Creating $(TARGETDIR)')
make.mkdir('$(TARGETDIR)')
_p('')
end
function make.cppObjDirRules(prj)
_p('$(OBJDIR):')
_p('\t@echo Creating $(OBJDIR)')
make.mkdir('$(OBJDIR)')
_p('')
end
function make.cppTools(cfg, toolset)
local tool = toolset.gettoolname(cfg, "cc")
if tool then
_p(' ifeq ($(origin CC), default)')
_p(' CC = %s', tool)
_p(' endif' )
end
tool = toolset.gettoolname(cfg, "cxx")
if tool then
_p(' ifeq ($(origin CXX), default)')
_p(' CXX = %s', tool)
_p(' endif' )
end
tool = toolset.gettoolname(cfg, "ar")
if tool then
_p(' ifeq ($(origin AR), default)')
_p(' AR = %s', tool)
_p(' endif' )
end
tool = toolset.gettoolname(cfg, "rc")
if tool then
_p(' RESCOMP = %s', tool)
end
end
function make.defines(cfg, toolset)
_p(' DEFINES +=%s', make.list(table.join(toolset.getdefines(cfg.defines, cfg), toolset.getundefines(cfg.undefines))))
end
function make.forceInclude(cfg, toolset)
local includes = toolset.getforceincludes(cfg)
if not cfg.flags.NoPCH and cfg.pchheader then
table.insert(includes, 1, "-include $(OBJDIR)/$(notdir $(PCH))")
end
_x(' FORCE_INCLUDE +=%s', make.list(includes))
end
function make.includes(cfg, toolset)
local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs, cfg.frameworkdirs)
_p(' INCLUDES +=%s', make.list(includes))
end
function make.ldDeps(cfg, toolset)
local deps = config.getlinks(cfg, "siblings", "fullpath")
_p(' LDDEPS +=%s', make.list(p.esc(deps)))
end
function make.ldFlags(cfg, toolset)
local flags = table.join(toolset.getLibraryDirectories(cfg), toolset.getrunpathdirs(cfg, table.join(cfg.runpathdirs, config.getsiblingtargetdirs(cfg))), toolset.getldflags(cfg), cfg.linkoptions)
_p(' ALL_LDFLAGS += $(LDFLAGS)%s', make.list(flags))
end
function make.libs(cfg, toolset)
local flags = toolset.getlinks(cfg)
_p(' LIBS +=%s', make.list(flags, true))
end
function make.linkCmd(cfg, toolset)
if cfg.kind == p.STATICLIB then
if cfg.architecture == p.UNIVERSAL then
_p(' LINKCMD = libtool -o "$@" $(OBJECTS)')
else
_p(' LINKCMD = $(AR) ' .. (toolset.arargs or '-rcs') ..' "$@" $(OBJECTS)')
end
elseif cfg.kind == p.UTILITY then
-- Empty LINKCMD for Utility (only custom build rules)
_p(' LINKCMD =')
else
-- this was $(TARGET) $(LDFLAGS) $(OBJECTS)
-- but had trouble linking to certain static libs; $(OBJECTS) moved up
-- $(LDFLAGS) moved to end (http://sourceforge.net/p/premake/patches/107/)
-- $(LIBS) moved to end (http://sourceforge.net/p/premake/bugs/279/)
local cc = iif(p.languages.isc(cfg.language), "CC", "CXX")
_p(' LINKCMD = $(%s) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)', cc)
end
end
function make.pch(cfg, toolset)
local pch = p.tools.gcc.getpch(cfg)
-- If there is no header, or if PCH has been disabled, I can early out
if pch == nil then
return
end
_x(' PCH = %s', pch)
_p(' GCH = $(OBJDIR)/$(notdir $(PCH)).gch')
end
function make.pchRules(prj)
_p('ifneq (,$(PCH))')
_p('$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)')
_p('$(GCH): $(PCH) | $(OBJDIR)')
_p('\t@echo $(notdir $<)')
local cmd = iif(prj.language == "C", "$(CC) -x c-header $(ALL_CFLAGS)", "$(CXX) -x c++-header $(ALL_CXXFLAGS)")
_p('\t$(SILENT) %s -o "$@" -MF "$(@:%%.gch=%%.d)" -c "$<"', cmd)
_p('else')
_p('$(OBJECTS): | $(OBJDIR)')
_p('endif')
_p('')
end
function make.resFlags(cfg, toolset)
local resflags = table.join(toolset.getdefines(cfg.resdefines), toolset.getincludedirs(cfg, cfg.resincludedirs), cfg.resoptions)
_p(' ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)%s', make.list(resflags))
end

View file

@ -0,0 +1,315 @@
--
-- make_csharp.lua
-- Generate a C# project makefile.
-- Copyright (c) 2002-2013 Jason Perkins and the Premake project
--
local p = premake
p.make.cs = {}
local make = p.make
local cs = p.make.cs
local project = p.project
local config = p.config
local fileconfig = p.fileconfig
--
-- Add namespace for element definition lists for p.callarray()
--
cs.elements = {}
--
-- Generate a GNU make C++ project makefile, with support for the new platforms API.
--
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
--
-- Generate a GNU make C# project makefile, with support for the new platforms API.
--
function make.cs.generate(prj)
p.eol("\n")
local toolset = p.tools.dotnet
p.callArray(cs.elements.makefile, prj, toolset)
end
--
-- Write out the settings for a particular configuration.
--
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
function make.csConfigs(prj, toolset)
for cfg in project.eachconfig(prj) do
_x('ifeq ($(config),%s)', cfg.shortname)
p.callArray(cs.elements.configuration, cfg, toolset)
_p('endif')
_p('')
end
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)/" .. p.esc(name .. path.getbasename(fname)) .. ".resources"
else
return fname
end
end
--
-- Iterate and output some selection of the source code files.
--
function cs.listsources(prj, selector)
local tr = project.getsourcetree(prj)
p.tree.traverse(tr, {
onleaf = function(node, depth)
local value = selector(node)
if value then
_x('\t%s \\', value)
end
end
})
end
---------------------------------------------------------------------------
--
-- Handlers for individual makefile elements
--
---------------------------------------------------------------------------
function make.csAllRules(prj, toolset)
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)')
_p('')
end
function make.csCleanRules(prj, toolset)
--[[
-- porting from 4.x
_p('clean:')
_p('\t@echo Cleaning %s', prj.name)
_p('ifeq (posix,$(SHELLTYPE))')
_p('\t$(SILENT) rm -f $(TARGETDIR)/%s.* $(COPYFILES)', target.basename)
_p('\t$(SILENT) rm -rf $(OBJDIR)')
_p('else')
_p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGETDIR)/%s) del $(subst /,\\\\,$(TARGETDIR)/%s.*)', target.name, target.basename)
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('')
--]]
end
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
_p('')
--]]
end
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 = p.tools.dotnet
local ext = make.getmakefilename(prj, true)
local makefile = path.getname(p.filename(prj, ext))
local response = make.cs.getresponsefilename(prj)
_p('$(RESPONSE): %s', makefile)
_p('\t@echo Generating response file', prj.name)
_p('ifeq (posix,$(SHELLTYPE))')
_x('\t$(SILENT) rm -f $(RESPONSE)')
_p('else')
_x('\t$(SILENT) if exist $(RESPONSE) del %s', path.translate(response, '\\'))
_p('endif')
local sep = os.istarget("windows") and "\\" or "/"
local tr = project.getsourcetree(prj)
p.tree.traverse(tr, {
onleaf = function(node, depth)
if toolset.fileinfo(node).action == "Compile" then
_x('\t@echo %s >> $(RESPONSE)', path.translate(node.relpath, sep))
end
end
})
_p('')
end
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)
_p('')
end
function make.csFileRules(prj, toolset)
--[[
-- porting from 4.x
_p('# Per-configuration copied file rules')
for cfg in p.eachconfig(prj) do
_x('ifneq (,$(findstring %s,$(config)))', cfg.name:lower())
for target, source in pairs(cfgpairs[cfg]) do
p.make_copyrule(source, target)
end
_p('endif')
_p('')
end
_p('# Copied file rules')
for target, source in pairs(copypairs) do
p.make_copyrule(source, target)
end
_p('# Embedded file rules')
for _, fname in ipairs(embedded) do
if path.getextension(fname) == ".resx" then
_x('%s: %s', getresourcefilename(prj, fname), fname)
_p('\t$(SILENT) $(RESGEN) $^ $@')
end
_p('')
end
--]]
end
function make.csFlags(cfg, toolset)
_p(' FLAGS =%s', make.list(toolset.getflags(cfg)))
end
function make.csLinkCmd(cfg, toolset)
local deps = p.esc(config.getlinks(cfg, "dependencies", "fullpath"))
_p(' DEPENDS =%s', make.list(deps))
_p(' REFERENCES = %s', table.implode(deps, "/r:", "", " "))
end
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)
local kindflag = "/t:" .. toolset.getkind(cfg):lower()
local libdirs = table.implode(p.esc(cfg.libdirs), "/lib:", "", " ")
_p('FLAGS += %s', table.concat(table.join(kindflag, libdirs), " "))
local refs = p.esc(config.getlinks(cfg, "system", "fullpath"))
_p('REFERENCES += %s', table.implode(refs, "/r:", "", " "))
_p('')
end
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)
_p('')
end
function make.csTargetRules(prj, toolset)
_p('$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS) $(RESPONSE)')
_p('\t$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) @$(RESPONSE) $(patsubst %%,/resource:%%,$(EMBEDFILES))')
_p('\t$(POSTBUILDCMDS)')
_p('')
end
function make.csTools(cfg, toolset)
_p(' CSC = %s', toolset.gettoolname(cfg, "csc"))
_p(' RESGEN = %s', toolset.gettoolname(cfg, "resgen"))
end

View file

@ -0,0 +1,93 @@
--
-- make_makefile.lua
-- Generate a C/C++ project makefile.
-- Copyright (c) 2002-2014 Jason Perkins and the Premake project
--
local p = premake
p.make.makefile = {}
local make = p.make
local makefile = p.make.makefile
local project = p.project
local config = p.config
local fileconfig = p.fileconfig
---
-- Add namespace for element definition lists for p.callarray()
---
makefile.elements = {}
--
-- Generate a GNU make makefile project makefile.
--
makefile.elements.makefile = {
"header",
"phonyRules",
"makefileConfigs",
"makefileTargetRules"
}
function make.makefile.generate(prj)
p.eol("\n")
p.callarray(make, makefile.elements.makefile, prj)
end
makefile.elements.configuration = {
"target",
"buildCommands",
"cleanCommands",
}
function make.makefileConfigs(prj)
for cfg in project.eachconfig(prj) do
-- identify the toolset used by this configurations (would be nicer if
-- this were computed and stored with the configuration up front)
local toolset = p.tools[cfg.toolset or "gcc"]
if not toolset then
error("Invalid toolset '" .. cfg.toolset .. "'")
end
_x('ifeq ($(config),%s)', cfg.shortname)
p.callarray(make, makefile.elements.configuration, cfg, toolset)
_p('endif')
_p('')
end
end
function make.makefileTargetRules(prj)
_p('$(TARGET):')
_p('\t$(BUILDCMDS)')
_p('')
_p('clean:')
_p('\t$(CLEANCMDS)')
_p('')
end
function make.buildCommands(cfg)
_p(' define BUILDCMDS')
local steps = cfg.buildcommands
if #steps > 0 then
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
_p('\t@echo Running build commands')
_p('\t%s', table.implode(steps, "", "", "\n\t"))
end
_p(' endef')
end
function make.cleanCommands(cfg)
_p(' define CLEANCMDS')
local steps = cfg.cleancommands
if #steps > 0 then
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
_p('\t@echo Running clean commands')
_p('\t%s', table.implode(steps, "", "", "\n\t"))
end
_p(' endef')
end

View file

@ -0,0 +1,67 @@
--
-- make_utility.lua
-- Generate a C/C++ project makefile.
-- Copyright (c) 2002-2014 Jason Perkins and the Premake project
--
local p = premake
p.make.utility = {}
local make = p.make
local utility = p.make.utility
local project = p.project
local config = p.config
local fileconfig = p.fileconfig
---
-- Add namespace for element definition lists for p.callarray()
---
utility.elements = {}
--
-- Generate a GNU make utility project makefile.
--
utility.elements.makefile = {
"header",
"phonyRules",
"utilityConfigs",
"utilityTargetRules"
}
function make.utility.generate(prj)
p.eol("\n")
p.callarray(make, utility.elements.makefile, prj)
end
utility.elements.configuration = {
"target",
"preBuildCmds",
"postBuildCmds",
}
function make.utilityConfigs(prj)
for cfg in project.eachconfig(prj) do
-- identify the toolset used by this configurations (would be nicer if
-- this were computed and stored with the configuration up front)
local toolset = p.tools[cfg.toolset or "gcc"]
if not toolset then
error("Invalid toolset '" .. cfg.toolset .. "'")
end
_x('ifeq ($(config),%s)', cfg.shortname)
p.callarray(make, utility.elements.configuration, cfg, toolset)
_p('endif')
_p('')
end
end
function make.utilityTargetRules(prj)
_p('$(TARGET):')
_p('\t$(PREBUILDCMDS)')
_p('\t$(POSTBUILDCMDS)')
_p('')
end

View file

@ -0,0 +1,188 @@
--
-- make_workspace.lua
-- Generate a workspace-level makefile.
-- Copyright (c) 2002-2015 Jason Perkins and the Premake project
--
local p = premake
local make = p.make
local tree = p.tree
local project = p.project
--
-- Generate a GNU make "workspace" makefile, with support for the new platforms API.
--
function make.generate_workspace(wks)
p.eol("\n")
make.header(wks)
make.configmap(wks)
make.projects(wks)
make.workspacePhonyRule(wks)
make.groupRules(wks)
make.projectrules(wks)
make.cleanrules(wks)
make.helprule(wks)
end
--
-- Write out the workspace's configuration map, which maps workspace
-- level configurations to the project level equivalents.
--
function make.configmap(wks)
for cfg in p.workspace.eachconfig(wks) do
_p('ifeq ($(config),%s)', cfg.shortname)
for prj in p.workspace.eachproject(wks) do
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
if prjcfg then
_p(' %s_config = %s', make.tovar(prj.name), prjcfg.shortname)
end
end
_p('endif')
end
_p('')
end
--
-- Write out the rules for the `make clean` action.
--
function make.cleanrules(wks)
_p('clean:')
for prj in p.workspace.eachproject(wks) do
local prjpath = p.filename(prj, make.getmakefilename(prj, true))
local prjdir = path.getdirectory(path.getrelative(wks.location, prjpath))
local prjname = path.getname(prjpath)
_x(1,'@${MAKE} --no-print-directory -C %s -f %s clean', prjdir, prjname)
end
_p('')
end
--
-- Write out the make file help rule and configurations list.
--
function make.helprule(wks)
_p('help:')
_p(1,'@echo "Usage: make [config=name] [target]"')
_p(1,'@echo ""')
_p(1,'@echo "CONFIGURATIONS:"')
for cfg in p.workspace.eachconfig(wks) do
_x(1, '@echo " %s"', cfg.shortname)
end
_p(1,'@echo ""')
_p(1,'@echo "TARGETS:"')
_p(1,'@echo " all (default)"')
_p(1,'@echo " clean"')
for prj in p.workspace.eachproject(wks) do
_p(1,'@echo " %s"', prj.name)
end
_p(1,'@echo ""')
_p(1,'@echo "For more information, see https://github.com/premake/premake-core/wiki"')
end
--
-- Write out the list of projects that comprise the workspace.
--
function make.projects(wks)
_p('PROJECTS := %s', table.concat(p.esc(table.extract(wks.projects, "name")), " "))
_p('')
end
--
-- Write out the workspace PHONY rule
--
function make.workspacePhonyRule(wks)
local groups = {}
local tr = p.workspace.grouptree(wks)
tree.traverse(tr, {
onbranch = function(n)
table.insert(groups, n.path)
end
})
_p('.PHONY: all clean help $(PROJECTS) ' .. table.implode(groups, '', '', ' '))
_p('')
_p('all: $(PROJECTS)')
_p('')
end
--
-- Write out the phony rules representing project groups
--
function make.groupRules(wks)
-- Transform workspace groups into target aggregate
local tr = p.workspace.grouptree(wks)
tree.traverse(tr, {
onbranch = function(n)
local rule = n.path .. ":"
local projectTargets = {}
local groupTargets = {}
for i, c in pairs(n.children)
do
if type(i) == "string"
then
if c.project
then
table.insert(projectTargets, c.name)
else
table.insert(groupTargets, c.path)
end
end
end
if #groupTargets > 0 then
table.sort(groupTargets)
rule = rule .. " " .. table.concat(groupTargets, " ")
end
if #projectTargets > 0 then
table.sort(projectTargets)
rule = rule .. " " .. table.concat(projectTargets, " ")
end
_p(rule)
_p('')
end
})
end
--
-- Write out the rules to build each of the workspace's projects.
--
function make.projectrules(wks)
for prj in p.workspace.eachproject(wks) do
local deps = project.getdependencies(prj)
deps = table.extract(deps, "name")
_p('%s:%s', p.esc(prj.name), make.list(deps))
local cfgvar = make.tovar(prj.name)
_p('ifneq (,$(%s_config))', cfgvar)
_p(1,'@echo "==== Building %s ($(%s_config)) ===="', prj.name, cfgvar)
local prjpath = p.filename(prj, make.getmakefilename(prj, true))
local prjdir = path.getdirectory(path.getrelative(wks.location, prjpath))
local prjname = path.getname(prjpath)
_x(1,'@${MAKE} --no-print-directory -C %s -f %s config=$(%s_config)', prjdir, prjname, cfgvar)
_p('endif')
_p('')
end
end

View file

@ -0,0 +1,33 @@
require ("gmake")
return {
-- Makefile tests
"test_make_escaping.lua",
"test_make_tovar.lua",
-- Makefile workspaces
"workspace/test_config_maps.lua",
"workspace/test_default_config.lua",
"workspace/test_group_rule.lua",
"workspace/test_help_rule.lua",
"workspace/test_project_rule.lua",
-- Makefile C/C++ projects
"cpp/test_clang.lua",
"cpp/test_file_rules.lua",
"cpp/test_flags.lua",
"cpp/test_ldflags.lua",
"cpp/test_make_pch.lua",
"cpp/test_make_linking.lua",
"cpp/test_objects.lua",
"cpp/test_target_rules.lua",
"cpp/test_tools.lua",
"cpp/test_wiidev.lua",
-- Makefile C# projects
"cs/test_embed_files.lua",
"cs/test_flags.lua",
"cs/test_links.lua",
"cs/test_response.lua",
"cs/test_sources.lua",
}

View file

@ -0,0 +1,63 @@
--
-- tests/actions/make/cpp/test_clang.lua
-- Test Clang support in Makefiles.
-- Copyright (c) 2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_clang")
local make = p.make
local cpp = p.make.cpp
local project = p.project
--
-- Setup
--
local wks, prj
function suite.setup()
wks = test.createWorkspace()
toolset "clang"
prj = p.workspace.getproject(wks, 1)
end
--
-- Make sure that the correct compilers are used.
--
function suite.usesCorrectCompilers()
make.cppConfigs(prj)
test.capture [[
ifeq ($(config),debug)
ifeq ($(origin CC), default)
CC = clang
endif
ifeq ($(origin CXX), default)
CXX = clang++
endif
ifeq ($(origin AR), default)
AR = ar
endif
]]
end
function suite.usesCorrectCompilersAndLinkTimeOptimization()
flags { "LinkTimeOptimization" }
make.cppConfigs(prj)
test.capture [[
ifeq ($(config),debug)
ifeq ($(origin CC), default)
CC = clang
endif
ifeq ($(origin CXX), default)
CXX = clang++
endif
ifeq ($(origin AR), default)
AR = llvm-ar
endif
]]
end

View file

@ -0,0 +1,170 @@
--
-- tests/actions/make/cpp/test_file_rules.lua
-- Validate the makefile source building rules.
-- Copyright (c) 2009-2014 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_cpp_file_rules")
local make = p.make
local project = p.project
--
-- Setup
--
local wks, prj
function suite.setup()
p.escaper(make.esc)
wks = test.createWorkspace()
end
local function prepare()
prj = p.workspace.getproject(wks, 1)
make.cppFileRules(prj)
end
--
-- Two files with the same base name should have different object files.
--
function suite.uniqueObjNames_onBaseNameCollision()
files { "src/hello.cpp", "src/greetings/hello.cpp" }
prepare()
test.capture [[
$(OBJDIR)/hello.o: src/greetings/hello.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/hello1.o: src/hello.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end
--
-- C files in C++ projects should been compiled as c
--
function suite.cFilesGetsCompiledWithCCWhileInCppProject()
files { "src/hello.c", "src/test.cpp" }
prepare()
test.capture [[
$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/test.o: src/test.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end
--
-- C files in C++ projects can be compiled as C++ with 'compileas'
--
function suite.cFilesGetsCompiledWithCXXWithCompileas()
files { "src/hello.c", "src/test.c" }
filter { "files:src/hello.c" }
compileas "C++"
prepare()
test.capture [[
$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
ifeq ($(config),debug)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
endif
ifeq ($(config),release)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
endif
$(OBJDIR)/test.o: src/test.c
@echo $(notdir $<)
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end
--
-- C files in C++ projects can be compiled as C++ with 'compileas' on a configuration basis
--
function suite.cFilesGetsCompiledWithCXXWithCompileasDebugOnly()
files { "src/test.c", "src/hello.c" }
filter { "configurations:Debug", "files:src/hello.c" }
compileas "C++"
prepare()
test.capture [[
$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
ifeq ($(config),debug)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
endif
ifeq ($(config),release)
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
endif
$(OBJDIR)/test.o: src/test.c
@echo $(notdir $<)
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end
--
-- If a custom build rule is supplied, it should be used.
--
function suite.customBuildRule()
files { "hello.x" }
filter "files:**.x"
buildmessage "Compiling %{file.name}"
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
prepare()
test.capture [[
ifeq ($(config),debug)
obj/Debug/hello.obj: hello.x
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
endif
ifeq ($(config),release)
obj/Release/hello.obj: hello.x
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
endif
]]
end
function suite.customBuildRuleWithAdditionalInputs()
files { "hello.x" }
filter "files:**.x"
buildmessage "Compiling %{file.name}"
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
buildinputs { "%{file.path}.inc", "%{file.path}.inc2" }
prepare()
test.capture [[
ifeq ($(config),debug)
obj/Debug/hello.obj: hello.x hello.x.inc hello.x.inc2
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
endif
ifeq ($(config),release)
obj/Release/hello.obj: hello.x hello.x.inc hello.x.inc2
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
endif
]]
end

View file

@ -0,0 +1,144 @@
--
-- tests/actions/make/cpp/test_flags.lua
-- Tests compiler and linker flags for Makefiles.
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_flags")
local make = p.make
local project = p.project
--
-- Setup
--
local wks, prj
function suite.setup()
wks, prj = test.createWorkspace()
end
local function prepare(calls)
local cfg = test.getconfig(prj, "Debug")
local toolset = p.tools.gcc
p.callarray(make, calls, cfg, toolset)
end
--
-- Include directories should be relative and space separated.
--
function suite.includeDirs()
includedirs { "src/include", "../include" }
prepare { "includes" }
test.capture [[
INCLUDES += -Isrc/include -I../include
]]
end
--
-- symbols "on" should produce -g
--
function suite.symbols_on()
symbols "on"
prepare { "cFlags", "cxxFlags" }
test.capture [[
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g
]]
end
--
-- symbols default to 'off'
--
function suite.symbols_default()
symbols "default"
prepare { "cFlags", "cxxFlags" }
test.capture [[
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS)
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS)
]]
end
--
-- All other symbols flags also produce -g
--
function suite.symbols_fastlink()
symbols "FastLink"
prepare { "cFlags", "cxxFlags" }
test.capture [[
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g
]]
end
function suite.symbols_full()
symbols "full"
prepare { "cFlags", "cxxFlags" }
test.capture [[
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g
]]
end
--
-- symbols "off" should not produce -g
--
function suite.symbols_off()
symbols "off"
prepare { "cFlags", "cxxFlags" }
test.capture [[
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS)
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS)
]]
end
--
-- symbols "on" with a proper debugformat should produce a corresponding -g
--
function suite.symbols_on_default()
symbols "on"
debugformat "Default"
prepare { "cFlags", "cxxFlags" }
test.capture [[
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g
]]
end
function suite.symbols_on_dwarf()
symbols "on"
debugformat "Dwarf"
prepare { "cFlags", "cxxFlags" }
test.capture [[
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -gdwarf
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -gdwarf
]]
end
function suite.symbols_on_split_dwarf()
symbols "on"
debugformat "SplitDwarf"
prepare { "cFlags", "cxxFlags" }
test.capture [[
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -gsplit-dwarf
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -gsplit-dwarf
]]
end
--
-- symbols "off" with a proper debugformat should not produce -g
--
function suite.symbols_off_dwarf()
symbols "off"
debugformat "Dwarf"
prepare { "cFlags", "cxxFlags" }
test.capture [[
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS)
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS)
]]
end

View file

@ -0,0 +1,78 @@
--
-- tests/actions/make/cpp/test_ldflags.lua
-- Tests compiler and linker flags for Makefiles.
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_ldflags")
local make = p.make
--
-- Setup
--
local wks, prj
function suite.setup()
wks, prj = test.createWorkspace()
symbols "On"
end
local function prepare(calls)
local cfg = test.getconfig(prj, "Debug")
local toolset = p.tools.gcc
make.ldFlags(cfg, toolset)
end
--
-- Check the output from default project values.
--
function suite.checkDefaultValues()
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS)
]]
end
--
-- Check addition of library search directores.
--
function suite.checkLibDirs()
libdirs { "../libs", "libs" }
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -L../libs -Llibs
]]
end
function suite.checkLibDirs_X86_64()
architecture ("x86_64")
system (p.LINUX)
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib64 -m64
]]
end
function suite.checkLibDirs_X86()
architecture ("x86")
system (p.LINUX)
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib32 -m32
]]
end
function suite.checkLibDirs_X86_64_MacOSX()
architecture ("x86_64")
system (p.MACOSX)
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -m64
]]
end

View file

@ -0,0 +1,270 @@
--
-- tests/actions/make/cpp/test_make_linking.lua
-- Validate the link step generation for makefiles.
-- Copyright (c) 2010-2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_linking")
local make = p.make
local project = p.project
--
-- Setup and teardown
--
local wks, prj
function suite.setup()
_TARGET_OS = "linux"
wks, prj = test.createWorkspace()
end
local function prepare(calls)
local cfg = test.getconfig(prj, "Debug")
local toolset = p.tools.gcc
p.callarray(make, calls, cfg, toolset)
end
--
-- Check link command for a shared C++ library.
--
function suite.links_onCppSharedLib()
kind "SharedLib"
prepare { "ldFlags", "linkCmd" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -shared -Wl,-soname=libMyProject.so -s
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
]]
end
function suite.links_onMacOSXCppSharedLib()
_TARGET_OS = "macosx"
kind "SharedLib"
prepare { "ldFlags", "linkCmd" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -dynamiclib -Wl,-install_name,@rpath/libMyProject.dylib -Wl,-x
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
]]
end
--
-- Check link command for a shared C library.
--
function suite.links_onCSharedLib()
language "C"
kind "SharedLib"
prepare { "ldFlags", "linkCmd" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -shared -Wl,-soname=libMyProject.so -s
LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
]]
end
--
-- Check link command for a static library.
--
function suite.links_onStaticLib()
kind "StaticLib"
prepare { "ldFlags", "linkCmd" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s
LINKCMD = $(AR) -rcs "$@" $(OBJECTS)
]]
end
--
-- Check link command for the Utility kind.
--
-- Utility projects should only run custom commands, and perform no linking.
--
function suite.links_onUtility()
kind "Utility"
prepare { "linkCmd" }
test.capture [[
LINKCMD =
]]
end
--
-- Check link command for a Mac OS X universal static library.
--
function suite.links_onMacUniversalStaticLib()
architecture "universal"
kind "StaticLib"
prepare { "ldFlags", "linkCmd" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s
LINKCMD = libtool -o "$@" $(OBJECTS)
]]
end
--
-- Check a linking to a sibling static library.
--
function suite.links_onSiblingStaticLib()
links "MyProject2"
test.createproject(wks)
kind "StaticLib"
location "build"
prepare { "ldFlags", "libs", "ldDeps" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s
LIBS += build/bin/Debug/libMyProject2.a
LDDEPS += build/bin/Debug/libMyProject2.a
]]
end
--
-- Check a linking to a sibling shared library.
--
function suite.links_onSiblingSharedLib()
links "MyProject2"
test.createproject(wks)
kind "SharedLib"
location "build"
prepare { "ldFlags", "libs", "ldDeps" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -Wl,-rpath,'$$ORIGIN/../../build/bin/Debug' -s
LIBS += build/bin/Debug/libMyProject2.so
LDDEPS += build/bin/Debug/libMyProject2.so
]]
end
--
-- Check a linking to a sibling shared library using -l and -L.
--
function suite.links_onSiblingSharedLibRelativeLinks()
links "MyProject2"
flags { "RelativeLinks" }
test.createproject(wks)
kind "SharedLib"
location "build"
prepare { "ldFlags", "libs", "ldDeps" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -Lbuild/bin/Debug -Wl,-rpath,'$$ORIGIN/../../build/bin/Debug' -s
LIBS += -lMyProject2
LDDEPS += build/bin/Debug/libMyProject2.so
]]
end
function suite.links_onMacOSXSiblingSharedLib()
_TARGET_OS = "macosx"
links "MyProject2"
flags { "RelativeLinks" }
test.createproject(wks)
kind "SharedLib"
location "build"
prepare { "ldFlags", "libs", "ldDeps" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -Lbuild/bin/Debug -Wl,-rpath,'@loader_path/../../build/bin/Debug' -Wl,-x
LIBS += -lMyProject2
LDDEPS += build/bin/Debug/libMyProject2.dylib
]]
end
--
-- Check a linking multiple siblings.
--
function suite.links_onMultipleSiblingStaticLib()
links "MyProject2"
links "MyProject3"
test.createproject(wks)
kind "StaticLib"
location "build"
test.createproject(wks)
kind "StaticLib"
location "build"
prepare { "ldFlags", "libs", "ldDeps" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s
LIBS += build/bin/Debug/libMyProject2.a build/bin/Debug/libMyProject3.a
LDDEPS += build/bin/Debug/libMyProject2.a build/bin/Debug/libMyProject3.a
]]
end
--
-- Check a linking multiple siblings with link groups enabled.
--
function suite.links_onSiblingStaticLibWithLinkGroups()
links "MyProject2"
links "MyProject3"
linkgroups "On"
test.createproject(wks)
kind "StaticLib"
location "build"
test.createproject(wks)
kind "StaticLib"
location "build"
prepare { "ldFlags", "libs", "ldDeps" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s
LIBS += -Wl,--start-group build/bin/Debug/libMyProject2.a build/bin/Debug/libMyProject3.a -Wl,--end-group
LDDEPS += build/bin/Debug/libMyProject2.a build/bin/Debug/libMyProject3.a
]]
end
--
-- When referencing an external library via a path, the directory
-- should be added to the library search paths, and the library
-- itself included via an -l flag.
--
function suite.onExternalLibraryWithPath()
location "MyProject"
links { "libs/SomeLib" }
prepare { "ldFlags", "libs" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -L../libs -s
LIBS += -lSomeLib
]]
end
--
-- When referencing an external library with a period in the
-- file name make sure it appears correctly in the LIBS
-- directive. Currently the period and everything after it
-- is stripped
--
function suite.onExternalLibraryWithPathAndVersion()
location "MyProject"
links { "libs/SomeLib-1.1" }
prepare { "libs", }
test.capture [[
LIBS += -lSomeLib-1.1
]]
end

View file

@ -0,0 +1,142 @@
--
-- tests/actions/make/cpp/test_make_pch.lua
-- Validate the setup for precompiled headers in makefiles.
-- Copyright (c) 2010-2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_pch")
local make = p.make
local project = p.project
--
-- Setup and teardown
--
local wks, prj
function suite.setup()
os.chdir(_TESTS_DIR)
wks, prj = test.createWorkspace()
end
local function prepareVars()
local cfg = test.getconfig(prj, "Debug")
make.pch(cfg)
end
local function prepareRules()
local cfg = test.getconfig(prj, "Debug")
make.pchRules(cfg.project)
end
--
-- If no header has been set, nothing should be output.
--
function suite.noConfig_onNoHeaderSet()
prepareVars()
test.isemptycapture()
end
--
-- If a header is set, but the NoPCH flag is also set, then
-- nothing should be output.
--
function suite.noConfig_onHeaderAndNoPCHFlag()
pchheader "include/myproject.h"
flags "NoPCH"
prepareVars()
test.isemptycapture()
end
--
-- If a header is specified and the NoPCH flag is not set, then
-- the header can be used.
--
function suite.config_onPchEnabled()
pchheader "include/myproject.h"
prepareVars()
test.capture [[
PCH = include/myproject.h
GCH = $(OBJDIR)/$(notdir $(PCH)).gch
]]
end
--
-- The PCH can be specified relative the an includes search path.
--
function suite.pch_searchesIncludeDirs()
pchheader "premake.h"
includedirs { "../../../src/host" }
prepareVars()
test.capture [[
PCH = ../../../src/host/premake.h
]]
end
--
-- Verify the format of the PCH rules block for a C++ file.
--
function suite.buildRules_onCpp()
pchheader "include/myproject.h"
prepareRules()
test.capture [[
ifneq (,$(PCH))
$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)
$(GCH): $(PCH) | $(OBJDIR)
@echo $(notdir $<)
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
else
$(OBJECTS): | $(OBJDIR)
endif
]]
end
--
-- Verify the format of the PCH rules block for a C file.
--
function suite.buildRules_onC()
language "C"
pchheader "include/myproject.h"
prepareRules()
test.capture [[
ifneq (,$(PCH))
$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)
$(GCH): $(PCH) | $(OBJDIR)
@echo $(notdir $<)
$(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
else
$(OBJECTS): | $(OBJDIR)
endif
]]
end
--
-- If the header is located on one of the include file
-- search directories, it should get found automatically.
--
function suite.findsPCH_onIncludeDirs()
location "MyProject"
pchheader "premake.h"
includedirs { "../../../src/host" }
prepareVars()
test.capture [[
PCH = ../../../../src/host/premake.h
]]
end

View file

@ -0,0 +1,250 @@
--
-- tests/actions/make/cpp/test_objects.lua
-- Validate the list of objects for a makefile.
-- Copyright (c) 2009-2015 Jason Perkins and the Premake project
--
local suite = test.declare("make_cpp_objects")
local p = premake
--
-- Setup
--
local wks, prj
function suite.setup()
wks = test.createWorkspace()
end
local function prepare()
prj = test.getproject(wks, 1)
p.make.cppObjects(prj)
end
--
-- If a file is listed at the project level, it should get listed in
-- the project level objects list.
--
function suite.listFileInProjectObjects()
files { "src/hello.cpp" }
prepare()
test.capture [[
OBJECTS := \
$(OBJDIR)/hello.o \
]]
end
--
-- Only buildable files should be listed.
--
function suite.onlyListBuildableFiles()
files { "include/gl.h", "src/hello.cpp" }
prepare()
test.capture [[
OBJECTS := \
$(OBJDIR)/hello.o \
]]
end
--
-- A file should only be listed in the configurations to which it belongs.
--
function suite.configFilesAreConditioned()
filter "Debug"
files { "src/hello_debug.cpp" }
filter "Release"
files { "src/hello_release.cpp" }
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
CUSTOMFILES := \
ifeq ($(config),debug)
OBJECTS += \
$(OBJDIR)/hello_debug.o \
endif
ifeq ($(config),release)
OBJECTS += \
$(OBJDIR)/hello_release.o \
endif
]]
end
--
-- Two files with the same base name should have different object files.
--
function suite.uniqueObjNames_onBaseNameCollision()
files { "src/hello.cpp", "src/greetings/hello.cpp" }
prepare()
test.capture [[
OBJECTS := \
$(OBJDIR)/hello.o \
$(OBJDIR)/hello1.o \
]]
end
--
-- If a custom rule builds to an object file, include it in the
-- link automatically to match the behavior of Visual Studio
--
function suite.linkBuildOutputs_onNotSpecified()
files { "hello.x" }
filter "files:**.x"
buildmessage "Compiling %{file.name}"
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
CUSTOMFILES := \
ifeq ($(config),debug)
OBJECTS += \
obj/Debug/hello.obj \
endif
]]
end
--
-- Also include it in the link step if we explicitly specified so with
-- linkbuildoutputs.
--
function suite.linkBuildOutputs_onOn()
files { "hello.x" }
filter "files:**.x"
buildmessage "Compiling %{file.name}"
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
linkbuildoutputs "On"
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
CUSTOMFILES := \
ifeq ($(config),debug)
OBJECTS += \
obj/Debug/hello.obj \
endif
]]
end
--
-- If linkbuildoutputs says that we shouldn't include it in the link however,
-- don't do it.
--
function suite.linkBuildOutputs_onOff()
files { "hello.x" }
filter "files:**.x"
buildmessage "Compiling %{file.name}"
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
linkbuildoutputs "Off"
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
CUSTOMFILES := \
ifeq ($(config),debug)
CUSTOMFILES += \
obj/Debug/hello.obj \
endif
]]
end
--
-- If a file is excluded from a configuration, it should not be listed.
--
function suite.excludedFromBuild_onExcludedFile()
files { "hello.cpp" }
filter "Debug"
removefiles { "hello.cpp" }
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
CUSTOMFILES := \
ifeq ($(config),release)
OBJECTS += \
$(OBJDIR)/hello.o \
endif
]]
end
function suite.excludedFromBuild_onExcludeFlag()
files { "hello.cpp" }
filter { "Debug", "files:hello.cpp" }
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
CUSTOMFILES := \
ifeq ($(config),release)
OBJECTS += \
$(OBJDIR)/hello.o \
endif
]]
end

View file

@ -0,0 +1,57 @@
--
-- tests/actions/make/cpp/test_target_rules.lua
-- Validate the makefile target building rules.
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_cpp_target_rules")
local make = p.make
local project = p.project
--
-- Setup
--
local wks, prj
function suite.setup()
wks, prj = test.createWorkspace()
end
local function prepare()
local cfg = test.getconfig(prj, "Debug")
make.cppAllRules(cfg)
end
--
-- Check the default, normal format of the rules.
--
function suite.defaultRules()
prepare()
test.capture [[
all: prebuild prelink $(TARGET)
@:
]]
end
--
-- Check rules for an OS X Cocoa application.
--
function suite.osxWindowedAppRules()
system "MacOSX"
kind "WindowedApp"
prepare()
test.capture [[
all: prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist
@:
$(dir $(TARGETDIR))PkgInfo:
$(dir $(TARGETDIR))Info.plist:
]]
end

View file

@ -0,0 +1,35 @@
--
-- tests/actions/make/cpp/test_tools.lua
-- Tests for tools support in makefiles.
-- Copyright (c) 2012-2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_tools")
local make = p.make
local cpp = p.make.cpp
local project = p.project
--
-- Setup
--
local cfg
function suite.setup()
local wks, prj = test.createWorkspace()
cfg = test.getconfig(prj, "Debug")
end
--
-- Make sure that the correct tools are used.
--
function suite.usesCorrectTools()
make.cppTools(cfg, p.tools.gcc)
test.capture [[
RESCOMP = windres
]]
end

View file

@ -0,0 +1,58 @@
--
-- tests/actions/make/cpp/test_wiidev.lua
-- Tests for Wii homebrew support in makefiles.
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_wiidev")
local make = p.make
local project = p.project
--
-- Setup
--
local cfg
function suite.setup()
local wks, prj = test.createWorkspace()
system "wii"
symbols "On"
cfg = test.getconfig(prj, "Debug")
end
--
-- Make sure that the Wii-specific flags are passed to the tools.
--
function suite.writesCorrectCppFlags()
make.cppFlags(cfg, p.tools.gcc)
test.capture [[
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -I$(LIBOGC_INC) $(MACHDEP) $(DEFINES) $(INCLUDES)
]]
end
function suite.writesCorrectLinkerFlags()
make.ldFlags(cfg, p.tools.gcc)
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -L$(LIBOGC_LIB) $(MACHDEP)
]]
end
--
-- Make sure the dev kit include is written to each Wii build configuration.
--
function suite.writesIncludeBlock()
make.settings(cfg, p.tools.gcc)
test.capture [[
ifeq ($(strip $(DEVKITPPC)),)
$(error "DEVKITPPC environment variable is not set")'
endif
include $(DEVKITPPC)/wii_rules'
]]
end

View file

@ -0,0 +1,75 @@
--
-- tests/actions/make/cs/test_embed_files.lua
-- Tests embedded file listings for C# Makefiles.
-- Copyright (c) 2013-2014 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_cs_embed_files")
local make = p.make
local cs = p.make.cs
local project = p.project
--
-- Setup
--
local wks, prj, cfg
function suite.setup()
wks = test.createWorkspace()
end
local function prepare()
prj = p.workspace.getproject(wks, 1)
make.csEmbedFiles(prj, p.tools.dotnet)
end
--
-- Files that can be compiled should be listed here.
--
function suite.doesListResourceFiles()
files { "Hello.resx" }
prepare()
test.capture [[
EMBEDFILES += \
$(OBJDIR)/MyProject.Hello.resources \
]]
end
--
-- Files that should not be compiled should be excluded.
--
function suite.doesIgnoreNonResourceFiles()
files { "About.txt", "Hello.resx" }
prepare()
test.capture [[
EMBEDFILES += \
$(OBJDIR)/MyProject.Hello.resources \
]]
end
--
-- Files with a non-standard file extension but a build action of
-- "Embed" should be listed here.
--
function suite.doesIncludeCompileBuildAction()
files { "Hello.txt" }
filter "files:*.txt"
buildaction "Embed"
prepare()
test.capture [[
EMBEDFILES += \
Hello.txt \
]]
end

View file

@ -0,0 +1,65 @@
--
-- tests/actions/make/cs/test_flags.lua
-- Tests compiler and linker flags for C# Makefiles.
-- Copyright (c) 2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_cs_flags")
local make = p.make
local cs = p.make.cs
local project = p.project
--
-- Setup
--
local wks, prj
function suite.setup()
wks, prj = test.createWorkspace()
end
local function prepare()
local cfg = test.getconfig(prj, "Debug")
make.csFlags(cfg, p.tools.dotnet)
end
--
-- Should return an empty assignment if nothing has been specified.
--
function suite.isEmptyAssignment_onNoSettings()
prepare()
test.capture [[
FLAGS = /noconfig
]]
end
--
-- If the Unsafe flag has been set, it should be specified.
--
function suite.onUnsafe()
clr "Unsafe"
prepare()
test.capture [[
FLAGS = /unsafe /noconfig
]]
end
--
-- If an application icon has been set, it should be specified.
--
function suite.onApplicationIcon()
icon "MyProject.ico"
prepare()
test.capture [[
FLAGS = /noconfig /win32icon:"MyProject.ico"
]]
end

View file

@ -0,0 +1,60 @@
--
-- tests/actions/make/cs/test_links.lua
-- Tests linking for C# Makefiles.
-- Copyright (c) 2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_cs_links")
local make = p.make
local cs = p.make.cs
local project = p.project
--
-- Setup
--
local wks, prj
function suite.setup()
wks, prj = test.createWorkspace()
end
local function prepare()
local cfg = test.getconfig(prj, "Debug")
make.csLinkCmd(cfg, p.tools.dotnet)
end
--
-- Should return an empty assignment if nothing has been specified.
--
function suite.isEmptyAssignment_onNoSettings()
prepare()
test.capture [[
DEPENDS =
]]
end
--
-- Files that can be compiled should be listed here.
--
function suite.doesListLinkDependencyFiles()
links { "MyProject2", "MyProject3" }
test.createproject(wks)
kind "SharedLib"
language "C#"
test.createproject(wks)
kind "SharedLib"
language "C#"
prepare ()
test.capture [[
DEPENDS = bin/Debug/MyProject2.dll bin/Debug/MyProject3.dll
]]
end

View file

@ -0,0 +1,90 @@
--
-- tests/actions/make/cs/test_response.lua
-- Validate the list of objects for a response file used by a makefile.
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_cs_response")
local make = p.make
--
-- Setup
--
local wks, prj
function suite.setup()
p.action.set("vs2010")
wks = test.createWorkspace()
end
local function prepare()
prj = test.getproject(wks, 1)
end
--
-- Create a project with a lot of files to force the generation of response files.
-- This makes sure they can be processed in Windows since else we reach the command
-- line length max limit.
--
function suite.listResponse()
prepare()
make.csResponseFile(prj)
test.capture [[
RESPONSE += $(OBJDIR)/MyProject.rsp
]]
end
function suite.listResponseTargets()
prepare()
make.csTargetRules(prj)
test.capture [[
$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS) $(RESPONSE)
$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) @$(RESPONSE) $(patsubst %,/resource:%,$(EMBEDFILES))
]]
end
function suite.listResponseRules()
files { "foo.cs", "bar.cs", "dir/foo.cs" }
prepare()
make.csResponseRules(prj)
end
function suite.listResponseRulesPosix()
_TARGET_OS = "linux"
suite.listResponseRules()
test.capture [[
$(RESPONSE): MyProject.make
@echo Generating response file
ifeq (posix,$(SHELLTYPE))
$(SILENT) rm -f $(RESPONSE)
else
$(SILENT) if exist $(RESPONSE) del $(OBJDIR)\MyProject.rsp
endif
@echo bar.cs >> $(RESPONSE)
@echo dir/foo.cs >> $(RESPONSE)
@echo foo.cs >> $(RESPONSE)
]]
end
function suite.listResponseRulesWindows()
_TARGET_OS = "windows"
suite.listResponseRules()
test.capture [[
$(RESPONSE): MyProject.make
@echo Generating response file
ifeq (posix,$(SHELLTYPE))
$(SILENT) rm -f $(RESPONSE)
else
$(SILENT) if exist $(RESPONSE) del $(OBJDIR)\MyProject.rsp
endif
@echo bar.cs >> $(RESPONSE)
@echo dir\foo.cs >> $(RESPONSE)
@echo foo.cs >> $(RESPONSE)
]]
end

View file

@ -0,0 +1,90 @@
--
-- tests/actions/make/cs/test_sources.lua
-- Tests source file listings for C# Makefiles.
-- Copyright (c) 2013-2014 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_cs_sources")
local make = p.make
local cs = p.make.cs
local project = p.project
--
-- Setup
--
local wks, prj, cfg
function suite.setup()
wks = test.createWorkspace()
end
local function prepare()
prj = p.workspace.getproject(wks, 1)
make.csSources(prj, p.tools.dotnet)
end
--
-- Files that can be compiled should be listed here.
--
function suite.doesListSourceFiles()
files { "Hello.cs" }
prepare()
test.capture [[
SOURCES += \
Hello.cs \
]]
end
--
-- Path delimiter uses slash instead of backslash
--
function suite.doesUseProperPathDelimiter()
files { "Folder\\Hello.cs", "Folder/World.cs" }
prepare()
test.capture [[
SOURCES += \
Folder/Hello.cs \
Folder/World.cs \
]]
end
--
-- Files that should not be compiled should be excluded.
--
function suite.doesIgnoreNonSourceFiles()
files { "About.txt", "Hello.cs" }
prepare()
test.capture [[
SOURCES += \
Hello.cs \
]]
end
--
-- Files with a non-standard file extension but a build action of
-- "Compile" should be listed here.
--
function suite.doesIncludeCompileBuildAction()
files { "Hello.txt" }
filter "files:*.txt"
buildaction "Compile"
prepare()
test.capture [[
SOURCES += \
Hello.txt \
]]
end

View file

@ -0,0 +1,31 @@
--
-- tests/actions/make/test_make_escaping.lua
-- Validate the escaping of literal values in Makefiles.
-- Copyright (c) 2010-2012 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_escaping")
local make = p.make
function suite.Escapes_Spaces()
test.isequal([[Program\ Files]], make.esc([[Program Files]]))
end
function suite.Escapes_Backslashes()
test.isequal([[Program\\Files]], make.esc([[Program\Files]]))
end
function suite.Escapes_Parens()
test.isequal([[Debug\(x86\)]], make.esc([[Debug(x86)]]))
end
function suite.DoesNotEscape_ShellReplacements()
test.isequal([[-L$(NVSDKCUDA_ROOT)/C/lib]], make.esc([[-L$(NVSDKCUDA_ROOT)/C/lib]]))
end
function suite.CanEscape_ShellReplacementCapturesShortest()
test.isequal([[a\(x\)b$(ROOT)c\(y\)d]], make.esc([[a(x)b$(ROOT)c(y)d]]))
end

View file

@ -0,0 +1,35 @@
--
-- tests/actions/make/test_make_tovar.lua
-- Test translation of strings to make variable names.
-- Copyright (c) 2012 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_tovar")
local make = p.make
--
-- Convert spaces to underscores.
--
function suite.removesSpaces()
test.isequal("My_Project", make.tovar("My Project"))
end
--
-- Convert dashes to underscores.
--
function suite.removesDashes()
test.isequal("My_Project", make.tovar("My-Project"))
end
--
-- Remove parenthesis.
--
function suite.removesParenthesis()
test.isequal("MyProject_x86", make.tovar("MyProject (x86)"))
end

View file

@ -0,0 +1,78 @@
--
-- tests/actions/make/test_config_maps.lua
-- Validate handling of configuration maps in makefiles.
-- Copyright (c) 2012 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_config_maps")
local make = p.make
--
-- Setup/teardown
--
local wks, prj
function suite.setup()
wks = test.createWorkspace()
end
local function prepare()
make.configmap(wks)
end
--
-- If no map is present, the configurations should pass through
-- to the projects unchanged.
--
function suite.passesThroughConfigs_onNoMap()
prepare()
test.capture [[
ifeq ($(config),debug)
MyProject_config = debug
endif
ifeq ($(config),release)
MyProject_config = release
endif
]]
end
--
-- If a map is present, the configuration change should be applied.
--
function suite.passesThroughConfigs_onMap()
configmap { Debug = "Development" }
prepare()
test.capture [[
ifeq ($(config),debug)
MyProject_config = development
endif
ifeq ($(config),release)
MyProject_config = release
endif
]]
end
--
-- If a configuration is not included in a particular project,
-- no mapping should be created.
--
function suite.passesThroughConfigs_onNoMapRemovedConfiguration()
removeconfigurations { "Debug" }
prepare()
test.capture [[
ifeq ($(config),debug)
endif
ifeq ($(config),release)
MyProject_config = release
endif
]]
end

View file

@ -0,0 +1,87 @@
--
-- tests/actions/make/test_default_config.lua
-- Validate generation of default configuration block for makefiles.
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
--
local suite = test.declare("make_default_config")
local p = premake
--
-- Setup/teardown
--
local wks, prj
function suite.setup()
wks = test.createWorkspace()
end
local function prepare()
prj = test.getproject(wks, 1)
p.make.defaultconfig(prj)
end
--
-- Verify the handling of the default setup: Debug and Release, no platforms.
--
function suite.defaultsToFirstBuildCfg_onNoPlatforms()
prepare()
test.capture [[
ifndef config
config=debug
endif
]]
end
--
-- Verify handling of build config/platform combination.
--
function suite.defaultsToFirstPairing_onPlatforms()
platforms { "Win32", "Win64" }
prepare()
test.capture [[
ifndef config
config=debug_win32
endif
]]
end
--
-- If the project excludes a workspace build cfg, it should be skipped
-- over as the default config as well.
--
function suite.usesFirstValidPairing_onExcludedConfig()
platforms { "Win32", "Win64" }
removeconfigurations { "Debug" }
prepare()
test.capture [[
ifndef config
config=release_win32
endif
]]
end
--
-- Verify handling of defaultplatform
--
function suite.defaultsToSpecifiedPlatform()
platforms { "Win32", "Win64" }
defaultplatform "Win64"
prepare()
test.capture [[
ifndef config
config=debug_win64
endif
]]
end

View file

@ -0,0 +1,61 @@
--
-- tests/actions/make/workspace/test_group_rule.lua
-- Validate generation of group rules
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_group_rule")
local make = p.make
--
-- Setup/teardown
--
local wks
function suite.setup()
wks = test.createWorkspace()
group "MainGroup"
test.createproject(wks)
group "MainGroup/SubGroup1"
test.createproject(wks)
group "MainGroup/SubGroup2"
test.createproject(wks)
test.createproject(wks)
end
local function prepare()
wks = test.getWorkspace(wks)
end
--
-- Groups should be added to workspace's PHONY
--
function suite.groupRule_groupAsPhony()
prepare()
make.workspacePhonyRule(wks)
test.capture [[
.PHONY: all clean help $(PROJECTS) MainGroup MainGroup/SubGroup1 MainGroup/SubGroup2
]]
end
--
-- Transform workspace groups into target aggregate
--
function suite.groupRule_groupRules()
prepare()
make.groupRules(wks)
test.capture [[
MainGroup: MainGroup/SubGroup1 MainGroup/SubGroup2 MyProject2
MainGroup/SubGroup1: MyProject3
MainGroup/SubGroup2: MyProject4 MyProject5
]]
end

View file

@ -0,0 +1,41 @@
--
-- tests/actions/make/test_help_rule.lua
-- Validate generation of help rule and configurations list.
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_help_rule")
--
-- Setup/teardown
--
local wks
function suite.setup()
wks = test.createWorkspace()
end
local function prepare()
wks = test.getWorkspace(wks)
p.make.helprule(wks)
end
--
-- Start with the default Debug and Release setup.
--
function suite.looksOkay_onDefaultSetup()
prepare()
test.capture [[
help:
@echo "Usage: make [config=name] [target]"
@echo ""
@echo "CONFIGURATIONS:"
@echo " debug"
@echo " release"
]]
end

View file

@ -0,0 +1,42 @@
--
-- tests/actions/make/workspace/test_project_rule.lua
-- Validate generation of project rules in workspace makefile.
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("make_project_rule")
--
-- Setup/teardown
--
local wks
function suite.setup()
wks = test.createWorkspace()
end
local function prepare()
p.oven.bake()
wks = test.getWorkspace(wks)
p.make.projectrules(wks)
end
--
-- Verify a simple project with no dependencies.
--
function suite.projectRule_onNoDependencies()
prepare()
test.capture [[
MyProject:
ifneq (,$(MyProject_config))
@echo "==== Building MyProject ($(MyProject_config)) ===="
@${MAKE} --no-print-directory -C . -f MyProject.make config=$(MyProject_config)
endif
]]
end