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
|
declare_args() {
host_ar = ar
host_cc = cc
host_cxx = cxx
if (is_android) {
if (host_os == "win") {
target_ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar.exe"
target_cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang.exe"
target_cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++.exe"
} else {
target_ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
target_cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
target_cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
}
} else {
target_ar = ar
target_cc = cc
target_cxx = cxx
}
cc_wrapper = ""
}
if (host_os == "win") {
python = "python.bat"
stamp = "cmd.exe /c echo >"
} else {
python = "python"
stamp = "touch"
}
toolchain("msvc") {
lib_dir_switch = "/LIBPATH:"
if (msvc == 2015) {
bin = "$windk/VC/bin/amd64"
env_setup = ""
if (target_cpu == "x86") {
bin += "_x86"
env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
}
} else {
bin = "$windk/VC/Tools/MSVC/14.10.25017/bin/HostX64/$target_cpu"
env_setup = ""
if (target_cpu == "x86") {
print("Be sure to run")
print("\"$windk/VC/Auxiliary/Build/vcvarsall.bat\" amd64_x86")
print("to set up your environment before running ninja.")
}
}
if (clang_win != "") {
cl = "$clang_win/bin/clang-cl.exe"
} else {
cl = "$bin/cl.exe"
}
tool("asm") {
_ml = "ml"
if (target_cpu == "x64") {
_ml += "64"
}
command = "$env_setup$bin/$_ml.exe /nologo /c /Fo {{output}} {{source}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
]
description = "assemble {{source}}"
}
tool("cc") {
rspfile = "{{output}}.rsp"
precompiled_header_type = "msvc"
pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
# Label names may have spaces so pdbname must be quoted.
command = "$env_setup$cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
depsformat = "msvc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
]
rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
description = "compile {{source}}"
}
tool("cxx") {
rspfile = "{{output}}.rsp"
precompiled_header_type = "msvc"
pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
# Label names may have spaces so pdbname must be quoted.
command = "$env_setup$cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
depsformat = "msvc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
]
rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
description = "compile {{source}}"
}
tool("alink") {
rspfile = "{{output}}.rsp"
command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
outputs = [
# Ignore {{output_extension}} and always use .lib, there's no reason to
# allow targets to override this extension on Windows.
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
]
default_output_extension = ".lib"
default_output_dir = "{{target_out_dir}}"
# inputs_newline works around a fixed per-line buffer size in the linker.
rspfile_content = "{{inputs_newline}}"
description = "link {{output}}"
}
tool("solink") {
dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
libname = "${dllname}.lib"
pdbname = "${dllname}.pdb"
rspfile = "${dllname}.rsp"
command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
outputs = [
dllname,
libname,
pdbname,
]
default_output_extension = ".dll"
default_output_dir = "{{root_out_dir}}"
link_output = libname
depend_output = libname
runtime_outputs = [
dllname,
pdbname,
]
# I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
restat = true
# inputs_newline works around a fixed per-line buffer size in the linker.
rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
description = "link {{output}}"
}
tool("link") {
exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
pdbname = "$exename.pdb"
rspfile = "$exename.rsp"
command =
"$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
default_output_extension = ".exe"
default_output_dir = "{{root_out_dir}}"
outputs = [
exename,
]
# inputs_newline works around a fixed per-line buffer size in the linker.
rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
description = "link {{output}}"
}
tool("stamp") {
command = "$stamp {{output}}"
description = "stamp {{output}}"
}
tool("copy") {
cp_py = rebase_path("../cp.py")
command = "$python $cp_py {{source}} {{output}}"
description = "copy {{source}} {{output}}"
}
}
template("gcc_like_toolchain") {
toolchain(target_name) {
ar = invoker.ar
cc = invoker.cc
cxx = invoker.cxx
lib_switch = "-l"
lib_dir_switch = "-L"
tool("cc") {
depfile = "{{output}}.d"
command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
depsformat = "gcc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
description = "compile {{source}}"
}
tool("cxx") {
depfile = "{{output}}.d"
command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
description = "compile {{source}}"
}
tool("objc") {
depfile = "{{output}}.d"
command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
description = "compile {{source}}"
}
tool("objcxx") {
depfile = "{{output}}.d"
command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
description = "compile {{source}}"
}
tool("asm") {
depfile = "{{output}}.d"
command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
depsformat = "gcc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
description = "assemble {{source}}"
}
tool("alink") {
rspfile = "{{output}}.rsp"
rspfile_content = "{{inputs}}"
ar_py = rebase_path("../ar.py")
command = "$python $ar_py $ar {{output}} $rspfile"
outputs = [
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
]
default_output_extension = ".a"
output_prefix = "lib"
description = "link {{output}}"
}
tool("solink") {
soname = "{{target_output_name}}{{output_extension}}"
rpath = "-Wl,-soname,$soname"
if (is_mac) {
rpath = "-Wl,-install_name,@rpath/$soname"
}
command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
outputs = [
"{{root_out_dir}}/$soname",
]
output_prefix = "lib"
default_output_extension = ".so"
description = "link {{output}}"
}
tool("link") {
command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
outputs = [
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
]
description = "link {{output}}"
}
tool("stamp") {
command = "$stamp {{output}}"
description = "stamp {{output}}"
}
tool("copy") {
cp_py = rebase_path("../cp.py")
command = "$python $cp_py {{source}} {{output}}"
description = "copy {{source}} {{output}}"
}
toolchain_args = {
current_cpu = invoker.cpu
current_os = invoker.os
}
}
}
gcc_like_toolchain("gcc_like") {
cpu = current_cpu
os = current_os
ar = target_ar
cc = target_cc
cxx = target_cxx
}
gcc_like_toolchain("gcc_like_host") {
cpu = host_cpu
os = host_os
ar = host_ar
cc = host_cc
cxx = host_cxx
}
|