blob: a52690da1714869dbe2dc75df5e7915568adcaef [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.
herbb6318bf2016-09-16 13:29:57 -070070 ]
mtkleinb9be9792016-09-16 14:44:18 -070071 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040072 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
73 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070074 "WIN32_LEAN_AND_MEAN",
75 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070076 ]
Mike Klein0f61faa2016-10-11 16:26:57 -040077 include_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040078 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040079
Mike Kleind3016832016-10-12 15:52:44 -040080 # For local builds.
Mike Klein0f61faa2016-10-11 16:26:57 -040081 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040082 "$windk/../Windows Kits/8.1/Include/shared",
Mike Klein3eb71212016-10-11 17:08:53 -040083 "$windk/../Windows Kits/8.1/Include/um",
Mike Kleincc300a12016-10-12 16:25:27 -040084
Mike Kleind3016832016-10-12 15:52:44 -040085 # For builds using win_toolchain asset.
86 "$windk/win_sdk/Include/10.0.10586.0/shared",
87 "$windk/win_sdk/Include/10.0.10586.0/ucrt",
88 "$windk/win_sdk/Include/10.0.10586.0/um",
Mike Klein0f61faa2016-10-11 16:26:57 -040089 ]
Mike Klein3eb71212016-10-11 17:08:53 -040090 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040091 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040092 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
93 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -040094
Mike Kleind3016832016-10-12 15:52:44 -040095 # For builds using win_toolchain asset.
Mike Klein0bc5a762016-10-12 22:42:55 -040096 "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu",
97 "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -040098 ]
Mike Klein0bc5a762016-10-12 22:42:55 -040099 if (target_cpu == "x86") {
100 lib_dirs += [ "$windk/VC/lib" ]
101 } else {
102 lib_dirs += [ "$windk/VC/lib/amd64" ]
103 }
mtkleinb9be9792016-09-16 14:44:18 -0700104 } else {
105 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700106 "-fstrict-aliasing",
107 "-fPIC",
108 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -0700109 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700110 ]
mtkleinb9be9792016-09-16 14:44:18 -0700111 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700112 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700113 "-fno-threadsafe-statics",
114 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700115 ]
mtkleinb9be9792016-09-16 14:44:18 -0700116 }
herbb6318bf2016-09-16 13:29:57 -0700117
mtkleinb9be9792016-09-16 14:44:18 -0700118 if (current_cpu == "arm") {
119 cflags += [
120 "-march=armv7-a",
121 "-mfpu=neon",
122 "-mthumb",
123 ]
124 } else if (current_cpu == "mipsel") {
125 cflags += [
126 "-march=mips32r2",
127 "-mdspr2",
128 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400129 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700130 asmflags += [ "-m32" ]
131 cflags += [
132 "-m32",
133 "-msse2",
134 "-mfpmath=sse",
135 ]
136 ldflags += [ "-m32" ]
137 }
herbb6318bf2016-09-16 13:29:57 -0700138
Herb Derby76073c12016-12-08 19:00:40 -0500139 if (malloc != "" && !is_win) {
140 cflags += [
141 "-fno-builtin-malloc",
142 "-fno-builtin-calloc",
143 "-fno-builtin-realloc",
144 "-fno-builtin-free",
145 ]
146 libs += [ malloc ]
147 }
148
mtkleinb9be9792016-09-16 14:44:18 -0700149 if (is_android) {
150 asmflags += [
151 "--target=$ndk_target",
152 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
153 ]
154 cflags += [
155 "--sysroot=$ndk/platforms/$ndk_platform",
156 "--target=$ndk_target",
157 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
158 ]
159 cflags_cc += [
160 "-isystem$ndk/sources/android/support/include",
Mike Klein4fdc5432016-10-11 11:21:36 -0400161 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
162 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
mtkleinb9be9792016-09-16 14:44:18 -0700163 ]
164 ldflags += [
165 "--sysroot=$ndk/platforms/$ndk_platform",
166 "--target=$ndk_target",
167 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700168 ]
169 lib_dirs = [
170 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
171 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
172 ]
herbb6318bf2016-09-16 13:29:57 -0700173
Mike Klein4fdc5432016-10-11 11:21:36 -0400174 if (current_cpu == "mips64el") {
175 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
176 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
177 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
178 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein978cceb2016-12-08 10:29:27 -0500179 ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein4fdc5432016-10-11 11:21:36 -0400180 }
181
Herb Derby76073c12016-12-08 19:00:40 -0500182 libs += [
mtkleinb9be9792016-09-16 14:44:18 -0700183 # Order matters here! Keep these three in exactly this order.
184 "c++_static",
185 "c++abi",
186 "android_support",
187 ]
188 if (target_cpu == "arm") {
189 libs += [ "unwind" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700190 }
191 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700192
Mike Klein7d302882016-11-03 14:06:31 -0400193 if (is_ios) {
194 cflags += [
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 ]
200 cflags_cc += [ "-stdlib=libc++" ]
201 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500202 "-isysroot",
203 ios_sysroot,
204 "-arch",
205 target_cpu,
Mike Klein7d302882016-11-03 14:06:31 -0400206 "-stdlib=libc++",
207 ]
Herb Derby76073c12016-12-08 19:00:40 -0500208 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400209
210 # We used to link all our iOS tools together, so none actually defines main().
211 # Instead they each define their own entry point, which our iOS mega-app called.
212 # If we can we'd like to not do that anymore. While we're building both ways, here's
213 # our clever hack to give each tool back its own main().
214 cflags += [
215 "-Ddm_main=main",
216 "-Dnanobench_main=main",
217 "-Dtool_main=main",
218 "-Dtest_main=main",
219 ]
220 }
221
mtkleinb9be9792016-09-16 14:44:18 -0700222 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500223 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700224 }
225
226 if (sanitize != "") {
227 # You can either pass the sanitizers directly, e.g. "address,undefined",
228 # or pass one of the couple common aliases used by the bots.
229 sanitizers = sanitize
230 if (sanitize == "ASAN") {
231 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"
232 } else if (sanitize == "TSAN") {
233 sanitizers = "thread"
234 } else if (sanitize == "MSAN") {
235 sanitizers = "memory"
236 }
237
238 cflags += [
239 "-fsanitize=$sanitizers",
240 "-fno-sanitize-recover=$sanitizers",
241 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
242 ]
243 ldflags += [ "-fsanitize=$sanitizers" ]
244 if (sanitizers == "memory") {
245 cflags += [ "-fsanitize-memory-track-origins" ]
246 cflags_cc += [ "-stdlib=libc++" ]
247 ldflags += [ "-stdlib=libc++" ]
248 }
249 }
250}
251
Mike Klein6e55fef2016-10-26 11:41:47 -0400252config("no_exceptions") {
253 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
254 if (!is_win) {
255 cflags_cc = [ "-fno-exceptions" ]
256 }
257}
258
Mike Kleinc7165c22016-10-12 23:58:06 -0400259config("warnings") {
260 cflags = []
261 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400262 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400263 if (is_win) {
264 cflags += [
265 "/W3", # Turn on lots of warnings.
266
267 # Disable a bunch of warnings:
268 "/wd4244", # conversion from 'float' to 'int', possible loss of data
269 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
270 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
271
272 # Probably only triggers when /EHsc is enabled.
273 "/wd4291", # no matching operator delete found;
274 # memory will not be freed if initialization throws an exception
275 ]
276 } else {
277 cflags += [
278 "-Wall",
279 "-Wextra",
280 "-Winit-self",
281 "-Wpointer-arith",
282 "-Wsign-compare",
283 "-Wvla",
284
285 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500286 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400287 ]
288 cflags_cc += [ "-Wnon-virtual-dtor" ]
289
290 if (is_clang) {
291 cflags += [
292 "-Weverything",
293 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
294 ]
295
296 if (is_android && target_cpu == "x86") {
297 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
298 # 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",
323 "-Wno-switch-enum",
324 "-Wno-undef",
325 "-Wno-unreachable-code",
326 "-Wno-unreachable-code-break",
327 "-Wno-unreachable-code-return",
328 "-Wno-unused-macros",
329 "-Wno-unused-member-function",
330 ]
331 cflags_cc += [
332 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400333 "-Wno-weak-vtables",
334 ]
335
336 # We are unlikely to want to fix these.
337 cflags += [
338 "-Wno-covered-switch-default",
339 "-Wno-deprecated",
340 "-Wno-implicit-fallthrough",
341 "-Wno-missing-noreturn",
342 "-Wno-old-style-cast",
343 "-Wno-padded",
344 ]
345 cflags_cc += [
346 "-Wno-c++98-compat",
347 "-Wno-c++98-compat-pedantic",
348 "-Wno-undefined-func-template",
349 ]
Mike Klein43c25262016-10-20 10:17:47 -0400350 cflags_objc += [
351 "-Wno-direct-ivar-access",
352 "-Wno-objc-interface-ivars",
353 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400354 }
355 }
356}
Mike Klein50500ad2016-11-16 12:13:44 -0500357config("warnings_except_public_headers") {
358 if (!is_win) {
359 cflags = [ "-Wno-unused-parameter" ]
360 }
361}
Mike Kleinc7165c22016-10-12 23:58:06 -0400362
Mike Klein121563e2016-10-04 17:09:13 -0400363config("extra_flags") {
364 cflags = extra_cflags
365 cflags_c = extra_cflags_c
366 cflags_cc = extra_cflags_cc
367 ldflags = extra_ldflags
368}
369
mtkleinb9be9792016-09-16 14:44:18 -0700370config("debug_symbols") {
371 # It's annoying to wait for full debug symbols to push over
372 # to Android devices. -gline-tables-only is a lot slimmer.
373 if (is_android) {
374 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400375 } else if (is_win) {
376 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400377 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400378 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700379 cflags = [ "-g" ]
380 }
381}
382
383config("no_rtti") {
384 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400385 if (is_win) {
386 cflags_cc = [ "/GR-" ]
387 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700388 cflags_cc = [ "-fno-rtti" ]
389 }
390 }
391}
392
393config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400394 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400395 cflags = [
396 "/O2",
397 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400398 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400399 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400400 ldflags = [
401 "/OPT:ICF",
402 "/OPT:REF",
403 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400404 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400405 cflags = [
406 "-O3",
407 "-momit-leaf-frame-pointer",
408 ]
herbb6318bf2016-09-16 13:29:57 -0700409 }
mtkleinb9be9792016-09-16 14:44:18 -0700410 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700411}
412
413config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500414 if (is_android) {
415 ldflags = [ "-pie" ]
416 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700417 ldflags = [ "-Wl,-rpath,@loader_path/." ]
418 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700419 ldflags = [
420 "-rdynamic",
421 "-Wl,-rpath,\$ORIGIN",
422 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500423 } else if (is_win) {
424 ldflags = [
425 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
426 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
427 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700428 }
429}
430
herbb6318bf2016-09-16 13:29:57 -0700431toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400432 lib_dir_switch = "/LIBPATH:"
433
Mike Klein0bc5a762016-10-12 22:42:55 -0400434 bin = "$windk/VC/bin/amd64"
435 env_setup = ""
436 if (target_cpu == "x86") {
437 bin += "_x86"
438 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
439 }
herbb6318bf2016-09-16 13:29:57 -0700440
441 tool("cc") {
442 rspfile = "{{output}}.rsp"
443 precompiled_header_type = "msvc"
444 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
445
Mike Klein0f61faa2016-10-11 16:26:57 -0400446 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400447 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700448 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700449 outputs = [
450 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700451 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400452 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400453 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700454 }
455
456 tool("cxx") {
457 rspfile = "{{output}}.rsp"
458 precompiled_header_type = "msvc"
459 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
460
Mike Klein0f61faa2016-10-11 16:26:57 -0400461 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400462 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700463 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700464 outputs = [
465 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
466 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400467 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400468 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700469 }
herbb6318bf2016-09-16 13:29:57 -0700470
471 tool("alink") {
472 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700473
Mike Kleinc756e862016-10-13 14:31:01 -0400474 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700475 outputs = [
476 # Ignore {{output_extension}} and always use .lib, there's no reason to
477 # allow targets to override this extension on Windows.
478 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
479 ]
480 default_output_extension = ".lib"
481 default_output_dir = "{{target_out_dir}}"
482
Mike Klein0f61faa2016-10-11 16:26:57 -0400483 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700484 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400485 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700486 }
487
Mike Klein1a8d6752016-10-17 11:51:11 -0400488 tool("solink") {
489 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
490 libname = "${dllname}.lib"
491 pdbname = "${dllname}.pdb"
492 rspfile = "${dllname}.rsp"
493
494 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
495 outputs = [
496 dllname,
497 libname,
498 pdbname,
499 ]
500 default_output_extension = ".dll"
501 default_output_dir = "{{root_out_dir}}"
502
503 link_output = libname
504 depend_output = libname
505 runtime_outputs = [
506 dllname,
507 pdbname,
508 ]
509
510 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
511 restat = true
512
513 # inputs_newline works around a fixed per-line buffer size in the linker.
514 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
515 description = "link {{output}}"
516 }
517
herbb6318bf2016-09-16 13:29:57 -0700518 tool("link") {
519 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
520 pdbname = "$exename.pdb"
521 rspfile = "$exename.rsp"
522
Mike Klein0bc5a762016-10-12 22:42:55 -0400523 command =
524 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700525
526 default_output_extension = ".exe"
527 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700528 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700529 exename,
530 ]
mtkleinb9be9792016-09-16 14:44:18 -0700531
Mike Klein0f61faa2016-10-11 16:26:57 -0400532 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700533 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400534 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700535 }
536
herbb6318bf2016-09-16 13:29:57 -0700537 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400538 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400539 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700540 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400541
542 tool("copy") {
543 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400544 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400545 description = "copy {{source}} {{output}}"
546 }
herbb6318bf2016-09-16 13:29:57 -0700547}
548
mtklein7fbfbbe2016-07-21 12:25:45 -0700549toolchain("gcc_like") {
550 lib_switch = "-l"
551 lib_dir_switch = "-L"
552
553 tool("cc") {
554 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400555 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700556 depsformat = "gcc"
557 outputs = [
558 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
559 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400560 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700561 }
562
563 tool("cxx") {
564 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400565 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700566 depsformat = "gcc"
567 outputs = [
568 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
569 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400570 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700571 }
572
Mike Klein43c25262016-10-20 10:17:47 -0400573 tool("objc") {
574 depfile = "{{output}}.d"
575 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
576 depsformat = "gcc"
577 outputs = [
578 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
579 ]
580 description = "compile {{source}}"
581 }
582
583 tool("objcxx") {
584 depfile = "{{output}}.d"
585 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
586 depsformat = "gcc"
587 outputs = [
588 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
589 ]
590 description = "compile {{source}}"
591 }
592
mtklein7fbfbbe2016-07-21 12:25:45 -0700593 tool("asm") {
594 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700595 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700596 depsformat = "gcc"
597 outputs = [
598 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
599 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400600 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700601 }
602
603 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500604 rspfile = "{{output}}.rsp"
605 rspfile_content = "{{inputs}}"
606 ar_py = rebase_path("ar.py")
607 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700608 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700609 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700610 ]
611 default_output_extension = ".a"
612 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400613 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700614 }
615
616 tool("solink") {
617 soname = "{{target_output_name}}{{output_extension}}"
618
619 rpath = "-Wl,-soname,$soname"
620 if (is_mac) {
621 rpath = "-Wl,-install_name,@rpath/$soname"
622 }
623
Mike Klein121563e2016-10-04 17:09:13 -0400624 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700625 outputs = [
626 "{{root_out_dir}}/$soname",
627 ]
628 output_prefix = "lib"
629 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400630 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700631 }
632
633 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400634 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700635 outputs = [
636 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
637 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400638 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700639 }
640
641 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400642 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400643 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700644 }
645
646 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400647 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400648 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400649 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700650 }
651}