-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvmake
executable file
·272 lines (236 loc) · 9.44 KB
/
vmake
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!./tools/vlua
dofile('tools/vmake.lua')
CC = 'gcc'
CXX = 'g++'
AR = 'ar -rc'
DLL_SUFFIX = '.so'
EXE_SUFFIX = ''
CFLAGS = {'-Wall', '-Wno-unused-function'}
CXX_CFLAGS = {}
PUSS_CONFIG = ''
if vlua.OS=='win32' then
EXE_SUFFIX = '.exe'
DLL_SUFFIX = '.dll'
array_push(CFLAGS, '-D_WIN32')
end
PUSS_INCLUDE_PATH = 'include'
GEN_INCLUDE_PATH = path_concat('objs', 'gen')
INCLUDES = { PUSS_INCLUDE_PATH, GEN_INCLUDE_PATH }
LUA_SRC_PATH = path_concat('3rd', 'lua-5.4.0', 'src')
-- debug && asan
do
if vlua.match_arg('^%-debug$') then
array_push(CFLAGS, '-g', '-O0', '-D_DEBUG')
PUSS_CONFIG = 'd'
else
array_push(CFLAGS, '-s', '-O2', '-DNDEBUG')
end
if vlua.match_arg('^%-asan$') then
array_push(CFLAGS, '-ggdb', '-fsanitize=address', '-fno-omit-frame-pointer')
PUSS_CONFIG = PUSS_CONFIG .. 'a'
end
end
OBJPATH = path_concat('objs', PUSS_CONFIG=='' and 'r' or PUSS_CONFIG)
PUSS_CONFIG_SUFFIX = PUSS_CONFIG=='' and '' or ('-'..PUSS_CONFIG)
-----------------------------
-- common utils
function make_c2objs(srcs, objpath, include_paths, ...) -- ... is cflags
if type(srcs)=='string' then srcs = scan_files(srcs, function(f) return f:match('^.+%.c$') end) end
local cflags = args_concat(...)
local incs = array_convert(include_paths, function(v) return '-I'..v end)
return make_objs(srcs, include_paths
, function(f) return path_concat(objpath or OBJPATH, f) end
, function(t) return CC, CFLAGS, cflags, incs, '-o', t.obj, '-c', t.src end)
end
function make_cpp2objs(srcs, objpath, include_paths, ...) -- ... is cflags
if type(srcs)=='string' then srcs = scan_files(srcs, function(f) return f:match('^.+%.cpp$') or f:match('^.+%.cxx$') end) end
local cflags = args_concat(...)
local incs = array_convert(include_paths, function(v) return '-I'..v end)
return make_objs(srcs, include_paths
, function(f) return path_concat(objpath or OBJPATH, f) end
, function(t) return CXX, CFLAGS, CXX_CFLAGS, cflags, incs, '-o', t.obj, '-c', t.src end)
end
vmake_target_add('', function(target)
local ts = os.time()
local targets = vmake_target_all()
targets['clean'] = nil -- ignore clean
targets[target] = nil -- ignore this
for target in pairs(targets) do
local ok, err = pcall(vmake, target)
if not ok then print('vmake', target, 'error:', err) end
end
local te = os.time()
print('use time:', te-ts)
end)
vmake_target_add('clean', function(target)
local rm = vlua.OS=='win32' and 'rd /S /Q ' or 'rm -rf '
os.execute(rm .. 'objs')
end)
-----------------------------
-- puss core
vmake_target_add('puss', function(target)
vmake('luaproxy')
local slibs = vmake('puss_toolkit', 'lua')
local incs = array_pack(INCLUDES, LUA_SRC_PATH, 'puss_toolkit')
local libs = vlua.OS=='win32' and '' or '-lm -ldl -lpthread'
local objs = make_c2objs(target, nil, incs)
local output = path_concat('bin', target..PUSS_CONFIG_SUFFIX..EXE_SUFFIX)
return make_target(output, {objs, slibs}, CC, CFLAGS, '-o', output, objs, slibs, libs)
end)
vmake_target_add('puss_toolkit', function(target)
local objs = make_c2objs(target, nil, INCLUDES, suffix_flag)
local output = path_concat(OBJPATH, 'lib'..target..'.a')
return make_target(output, objs, AR, output, objs)
end)
vmake_target_add('luaproxy', function(target)
local luaproxy_lua = path_concat('tools', 'luaproxy.lua')
local deps =
{ luaproxy_lua
, make_copy('luaconf.h', PUSS_INCLUDE_PATH, LUA_SRC_PATH)
, make_copy('lua.h', PUSS_INCLUDE_PATH, LUA_SRC_PATH)
, make_copy('lualib.h', PUSS_INCLUDE_PATH, LUA_SRC_PATH)
, make_copy('lauxlib.h', PUSS_INCLUDE_PATH, LUA_SRC_PATH)
}
if check_deps(path_concat(PUSS_INCLUDE_PATH, 'luaproxy.h'), deps)
and check_deps(path_concat(GEN_INCLUDE_PATH, 'luaproxy.symbols'), deps)
then
return
end
make_target(path_concat(GEN_INCLUDE_PATH, '.dummy'), nil
, vlua.self, luaproxy_lua
, '-path="'..PUSS_INCLUDE_PATH..'"'
, '-gen="'..GEN_INCLUDE_PATH..'"'
)
end)
vmake_target_add('lua', function(target)
local cflags = vlua.OS=='win32' and '' or '-DLUA_USE_LINUX'
local srcs = scan_files(LUA_SRC_PATH, function(f)
if f=='lua.c' then return end
if f=='luac.c' then return end
return f:match('^.+%.c$')
end)
local objs = make_c2objs(srcs, nil, nil, cflags)
local output = path_concat(OBJPATH, 'lib'..target..'.a')
return make_target(output, objs, AR, output, objs)
end)
vmake_target_add('puss_system', function(target)
vmake('luaproxy')
local objs = make_c2objs(path_concat('plugins', target), nil, INCLUDES, '-fPIC', '-fvisibility=hidden')
local output = path_concat('bin', 'plugins', target..PUSS_CONFIG_SUFFIX..DLL_SUFFIX)
local libs = vlua.OS=='win32' and '-lwsock32' or ''
return make_target(output, objs, CC, CFLAGS, '-shared', '-o', output, objs, libs)
end)
vmake_target_add('puss_linenoise_ng', function(target)
vmake('luaproxy')
local objs = make_cpp2objs(path_concat('plugins', target), nil, INCLUDES, '-fPIC', '-fvisibility=hidden')
local output = path_concat('bin', 'plugins', target..PUSS_CONFIG_SUFFIX..DLL_SUFFIX)
return make_target(output, objs, CXX, CXXFLAGS, '-shared', '-o', output, objs)
end)
vmake_target_add('puss_luaparser', function(target)
vmake('luaproxy')
local objs = make_c2objs(path_concat('plugins', target), nil, INCLUDES, '-fPIC', '-fvisibility=hidden')
local output = path_concat('bin', 'plugins', target..PUSS_CONFIG_SUFFIX..DLL_SUFFIX)
return make_target(output, objs, CC, CFLAGS, '-shared', '-o', output, objs)
end)
-----------------------------
-- imgui lua wrapper
vmake_target_add('imgui_wrap', function(target)
local src = path_concat('plugins', 'puss_imgui', 'imgui')
local imgui_wrap = path_concat('tools', 'imgui_wrap.lua')
local deps =
{ imgui_wrap
, path_concat(src, 'imgui.h')
}
if check_deps(path_concat(GEN_INCLUDE_PATH, 'imgui_enums.inl'), deps)
and check_deps(path_concat(GEN_INCLUDE_PATH, 'imgui_wraps.inl'), deps)
and check_deps(path_concat(GEN_INCLUDE_PATH, 'imgui_lua.inl'), deps)
then
return
end
make_target(path_concat(GEN_INCLUDE_PATH, '.dummy'), nil
, vlua.self, imgui_wrap
, '-src='..src
, '-out='..GEN_INCLUDE_PATH
)
end)
-----------------------------
-- scintilla iface
SCINTILLA_ROOT_PATH = path_concat('plugins', 'puss_imgui', 'scintilla3')
SCINTILLA_INCLUDE_PATH = path_concat(SCINTILLA_ROOT_PATH, 'include')
vmake_target_add('scintilla_iface', function(target)
make_copy('Scintilla.iface', GEN_INCLUDE_PATH, SCINTILLA_INCLUDE_PATH)
local scintilla_iface_lua = path_concat('tools', 'scintilla_iface.lua')
local scintilla_iface = path_concat(GEN_INCLUDE_PATH, 'Scintilla.iface')
local scintilla_output = path_concat(GEN_INCLUDE_PATH, 'scintilla.iface.inl')
local deps =
{ scintilla_iface_lua
, scintilla_iface
}
return make_target( scintilla_output, deps
, vlua.self, scintilla_iface_lua
, '-input='..scintilla_iface
, '-output='..scintilla_output
)
end)
-----------------------------
-- scintilla
vmake_target_add('scintilla', function(target)
local incs =
{ SCINTILLA_INCLUDE_PATH
, path_concat(SCINTILLA_ROOT_PATH, 'src')
, path_concat(SCINTILLA_ROOT_PATH, 'lexlib')
}
local cflags = array_pack(CFLAGS, CXX_CFLAGS, '-fPIC', '-fvisibility=hidden', '-DFOX', '-DSCI_LEXER', array_convert(incs, function(v) return '-I'..v end))
local function build(dir, dst)
return make_objs(scan_files(path_concat(SCINTILLA_ROOT_PATH, dir), function(f) return f:match('^.+%.cpp$') or f:match('^.+%.cxx$') end)
, incs
, function(f) return path_concat(OBJPATH, 'sci', f:sub(#SCINTILLA_ROOT_PATH + 1)) end
, function(t) return CXX, cflags, '-o', t.obj, '-c', t.src end)
end
local lexersobjs = build('lexers')
table.sort(lexersobjs)
local all_objs = {build('src'), build('lexlib'), lexersobjs}
local lib = path_concat(OBJPATH, 'lib'..target..'.a')
return make_target(lib, all_objs, AR, lib, all_objs)
end)
-----------------------------
-- puss imgui
local function make_puss_imgui(target)
vmake('luaproxy', 'imgui_wrap', 'scintilla_iface')
local slibs = vmake('scintilla')
local src = path_concat('plugins', 'puss_imgui')
local incs = array_pack(
{ INCLUDES
, SCINTILLA_INCLUDE_PATH
, path_concat(SCINTILLA_ROOT_PATH, 'src')
, path_concat(SCINTILLA_ROOT_PATH, 'lexlib')
, src
, path_concat(src, 'imgui')
})
local flags
local libs
local objpath
local gl3wobjs = {}
if (vlua.OS=='win32' and target=='puss_imgui') then
flags = '-DUNICODE -D_UNICODE -DPUSS_IMGUI_USE_DX11 -DSCI_LEXER -DFOX'
libs = '-ld3dcompiler -ldxgi -ld3d11 -lxinput -lgdi32'
else
flags = shell('pkg-config --static --cflags glfw3')
libs = shell('pkg-config --static --libs glfw3')
flags = array_pack(flags, '-DPUSS_IMGUI_USE_GLFW', '-DSCI_LEXER', '-DFOX')
libs = array_pack(libs, (vlua.OS=='win32') and '-lopengl32' or '-lGL')
objpath = OBJPATH..'gl'
incs = array_pack(incs, path_concat(src, 'gl3w'))
gl3wobjs = make_c2objs(path_concat(src, 'gl3w'), objpath, incs, '-fPIC', '-fvisibility=hidden')
end
local srcs = scan_files(src, function(f) return f:match('^.+%.cpp$') end, nil, true)
local objs = make_cpp2objs(srcs, objpath, incs, '-fPIC', '-fvisibility=hidden', flags)
local imguisrcs = scan_files(path_concat(src, 'imgui'), function(f) return f:match('^.+%.cpp$') end, nil, true)
local imguiobjs = make_cpp2objs(imguisrcs, objpath, incs, '-fPIC', '-fvisibility=hidden', flags)
local output = path_concat('bin', 'plugins', target..PUSS_CONFIG_SUFFIX..DLL_SUFFIX)
return make_target(output, {objs, imguiobjs, gl3wobjs}, CXX, CFLAGS, flags, '-shared', '-o', output, objs, imguiobjs, gl3wobjs, slibs, libs)
end
vmake_target_add('puss_imgui', make_puss_imgui)
if vlua.OS=='win32' then
vmake_target_add('puss_imgui_glfw', make_puss_imgui)
end