blob: 14a8a9196542aaa3de7aa03dbbbbc43d8c490a1d [file] [log] [blame]
Ethan Nicholas762466e2017-06-29 10:03:38 -04001declare_args() {
2 host_ar = ar
3 host_cc = cc
4 host_cxx = cxx
5
6 if (is_android) {
7 if (host_os == "win") {
8 target_ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar.exe"
9 target_cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang.exe"
10 target_cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++.exe"
11 } else {
12 target_ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
13 target_cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
14 target_cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
15 }
16 } else {
17 target_ar = ar
18 target_cc = cc
19 target_cxx = cxx
20 }
21
22 cc_wrapper = ""
23}
24
25if (host_os == "win") {
26 python = "python.bat"
27 stamp = "cmd.exe /c echo >"
28} else {
29 python = "python"
30 stamp = "touch"
31}
32
33toolchain("msvc") {
34 lib_dir_switch = "/LIBPATH:"
35
36 if (msvc == 2015) {
37 bin = "$windk/VC/bin/amd64"
38 env_setup = ""
39 if (target_cpu == "x86") {
40 bin += "_x86"
41 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
42 }
43 } else {
44 bin = "$windk/VC/Tools/MSVC/14.10.25017/bin/HostX64/$target_cpu"
45 env_setup = ""
46 if (target_cpu == "x86") {
47 print("Be sure to run")
Mike Klein263cef72017-07-17 10:26:26 -040048 print("\"$windk/VC/Auxiliary/Build/vcvarsall.bat\" amd64_x86")
Ethan Nicholas762466e2017-06-29 10:03:38 -040049 print("to set up your environment before running ninja.")
50 }
51 }
52
Mike Kleinc722f792017-07-31 11:57:21 -040053 if (clang_win != "") {
54 cl = "$clang_win/bin/clang-cl.exe"
55 } else {
56 cl = "$bin/cl.exe"
57 }
58
59
Ethan Nicholas762466e2017-06-29 10:03:38 -040060 tool("asm") {
61 _ml = "ml"
62 if (target_cpu == "x64") {
63 _ml += "64"
64 }
65 command = "$env_setup$bin/$_ml.exe /nologo /c /Fo {{output}} {{source}}"
66 outputs = [
67 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
68 ]
69 description = "assemble {{source}}"
70 }
71
72 tool("cc") {
73 rspfile = "{{output}}.rsp"
74 precompiled_header_type = "msvc"
75 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
76
77 # Label names may have spaces so pdbname must be quoted.
Mike Kleinc722f792017-07-31 11:57:21 -040078 command = "$env_setup$cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
Ethan Nicholas762466e2017-06-29 10:03:38 -040079 depsformat = "msvc"
80 outputs = [
81 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
82 ]
83 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
84 description = "compile {{source}}"
85 }
86
87 tool("cxx") {
88 rspfile = "{{output}}.rsp"
89 precompiled_header_type = "msvc"
90 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
91
92 # Label names may have spaces so pdbname must be quoted.
Mike Kleinc722f792017-07-31 11:57:21 -040093 command = "$env_setup$cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
Ethan Nicholas762466e2017-06-29 10:03:38 -040094 depsformat = "msvc"
95 outputs = [
96 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
97 ]
98 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
99 description = "compile {{source}}"
100 }
101
102 tool("alink") {
103 rspfile = "{{output}}.rsp"
104
105 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
106 outputs = [
107 # Ignore {{output_extension}} and always use .lib, there's no reason to
108 # allow targets to override this extension on Windows.
109 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
110 ]
111 default_output_extension = ".lib"
112 default_output_dir = "{{target_out_dir}}"
113
114 # inputs_newline works around a fixed per-line buffer size in the linker.
115 rspfile_content = "{{inputs_newline}}"
116 description = "link {{output}}"
117 }
118
119 tool("solink") {
120 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
121 libname = "${dllname}.lib"
122 pdbname = "${dllname}.pdb"
123 rspfile = "${dllname}.rsp"
124
125 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
126 outputs = [
127 dllname,
128 libname,
129 pdbname,
130 ]
131 default_output_extension = ".dll"
132 default_output_dir = "{{root_out_dir}}"
133
134 link_output = libname
135 depend_output = libname
136 runtime_outputs = [
137 dllname,
138 pdbname,
139 ]
140
141 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
142 restat = true
143
144 # inputs_newline works around a fixed per-line buffer size in the linker.
145 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
146 description = "link {{output}}"
147 }
148
149 tool("link") {
150 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
151 pdbname = "$exename.pdb"
152 rspfile = "$exename.rsp"
153
154 command =
155 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
156
157 default_output_extension = ".exe"
158 default_output_dir = "{{root_out_dir}}"
159 outputs = [
160 exename,
161 ]
162
163 # inputs_newline works around a fixed per-line buffer size in the linker.
164 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
165 description = "link {{output}}"
166 }
167
168 tool("stamp") {
169 command = "$stamp {{output}}"
170 description = "stamp {{output}}"
171 }
172
173 tool("copy") {
174 cp_py = rebase_path("../cp.py")
175 command = "$python $cp_py {{source}} {{output}}"
176 description = "copy {{source}} {{output}}"
177 }
178}
179
180template("gcc_like_toolchain") {
181 toolchain(target_name) {
182 ar = invoker.ar
183 cc = invoker.cc
184 cxx = invoker.cxx
185 lib_switch = "-l"
186 lib_dir_switch = "-L"
187
188 tool("cc") {
189 depfile = "{{output}}.d"
190 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
191 depsformat = "gcc"
192 outputs = [
193 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
194 ]
195 description = "compile {{source}}"
196 }
197
198 tool("cxx") {
199 depfile = "{{output}}.d"
200 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
201 depsformat = "gcc"
202 outputs = [
203 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
204 ]
205 description = "compile {{source}}"
206 }
207
208 tool("objc") {
209 depfile = "{{output}}.d"
210 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
211 depsformat = "gcc"
212 outputs = [
213 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
214 ]
215 description = "compile {{source}}"
216 }
217
218 tool("objcxx") {
219 depfile = "{{output}}.d"
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400220 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400221 depsformat = "gcc"
222 outputs = [
223 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
224 ]
225 description = "compile {{source}}"
226 }
227
228 tool("asm") {
229 depfile = "{{output}}.d"
230 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
231 depsformat = "gcc"
232 outputs = [
233 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
234 ]
235 description = "assemble {{source}}"
236 }
237
238 tool("alink") {
239 rspfile = "{{output}}.rsp"
240 rspfile_content = "{{inputs}}"
241 ar_py = rebase_path("../ar.py")
242 command = "$python $ar_py $ar {{output}} $rspfile"
243 outputs = [
244 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
245 ]
246 default_output_extension = ".a"
247 output_prefix = "lib"
248 description = "link {{output}}"
249 }
250
251 tool("solink") {
252 soname = "{{target_output_name}}{{output_extension}}"
253
254 rpath = "-Wl,-soname,$soname"
255 if (is_mac) {
256 rpath = "-Wl,-install_name,@rpath/$soname"
257 }
258
259 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
260 outputs = [
261 "{{root_out_dir}}/$soname",
262 ]
263 output_prefix = "lib"
264 default_output_extension = ".so"
265 description = "link {{output}}"
266 }
267
268 tool("link") {
269 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
270 outputs = [
271 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
272 ]
273 description = "link {{output}}"
274 }
275
276 tool("stamp") {
277 command = "$stamp {{output}}"
278 description = "stamp {{output}}"
279 }
280
281 tool("copy") {
282 cp_py = rebase_path("../cp.py")
283 command = "$python $cp_py {{source}} {{output}}"
284 description = "copy {{source}} {{output}}"
285 }
286
287 toolchain_args = {
288 current_cpu = invoker.cpu
289 current_os = invoker.os
290 }
291 }
292}
293
294gcc_like_toolchain("gcc_like") {
295 cpu = current_cpu
296 os = current_os
297 ar = target_ar
298 cc = target_cc
299 cxx = target_cxx
300}
301
302gcc_like_toolchain("gcc_like_host") {
303 cpu = host_cpu
304 os = host_os
305 ar = host_ar
306 cc = host_cc
307 cxx = host_cxx
308}