summaryrefslogtreecommitdiff
path: root/core/xmake.sh
blob: c8679027999d5fd2e9438e8856ba7e398da29b39 (plain)
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
#!/bin/sh

set_project "xmake"
set_version "2.7.4" "%Y%m%d%H%M"

# 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"

# 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_links "curses"
    add_cfuncs "initscr"
    add_cincludes "curses.h"
    add_defines "XM_CONFIG_API_HAVE_CURSES"
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-cjson option
option "lua_cjson"
    add_links "lua5.1-cjson"
    add_csnippets "
int luaopen_cjson(void *l);\n
void test() {\n
    luaopen_cjson(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() {
    option "lua"
        add_cflags `pkg-config --cflags lua5.4 2>/dev/null`
        add_ldflags `pkg-config --libs lua5.4 2>/dev/null`
    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() {
    option "luajit"
        add_cflags `pkg-config --cflags luajit 2>/dev/null`
        add_ldflags `pkg-config --libs luajit 2>/dev/null`
    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() {
    option "lz4"
        add_cflags `pkg-config --cflags liblz4 2>/dev/null`
        add_ldflags `pkg-config --libs liblz4 2>/dev/null`
    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() {
    option "sv"
        local dirs="/usr/local /usr"
        for dir in $dirs; do
            if test -f "${dir}/lib/libsv.a"; then
                add_linkdirs "${dir}/lib"
                add_includedirs "${dir}/include/sv"
                break
            fi
        done
    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() {
    option "tbox"
        local dirs="/usr/local /usr"
        for dir in $dirs; do
            if test -f "${dir}/lib/libtbox.a"; then
                add_linkdirs "${dir}/lib"
                add_includedirs "${dir}/include"
                break
            fi
        done
    option_end
}

# add projects
if ! has_config "lua"; then
    if is_config "runtime" "luajit"; then
        includes "src/luajit"
    else
        includes "src/lua"
    fi
fi
if ! has_config "lua_cjson"; then
    includes "src/lua-cjson"
fi
if ! has_config "lz4"; then
    includes "src/lz4"
fi
if ! has_config "sv"; then
    includes "src/sv"
fi
if ! has_config "tbox"; then
    includes "src/tbox"
fi
includes "src/xmake"
includes "src/demo"