blob: bebe3c589b5364f73bd2b9c20eb63933c171287f [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
mtkleinb9be9792016-09-16 14:44:18 -070049config("default") {
50 asmflags = []
51 cflags = []
52 cflags_c = []
53 cflags_cc = []
54 defines = []
55 ldflags = []
56
57 if (is_win) {
58 cflags += [
59 "/FS", # Preserve previous PDB behavior.
herbb6318bf2016-09-16 13:29:57 -070060 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040061 "/WX", # Treat warnings as errors.
herbb6318bf2016-09-16 13:29:57 -070062 ]
mtkleinb9be9792016-09-16 14:44:18 -070063 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040064 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
65 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070066 "WIN32_LEAN_AND_MEAN",
67 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070068 ]
Mike Klein0f61faa2016-10-11 16:26:57 -040069 include_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040070 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040071
Mike Kleind3016832016-10-12 15:52:44 -040072 # For local builds.
Mike Klein0f61faa2016-10-11 16:26:57 -040073 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040074 "$windk/../Windows Kits/8.1/Include/shared",
Mike Klein3eb71212016-10-11 17:08:53 -040075 "$windk/../Windows Kits/8.1/Include/um",
Mike Kleincc300a12016-10-12 16:25:27 -040076
Mike Kleind3016832016-10-12 15:52:44 -040077 # For builds using win_toolchain asset.
78 "$windk/win_sdk/Include/10.0.10586.0/shared",
79 "$windk/win_sdk/Include/10.0.10586.0/ucrt",
80 "$windk/win_sdk/Include/10.0.10586.0/um",
Mike Klein0f61faa2016-10-11 16:26:57 -040081 ]
Mike Klein3eb71212016-10-11 17:08:53 -040082 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040083 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040084 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
85 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -040086
Mike Kleind3016832016-10-12 15:52:44 -040087 # For builds using win_toolchain asset.
Mike Klein0bc5a762016-10-12 22:42:55 -040088 "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu",
89 "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -040090 ]
Mike Klein0bc5a762016-10-12 22:42:55 -040091 if (target_cpu == "x86") {
92 lib_dirs += [ "$windk/VC/lib" ]
93 } else {
94 lib_dirs += [ "$windk/VC/lib/amd64" ]
95 }
mtkleinb9be9792016-09-16 14:44:18 -070096 } else {
97 cflags += [
herbb6318bf2016-09-16 13:29:57 -070098 "-O1",
99 "-fstrict-aliasing",
100 "-fPIC",
101 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -0700102 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700103 ]
mtkleinb9be9792016-09-16 14:44:18 -0700104 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700105 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700106 "-fno-threadsafe-statics",
107 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700108 ]
mtkleinb9be9792016-09-16 14:44:18 -0700109 }
herbb6318bf2016-09-16 13:29:57 -0700110
mtkleinb9be9792016-09-16 14:44:18 -0700111 if (current_cpu == "arm") {
112 cflags += [
113 "-march=armv7-a",
114 "-mfpu=neon",
115 "-mthumb",
116 ]
117 } else if (current_cpu == "mipsel") {
118 cflags += [
119 "-march=mips32r2",
120 "-mdspr2",
121 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400122 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700123 asmflags += [ "-m32" ]
124 cflags += [
125 "-m32",
126 "-msse2",
127 "-mfpmath=sse",
128 ]
129 ldflags += [ "-m32" ]
130 }
herbb6318bf2016-09-16 13:29:57 -0700131
mtkleinb9be9792016-09-16 14:44:18 -0700132 if (is_android) {
133 asmflags += [
134 "--target=$ndk_target",
135 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
136 ]
137 cflags += [
138 "--sysroot=$ndk/platforms/$ndk_platform",
139 "--target=$ndk_target",
140 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
141 ]
142 cflags_cc += [
143 "-isystem$ndk/sources/android/support/include",
Mike Klein4fdc5432016-10-11 11:21:36 -0400144 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
145 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
mtkleinb9be9792016-09-16 14:44:18 -0700146 ]
147 ldflags += [
148 "--sysroot=$ndk/platforms/$ndk_platform",
149 "--target=$ndk_target",
150 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
151 "-pie",
152 ]
153 lib_dirs = [
154 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
155 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
156 ]
herbb6318bf2016-09-16 13:29:57 -0700157
Mike Klein4fdc5432016-10-11 11:21:36 -0400158 if (current_cpu == "mips64el") {
159 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
160 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
161 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
162 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
163 ldflags += [
164 # Clang will try to link these two files, but not find them. Again, do it manually.
165 "-nostartfiles",
166 "$ndk/platforms/$ndk_platform/usr/lib64/crtbegin_dynamic.o",
167 "$ndk/platforms/$ndk_platform/usr/lib64/crtend_android.o",
168 ]
169 }
170
mtkleinb9be9792016-09-16 14:44:18 -0700171 libs = [
172 # Order matters here! Keep these three in exactly this order.
173 "c++_static",
174 "c++abi",
175 "android_support",
176 ]
177 if (target_cpu == "arm") {
178 libs += [ "unwind" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700179 }
180 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700181
mtkleinb9be9792016-09-16 14:44:18 -0700182 if (is_linux) {
183 libs = [ "pthread" ]
184 }
185
186 if (sanitize != "") {
187 # You can either pass the sanitizers directly, e.g. "address,undefined",
188 # or pass one of the couple common aliases used by the bots.
189 sanitizers = sanitize
190 if (sanitize == "ASAN") {
191 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"
192 } else if (sanitize == "TSAN") {
193 sanitizers = "thread"
194 } else if (sanitize == "MSAN") {
195 sanitizers = "memory"
196 }
197
198 cflags += [
199 "-fsanitize=$sanitizers",
200 "-fno-sanitize-recover=$sanitizers",
201 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
202 ]
203 ldflags += [ "-fsanitize=$sanitizers" ]
204 if (sanitizers == "memory") {
205 cflags += [ "-fsanitize-memory-track-origins" ]
206 cflags_cc += [ "-stdlib=libc++" ]
207 ldflags += [ "-stdlib=libc++" ]
208 }
209 }
210}
211
Mike Klein6e55fef2016-10-26 11:41:47 -0400212config("no_exceptions") {
213 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
214 if (!is_win) {
215 cflags_cc = [ "-fno-exceptions" ]
216 }
217}
218
Mike Kleinc7165c22016-10-12 23:58:06 -0400219config("warnings") {
220 cflags = []
221 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400222 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400223 if (is_win) {
224 cflags += [
225 "/W3", # Turn on lots of warnings.
226
227 # Disable a bunch of warnings:
228 "/wd4244", # conversion from 'float' to 'int', possible loss of data
229 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
230 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
231
232 # Probably only triggers when /EHsc is enabled.
233 "/wd4291", # no matching operator delete found;
234 # memory will not be freed if initialization throws an exception
235 ]
236 } else {
237 cflags += [
238 "-Wall",
239 "-Wextra",
240 "-Winit-self",
241 "-Wpointer-arith",
242 "-Wsign-compare",
243 "-Wvla",
244
245 "-Wno-deprecated-declarations",
246 "-Wno-unused-parameter",
247 ]
248 cflags_cc += [ "-Wnon-virtual-dtor" ]
249
250 if (is_clang) {
251 cflags += [
252 "-Weverything",
253 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
254 ]
255
256 if (is_android && target_cpu == "x86") {
257 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
258 # We're pretty sure it's actually 8-byte alignment.
259 cflags += [ "-Wno-over-aligned" ]
260 }
261
262 cflags += [
263 "-Wno-cast-align",
264 "-Wno-conditional-uninitialized",
265 "-Wno-conversion",
266 "-Wno-disabled-macro-expansion",
267 "-Wno-documentation",
268 "-Wno-documentation-unknown-command",
269 "-Wno-double-promotion",
270 "-Wno-exit-time-destructors", # TODO: OK outside libskia
271 "-Wno-float-conversion",
272 "-Wno-float-equal",
273 "-Wno-format-nonliteral",
274 "-Wno-global-constructors", # TODO: OK outside libskia
275 "-Wno-gnu-zero-variadic-macro-arguments",
276 "-Wno-missing-prototypes",
277 "-Wno-missing-variable-declarations",
278 "-Wno-pedantic",
279 "-Wno-reserved-id-macro",
280 "-Wno-shadow",
281 "-Wno-shift-sign-overflow",
282 "-Wno-sign-conversion",
283 "-Wno-switch-enum",
284 "-Wno-undef",
285 "-Wno-unreachable-code",
286 "-Wno-unreachable-code-break",
287 "-Wno-unreachable-code-return",
288 "-Wno-unused-macros",
289 "-Wno-unused-member-function",
290 ]
291 cflags_cc += [
292 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400293 "-Wno-weak-vtables",
294 ]
295
296 # We are unlikely to want to fix these.
297 cflags += [
298 "-Wno-covered-switch-default",
299 "-Wno-deprecated",
300 "-Wno-implicit-fallthrough",
301 "-Wno-missing-noreturn",
302 "-Wno-old-style-cast",
303 "-Wno-padded",
304 ]
305 cflags_cc += [
306 "-Wno-c++98-compat",
307 "-Wno-c++98-compat-pedantic",
308 "-Wno-undefined-func-template",
309 ]
Mike Klein43c25262016-10-20 10:17:47 -0400310 cflags_objc += [
311 "-Wno-direct-ivar-access",
312 "-Wno-objc-interface-ivars",
313 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400314 }
315 }
316}
317
Mike Klein121563e2016-10-04 17:09:13 -0400318config("extra_flags") {
319 cflags = extra_cflags
320 cflags_c = extra_cflags_c
321 cflags_cc = extra_cflags_cc
322 ldflags = extra_ldflags
323}
324
mtkleinb9be9792016-09-16 14:44:18 -0700325config("debug_symbols") {
326 # It's annoying to wait for full debug symbols to push over
327 # to Android devices. -gline-tables-only is a lot slimmer.
328 if (is_android) {
329 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400330 } else if (is_win) {
331 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400332 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400333 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700334 cflags = [ "-g" ]
335 }
336}
337
338config("no_rtti") {
339 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400340 if (is_win) {
341 cflags_cc = [ "/GR-" ]
342 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700343 cflags_cc = [ "-fno-rtti" ]
344 }
345 }
346}
347
348config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400349 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400350 cflags = [
351 "/O2",
352 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400353 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400354 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400355 ldflags = [
356 "/OPT:ICF",
357 "/OPT:REF",
358 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400359 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400360 cflags = [
361 "-O3",
362 "-momit-leaf-frame-pointer",
363 ]
herbb6318bf2016-09-16 13:29:57 -0700364 }
mtkleinb9be9792016-09-16 14:44:18 -0700365 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700366}
367
368config("executable") {
369 if (is_mac) {
370 ldflags = [ "-Wl,-rpath,@loader_path/." ]
371 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700372 ldflags = [
373 "-rdynamic",
374 "-Wl,-rpath,\$ORIGIN",
375 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700376 }
377}
378
herbb6318bf2016-09-16 13:29:57 -0700379toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400380 lib_dir_switch = "/LIBPATH:"
381
Mike Klein0bc5a762016-10-12 22:42:55 -0400382 bin = "$windk/VC/bin/amd64"
383 env_setup = ""
384 if (target_cpu == "x86") {
385 bin += "_x86"
386 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
387 }
herbb6318bf2016-09-16 13:29:57 -0700388
389 tool("cc") {
390 rspfile = "{{output}}.rsp"
391 precompiled_header_type = "msvc"
392 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
393
Mike Klein0f61faa2016-10-11 16:26:57 -0400394 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400395 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700396 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700397 outputs = [
398 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700399 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400400 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400401 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700402 }
403
404 tool("cxx") {
405 rspfile = "{{output}}.rsp"
406 precompiled_header_type = "msvc"
407 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
408
Mike Klein0f61faa2016-10-11 16:26:57 -0400409 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400410 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700411 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700412 outputs = [
413 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
414 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400415 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400416 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700417 }
herbb6318bf2016-09-16 13:29:57 -0700418
419 tool("alink") {
420 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700421
Mike Kleinc756e862016-10-13 14:31:01 -0400422 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700423 outputs = [
424 # Ignore {{output_extension}} and always use .lib, there's no reason to
425 # allow targets to override this extension on Windows.
426 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
427 ]
428 default_output_extension = ".lib"
429 default_output_dir = "{{target_out_dir}}"
430
Mike Klein0f61faa2016-10-11 16:26:57 -0400431 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700432 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400433 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700434 }
435
Mike Klein1a8d6752016-10-17 11:51:11 -0400436 tool("solink") {
437 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
438 libname = "${dllname}.lib"
439 pdbname = "${dllname}.pdb"
440 rspfile = "${dllname}.rsp"
441
442 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
443 outputs = [
444 dllname,
445 libname,
446 pdbname,
447 ]
448 default_output_extension = ".dll"
449 default_output_dir = "{{root_out_dir}}"
450
451 link_output = libname
452 depend_output = libname
453 runtime_outputs = [
454 dllname,
455 pdbname,
456 ]
457
458 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
459 restat = true
460
461 # inputs_newline works around a fixed per-line buffer size in the linker.
462 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
463 description = "link {{output}}"
464 }
465
herbb6318bf2016-09-16 13:29:57 -0700466 tool("link") {
467 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
468 pdbname = "$exename.pdb"
469 rspfile = "$exename.rsp"
470
Mike Klein0bc5a762016-10-12 22:42:55 -0400471 command =
472 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700473
474 default_output_extension = ".exe"
475 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700476 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700477 exename,
478 ]
mtkleinb9be9792016-09-16 14:44:18 -0700479
Mike Klein0f61faa2016-10-11 16:26:57 -0400480 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700481 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400482 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700483 }
484
herbb6318bf2016-09-16 13:29:57 -0700485 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400486 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400487 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700488 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400489
490 tool("copy") {
491 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400492 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400493 description = "copy {{source}} {{output}}"
494 }
herbb6318bf2016-09-16 13:29:57 -0700495}
496
mtklein7fbfbbe2016-07-21 12:25:45 -0700497toolchain("gcc_like") {
498 lib_switch = "-l"
499 lib_dir_switch = "-L"
500
501 tool("cc") {
502 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400503 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700504 depsformat = "gcc"
505 outputs = [
506 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
507 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400508 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700509 }
510
511 tool("cxx") {
512 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400513 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700514 depsformat = "gcc"
515 outputs = [
516 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
517 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400518 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700519 }
520
Mike Klein43c25262016-10-20 10:17:47 -0400521 tool("objc") {
522 depfile = "{{output}}.d"
523 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
524 depsformat = "gcc"
525 outputs = [
526 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
527 ]
528 description = "compile {{source}}"
529 }
530
531 tool("objcxx") {
532 depfile = "{{output}}.d"
533 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
534 depsformat = "gcc"
535 outputs = [
536 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
537 ]
538 description = "compile {{source}}"
539 }
540
mtklein7fbfbbe2016-07-21 12:25:45 -0700541 tool("asm") {
542 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700543 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700544 depsformat = "gcc"
545 outputs = [
546 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
547 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400548 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700549 }
550
551 tool("alink") {
Mike Klein82364ba2016-10-24 16:49:15 -0400552 if (host_os == "win") {
553 rspfile = "{{output}}.rsp"
554 rspfile_content = "{{inputs}}"
555 ar_py = rebase_path("ar.py")
556 command = "$python $ar_py $ar {{output}} $rspfile"
557 } else {
558 # We'd use ar.py all the time, but Mac ar doesn't support @rspfile syntax. :(
559 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
560 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700561 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700562 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700563 ]
564 default_output_extension = ".a"
565 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400566 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700567 }
568
569 tool("solink") {
570 soname = "{{target_output_name}}{{output_extension}}"
571
572 rpath = "-Wl,-soname,$soname"
573 if (is_mac) {
574 rpath = "-Wl,-install_name,@rpath/$soname"
575 }
576
Mike Klein121563e2016-10-04 17:09:13 -0400577 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700578 outputs = [
579 "{{root_out_dir}}/$soname",
580 ]
581 output_prefix = "lib"
582 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400583 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700584 }
585
586 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400587 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700588 outputs = [
589 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
590 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400591 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700592 }
593
594 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400595 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400596 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700597 }
598
599 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400600 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400601 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400602 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700603 }
604}