blob: b223a0a1c1b0fb91aed7075aa2904ffcadd876b7 [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 Klein4fe2b152017-02-17 15:36:01 -0500193 asmflags += [
194 "-isysroot",
195 ios_sysroot,
196 "-arch",
197 _target,
198 ]
Mike Klein7d302882016-11-03 14:06:31 -0400199 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500200 "-isysroot",
201 ios_sysroot,
202 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500203 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400204 ]
205 cflags_cc += [ "-stdlib=libc++" ]
206 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500207 "-isysroot",
208 ios_sysroot,
209 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500210 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400211 "-stdlib=libc++",
212 ]
Herb Derby76073c12016-12-08 19:00:40 -0500213 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400214 }
215
mtkleinb9be9792016-09-16 14:44:18 -0700216 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500217 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700218 }
219
220 if (sanitize != "") {
221 # You can either pass the sanitizers directly, e.g. "address,undefined",
222 # or pass one of the couple common aliases used by the bots.
223 sanitizers = sanitize
224 if (sanitize == "ASAN") {
225 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"
226 } else if (sanitize == "TSAN") {
227 sanitizers = "thread"
228 } else if (sanitize == "MSAN") {
229 sanitizers = "memory"
230 }
231
232 cflags += [
233 "-fsanitize=$sanitizers",
234 "-fno-sanitize-recover=$sanitizers",
235 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
236 ]
237 ldflags += [ "-fsanitize=$sanitizers" ]
238 if (sanitizers == "memory") {
239 cflags += [ "-fsanitize-memory-track-origins" ]
240 cflags_cc += [ "-stdlib=libc++" ]
241 ldflags += [ "-stdlib=libc++" ]
242 }
243 }
244}
245
Mike Klein6e55fef2016-10-26 11:41:47 -0400246config("no_exceptions") {
247 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
248 if (!is_win) {
249 cflags_cc = [ "-fno-exceptions" ]
250 }
251}
252
Mike Kleinc7165c22016-10-12 23:58:06 -0400253config("warnings") {
254 cflags = []
255 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400256 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400257 if (is_win) {
258 cflags += [
259 "/W3", # Turn on lots of warnings.
260
261 # Disable a bunch of warnings:
262 "/wd4244", # conversion from 'float' to 'int', possible loss of data
263 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
264 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
265
266 # Probably only triggers when /EHsc is enabled.
267 "/wd4291", # no matching operator delete found;
268 # memory will not be freed if initialization throws an exception
269 ]
270 } else {
271 cflags += [
272 "-Wall",
273 "-Wextra",
274 "-Winit-self",
275 "-Wpointer-arith",
276 "-Wsign-compare",
277 "-Wvla",
278
279 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500280 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400281 ]
282 cflags_cc += [ "-Wnon-virtual-dtor" ]
283
284 if (is_clang) {
285 cflags += [
286 "-Weverything",
287 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
288 ]
289
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500290 if ((target_cpu == "x86" && is_android) ||
291 (target_cpu == "arm" && is_ios)) {
292 # 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 -0400293 # We're pretty sure it's actually 8-byte alignment.
294 cflags += [ "-Wno-over-aligned" ]
295 }
296
297 cflags += [
298 "-Wno-cast-align",
299 "-Wno-conditional-uninitialized",
300 "-Wno-conversion",
301 "-Wno-disabled-macro-expansion",
302 "-Wno-documentation",
303 "-Wno-documentation-unknown-command",
304 "-Wno-double-promotion",
305 "-Wno-exit-time-destructors", # TODO: OK outside libskia
306 "-Wno-float-conversion",
307 "-Wno-float-equal",
308 "-Wno-format-nonliteral",
309 "-Wno-global-constructors", # TODO: OK outside libskia
310 "-Wno-gnu-zero-variadic-macro-arguments",
311 "-Wno-missing-prototypes",
312 "-Wno-missing-variable-declarations",
313 "-Wno-pedantic",
314 "-Wno-reserved-id-macro",
315 "-Wno-shadow",
316 "-Wno-shift-sign-overflow",
317 "-Wno-sign-conversion",
Matt Sarettd3ed4022017-01-04 17:13:44 -0500318 "-Wno-signed-enum-bitfield",
Mike Kleinc7165c22016-10-12 23:58:06 -0400319 "-Wno-switch-enum",
320 "-Wno-undef",
321 "-Wno-unreachable-code",
322 "-Wno-unreachable-code-break",
323 "-Wno-unreachable-code-return",
324 "-Wno-unused-macros",
325 "-Wno-unused-member-function",
326 ]
327 cflags_cc += [
328 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400329 "-Wno-weak-vtables",
330 ]
331
332 # We are unlikely to want to fix these.
333 cflags += [
334 "-Wno-covered-switch-default",
335 "-Wno-deprecated",
336 "-Wno-implicit-fallthrough",
337 "-Wno-missing-noreturn",
338 "-Wno-old-style-cast",
339 "-Wno-padded",
340 ]
341 cflags_cc += [
342 "-Wno-c++98-compat",
343 "-Wno-c++98-compat-pedantic",
344 "-Wno-undefined-func-template",
345 ]
Mike Klein43c25262016-10-20 10:17:47 -0400346 cflags_objc += [
347 "-Wno-direct-ivar-access",
348 "-Wno-objc-interface-ivars",
349 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400350 }
351 }
352}
Mike Klein50500ad2016-11-16 12:13:44 -0500353config("warnings_except_public_headers") {
354 if (!is_win) {
355 cflags = [ "-Wno-unused-parameter" ]
356 }
357}
Mike Kleinc7165c22016-10-12 23:58:06 -0400358
Mike Klein121563e2016-10-04 17:09:13 -0400359config("extra_flags") {
360 cflags = extra_cflags
361 cflags_c = extra_cflags_c
362 cflags_cc = extra_cflags_cc
363 ldflags = extra_ldflags
364}
365
mtkleinb9be9792016-09-16 14:44:18 -0700366config("debug_symbols") {
367 # It's annoying to wait for full debug symbols to push over
368 # to Android devices. -gline-tables-only is a lot slimmer.
369 if (is_android) {
370 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400371 } else if (is_win) {
372 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400373 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400374 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700375 cflags = [ "-g" ]
376 }
377}
378
379config("no_rtti") {
380 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400381 if (is_win) {
382 cflags_cc = [ "/GR-" ]
383 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700384 cflags_cc = [ "-fno-rtti" ]
385 }
386 }
387}
388
389config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400390 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400391 cflags = [
392 "/O2",
393 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400394 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400395 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400396 ldflags = [
397 "/OPT:ICF",
398 "/OPT:REF",
399 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400400 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400401 cflags = [
402 "-O3",
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500403 "-fdata-sections",
404 "-ffunction-sections",
Mike Klein0bcfeac2016-10-19 22:24:10 -0400405 "-momit-leaf-frame-pointer",
406 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500407 if (is_mac || is_ios) {
408 ldflags = [ "-dead_strip" ]
409 } else {
410 ldflags = [ "-Wl,--gc-sections" ]
411 }
herbb6318bf2016-09-16 13:29:57 -0700412 }
mtkleinb9be9792016-09-16 14:44:18 -0700413 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700414}
415
416config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500417 if (is_android) {
418 ldflags = [ "-pie" ]
419 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700420 ldflags = [ "-Wl,-rpath,@loader_path/." ]
421 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700422 ldflags = [
423 "-rdynamic",
424 "-Wl,-rpath,\$ORIGIN",
425 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500426 } else if (is_win) {
427 ldflags = [
428 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
429 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
430 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700431 }
432}
433
herbb6318bf2016-09-16 13:29:57 -0700434toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400435 lib_dir_switch = "/LIBPATH:"
436
Mike Klein0bc5a762016-10-12 22:42:55 -0400437 bin = "$windk/VC/bin/amd64"
438 env_setup = ""
439 if (target_cpu == "x86") {
440 bin += "_x86"
441 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
442 }
herbb6318bf2016-09-16 13:29:57 -0700443
444 tool("cc") {
445 rspfile = "{{output}}.rsp"
446 precompiled_header_type = "msvc"
447 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
448
Mike Klein0f61faa2016-10-11 16:26:57 -0400449 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400450 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700451 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700452 outputs = [
453 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700454 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400455 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400456 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700457 }
458
459 tool("cxx") {
460 rspfile = "{{output}}.rsp"
461 precompiled_header_type = "msvc"
462 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
463
Mike Klein0f61faa2016-10-11 16:26:57 -0400464 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400465 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700466 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700467 outputs = [
468 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
469 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400470 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400471 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700472 }
herbb6318bf2016-09-16 13:29:57 -0700473
474 tool("alink") {
475 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700476
Mike Kleinc756e862016-10-13 14:31:01 -0400477 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700478 outputs = [
479 # Ignore {{output_extension}} and always use .lib, there's no reason to
480 # allow targets to override this extension on Windows.
481 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
482 ]
483 default_output_extension = ".lib"
484 default_output_dir = "{{target_out_dir}}"
485
Mike Klein0f61faa2016-10-11 16:26:57 -0400486 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700487 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400488 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700489 }
490
Mike Klein1a8d6752016-10-17 11:51:11 -0400491 tool("solink") {
492 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
493 libname = "${dllname}.lib"
494 pdbname = "${dllname}.pdb"
495 rspfile = "${dllname}.rsp"
496
497 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
498 outputs = [
499 dllname,
500 libname,
501 pdbname,
502 ]
503 default_output_extension = ".dll"
504 default_output_dir = "{{root_out_dir}}"
505
506 link_output = libname
507 depend_output = libname
508 runtime_outputs = [
509 dllname,
510 pdbname,
511 ]
512
513 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
514 restat = true
515
516 # inputs_newline works around a fixed per-line buffer size in the linker.
517 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
518 description = "link {{output}}"
519 }
520
herbb6318bf2016-09-16 13:29:57 -0700521 tool("link") {
522 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
523 pdbname = "$exename.pdb"
524 rspfile = "$exename.rsp"
525
Mike Klein0bc5a762016-10-12 22:42:55 -0400526 command =
527 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700528
529 default_output_extension = ".exe"
530 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700531 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700532 exename,
533 ]
mtkleinb9be9792016-09-16 14:44:18 -0700534
Mike Klein0f61faa2016-10-11 16:26:57 -0400535 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700536 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400537 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700538 }
539
herbb6318bf2016-09-16 13:29:57 -0700540 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400541 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400542 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700543 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400544
545 tool("copy") {
546 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400547 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400548 description = "copy {{source}} {{output}}"
549 }
herbb6318bf2016-09-16 13:29:57 -0700550}
551
mtklein7fbfbbe2016-07-21 12:25:45 -0700552toolchain("gcc_like") {
553 lib_switch = "-l"
554 lib_dir_switch = "-L"
555
556 tool("cc") {
557 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400558 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700559 depsformat = "gcc"
560 outputs = [
561 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
562 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400563 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700564 }
565
566 tool("cxx") {
567 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400568 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700569 depsformat = "gcc"
570 outputs = [
571 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
572 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400573 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700574 }
575
Mike Klein43c25262016-10-20 10:17:47 -0400576 tool("objc") {
577 depfile = "{{output}}.d"
578 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
579 depsformat = "gcc"
580 outputs = [
581 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
582 ]
583 description = "compile {{source}}"
584 }
585
586 tool("objcxx") {
587 depfile = "{{output}}.d"
588 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
589 depsformat = "gcc"
590 outputs = [
591 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
592 ]
593 description = "compile {{source}}"
594 }
595
mtklein7fbfbbe2016-07-21 12:25:45 -0700596 tool("asm") {
597 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700598 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700599 depsformat = "gcc"
600 outputs = [
601 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
602 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400603 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700604 }
605
606 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500607 rspfile = "{{output}}.rsp"
608 rspfile_content = "{{inputs}}"
609 ar_py = rebase_path("ar.py")
610 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700611 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700612 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700613 ]
614 default_output_extension = ".a"
615 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400616 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700617 }
618
619 tool("solink") {
620 soname = "{{target_output_name}}{{output_extension}}"
621
622 rpath = "-Wl,-soname,$soname"
623 if (is_mac) {
624 rpath = "-Wl,-install_name,@rpath/$soname"
625 }
626
Mike Klein121563e2016-10-04 17:09:13 -0400627 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700628 outputs = [
629 "{{root_out_dir}}/$soname",
630 ]
631 output_prefix = "lib"
632 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400633 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700634 }
635
636 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400637 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700638 outputs = [
639 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
640 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400641 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700642 }
643
644 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400645 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400646 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700647 }
648
649 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400650 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400651 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400652 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700653 }
654}