blob: 37852251cb51cae5c1fd553df61e03cd9d5483c4 [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
mtkleinb9be9792016-09-16 14:44:18 -0700210 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500211 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700212 }
213
214 if (sanitize != "") {
215 # You can either pass the sanitizers directly, e.g. "address,undefined",
216 # or pass one of the couple common aliases used by the bots.
217 sanitizers = sanitize
218 if (sanitize == "ASAN") {
219 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"
220 } else if (sanitize == "TSAN") {
221 sanitizers = "thread"
222 } else if (sanitize == "MSAN") {
223 sanitizers = "memory"
224 }
225
226 cflags += [
227 "-fsanitize=$sanitizers",
228 "-fno-sanitize-recover=$sanitizers",
229 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
230 ]
231 ldflags += [ "-fsanitize=$sanitizers" ]
232 if (sanitizers == "memory") {
233 cflags += [ "-fsanitize-memory-track-origins" ]
234 cflags_cc += [ "-stdlib=libc++" ]
235 ldflags += [ "-stdlib=libc++" ]
236 }
237 }
238}
239
Mike Klein6e55fef2016-10-26 11:41:47 -0400240config("no_exceptions") {
241 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
242 if (!is_win) {
243 cflags_cc = [ "-fno-exceptions" ]
244 }
245}
246
Mike Kleinc7165c22016-10-12 23:58:06 -0400247config("warnings") {
248 cflags = []
249 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400250 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400251 if (is_win) {
252 cflags += [
253 "/W3", # Turn on lots of warnings.
254
255 # Disable a bunch of warnings:
256 "/wd4244", # conversion from 'float' to 'int', possible loss of data
257 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
258 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
259
260 # Probably only triggers when /EHsc is enabled.
261 "/wd4291", # no matching operator delete found;
262 # memory will not be freed if initialization throws an exception
263 ]
264 } else {
265 cflags += [
266 "-Wall",
267 "-Wextra",
268 "-Winit-self",
269 "-Wpointer-arith",
270 "-Wsign-compare",
271 "-Wvla",
272
273 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500274 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400275 ]
276 cflags_cc += [ "-Wnon-virtual-dtor" ]
277
278 if (is_clang) {
279 cflags += [
280 "-Weverything",
281 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
282 ]
283
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500284 if ((target_cpu == "x86" && is_android) ||
285 (target_cpu == "arm" && is_ios)) {
286 # 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 -0400287 # We're pretty sure it's actually 8-byte alignment.
288 cflags += [ "-Wno-over-aligned" ]
289 }
290
291 cflags += [
292 "-Wno-cast-align",
293 "-Wno-conditional-uninitialized",
294 "-Wno-conversion",
295 "-Wno-disabled-macro-expansion",
296 "-Wno-documentation",
297 "-Wno-documentation-unknown-command",
298 "-Wno-double-promotion",
299 "-Wno-exit-time-destructors", # TODO: OK outside libskia
300 "-Wno-float-conversion",
301 "-Wno-float-equal",
302 "-Wno-format-nonliteral",
303 "-Wno-global-constructors", # TODO: OK outside libskia
304 "-Wno-gnu-zero-variadic-macro-arguments",
305 "-Wno-missing-prototypes",
306 "-Wno-missing-variable-declarations",
307 "-Wno-pedantic",
308 "-Wno-reserved-id-macro",
309 "-Wno-shadow",
310 "-Wno-shift-sign-overflow",
311 "-Wno-sign-conversion",
Matt Sarettd3ed4022017-01-04 17:13:44 -0500312 "-Wno-signed-enum-bitfield",
Mike Kleinc7165c22016-10-12 23:58:06 -0400313 "-Wno-switch-enum",
314 "-Wno-undef",
315 "-Wno-unreachable-code",
316 "-Wno-unreachable-code-break",
317 "-Wno-unreachable-code-return",
318 "-Wno-unused-macros",
319 "-Wno-unused-member-function",
320 ]
321 cflags_cc += [
322 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400323 "-Wno-weak-vtables",
324 ]
325
326 # We are unlikely to want to fix these.
327 cflags += [
328 "-Wno-covered-switch-default",
329 "-Wno-deprecated",
330 "-Wno-implicit-fallthrough",
331 "-Wno-missing-noreturn",
332 "-Wno-old-style-cast",
333 "-Wno-padded",
334 ]
335 cflags_cc += [
336 "-Wno-c++98-compat",
337 "-Wno-c++98-compat-pedantic",
338 "-Wno-undefined-func-template",
339 ]
Mike Klein43c25262016-10-20 10:17:47 -0400340 cflags_objc += [
341 "-Wno-direct-ivar-access",
342 "-Wno-objc-interface-ivars",
343 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400344 }
345 }
346}
Mike Klein50500ad2016-11-16 12:13:44 -0500347config("warnings_except_public_headers") {
348 if (!is_win) {
349 cflags = [ "-Wno-unused-parameter" ]
350 }
351}
Mike Kleinc7165c22016-10-12 23:58:06 -0400352
Mike Klein121563e2016-10-04 17:09:13 -0400353config("extra_flags") {
354 cflags = extra_cflags
355 cflags_c = extra_cflags_c
356 cflags_cc = extra_cflags_cc
357 ldflags = extra_ldflags
358}
359
mtkleinb9be9792016-09-16 14:44:18 -0700360config("debug_symbols") {
361 # It's annoying to wait for full debug symbols to push over
362 # to Android devices. -gline-tables-only is a lot slimmer.
363 if (is_android) {
364 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400365 } else if (is_win) {
366 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400367 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400368 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700369 cflags = [ "-g" ]
370 }
371}
372
373config("no_rtti") {
374 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400375 if (is_win) {
376 cflags_cc = [ "/GR-" ]
377 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700378 cflags_cc = [ "-fno-rtti" ]
379 }
380 }
381}
382
383config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400384 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400385 cflags = [
386 "/O2",
387 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400388 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400389 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400390 ldflags = [
391 "/OPT:ICF",
392 "/OPT:REF",
393 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400394 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400395 cflags = [
396 "-O3",
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500397 "-fdata-sections",
398 "-ffunction-sections",
Mike Klein0bcfeac2016-10-19 22:24:10 -0400399 "-momit-leaf-frame-pointer",
400 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500401 if (is_mac || is_ios) {
402 ldflags = [ "-dead_strip" ]
403 } else {
404 ldflags = [ "-Wl,--gc-sections" ]
405 }
herbb6318bf2016-09-16 13:29:57 -0700406 }
mtkleinb9be9792016-09-16 14:44:18 -0700407 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700408}
409
410config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500411 if (is_android) {
412 ldflags = [ "-pie" ]
413 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700414 ldflags = [ "-Wl,-rpath,@loader_path/." ]
415 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700416 ldflags = [
417 "-rdynamic",
418 "-Wl,-rpath,\$ORIGIN",
419 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500420 } else if (is_win) {
421 ldflags = [
422 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
423 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
424 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700425 }
426}
427
herbb6318bf2016-09-16 13:29:57 -0700428toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400429 lib_dir_switch = "/LIBPATH:"
430
Mike Klein0bc5a762016-10-12 22:42:55 -0400431 bin = "$windk/VC/bin/amd64"
432 env_setup = ""
433 if (target_cpu == "x86") {
434 bin += "_x86"
435 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
436 }
herbb6318bf2016-09-16 13:29:57 -0700437
438 tool("cc") {
439 rspfile = "{{output}}.rsp"
440 precompiled_header_type = "msvc"
441 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
442
Mike Klein0f61faa2016-10-11 16:26:57 -0400443 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400444 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700445 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700446 outputs = [
447 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700448 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400449 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400450 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700451 }
452
453 tool("cxx") {
454 rspfile = "{{output}}.rsp"
455 precompiled_header_type = "msvc"
456 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
457
Mike Klein0f61faa2016-10-11 16:26:57 -0400458 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400459 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700460 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700461 outputs = [
462 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
463 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400464 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400465 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700466 }
herbb6318bf2016-09-16 13:29:57 -0700467
468 tool("alink") {
469 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700470
Mike Kleinc756e862016-10-13 14:31:01 -0400471 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700472 outputs = [
473 # Ignore {{output_extension}} and always use .lib, there's no reason to
474 # allow targets to override this extension on Windows.
475 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
476 ]
477 default_output_extension = ".lib"
478 default_output_dir = "{{target_out_dir}}"
479
Mike Klein0f61faa2016-10-11 16:26:57 -0400480 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700481 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400482 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700483 }
484
Mike Klein1a8d6752016-10-17 11:51:11 -0400485 tool("solink") {
486 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
487 libname = "${dllname}.lib"
488 pdbname = "${dllname}.pdb"
489 rspfile = "${dllname}.rsp"
490
491 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
492 outputs = [
493 dllname,
494 libname,
495 pdbname,
496 ]
497 default_output_extension = ".dll"
498 default_output_dir = "{{root_out_dir}}"
499
500 link_output = libname
501 depend_output = libname
502 runtime_outputs = [
503 dllname,
504 pdbname,
505 ]
506
507 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
508 restat = true
509
510 # inputs_newline works around a fixed per-line buffer size in the linker.
511 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
512 description = "link {{output}}"
513 }
514
herbb6318bf2016-09-16 13:29:57 -0700515 tool("link") {
516 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
517 pdbname = "$exename.pdb"
518 rspfile = "$exename.rsp"
519
Mike Klein0bc5a762016-10-12 22:42:55 -0400520 command =
521 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700522
523 default_output_extension = ".exe"
524 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700525 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700526 exename,
527 ]
mtkleinb9be9792016-09-16 14:44:18 -0700528
Mike Klein0f61faa2016-10-11 16:26:57 -0400529 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700530 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400531 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700532 }
533
herbb6318bf2016-09-16 13:29:57 -0700534 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400535 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400536 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700537 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400538
539 tool("copy") {
540 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400541 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400542 description = "copy {{source}} {{output}}"
543 }
herbb6318bf2016-09-16 13:29:57 -0700544}
545
mtklein7fbfbbe2016-07-21 12:25:45 -0700546toolchain("gcc_like") {
547 lib_switch = "-l"
548 lib_dir_switch = "-L"
549
550 tool("cc") {
551 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400552 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700553 depsformat = "gcc"
554 outputs = [
555 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
556 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400557 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700558 }
559
560 tool("cxx") {
561 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400562 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700563 depsformat = "gcc"
564 outputs = [
565 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
566 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400567 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700568 }
569
Mike Klein43c25262016-10-20 10:17:47 -0400570 tool("objc") {
571 depfile = "{{output}}.d"
572 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
573 depsformat = "gcc"
574 outputs = [
575 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
576 ]
577 description = "compile {{source}}"
578 }
579
580 tool("objcxx") {
581 depfile = "{{output}}.d"
582 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
583 depsformat = "gcc"
584 outputs = [
585 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
586 ]
587 description = "compile {{source}}"
588 }
589
mtklein7fbfbbe2016-07-21 12:25:45 -0700590 tool("asm") {
591 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700592 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700593 depsformat = "gcc"
594 outputs = [
595 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
596 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400597 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700598 }
599
600 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500601 rspfile = "{{output}}.rsp"
602 rspfile_content = "{{inputs}}"
603 ar_py = rebase_path("ar.py")
604 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700605 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700606 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700607 ]
608 default_output_extension = ".a"
609 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400610 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700611 }
612
613 tool("solink") {
614 soname = "{{target_output_name}}{{output_extension}}"
615
616 rpath = "-Wl,-soname,$soname"
617 if (is_mac) {
618 rpath = "-Wl,-install_name,@rpath/$soname"
619 }
620
Mike Klein121563e2016-10-04 17:09:13 -0400621 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700622 outputs = [
623 "{{root_out_dir}}/$soname",
624 ]
625 output_prefix = "lib"
626 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400627 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700628 }
629
630 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400631 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700632 outputs = [
633 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
634 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400635 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700636 }
637
638 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400639 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400640 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700641 }
642
643 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400644 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400645 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400646 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700647 }
648}