File: gen-configs

package info (click to toggle)
lua-posix 36.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,720 kB
  • sloc: ansic: 5,462; makefile: 21; sh: 6
file content (117 lines) | stat: -rw-r--r-- 3,693 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/lua

luavs = {"5.1", "5.3", "5.4"}

loadluke = function(filename)
    local f = io.open(filename)
    local content, err = f:read("*a")
    f:close()
    if content == nil then
        return nil, err
    end
    local r = {}
    local chunk, err = load(content, filename, "t", r)
    if chunk == nil then
        return nil, "Error loading file: " .. err
    end
    local ok, err = pcall(chunk)
    if not ok then
        return nil, "Error running file: " .. err
    end
    return r
end

saveconfig = function(luav, mod, src, defines, incdirs)
    local content = {
        "PKG_NAME=" .. mod,
        "PKG_VERSION=" .. arg[1],
    }
    local arch = arg[2]
    local cflags = {
        "-D_GNU_SOURCE=1", -- For GNU/Hurd
    }
    local ldflags = {}
    for i, d in pairs(incdirs) do
        table.insert(cflags, "-I" .. d)
    end
    for d, v in pairs(defines) do
        if d == "platforms" then
            for dd, vv in pairs(v["linux"]) do
                table.insert(cflags, "-D" .. dd .. "=" .. vv)
            end
            for dd, vv in pairs(v["unix"]) do
                table.insert(cflags, "-D" .. dd .. "=" .. vv)
            end
        else
            table.insert(cflags, "-D" .. d .. "=" .. v)
        end
    end
    if type(src) == "string" then
        if string.find(src, "%.in$") then
            local src1 = string.gsub(src, "%.in$", "")
            local f1 = io.open(src)
            local content, err = f1:read("*a")
            f1:close()
            content = string.gsub(content, "@package@", r["package"])
            content = string.gsub(content, "@version@", arg[1])
            local f2 = io.open(src1, "w")
            f2:write(content)
            f2:close()
            src = src1
        end
        if string.find(src, "%.c$") then
            table.insert(content, "LUA_MODNAME_CPART=" .. mod)
            table.insert(content, "CLIB_OBJS=" .. string.gsub(src, "%.c$", ".lo"))
        else
            table.insert(content, "LUA_MODNAME=" .. mod)
            table.insert(content, "LUA_SOURCES=" .. src)
        end
    else
        -- table
        table.insert(content, "LUA_MODNAME_CPART=" .. mod)
        table.insert(content, "CLIB_OBJS=" .. string.gsub(src["sources"], "%.c$", ".lo"))
        if src["defines"] ~= nil then
            for d,c in pairs(src["defines"]) do
                local q = true
                for n,v in pairs(c) do
                    if n == "checkheader" and string.find(arch, "hurd") and string.find(v, "linux") then
                        q = false
                    end
                end
                if q then
                    table.insert(cflags, "-D" .. d)
                end
            end
        end
        if src["libraries"] ~= nil then
            for i,l in pairs(src["libraries"]) do
                if l["library"] ~= "socket" then
                    table.insert(ldflags, "-l" .. l["library"])
                end
            end
        end
    end
    -- print(inspect(content))
    -- print(inspect(cflags))
    -- print(inspect(ldflags))
    f = io.open("debian/lua" .. luav .. "." .. mod .. ".dh-lua.conf", "w")
    for i,v in pairs(content) do
        f:write(v .. "\n")
    end
    f:write("CLIB_CFLAGS=" .. table.concat(cflags, " ") .. "\n")
    f:write("CLIB_LDFLAGS=" .. table.concat(ldflags, " ") .. "\n")
    f:close()
end

r = loadluke("lukefile")
r["defines"]["PACKAGE"] = "'\"" .. r["package"] .. "\"'"
r["defines"]["VERSION"] = "'\"$(PKG_VERSION)\"'"

-- inspect = require('inspect')
-- print(inspect(r))

for i, luav in pairs(luavs) do
    for mod, src in pairs(r['modules']) do
	saveconfig(luav, mod, src, r["defines"], r["incdirs"])
    end
end