blob: c71ec3f3bd06959a170d5ef5513197b391186219 [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 = ""
Herb Derby76073c12016-12-08 19:00:40 -050030 malloc = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070031}
32
Mike Klein82364ba2016-10-24 16:49:15 -040033if (host_os == "win") {
34 python = "python.bat"
35 stamp = "cmd.exe /c echo >"
36} else {
37 python = "python"
38 stamp = "touch"
39}
40
Mike Klein87c36f22016-11-13 10:29:25 -050041is_clang = is_android || is_ios || is_mac || (cc == "clang" && cxx == "clang++")
42if (!is_clang && !is_win) {
Mike Klein461d3282016-10-11 13:51:55 -040043 is_clang = exec_script("is_clang.py",
44 [
45 cc,
46 cxx,
47 ],
48 "value")
49}
mtkleinf347c512016-09-26 08:40:12 -070050
Mike Klein7d302882016-11-03 14:06:31 -040051if (is_ios) {
52 ios_sysroot = exec_script("find_ios_sysroot.py", [], "trim string")
53}
54
mtkleinb9be9792016-09-16 14:44:18 -070055config("default") {
56 asmflags = []
57 cflags = []
58 cflags_c = []
59 cflags_cc = []
60 defines = []
61 ldflags = []
Herb Derby76073c12016-12-08 19:00:40 -050062 libs = []
mtkleinb9be9792016-09-16 14:44:18 -070063
64 if (is_win) {
65 cflags += [
66 "/FS", # Preserve previous PDB behavior.
herbb6318bf2016-09-16 13:29:57 -070067 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040068 "/WX", # Treat warnings as errors.
herbb6318bf2016-09-16 13:29:57 -070069 ]
mtkleinb9be9792016-09-16 14:44:18 -070070 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040071 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
72 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070073 "WIN32_LEAN_AND_MEAN",
74 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070075 ]
Mike Klein0f61faa2016-10-11 16:26:57 -040076 include_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040077 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040078
Mike Kleind3016832016-10-12 15:52:44 -040079 # For local builds.
Mike Klein0f61faa2016-10-11 16:26:57 -040080 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040081 "$windk/../Windows Kits/8.1/Include/shared",
Mike Klein3eb71212016-10-11 17:08:53 -040082 "$windk/../Windows Kits/8.1/Include/um",
Mike Kleincc300a12016-10-12 16:25:27 -040083
Mike Kleind3016832016-10-12 15:52:44 -040084 # For builds using win_toolchain asset.
85 "$windk/win_sdk/Include/10.0.10586.0/shared",
86 "$windk/win_sdk/Include/10.0.10586.0/ucrt",
87 "$windk/win_sdk/Include/10.0.10586.0/um",
Mike Klein0f61faa2016-10-11 16:26:57 -040088 ]
Mike Klein3eb71212016-10-11 17:08:53 -040089 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040090 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040091 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
92 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -040093
Mike Kleind3016832016-10-12 15:52:44 -040094 # For builds using win_toolchain asset.
Mike Klein0bc5a762016-10-12 22:42:55 -040095 "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu",
96 "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -040097 ]
Mike Klein0bc5a762016-10-12 22:42:55 -040098 if (target_cpu == "x86") {
99 lib_dirs += [ "$windk/VC/lib" ]
100 } else {
101 lib_dirs += [ "$windk/VC/lib/amd64" ]
102 }
mtkleinb9be9792016-09-16 14:44:18 -0700103 } else {
104 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700105 "-fstrict-aliasing",
106 "-fPIC",
107 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -0700108 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700109 ]
mtkleinb9be9792016-09-16 14:44:18 -0700110 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700111 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700112 "-fno-threadsafe-statics",
113 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700114 ]
mtkleinb9be9792016-09-16 14:44:18 -0700115 }
herbb6318bf2016-09-16 13:29:57 -0700116
mtkleinb9be9792016-09-16 14:44:18 -0700117 if (current_cpu == "arm") {
118 cflags += [
119 "-march=armv7-a",
120 "-mfpu=neon",
121 "-mthumb",
122 ]
123 } else if (current_cpu == "mipsel") {
124 cflags += [
125 "-march=mips32r2",
126 "-mdspr2",
127 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400128 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700129 asmflags += [ "-m32" ]
130 cflags += [
131 "-m32",
132 "-msse2",
133 "-mfpmath=sse",
134 ]
135 ldflags += [ "-m32" ]
136 }
herbb6318bf2016-09-16 13:29:57 -0700137
Herb Derby76073c12016-12-08 19:00:40 -0500138 if (malloc != "" && !is_win) {
139 cflags += [
140 "-fno-builtin-malloc",
141 "-fno-builtin-calloc",
142 "-fno-builtin-realloc",
143 "-fno-builtin-free",
144 ]
145 libs += [ malloc ]
146 }
147
mtkleinb9be9792016-09-16 14:44:18 -0700148 if (is_android) {
149 asmflags += [
150 "--target=$ndk_target",
151 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
152 ]
153 cflags += [
154 "--sysroot=$ndk/platforms/$ndk_platform",
155 "--target=$ndk_target",
156 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
157 ]
158 cflags_cc += [
159 "-isystem$ndk/sources/android/support/include",
Mike Klein4fdc5432016-10-11 11:21:36 -0400160 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
161 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
mtkleinb9be9792016-09-16 14:44:18 -0700162 ]
163 ldflags += [
164 "--sysroot=$ndk/platforms/$ndk_platform",
165 "--target=$ndk_target",
166 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700167 ]
168 lib_dirs = [
169 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
170 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
171 ]
herbb6318bf2016-09-16 13:29:57 -0700172
Mike Klein4fdc5432016-10-11 11:21:36 -0400173 if (current_cpu == "mips64el") {
174 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
175 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
176 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
177 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein978cceb2016-12-08 10:29:27 -0500178 ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein4fdc5432016-10-11 11:21:36 -0400179 }
180
Herb Derby76073c12016-12-08 19:00:40 -0500181 libs += [
mtkleinb9be9792016-09-16 14:44:18 -0700182 # Order matters here! Keep these three in exactly this order.
183 "c++_static",
184 "c++abi",
185 "android_support",
186 ]
187 if (target_cpu == "arm") {
188 libs += [ "unwind" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700189 }
190 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700191
Mike Klein7d302882016-11-03 14:06:31 -0400192 if (is_ios) {
193 cflags += [
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 ]
199 cflags_cc += [ "-stdlib=libc++" ]
200 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500201 "-isysroot",
202 ios_sysroot,
203 "-arch",
204 target_cpu,
Mike Klein7d302882016-11-03 14:06:31 -0400205 "-stdlib=libc++",
206 ]
Herb Derby76073c12016-12-08 19:00:40 -0500207 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400208
209 # We used to link all our iOS tools together, so none actually defines main().
210 # Instead they each define their own entry point, which our iOS mega-app called.
211 # If we can we'd like to not do that anymore. While we're building both ways, here's
212 # our clever hack to give each tool back its own main().
213 cflags += [
214 "-Ddm_main=main",
215 "-Dnanobench_main=main",
216 "-Dtool_main=main",
217 "-Dtest_main=main",
218 ]
219 }
220
mtkleinb9be9792016-09-16 14:44:18 -0700221 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500222 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700223 }
224
225 if (sanitize != "") {
226 # You can either pass the sanitizers directly, e.g. "address,undefined",
227 # or pass one of the couple common aliases used by the bots.
228 sanitizers = sanitize
229 if (sanitize == "ASAN") {
230 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"
231 } else if (sanitize == "TSAN") {
232 sanitizers = "thread"
233 } else if (sanitize == "MSAN") {
234 sanitizers = "memory"
235 }
236
237 cflags += [
238 "-fsanitize=$sanitizers",
239 "-fno-sanitize-recover=$sanitizers",
240 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
241 ]
242 ldflags += [ "-fsanitize=$sanitizers" ]
243 if (sanitizers == "memory") {
244 cflags += [ "-fsanitize-memory-track-origins" ]
245 cflags_cc += [ "-stdlib=libc++" ]
246 ldflags += [ "-stdlib=libc++" ]
247 }
248 }
249}
250
Mike Klein6e55fef2016-10-26 11:41:47 -0400251config("no_exceptions") {
252 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
253 if (!is_win) {
254 cflags_cc = [ "-fno-exceptions" ]
255 }
256}
257
Mike Kleinc7165c22016-10-12 23:58:06 -0400258config("warnings") {
259 cflags = []
260 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400261 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400262 if (is_win) {
263 cflags += [
264 "/W3", # Turn on lots of warnings.
265
266 # Disable a bunch of warnings:
267 "/wd4244", # conversion from 'float' to 'int', possible loss of data
268 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
269 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
270
271 # Probably only triggers when /EHsc is enabled.
272 "/wd4291", # no matching operator delete found;
273 # memory will not be freed if initialization throws an exception
274 ]
275 } else {
276 cflags += [
277 "-Wall",
278 "-Wextra",
279 "-Winit-self",
280 "-Wpointer-arith",
281 "-Wsign-compare",
282 "-Wvla",
283
284 "-Wno-deprecated-declarations",
Mike Kleinc7165c22016-10-12 23:58:06 -0400285 ]
286 cflags_cc += [ "-Wnon-virtual-dtor" ]
287
288 if (is_clang) {
289 cflags += [
290 "-Weverything",
291 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
292 ]
293
294 if (is_android && target_cpu == "x86") {
295 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
296 # We're pretty sure it's actually 8-byte alignment.
297 cflags += [ "-Wno-over-aligned" ]
298 }
299
300 cflags += [
301 "-Wno-cast-align",
302 "-Wno-conditional-uninitialized",
303 "-Wno-conversion",
304 "-Wno-disabled-macro-expansion",
305 "-Wno-documentation",
306 "-Wno-documentation-unknown-command",
307 "-Wno-double-promotion",
308 "-Wno-exit-time-destructors", # TODO: OK outside libskia
309 "-Wno-float-conversion",
310 "-Wno-float-equal",
311 "-Wno-format-nonliteral",
312 "-Wno-global-constructors", # TODO: OK outside libskia
313 "-Wno-gnu-zero-variadic-macro-arguments",
314 "-Wno-missing-prototypes",
315 "-Wno-missing-variable-declarations",
316 "-Wno-pedantic",
317 "-Wno-reserved-id-macro",
318 "-Wno-shadow",
319 "-Wno-shift-sign-overflow",
320 "-Wno-sign-conversion",
321 "-Wno-switch-enum",
322 "-Wno-undef",
323 "-Wno-unreachable-code",
324 "-Wno-unreachable-code-break",
325 "-Wno-unreachable-code-return",
326 "-Wno-unused-macros",
327 "-Wno-unused-member-function",
328 ]
329 cflags_cc += [
330 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400331 "-Wno-weak-vtables",
332 ]
333
334 # We are unlikely to want to fix these.
335 cflags += [
336 "-Wno-covered-switch-default",
337 "-Wno-deprecated",
338 "-Wno-implicit-fallthrough",
339 "-Wno-missing-noreturn",
340 "-Wno-old-style-cast",
341 "-Wno-padded",
342 ]
343 cflags_cc += [
344 "-Wno-c++98-compat",
345 "-Wno-c++98-compat-pedantic",
346 "-Wno-undefined-func-template",
347 ]
Mike Klein43c25262016-10-20 10:17:47 -0400348 cflags_objc += [
349 "-Wno-direct-ivar-access",
350 "-Wno-objc-interface-ivars",
351 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400352 }
353 }
354}
Mike Klein50500ad2016-11-16 12:13:44 -0500355config("warnings_except_public_headers") {
356 if (!is_win) {
357 cflags = [ "-Wno-unused-parameter" ]
358 }
359}
Mike Kleinc7165c22016-10-12 23:58:06 -0400360
Mike Klein121563e2016-10-04 17:09:13 -0400361config("extra_flags") {
362 cflags = extra_cflags
363 cflags_c = extra_cflags_c
364 cflags_cc = extra_cflags_cc
365 ldflags = extra_ldflags
366}
367
mtkleinb9be9792016-09-16 14:44:18 -0700368config("debug_symbols") {
369 # It's annoying to wait for full debug symbols to push over
370 # to Android devices. -gline-tables-only is a lot slimmer.
371 if (is_android) {
372 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400373 } else if (is_win) {
374 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400375 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400376 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700377 cflags = [ "-g" ]
378 }
379}
380
381config("no_rtti") {
382 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400383 if (is_win) {
384 cflags_cc = [ "/GR-" ]
385 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700386 cflags_cc = [ "-fno-rtti" ]
387 }
388 }
389}
390
391config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400392 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400393 cflags = [
394 "/O2",
395 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400396 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400397 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400398 ldflags = [
399 "/OPT:ICF",
400 "/OPT:REF",
401 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400402 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400403 cflags = [
404 "-O3",
405 "-momit-leaf-frame-pointer",
406 ]
herbb6318bf2016-09-16 13:29:57 -0700407 }
mtkleinb9be9792016-09-16 14:44:18 -0700408 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700409}
410
411config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500412 if (is_android) {
413 ldflags = [ "-pie" ]
414 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700415 ldflags = [ "-Wl,-rpath,@loader_path/." ]
416 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700417 ldflags = [
418 "-rdynamic",
419 "-Wl,-rpath,\$ORIGIN",
420 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500421 } else if (is_win) {
422 ldflags = [
423 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
424 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
425 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700426 }
427}
428
herbb6318bf2016-09-16 13:29:57 -0700429toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400430 lib_dir_switch = "/LIBPATH:"
431
Mike Klein0bc5a762016-10-12 22:42:55 -0400432 bin = "$windk/VC/bin/amd64"
433 env_setup = ""
434 if (target_cpu == "x86") {
435 bin += "_x86"
436 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
437 }
herbb6318bf2016-09-16 13:29:57 -0700438
439 tool("cc") {
440 rspfile = "{{output}}.rsp"
441 precompiled_header_type = "msvc"
442 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
443
Mike Klein0f61faa2016-10-11 16:26:57 -0400444 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400445 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700446 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700447 outputs = [
448 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700449 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400450 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400451 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700452 }
453
454 tool("cxx") {
455 rspfile = "{{output}}.rsp"
456 precompiled_header_type = "msvc"
457 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
458
Mike Klein0f61faa2016-10-11 16:26:57 -0400459 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400460 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700461 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700462 outputs = [
463 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
464 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400465 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400466 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700467 }
herbb6318bf2016-09-16 13:29:57 -0700468
469 tool("alink") {
470 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700471
Mike Kleinc756e862016-10-13 14:31:01 -0400472 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700473 outputs = [
474 # Ignore {{output_extension}} and always use .lib, there's no reason to
475 # allow targets to override this extension on Windows.
476 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
477 ]
478 default_output_extension = ".lib"
479 default_output_dir = "{{target_out_dir}}"
480
Mike Klein0f61faa2016-10-11 16:26:57 -0400481 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700482 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400483 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700484 }
485
Mike Klein1a8d6752016-10-17 11:51:11 -0400486 tool("solink") {
487 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
488 libname = "${dllname}.lib"
489 pdbname = "${dllname}.pdb"
490 rspfile = "${dllname}.rsp"
491
492 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
493 outputs = [
494 dllname,
495 libname,
496 pdbname,
497 ]
498 default_output_extension = ".dll"
499 default_output_dir = "{{root_out_dir}}"
500
501 link_output = libname
502 depend_output = libname
503 runtime_outputs = [
504 dllname,
505 pdbname,
506 ]
507
508 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
509 restat = true
510
511 # inputs_newline works around a fixed per-line buffer size in the linker.
512 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
513 description = "link {{output}}"
514 }
515
herbb6318bf2016-09-16 13:29:57 -0700516 tool("link") {
517 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
518 pdbname = "$exename.pdb"
519 rspfile = "$exename.rsp"
520
Mike Klein0bc5a762016-10-12 22:42:55 -0400521 command =
522 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700523
524 default_output_extension = ".exe"
525 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700526 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700527 exename,
528 ]
mtkleinb9be9792016-09-16 14:44:18 -0700529
Mike Klein0f61faa2016-10-11 16:26:57 -0400530 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700531 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400532 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700533 }
534
herbb6318bf2016-09-16 13:29:57 -0700535 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400536 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400537 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700538 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400539
540 tool("copy") {
541 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400542 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400543 description = "copy {{source}} {{output}}"
544 }
herbb6318bf2016-09-16 13:29:57 -0700545}
546
mtklein7fbfbbe2016-07-21 12:25:45 -0700547toolchain("gcc_like") {
548 lib_switch = "-l"
549 lib_dir_switch = "-L"
550
551 tool("cc") {
552 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400553 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700554 depsformat = "gcc"
555 outputs = [
556 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
557 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400558 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700559 }
560
561 tool("cxx") {
562 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400563 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700564 depsformat = "gcc"
565 outputs = [
566 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
567 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400568 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700569 }
570
Mike Klein43c25262016-10-20 10:17:47 -0400571 tool("objc") {
572 depfile = "{{output}}.d"
573 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
574 depsformat = "gcc"
575 outputs = [
576 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
577 ]
578 description = "compile {{source}}"
579 }
580
581 tool("objcxx") {
582 depfile = "{{output}}.d"
583 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
584 depsformat = "gcc"
585 outputs = [
586 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
587 ]
588 description = "compile {{source}}"
589 }
590
mtklein7fbfbbe2016-07-21 12:25:45 -0700591 tool("asm") {
592 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700593 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700594 depsformat = "gcc"
595 outputs = [
596 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
597 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400598 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700599 }
600
601 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500602 rspfile = "{{output}}.rsp"
603 rspfile_content = "{{inputs}}"
604 ar_py = rebase_path("ar.py")
605 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700606 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700607 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700608 ]
609 default_output_extension = ".a"
610 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400611 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700612 }
613
614 tool("solink") {
615 soname = "{{target_output_name}}{{output_extension}}"
616
617 rpath = "-Wl,-soname,$soname"
618 if (is_mac) {
619 rpath = "-Wl,-install_name,@rpath/$soname"
620 }
621
Mike Klein121563e2016-10-04 17:09:13 -0400622 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700623 outputs = [
624 "{{root_out_dir}}/$soname",
625 ]
626 output_prefix = "lib"
627 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400628 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700629 }
630
631 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400632 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700633 outputs = [
634 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
635 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400636 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700637 }
638
639 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400640 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400641 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700642 }
643
644 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400645 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400646 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400647 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700648 }
649}