diff options
author | Jason Perkins <starkos@industriousone.com> | 2013-01-24 22:19:06 +0400 |
---|---|---|
committer | Jason Perkins <starkos@industriousone.com> | 2013-01-24 22:19:06 +0400 |
commit | 53b6b39a8d1db9b6cabaf190c326a42064217266 (patch) | |
tree | fc1303ee86c8abfd9b6c12ddfc47506a5a3670df | |
parent | a3829657a1d29e7f863f8618414cf898cebf52a5 (diff) |
Clean up GMake link tests in preparation for a bug fix
-rw-r--r-- | CHANGES.txt | 1 | ||||
-rw-r--r-- | src/actions/make/_make.lua | 42 | ||||
-rw-r--r-- | src/actions/make/make_cpp.lua | 67 | ||||
-rw-r--r-- | tests/actions/make/test_make_linking.lua | 198 | ||||
-rw-r--r-- | tests/actions/make/test_wiidev.lua | 24 | ||||
-rw-r--r-- | tests/test_gmake_cpp.lua | 66 |
6 files changed, 212 insertions, 186 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 0cd4777..dfbc7ee 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -66,6 +66,7 @@ * Patch 3466877: Removed -flat_namespace from Mac OS X flags (Konstantin Tokarev) * Pull 25: Add Unix support to os.getversion() (wfgleper) * Bug 268: Target extension not set properly for Visual Studio 2010 +* Allow command line override of makefile flags (Cameron Hart) ------- diff --git a/src/actions/make/_make.lua b/src/actions/make/_make.lua index 0bf80f6..13facf2 100644 --- a/src/actions/make/_make.lua +++ b/src/actions/make/_make.lua @@ -26,13 +26,13 @@ result = result:gsub(" ", "\\ ") result = result:gsub("%(", "\\%(") result = result:gsub("%)", "\\%)") - + -- leave $(...) shell replacement sequences alone result = result:gsub("$\\%((.-)\\%)", "$%(%1%)") return result end end - + -- @@ -59,8 +59,20 @@ _p('endif') _p('') end - - + + +-- +-- Format a list of values to be safely written as part of a variable assignment. +-- + + function make.list(value) + if #value > 0 then + return " " .. table.concat(value, " ") + else + return "" + end + end + -- -- Get the makefile file name for a solution or a project. If this object is the @@ -79,14 +91,14 @@ end end end - + if (count == 1) then return "Makefile" else return this.name .. ".make" end end - + -- -- Returns a list of object names, properly escaped to be included in the makefile. @@ -99,7 +111,7 @@ end return result end - + -- @@ -112,7 +124,7 @@ _p(value) end end - + local toolsettings = cc.platforms[cfg.platform].cfgsettings if toolsettings then _p(toolsettings) @@ -128,20 +140,20 @@ trigger = "gmake", shortname = "GNU Make", description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin", - + valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - + valid_languages = { "C", "C++", "C#" }, - + valid_tools = { cc = { "gcc" }, dotnet = { "mono", "msnet", "pnet" }, }, - + onsolution = function(sln) premake.generate(sln, _MAKE.getmakefilename(sln, false), premake.make_solution) end, - + onproject = function(prj) local makefile = _MAKE.getmakefilename(prj, true) if premake.isdotnetproject(prj) then @@ -150,11 +162,11 @@ premake.generate(prj, makefile, premake.make_cpp) end end, - + oncleansolution = function(sln) premake.clean.file(sln, _MAKE.getmakefilename(sln, false)) end, - + oncleanproject = function(prj) premake.clean.file(prj, _MAKE.getmakefilename(prj, true)) end diff --git a/src/actions/make/make_cpp.lua b/src/actions/make/make_cpp.lua index 7f9f6b2..8f34455 100644 --- a/src/actions/make/make_cpp.lua +++ b/src/actions/make/make_cpp.lua @@ -154,7 +154,7 @@ _p('CXX = %s', cc.cxx) _p('AR = %s', cc.ar) _p('') - + _p('ifndef RESCOMP') _p(' ifdef WINDRES') _p(' RESCOMP = $(WINDRES)') @@ -162,7 +162,7 @@ _p(' RESCOMP = windres') _p(' endif') _p('endif') - _p('') + _p('') end -- @@ -179,32 +179,18 @@ _p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir)) _p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory)) _p(' TARGET = $(TARGETDIR)/%s', _MAKE.esc(cfg.buildtarget.name)) - _p(' DEFINES += %s', table.concat(cc.getdefines(cfg.defines), " ")) - _p(' INCLUDES += %s', table.concat(cc.getincludedirs(cfg.includedirs), " ")) + _p(' DEFINES +=%s', make.list(cc.getdefines(cfg.defines))) + _p(' INCLUDES +=%s', make.list(cc.getincludedirs(cfg.includedirs))) - -- CPPFLAGS, CFLAGS, CXXFLAGS, LDFLAGS, and RESFLAGS + -- CPPFLAGS, CFLAGS, CXXFLAGS, and RESFLAGS cpp.flags(cfg, cc) + -- write out libraries, linker flags, and the link command + cpp.linker(cfg, cc) + -- set up precompiled headers cpp.pchconfig(cfg) - _p(' LIBS += %s', table.concat(cc.getlinkflags(cfg), " ")) - _p(' LDDEPS += %s', table.concat(_MAKE.esc(premake.getlinks(cfg, "siblings", "fullpath")), " ")) - - if cfg.kind == "StaticLib" then - if cfg.platform:startswith("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 so $(OBJECTS) moved up - -- then $(LDFLAGS) moved to end - -- https://sourceforge.net/tracker/?func=detail&aid=3430158&group_id=71616&atid=531880 - _p(' LINKCMD = $(%s) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(ALL_LDFLAGS)', iif(cfg.language == "C", "CC", "CXX")) - end - _p(' define PREBUILDCMDS') if #cfg.prebuildcommands > 0 then _p('\t@echo Running pre-build commands') @@ -258,15 +244,40 @@ function cpp.flags(cfg, cc) _p(' ALL_CPPFLAGS += $(CPPFLAGS) %s $(DEFINES) $(INCLUDES)', table.concat(cc.getcppflags(cfg), " ")) - _p(' ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) %s', table.concat(table.join(cc.getcflags(cfg), cfg.buildoptions), " ")) - _p(' ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) %s', table.concat(cc.getcxxflags(cfg), " ")) + _p(' ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)%s', make.list(table.join(cc.getcflags(cfg), cfg.buildoptions))) + _p(' ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)%s', make.list(cc.getcxxflags(cfg))) + + _p(' ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)%s', + make.list(table.join(cc.getdefines(cfg.resdefines), + cc.getincludedirs(cfg.resincludedirs), cfg.resoptions))) + end + + +-- +-- Linker settings, including the libraries to link, the linker flags, +-- and the linker command. +-- + function cpp.linker(cfg, cc) -- Patch #3401184 changed the order - _p(' ALL_LDFLAGS += $(LDFLAGS) %s', table.concat(table.join(cc.getlibdirflags(cfg), cc.getldflags(cfg), cfg.linkoptions), " ")) + _p(' ALL_LDFLAGS += $(LDFLAGS)%s', make.list(table.join(cc.getlibdirflags(cfg), cc.getldflags(cfg), cfg.linkoptions))) - _p(' RESFLAGS += $(DEFINES) $(INCLUDES) %s', - table.concat(table.join(cc.getdefines(cfg.resdefines), - cc.getincludedirs(cfg.resincludedirs), cfg.resoptions), " ")) + _p(' LIBS +=%s', make.list(cc.getlinkflags(cfg))) + _p(' LDDEPS +=%s', make.list(_MAKE.esc(premake.getlinks(cfg, "siblings", "fullpath")))) + + if cfg.kind == "StaticLib" then + if cfg.platform:startswith("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 so $(OBJECTS) moved up + -- then $(LDFLAGS) moved to end + -- https://sourceforge.net/tracker/?func=detail&aid=3430158&group_id=71616&atid=531880 + _p(' LINKCMD = $(%s) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(ALL_LDFLAGS)', iif(cfg.language == "C", "CC", "CXX")) + end end diff --git a/tests/actions/make/test_make_linking.lua b/tests/actions/make/test_make_linking.lua index 7a346e6..f9d9c5d 100644 --- a/tests/actions/make/test_make_linking.lua +++ b/tests/actions/make/test_make_linking.lua @@ -1,112 +1,108 @@ - - T.gcc_linking = { } +-- +-- tests/actions/make/test_make_linking.lua +-- Validate library references in makefiles. +-- Copyright (c) 2010-2013 Jason Perkins and the Premake project +-- + + T.gcc_linking = {} local suite = T.gcc_linking - - local staticPrj - local linksToStaticProj - local sln - + local cpp = premake.make.cpp + +-- +-- Setup +-- + + local sln, prj + function suite.setup() - _ACTION = "gmake" - - sln = solution "MySolution" - configurations { "Debug" } - platforms {} - - staticPrj = project "staticPrj" - targetdir 'bar' - language 'C++' - kind "StaticLib" - - linksToStaticProj = project "linksToStaticProj" - language 'C++' - kind 'ConsoleApp' - links{'staticPrj'} - end - - function suite.teardown() - staticPrj = nil - linksToStaticProj = nil - sln = nil + _OS = "linux" + sln, prj = test.createsolution() end - - local get_buffer = function(projectName) - io.capture() + + local function prepare() premake.bake.buildconfigs() - local cfg = premake.getconfig(projectName, 'Debug', 'Native') - premake.gmake_cpp_config(cfg, premake.gcc) - local buffer = io.endcapture() - return buffer - end - - function suite.projectLinksToStaticPremakeMadeLibrary_linksUsingTheFormat_pathNameExtension() - local buffer = get_buffer(linksToStaticProj) - local format_exspected = 'LIBS %+%= bar/libstaticPrj.a' - test.string_contains(buffer,format_exspected) + cfg = premake.getconfig(prj, "Debug") + cpp.linker(cfg, premake.gcc) end - T.link_suite= { } - local firstProject = nil - local linksToFirstProject = nil - - function T.link_suite.setup() - _ACTION = "gmake" - solution('dontCareSolution') - configurations{'Debug'} - end - - function T.link_suite.teardown() - _ACTION = nil - firstProject = nil - linksToFirstProject = nil + +-- +-- Check linking to a shared library sibling project. Should add the library +-- path using -L, and link using the base name with -l flag. +-- + + function suite.onSharedLibrarySibling() + links { "MyProject2" } + test.createproject(sln) + kind "SharedLib" + targetdir "libs" + prepare() + test.capture [[ + ALL_LDFLAGS += $(LDFLAGS) -Llibs -s + LIBS += -lMyProject2 + LDDEPS += libs/libMyProject2.so + ]] end - - function T.link_suite.projectLinksToSharedPremakeMadeLibrary_linksUsingFormat_dashLName() - - firstProject = project 'firstProject' - kind 'SharedLib' - language 'C' - - linksToFirstProject = project 'linksToFirstProject' - kind 'ConsoleApp' - language 'C' - links{'firstProject'} - - local buffer = get_buffer(linksToFirstProject) - local format_exspected = 'LIBS %+%= %-lfirstProject' - test.string_contains(buffer,format_exspected) + + +-- +-- Check linking to a static library sibling project. Should use the full +-- decorated library name, relative path, and no -l flag. +-- + + function suite.onStaticLibrarySibling() + links { "MyProject2" } + test.createproject(sln) + kind "StaticLib" + targetdir "libs" + prepare() + test.capture [[ + ALL_LDFLAGS += $(LDFLAGS) -Llibs -s + LIBS += libs/libMyProject2.a + LDDEPS += libs/libMyProject2.a + ]] end - - function T.link_suite.projectLinksToPremakeMadeConsoleApp_doesNotLinkToConsoleApp() - - firstProject = project 'firstProject' - kind 'ConsoleApp' - language 'C' - - linksToFirstProject = project 'linksToFirstProject' - kind 'ConsoleApp' - language 'C' - links{'firstProject'} - - local buffer = get_buffer(linksToFirstProject) - local format_exspected = 'LIBS %+%=%s+\n' - test.string_contains(buffer,format_exspected) + + +-- +-- If an executable is listed in the links, no linking should happen (a +-- build dependency would have been created at the solution level) +-- + + function suite.onConsoleAppSibling() + links { "MyProject2" } + test.createproject(sln) + kind "ConsoleApp" + targetdir "libs" + prepare() + test.capture [[ + ALL_LDFLAGS += $(LDFLAGS) -s + LIBS += + LDDEPS += + ]] end - - function T.link_suite.projectLinksToStaticPremakeMadeLibrary_projectDifferInDirectoryHeights_linksUsingCorrectRelativePath() - - firstProject = project 'firstProject' - kind 'StaticLib' - language 'C' - - linksToFirstProject = project 'linksToFirstProject' - kind 'ConsoleApp' - language 'C' - links{'firstProject'} - location './foo/bar' - - local buffer = get_buffer(linksToFirstProject) - local format_exspected = 'LIBS %+%= ../../libfirstProject.a' - test.string_contains(buffer,format_exspected) + + +-- +-- Make sure that project locations are taken into account when building +-- the path to the library. +-- + + + function suite.onProjectLocations() + location "MyProject" + links { "MyProject2" } + + test.createproject(sln) + kind "SharedLib" + location "MyProject2" + targetdir "MyProject2" + + prepare() + test.capture [[ + ALL_LDFLAGS += $(LDFLAGS) -L../MyProject2 -s + LIBS += -lMyProject2 + LDDEPS += ../MyProject2/libMyProject2.so + ]] end diff --git a/tests/actions/make/test_wiidev.lua b/tests/actions/make/test_wiidev.lua index 4561b0c..f3787a0 100644 --- a/tests/actions/make/test_wiidev.lua +++ b/tests/actions/make/test_wiidev.lua @@ -3,23 +3,23 @@ -- Tests for Wii homebrew support in makefiles. -- Copyright (c) 2011 Jason Perkins and the Premake project -- - + T.make_wiidev = { } local suite = T.make_wiidev local make = premake.make local cpp = premake.make.cpp - + local sln, prj, cfg - + function suite.setup() _ACTION = "gmake" sln = solution("MySolution") configurations { "Debug", "Release" } - platforms { "WiiDev" } - + platforms { "WiiDev" } + prj = project("MyProject") - + premake.bake.buildconfigs() cfg = premake.getconfig(prj, "Debug", "WiiDev") end @@ -33,10 +33,16 @@ cpp.flags(cfg, premake.gcc) test.capture [[ ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -I$(LIBOGC_INC) $(MACHDEP) -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + ]] + end + + function suite.writesCorrectLinkFlags() + cpp.linker(cfg, premake.gcc) + test.capture [[ ALL_LDFLAGS += $(LDFLAGS) -s -L$(LIBOGC_LIB) $(MACHDEP) - RESFLAGS += $(DEFINES) $(INCLUDES) ]] end diff --git a/tests/test_gmake_cpp.lua b/tests/test_gmake_cpp.lua index d87a1bf..4a6992e 100644 --- a/tests/test_gmake_cpp.lua +++ b/tests/test_gmake_cpp.lua @@ -18,16 +18,16 @@ sln = solution "MySolution" configurations { "Debug", "Release" } platforms { "native" } - + prj = project "MyProject" language "C++" - kind "ConsoleApp" + kind "ConsoleApp" end local function prepare() premake.bake.buildconfigs() end - + -- @@ -60,9 +60,9 @@ ifndef RESCOMP endif ]] end - - - + + + -- -- Test configuration blocks -- @@ -76,15 +76,15 @@ ifeq ($(config),debug) OBJDIR = obj/Debug TARGETDIR = . TARGET = $(TARGETDIR)/MyProject - DEFINES += - INCLUDES += + DEFINES += + INCLUDES += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_LDFLAGS += $(LDFLAGS) -s - RESFLAGS += $(DEFINES) $(INCLUDES) - LIBS += - LDDEPS += + LIBS += + LDDEPS += LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(ALL_LDFLAGS) define PREBUILDCMDS endef @@ -95,7 +95,7 @@ ifeq ($(config),debug) endif ]] end - + function T.gmake_cpp.BasicCfgBlockWithPlatformCc() platforms { "ps3" } @@ -110,15 +110,15 @@ ifeq ($(config),debugps3) OBJDIR = obj/PS3/Debug TARGETDIR = . TARGET = $(TARGETDIR)/MyProject.elf - DEFINES += - INCLUDES += + DEFINES += + INCLUDES += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_LDFLAGS += $(LDFLAGS) -s - RESFLAGS += $(DEFINES) $(INCLUDES) - LIBS += - LDDEPS += + LIBS += + LDDEPS += LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(ALL_LDFLAGS) define PREBUILDCMDS endef @@ -141,15 +141,15 @@ ifeq ($(config),debug64) OBJDIR = obj/x64/Debug TARGETDIR = . TARGET = $(TARGETDIR)/MyProject - DEFINES += - INCLUDES += + DEFINES += + INCLUDES += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -m64 - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_LDFLAGS += $(LDFLAGS) -s -m64 -L/usr/lib64 - RESFLAGS += $(DEFINES) $(INCLUDES) - LIBS += - LDDEPS += + LIBS += + LDDEPS += LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(ALL_LDFLAGS) define PREBUILDCMDS endef @@ -173,15 +173,15 @@ ifeq ($(config),debuguniv32) OBJDIR = obj/Universal32/Debug TARGETDIR = . TARGET = $(TARGETDIR)/libMyProject.a - DEFINES += - INCLUDES += + DEFINES += + INCLUDES += ALL_CPPFLAGS += $(CPPFLAGS) $(DEFINES) $(INCLUDES) ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -arch i386 -arch ppc - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_LDFLAGS += $(LDFLAGS) -s -arch i386 -arch ppc - RESFLAGS += $(DEFINES) $(INCLUDES) - LIBS += - LDDEPS += + LIBS += + LDDEPS += LINKCMD = libtool -o $(TARGET) $(OBJECTS) define PREBUILDCMDS endef |