From 5761e86cb6d27f047b470ce1f7d8966086d7f0eb Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Tue, 28 Feb 2012 16:15:46 -0500 Subject: [PATCH] Ported GCC and SNC linker flag generation to new tool APIs --- src/actions/vstudio/vs200x_vcproj.lua | 4 +-- src/project/config.lua | 18 +++++----- src/tools/gcc.lua | 34 +++++++++++++++++++ src/tools/snc.lua | 14 ++++++++ .../vstudio/vc200x/test_external_compiler.lua | 2 ++ .../vstudio/vc200x/test_external_linker.lua | 17 ++++++++++ tests/tools/test_gcc.lua | 33 ++++++++++++++++++ tests/tools/test_snc.lua | 12 +++++++ 8 files changed, 123 insertions(+), 11 deletions(-) diff --git a/src/actions/vstudio/vs200x_vcproj.lua b/src/actions/vstudio/vs200x_vcproj.lua index 68ea186b..d67486c7 100644 --- a/src/actions/vstudio/vs200x_vcproj.lua +++ b/src/actions/vstudio/vs200x_vcproj.lua @@ -424,7 +424,7 @@ end if #cfg.links > 0 then - _x(4,'AdditionalDependencies="%s"', table.concat(config.getlinks(cfg, "all", "fullpath"), " ")) + _x(4,'AdditionalDependencies="%s"', table.concat(toolset.getlinks(cfg), " ")) end _x(4,'OutputFile="$(OutDir)\\%s"', config.gettargetinfo(cfg).name) @@ -674,7 +674,7 @@ -- vc200x.toolsets = { - ps3 = premake.snc + ps3 = premake.tools.snc } diff --git a/src/project/config.lua b/src/project/config.lua index 9dc815fc..0aa3dc14 100755 --- a/src/project/config.lua +++ b/src/project/config.lua @@ -29,8 +29,6 @@ local basedir = project.getlocation(cfg.project) local directory = cfg[field.."dir"] or cfg.targetdir or basedir - directory = project.getrelative(cfg.project, directory) - local basename = cfg[field.."name"] or cfg.targetname or cfg.project.name local bundlename = "" @@ -44,8 +42,7 @@ -- Mac .app requires more logic than I can bundle up in a table right now if cfg.system == premake.MACOSX and kind == premake.WINDOWEDAPP then bundlename = basename .. ".app" - bundlepath = path.join(directory, bundlename) - bundlepath = path.join(bundlepath, "Contents/MacOS") + bundlepath = path.join(bundlename, "Contents/MacOS") end prefix = cfg[field.."prefix"] or cfg.targetprefix or prefix @@ -53,13 +50,14 @@ extension = cfg[field.."extension"] or cfg.targetextension or extension local info = {} - info.directory = directory + info.directory = project.getrelative(cfg.project, directory) info.basename = prefix .. basename .. suffix info.name = info.basename .. extension info.extension = extension + info.abspath = path.join(directory, info.name) info.fullpath = path.join(info.directory, info.name) info.bundlename = bundlename - info.bundlepath = bundlepath + info.bundlepath = path.join(info.directory, bundlepath) info.prefix = prefix info.suffix = suffix return info @@ -103,7 +101,8 @@ -- extension - the file extension -- prefix - the file name prefix -- suffix - the file name suffix --- fullpath - directory, name, and extension +-- fullpath - directory, name, and extension relative to project +-- abspath - absolute directory, name, and extension -- function config.getlinkinfo(cfg) @@ -125,7 +124,7 @@ local info = buildtargetinfo(cfg, kind, field) -- cache the results for future calls - cfg.linktinfo = info + cfg.linkinfo = info return info end @@ -258,7 +257,8 @@ -- extension - the file extension -- prefix - the file name prefix -- suffix - the file name suffix --- fullpath - directory, name, and extension +-- fullpath - directory, name, and extension, relative to project +-- abspath - absolute directory, name, and extension -- bundlepath - the relative path and file name of the bundle -- diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 42d3e31f..14c0177f 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -6,6 +6,7 @@ premake.tools.gcc = {} local gcc = premake.tools.gcc + local project = premake5.project local config = premake5.config @@ -130,6 +131,39 @@ end +-- +-- Return the list of libraries to link, decorated with flags as needed. +-- + + function gcc.getlinks(cfg) + local result = {} + + local links = config.getlinks(cfg, "siblings", "object") + for _, link in ipairs(links) do + if link.kind == premake.STATICLIB then + -- Don't use "-l" flag when linking static libraries; instead use + -- path/libname.a to avoid linking a shared library of the same + -- name if one is present + local linkinfo = config.getlinkinfo(link) + table.insert(result, project.getrelative(cfg.project, linkinfo.abspath)) + else + table.insert(result, "-l" .. link.basename) + end + end + + -- The "-l" flag is fine for system libraries + links = config.getlinks(cfg, "system", "basename") + for _, link in ipairs(links) do + if path.getextension(link) == ".framework" then + table.insert(result, "-framework " .. path.getbasename(link)) + else + table.insert(result, "-l" .. link) + end + end + + return result + end + ----------------------------------------------------------------------------- -- Everything below this point is a candidate for deprecation diff --git a/src/tools/snc.lua b/src/tools/snc.lua index 76969ff4..c057e425 100644 --- a/src/tools/snc.lua +++ b/src/tools/snc.lua @@ -80,6 +80,20 @@ end +-- +-- Return the list of libraries to link, formatted for the linker command line. +-- + + function snc.getlinks(cfg) + local result = {} + local links = config.getlinks(cfg, "all", "basename") + for _, link in ipairs(links) do + table.insert(result, "-l" .. link) + end + return result + end + + ----------------------------------------------------------------------------- -- Everything below this point is a candidate for deprecation diff --git a/tests/actions/vstudio/vc200x/test_external_compiler.lua b/tests/actions/vstudio/vc200x/test_external_compiler.lua index d3f8bcb9..ec46c222 100644 --- a/tests/actions/vstudio/vc200x/test_external_compiler.lua +++ b/tests/actions/vstudio/vc200x/test_external_compiler.lua @@ -37,6 +37,7 @@ ]] end + + +-- +-- Verify the handling of system libraries. +-- + + function suite.additionalDependencies_onSystemLibs() + kind "ConsoleApp" + links { "fs_stub", "net_stub" } + prepare() + test.capture [[ +