-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.rabs
86 lines (75 loc) · 2.05 KB
/
common.rabs
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
PLATFORM := defined("PLATFORM") or shell("uname"):trim
DEBUG := defined("DEBUG")
CFLAGS := []
LDFLAGS := []
PREBUILDS := []
pkgconfig := fun(Args) do
expr('pkg-config {Args}') => fun() shell('pkg-config', Args):trim
end
c_compile := fun(Source, Object) do
execute('cc -c {CFLAGS} -o{Object} {Source}')
end
c_includes := fun(Target) do
var Lines := shell('cc -c {CFLAGS} -M -MG {Target:source}')
Lines := Lines:replace("\\\n ", "")
Lines := Lines[Lines:find(": ") + 2, 0]:trim
var Files := Lines / r"[^\\\\]( +)"
for File in Files do
File := file(File:replace("\\ ", " "))
end
ret Files
end
var SourceTypes := {
"c" is [c_includes, c_compile]
}
c_program := fun(Executable, Objects, Libraries) do
var Sources := []
for Object in Objects or [] do
for Extension, Functions in SourceTypes do
var Source := Object % Extension
if Source:exists then
Sources:put(Source)
var Scan := Source:scan("INCLUDES")[PREBUILDS] => Functions[1]
Object[Source, Scan] => (Functions[2] !! [Source])
exit
end
end
end
Executable[Objects, Libraries] => fun(Executable) do
execute('cc', '-o', Executable, Objects, Libraries, LDFLAGS)
end
DEFAULT[Executable]
ret Executable
end
c_library := fun(Library, Objects, Libraries) do
var Sources := []
for Object in Objects or [] do
for Extension, Functions in SourceTypes do
var Source := Object % Extension
if Source:exists then
Sources:put(Source)
var Scan := Source:scan("INCLUDES")[PREBUILDS] => Functions[1]
Object[Source, Scan] => (Functions[2] !! [Source])
exit
end
end
end
Library[Objects, Libraries] => fun(Executable) do
execute('ar', 'rcs', Library, Objects, Libraries)
end
DEFAULT[Library]
ret Library
end
PREFIX := old or file('{getenv("DESTDIR") or ""}{defined("PREFIX") or "/usr/local"}')
INSTALL := meta("install")
install := fun(Source, Target, Mode) do
Target[Source] => fun(Target) do
print(Source, " -> ", Target, "\n")
Target:dir:mkdir
Source:copy(Target)
Mode and execute("chmod", Mode, Target)
end
INSTALL[Target]
ret Target
end
TEST := meta("test")