Rework Gmake C++ exporter to use new extensibility conventions

This commit is contained in:
Jason Perkins 2013-08-11 14:22:24 -04:00
parent b18e8b7ccd
commit 99ce5cfbbf
13 changed files with 405 additions and 395 deletions

View File

@ -78,22 +78,6 @@
end
--
-- Output logic to detect the shell type at runtime.
--
function make.detectshell()
_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.
---
@ -168,17 +152,7 @@
-- it screws up the escaping of spaces and parethesis (anyone know a solution?)
--
function make.copyrule(source, target)
_p('%s: %s', target, source)
_p('\t@echo Copying $(notdir %s)', target)
_p('ifeq (posix,$(SHELLTYPE))')
_p('\t$(SILENT) cp -fR %s %s', source, target)
_p('else')
_p('\t$(SILENT) copy /Y $(subst /,\\\\,%s) $(subst /,\\\\,%s)', source, target)
_p('endif')
end
function make.mkdirrule(dirname)
function make.mkdirRules(dirname)
_p('%s:', dirname)
_p('\t@echo Creating %s', dirname)
_p('ifeq (posix,$(SHELLTYPE))')
@ -204,9 +178,83 @@
--
-- Write out raw makefile rules for a configuration.
-- 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', 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.preBuildCmds(cfg, toolset)
_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')
end
function make.preBuildRules(prj)
_p('prebuild:')
_p('\t$(PREBUILDCMDS)')
_p('')
end
function make.preLinkCmds(cfg, toolset)
_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')
end
function make.preLinkRules(prj)
_p('prelink:')
_p('\t$(PRELINKCMDS)')
_p('')
end
function make.postBuildCmds(cfg, toolset)
_p(' define POSTBUILDCMDS')
if #cfg.postbuildcommands > 0 then
_p('\t@echo Running post-build commands')
_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
end
_p(' endef')
end
function make.settings(cfg, toolset)
if #cfg.makesettings > 0 then
for _, value in ipairs(cfg.makesettings) do
@ -221,26 +269,24 @@
end
--
-- Output the main target variables: target directory, target name,
-- and objects (or intermediate files) directory. These values are
-- common across both C++ and C# projects.
--
function make.targetconfig(cfg)
local targetdir =
_x(' TARGETDIR = %s', project.getrelative(cfg.project, cfg.buildtarget.directory))
_x(' TARGET = $(TARGETDIR)/%s', cfg.buildtarget.name)
_x(' OBJDIR = %s', project.getrelative(cfg.project, cfg.objdir))
function make.shellType()
_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
--
-- Convert an arbitrary string (project name) to a make variable name.
--
function make.tovar(value)
value = value:gsub("[ -]", "_")
value = value:gsub("[()]", "")
return value
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

View File

@ -1,7 +1,7 @@
--
-- make_cpp.lua
-- Generate a C/C++ project makefile.
-- Copyright (c) 2002-2012 Jason Perkins and the Premake project
-- Copyright (c) 2002-2013 Jason Perkins and the Premake project
--
premake.make.cpp = {}
@ -12,68 +12,36 @@
local fileconfig = premake5.fileconfig
---
-- Add namespace for element definition lists for premake.callarray()
---
cpp.elements = {}
--
-- Generate a GNU make C++ project makefile, with support for the new platforms API.
--
cpp.elements.makefile = {
"header",
"phonyRules",
"cppConfigs",
"cppObjects",
"shellType",
"cppTargetRules",
"targetDirRules",
"objDirRules",
"cppCleanRules",
"preBuildRules",
"preLinkRules",
"pchRules",
"cppFileRules",
"cppDependencies",
}
function make.cpp.generate(prj)
make.header(prj)
-- main build rule(s)
_p('.PHONY: clean prebuild prelink')
_p('')
for cfg in project.eachconfig(prj) do
cpp.config(cfg)
end
-- list intermediate files
cpp.objects(prj)
make.detectshell()
-- common build target rules
_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
_p('\t@echo Linking %s', prj.name)
_p('\t$(SILENT) $(LINKCMD)')
_p('\t$(POSTBUILDCMDS)')
_p('')
make.mkdirrule("$(TARGETDIR)")
make.mkdirrule("$(OBJDIR)")
-- clean target
_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('')
-- custom build step targets
_p('prebuild:')
_p('\t$(PREBUILDCMDS)')
_p('')
_p('prelink:')
_p('\t$(PRELINKCMDS)')
_p('')
-- precompiler header rule
cpp.pchrules(prj)
-- file building rules
cpp.filerules(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')
premake.callarray(make, cpp.elements.makefile, prj)
end
@ -81,61 +49,44 @@
-- Write out the settings for a particular configuration.
--
function cpp.config(cfg)
-- identify the toolset used by this configurations
local toolset = premake.tools[cfg.toolset or "gcc"]
if not toolset then
error("Invalid toolset '" + cfg.toolset + "'")
cpp.elements.configuration = {
"cppTools",
"target",
"objdir",
"defines",
"includes",
"forceIncludes",
"cppFlags",
"cFlags",
"cxxFlags",
"resFlags",
"pch",
"libs",
"ldDeps",
"ldFlags",
"linkCmd",
"preBuildCmds",
"preLinkCmds",
"postBuildCmds",
"cppAllRules",
"settings",
}
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 = premake.tools[cfg.toolset or "gcc"]
if not toolset then
error("Invalid toolset '" + cfg.toolset + "'")
end
_x('ifeq ($(config),%s)', cfg.shortname)
premake.callarray(make, cpp.elements.configuration, cfg, toolset)
_p('endif')
_p('')
end
_x('ifeq ($(config),%s)', cfg.shortname)
-- write toolset specific configurations
cpp.toolconfig(cfg, toolset)
-- write target information (target dir, name, obj dir)
make.targetconfig(cfg)
-- write flags
cpp.flags(cfg, toolset)
-- set up precompiled headers
cpp.pchconfig(cfg)
-- write the link step
cpp.linkconfig(cfg, toolset)
-- write the custom build commands
_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"))
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
@ -154,7 +105,7 @@
-- Output the list of file building rules.
--
function cpp.filerules(prj)
function make.cppFileRules(prj)
local tr = project.getsourcetree(prj)
premake.tree.traverse(tr, {
onleaf = function(node, depth)
@ -171,16 +122,16 @@
-- if it has custom rules, need to break them out
-- into individual configurations
if rules then
cpp.customfilerules(prj, node)
cpp.customFileRules(prj, node)
else
cpp.standardfilerules(prj, node)
cpp.standardFileRules(prj, node)
end
end
})
_p('')
end
function cpp.standardfilerules(prj, node)
function cpp.standardFileRules(prj, node)
-- C/C++ file
if path.iscppfile(node.abspath) then
_x('$(OBJDIR)/%s.o: %s', node.objname, node.relpath)
@ -195,7 +146,7 @@
end
end
function cpp.customfilerules(prj, node)
function cpp.customFileRules(prj, node)
for cfg in project.eachconfig(prj) do
local filecfg = fileconfig.getconfig(node, cfg)
if filecfg then
@ -213,66 +164,11 @@
end
--
-- Compile flags
--
function cpp.flags(cfg, toolset)
_p(' DEFINES +=%s', make.list(toolset.getdefines(cfg.defines)))
local includes = premake.esc(toolset.getincludedirs(cfg, cfg.includedirs))
_p(' INCLUDES +=%s', make.list(includes))
includes = toolset.getforceincludes(cfg)
_x(' FORCE_INCLUDE +=%s', make.list(includes))
_p(' ALL_CPPFLAGS += $(CPPFLAGS)%s $(DEFINES) $(INCLUDES) $(FORCE_INCLUDE)', make.list(toolset.getcppflags(cfg)))
_p(' ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)%s', make.list(table.join(toolset.getcflags(cfg), cfg.buildoptions)))
_p(' ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)%s', make.list(toolset.getcxxflags(cfg)))
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
--
-- Link step
--
function cpp.linkconfig(cfg, toolset)
_p(' ALL_LDFLAGS += $(LDFLAGS)%s', make.list(table.join(toolset.getldflags(cfg), cfg.linkoptions)))
local flags = toolset.getlinks(cfg)
_p(' LIBS +=%s', make.list(flags))
local deps = config.getlinks(cfg, "siblings", "fullpath")
_p(' LDDEPS +=%s', make.list(premake.esc(deps)))
if cfg.kind == premake.STATICLIB then
if cfg.architecture == premake.UNIVERSAL then
_p(' LINKCMD = libtool -o $(TARGET) $(OBJECTS)')
else
_p(' LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS)')
end
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(cfg.language == "C", "CC", "CXX")
_p(' LINKCMD = $(%s) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)', cc)
end
end
--
-- List the objects file for the project, and each configuration.
--
function cpp.objects(prj)
function make.cppObjects(prj)
-- create lists for intermediate files, at the project level and
-- for each configuration
local root = { objects={}, resources={} }
@ -376,15 +272,147 @@
end
---------------------------------------------------------------------------
--
-- Precompiled header support
-- Handlers for individual makefile elements
--
---------------------------------------------------------------------------
function cpp.pchconfig(cfg)
function make.cFlags(cfg, toolset)
_p(' ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)%s', make.list(table.join(toolset.getcflags(cfg), cfg.buildoptions)))
end
function make.cppAllRules(cfg, toolset)
if cfg.system == premake.MACOSX and cfg.kind == premake.WINDOWEDAPP then
_p('all: $(TARGETDIR) $(OBJDIR) 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: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
_p('\t@:')
end
end
function make.cppFlags(cfg, toolset)
_p(' ALL_CPPFLAGS += $(CPPFLAGS)%s $(DEFINES) $(INCLUDES) $(FORCE_INCLUDE)', make.list(toolset.getcppflags(cfg)))
end
function make.cxxFlags(cfg, toolset)
_p(' ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)%s', make.list(toolset.getcxxflags(cfg)))
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) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
_p('\t@echo Linking %s', prj.name)
_p('\t$(SILENT) $(LINKCMD)')
_p('\t$(POSTBUILDCMDS)')
_p('')
end
function make.cppTools(cfg, toolset)
local tool = toolset.gettoolname(cfg, "cc")
if tool then
_p(' CC = %s', tool)
end
tool = toolset.gettoolname(cfg, "cxx")
if tool then
_p(' CXX = %s', tool)
end
tool = toolset.gettoolname(cfg, "ar")
if tool then
_p(' AR = %s', tool)
end
end
function make.defines(cfg, toolset)
_p(' DEFINES +=%s', make.list(toolset.getdefines(cfg.defines)))
end
function make.forceIncludes(cfg, toolset)
local includes = toolset.getforceincludes(cfg)
_x(' FORCE_INCLUDE +=%s', make.list(includes))
end
function make.includes(cfg, toolset)
local includes = premake.esc(toolset.getincludedirs(cfg, cfg.includedirs))
_p(' INCLUDES +=%s', make.list(includes))
end
function make.ldDeps(cfg, toolset)
local deps = config.getlinks(cfg, "siblings", "fullpath")
_p(' LDDEPS +=%s', make.list(premake.esc(deps)))
end
function make.ldFlags(cfg, toolset)
_p(' ALL_LDFLAGS += $(LDFLAGS)%s', make.list(table.join(toolset.getldflags(cfg), cfg.linkoptions)))
end
function make.libs(cfg, toolset)
local flags = toolset.getlinks(cfg)
_p(' LIBS +=%s', make.list(flags))
end
function make.linkCmd(cfg, toolset)
if cfg.kind == premake.STATICLIB then
if cfg.architecture == premake.UNIVERSAL then
_p(' LINKCMD = libtool -o $(TARGET) $(OBJECTS)')
else
_p(' LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS)')
end
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(cfg.language == "C", "CC", "CXX")
_p(' LINKCMD = $(%s) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)', cc)
end
end
function make.pch(cfg, toolset)
if not cfg.flags.NoPCH and cfg.pchheader then
-- Visual Studio needs the PCH path to match the way it appears in
-- the project's #include statement. GCC needs the full path. Assume
-- the #include path is given, is search the include dirs for it.
-- Try to locate the header on the include search paths
local pchheader = cfg.pchheader
for _, incdir in ipairs(cfg.includedirs) do
local testname = path.join(incdir, cfg.pchheader)
@ -395,13 +423,13 @@
end
local gch = path.getname(pchheader)
_x(' PCH = %s', project.getrelative(cfg.project, pchheader))
_x(' GCH = $(OBJDIR)/%s.gch', gch)
_x(' PCH = %s', project.getrelative(cfg.project, pchheader))
_x(' GCH = $(OBJDIR)/%s.gch', gch)
_x(' ALL_CPPFLAGS += -I$(OBJDIR) -include $(OBJDIR)/%s', gch)
end
end
function cpp.pchrules(prj)
function make.pchRules(prj)
_p('ifneq (,$(PCH))')
_p('$(GCH): $(PCH)')
_p('\t@echo $(notdir $<)')
@ -416,45 +444,7 @@
end
--
-- The main build target rules.
--
function cpp.targetrules(cfg)
local macapp = (cfg.system == premake.MACOSX and cfg.kind == premake.WINDOWEDAPP)
if macapp then
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
else
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
end
_p('\t@:')
if macapp then
_p('')
_p('$(dir $(TARGETDIR))PkgInfo:')
_p('$(dir $(TARGETDIR))Info.plist:')
end
end
--
-- System specific toolset configuration.
--
function cpp.toolconfig(cfg, toolset)
local tool = toolset.gettoolname(cfg, "cc")
if tool then
_p(' CC = %s', tool)
end
tool = toolset.gettoolname(cfg, "cxx")
if tool then
_p(' CXX = %s', tool)
end
tool = toolset.gettoolname(cfg, "ar")
if tool then
_p(' AR = %s', tool)
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

@ -60,7 +60,7 @@
_p('')
--]]
make.detectshell()
make.shellType()
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)')
_p('')
@ -70,8 +70,8 @@
_p('\t$(POSTBUILDCMDS)')
_p('')
make.mkdirrule("$(TARGETDIR)")
make.mkdirrule("$(OBJDIR)")
make.mkdirRules("$(TARGETDIR)")
make.mkdirRules("$(OBJDIR)")
-- clean target
local target = firstcfg.buildtarget
@ -144,7 +144,8 @@
cs.toolconfig(cfg, toolset)
-- write target information (target dir, name, obj dir)
make.targetconfig(cfg)
make.target(cfg)
make.objdir(cfg)
-- write flags
cs.flags(cfg, toolset)

View File

@ -67,7 +67,7 @@
for i = 1, n do
local fn = namespace[array[i]]
if not fn then
error(string.format("Unable to find function '%s'", name))
error(string.format("Unable to find function '%s'", array[i]))
end
fn(...)
end

View File

@ -14,13 +14,12 @@
-- Setup
--
local sln, prj, cfg
local sln, prj
function suite.setup()
sln = test.createsolution()
toolset "clang"
prj = premake.solution.getproject_ng(sln, 1)
cfg = project.getconfig(prj, "Debug")
end
@ -29,12 +28,12 @@
--
function suite.usesCorrectCompilers()
cpp.config(cfg)
make.cppConfigs(prj)
test.capture [[
ifeq ($(config),debug)
CC = clang
CXX = clang
AR = ar
CC = clang
CXX = clang
AR = ar
]]
end

View File

@ -1,12 +1,11 @@
--
-- tests/actions/make/cpp/test_file_rules.lua
-- Validate the makefile source building rules.
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
--
T.make_cpp_file_rules = { }
local suite = T.make_cpp_file_rules
local cpp = premake.make.cpp
local suite = test.declare("make_cpp_file_rules")
local make = premake.make
local project = premake5.project
@ -22,7 +21,7 @@
local function prepare()
prj = premake.solution.getproject_ng(sln, 1)
cpp.filerules(prj)
make.cppFileRules(prj)
end

View File

@ -1,13 +1,11 @@
--
-- tests/actions/make/cpp/test_flags.lua
-- Tests compiler and linker flags for Makefiles.
-- Copyright (c) 2012 Jason Perkins and the Premake project
-- Copyright (c) 2012-2013 Jason Perkins and the Premake project
--
T.make_flags = {}
local suite = T.make_flags
local suite = test.declare("make_flags")
local make = premake.make
local cpp = premake.make.cpp
local project = premake5.project
@ -15,16 +13,16 @@
-- Setup
--
local sln, prj, cfg
local sln, prj
function suite.setup()
sln = test.createsolution()
sln, prj = test.createsolution()
end
local function prepare()
prj = premake.solution.getproject_ng(sln, 1)
cfg = project.getconfig(prj, "Debug")
cpp.flags(cfg, premake.tools.gcc)
local function prepare(calls)
local cfg = project.getconfig(prj, "Debug")
local toolset = premake.tools.gcc
premake.callarray(make, calls, cfg, toolset)
end
@ -34,9 +32,8 @@
function suite.includeDirs()
includedirs { "src/include", "../include" }
prepare()
prepare { "includes" }
test.capture [[
DEFINES +=
INCLUDES += -I"src/include" -I"../include"
INCLUDES += -I"src/include" -I"../include"
]]
end

View File

@ -4,9 +4,8 @@
-- Copyright (c) 2010-2013 Jason Perkins and the Premake project
--
T.make_linking = { }
local suite = T.make_linking
local cpp = premake.make.cpp
local suite = test.declare("make_linking")
local make = premake.make
local project = premake5.project
@ -21,9 +20,10 @@
sln, prj = test.createsolution()
end
local function prepare()
local function prepare(calls)
local cfg = project.getconfig(prj, "Debug")
cpp.linkconfig(cfg, premake.tools.gcc)
local toolset = premake.tools.gcc
premake.callarray(make, calls, cfg, toolset)
end
@ -33,12 +33,10 @@
function suite.links_onCppSharedLib()
kind "SharedLib"
prepare()
prepare { "ldFlags", "linkCmd" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s -shared
LIBS +=
LDDEPS +=
LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
ALL_LDFLAGS += $(LDFLAGS) -s -shared
LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
]]
end
@ -50,12 +48,10 @@
function suite.links_onCSharedLib()
language "C"
kind "SharedLib"
prepare()
prepare { "ldFlags", "linkCmd" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s -shared
LIBS +=
LDDEPS +=
LINKCMD = $(CC) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
ALL_LDFLAGS += $(LDFLAGS) -s -shared
LINKCMD = $(CC) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
]]
end
@ -66,11 +62,10 @@
function suite.links_onStaticLib()
kind "StaticLib"
prepare()
prepare { "ldFlags", "linkCmd" }
test.capture [[
LIBS +=
LDDEPS +=
LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS)
ALL_LDFLAGS += $(LDFLAGS) -s
LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS)
]]
end
@ -79,15 +74,13 @@
-- Check link command for a Mac OS X universal static library.
--
function suite.links_onStaticLib()
function suite.links_onMacUniversalStaticLib()
architecture "universal"
kind "StaticLib"
prepare()
prepare { "ldFlags", "linkCmd" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s
LIBS +=
LDDEPS +=
LINKCMD = libtool -o $(TARGET) $(OBJECTS)
ALL_LDFLAGS += $(LDFLAGS) -s
LINKCMD = libtool -o $(TARGET) $(OBJECTS)
]]
end
@ -103,11 +96,11 @@
kind "StaticLib"
location "build"
prepare()
prepare { "ldFlags", "libs", "ldDeps" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s
LIBS += build/libMyProject2.a
LDDEPS += build/libMyProject2.a
ALL_LDFLAGS += $(LDFLAGS) -s
LIBS += build/libMyProject2.a
LDDEPS += build/libMyProject2.a
]]
end
@ -123,11 +116,11 @@
kind "SharedLib"
location "build"
prepare()
prepare { "ldFlags", "libs", "ldDeps" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s
LIBS += build/libMyProject2.so
LDDEPS += build/libMyProject2.so
ALL_LDFLAGS += $(LDFLAGS) -s
LIBS += build/libMyProject2.so
LDDEPS += build/libMyProject2.so
]]
end
@ -140,10 +133,9 @@
function suite.onExternalLibraryWithPath()
location "MyProject"
links { "libs/SomeLib" }
prepare()
prepare { "ldFlags", "libs" }
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -L../libs -s
LIBS += -lSomeLib
LDDEPS +=
ALL_LDFLAGS += $(LDFLAGS) -L../libs -s
LIBS += -lSomeLib
]]
end

View File

@ -1,12 +1,11 @@
--
-- tests/actions/make/cpp/test_make_pch.lua
-- Validate the setup for precompiled headers in makefiles.
-- Copyright (c) 2010-2012 Jason Perkins and the Premake project
-- Copyright (c) 2010-2013 Jason Perkins and the Premake project
--
T.make_pch = { }
local suite = T.make_pch
local cpp = premake.make.cpp
local suite = test.declare("make_pch")
local make = premake.make
local project = premake5.project
@ -20,8 +19,14 @@
sln, prj = test.createsolution()
end
local function prepare()
local function prepareVars()
cfg = project.getconfig(prj, "Debug")
make.pch(cfg)
end
local function prepareRules()
cfg = project.getconfig(prj, "Debug")
make.pchRules(cfg.project)
end
@ -30,8 +35,7 @@
--
function suite.noConfig_onNoHeaderSet()
prepare()
cpp.pchconfig(cfg)
prepareVars()
test.isemptycapture()
end
@ -44,8 +48,7 @@
function suite.noConfig_onHeaderAndNoPCHFlag()
pchheader "include/myproject.h"
flags "NoPCH"
prepare()
cpp.pchconfig(cfg)
prepareVars()
test.isemptycapture()
end
@ -57,12 +60,10 @@
function suite.config_onPchEnabled()
pchheader "include/myproject.h"
prepare()
cpp.pchconfig(cfg)
prepareVars()
test.capture [[
PCH = include/myproject.h
GCH = $(OBJDIR)/myproject.h.gch
ALL_CPPFLAGS += -I$(OBJDIR) -include $(OBJDIR)/myproject.h
PCH = include/myproject.h
GCH = $(OBJDIR)/myproject.h.gch
]]
end
@ -74,12 +75,10 @@
function suite.pch_searchesIncludeDirs()
pchheader "premake.h"
includedirs { "../src/host" }
prepare()
cpp.pchconfig(cfg)
prepareVars()
test.capture [[
PCH = ../src/host/premake.h
GCH = $(OBJDIR)/premake.h.gch
ALL_CPPFLAGS += -I$(OBJDIR) -include $(OBJDIR)/premake.h
PCH = ../src/host/premake.h
GCH = $(OBJDIR)/premake.h.gch
]]
end
@ -90,8 +89,7 @@
function suite.buildRules_onCpp()
pchheader "include/myproject.h"
prepare()
cpp.pchrules(cfg.project)
prepareRules()
test.capture [[
ifneq (,$(PCH))
$(GCH): $(PCH)
@ -114,8 +112,7 @@ endif
function suite.buildRules_onC()
language "C"
pchheader "include/myproject.h"
prepare()
cpp.pchrules(cfg.project)
prepareRules()
test.capture [[
ifneq (,$(PCH))
$(GCH): $(PCH)

View File

@ -5,7 +5,7 @@
--
local suite = test.declare("make_cpp_objects")
local cpp = premake.make.cpp
local make = premake.make
local project = premake5.project
@ -21,7 +21,7 @@
local function prepare()
prj = premake.solution.getproject_ng(sln, 1)
cpp.objects(prj)
make.cppObjects(prj)
end

View File

@ -1,11 +1,10 @@
--
-- tests/actions/make/cpp/test_ps3.lua
-- Tests for PS3 support in makefiles.
-- Copyright (c) 2012 Jason Perkins and the Premake project
-- Copyright (c) 2012-2013 Jason Perkins and the Premake project
--
T.make_ps3 = {}
local suite = T.make_ps3
local suite = test.declare("make_ps3")
local make = premake.make
local cpp = premake.make.cpp
local project = premake5.project
@ -14,7 +13,7 @@
--
-- Setup
--
local sln, prj, cfg
function suite.setup()
@ -29,12 +28,12 @@
-- Make sure that the correct compilers are used.
--
function suite.usesCorrectCompilers()
cpp.toolconfig(cfg, premake.tools.gcc)
function suite.usesCorrectCompilers()
make.cppTools(cfg, premake.tools.gcc)
test.capture [[
CC = ppu-lv2-g++
CXX = ppu-lv2-g++
AR = ppu-lv2-ar
CC = ppu-lv2-g++
CXX = ppu-lv2-g++
AR = ppu-lv2-ar
]]
end
@ -44,10 +43,9 @@
--
function suite.usesCorrectTarget()
make.targetconfig(cfg)
make.target(cfg)
test.capture [[
TARGETDIR = .
TARGET = $(TARGETDIR)/MyProject.elf
OBJDIR = obj/Debug
TARGETDIR = .
TARGET = $(TARGETDIR)/MyProject.elf
]]
end

View File

@ -1,28 +1,27 @@
--
-- tests/actions/make/cpp/test_target_rules.lua
-- Validate the makefile target building rules.
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
--
T.make_cpp_target_rules = { }
local suite = T.make_cpp_target_rules
local cpp = premake.make.cpp
local suite = test.declare("make_cpp_target_rules")
local make = premake.make
local project = premake5.project
--
-- Setup
-- Setup
--
local sln, prj
function suite.setup()
sln, prj = test.createsolution()
end
local function prepare()
local cfg = project.getconfig(prj, "Debug")
cpp.targetrules(cfg)
make.cppAllRules(cfg)
end

View File

@ -4,10 +4,8 @@
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
--
T.make_wiidev = {}
local suite = T.make_wiidev
local suite = test.declare("make_wiidev")
local make = premake.make
local cpp = premake.make.cpp
local project = premake5.project
@ -28,23 +26,17 @@
-- Make sure that the Wii-specific flags are passed to the tools.
--
function suite.writesCorrectFlags()
cpp.flags(cfg, premake.tools.gcc)
function suite.writesCorrectCppFlags()
make.cppFlags(cfg, premake.tools.gcc)
test.capture [[
DEFINES +=
INCLUDES +=
FORCE_INCLUDE +=
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -I$(LIBOGC_INC) $(MACHDEP) $(DEFINES) $(INCLUDES) $(FORCE_INCLUDE)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
]]
end
function suite.writesCorrectLinkerFlags()
cpp.linkconfig(cfg, premake.tools.gcc)
make.ldFlags(cfg, premake.tools.gcc)
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s -L$(LIBOGC_LIB) $(MACHDEP)
ALL_LDFLAGS += $(LDFLAGS) -s -L$(LIBOGC_LIB) $(MACHDEP)
]]
end