diff --git a/CHANGES.txt b/CHANGES.txt index 78e3a58b..a14f2453 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,6 +10,7 @@ * Bug 3138377: Link dependencies ignored within "SharedLib" configuration * Bug 3163703: pdb file being set in the wrong section. (hodsondd) * Bug 3157645: Full path for xcode frameworks +* Patch 3043933 gmake incorrectly links using -l when a solution contains a .so and .a of the same name and the static lib is wanted (Jonathan Derque) ------- 4.3 diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 1f5fc74e..771cd17c 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -174,7 +174,23 @@ function premake.gcc.getlinkflags(cfg) local result = { } - for _, value in ipairs(premake.getlinks(cfg, "all", "basename")) do + for _, value in ipairs(premake.getlinks(cfg, "dependencies", "object")) do + -- don't use "-llib" arguments when linking static libraries + if (value.kind == "StaticLib") then + local pathstyle = premake.getpathstyle(value) + local namestyle = premake.getnamestyle(value) + local linktarget = premake.gettarget(value, "link", pathstyle, namestyle, cfg.system) + table.insert(result, linktarget.fullpath) + else + if path.getextension(value.basename) == ".framework" then + table.insert(result, '-framework ' .. _MAKE.esc(path.getbasename(value.basename))) + else + table.insert(result, '-l' .. _MAKE.esc(value.basename)) + end + end + end + -- "-llib" is fine for system dependencies + for _, value in ipairs(premake.getlinks(cfg, "system", "basename")) do if path.getextension(value) == ".framework" then table.insert(result, '-framework ' .. _MAKE.esc(path.getbasename(value))) else diff --git a/tests/actions/make/test_make_linking.lua b/tests/actions/make/test_make_linking.lua new file mode 100644 index 00000000..dd9b26d0 --- /dev/null +++ b/tests/actions/make/test_make_linking.lua @@ -0,0 +1,43 @@ + + T.gcc_linking = { } + local suite = T.gcc_linking + + local staticPrj + local linksToStaticProj + + 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 + end + + local get_buffer = function() + io.capture() + premake.buildconfigs() + local cfg = premake.getconfig(linksToStaticProj, '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() + local format_exspected = 'LIBS %+%= bar/libstaticPrj.a' + test.string_contains(buffer,format_exspected) + end diff --git a/tests/premake4.lua b/tests/premake4.lua index 83b35add..be606ae5 100644 --- a/tests/premake4.lua +++ b/tests/premake4.lua @@ -77,6 +77,7 @@ -- Makefile tests dofile("actions/make/test_make_escaping.lua") dofile("actions/make/test_make_pch.lua") + dofile("actions/make/test_make_linking.lua") -- Xcode tests dofile("actions/xcode/test_xcode_common.lua")