blob: 60dddffd40f26ab0c3da5088d389ca456e9f38ac [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) {
mtklein349cece2016-08-26 08:13:04 -070012 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
mtklein7d6fb2c2016-08-25 14:50:44 -070013 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
14 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
Mike Klein82364ba2016-10-24 16:49:15 -040015 if (host_os == "win") {
16 ar = ar + ".exe"
17 cc = cc + ".exe"
18 cxx = cxx + ".exe"
19 }
mtklein7d6fb2c2016-08-25 14:50:44 -070020 }
21
Mike Klein0f61faa2016-10-11 16:26:57 -040022 windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0"
herbb6318bf2016-09-16 13:29:57 -070023
Mike Klein121563e2016-10-04 17:09:13 -040024 extra_cflags = []
25 extra_cflags_c = []
26 extra_cflags_cc = []
27 extra_ldflags = []
mtkleincab0bb72016-08-26 13:43:19 -070028
mtklein60b7ab72016-09-20 12:09:12 -070029 cc_wrapper = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070030}
31
Mike Klein82364ba2016-10-24 16:49:15 -040032if (host_os == "win") {
33 python = "python.bat"
34 stamp = "cmd.exe /c echo >"
35} else {
36 python = "python"
37 stamp = "touch"
38}
39
Mike Klein87c36f22016-11-13 10:29:25 -050040is_clang = is_android || is_ios || is_mac || (cc == "clang" && cxx == "clang++")
41if (!is_clang && !is_win) {
Mike Klein461d3282016-10-11 13:51:55 -040042 is_clang = exec_script("is_clang.py",
43 [
44 cc,
45 cxx,
46 ],
47 "value")
48}
mtkleinf347c512016-09-26 08:40:12 -070049
Mike Klein7d302882016-11-03 14:06:31 -040050if (is_ios) {
51 ios_sysroot = exec_script("find_ios_sysroot.py", [], "trim string")
52}
53
mtkleinb9be9792016-09-16 14:44:18 -070054config("default") {
55 asmflags = []
56 cflags = []
57 cflags_c = []
58 cflags_cc = []
59 defines = []
60 ldflags = []
61
62 if (is_win) {
63 cflags += [
64 "/FS", # Preserve previous PDB behavior.
herbb6318bf2016-09-16 13:29:57 -070065 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040066 "/WX", # Treat warnings as errors.
herbb6318bf2016-09-16 13:29:57 -070067 ]
mtkleinb9be9792016-09-16 14:44:18 -070068 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040069 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
70 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070071 "WIN32_LEAN_AND_MEAN",
72 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070073 ]
Mike Klein0f61faa2016-10-11 16:26:57 -040074 include_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040075 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040076
Mike Kleind3016832016-10-12 15:52:44 -040077 # For local builds.
Mike Klein0f61faa2016-10-11 16:26:57 -040078 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040079 "$windk/../Windows Kits/8.1/Include/shared",
Mike Klein3eb71212016-10-11 17:08:53 -040080 "$windk/../Windows Kits/8.1/Include/um",
Mike Kleincc300a12016-10-12 16:25:27 -040081
Mike Kleind3016832016-10-12 15:52:44 -040082 # For builds using win_toolchain asset.
83 "$windk/win_sdk/Include/10.0.10586.0/shared",
84 "$windk/win_sdk/Include/10.0.10586.0/ucrt",
85 "$windk/win_sdk/Include/10.0.10586.0/um",
Mike Klein0f61faa2016-10-11 16:26:57 -040086 ]
Mike Klein3eb71212016-10-11 17:08:53 -040087 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040088 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040089 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
90 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -040091
Mike Kleind3016832016-10-12 15:52:44 -040092 # For builds using win_toolchain asset.
Mike Klein0bc5a762016-10-12 22:42:55 -040093 "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu",
94 "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -040095 ]
Mike Klein0bc5a762016-10-12 22:42:55 -040096 if (target_cpu == "x86") {
97 lib_dirs += [ "$windk/VC/lib" ]
98 } else {
99 lib_dirs += [ "$windk/VC/lib/amd64" ]
100 }
mtkleinb9be9792016-09-16 14:44:18 -0700101 } else {
102 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700103 "-fstrict-aliasing",
104 "-fPIC",
105 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -0700106 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700107 ]
mtkleinb9be9792016-09-16 14:44:18 -0700108 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700109 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700110 "-fno-threadsafe-statics",
111 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700112 ]
mtkleinb9be9792016-09-16 14:44:18 -0700113 }
herbb6318bf2016-09-16 13:29:57 -0700114
mtkleinb9be9792016-09-16 14:44:18 -0700115 if (current_cpu == "arm") {
116 cflags += [
117 "-march=armv7-a",
118 "-mfpu=neon",
119 "-mthumb",
120 ]
121 } else if (current_cpu == "mipsel") {
122 cflags += [
123 "-march=mips32r2",
124 "-mdspr2",
125 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400126 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700127 asmflags += [ "-m32" ]
128 cflags += [
129 "-m32",
130 "-msse2",
131 "-mfpmath=sse",
132 ]
133 ldflags += [ "-m32" ]
134 }
herbb6318bf2016-09-16 13:29:57 -0700135
mtkleinb9be9792016-09-16 14:44:18 -0700136 if (is_android) {
137 asmflags += [
138 "--target=$ndk_target",
139 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
140 ]
141 cflags += [
142 "--sysroot=$ndk/platforms/$ndk_platform",
143 "--target=$ndk_target",
144 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
145 ]
146 cflags_cc += [
147 "-isystem$ndk/sources/android/support/include",
Mike Klein4fdc5432016-10-11 11:21:36 -0400148 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
149 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
mtkleinb9be9792016-09-16 14:44:18 -0700150 ]
151 ldflags += [
152 "--sysroot=$ndk/platforms/$ndk_platform",
153 "--target=$ndk_target",
154 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
155 "-pie",
156 ]
157 lib_dirs = [
158 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
159 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
160 ]
herbb6318bf2016-09-16 13:29:57 -0700161
Mike Klein4fdc5432016-10-11 11:21:36 -0400162 if (current_cpu == "mips64el") {
163 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
164 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
165 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
166 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
167 ldflags += [
168 # Clang will try to link these two files, but not find them. Again, do it manually.
169 "-nostartfiles",
170 "$ndk/platforms/$ndk_platform/usr/lib64/crtbegin_dynamic.o",
171 "$ndk/platforms/$ndk_platform/usr/lib64/crtend_android.o",
172 ]
173 }
174
mtkleinb9be9792016-09-16 14:44:18 -0700175 libs = [
176 # Order matters here! Keep these three in exactly this order.
177 "c++_static",
178 "c++abi",
179 "android_support",
180 ]
181 if (target_cpu == "arm") {
182 libs += [ "unwind" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700183 }
184 }
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 ]
201 libs = [ "objc" ]
202
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) {
216 libs = [ "pthread" ]
217 }
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 Kleinc7165c22016-10-12 23:58:06 -0400279 ]
280 cflags_cc += [ "-Wnon-virtual-dtor" ]
281
282 if (is_clang) {
283 cflags += [
284 "-Weverything",
285 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
286 ]
287
288 if (is_android && target_cpu == "x86") {
289 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
290 # We're pretty sure it's actually 8-byte alignment.
291 cflags += [ "-Wno-over-aligned" ]
292 }
293
294 cflags += [
295 "-Wno-cast-align",
296 "-Wno-conditional-uninitialized",
297 "-Wno-conversion",
298 "-Wno-disabled-macro-expansion",
299 "-Wno-documentation",
300 "-Wno-documentation-unknown-command",
301 "-Wno-double-promotion",
302 "-Wno-exit-time-destructors", # TODO: OK outside libskia
303 "-Wno-float-conversion",
304 "-Wno-float-equal",
305 "-Wno-format-nonliteral",
306 "-Wno-global-constructors", # TODO: OK outside libskia
307 "-Wno-gnu-zero-variadic-macro-arguments",
308 "-Wno-missing-prototypes",
309 "-Wno-missing-variable-declarations",
310 "-Wno-pedantic",
311 "-Wno-reserved-id-macro",
312 "-Wno-shadow",
313 "-Wno-shift-sign-overflow",
314 "-Wno-sign-conversion",
315 "-Wno-switch-enum",
316 "-Wno-undef",
317 "-Wno-unreachable-code",
318 "-Wno-unreachable-code-break",
319 "-Wno-unreachable-code-return",
320 "-Wno-unused-macros",
321 "-Wno-unused-member-function",
322 ]
323 cflags_cc += [
324 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400325 "-Wno-weak-vtables",
326 ]
327
328 # We are unlikely to want to fix these.
329 cflags += [
330 "-Wno-covered-switch-default",
331 "-Wno-deprecated",
332 "-Wno-implicit-fallthrough",
333 "-Wno-missing-noreturn",
334 "-Wno-old-style-cast",
335 "-Wno-padded",
336 ]
337 cflags_cc += [
338 "-Wno-c++98-compat",
339 "-Wno-c++98-compat-pedantic",
340 "-Wno-undefined-func-template",
341 ]
Mike Klein43c25262016-10-20 10:17:47 -0400342 cflags_objc += [
343 "-Wno-direct-ivar-access",
344 "-Wno-objc-interface-ivars",
345 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400346 }
347 }
348}
Mike Klein50500ad2016-11-16 12:13:44 -0500349config("warnings_except_public_headers") {
350 if (!is_win) {
351 cflags = [ "-Wno-unused-parameter" ]
352 }
353}
Mike Kleinc7165c22016-10-12 23:58:06 -0400354
Mike Klein121563e2016-10-04 17:09:13 -0400355config("extra_flags") {
356 cflags = extra_cflags
357 cflags_c = extra_cflags_c
358 cflags_cc = extra_cflags_cc
359 ldflags = extra_ldflags
360}
361
mtkleinb9be9792016-09-16 14:44:18 -0700362config("debug_symbols") {
363 # It's annoying to wait for full debug symbols to push over
364 # to Android devices. -gline-tables-only is a lot slimmer.
365 if (is_android) {
366 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400367 } else if (is_win) {
368 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400369 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400370 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700371 cflags = [ "-g" ]
372 }
373}
374
375config("no_rtti") {
376 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400377 if (is_win) {
378 cflags_cc = [ "/GR-" ]
379 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700380 cflags_cc = [ "-fno-rtti" ]
381 }
382 }
383}
384
385config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400386 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400387 cflags = [
388 "/O2",
389 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400390 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400391 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400392 ldflags = [
393 "/OPT:ICF",
394 "/OPT:REF",
395 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400396 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400397 cflags = [
398 "-O3",
399 "-momit-leaf-frame-pointer",
400 ]
herbb6318bf2016-09-16 13:29:57 -0700401 }
mtkleinb9be9792016-09-16 14:44:18 -0700402 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700403}
404
405config("executable") {
406 if (is_mac) {
407 ldflags = [ "-Wl,-rpath,@loader_path/." ]
408 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700409 ldflags = [
410 "-rdynamic",
411 "-Wl,-rpath,\$ORIGIN",
412 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500413 } else if (is_win) {
414 ldflags = [
415 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
416 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
417 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700418 }
419}
420
herbb6318bf2016-09-16 13:29:57 -0700421toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400422 lib_dir_switch = "/LIBPATH:"
423
Mike Klein0bc5a762016-10-12 22:42:55 -0400424 bin = "$windk/VC/bin/amd64"
425 env_setup = ""
426 if (target_cpu == "x86") {
427 bin += "_x86"
428 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
429 }
herbb6318bf2016-09-16 13:29:57 -0700430
431 tool("cc") {
432 rspfile = "{{output}}.rsp"
433 precompiled_header_type = "msvc"
434 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
435
Mike Klein0f61faa2016-10-11 16:26:57 -0400436 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400437 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700438 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700439 outputs = [
440 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700441 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400442 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400443 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700444 }
445
446 tool("cxx") {
447 rspfile = "{{output}}.rsp"
448 precompiled_header_type = "msvc"
449 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
450
Mike Klein0f61faa2016-10-11 16:26:57 -0400451 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400452 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700453 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700454 outputs = [
455 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
456 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400457 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400458 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700459 }
herbb6318bf2016-09-16 13:29:57 -0700460
461 tool("alink") {
462 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700463
Mike Kleinc756e862016-10-13 14:31:01 -0400464 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700465 outputs = [
466 # Ignore {{output_extension}} and always use .lib, there's no reason to
467 # allow targets to override this extension on Windows.
468 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
469 ]
470 default_output_extension = ".lib"
471 default_output_dir = "{{target_out_dir}}"
472
Mike Klein0f61faa2016-10-11 16:26:57 -0400473 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700474 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400475 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700476 }
477
Mike Klein1a8d6752016-10-17 11:51:11 -0400478 tool("solink") {
479 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
480 libname = "${dllname}.lib"
481 pdbname = "${dllname}.pdb"
482 rspfile = "${dllname}.rsp"
483
484 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
485 outputs = [
486 dllname,
487 libname,
488 pdbname,
489 ]
490 default_output_extension = ".dll"
491 default_output_dir = "{{root_out_dir}}"
492
493 link_output = libname
494 depend_output = libname
495 runtime_outputs = [
496 dllname,
497 pdbname,
498 ]
499
500 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
501 restat = true
502
503 # inputs_newline works around a fixed per-line buffer size in the linker.
504 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
505 description = "link {{output}}"
506 }
507
herbb6318bf2016-09-16 13:29:57 -0700508 tool("link") {
509 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
510 pdbname = "$exename.pdb"
511 rspfile = "$exename.rsp"
512
Mike Klein0bc5a762016-10-12 22:42:55 -0400513 command =
514 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700515
516 default_output_extension = ".exe"
517 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700518 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700519 exename,
520 ]
mtkleinb9be9792016-09-16 14:44:18 -0700521
Mike Klein0f61faa2016-10-11 16:26:57 -0400522 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700523 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400524 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700525 }
526
herbb6318bf2016-09-16 13:29:57 -0700527 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400528 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400529 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700530 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400531
532 tool("copy") {
533 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400534 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400535 description = "copy {{source}} {{output}}"
536 }
herbb6318bf2016-09-16 13:29:57 -0700537}
538
mtklein7fbfbbe2016-07-21 12:25:45 -0700539toolchain("gcc_like") {
540 lib_switch = "-l"
541 lib_dir_switch = "-L"
542
543 tool("cc") {
544 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400545 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700546 depsformat = "gcc"
547 outputs = [
548 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
549 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400550 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700551 }
552
553 tool("cxx") {
554 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400555 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -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
Mike Klein43c25262016-10-20 10:17:47 -0400563 tool("objc") {
564 depfile = "{{output}}.d"
565 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
566 depsformat = "gcc"
567 outputs = [
568 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
569 ]
570 description = "compile {{source}}"
571 }
572
573 tool("objcxx") {
574 depfile = "{{output}}.d"
575 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{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
mtklein7fbfbbe2016-07-21 12:25:45 -0700583 tool("asm") {
584 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700585 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700586 depsformat = "gcc"
587 outputs = [
588 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
589 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400590 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700591 }
592
593 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500594 rspfile = "{{output}}.rsp"
595 rspfile_content = "{{inputs}}"
596 ar_py = rebase_path("ar.py")
597 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700598 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700599 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700600 ]
601 default_output_extension = ".a"
602 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400603 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700604 }
605
606 tool("solink") {
607 soname = "{{target_output_name}}{{output_extension}}"
608
609 rpath = "-Wl,-soname,$soname"
610 if (is_mac) {
611 rpath = "-Wl,-install_name,@rpath/$soname"
612 }
613
Mike Klein121563e2016-10-04 17:09:13 -0400614 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700615 outputs = [
616 "{{root_out_dir}}/$soname",
617 ]
618 output_prefix = "lib"
619 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400620 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700621 }
622
623 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400624 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700625 outputs = [
626 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
627 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400628 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700629 }
630
631 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400632 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400633 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700634 }
635
636 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400637 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400638 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400639 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700640 }
641}