This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.lua
executable file
·119 lines (97 loc) · 2.63 KB
/
build.lua
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
118
119
#! /usr/bin/env lua
--[[
Why use Makefiles when there is Lua available?
Usage: ./build absolute_out_path [AMD64]
--]]
SEP = package.config:sub(1,1)
local SEP = SEP
local exe_path
if arg[0]:sub(1,1) == '.' then
exe_path = os.getenv'PWD'
exe_path = exe_path .. SEP .. arg[0]
else
exe_path = arg[0]
end
_,_, exe_path = exe_path:find('^(.+)' .. SEP .. '.+$')
package.path = exe_path .. '/?.lua;' .. package.path
if SEP == '/' then
package.cpath = exe_path .. '/?.so;' .. package.cpath
else
package.cpath = exe_path .. '/?.dll;' .. package.cpath
end
local base = _G
local _expandStr_mt = { __index = base }
function expandStr(str, t)
if not t then t = { } end
str = str:gsub('%$(%b())', function (s)
s = s:sub(2, #s-1)
local func = loadstring('return ' .. s)
local env = setmetatable(t, _expandStr_mt)
setfenv(func, env)
return tostring(func())
end)
str = str:gsub('%$([%w_]+)', function (s)
return tostring(t[s] or base[s])
end)
return str
end
sf = string.format
local sf = sf
es = expandStr
local es = es
local usage = es'Usage: $(arg[0]) absolute_dest [AMD64]'
DEST = assert(arg[1], usage)
AMD64 = arg[2] == 'AMD64'
GEN = DEST .. '/bin/lgob-generator'
function shell(cmd)
local f = assert(io.popen(cmd), sf("Couldn't open the pipe for %s!", cmd))
local a = f:read('*a')
f:close()
a = a:gsub('\n', '')
return a
end
sh = shell
local sh = sh
require('config')
function pkg(arg, pkgs)
local p = table.concat(pkgs, ' ')
local t = { p = p, arg = arg }
return sh( es('$PKG $arg $p', t) )
end
function gen_iface(mod)
local t = { name = mod.name }
t.input = es('src/$name.ovr' , t)
t.output = es('src/iface.c', t)
t.log = es('src/log', t)
t.version = pkg('--modversion', {mod.pkg})
sh(es('$GEN -i $input -o $output -l $log -v $version', t))
end
function compile(mod)
local t = { name = mod.name, src = mod.src or 'iface.c' }
t.input = es('src/$src', t)
t.output = es('src/$name.$EXT', t)
t.pkgflags = pkg('--cflags --libs', {LUA_PKG, mod.pkg})
sh(es('$CC $COMPILE_FLAGS -I$DEST/include $input -o $output $pkgflags', t))
end
function install(mod, dest)
local t = { name = mod.name, dest = dest }
t.dir = 'src'
local inst = mod.inst or {es('$name.$EXT', t)}
for _, f in ipairs(inst) do
t.f = f
sh(es('$INST $dir/$f $DEST/$dest/$f', t))
end
end
function clean(mod)
local t = {}
t.dir = 'src'
local garb = mod.garb or {'iface.c', 'log', mod.name .. '.' .. EXT}
for _, f in ipairs(garb) do
t.f = f
sh(es('$RM $dir/$f', t))
end
end
function init()
print( es'** Building module $MODULE with $COMPILE_FLAGS **' )
end
require( 'mod' )