forked from actboy168/lua-debug
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake.lua
More file actions
187 lines (170 loc) · 4.31 KB
/
make.lua
File metadata and controls
187 lines (170 loc) · 4.31 KB
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
local lm = require "luamake"
local fs = require 'bee.filesystem'
local bindir = "publish/runtime/" .. lm.runtime_platform
--the generated file must store into different directory
local defined = require "compile.luajit.defined"
local arch = defined.arch
local LUAJIT_ENABLE_LUA52COMPAT = defined.LUAJIT_ENABLE_LUA52COMPAT
local LUAJIT_NUMMODE = defined.LUAJIT_NUMMODE
local luajitDir = defined.luajitDir
local is_old_version_luajit = defined.is_old_version_luajit
local LJLIB_C = {
luajitDir .. "/lib_base.c ",
luajitDir .. "/lib_math.c ",
luajitDir .. "/lib_bit.c ",
luajitDir .. "/lib_string.c ",
luajitDir .. "/lib_table.c ",
luajitDir .. "/lib_io.c ",
luajitDir .. "/lib_os.c ",
luajitDir .. "/lib_package.c ",
luajitDir .. "/lib_debug.c ",
luajitDir .. "/lib_jit.c ",
luajitDir .. "/lib_ffi.c ",
luajitDir .. "/lib_buffer.c",
}
local function buildvmX(value)
local fileName = string.format("lj_%s.h", value)
lm:build(fileName) {
deps = "buildvm",
args = {
"$bin/buildvm",
string.format(" -m %s -o ", value), "$out",
LJLIB_C,
},
outputs = lm.bindir .. "/" .. fileName,
}
end
local LJVM_MODE = "elfasm"
if lm.os == "windows" then
LJVM_MODE = "peobj"
elseif lm.os == "macos" then
LJVM_MODE = "machasm"
end
lm:build "lj_vm.S" {
deps = "buildvm",
args = {
"$bin/buildvm",
"-m",
LJVM_MODE,
"-o", "$out",
},
outputs = lm.bindir .. "/lj_vm.S",
}
buildvmX("bcdef")
buildvmX("ffdef")
buildvmX("libdef")
buildvmX("recdef")
lm:build "lj_folddef.h" {
deps = "buildvm",
args = {
"$bin/buildvm",
" -m folddef -o ", "$out", "$in",
},
inputs = luajitDir .. "/lj_opt_fold.c",
outputs = lm.bindir .. "/lj_folddef.h",
}
local _FILE_OFFSET_BITS = "_FILE_OFFSET_BITS=64"
local _LARGEFILE_SOURCE = "_LARGEFILE_SOURCE"
local U_FORTIFY_SOURCE = "-U_FORTIFY_SOURCE"
local LUAJIT_UNWIND_EXTERNAL = "LUAJIT_UNWIND_EXTERNAL"
local LUA_MULTILIB = "LUA_MULTILIB=\"lib\""
lm:build "lj_vm.obj" {
deps = { "lj_vm.S" },
args = {
"$cc",
"-Wall",
"-D" .. _FILE_OFFSET_BITS,
"-D" .. _LARGEFILE_SOURCE,
U_FORTIFY_SOURCE,
"-D" .. LUA_MULTILIB,
"-D" .. LUAJIT_ENABLE_LUA52COMPAT,
"-D" .. LUAJIT_NUMMODE,
"-fno-stack-protector",
"-D" .. LUAJIT_UNWIND_EXTERNAL,
lm.os == "macos" and "-target " .. lm.target,
"-c -o", "$out", "$in",
},
inputs = lm.bindir .. "/lj_vm.S",
outputs = lm.bindir .. "/lj_vm.obj",
}
local has_str_hash = fs.exists(luajitDir.. '/lj_str_hash.c')
if has_str_hash then
local lj_str_hash_flags = {
"-fno-stack-protector",
U_FORTIFY_SOURCE,
"-fPIC",
}
if arch == "x64" then
table.insert(lj_str_hash_flags, "-msse4.2")
end
lm:source_set("lj_str_hash.c") {
rootdir = luajitDir,
sources = { "lj_str_hash.c" },
includes = { '.' },
defines = {
LUAJIT_UNWIND_EXTERNAL,
_FILE_OFFSET_BITS,
_LARGEFILE_SOURCE,
LUA_MULTILIB,
LUAJIT_ENABLE_LUA52COMPAT,
LUAJIT_NUMMODE,
},
linux = {
defines = {
"_GNU_SOURCE",
}
},
flags = lj_str_hash_flags
}
end
lm:executable("luajit/lua") {
rootdir = luajitDir,
bindir = bindir,
objdeps = {
"lj_vm.obj",
"lj_folddef.h",
"lj_bcdef.h",
"lj_ffdef.h",
"lj_libdef.h",
"lj_recdef.h",
},
deps = {
has_str_hash and "lj_str_hash.c",
},
sources = {
"luajit.c",
"lj_*.c",
"lib_*.c",
has_str_hash and "!lj_str_hash.c",
lm.bindir .. "/lj_vm.obj",
},
includes = {
".",
lm.bindir
},
links = "m",
linux = {
links = "dl",
ldflags = "-Wl,-E",
defines = {
"_GNU_SOURCE",
}
},
android = {
links = "dl"
},
defines = {
LUAJIT_UNWIND_EXTERNAL,
_FILE_OFFSET_BITS,
_LARGEFILE_SOURCE,
LUA_MULTILIB,
LUAJIT_ENABLE_LUA52COMPAT,
LUAJIT_NUMMODE,
},
flags = {
"-fno-stack-protector",
U_FORTIFY_SOURCE,
"-fPIC"
},
visibility = "default",
}