Ticket #1938: update-premake-findlib.patch

File update-premake-findlib.patch, 2.7 KB (added by Markus, 11 years ago)

update os.findlib (slightly modified premake head)

  • trunk/build/premake/premake4/src/base/os.lua

    a b  
    1919-- Scan the well-known system locations for a particular library.
    2020--
    2121
     22    local function parse_ld_so_conf(conf_file)
     23        -- Linux ldconfig file parser to find system library locations
     24        local first, last
     25        local dirs = { }
     26        local file = io.open(conf_file)
     27        if file == nil then
     28            return dict
     29        end
     30        for line in io.lines(file) do
     31            -- ignore comments
     32            first = line:find("#", 1, true)
     33            if first ~= nil then
     34                line = line:sub(1, first - 1)
     35            end
     36
     37            if line ~= "" then
     38                -- check for include files
     39                first, last = line:find("include%s+")
     40                if first ~= nil then
     41                    -- found include glob
     42                    local include_glob = line:sub(last + 1)
     43                    local includes = os.matchfiles(include_glob)
     44                    for _, v in ipairs(includes) do
     45                        dirs = table.join(dirs, parse_ld_so_conf(v))
     46                    end
     47                else
     48                    -- found an actual ld path entry
     49                    table.insert(dirs, line)
     50                end
     51            end
     52        end
     53        return dirs
     54    end
     55
    2256    function os.findlib(libname)
    2357        local path, formats
    2458       
     
    3771                formats = { "lib%s.so", "%s.so" }
    3872                path = os.getenv("LD_LIBRARY_PATH") or ""
    3973   
    40                 io.input("/etc/ld.so.conf")
    41                 if io.input() then
    42                     for line in io.lines() do
    43                         path = path .. ":" .. line
    44                     end
    45                     io.input():close()
     74                for _, v in ipairs(parse_ld_so_conf("/etc/ld.so.conf")) do
     75                    path = path .. ":" .. v
    4676                end
    4777            end
    4878           
    4979            table.insert(formats, "%s")
    50             path = (path or "") .. ":/lib:/usr/lib:/usr/local/lib"
     80            path = path or ""
     81            if os.is64bit() then
     82                path = path .. ":/lib64:/usr/lib64/:usr/local/lib64"
     83            end
     84            path = path .. ":/lib:/usr/lib:/usr/local/lib"
    5185        end
    5286       
    5387        for _, fmt in ipairs(formats) do
     
    80114   
    81115
    82116--
     117-- Determine if the current system is running a 64-bit architecture
     118--
     119
     120    local _64BitHostTypes = {
     121        "x86_64",
     122        "ia64",
     123        "amd64",
     124        "ppc64",
     125        "powerpc64",
     126        "sparc64"
     127    }
     128
     129    function os.is64bit()
     130
     131        -- Identify the system
     132        local arch
     133        if _OS == "windows" then
     134            arch = os.getenv("PROCESSOR_ARCHITECTURE")
     135        elseif _OS == "macosx" then
     136            arch = os.outputof("echo $HOSTTYPE")
     137        else
     138            arch = os.outputof("uname -m")
     139        end
     140
     141        -- Check our known 64-bit identifiers
     142        arch = arch:lower()
     143        for _, hosttype in ipairs(_64BitHostTypes) do
     144            if arch:find(hosttype) then
     145                return true
     146            end
     147        end
     148        return false
     149    end
     150
     151
     152
     153--
    83154-- The os.matchdirs() and os.matchfiles() functions
    84155--
    85156