blob: a39217efb00d75994e7b4197c4eeb31dd29323f3 [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 Klein461d3282016-10-11 13:51:55 -040040if (!is_win) {
41 is_clang = exec_script("is_clang.py",
42 [
43 cc,
44 cxx,
45 ],
46 "value")
47}
mtkleinf347c512016-09-26 08:40:12 -070048
Mike Klein7d302882016-11-03 14:06:31 -040049if (is_ios) {
50 ios_sysroot = exec_script("find_ios_sysroot.py", [], "trim string")
51}
52
mtkleinb9be9792016-09-16 14:44:18 -070053config("default") {
54 asmflags = []
55 cflags = []
56 cflags_c = []
57 cflags_cc = []
58 defines = []
59 ldflags = []
60
61 if (is_win) {
62 cflags += [
63 "/FS", # Preserve previous PDB behavior.
herbb6318bf2016-09-16 13:29:57 -070064 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040065 "/WX", # Treat warnings as errors.
herbb6318bf2016-09-16 13:29:57 -070066 ]
mtkleinb9be9792016-09-16 14:44:18 -070067 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040068 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
69 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070070 "WIN32_LEAN_AND_MEAN",
71 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070072 ]
Mike Klein0f61faa2016-10-11 16:26:57 -040073 include_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040074 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040075
Mike Kleind3016832016-10-12 15:52:44 -040076 # For local builds.
Mike Klein0f61faa2016-10-11 16:26:57 -040077 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040078 "$windk/../Windows Kits/8.1/Include/shared",
Mike Klein3eb71212016-10-11 17:08:53 -040079 "$windk/../Windows Kits/8.1/Include/um",
Mike Kleincc300a12016-10-12 16:25:27 -040080
Mike Kleind3016832016-10-12 15:52:44 -040081 # For builds using win_toolchain asset.
82 "$windk/win_sdk/Include/10.0.10586.0/shared",
83 "$windk/win_sdk/Include/10.0.10586.0/ucrt",
84 "$windk/win_sdk/Include/10.0.10586.0/um",
Mike Klein0f61faa2016-10-11 16:26:57 -040085 ]
Mike Klein3eb71212016-10-11 17:08:53 -040086 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040087 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040088 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
89 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -040090
Mike Kleind3016832016-10-12 15:52:44 -040091 # For builds using win_toolchain asset.
Mike Klein0bc5a762016-10-12 22:42:55 -040092 "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu",
93 "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -040094 ]
Mike Klein0bc5a762016-10-12 22:42:55 -040095 if (target_cpu == "x86") {
96 lib_dirs += [ "$windk/VC/lib" ]
97 } else {
98 lib_dirs += [ "$windk/VC/lib/amd64" ]
99 }
mtkleinb9be9792016-09-16 14:44:18 -0700100 } else {
101 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700102 "-fstrict-aliasing",
103 "-fPIC",
104 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -0700105 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700106 ]
mtkleinb9be9792016-09-16 14:44:18 -0700107 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700108 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700109 "-fno-threadsafe-statics",
110 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700111 ]
mtkleinb9be9792016-09-16 14:44:18 -0700112 }
herbb6318bf2016-09-16 13:29:57 -0700113
mtkleinb9be9792016-09-16 14:44:18 -0700114 if (current_cpu == "arm") {
115 cflags += [
116 "-march=armv7-a",
117 "-mfpu=neon",
118 "-mthumb",
119 ]
120 } else if (current_cpu == "mipsel") {
121 cflags += [
122 "-march=mips32r2",
123 "-mdspr2",
124 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400125 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700126 asmflags += [ "-m32" ]
127 cflags += [
128 "-m32",
129 "-msse2",
130 "-mfpmath=sse",
131 ]
132 ldflags += [ "-m32" ]
133 }
herbb6318bf2016-09-16 13:29:57 -0700134
mtkleinb9be9792016-09-16 14:44:18 -0700135 if (is_android) {
136 asmflags += [
137 "--target=$ndk_target",
138 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
139 ]
140 cflags += [
141 "--sysroot=$ndk/platforms/$ndk_platform",
142 "--target=$ndk_target",
143 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
144 ]
145 cflags_cc += [
146 "-isystem$ndk/sources/android/support/include",
Mike Klein4fdc5432016-10-11 11:21:36 -0400147 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
148 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
mtkleinb9be9792016-09-16 14:44:18 -0700149 ]
150 ldflags += [
151 "--sysroot=$ndk/platforms/$ndk_platform",
152 "--target=$ndk_target",
153 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
154 "-pie",
155 ]
156 lib_dirs = [
157 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
158 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
159 ]
herbb6318bf2016-09-16 13:29:57 -0700160
Mike Klein4fdc5432016-10-11 11:21:36 -0400161 if (current_cpu == "mips64el") {
162 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
163 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
164 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
165 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
166 ldflags += [
167 # Clang will try to link these two files, but not find them. Again, do it manually.
168 "-nostartfiles",
169 "$ndk/platforms/$ndk_platform/usr/lib64/crtbegin_dynamic.o",
170 "$ndk/platforms/$ndk_platform/usr/lib64/crtend_android.o",
171 ]
172 }
173
mtkleinb9be9792016-09-16 14:44:18 -0700174 libs = [
175 # Order matters here! Keep these three in exactly this order.
176 "c++_static",
177 "c++abi",
178 "android_support",
179 ]
180 if (target_cpu == "arm") {
181 libs += [ "unwind" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700182 }
183 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700184
Mike Klein7d302882016-11-03 14:06:31 -0400185 if (is_ios) {
186 cflags += [
187 "--sysroot=$ios_sysroot",
188 "--target=$target_cpu-apple-darwin11",
189 ]
190 cflags_cc += [ "-stdlib=libc++" ]
191 ldflags += [
192 "--sysroot=$ios_sysroot",
193 "--target=$target_cpu-apple-darwin11",
194 "-stdlib=libc++",
195 ]
196 libs = [ "objc" ]
197
198 # We used to link all our iOS tools together, so none actually defines main().
199 # Instead they each define their own entry point, which our iOS mega-app called.
200 # If we can we'd like to not do that anymore. While we're building both ways, here's
201 # our clever hack to give each tool back its own main().
202 cflags += [
203 "-Ddm_main=main",
204 "-Dnanobench_main=main",
205 "-Dtool_main=main",
206 "-Dtest_main=main",
207 ]
208 }
209
mtkleinb9be9792016-09-16 14:44:18 -0700210 if (is_linux) {
211 libs = [ "pthread" ]
212 }
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",
274 "-Wno-unused-parameter",
275 ]
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
284 if (is_android && target_cpu == "x86") {
285 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
286 # We're pretty sure it's actually 8-byte alignment.
287 cflags += [ "-Wno-over-aligned" ]
288 }
289
290 cflags += [
291 "-Wno-cast-align",
292 "-Wno-conditional-uninitialized",
293 "-Wno-conversion",
294 "-Wno-disabled-macro-expansion",
295 "-Wno-documentation",
296 "-Wno-documentation-unknown-command",
297 "-Wno-double-promotion",
298 "-Wno-exit-time-destructors", # TODO: OK outside libskia
299 "-Wno-float-conversion",
300 "-Wno-float-equal",
301 "-Wno-format-nonliteral",
302 "-Wno-global-constructors", # TODO: OK outside libskia
303 "-Wno-gnu-zero-variadic-macro-arguments",
304 "-Wno-missing-prototypes",
305 "-Wno-missing-variable-declarations",
306 "-Wno-pedantic",
307 "-Wno-reserved-id-macro",
308 "-Wno-shadow",
309 "-Wno-shift-sign-overflow",
310 "-Wno-sign-conversion",
311 "-Wno-switch-enum",
312 "-Wno-undef",
313 "-Wno-unreachable-code",
314 "-Wno-unreachable-code-break",
315 "-Wno-unreachable-code-return",
316 "-Wno-unused-macros",
317 "-Wno-unused-member-function",
318 ]
319 cflags_cc += [
320 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400321 "-Wno-weak-vtables",
322 ]
323
324 # We are unlikely to want to fix these.
325 cflags += [
326 "-Wno-covered-switch-default",
327 "-Wno-deprecated",
328 "-Wno-implicit-fallthrough",
329 "-Wno-missing-noreturn",
330 "-Wno-old-style-cast",
331 "-Wno-padded",
332 ]
333 cflags_cc += [
334 "-Wno-c++98-compat",
335 "-Wno-c++98-compat-pedantic",
336 "-Wno-undefined-func-template",
337 ]
Mike Klein43c25262016-10-20 10:17:47 -0400338 cflags_objc += [
339 "-Wno-direct-ivar-access",
340 "-Wno-objc-interface-ivars",
341 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400342 }
343 }
344}
345
Mike Klein121563e2016-10-04 17:09:13 -0400346config("extra_flags") {
347 cflags = extra_cflags
348 cflags_c = extra_cflags_c
349 cflags_cc = extra_cflags_cc
350 ldflags = extra_ldflags
351}
352
mtkleinb9be9792016-09-16 14:44:18 -0700353config("debug_symbols") {
354 # It's annoying to wait for full debug symbols to push over
355 # to Android devices. -gline-tables-only is a lot slimmer.
356 if (is_android) {
357 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400358 } else if (is_win) {
359 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400360 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400361 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700362 cflags = [ "-g" ]
363 }
364}
365
366config("no_rtti") {
367 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400368 if (is_win) {
369 cflags_cc = [ "/GR-" ]
370 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700371 cflags_cc = [ "-fno-rtti" ]
372 }
373 }
374}
375
376config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400377 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400378 cflags = [
379 "/O2",
380 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400381 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400382 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400383 ldflags = [
384 "/OPT:ICF",
385 "/OPT:REF",
386 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400387 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400388 cflags = [
389 "-O3",
390 "-momit-leaf-frame-pointer",
391 ]
herbb6318bf2016-09-16 13:29:57 -0700392 }
mtkleinb9be9792016-09-16 14:44:18 -0700393 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700394}
395
396config("executable") {
397 if (is_mac) {
398 ldflags = [ "-Wl,-rpath,@loader_path/." ]
399 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700400 ldflags = [
401 "-rdynamic",
402 "-Wl,-rpath,\$ORIGIN",
403 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700404 }
405}
406
herbb6318bf2016-09-16 13:29:57 -0700407toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400408 lib_dir_switch = "/LIBPATH:"
409
Mike Klein0bc5a762016-10-12 22:42:55 -0400410 bin = "$windk/VC/bin/amd64"
411 env_setup = ""
412 if (target_cpu == "x86") {
413 bin += "_x86"
414 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
415 }
herbb6318bf2016-09-16 13:29:57 -0700416
417 tool("cc") {
418 rspfile = "{{output}}.rsp"
419 precompiled_header_type = "msvc"
420 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
421
Mike Klein0f61faa2016-10-11 16:26:57 -0400422 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400423 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700424 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700425 outputs = [
426 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700427 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400428 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400429 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700430 }
431
432 tool("cxx") {
433 rspfile = "{{output}}.rsp"
434 precompiled_header_type = "msvc"
435 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
436
Mike Klein0f61faa2016-10-11 16:26:57 -0400437 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400438 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700439 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700440 outputs = [
441 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
442 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400443 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400444 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700445 }
herbb6318bf2016-09-16 13:29:57 -0700446
447 tool("alink") {
448 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700449
Mike Kleinc756e862016-10-13 14:31:01 -0400450 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700451 outputs = [
452 # Ignore {{output_extension}} and always use .lib, there's no reason to
453 # allow targets to override this extension on Windows.
454 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
455 ]
456 default_output_extension = ".lib"
457 default_output_dir = "{{target_out_dir}}"
458
Mike Klein0f61faa2016-10-11 16:26:57 -0400459 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700460 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400461 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700462 }
463
Mike Klein1a8d6752016-10-17 11:51:11 -0400464 tool("solink") {
465 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
466 libname = "${dllname}.lib"
467 pdbname = "${dllname}.pdb"
468 rspfile = "${dllname}.rsp"
469
470 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
471 outputs = [
472 dllname,
473 libname,
474 pdbname,
475 ]
476 default_output_extension = ".dll"
477 default_output_dir = "{{root_out_dir}}"
478
479 link_output = libname
480 depend_output = libname
481 runtime_outputs = [
482 dllname,
483 pdbname,
484 ]
485
486 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
487 restat = true
488
489 # inputs_newline works around a fixed per-line buffer size in the linker.
490 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
491 description = "link {{output}}"
492 }
493
herbb6318bf2016-09-16 13:29:57 -0700494 tool("link") {
495 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
496 pdbname = "$exename.pdb"
497 rspfile = "$exename.rsp"
498
Mike Klein0bc5a762016-10-12 22:42:55 -0400499 command =
500 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700501
502 default_output_extension = ".exe"
503 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700504 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700505 exename,
506 ]
mtkleinb9be9792016-09-16 14:44:18 -0700507
Mike Klein0f61faa2016-10-11 16:26:57 -0400508 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700509 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400510 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700511 }
512
herbb6318bf2016-09-16 13:29:57 -0700513 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400514 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400515 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700516 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400517
518 tool("copy") {
519 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400520 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400521 description = "copy {{source}} {{output}}"
522 }
herbb6318bf2016-09-16 13:29:57 -0700523}
524
mtklein7fbfbbe2016-07-21 12:25:45 -0700525toolchain("gcc_like") {
526 lib_switch = "-l"
527 lib_dir_switch = "-L"
528
529 tool("cc") {
530 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400531 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700532 depsformat = "gcc"
533 outputs = [
534 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
535 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400536 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700537 }
538
539 tool("cxx") {
540 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400541 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700542 depsformat = "gcc"
543 outputs = [
544 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
545 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400546 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700547 }
548
Mike Klein43c25262016-10-20 10:17:47 -0400549 tool("objc") {
550 depfile = "{{output}}.d"
551 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
552 depsformat = "gcc"
553 outputs = [
554 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
555 ]
556 description = "compile {{source}}"
557 }
558
559 tool("objcxx") {
560 depfile = "{{output}}.d"
561 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
562 depsformat = "gcc"
563 outputs = [
564 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
565 ]
566 description = "compile {{source}}"
567 }
568
mtklein7fbfbbe2016-07-21 12:25:45 -0700569 tool("asm") {
570 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700571 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700572 depsformat = "gcc"
573 outputs = [
574 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
575 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400576 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700577 }
578
579 tool("alink") {
Mike Klein82364ba2016-10-24 16:49:15 -0400580 if (host_os == "win") {
581 rspfile = "{{output}}.rsp"
582 rspfile_content = "{{inputs}}"
583 ar_py = rebase_path("ar.py")
584 command = "$python $ar_py $ar {{output}} $rspfile"
585 } else {
586 # We'd use ar.py all the time, but Mac ar doesn't support @rspfile syntax. :(
587 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
588 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700589 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700590 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700591 ]
592 default_output_extension = ".a"
593 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400594 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700595 }
596
597 tool("solink") {
598 soname = "{{target_output_name}}{{output_extension}}"
599
600 rpath = "-Wl,-soname,$soname"
601 if (is_mac) {
602 rpath = "-Wl,-install_name,@rpath/$soname"
603 }
604
Mike Klein121563e2016-10-04 17:09:13 -0400605 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700606 outputs = [
607 "{{root_out_dir}}/$soname",
608 ]
609 output_prefix = "lib"
610 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400611 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700612 }
613
614 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400615 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700616 outputs = [
617 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
618 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400619 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700620 }
621
622 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400623 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400624 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700625 }
626
627 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400628 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400629 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400630 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700631 }
632}