blob: 8451b9f0780c77d558e166391ae014a0c95b692f [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",
106 "-fno-exceptions",
107 "-fno-threadsafe-statics",
108 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -0700109 ]
mtkleinb9be9792016-09-16 14:44:18 -0700110 }
herbb6318bf2016-09-16 13:29:57 -0700111
mtkleinb9be9792016-09-16 14:44:18 -0700112 if (current_cpu == "arm") {
113 cflags += [
114 "-march=armv7-a",
115 "-mfpu=neon",
116 "-mthumb",
117 ]
118 } else if (current_cpu == "mipsel") {
119 cflags += [
120 "-march=mips32r2",
121 "-mdspr2",
122 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400123 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700124 asmflags += [ "-m32" ]
125 cflags += [
126 "-m32",
127 "-msse2",
128 "-mfpmath=sse",
129 ]
130 ldflags += [ "-m32" ]
131 }
herbb6318bf2016-09-16 13:29:57 -0700132
mtkleinb9be9792016-09-16 14:44:18 -0700133 if (is_android) {
134 asmflags += [
135 "--target=$ndk_target",
136 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
137 ]
138 cflags += [
139 "--sysroot=$ndk/platforms/$ndk_platform",
140 "--target=$ndk_target",
141 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
142 ]
143 cflags_cc += [
144 "-isystem$ndk/sources/android/support/include",
Mike Klein4fdc5432016-10-11 11:21:36 -0400145 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
146 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
mtkleinb9be9792016-09-16 14:44:18 -0700147 ]
148 ldflags += [
149 "--sysroot=$ndk/platforms/$ndk_platform",
150 "--target=$ndk_target",
151 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
152 "-pie",
153 ]
154 lib_dirs = [
155 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
156 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
157 ]
herbb6318bf2016-09-16 13:29:57 -0700158
Mike Klein4fdc5432016-10-11 11:21:36 -0400159 if (current_cpu == "mips64el") {
160 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
161 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
162 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
163 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
164 ldflags += [
165 # Clang will try to link these two files, but not find them. Again, do it manually.
166 "-nostartfiles",
167 "$ndk/platforms/$ndk_platform/usr/lib64/crtbegin_dynamic.o",
168 "$ndk/platforms/$ndk_platform/usr/lib64/crtend_android.o",
169 ]
170 }
171
mtkleinb9be9792016-09-16 14:44:18 -0700172 libs = [
173 # Order matters here! Keep these three in exactly this order.
174 "c++_static",
175 "c++abi",
176 "android_support",
177 ]
178 if (target_cpu == "arm") {
179 libs += [ "unwind" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700180 }
181 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700182
mtkleinb9be9792016-09-16 14:44:18 -0700183 if (is_linux) {
184 libs = [ "pthread" ]
185 }
186
187 if (sanitize != "") {
188 # You can either pass the sanitizers directly, e.g. "address,undefined",
189 # or pass one of the couple common aliases used by the bots.
190 sanitizers = sanitize
191 if (sanitize == "ASAN") {
192 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"
193 } else if (sanitize == "TSAN") {
194 sanitizers = "thread"
195 } else if (sanitize == "MSAN") {
196 sanitizers = "memory"
197 }
198
199 cflags += [
200 "-fsanitize=$sanitizers",
201 "-fno-sanitize-recover=$sanitizers",
202 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
203 ]
204 ldflags += [ "-fsanitize=$sanitizers" ]
205 if (sanitizers == "memory") {
206 cflags += [ "-fsanitize-memory-track-origins" ]
207 cflags_cc += [ "-stdlib=libc++" ]
208 ldflags += [ "-stdlib=libc++" ]
209 }
210 }
211}
212
Mike Kleinc7165c22016-10-12 23:58:06 -0400213config("warnings") {
214 cflags = []
215 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400216 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400217 if (is_win) {
218 cflags += [
219 "/W3", # Turn on lots of warnings.
220
221 # Disable a bunch of warnings:
222 "/wd4244", # conversion from 'float' to 'int', possible loss of data
223 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
224 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
225
226 # Probably only triggers when /EHsc is enabled.
227 "/wd4291", # no matching operator delete found;
228 # memory will not be freed if initialization throws an exception
229 ]
230 } else {
231 cflags += [
232 "-Wall",
233 "-Wextra",
234 "-Winit-self",
235 "-Wpointer-arith",
236 "-Wsign-compare",
237 "-Wvla",
238
239 "-Wno-deprecated-declarations",
240 "-Wno-unused-parameter",
241 ]
242 cflags_cc += [ "-Wnon-virtual-dtor" ]
243
244 if (is_clang) {
245 cflags += [
246 "-Weverything",
247 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
248 ]
249
250 if (is_android && target_cpu == "x86") {
251 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
252 # We're pretty sure it's actually 8-byte alignment.
253 cflags += [ "-Wno-over-aligned" ]
254 }
255
256 cflags += [
257 "-Wno-cast-align",
258 "-Wno-conditional-uninitialized",
259 "-Wno-conversion",
260 "-Wno-disabled-macro-expansion",
261 "-Wno-documentation",
262 "-Wno-documentation-unknown-command",
263 "-Wno-double-promotion",
264 "-Wno-exit-time-destructors", # TODO: OK outside libskia
265 "-Wno-float-conversion",
266 "-Wno-float-equal",
267 "-Wno-format-nonliteral",
268 "-Wno-global-constructors", # TODO: OK outside libskia
269 "-Wno-gnu-zero-variadic-macro-arguments",
270 "-Wno-missing-prototypes",
271 "-Wno-missing-variable-declarations",
272 "-Wno-pedantic",
273 "-Wno-reserved-id-macro",
274 "-Wno-shadow",
275 "-Wno-shift-sign-overflow",
276 "-Wno-sign-conversion",
277 "-Wno-switch-enum",
278 "-Wno-undef",
279 "-Wno-unreachable-code",
280 "-Wno-unreachable-code-break",
281 "-Wno-unreachable-code-return",
282 "-Wno-unused-macros",
283 "-Wno-unused-member-function",
284 ]
285 cflags_cc += [
286 "-Wno-abstract-vbase-init",
287 "-Wno-range-loop-analysis",
288 "-Wno-weak-vtables",
289 ]
290
291 # We are unlikely to want to fix these.
292 cflags += [
293 "-Wno-covered-switch-default",
294 "-Wno-deprecated",
295 "-Wno-implicit-fallthrough",
296 "-Wno-missing-noreturn",
297 "-Wno-old-style-cast",
298 "-Wno-padded",
299 ]
300 cflags_cc += [
301 "-Wno-c++98-compat",
302 "-Wno-c++98-compat-pedantic",
303 "-Wno-undefined-func-template",
304 ]
Mike Klein43c25262016-10-20 10:17:47 -0400305 cflags_objc += [
306 "-Wno-direct-ivar-access",
307 "-Wno-objc-interface-ivars",
308 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400309 }
310 }
311}
312
Mike Klein121563e2016-10-04 17:09:13 -0400313config("extra_flags") {
314 cflags = extra_cflags
315 cflags_c = extra_cflags_c
316 cflags_cc = extra_cflags_cc
317 ldflags = extra_ldflags
318}
319
mtkleinb9be9792016-09-16 14:44:18 -0700320config("debug_symbols") {
321 # It's annoying to wait for full debug symbols to push over
322 # to Android devices. -gline-tables-only is a lot slimmer.
323 if (is_android) {
324 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400325 } else if (is_win) {
326 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400327 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400328 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700329 cflags = [ "-g" ]
330 }
331}
332
333config("no_rtti") {
334 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400335 if (is_win) {
336 cflags_cc = [ "/GR-" ]
337 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700338 cflags_cc = [ "-fno-rtti" ]
339 }
340 }
341}
342
343config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400344 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400345 cflags = [
346 "/O2",
347 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400348 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400349 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400350 ldflags = [
351 "/OPT:ICF",
352 "/OPT:REF",
353 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400354 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400355 cflags = [
356 "-O3",
357 "-momit-leaf-frame-pointer",
358 ]
herbb6318bf2016-09-16 13:29:57 -0700359 }
mtkleinb9be9792016-09-16 14:44:18 -0700360 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700361}
362
363config("executable") {
364 if (is_mac) {
365 ldflags = [ "-Wl,-rpath,@loader_path/." ]
366 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700367 ldflags = [
368 "-rdynamic",
369 "-Wl,-rpath,\$ORIGIN",
370 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700371 }
372}
373
herbb6318bf2016-09-16 13:29:57 -0700374toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400375 lib_dir_switch = "/LIBPATH:"
376
Mike Klein0bc5a762016-10-12 22:42:55 -0400377 bin = "$windk/VC/bin/amd64"
378 env_setup = ""
379 if (target_cpu == "x86") {
380 bin += "_x86"
381 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
382 }
herbb6318bf2016-09-16 13:29:57 -0700383
384 tool("cc") {
385 rspfile = "{{output}}.rsp"
386 precompiled_header_type = "msvc"
387 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
388
Mike Klein0f61faa2016-10-11 16:26:57 -0400389 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400390 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700391 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700392 outputs = [
393 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700394 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400395 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400396 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700397 }
398
399 tool("cxx") {
400 rspfile = "{{output}}.rsp"
401 precompiled_header_type = "msvc"
402 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
403
Mike Klein0f61faa2016-10-11 16:26:57 -0400404 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400405 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700406 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700407 outputs = [
408 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
409 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400410 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400411 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700412 }
herbb6318bf2016-09-16 13:29:57 -0700413
414 tool("alink") {
415 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700416
Mike Kleinc756e862016-10-13 14:31:01 -0400417 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700418 outputs = [
419 # Ignore {{output_extension}} and always use .lib, there's no reason to
420 # allow targets to override this extension on Windows.
421 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
422 ]
423 default_output_extension = ".lib"
424 default_output_dir = "{{target_out_dir}}"
425
Mike Klein0f61faa2016-10-11 16:26:57 -0400426 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700427 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400428 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700429 }
430
Mike Klein1a8d6752016-10-17 11:51:11 -0400431 tool("solink") {
432 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
433 libname = "${dllname}.lib"
434 pdbname = "${dllname}.pdb"
435 rspfile = "${dllname}.rsp"
436
437 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
438 outputs = [
439 dllname,
440 libname,
441 pdbname,
442 ]
443 default_output_extension = ".dll"
444 default_output_dir = "{{root_out_dir}}"
445
446 link_output = libname
447 depend_output = libname
448 runtime_outputs = [
449 dllname,
450 pdbname,
451 ]
452
453 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
454 restat = true
455
456 # inputs_newline works around a fixed per-line buffer size in the linker.
457 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
458 description = "link {{output}}"
459 }
460
herbb6318bf2016-09-16 13:29:57 -0700461 tool("link") {
462 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
463 pdbname = "$exename.pdb"
464 rspfile = "$exename.rsp"
465
Mike Klein0bc5a762016-10-12 22:42:55 -0400466 command =
467 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700468
469 default_output_extension = ".exe"
470 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700471 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700472 exename,
473 ]
mtkleinb9be9792016-09-16 14:44:18 -0700474
Mike Klein0f61faa2016-10-11 16:26:57 -0400475 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700476 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400477 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700478 }
479
herbb6318bf2016-09-16 13:29:57 -0700480 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400481 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400482 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700483 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400484
485 tool("copy") {
486 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400487 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400488 description = "copy {{source}} {{output}}"
489 }
herbb6318bf2016-09-16 13:29:57 -0700490}
491
mtklein7fbfbbe2016-07-21 12:25:45 -0700492toolchain("gcc_like") {
493 lib_switch = "-l"
494 lib_dir_switch = "-L"
495
496 tool("cc") {
497 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400498 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700499 depsformat = "gcc"
500 outputs = [
501 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
502 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400503 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700504 }
505
506 tool("cxx") {
507 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400508 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700509 depsformat = "gcc"
510 outputs = [
511 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
512 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400513 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700514 }
515
Mike Klein43c25262016-10-20 10:17:47 -0400516 tool("objc") {
517 depfile = "{{output}}.d"
518 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
519 depsformat = "gcc"
520 outputs = [
521 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
522 ]
523 description = "compile {{source}}"
524 }
525
526 tool("objcxx") {
527 depfile = "{{output}}.d"
528 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
529 depsformat = "gcc"
530 outputs = [
531 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
532 ]
533 description = "compile {{source}}"
534 }
535
mtklein7fbfbbe2016-07-21 12:25:45 -0700536 tool("asm") {
537 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700538 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700539 depsformat = "gcc"
540 outputs = [
541 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
542 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400543 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700544 }
545
546 tool("alink") {
Mike Klein82364ba2016-10-24 16:49:15 -0400547 if (host_os == "win") {
548 rspfile = "{{output}}.rsp"
549 rspfile_content = "{{inputs}}"
550 ar_py = rebase_path("ar.py")
551 command = "$python $ar_py $ar {{output}} $rspfile"
552 } else {
553 # We'd use ar.py all the time, but Mac ar doesn't support @rspfile syntax. :(
554 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
555 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700556 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700557 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700558 ]
559 default_output_extension = ".a"
560 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400561 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700562 }
563
564 tool("solink") {
565 soname = "{{target_output_name}}{{output_extension}}"
566
567 rpath = "-Wl,-soname,$soname"
568 if (is_mac) {
569 rpath = "-Wl,-install_name,@rpath/$soname"
570 }
571
Mike Klein121563e2016-10-04 17:09:13 -0400572 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700573 outputs = [
574 "{{root_out_dir}}/$soname",
575 ]
576 output_prefix = "lib"
577 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400578 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700579 }
580
581 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400582 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700583 outputs = [
584 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
585 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400586 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700587 }
588
589 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400590 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400591 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700592 }
593
594 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400595 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400596 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400597 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700598 }
599}