Skip to content

Commit 92c984e

Browse files
Allow for absolute runpath directories (#2579)
1 parent 34208df commit 92c984e

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

src/tools/gcc.lua

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,29 @@
439439
end
440440

441441
for _, fullpath in ipairs(dirs) do
442+
-- Try to make rpath relative to target dir
442443
local rpath = path.getrelative(cfg.buildtarget.directory, fullpath)
443-
if table.contains(os.getSystemTags(cfg.system), "darwin") then
444-
rpath = "@loader_path/" .. rpath
445-
elseif (cfg.system == p.LINUX) then
446-
rpath = iif(rpath == ".", "", "/" .. rpath)
447-
rpath = "$$ORIGIN" .. rpath
448-
end
449444

450-
if mode == "linker" then
451-
rpath = "-Wl,-rpath,'" .. rpath .. "'"
452-
end
445+
if path.isabsolute(rpath) then
446+
if mode == "linker" then
447+
rpath = "-Wl,-rpath,'" .. rpath .. "'"
448+
end
453449

454-
table.insert(result, rpath)
450+
table.insert(result, rpath)
451+
else
452+
if table.contains(os.getSystemTags(cfg.system), "darwin") then
453+
rpath = "@loader_path/" .. rpath
454+
elseif (cfg.system == p.LINUX) then
455+
rpath = iif(rpath == ".", "", "/" .. rpath)
456+
rpath = "$$ORIGIN" .. rpath
457+
end
458+
459+
if mode == "linker" then
460+
rpath = "-Wl,-rpath,'" .. rpath .. "'"
461+
end
462+
463+
table.insert(result, rpath)
464+
end
455465
end
456466

457467
return result

tests/tools/test_gcc.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,3 +1400,36 @@ end
14001400
test.contains({ "-pg" }, gcc.getcxxflags(cfg))
14011401
test.contains({ "-pg" }, gcc.getldflags(cfg))
14021402
end
1403+
1404+
--
1405+
-- Test runpath dirs
1406+
--
1407+
1408+
function suite.runpathdirs_onRelativeDir()
1409+
local paths = { "libs" }
1410+
1411+
runpathdirs(paths)
1412+
prepare()
1413+
1414+
test.contains({ "-Wl,-rpath,'$$ORIGIN/libs'" }, gcc.getrunpathdirs(cfg, paths))
1415+
end
1416+
1417+
1418+
function suite.runpathdirs_onRelativeDir_macosx()
1419+
local paths = { "libs" }
1420+
1421+
system("MacOSX")
1422+
runpathdirs(paths)
1423+
prepare()
1424+
1425+
test.contains({ "-Wl,-rpath,'@loader_path/libs'" }, gcc.getrunpathdirs(cfg, paths))
1426+
end
1427+
1428+
function suite.runpathdirs_onAbsoluteDir()
1429+
local paths = { "/usr/local/lib/mylibs" }
1430+
1431+
runpathdirs(paths)
1432+
prepare()
1433+
1434+
test.contains({ "-Wl,-rpath,'/usr/local/lib/mylibs'" }, gcc.getrunpathdirs(cfg, paths))
1435+
end

0 commit comments

Comments
 (0)