Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCameron Hart <cam@bitshifter.net.nz>2013-01-19 09:41:49 +0400
committerCameron Hart <cam@bitshifter.net.nz>2013-01-19 09:41:49 +0400
commitb2ca3e4d0df86b77e336eb57cdc3fe31e2997014 (patch)
treeb33da4aa00ae3f1f0b4eabfe5de649262a087ff7
parentbc38d316887263a1a53783efb73968e69acadfcd (diff)
Process ld.so.conf for includes, fixes os.findlib in Linux.
-rw-r--r--src/base/os.lua38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/base/os.lua b/src/base/os.lua
index e9a1ff0..87255da 100644
--- a/src/base/os.lua
+++ b/src/base/os.lua
@@ -19,6 +19,36 @@
-- Scan the well-known system locations for a particular library.
--
+ local function parse_ld_so_conf(conf_file)
+ -- Linux ldconfig file parser to find system library locations
+ local first, last
+ local dirs = { }
+ for line in io.lines(conf_file) do
+ -- ignore comments
+ first = line:find("#", 1, true)
+ if first ~= nil then
+ line = line:sub(1, first - 1)
+ end
+
+ if line ~= "" then
+ -- check for include files
+ first, last = line:find("include%s+")
+ if first ~= nil then
+ -- found include glob
+ local include_glob = line:sub(last + 1)
+ local includes = os.matchfiles(include_glob)
+ for _, v in ipairs(includes) do
+ dirs = table.join(dirs, parse_ld_so_conf(v))
+ end
+ else
+ -- found an actual ld path entry
+ table.insert(dirs, line)
+ end
+ end
+ end
+ return dirs
+ end
+
function os.findlib(libname)
local path, formats
@@ -37,12 +67,8 @@
formats = { "lib%s.so", "%s.so" }
path = os.getenv("LD_LIBRARY_PATH") or ""
- io.input("/etc/ld.so.conf")
- if io.input() then
- for line in io.lines() do
- path = path .. ":" .. line
- end
- io.input():close()
+ for _, v in ipairs(parse_ld_so_conf("/etc/ld.so.conf")) do
+ path = path .. ":" .. v
end
end