blob: 7d94f5a6eba26134161c4454ef57dfc1c18a41d8 [file] [log] [blame]
mtklein7fbfbbe2016-07-21 12:25:45 -07001# Copyright 2016 Google Inc.
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6declare_args() {
mtklein349cece2016-08-26 08:13:04 -07007 ar = "ar"
mtklein7fbfbbe2016-07-21 12:25:45 -07008 cc = "cc"
9 cxx = "c++"
mtklein8079ba62016-08-16 09:31:16 -070010
mtklein7d6fb2c2016-08-25 14:50:44 -070011 if (is_android) {
mtklein349cece2016-08-26 08:13:04 -070012 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
mtklein7d6fb2c2016-08-25 14:50:44 -070013 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
14 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
Mike Klein82364ba2016-10-24 16:49:15 -040015 if (host_os == "win") {
16 ar = ar + ".exe"
17 cc = cc + ".exe"
18 cxx = cxx + ".exe"
19 }
mtklein7d6fb2c2016-08-25 14:50:44 -070020 }
21
Mike Klein0f61faa2016-10-11 16:26:57 -040022 windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0"
herbb6318bf2016-09-16 13:29:57 -070023
Mike Klein121563e2016-10-04 17:09:13 -040024 extra_cflags = []
25 extra_cflags_c = []
26 extra_cflags_cc = []
27 extra_ldflags = []
mtkleincab0bb72016-08-26 13:43:19 -070028
mtklein60b7ab72016-09-20 12:09:12 -070029 cc_wrapper = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070030}
31
Mike Klein82364ba2016-10-24 16:49:15 -040032if (host_os == "win") {
33 python = "python.bat"
34 stamp = "cmd.exe /c echo >"
35} else {
36 python = "python"
37 stamp = "touch"
38}
39
Mike Klein461d3282016-10-11 13:51:55 -040040if (!is_win) {
41 is_clang = exec_script("is_clang.py",
42 [
43 cc,
44 cxx,
45 ],
46 "value")
47}
mtkleinf347c512016-09-26 08:40:12 -070048
Mike Klein7d302882016-11-03 14:06:31 -040049if (is_ios) {
50 ios_sysroot = exec_script("find_ios_sysroot.py", [], "trim string")
51}
52
mtkleinb9be9792016-09-16 14:44:18 -070053config("default") {
54 asmflags = []
55 cflags = []
56 cflags_c = []
57 cflags_cc = []
58 defines = []
59 ldflags = []
60
61 if (is_win) {
62 cflags += [
63 "/FS", # Preserve previous PDB behavior.
herbb6318bf2016-09-16 13:29:57 -070064 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040065 "/WX", # Treat warnings as errors.
herbb6318bf2016-09-16 13:29:57 -070066 ]
mtkleinb9be9792016-09-16 14:44:18 -070067 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040068 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
69 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070070 "WIN32_LEAN_AND_MEAN",
71 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070072 ]
Mike Klein0f61faa2016-10-11 16:26:57 -040073 include_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040074 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040075
Mike Kleind3016832016-10-12 15:52:44 -040076 # For local builds.
Mike Klein0f61faa2016-10-11 16:26:57 -040077 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040078 "$windk/../Windows Kits/8.1/Include/shared",
Mike Klein3eb71212016-10-11 17:08:53 -040079 "$windk/../Windows Kits/8.1/Include/um",
Mike Kleincc300a12016-10-12 16:25:27 -040080
Mike Kleind3016832016-10-12 15:52:44 -040081 # For builds using win_toolchain asset.
82 "$windk/win_sdk/Include/10.0.10586.0/shared",
83 "$windk/win_sdk/Include/10.0.10586.0/ucrt",
84 "$windk/win_sdk/Include/10.0.10586.0/um",
Mike Klein0f61faa2016-10-11 16:26:57 -040085 ]
Mike Klein3eb71212016-10-11 17:08:53 -040086 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040087 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040088 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
89 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -040090
Mike Kleind3016832016-10-12 15:52:44 -040091 # For builds using win_toolchain asset.
Mike Klein0bc5a762016-10-12 22:42:55 -040092 "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu",
93 "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -040094 ]
Mike Klein0bc5a762016-10-12 22:42:55 -040095 if (target_cpu == "x86") {
96 lib_dirs += [ "$windk/VC/lib" ]
97 } else {
98 lib_dirs += [ "$windk/VC/lib/amd64" ]
99 }
mtkleinb9be9792016-09-16 14:44:18 -0700100 } else {
101 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700102 "-fstrict-aliasing",
103 "-fPIC",
104 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -0700105 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700106 ]
mtkleinb9be9792016-09-16 14:44:18 -0700107 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700108 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700109 "-fno-threadsafe-statics",
110 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700111 ]
mtkleinb9be9792016-09-16 14:44:18 -0700112 }
herbb6318bf2016-09-16 13:29:57 -0700113
mtkleinb9be9792016-09-16 14:44:18 -0700114 if (current_cpu == "arm") {
115 cflags += [
116 "-march=armv7-a",
117 "-mfpu=neon",
118 "-mthumb",
119 ]
120 } else if (current_cpu == "mipsel") {
121 cflags += [
122 "-march=mips32r2",
123 "-mdspr2",
124 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400125 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700126 asmflags += [ "-m32" ]
127 cflags += [
128 "-m32",
129 "-msse2",
130 "-mfpmath=sse",
131 ]
132 ldflags += [ "-m32" ]
133 }
herbb6318bf2016-09-16 13:29:57 -0700134
mtkleinb9be9792016-09-16 14:44:18 -0700135 if (is_android) {
136 asmflags += [
137 "--target=$ndk_target",
138 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
139 ]
140 cflags += [
141 "--sysroot=$ndk/platforms/$ndk_platform",
142 "--target=$ndk_target",
143 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
144 ]
145 cflags_cc += [
146 "-isystem$ndk/sources/android/support/include",
Mike Klein4fdc5432016-10-11 11:21:36 -0400147 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
148 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
mtkleinb9be9792016-09-16 14:44:18 -0700149 ]
150 ldflags += [
151 "--sysroot=$ndk/platforms/$ndk_platform",
152 "--target=$ndk_target",
153 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
154 "-pie",
155 ]
156 lib_dirs = [
157 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
158 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
159 ]
herbb6318bf2016-09-16 13:29:57 -0700160
Mike Klein4fdc5432016-10-11 11:21:36 -0400161 if (current_cpu == "mips64el") {
162 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
163 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
164 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
165 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
166 ldflags += [
167 # Clang will try to link these two files, but not find them. Again, do it manually.
168 "-nostartfiles",
169 "$ndk/platforms/$ndk_platform/usr/lib64/crtbegin_dynamic.o",
170 "$ndk/platforms/$ndk_platform/usr/lib64/crtend_android.o",
171 ]
172 }
173
mtkleinb9be9792016-09-16 14:44:18 -0700174 libs = [
175 # Order matters here! Keep these three in exactly this order.
176 "c++_static",
177 "c++abi",
178 "android_support",
179 ]
180 if (target_cpu == "arm") {
181 libs += [ "unwind" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700182 }
183 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700184
Mike Klein7d302882016-11-03 14:06:31 -0400185 if (is_ios) {
186 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500187 "-isysroot",
188 ios_sysroot,
189 "-arch",
190 target_cpu,
Mike Klein7d302882016-11-03 14:06:31 -0400191 ]
192 cflags_cc += [ "-stdlib=libc++" ]
193 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500194 "-isysroot",
195 ios_sysroot,
196 "-arch",
197 target_cpu,
Mike Klein7d302882016-11-03 14:06:31 -0400198 "-stdlib=libc++",
199 ]
200 libs = [ "objc" ]
201
202 # We used to link all our iOS tools together, so none actually defines main().
203 # Instead they each define their own entry point, which our iOS mega-app called.
204 # If we can we'd like to not do that anymore. While we're building both ways, here's
205 # our clever hack to give each tool back its own main().
206 cflags += [
207 "-Ddm_main=main",
208 "-Dnanobench_main=main",
209 "-Dtool_main=main",
210 "-Dtest_main=main",
211 ]
212 }
213
mtkleinb9be9792016-09-16 14:44:18 -0700214 if (is_linux) {
215 libs = [ "pthread" ]
216 }
217
218 if (sanitize != "") {
219 # You can either pass the sanitizers directly, e.g. "address,undefined",
220 # or pass one of the couple common aliases used by the bots.
221 sanitizers = sanitize
222 if (sanitize == "ASAN") {
223 sanitizers = "address,bool,function,integer-divide-by-zero,nonnull-attribute,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
224 } else if (sanitize == "TSAN") {
225 sanitizers = "thread"
226 } else if (sanitize == "MSAN") {
227 sanitizers = "memory"
228 }
229
230 cflags += [
231 "-fsanitize=$sanitizers",
232 "-fno-sanitize-recover=$sanitizers",
233 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
234 ]
235 ldflags += [ "-fsanitize=$sanitizers" ]
236 if (sanitizers == "memory") {
237 cflags += [ "-fsanitize-memory-track-origins" ]
238 cflags_cc += [ "-stdlib=libc++" ]
239 ldflags += [ "-stdlib=libc++" ]
240 }
241 }
242}
243
Mike Klein6e55fef2016-10-26 11:41:47 -0400244config("no_exceptions") {
245 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
246 if (!is_win) {
247 cflags_cc = [ "-fno-exceptions" ]
248 }
249}
250
Mike Kleinc7165c22016-10-12 23:58:06 -0400251config("warnings") {
252 cflags = []
253 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400254 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400255 if (is_win) {
256 cflags += [
257 "/W3", # Turn on lots of warnings.
258
259 # Disable a bunch of warnings:
260 "/wd4244", # conversion from 'float' to 'int', possible loss of data
261 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
262 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
263
264 # Probably only triggers when /EHsc is enabled.
265 "/wd4291", # no matching operator delete found;
266 # memory will not be freed if initialization throws an exception
267 ]
268 } else {
269 cflags += [
270 "-Wall",
271 "-Wextra",
272 "-Winit-self",
273 "-Wpointer-arith",
274 "-Wsign-compare",
275 "-Wvla",
276
277 "-Wno-deprecated-declarations",
278 "-Wno-unused-parameter",
279 ]
280 cflags_cc += [ "-Wnon-virtual-dtor" ]
281
282 if (is_clang) {
283 cflags += [
284 "-Weverything",
285 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
286 ]
287
288 if (is_android && target_cpu == "x86") {
289 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
290 # We're pretty sure it's actually 8-byte alignment.
291 cflags += [ "-Wno-over-aligned" ]
292 }
293
294 cflags += [
295 "-Wno-cast-align",
296 "-Wno-conditional-uninitialized",
297 "-Wno-conversion",
298 "-Wno-disabled-macro-expansion",
299 "-Wno-documentation",
300 "-Wno-documentation-unknown-command",
301 "-Wno-double-promotion",
302 "-Wno-exit-time-destructors", # TODO: OK outside libskia
303 "-Wno-float-conversion",
304 "-Wno-float-equal",
305 "-Wno-format-nonliteral",
306 "-Wno-global-constructors", # TODO: OK outside libskia
307 "-Wno-gnu-zero-variadic-macro-arguments",
308 "-Wno-missing-prototypes",
309 "-Wno-missing-variable-declarations",
310 "-Wno-pedantic",
311 "-Wno-reserved-id-macro",
312 "-Wno-shadow",
313 "-Wno-shift-sign-overflow",
314 "-Wno-sign-conversion",
315 "-Wno-switch-enum",
316 "-Wno-undef",
317 "-Wno-unreachable-code",
318 "-Wno-unreachable-code-break",
319 "-Wno-unreachable-code-return",
320 "-Wno-unused-macros",
321 "-Wno-unused-member-function",
322 ]
323 cflags_cc += [
324 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400325 "-Wno-weak-vtables",
326 ]
327
328 # We are unlikely to want to fix these.
329 cflags += [
330 "-Wno-covered-switch-default",
331 "-Wno-deprecated",
332 "-Wno-implicit-fallthrough",
333 "-Wno-missing-noreturn",
334 "-Wno-old-style-cast",
335 "-Wno-padded",
336 ]
337 cflags_cc += [
338 "-Wno-c++98-compat",
339 "-Wno-c++98-compat-pedantic",
340 "-Wno-undefined-func-template",
341 ]
Mike Klein43c25262016-10-20 10:17:47 -0400342 cflags_objc += [
343 "-Wno-direct-ivar-access",
344 "-Wno-objc-interface-ivars",
345 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400346 }
347 }
348}
349
Mike Klein121563e2016-10-04 17:09:13 -0400350config("extra_flags") {
351 cflags = extra_cflags
352 cflags_c = extra_cflags_c
353 cflags_cc = extra_cflags_cc
354 ldflags = extra_ldflags
355}
356
mtkleinb9be9792016-09-16 14:44:18 -0700357config("debug_symbols") {
358 # It's annoying to wait for full debug symbols to push over
359 # to Android devices. -gline-tables-only is a lot slimmer.
360 if (is_android) {
361 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400362 } else if (is_win) {
363 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400364 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400365 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700366 cflags = [ "-g" ]
367 }
368}
369
370config("no_rtti") {
371 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400372 if (is_win) {
373 cflags_cc = [ "/GR-" ]
374 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700375 cflags_cc = [ "-fno-rtti" ]
376 }
377 }
378}
379
380config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400381 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400382 cflags = [
383 "/O2",
384 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400385 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400386 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400387 ldflags = [
388 "/OPT:ICF",
389 "/OPT:REF",
390 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400391 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400392 cflags = [
393 "-O3",
394 "-momit-leaf-frame-pointer",
395 ]
herbb6318bf2016-09-16 13:29:57 -0700396 }
mtkleinb9be9792016-09-16 14:44:18 -0700397 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700398}
399
400config("executable") {
401 if (is_mac) {
402 ldflags = [ "-Wl,-rpath,@loader_path/." ]
403 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700404 ldflags = [
405 "-rdynamic",
406 "-Wl,-rpath,\$ORIGIN",
407 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500408 } else if (is_win) {
409 ldflags = [
410 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
411 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
412 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700413 }
414}
415
herbb6318bf2016-09-16 13:29:57 -0700416toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400417 lib_dir_switch = "/LIBPATH:"
418
Mike Klein0bc5a762016-10-12 22:42:55 -0400419 bin = "$windk/VC/bin/amd64"
420 env_setup = ""
421 if (target_cpu == "x86") {
422 bin += "_x86"
423 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
424 }
herbb6318bf2016-09-16 13:29:57 -0700425
426 tool("cc") {
427 rspfile = "{{output}}.rsp"
428 precompiled_header_type = "msvc"
429 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
430
Mike Klein0f61faa2016-10-11 16:26:57 -0400431 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400432 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700433 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700434 outputs = [
435 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700436 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400437 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400438 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700439 }
440
441 tool("cxx") {
442 rspfile = "{{output}}.rsp"
443 precompiled_header_type = "msvc"
444 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
445
Mike Klein0f61faa2016-10-11 16:26:57 -0400446 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400447 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700448 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700449 outputs = [
450 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
451 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400452 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400453 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700454 }
herbb6318bf2016-09-16 13:29:57 -0700455
456 tool("alink") {
457 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700458
Mike Kleinc756e862016-10-13 14:31:01 -0400459 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700460 outputs = [
461 # Ignore {{output_extension}} and always use .lib, there's no reason to
462 # allow targets to override this extension on Windows.
463 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
464 ]
465 default_output_extension = ".lib"
466 default_output_dir = "{{target_out_dir}}"
467
Mike Klein0f61faa2016-10-11 16:26:57 -0400468 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700469 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400470 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700471 }
472
Mike Klein1a8d6752016-10-17 11:51:11 -0400473 tool("solink") {
474 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
475 libname = "${dllname}.lib"
476 pdbname = "${dllname}.pdb"
477 rspfile = "${dllname}.rsp"
478
479 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
480 outputs = [
481 dllname,
482 libname,
483 pdbname,
484 ]
485 default_output_extension = ".dll"
486 default_output_dir = "{{root_out_dir}}"
487
488 link_output = libname
489 depend_output = libname
490 runtime_outputs = [
491 dllname,
492 pdbname,
493 ]
494
495 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
496 restat = true
497
498 # inputs_newline works around a fixed per-line buffer size in the linker.
499 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
500 description = "link {{output}}"
501 }
502
herbb6318bf2016-09-16 13:29:57 -0700503 tool("link") {
504 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
505 pdbname = "$exename.pdb"
506 rspfile = "$exename.rsp"
507
Mike Klein0bc5a762016-10-12 22:42:55 -0400508 command =
509 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700510
511 default_output_extension = ".exe"
512 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700513 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700514 exename,
515 ]
mtkleinb9be9792016-09-16 14:44:18 -0700516
Mike Klein0f61faa2016-10-11 16:26:57 -0400517 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700518 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400519 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700520 }
521
herbb6318bf2016-09-16 13:29:57 -0700522 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400523 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400524 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700525 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400526
527 tool("copy") {
528 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400529 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400530 description = "copy {{source}} {{output}}"
531 }
herbb6318bf2016-09-16 13:29:57 -0700532}
533
mtklein7fbfbbe2016-07-21 12:25:45 -0700534toolchain("gcc_like") {
535 lib_switch = "-l"
536 lib_dir_switch = "-L"
537
538 tool("cc") {
539 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400540 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700541 depsformat = "gcc"
542 outputs = [
543 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
544 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400545 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700546 }
547
548 tool("cxx") {
549 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400550 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700551 depsformat = "gcc"
552 outputs = [
553 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
554 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400555 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700556 }
557
Mike Klein43c25262016-10-20 10:17:47 -0400558 tool("objc") {
559 depfile = "{{output}}.d"
560 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
561 depsformat = "gcc"
562 outputs = [
563 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
564 ]
565 description = "compile {{source}}"
566 }
567
568 tool("objcxx") {
569 depfile = "{{output}}.d"
570 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
571 depsformat = "gcc"
572 outputs = [
573 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
574 ]
575 description = "compile {{source}}"
576 }
577
mtklein7fbfbbe2016-07-21 12:25:45 -0700578 tool("asm") {
579 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700580 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700581 depsformat = "gcc"
582 outputs = [
583 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
584 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400585 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700586 }
587
588 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500589 rspfile = "{{output}}.rsp"
590 rspfile_content = "{{inputs}}"
591 ar_py = rebase_path("ar.py")
592 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700593 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700594 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700595 ]
596 default_output_extension = ".a"
597 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400598 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700599 }
600
601 tool("solink") {
602 soname = "{{target_output_name}}{{output_extension}}"
603
604 rpath = "-Wl,-soname,$soname"
605 if (is_mac) {
606 rpath = "-Wl,-install_name,@rpath/$soname"
607 }
608
Mike Klein121563e2016-10-04 17:09:13 -0400609 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700610 outputs = [
611 "{{root_out_dir}}/$soname",
612 ]
613 output_prefix = "lib"
614 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400615 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700616 }
617
618 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400619 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700620 outputs = [
621 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
622 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400623 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700624 }
625
626 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400627 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400628 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700629 }
630
631 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400632 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400633 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400634 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700635 }
636}