blob: 7741354097e05e67d103511d02683debd6615a5f [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) {
Mike Klein82364ba2016-10-24 16:49:15 -040012 if (host_os == "win") {
Mike Klein67702f62016-12-09 10:32:28 -050013 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar.exe"
14 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang.exe"
15 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++.exe"
16 } else {
17 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
18 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
19 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
Mike Klein82364ba2016-10-24 16:49:15 -040020 }
mtklein7d6fb2c2016-08-25 14:50:44 -070021 }
22
Mike Klein0f61faa2016-10-11 16:26:57 -040023 windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0"
herbb6318bf2016-09-16 13:29:57 -070024
Mike Klein121563e2016-10-04 17:09:13 -040025 extra_cflags = []
26 extra_cflags_c = []
27 extra_cflags_cc = []
28 extra_ldflags = []
mtkleincab0bb72016-08-26 13:43:19 -070029
mtklein60b7ab72016-09-20 12:09:12 -070030 cc_wrapper = ""
Herb Derby76073c12016-12-08 19:00:40 -050031 malloc = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070032}
33
Mike Klein82364ba2016-10-24 16:49:15 -040034if (host_os == "win") {
35 python = "python.bat"
36 stamp = "cmd.exe /c echo >"
37} else {
38 python = "python"
39 stamp = "touch"
40}
41
Mike Klein87c36f22016-11-13 10:29:25 -050042is_clang = is_android || is_ios || is_mac || (cc == "clang" && cxx == "clang++")
43if (!is_clang && !is_win) {
Mike Klein461d3282016-10-11 13:51:55 -040044 is_clang = exec_script("is_clang.py",
45 [
46 cc,
47 cxx,
48 ],
49 "value")
50}
mtkleinf347c512016-09-26 08:40:12 -070051
Mike Klein7d302882016-11-03 14:06:31 -040052if (is_ios) {
Mike Klein7a5e0f32017-03-13 09:25:33 -070053 sdk = "iphoneos"
54 if (target_cpu == "x86" || target_cpu == "x64") {
55 sdk = "iphonesimulator"
56 }
57 ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string")
Mike Klein7d302882016-11-03 14:06:31 -040058}
59
mtkleinb9be9792016-09-16 14:44:18 -070060config("default") {
61 asmflags = []
62 cflags = []
63 cflags_c = []
64 cflags_cc = []
65 defines = []
66 ldflags = []
Herb Derby76073c12016-12-08 19:00:40 -050067 libs = []
mtkleinb9be9792016-09-16 14:44:18 -070068
69 if (is_win) {
70 cflags += [
71 "/FS", # Preserve previous PDB behavior.
herbb6318bf2016-09-16 13:29:57 -070072 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040073 "/WX", # Treat warnings as errors.
Ben Wagnere6b274e2017-01-03 17:09:59 -050074 "/utf-8", # Set Source and Executable character sets to UTF-8.
herbb6318bf2016-09-16 13:29:57 -070075 ]
mtkleinb9be9792016-09-16 14:44:18 -070076 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040077 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
78 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070079 "WIN32_LEAN_AND_MEAN",
80 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070081 ]
Mike Klein0f61faa2016-10-11 16:26:57 -040082 include_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040083 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040084
Mike Kleind3016832016-10-12 15:52:44 -040085 # For local builds.
Mike Klein0f61faa2016-10-11 16:26:57 -040086 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040087 "$windk/../Windows Kits/8.1/Include/shared",
Mike Klein3eb71212016-10-11 17:08:53 -040088 "$windk/../Windows Kits/8.1/Include/um",
Brian Osman21d742d2017-01-10 13:31:33 -050089 "$windk/../Windows Kits/8.1/Include/winrt",
Mike Kleincc300a12016-10-12 16:25:27 -040090
Mike Kleind3016832016-10-12 15:52:44 -040091 # For builds using win_toolchain asset.
Brian Osman3f289332017-01-10 10:38:23 -050092 "$windk/win_sdk/Include/10.0.14393.0/shared",
93 "$windk/win_sdk/Include/10.0.14393.0/ucrt",
94 "$windk/win_sdk/Include/10.0.14393.0/um",
Brian Osman21d742d2017-01-10 13:31:33 -050095 "$windk/win_sdk/Include/10.0.14393.0/winrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040096 ]
Mike Klein3eb71212016-10-11 17:08:53 -040097 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040098 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040099 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
100 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -0400101
Mike Kleind3016832016-10-12 15:52:44 -0400102 # For builds using win_toolchain asset.
Brian Osman3f289332017-01-10 10:38:23 -0500103 "$windk/win_sdk/Lib/10.0.14393.0/ucrt/$target_cpu",
104 "$windk/win_sdk/Lib/10.0.14393.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -0400105 ]
Mike Klein0bc5a762016-10-12 22:42:55 -0400106 if (target_cpu == "x86") {
107 lib_dirs += [ "$windk/VC/lib" ]
108 } else {
109 lib_dirs += [ "$windk/VC/lib/amd64" ]
110 }
mtkleinb9be9792016-09-16 14:44:18 -0700111 } else {
112 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700113 "-fstrict-aliasing",
114 "-fPIC",
115 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -0700116 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700117 ]
mtkleinb9be9792016-09-16 14:44:18 -0700118 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700119 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700120 "-fno-threadsafe-statics",
121 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700122 ]
mtkleinb9be9792016-09-16 14:44:18 -0700123 }
herbb6318bf2016-09-16 13:29:57 -0700124
mtkleinb9be9792016-09-16 14:44:18 -0700125 if (current_cpu == "arm") {
126 cflags += [
127 "-march=armv7-a",
128 "-mfpu=neon",
129 "-mthumb",
130 ]
131 } else if (current_cpu == "mipsel") {
132 cflags += [
Mike Kleine6320032017-03-04 05:39:54 -0500133 "-no-integrated-as", # Clang <4.0 doesn't understand 'usw' mnemonic.
mtkleinb9be9792016-09-16 14:44:18 -0700134 "-march=mips32r2",
135 "-mdspr2",
136 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400137 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700138 asmflags += [ "-m32" ]
139 cflags += [
140 "-m32",
141 "-msse2",
142 "-mfpmath=sse",
143 ]
144 ldflags += [ "-m32" ]
145 }
herbb6318bf2016-09-16 13:29:57 -0700146
Herb Derby76073c12016-12-08 19:00:40 -0500147 if (malloc != "" && !is_win) {
148 cflags += [
149 "-fno-builtin-malloc",
150 "-fno-builtin-calloc",
151 "-fno-builtin-realloc",
152 "-fno-builtin-free",
153 ]
154 libs += [ malloc ]
155 }
156
mtkleinb9be9792016-09-16 14:44:18 -0700157 if (is_android) {
158 asmflags += [
159 "--target=$ndk_target",
160 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
161 ]
162 cflags += [
163 "--sysroot=$ndk/platforms/$ndk_platform",
164 "--target=$ndk_target",
165 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
166 ]
167 cflags_cc += [
168 "-isystem$ndk/sources/android/support/include",
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500169 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/include",
170 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib/include",
mtkleinb9be9792016-09-16 14:44:18 -0700171 ]
172 ldflags += [
173 "--sysroot=$ndk/platforms/$ndk_platform",
174 "--target=$ndk_target",
175 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700176 ]
177 lib_dirs = [
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500178 "$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib",
mtkleinb9be9792016-09-16 14:44:18 -0700179 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
180 ]
herbb6318bf2016-09-16 13:29:57 -0700181
Mike Klein4fdc5432016-10-11 11:21:36 -0400182 if (current_cpu == "mips64el") {
183 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
184 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
185 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
186 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein978cceb2016-12-08 10:29:27 -0500187 ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein4fdc5432016-10-11 11:21:36 -0400188 }
189
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500190 libs += [ "gnustl_static" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700191 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700192
Mike Klein7d302882016-11-03 14:06:31 -0400193 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500194 _target = target_cpu
195 if (target_cpu == "arm") {
196 _target = "armv7"
Mike Klein7a5e0f32017-03-13 09:25:33 -0700197 } else if (target_cpu == "x86") {
198 _target = "i386"
199 } else if (target_cpu == "x64") {
200 _target = "x86_64"
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500201 }
Mike Klein4fe2b152017-02-17 15:36:01 -0500202 asmflags += [
203 "-isysroot",
204 ios_sysroot,
205 "-arch",
206 _target,
207 ]
Mike Klein7d302882016-11-03 14:06:31 -0400208 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500209 "-isysroot",
210 ios_sysroot,
211 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500212 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400213 ]
214 cflags_cc += [ "-stdlib=libc++" ]
215 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500216 "-isysroot",
217 ios_sysroot,
218 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500219 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400220 "-stdlib=libc++",
221 ]
Herb Derby76073c12016-12-08 19:00:40 -0500222 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400223 }
224
mtkleinb9be9792016-09-16 14:44:18 -0700225 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500226 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700227 }
228
229 if (sanitize != "") {
230 # You can either pass the sanitizers directly, e.g. "address,undefined",
231 # or pass one of the couple common aliases used by the bots.
232 sanitizers = sanitize
233 if (sanitize == "ASAN") {
234 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"
235 } else if (sanitize == "TSAN") {
236 sanitizers = "thread"
237 } else if (sanitize == "MSAN") {
238 sanitizers = "memory"
239 }
240
241 cflags += [
242 "-fsanitize=$sanitizers",
243 "-fno-sanitize-recover=$sanitizers",
244 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
245 ]
246 ldflags += [ "-fsanitize=$sanitizers" ]
247 if (sanitizers == "memory") {
248 cflags += [ "-fsanitize-memory-track-origins" ]
249 cflags_cc += [ "-stdlib=libc++" ]
250 ldflags += [ "-stdlib=libc++" ]
251 }
252 }
253}
254
Mike Klein6e55fef2016-10-26 11:41:47 -0400255config("no_exceptions") {
256 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
257 if (!is_win) {
258 cflags_cc = [ "-fno-exceptions" ]
259 }
260}
261
Mike Kleinc7165c22016-10-12 23:58:06 -0400262config("warnings") {
263 cflags = []
264 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400265 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400266 if (is_win) {
267 cflags += [
268 "/W3", # Turn on lots of warnings.
269
270 # Disable a bunch of warnings:
271 "/wd4244", # conversion from 'float' to 'int', possible loss of data
272 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
273 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
274
275 # Probably only triggers when /EHsc is enabled.
276 "/wd4291", # no matching operator delete found;
277 # memory will not be freed if initialization throws an exception
278 ]
279 } else {
280 cflags += [
281 "-Wall",
282 "-Wextra",
283 "-Winit-self",
284 "-Wpointer-arith",
285 "-Wsign-compare",
286 "-Wvla",
287
288 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500289 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400290 ]
291 cflags_cc += [ "-Wnon-virtual-dtor" ]
292
293 if (is_clang) {
294 cflags += [
295 "-Weverything",
296 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
297 ]
298
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500299 if ((target_cpu == "x86" && is_android) ||
300 (target_cpu == "arm" && is_ios)) {
301 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android and 32-bit iOS.
Mike Kleinc7165c22016-10-12 23:58:06 -0400302 # We're pretty sure it's actually 8-byte alignment.
303 cflags += [ "-Wno-over-aligned" ]
304 }
305
306 cflags += [
307 "-Wno-cast-align",
308 "-Wno-conditional-uninitialized",
309 "-Wno-conversion",
310 "-Wno-disabled-macro-expansion",
311 "-Wno-documentation",
312 "-Wno-documentation-unknown-command",
313 "-Wno-double-promotion",
314 "-Wno-exit-time-destructors", # TODO: OK outside libskia
315 "-Wno-float-conversion",
316 "-Wno-float-equal",
317 "-Wno-format-nonliteral",
318 "-Wno-global-constructors", # TODO: OK outside libskia
319 "-Wno-gnu-zero-variadic-macro-arguments",
320 "-Wno-missing-prototypes",
321 "-Wno-missing-variable-declarations",
322 "-Wno-pedantic",
323 "-Wno-reserved-id-macro",
324 "-Wno-shadow",
325 "-Wno-shift-sign-overflow",
326 "-Wno-sign-conversion",
Matt Sarettd3ed4022017-01-04 17:13:44 -0500327 "-Wno-signed-enum-bitfield",
Mike Kleinc7165c22016-10-12 23:58:06 -0400328 "-Wno-switch-enum",
329 "-Wno-undef",
330 "-Wno-unreachable-code",
331 "-Wno-unreachable-code-break",
332 "-Wno-unreachable-code-return",
333 "-Wno-unused-macros",
334 "-Wno-unused-member-function",
335 ]
336 cflags_cc += [
337 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400338 "-Wno-weak-vtables",
339 ]
340
341 # We are unlikely to want to fix these.
342 cflags += [
343 "-Wno-covered-switch-default",
344 "-Wno-deprecated",
345 "-Wno-implicit-fallthrough",
346 "-Wno-missing-noreturn",
347 "-Wno-old-style-cast",
348 "-Wno-padded",
349 ]
350 cflags_cc += [
351 "-Wno-c++98-compat",
352 "-Wno-c++98-compat-pedantic",
353 "-Wno-undefined-func-template",
354 ]
Mike Klein43c25262016-10-20 10:17:47 -0400355 cflags_objc += [
356 "-Wno-direct-ivar-access",
357 "-Wno-objc-interface-ivars",
358 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400359 }
360 }
361}
Mike Klein50500ad2016-11-16 12:13:44 -0500362config("warnings_except_public_headers") {
363 if (!is_win) {
364 cflags = [ "-Wno-unused-parameter" ]
365 }
366}
Mike Kleinc7165c22016-10-12 23:58:06 -0400367
Mike Klein121563e2016-10-04 17:09:13 -0400368config("extra_flags") {
369 cflags = extra_cflags
370 cflags_c = extra_cflags_c
371 cflags_cc = extra_cflags_cc
372 ldflags = extra_ldflags
373}
374
mtkleinb9be9792016-09-16 14:44:18 -0700375config("debug_symbols") {
376 # It's annoying to wait for full debug symbols to push over
377 # to Android devices. -gline-tables-only is a lot slimmer.
378 if (is_android) {
379 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400380 } else if (is_win) {
381 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400382 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400383 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700384 cflags = [ "-g" ]
385 }
386}
387
388config("no_rtti") {
389 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400390 if (is_win) {
391 cflags_cc = [ "/GR-" ]
392 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700393 cflags_cc = [ "-fno-rtti" ]
394 }
395 }
396}
397
398config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400399 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400400 cflags = [
401 "/O2",
402 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400403 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400404 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400405 ldflags = [
406 "/OPT:ICF",
407 "/OPT:REF",
408 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400409 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400410 cflags = [
411 "-O3",
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500412 "-fdata-sections",
413 "-ffunction-sections",
Mike Klein0bcfeac2016-10-19 22:24:10 -0400414 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500415 if (is_mac || is_ios) {
416 ldflags = [ "-dead_strip" ]
417 } else {
418 ldflags = [ "-Wl,--gc-sections" ]
419 }
herbb6318bf2016-09-16 13:29:57 -0700420 }
mtkleinb9be9792016-09-16 14:44:18 -0700421 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700422}
423
424config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500425 if (is_android) {
426 ldflags = [ "-pie" ]
427 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700428 ldflags = [ "-Wl,-rpath,@loader_path/." ]
429 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700430 ldflags = [
431 "-rdynamic",
432 "-Wl,-rpath,\$ORIGIN",
433 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500434 } else if (is_win) {
435 ldflags = [
436 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
437 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
438 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700439 }
440}
441
herbb6318bf2016-09-16 13:29:57 -0700442toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400443 lib_dir_switch = "/LIBPATH:"
444
Mike Klein0bc5a762016-10-12 22:42:55 -0400445 bin = "$windk/VC/bin/amd64"
446 env_setup = ""
447 if (target_cpu == "x86") {
448 bin += "_x86"
449 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
450 }
herbb6318bf2016-09-16 13:29:57 -0700451
Mike Kleined1b9022017-02-21 12:13:44 -0500452 tool("asm") {
453 command = "$env_setup$bin/ml64.exe /nologo /c /Fo {{output}} {{source}}"
454 outputs = [
455 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
456 ]
457 description = "assemble {{source}}"
458 }
459
herbb6318bf2016-09-16 13:29:57 -0700460 tool("cc") {
461 rspfile = "{{output}}.rsp"
462 precompiled_header_type = "msvc"
463 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
464
Mike Klein0f61faa2016-10-11 16:26:57 -0400465 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400466 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700467 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700468 outputs = [
469 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700470 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400471 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400472 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700473 }
474
475 tool("cxx") {
476 rspfile = "{{output}}.rsp"
477 precompiled_header_type = "msvc"
478 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
479
Mike Klein0f61faa2016-10-11 16:26:57 -0400480 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400481 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700482 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700483 outputs = [
484 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
485 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400486 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400487 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700488 }
herbb6318bf2016-09-16 13:29:57 -0700489
490 tool("alink") {
491 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700492
Mike Kleinc756e862016-10-13 14:31:01 -0400493 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700494 outputs = [
495 # Ignore {{output_extension}} and always use .lib, there's no reason to
496 # allow targets to override this extension on Windows.
497 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
498 ]
499 default_output_extension = ".lib"
500 default_output_dir = "{{target_out_dir}}"
501
Mike Klein0f61faa2016-10-11 16:26:57 -0400502 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700503 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400504 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700505 }
506
Mike Klein1a8d6752016-10-17 11:51:11 -0400507 tool("solink") {
508 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
509 libname = "${dllname}.lib"
510 pdbname = "${dllname}.pdb"
511 rspfile = "${dllname}.rsp"
512
513 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
514 outputs = [
515 dllname,
516 libname,
517 pdbname,
518 ]
519 default_output_extension = ".dll"
520 default_output_dir = "{{root_out_dir}}"
521
522 link_output = libname
523 depend_output = libname
524 runtime_outputs = [
525 dllname,
526 pdbname,
527 ]
528
529 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
530 restat = true
531
532 # inputs_newline works around a fixed per-line buffer size in the linker.
533 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
534 description = "link {{output}}"
535 }
536
herbb6318bf2016-09-16 13:29:57 -0700537 tool("link") {
538 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
539 pdbname = "$exename.pdb"
540 rspfile = "$exename.rsp"
541
Mike Klein0bc5a762016-10-12 22:42:55 -0400542 command =
543 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700544
545 default_output_extension = ".exe"
546 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700547 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700548 exename,
549 ]
mtkleinb9be9792016-09-16 14:44:18 -0700550
Mike Klein0f61faa2016-10-11 16:26:57 -0400551 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700552 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400553 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700554 }
555
herbb6318bf2016-09-16 13:29:57 -0700556 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400557 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400558 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700559 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400560
561 tool("copy") {
562 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400563 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400564 description = "copy {{source}} {{output}}"
565 }
herbb6318bf2016-09-16 13:29:57 -0700566}
567
mtklein7fbfbbe2016-07-21 12:25:45 -0700568toolchain("gcc_like") {
569 lib_switch = "-l"
570 lib_dir_switch = "-L"
571
572 tool("cc") {
573 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400574 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700575 depsformat = "gcc"
576 outputs = [
577 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
578 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400579 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700580 }
581
582 tool("cxx") {
583 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400584 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700585 depsformat = "gcc"
586 outputs = [
587 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
588 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400589 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700590 }
591
Mike Klein43c25262016-10-20 10:17:47 -0400592 tool("objc") {
593 depfile = "{{output}}.d"
594 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
595 depsformat = "gcc"
596 outputs = [
597 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
598 ]
599 description = "compile {{source}}"
600 }
601
602 tool("objcxx") {
603 depfile = "{{output}}.d"
604 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
605 depsformat = "gcc"
606 outputs = [
607 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
608 ]
609 description = "compile {{source}}"
610 }
611
mtklein7fbfbbe2016-07-21 12:25:45 -0700612 tool("asm") {
613 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700614 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700615 depsformat = "gcc"
616 outputs = [
617 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
618 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400619 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700620 }
621
622 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500623 rspfile = "{{output}}.rsp"
624 rspfile_content = "{{inputs}}"
625 ar_py = rebase_path("ar.py")
626 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700627 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700628 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700629 ]
630 default_output_extension = ".a"
631 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400632 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700633 }
634
635 tool("solink") {
636 soname = "{{target_output_name}}{{output_extension}}"
637
638 rpath = "-Wl,-soname,$soname"
639 if (is_mac) {
640 rpath = "-Wl,-install_name,@rpath/$soname"
641 }
642
Mike Klein121563e2016-10-04 17:09:13 -0400643 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700644 outputs = [
645 "{{root_out_dir}}/$soname",
646 ]
647 output_prefix = "lib"
648 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400649 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700650 }
651
652 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400653 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700654 outputs = [
655 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
656 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400657 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700658 }
659
660 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400661 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400662 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700663 }
664
665 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400666 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400667 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400668 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700669 }
670}