blob: ec3a1f1ee3a25ca08232d71d13ec6cfa8a637a7d [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) {
53 ios_sysroot = exec_script("find_ios_sysroot.py", [], "trim string")
54}
55
mtkleinb9be9792016-09-16 14:44:18 -070056config("default") {
57 asmflags = []
58 cflags = []
59 cflags_c = []
60 cflags_cc = []
61 defines = []
62 ldflags = []
Herb Derby76073c12016-12-08 19:00:40 -050063 libs = []
mtkleinb9be9792016-09-16 14:44:18 -070064
65 if (is_win) {
66 cflags += [
67 "/FS", # Preserve previous PDB behavior.
herbb6318bf2016-09-16 13:29:57 -070068 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040069 "/WX", # Treat warnings as errors.
Ben Wagnere6b274e2017-01-03 17:09:59 -050070 "/utf-8", # Set Source and Executable character sets to UTF-8.
herbb6318bf2016-09-16 13:29:57 -070071 ]
mtkleinb9be9792016-09-16 14:44:18 -070072 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040073 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
74 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070075 "WIN32_LEAN_AND_MEAN",
76 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070077 ]
Mike Klein0f61faa2016-10-11 16:26:57 -040078 include_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040079 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040080
Mike Kleind3016832016-10-12 15:52:44 -040081 # For local builds.
Mike Klein0f61faa2016-10-11 16:26:57 -040082 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040083 "$windk/../Windows Kits/8.1/Include/shared",
Mike Klein3eb71212016-10-11 17:08:53 -040084 "$windk/../Windows Kits/8.1/Include/um",
Brian Osman21d742d2017-01-10 13:31:33 -050085 "$windk/../Windows Kits/8.1/Include/winrt",
Mike Kleincc300a12016-10-12 16:25:27 -040086
Mike Kleind3016832016-10-12 15:52:44 -040087 # For builds using win_toolchain asset.
Brian Osman3f289332017-01-10 10:38:23 -050088 "$windk/win_sdk/Include/10.0.14393.0/shared",
89 "$windk/win_sdk/Include/10.0.14393.0/ucrt",
90 "$windk/win_sdk/Include/10.0.14393.0/um",
Brian Osman21d742d2017-01-10 13:31:33 -050091 "$windk/win_sdk/Include/10.0.14393.0/winrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040092 ]
Mike Klein3eb71212016-10-11 17:08:53 -040093 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040094 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040095 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
96 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -040097
Mike Kleind3016832016-10-12 15:52:44 -040098 # For builds using win_toolchain asset.
Brian Osman3f289332017-01-10 10:38:23 -050099 "$windk/win_sdk/Lib/10.0.14393.0/ucrt/$target_cpu",
100 "$windk/win_sdk/Lib/10.0.14393.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -0400101 ]
Mike Klein0bc5a762016-10-12 22:42:55 -0400102 if (target_cpu == "x86") {
103 lib_dirs += [ "$windk/VC/lib" ]
104 } else {
105 lib_dirs += [ "$windk/VC/lib/amd64" ]
106 }
mtkleinb9be9792016-09-16 14:44:18 -0700107 } else {
108 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700109 "-fstrict-aliasing",
110 "-fPIC",
111 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -0700112 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700113 ]
mtkleinb9be9792016-09-16 14:44:18 -0700114 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700115 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700116 "-fno-threadsafe-statics",
117 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700118 ]
mtkleinb9be9792016-09-16 14:44:18 -0700119 }
herbb6318bf2016-09-16 13:29:57 -0700120
mtkleinb9be9792016-09-16 14:44:18 -0700121 if (current_cpu == "arm") {
122 cflags += [
123 "-march=armv7-a",
124 "-mfpu=neon",
125 "-mthumb",
126 ]
127 } else if (current_cpu == "mipsel") {
128 cflags += [
129 "-march=mips32r2",
130 "-mdspr2",
131 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400132 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700133 asmflags += [ "-m32" ]
134 cflags += [
135 "-m32",
136 "-msse2",
137 "-mfpmath=sse",
138 ]
139 ldflags += [ "-m32" ]
140 }
herbb6318bf2016-09-16 13:29:57 -0700141
Herb Derby76073c12016-12-08 19:00:40 -0500142 if (malloc != "" && !is_win) {
143 cflags += [
144 "-fno-builtin-malloc",
145 "-fno-builtin-calloc",
146 "-fno-builtin-realloc",
147 "-fno-builtin-free",
148 ]
149 libs += [ malloc ]
150 }
151
mtkleinb9be9792016-09-16 14:44:18 -0700152 if (is_android) {
153 asmflags += [
154 "--target=$ndk_target",
155 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
156 ]
157 cflags += [
158 "--sysroot=$ndk/platforms/$ndk_platform",
159 "--target=$ndk_target",
160 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
161 ]
162 cflags_cc += [
163 "-isystem$ndk/sources/android/support/include",
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500164 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/include",
165 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib/include",
mtkleinb9be9792016-09-16 14:44:18 -0700166 ]
167 ldflags += [
168 "--sysroot=$ndk/platforms/$ndk_platform",
169 "--target=$ndk_target",
170 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700171 ]
172 lib_dirs = [
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500173 "$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib",
mtkleinb9be9792016-09-16 14:44:18 -0700174 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
175 ]
herbb6318bf2016-09-16 13:29:57 -0700176
Mike Klein4fdc5432016-10-11 11:21:36 -0400177 if (current_cpu == "mips64el") {
178 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
179 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
180 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
181 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein978cceb2016-12-08 10:29:27 -0500182 ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein4fdc5432016-10-11 11:21:36 -0400183 }
184
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500185 libs += [ "gnustl_static" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700186 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700187
Mike Klein7d302882016-11-03 14:06:31 -0400188 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500189 _target = target_cpu
190 if (target_cpu == "arm") {
191 _target = "armv7"
192 }
Mike Klein7d302882016-11-03 14:06:31 -0400193 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500194 "-isysroot",
195 ios_sysroot,
196 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500197 _target,
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",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500204 _target,
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 Kleindb402ca2016-12-13 12:46:05 -0500285 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400286 ]
287 cflags_cc += [ "-Wnon-virtual-dtor" ]
288
289 if (is_clang) {
290 cflags += [
291 "-Weverything",
292 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
293 ]
294
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500295 if ((target_cpu == "x86" && is_android) ||
296 (target_cpu == "arm" && is_ios)) {
297 # 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 -0400298 # We're pretty sure it's actually 8-byte alignment.
299 cflags += [ "-Wno-over-aligned" ]
300 }
301
302 cflags += [
303 "-Wno-cast-align",
304 "-Wno-conditional-uninitialized",
305 "-Wno-conversion",
306 "-Wno-disabled-macro-expansion",
307 "-Wno-documentation",
308 "-Wno-documentation-unknown-command",
309 "-Wno-double-promotion",
310 "-Wno-exit-time-destructors", # TODO: OK outside libskia
311 "-Wno-float-conversion",
312 "-Wno-float-equal",
313 "-Wno-format-nonliteral",
314 "-Wno-global-constructors", # TODO: OK outside libskia
315 "-Wno-gnu-zero-variadic-macro-arguments",
316 "-Wno-missing-prototypes",
317 "-Wno-missing-variable-declarations",
318 "-Wno-pedantic",
319 "-Wno-reserved-id-macro",
320 "-Wno-shadow",
321 "-Wno-shift-sign-overflow",
322 "-Wno-sign-conversion",
Matt Sarettd3ed4022017-01-04 17:13:44 -0500323 "-Wno-signed-enum-bitfield",
Mike Kleinc7165c22016-10-12 23:58:06 -0400324 "-Wno-switch-enum",
325 "-Wno-undef",
326 "-Wno-unreachable-code",
327 "-Wno-unreachable-code-break",
328 "-Wno-unreachable-code-return",
329 "-Wno-unused-macros",
330 "-Wno-unused-member-function",
331 ]
332 cflags_cc += [
333 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400334 "-Wno-weak-vtables",
335 ]
336
337 # We are unlikely to want to fix these.
338 cflags += [
339 "-Wno-covered-switch-default",
340 "-Wno-deprecated",
341 "-Wno-implicit-fallthrough",
342 "-Wno-missing-noreturn",
343 "-Wno-old-style-cast",
344 "-Wno-padded",
345 ]
346 cflags_cc += [
347 "-Wno-c++98-compat",
348 "-Wno-c++98-compat-pedantic",
349 "-Wno-undefined-func-template",
350 ]
Mike Klein43c25262016-10-20 10:17:47 -0400351 cflags_objc += [
352 "-Wno-direct-ivar-access",
353 "-Wno-objc-interface-ivars",
354 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400355 }
356 }
357}
Mike Klein50500ad2016-11-16 12:13:44 -0500358config("warnings_except_public_headers") {
359 if (!is_win) {
360 cflags = [ "-Wno-unused-parameter" ]
361 }
362}
Mike Kleinc7165c22016-10-12 23:58:06 -0400363
Mike Klein121563e2016-10-04 17:09:13 -0400364config("extra_flags") {
365 cflags = extra_cflags
366 cflags_c = extra_cflags_c
367 cflags_cc = extra_cflags_cc
368 ldflags = extra_ldflags
369}
370
mtkleinb9be9792016-09-16 14:44:18 -0700371config("debug_symbols") {
372 # It's annoying to wait for full debug symbols to push over
373 # to Android devices. -gline-tables-only is a lot slimmer.
374 if (is_android) {
375 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400376 } else if (is_win) {
377 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400378 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400379 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700380 cflags = [ "-g" ]
381 }
382}
383
384config("no_rtti") {
385 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400386 if (is_win) {
387 cflags_cc = [ "/GR-" ]
388 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700389 cflags_cc = [ "-fno-rtti" ]
390 }
391 }
392}
393
394config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400395 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400396 cflags = [
397 "/O2",
398 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400399 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400400 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400401 ldflags = [
402 "/OPT:ICF",
403 "/OPT:REF",
404 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400405 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400406 cflags = [
407 "-O3",
408 "-momit-leaf-frame-pointer",
409 ]
herbb6318bf2016-09-16 13:29:57 -0700410 }
mtkleinb9be9792016-09-16 14:44:18 -0700411 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700412}
413
414config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500415 if (is_android) {
416 ldflags = [ "-pie" ]
417 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700418 ldflags = [ "-Wl,-rpath,@loader_path/." ]
419 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700420 ldflags = [
421 "-rdynamic",
422 "-Wl,-rpath,\$ORIGIN",
423 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500424 } else if (is_win) {
425 ldflags = [
426 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
427 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
428 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700429 }
430}
431
herbb6318bf2016-09-16 13:29:57 -0700432toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400433 lib_dir_switch = "/LIBPATH:"
434
Mike Klein0bc5a762016-10-12 22:42:55 -0400435 bin = "$windk/VC/bin/amd64"
436 env_setup = ""
437 if (target_cpu == "x86") {
438 bin += "_x86"
439 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
440 }
herbb6318bf2016-09-16 13:29:57 -0700441
442 tool("cc") {
443 rspfile = "{{output}}.rsp"
444 precompiled_header_type = "msvc"
445 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
446
Mike Klein0f61faa2016-10-11 16:26:57 -0400447 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400448 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700449 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700450 outputs = [
451 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700452 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400453 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400454 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700455 }
456
457 tool("cxx") {
458 rspfile = "{{output}}.rsp"
459 precompiled_header_type = "msvc"
460 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
461
Mike Klein0f61faa2016-10-11 16:26:57 -0400462 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400463 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700464 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700465 outputs = [
466 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
467 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400468 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400469 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700470 }
herbb6318bf2016-09-16 13:29:57 -0700471
472 tool("alink") {
473 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700474
Mike Kleinc756e862016-10-13 14:31:01 -0400475 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700476 outputs = [
477 # Ignore {{output_extension}} and always use .lib, there's no reason to
478 # allow targets to override this extension on Windows.
479 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
480 ]
481 default_output_extension = ".lib"
482 default_output_dir = "{{target_out_dir}}"
483
Mike Klein0f61faa2016-10-11 16:26:57 -0400484 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700485 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400486 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700487 }
488
Mike Klein1a8d6752016-10-17 11:51:11 -0400489 tool("solink") {
490 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
491 libname = "${dllname}.lib"
492 pdbname = "${dllname}.pdb"
493 rspfile = "${dllname}.rsp"
494
495 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
496 outputs = [
497 dllname,
498 libname,
499 pdbname,
500 ]
501 default_output_extension = ".dll"
502 default_output_dir = "{{root_out_dir}}"
503
504 link_output = libname
505 depend_output = libname
506 runtime_outputs = [
507 dllname,
508 pdbname,
509 ]
510
511 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
512 restat = true
513
514 # inputs_newline works around a fixed per-line buffer size in the linker.
515 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
516 description = "link {{output}}"
517 }
518
herbb6318bf2016-09-16 13:29:57 -0700519 tool("link") {
520 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
521 pdbname = "$exename.pdb"
522 rspfile = "$exename.rsp"
523
Mike Klein0bc5a762016-10-12 22:42:55 -0400524 command =
525 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700526
527 default_output_extension = ".exe"
528 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700529 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700530 exename,
531 ]
mtkleinb9be9792016-09-16 14:44:18 -0700532
Mike Klein0f61faa2016-10-11 16:26:57 -0400533 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700534 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400535 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700536 }
537
herbb6318bf2016-09-16 13:29:57 -0700538 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400539 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400540 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700541 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400542
543 tool("copy") {
544 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400545 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400546 description = "copy {{source}} {{output}}"
547 }
herbb6318bf2016-09-16 13:29:57 -0700548}
549
mtklein7fbfbbe2016-07-21 12:25:45 -0700550toolchain("gcc_like") {
551 lib_switch = "-l"
552 lib_dir_switch = "-L"
553
554 tool("cc") {
555 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400556 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700557 depsformat = "gcc"
558 outputs = [
559 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
560 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400561 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700562 }
563
564 tool("cxx") {
565 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400566 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700567 depsformat = "gcc"
568 outputs = [
569 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
570 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400571 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700572 }
573
Mike Klein43c25262016-10-20 10:17:47 -0400574 tool("objc") {
575 depfile = "{{output}}.d"
576 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
577 depsformat = "gcc"
578 outputs = [
579 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
580 ]
581 description = "compile {{source}}"
582 }
583
584 tool("objcxx") {
585 depfile = "{{output}}.d"
586 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
587 depsformat = "gcc"
588 outputs = [
589 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
590 ]
591 description = "compile {{source}}"
592 }
593
mtklein7fbfbbe2016-07-21 12:25:45 -0700594 tool("asm") {
595 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700596 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700597 depsformat = "gcc"
598 outputs = [
599 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
600 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400601 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700602 }
603
604 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500605 rspfile = "{{output}}.rsp"
606 rspfile_content = "{{inputs}}"
607 ar_py = rebase_path("ar.py")
608 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700609 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700610 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700611 ]
612 default_output_extension = ".a"
613 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400614 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700615 }
616
617 tool("solink") {
618 soname = "{{target_output_name}}{{output_extension}}"
619
620 rpath = "-Wl,-soname,$soname"
621 if (is_mac) {
622 rpath = "-Wl,-install_name,@rpath/$soname"
623 }
624
Mike Klein121563e2016-10-04 17:09:13 -0400625 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700626 outputs = [
627 "{{root_out_dir}}/$soname",
628 ]
629 output_prefix = "lib"
630 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400631 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700632 }
633
634 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400635 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700636 outputs = [
637 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
638 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400639 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700640 }
641
642 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400643 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400644 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700645 }
646
647 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400648 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400649 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400650 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700651 }
652}