-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmake.lua
479 lines (448 loc) · 13.5 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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
add_rules("mode.debug", "mode.release")
add_includedirs("src")
set_languages("c++17")
set_rundir("$(projectdir)")
local VERSION = os.getenv("VERSION") or "0.9.10-development"
if VERSION:startswith("v") then
VERSION = VERSION:sub(2)
end
add_repositories("xrepo https://github.com/zeromake/xrepo.git")
option("simd")
set_default(true)
set_showmenu(true)
set_description('开启 simd 优化')
option_end()
option("simd_sse")
set_default(false)
set_showmenu(true)
set_description('强制使用 sse 选项')
option_end()
option("omp")
set_default(false)
set_showmenu(true)
set_description('使用 opennmp 进行并行')
option_end()
option("c++_shared")
set_default(false)
set_showmenu(true)
set_description('安卓编译把 libc++_shared.so 拷贝到 app 里')
option_end()
option("android_16k")
set_default(false)
set_showmenu(true)
option_end()
add_defines(
"ONS_ZERO_VERSION=\""..VERSION.."\"",
"ONS_JH_VERSION=\"0.8.0\"",
"ONS_VERSION=\"20181218\"",
"NSC_VERSION=296"
)
if is_plat("windows") then
add_defines("XMD_H=1")
add_cxflags("/utf-8")
add_cxflags("/UNICODE")
add_cxflags("/EHsc")
if get_config("omp") then
add_cxflags("/openmp")
add_ldflags("/openmp")
end
add_defines("UNICODE", "_UNICODE", "WINVER=0x0606")
add_includedirs("include/windows")
elseif is_plat("mingw") then
if get_config("omp") then
add_cxflags("-fopenmp")
add_ldflags("-fopenmp")
end
add_defines("UNICODE", "_UNICODE", "WINVER=0x0606")
end
add_includedirs("src", "src/onscripter", "src/reader", "include")
local deps = {
"zlib",
"bzip2",
"jpeg",
"png",
"webp",
"sdl2_mixer",
"brotli",
"ghc_filesystem",
"luajit",
"stb",
"fmt"
}
local sdlConfigs = {
bmp_compat = true
}
if is_plat("android") then
table.insert(deps, "ndk-cpufeatures")
sdlConfigs["shared"] = true
end
local dep_opt = {system=false}
if is_plat("android") and get_config("android_16k") then
dep_opt["configs"] = {}
dep_opt["configs"]["cxflags"] = {"-Wl,-z,max-page-size=16384"}
sdlConfigs["cxflags"] = {"-Wl,-z,max-page-size=16384"}
add_cxflags("-Wl,-z,max-page-size=16384")
end
for _, dep_name in ipairs(deps) do
add_requires(dep_name, dep_opt)
end
add_requireconfs("sdl2", {system=false, configs=sdlConfigs})
add_requireconfs("**.sdl2", {system=false, configs=sdlConfigs})
-- add_requireconfs("**.harfbuzz", {system=false, configs={freetype=true}})
add_requireconfs("**.freetype", {system=false})
add_requires("freetype", {
system=false,
configs={
zlib=true,
bzip2=true,
brotli=true,
png=true
}
})
add_requires("sdl2_ttf", {system=false})
local sdl2_image_config = {
webp=true
}
if is_plat("windows", "mingw") then
sdl2_image_config["backend"] = "wic"
elseif is_plat("macosx") then
sdl2_image_config["backend"] = "imageio"
elseif is_plat("android") then
-- 安卓 jpeg 库有 bug 无法显示,改用 stb 替代
sdl2_image_config["backend"] = "stb"
else
-- 没有 backend,需要外部库
sdl2_image_config["backend"] = "common"
sdl2_image_config["png"] = true
sdl2_image_config["jpeg"] = true
end
add_requires("sdl2_image", {system=false, configs=sdl2_image_config})
local function use_binary()
set_kind("binary")
if is_plat("mingw") then
add_ldflags("-static-libgcc", "-static-libstdc++")
end
if is_plat("windows", "mingw") then
add_files("src/resource.rc")
end
add_defines("UTF8_FILESYSTEM=1")
end
target("onscripter")
-- add_defines("ONS_RESIZE_SURFACE_IMPLEMENT=2")
set_pcxxheader("src/config.hpp")
if is_plat("android") then
set_kind("shared")
elseif is_plat("iphoneos") then
-- codesign --force --deep --sign - xxx.app
-- ideviceinstaller -i xxx.app
-- ideviceinstaller -i xxx.ipa
set_kind("static")
add_cxflags("-fembed-bitcode")
add_mxflags("-fembed-bitcode")
add_defines("ONSCRIPTER_MAIN_RENAME=onscripter_main")
add_defines("ONSCRIPTER_MAIN_EXTREN=extern \"C\"")
else
use_binary()
end
add_packages(
"zlib",
"bzip2",
"jpeg",
"png",
"webp",
"freetype",
"harfbuzz",
"sdl2",
"sdl2_image",
"sdl2_ttf",
"sdl2_mixer",
"brotli",
"ghc_filesystem",
"stb",
"fmt",
"luajit"
)
add_defines("ONSCRIPTER_EXTEND_INIT=1")
add_files("src/entry/onscripter_main.cpp")
if not is_plat("windows", "mingw") then
add_defines("RENDER_COPY_RECT_FULL=1")
end
if is_plat("macosx") then
add_links("sdl2_main")
add_files("src/entry/*.mm")
add_frameworks("AudioToolbox", "Cocoa")
if get_config("target_minver") then
local target_minver = tonumber(get_config("target_minver"))
if target_minver < 10.15 then
add_defines("INFRA_FORCE_GHC_FS")
end
end
elseif is_plat("iphoneos") then
add_links("sdl2_main")
add_files("src/entry/*.mm")
if get_config("target_minver") then
local target_minver = tonumber(get_config("target_minver"))
if target_minver < 13.0 then
add_defines("INFRA_FORCE_GHC_FS")
end
end
add_defines("IOS", "GLES_SILENCE_DEPRECATION")
elseif is_plat("windows", "mingw") then
add_defines("ONSCRIPTER_UNDEF_MAIN")
add_defines(
"UNICODE",
"_UNICODE"
)
add_syslinks("windowscodecs")
elseif is_plat("android") then
add_packages("ndk-cpufeatures")
add_defines("SDL_JAVA_PACKAGE_PATH=com_zeromake_onscripter", "ANDROID")
add_cxflags("-fPIC", {force = true})
add_ldflags("-fPIC", {force = true})
add_cxflags("-funwind-tables", {force = true})
end
if get_config('simd') then
add_defines("USE_SIMD=1")
if is_arch("x86", "x64", "i386", "x86_64") then
if get_config("simd_sse") then
add_vectorexts("sse", "sse2", "sse3", "ssse3", "sse4.2")
else
add_vectorexts("avx2")
end
elseif is_arch("arm.*") then
add_vectorexts("neon")
else
add_vectorexts("all")
end
end
add_defines(
"USE_LUA=1",
"USE_BUILTIN_LAYER_EFFECTS=1",
"USE_BUILTIN_EFFECTS=1",
"USE_PARALLEL=1",
"FMT_HEADER_ONLY=1",
"USE_IMAGE_CACHE=1"
)
if get_config("omp") then
add_defines("USE_OMP_PARALLEL=1")
end
add_files(
"src/*.cpp",
"src/charset/*.c",
"src/SDL2_rotozoom.c",
"src/renderer/*.cpp",
"src/reader/*.cpp",
"src/onscripter/*.cpp",
"src/builtin_dll/*.cpp",
"src/language/*.cpp",
"src/private/*.cpp"
)
add_files("src/resize/*.cpp")
remove_files("src/AVIWrapper.cpp")
after_build(function (target)
if target:is_plat("android") then
local outDir = "project/android/app/libs/"..target:arch().."/"
local shareds = {}
for name, pkg in pairs(target:pkgs()) do
local libfiles = pkg:libraryfiles()
for _, libfile in ipairs(libfiles) do
if libfile:endswith(".so") then
shareds[libfile] = 1
end
end
end
for libfile, _ in pairs(shareds) do
print("cp "..libfile.." "..outDir)
os.cp(libfile, outDir)
end
os.cp(target:targetfile(), outDir)
local dirs = {
['armeabi-v7a'] = 'arm-linux-androideabi',
['arm64-v8a'] = 'aarch64-linux-android',
['x86_64'] = 'x86_64-linux-android',
['x86'] = 'i686-linux-android',
}
if get_config("c++_shared") then
local ndk_sysroot = target:toolchain("ndk")._CONFIGS.ndk_sysroot
local cpp_shared_file = path.join(ndk_sysroot, "usr/lib/"..dirs[target:arch()].."/libc++_shared.so")
print("cp "..cpp_shared_file.." "..outDir)
os.cp(cpp_shared_file, outDir)
end
return
elseif target:is_plat("iphoneos") then
import("script.generate_xcode")(target, VERSION)
return
end
local out_name = "onscripter"
if target:is_plat("macosx") then
out_name = out_name.."-darwin"
elseif target:is_plat("windows", "mingw") then
out_name = out_name.."-windows"
end
if target:is_arch("x64", "x86_64") then
out_name = out_name.."-x86_64"
elseif target:is_arch("arm64") then
out_name = out_name.."-arm64"
end
if target:is_plat("windows", "mingw") then
out_name = out_name..".exe"
end
os.cp(target:targetfile(), path.join(os.scriptdir(), "dist", out_name))
end)
if is_plat("android") and is_arch("arm.*") and not is_arch("arm64.*") then
add_cxflags("-mfpu=neon-vfpv4", {force = true})
end
if is_plat("iphoneos") then
target("onscripter-oc")
add_rules("xcode.application")
add_packages(
"sdl2_image"
)
set_configdir("$(buildir)/config")
add_configfiles("project/ios/onscripter-oc/Info.plist.in")
set_configvar("VERSION", VERSION)
add_files("project/ios/onscripter-oc/onscripter/*.xcassets")
add_files("project/ios/onscripter-oc/onscripter/*.mm")
add_files("project/ios/onscripter-oc/onscripter/*.m")
add_files("project/ios/onscripter-oc/onscripter/*.storyboard")
add_files("$(buildir)/config/Info.plist")
add_deps("onscripter")
add_links("sdl2_main")
end
target("nsdec")
use_binary()
add_files(
"src/tools/nscriptdecode.cpp"
)
target("sardec")
use_binary()
add_packages("bzip2")
add_files(
"src/charset/*.c",
"src/private/uitls.cpp",
"src/config.cpp",
"src/coding2utf16.cpp",
"src/tools/sardec.cpp",
"src/reader/SarReader.cpp",
"src/reader/DirectReader.cpp"
)
target("nsaenc")
use_binary()
add_packages("bzip2", "jpeg")
add_files(
"src/config.cpp",
"src/charset/*.c",
"src/tools/nsaenc.cpp",
"src/coding2utf16.cpp",
"src/gbk2utf16.cpp",
"src/reader/DirectReader.cpp",
"src/reader/NsaReader.cpp",
"src/reader/SarReader.cpp",
"src/tools/conv_shared.cpp",
"src/resize_image.cpp",
"src/language/*.cpp",
"src/private/*.cpp"
)
target("nsadec")
use_binary()
add_packages("bzip2")
add_files(
"src/config.cpp",
"src/charset/*.c",
"src/tools/nsadec.cpp",
"src/coding2utf16.cpp",
"src/gbk2utf16.cpp",
"src/sjis2utf16.cpp",
"src/reader/NsaReader.cpp",
"src/reader/DirectReader.cpp",
"src/reader/SarReader.cpp",
"src/language/*.cpp",
"src/private/*.cpp"
)
target("arcmake")
use_binary()
add_packages("bzip2", "jpeg")
add_files(
"src/charset/*.c",
"src/private/uitls.cpp",
"src/config.cpp",
"src/tools/arcmake.cpp",
"src/coding2utf16.cpp",
"src/gbk2utf16.cpp",
"src/reader/DirectReader.cpp",
"src/reader/NsaReader.cpp",
"src/reader/SarReader.cpp",
"src/tools/conv_shared.cpp",
"src/resize_image.cpp",
"src/language/*.cpp"
)
-- target("sarconv")
-- use_binary()
-- add_packages("bzip2", "jpeg")
-- add_files(
-- "src/tools/sarconv.cpp",
-- "src/coding2utf16.cpp",
-- "src/reader/DirectReader.cpp",
-- "src/reader/SarReader.cpp",
-- "src/tools/conv_shared.cpp",
-- "src/resize_image.cpp"
-- )
-- target("nsaconv")
-- add_packages("bzip2", "jpeg")
-- use_binary()
-- add_files(
-- "src/tools/nsaconv.cpp",
-- "src/coding2utf16.cpp",
-- "src/tools/conv_shared.cpp",
-- "src/gbk2utf16.cpp",
-- "src/sjis2utf16.cpp",
-- "src/reader/NsaReader.cpp",
-- "src/reader/SarReader.cpp",
-- "src/reader/DirectReader.cpp",
-- "src/resize_image.cpp",
-- "src/language/*.cpp"
-- )
-- target("resize")
-- add_packages("sdl2", "sdl2_image")
-- use_binary()
-- add_files("demo/resize.cpp")
-- add_files("src/resize/*.c")
-- add_includedirs("src")
-- target_end()
-- add_requires("benchmark")
-- target("benchmark_resize")
-- add_includedirs("src")
-- add_files("demo/benchmark_resize.cpp")
-- add_files("src/resize_image.cpp")
-- add_files("src/resize/resize.c")
-- add_packages(
-- "benchmark",
-- "stb"
-- )
-- if is_arch("x86", "x64", "i386", "x86_64") then
-- add_vectorexts("avx2")
-- elseif is_arch("arm.*") then
-- add_vectorexts("neon")
-- end
-- target("gbk2utf8")
-- use_binary()
-- add_syslinks("iconv")
-- add_files(
-- "src/charset/*.c",
-- "demo/gbk2utf8.cpp",
-- "src/coding2utf16.cpp",
-- "src/gbk2utf16.cpp",
-- "src/language/*.cpp"
-- )
-- add_includedirs("src")
-- target_end()
-- target("bmp2png")
-- use_binary()
-- add_files("demo/bmp2png.cpp")
-- add_packages("stb")
-- target_end()
-- target("flecs_demo")
-- use_binary()
-- add_files("demo/flecs_demo.cpp")
-- add_packages("sdl2_image", "flecs")
-- target_end()