-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bin.do
executable file
·68 lines (49 loc) · 1.27 KB
/
.bin.do
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
#!/usr/bin/env lua
--------- Editable -----------
local Linker = "gcc"
local Libs = ""
------------------------------
local BinName = arg[2]
local TDir, TName = arg[2]:match("(.-)([^/]*)$")
if TName == "" then
TName = "main"
local DirName = TDir
if DirName == "" then
local f = assert(io.popen("pwd"))
DirName = f:read() .. "/"
assert(f:close())
end
BinName = TDir .. DirName:match("([^/]*)/$")
end
local CName = TDir .. TName .. ".c"
local RName = TDir .. TName .. ".require"
local Assert = function(cmd, msg)
local success, how, exit_code = os.execute(cmd)
if not success then
if msg then
io.stderr:write(msg .. "\n")
end
os.exit(exit_code)
end
end
Assert("test -e " .. CName, "Missing " .. CName)
Assert("depends-on " .. RName)
local RUniq = {}
local DUniq = {}
for n in io.lines(RName) do
if n:match("%.o$") then
table.insert(RUniq, TDir .. n)
else
table.insert(DUniq, n)
end
end
local RList = table.concat(RUniq, " ")
local DList = table.concat(DUniq, " ")
if DList ~= "" then
f = assert(io.popen("pkg-config --libs " .. DList))
Libs = Libs .. " " .. f:read()
assert(f:close())
end
Assert("depends-on " .. RList)
Assert(Linker .. " -o " .. BinName .. " " .. RList .. " " .. Libs)
Assert("depends-on " .. BinName)