-
-
Notifications
You must be signed in to change notification settings - Fork 765
/
xmake.sh
executable file
·218 lines (195 loc) · 5.14 KB
/
xmake.sh
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
#!/bin/sh
set_project "xmake"
set_version "2.7.6" "%Y%m%d"
# set warning all
set_warnings "all"
# set language: c99
set_languages "c99"
# add defines
add_defines "_GNU_SOURCE=1" "_FILE_OFFSET_BITS=64" "_LARGEFILE_SOURCE"
# disable some compiler errors
if is_plat "macosx"; then
add_cxflags "-Wno-error=deprecated-declarations" "-fno-strict-aliasing" "-Wno-error=nullability-completeness" "-Wno-error=parentheses-equality"
fi
# add build modes
if is_mode "debug"; then
set_symbols "debug"
set_optimizes "none"
else
set_strip "all"
set_symbols "hidden"
set_optimizes "smallest"
if is_plat "macosx"; then
add_cxflags "-flto"
add_mxflags "-flto"
add_ldflags "-flto"
fi
fi
# the runtime option, lua or luajit
option "runtime" "Use luajit or lua runtime" "lua"
# always use external dependencies
option "external" "Always use external dependencies" false
# the readline option
option "readline"
add_links "readline"
add_cincludes "readline/readline.h"
add_cfuncs "readline"
add_defines "XM_CONFIG_API_HAVE_READLINE"
option_end
# the curses option
option "curses"
add_cfuncs "initscr"
add_cincludes "curses.h"
add_defines "XM_CONFIG_API_HAVE_CURSES"
before_check "option_find_curses"
option_end
option_find_curses() {
local ncurses_ldflags=""
ncurses_ldflags=$(pkg-config --libs ncurses 2>/dev/null)
option "curses"
if test_nz "${ncurses_ldflags}"; then
add_cflags `pkg-config --cflags ncurses 2>/dev/null`
add_ldflags "${ncurses_ldflags}"
else
add_links "curses"
fi
option_end
}
# the atomic option
# @note some systems need link atomic, e.g. raspberrypi
option "atomic"
add_links "atomic"
add_csnippets "
void test() {\n
int v;\n
__atomic_load(&v,&v,0);\n
}"
option_end
# the lua option
option "lua"
add_cfuncs "lua_pushstring"
add_cincludes "lua.h" "lualib.h" "lauxlib.h"
add_defines "LUA_COMPAT_5_1" "LUA_COMPAT_5_2" "LUA_COMPAT_5_3"
before_check "option_find_lua"
option_end
option_find_lua() {
local ldflags=""
local cflags=""
option "lua"
cflags=`pkg-config --cflags lua5.4 2>/dev/null`
ldflags=`pkg-config --libs lua5.4 2>/dev/null`
if test_z "${cflags}"; then
cflags="-I/usr/include/lua5.4"
fi
if test_z "${ldflags}"; then
ldflags="-llua5.4"
fi
add_cflags "${cflags}"
add_ldflags "${ldflags}"
option_end
}
# the luajit option
option "luajit"
add_cfuncs "lua_pushstring"
add_cincludes "lua.h" "lualib.h" "lauxlib.h"
add_defines "USE_LUAJIT"
before_check "option_find_luajit"
option_end
option_find_luajit() {
local ldflags=""
local cflags=""
option "luajit"
cflags=`pkg-config --cflags luajit 2>/dev/null`
ldflags=`pkg-config --libs luajit 2>/dev/null`
if test_z "${cflags}"; then
cflags="-I/usr/include/luajit-2.1"
fi
if test_z "${ldflags}"; then
ldflags="-lluajit"
fi
add_cflags "${cflags}"
add_ldflags "${ldflags}"
option_end
}
# the lz4 option
option "lz4"
add_cfuncs "LZ4F_compressFrame"
add_cincludes "lz4.h" "lz4frame.h"
before_check "option_find_lz4"
option_end
option_find_lz4() {
local ldflags=""
local cflags=""
option "lz4"
cflags=`pkg-config --cflags liblz4 2>/dev/null`
ldflags=`pkg-config --libs liblz4 2>/dev/null`
if test_z "${cflags}"; then
cflags="-I/usr/include"
fi
if test_z "${ldflags}"; then
ldflags="-llz4"
fi
add_cflags "${cflags}"
add_ldflags "${ldflags}"
option_end
}
# the sv option
option "sv"
add_cfuncs "semver_tryn"
add_cincludes "semver.h"
add_links "sv"
before_check "option_find_sv"
option_end
option_find_sv() {
local ldflags=""
local cflags=""
option "sv"
cflags=`pkg-config --cflags libsv 2>/dev/null`
ldflags=`pkg-config --libs libsv 2>/dev/null`
if test_z "${cflags}"; then
cflags="-I/usr/include"
fi
if test_z "${ldflags}"; then
ldflags="-lsv"
fi
add_cflags "${cflags}"
add_ldflags "${ldflags}"
option_end
}
# the tbox option
option "tbox"
add_cfuncs "tb_exit" "tb_md5_init" "tb_charset_conv_data"
add_cincludes "tbox/tbox.h"
add_links "tbox"
before_check "option_find_tbox"
option_end
option_find_tbox() {
local ldflags=""
local cflags=""
option "tbox"
cflags=`pkg-config --cflags libtbox 2>/dev/null`
ldflags=`pkg-config --libs libtbox 2>/dev/null`
if test_z "${cflags}"; then
cflags="-I/usr/include"
fi
if test_z "${ldflags}"; then
ldflags="-ltbox"
fi
add_cflags "${cflags}"
add_ldflags "${ldflags}"
option_end
}
# add projects
if ! has_config "external"; then
if is_config "runtime" "luajit"; then
includes "src/luajit"
else
includes "src/lua"
fi
includes "src/lua-cjson"
includes "src/lz4"
includes "src/sv"
includes "src/tbox"
fi
includes "src/xmake"
includes "src/demo"