-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmake.lua
201 lines (181 loc) · 5.85 KB
/
xmake.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
set_project("samurai-render")
option("build_examples")
set_default(false)
set_showmenu(true)
option("backend_cairo")
set_default(true)
set_showmenu(true)
add_defines("BACKEND_CAIRO")
option("backend_opengl")
set_default(false)
set_showmenu(true)
add_defines("BACKEND_OPENGL")
option_end()
add_requires("wayland")
if get_config("backend_cairo") then
add_requires("cairo")
end
if get_config("backend_opengl") then
add_requires("libglvnd")
end
rule("wayland-protocol")
set_extensions(".protocol")
on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
function string.startswith(String, Start)
return string.sub(String, 1, string.len(Start)) == Start
end
import("lib.detect.find_program")
local scanner = find_program("wayland-scanner")
if scanner == nil then
print("error: wayland-scanner is required to generate c code for wayland-protocols")
return
end
local lines = io.lines(sourcefile)
local source = lines(0)
local h_file = path.join("samure/wayland", lines(1))
local c_file = path.join("samure/wayland", lines(2))
if string.startswith(source, "https") then
local curl = find_program("curl")
if curl == nil then
printf("error: curl is required to generate %s protocol\n", path.basename(sourcefile))
return
end
local output = os.tmpfile()
os.vrunv(curl, {"-o", output, source})
source = output
end
batchcmds:show_progress(opt.progress, "${color.build.object}wayland-scanner.header %s", path.basename(sourcefile))
batchcmds:vrunv("wayland-scanner", {"client-header", source, h_file})
batchcmds:show_progress(opt.progress, "${color.build.object}wayland-scanner.source %s", path.basename(sourcefile))
batchcmds:vrunv("wayland-scanner", {"private-code", source, c_file})
batchcmds:add_depfiles(sourcefile)
batchcmds:set_depmtime(os.mtime(c_file))
batchcmds:set_depcache(target:dependfile(c_file))
end)
rule_end()
target("wayland-protocols")
set_kind("object")
add_rules("wayland-protocol")
add_files("samure/wayland/*.protocol")
target_end()
add_rules("mode.debug", "mode.release")
if get_config("backend_cairo") then
target("samurai-render-backend-cairo")
-- todo: also allow static linking
set_kind("shared")
add_packages("wayland", "cairo")
add_headerfiles(
"samure/*.h",
"samure/backends/cairo.h"
)
add_files("samure/backends/cairo.c")
target_end()
end
if get_config("backend_opengl") then
target("samurai-render-backend-opengl")
set_kind("shared")
add_packages("wayland", "wayland-egl", "EGL", "libglvnd")
add_headerfiles(
"samure/*.h",
"samure/backends/opengl.h"
)
add_files("samure/backends/opengl.c")
target_end()
end
target("samurai-render")
set_kind("$(kind)")
add_packages("wayland")
add_options(
"backend_cairo",
"backend_opengl"
)
add_headerfiles(
"samure/*.h",
"samure/wayland/*.h",
"samure/backends/*.h"
)
add_files(
"samure/*.c",
"samure/wayland/*.c",
"samure/backends/*.c"
)
remove_files("samure/backends/cairo.c")
remove_files("samure/backends/opengl.c")
target_end()
if get_config("build_examples") then
add_requires("olive.c")
target("olivec_bounce")
set_kind("binary")
add_packages("wayland", "olive.c")
add_options(
"backend_cairo",
"backend_opengl"
)
add_includedirs(os.scriptdir())
add_deps("samurai-render")
add_files("examples/olivec_bounce.c")
target("blank")
set_kind("binary")
add_packages("wayland")
add_options(
"backend_cairo",
"backend_opengl"
)
add_includedirs(os.scriptdir())
add_deps("samurai-render")
add_files("examples/blank.c")
if get_config("backend_cairo") then
target("cairo_bounce")
set_kind("binary")
add_packages("wayland", "cairo")
add_options(
"backend_cairo",
"backend_opengl"
)
add_includedirs(os.scriptdir())
add_deps("samurai-render")
add_files("examples/cairo_bounce.c")
target("slurpy")
set_kind("binary")
add_packages("wayland", "cairo")
add_options(
"backend_cairo",
"backend_opengl"
)
add_includedirs(os.scriptdir())
add_deps("samurai-render")
add_files("examples/slurpy.c")
target("image_draw")
set_kind("binary")
add_packages("wayland", "cairo")
add_options(
"backend_cairo",
"backend_opengl"
)
add_includedirs(os.scriptdir())
add_deps("samurai-render")
add_files("examples/image_draw.c")
target("screenshot_draw")
set_kind("binary")
add_packages("wayland", "cairo")
add_options(
"backend_cairo",
"backend_opengl"
)
add_includedirs(os.scriptdir())
add_deps("samurai-render")
add_files("examples/screenshot_draw.c")
end
if get_config("backend_opengl") then
target("opengl_bounce")
set_kind("binary")
add_packages("wayland", "libglvnd")
add_options(
"backend_cairo",
"backend_opengl"
)
add_includedirs(os.scriptdir())
add_deps("samurai-render")
add_files("examples/opengl_bounce.c")
end
end