blob: 3b50286d21c23ac0cff8cee9a89fc675e23dec65 [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",
Mike Kleincc300a12016-10-12 16:25:27 -040085
Mike Kleind3016832016-10-12 15:52:44 -040086 # For builds using win_toolchain asset.
87 "$windk/win_sdk/Include/10.0.10586.0/shared",
88 "$windk/win_sdk/Include/10.0.10586.0/ucrt",
89 "$windk/win_sdk/Include/10.0.10586.0/um",
Mike Klein0f61faa2016-10-11 16:26:57 -040090 ]
Mike Klein3eb71212016-10-11 17:08:53 -040091 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040092 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040093 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
94 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -040095
Mike Kleind3016832016-10-12 15:52:44 -040096 # For builds using win_toolchain asset.
Mike Klein0bc5a762016-10-12 22:42:55 -040097 "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu",
98 "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -040099 ]
Mike Klein0bc5a762016-10-12 22:42:55 -0400100 if (target_cpu == "x86") {
101 lib_dirs += [ "$windk/VC/lib" ]
102 } else {
103 lib_dirs += [ "$windk/VC/lib/amd64" ]
104 }
mtkleinb9be9792016-09-16 14:44:18 -0700105 } else {
106 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700107 "-fstrict-aliasing",
108 "-fPIC",
109 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -0700110 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700111 ]
mtkleinb9be9792016-09-16 14:44:18 -0700112 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700113 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700114 "-fno-threadsafe-statics",
115 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700116 ]
mtkleinb9be9792016-09-16 14:44:18 -0700117 }
herbb6318bf2016-09-16 13:29:57 -0700118
mtkleinb9be9792016-09-16 14:44:18 -0700119 if (current_cpu == "arm") {
120 cflags += [
121 "-march=armv7-a",
122 "-mfpu=neon",
123 "-mthumb",
124 ]
125 } else if (current_cpu == "mipsel") {
126 cflags += [
127 "-march=mips32r2",
128 "-mdspr2",
129 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400130 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700131 asmflags += [ "-m32" ]
132 cflags += [
133 "-m32",
134 "-msse2",
135 "-mfpmath=sse",
136 ]
137 ldflags += [ "-m32" ]
138 }
herbb6318bf2016-09-16 13:29:57 -0700139
Herb Derby76073c12016-12-08 19:00:40 -0500140 if (malloc != "" && !is_win) {
141 cflags += [
142 "-fno-builtin-malloc",
143 "-fno-builtin-calloc",
144 "-fno-builtin-realloc",
145 "-fno-builtin-free",
146 ]
147 libs += [ malloc ]
148 }
149
mtkleinb9be9792016-09-16 14:44:18 -0700150 if (is_android) {
151 asmflags += [
152 "--target=$ndk_target",
153 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
154 ]
155 cflags += [
156 "--sysroot=$ndk/platforms/$ndk_platform",
157 "--target=$ndk_target",
158 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
159 ]
160 cflags_cc += [
161 "-isystem$ndk/sources/android/support/include",
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500162 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/include",
163 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib/include",
mtkleinb9be9792016-09-16 14:44:18 -0700164 ]
165 ldflags += [
166 "--sysroot=$ndk/platforms/$ndk_platform",
167 "--target=$ndk_target",
168 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700169 ]
170 lib_dirs = [
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500171 "$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib",
mtkleinb9be9792016-09-16 14:44:18 -0700172 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
173 ]
herbb6318bf2016-09-16 13:29:57 -0700174
Mike Klein4fdc5432016-10-11 11:21:36 -0400175 if (current_cpu == "mips64el") {
176 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
177 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
178 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
179 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein978cceb2016-12-08 10:29:27 -0500180 ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein4fdc5432016-10-11 11:21:36 -0400181 }
182
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500183 libs += [ "gnustl_static" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700184 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700185
Mike Klein7d302882016-11-03 14:06:31 -0400186 if (is_ios) {
187 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500188 "-isysroot",
189 ios_sysroot,
190 "-arch",
191 target_cpu,
Mike Klein7d302882016-11-03 14:06:31 -0400192 ]
193 cflags_cc += [ "-stdlib=libc++" ]
194 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500195 "-isysroot",
196 ios_sysroot,
197 "-arch",
198 target_cpu,
Mike Klein7d302882016-11-03 14:06:31 -0400199 "-stdlib=libc++",
200 ]
Herb Derby76073c12016-12-08 19:00:40 -0500201 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400202
203 # We used to link all our iOS tools together, so none actually defines main().
204 # Instead they each define their own entry point, which our iOS mega-app called.
205 # If we can we'd like to not do that anymore. While we're building both ways, here's
206 # our clever hack to give each tool back its own main().
207 cflags += [
208 "-Ddm_main=main",
209 "-Dnanobench_main=main",
210 "-Dtool_main=main",
211 "-Dtest_main=main",
212 ]
213 }
214
mtkleinb9be9792016-09-16 14:44:18 -0700215 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500216 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700217 }
218
219 if (sanitize != "") {
220 # You can either pass the sanitizers directly, e.g. "address,undefined",
221 # or pass one of the couple common aliases used by the bots.
222 sanitizers = sanitize
223 if (sanitize == "ASAN") {
224 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"
225 } else if (sanitize == "TSAN") {
226 sanitizers = "thread"
227 } else if (sanitize == "MSAN") {
228 sanitizers = "memory"
229 }
230
231 cflags += [
232 "-fsanitize=$sanitizers",
233 "-fno-sanitize-recover=$sanitizers",
234 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
235 ]
236 ldflags += [ "-fsanitize=$sanitizers" ]
237 if (sanitizers == "memory") {
238 cflags += [ "-fsanitize-memory-track-origins" ]
239 cflags_cc += [ "-stdlib=libc++" ]
240 ldflags += [ "-stdlib=libc++" ]
241 }
242 }
243}
244
Mike Klein6e55fef2016-10-26 11:41:47 -0400245config("no_exceptions") {
246 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
247 if (!is_win) {
248 cflags_cc = [ "-fno-exceptions" ]
249 }
250}
251
Mike Kleinc7165c22016-10-12 23:58:06 -0400252config("warnings") {
253 cflags = []
254 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400255 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400256 if (is_win) {
257 cflags += [
258 "/W3", # Turn on lots of warnings.
259
260 # Disable a bunch of warnings:
261 "/wd4244", # conversion from 'float' to 'int', possible loss of data
262 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
263 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
264
265 # Probably only triggers when /EHsc is enabled.
266 "/wd4291", # no matching operator delete found;
267 # memory will not be freed if initialization throws an exception
268 ]
269 } else {
270 cflags += [
271 "-Wall",
272 "-Wextra",
273 "-Winit-self",
274 "-Wpointer-arith",
275 "-Wsign-compare",
276 "-Wvla",
277
278 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500279 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400280 ]
281 cflags_cc += [ "-Wnon-virtual-dtor" ]
282
283 if (is_clang) {
284 cflags += [
285 "-Weverything",
286 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
287 ]
288
289 if (is_android && target_cpu == "x86") {
290 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
291 # We're pretty sure it's actually 8-byte alignment.
292 cflags += [ "-Wno-over-aligned" ]
293 }
294
295 cflags += [
296 "-Wno-cast-align",
297 "-Wno-conditional-uninitialized",
298 "-Wno-conversion",
299 "-Wno-disabled-macro-expansion",
300 "-Wno-documentation",
301 "-Wno-documentation-unknown-command",
302 "-Wno-double-promotion",
303 "-Wno-exit-time-destructors", # TODO: OK outside libskia
304 "-Wno-float-conversion",
305 "-Wno-float-equal",
306 "-Wno-format-nonliteral",
307 "-Wno-global-constructors", # TODO: OK outside libskia
308 "-Wno-gnu-zero-variadic-macro-arguments",
309 "-Wno-missing-prototypes",
310 "-Wno-missing-variable-declarations",
311 "-Wno-pedantic",
312 "-Wno-reserved-id-macro",
313 "-Wno-shadow",
314 "-Wno-shift-sign-overflow",
315 "-Wno-sign-conversion",
316 "-Wno-switch-enum",
317 "-Wno-undef",
318 "-Wno-unreachable-code",
319 "-Wno-unreachable-code-break",
320 "-Wno-unreachable-code-return",
321 "-Wno-unused-macros",
322 "-Wno-unused-member-function",
323 ]
324 cflags_cc += [
325 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400326 "-Wno-weak-vtables",
327 ]
328
329 # We are unlikely to want to fix these.
330 cflags += [
331 "-Wno-covered-switch-default",
332 "-Wno-deprecated",
333 "-Wno-implicit-fallthrough",
334 "-Wno-missing-noreturn",
335 "-Wno-old-style-cast",
336 "-Wno-padded",
337 ]
338 cflags_cc += [
339 "-Wno-c++98-compat",
340 "-Wno-c++98-compat-pedantic",
341 "-Wno-undefined-func-template",
342 ]
Mike Klein43c25262016-10-20 10:17:47 -0400343 cflags_objc += [
344 "-Wno-direct-ivar-access",
345 "-Wno-objc-interface-ivars",
346 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400347 }
348 }
349}
Mike Klein50500ad2016-11-16 12:13:44 -0500350config("warnings_except_public_headers") {
351 if (!is_win) {
352 cflags = [ "-Wno-unused-parameter" ]
353 }
354}
Mike Kleinc7165c22016-10-12 23:58:06 -0400355
Mike Klein121563e2016-10-04 17:09:13 -0400356config("extra_flags") {
357 cflags = extra_cflags
358 cflags_c = extra_cflags_c
359 cflags_cc = extra_cflags_cc
360 ldflags = extra_ldflags
361}
362
mtkleinb9be9792016-09-16 14:44:18 -0700363config("debug_symbols") {
364 # It's annoying to wait for full debug symbols to push over
365 # to Android devices. -gline-tables-only is a lot slimmer.
366 if (is_android) {
367 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400368 } else if (is_win) {
369 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400370 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400371 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700372 cflags = [ "-g" ]
373 }
374}
375
376config("no_rtti") {
377 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400378 if (is_win) {
379 cflags_cc = [ "/GR-" ]
380 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700381 cflags_cc = [ "-fno-rtti" ]
382 }
383 }
384}
385
386config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400387 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400388 cflags = [
389 "/O2",
390 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400391 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400392 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400393 ldflags = [
394 "/OPT:ICF",
395 "/OPT:REF",
396 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400397 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400398 cflags = [
399 "-O3",
400 "-momit-leaf-frame-pointer",
401 ]
herbb6318bf2016-09-16 13:29:57 -0700402 }
mtkleinb9be9792016-09-16 14:44:18 -0700403 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700404}
405
406config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500407 if (is_android) {
408 ldflags = [ "-pie" ]
409 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700410 ldflags = [ "-Wl,-rpath,@loader_path/." ]
411 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700412 ldflags = [
413 "-rdynamic",
414 "-Wl,-rpath,\$ORIGIN",
415 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500416 } else if (is_win) {
417 ldflags = [
418 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
419 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
420 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700421 }
422}
423
herbb6318bf2016-09-16 13:29:57 -0700424toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400425 lib_dir_switch = "/LIBPATH:"
426
Mike Klein0bc5a762016-10-12 22:42:55 -0400427 bin = "$windk/VC/bin/amd64"
428 env_setup = ""
429 if (target_cpu == "x86") {
430 bin += "_x86"
431 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
432 }
herbb6318bf2016-09-16 13:29:57 -0700433
434 tool("cc") {
435 rspfile = "{{output}}.rsp"
436 precompiled_header_type = "msvc"
437 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
438
Mike Klein0f61faa2016-10-11 16:26:57 -0400439 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400440 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700441 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700442 outputs = [
443 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700444 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400445 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400446 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700447 }
448
449 tool("cxx") {
450 rspfile = "{{output}}.rsp"
451 precompiled_header_type = "msvc"
452 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
453
Mike Klein0f61faa2016-10-11 16:26:57 -0400454 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400455 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700456 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700457 outputs = [
458 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
459 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400460 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400461 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700462 }
herbb6318bf2016-09-16 13:29:57 -0700463
464 tool("alink") {
465 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700466
Mike Kleinc756e862016-10-13 14:31:01 -0400467 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700468 outputs = [
469 # Ignore {{output_extension}} and always use .lib, there's no reason to
470 # allow targets to override this extension on Windows.
471 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
472 ]
473 default_output_extension = ".lib"
474 default_output_dir = "{{target_out_dir}}"
475
Mike Klein0f61faa2016-10-11 16:26:57 -0400476 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700477 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400478 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700479 }
480
Mike Klein1a8d6752016-10-17 11:51:11 -0400481 tool("solink") {
482 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
483 libname = "${dllname}.lib"
484 pdbname = "${dllname}.pdb"
485 rspfile = "${dllname}.rsp"
486
487 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
488 outputs = [
489 dllname,
490 libname,
491 pdbname,
492 ]
493 default_output_extension = ".dll"
494 default_output_dir = "{{root_out_dir}}"
495
496 link_output = libname
497 depend_output = libname
498 runtime_outputs = [
499 dllname,
500 pdbname,
501 ]
502
503 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
504 restat = true
505
506 # inputs_newline works around a fixed per-line buffer size in the linker.
507 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
508 description = "link {{output}}"
509 }
510
herbb6318bf2016-09-16 13:29:57 -0700511 tool("link") {
512 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
513 pdbname = "$exename.pdb"
514 rspfile = "$exename.rsp"
515
Mike Klein0bc5a762016-10-12 22:42:55 -0400516 command =
517 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700518
519 default_output_extension = ".exe"
520 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700521 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700522 exename,
523 ]
mtkleinb9be9792016-09-16 14:44:18 -0700524
Mike Klein0f61faa2016-10-11 16:26:57 -0400525 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700526 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400527 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700528 }
529
herbb6318bf2016-09-16 13:29:57 -0700530 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400531 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400532 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700533 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400534
535 tool("copy") {
536 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400537 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400538 description = "copy {{source}} {{output}}"
539 }
herbb6318bf2016-09-16 13:29:57 -0700540}
541
mtklein7fbfbbe2016-07-21 12:25:45 -0700542toolchain("gcc_like") {
543 lib_switch = "-l"
544 lib_dir_switch = "-L"
545
546 tool("cc") {
547 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400548 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700549 depsformat = "gcc"
550 outputs = [
551 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
552 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400553 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700554 }
555
556 tool("cxx") {
557 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400558 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -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
Mike Klein43c25262016-10-20 10:17:47 -0400566 tool("objc") {
567 depfile = "{{output}}.d"
568 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
569 depsformat = "gcc"
570 outputs = [
571 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
572 ]
573 description = "compile {{source}}"
574 }
575
576 tool("objcxx") {
577 depfile = "{{output}}.d"
578 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{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
mtklein7fbfbbe2016-07-21 12:25:45 -0700586 tool("asm") {
587 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700588 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700589 depsformat = "gcc"
590 outputs = [
591 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
592 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400593 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700594 }
595
596 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500597 rspfile = "{{output}}.rsp"
598 rspfile_content = "{{inputs}}"
599 ar_py = rebase_path("ar.py")
600 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700601 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700602 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700603 ]
604 default_output_extension = ".a"
605 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400606 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700607 }
608
609 tool("solink") {
610 soname = "{{target_output_name}}{{output_extension}}"
611
612 rpath = "-Wl,-soname,$soname"
613 if (is_mac) {
614 rpath = "-Wl,-install_name,@rpath/$soname"
615 }
616
Mike Klein121563e2016-10-04 17:09:13 -0400617 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700618 outputs = [
619 "{{root_out_dir}}/$soname",
620 ]
621 output_prefix = "lib"
622 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400623 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700624 }
625
626 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400627 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700628 outputs = [
629 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
630 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400631 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700632 }
633
634 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400635 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400636 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700637 }
638
639 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400640 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400641 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400642 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700643 }
644}