1 # Copyright 2016 Google Inc.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
12 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
13 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
14 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
17 windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0"
28 is_clang = exec_script("is_clang.py",
46 "/FS", # Preserve previous PDB behavior.
47 "/bigobj", # Some of our files are bigger than the regular limits.
48 "/WX", # Treat warnings as errors.
51 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
52 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
53 "WIN32_LEAN_AND_MEAN",
60 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
61 "$windk/../Windows Kits/8.1/Include/shared",
62 "$windk/../Windows Kits/8.1/Include/um",
64 # For builds using win_toolchain asset.
65 "$windk/win_sdk/Include/10.0.10586.0/shared",
66 "$windk/win_sdk/Include/10.0.10586.0/ucrt",
67 "$windk/win_sdk/Include/10.0.10586.0/um",
71 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
72 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
74 # For builds using win_toolchain asset.
75 "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu",
76 "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu",
78 if (target_cpu == "x86") {
79 lib_dirs += [ "$windk/VC/lib" ]
81 lib_dirs += [ "$windk/VC/lib/amd64" ]
88 "-fvisibility=hidden",
94 "-fno-threadsafe-statics",
95 "-fvisibility-inlines-hidden",
99 if (current_cpu == "arm") {
105 } else if (current_cpu == "mipsel") {
110 } else if (current_cpu == "x86" && !is_win) {
111 asmflags += [ "-m32" ]
117 ldflags += [ "-m32" ]
122 "--target=$ndk_target",
123 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
126 "--sysroot=$ndk/platforms/$ndk_platform",
127 "--target=$ndk_target",
128 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
131 "-isystem$ndk/sources/android/support/include",
132 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
133 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
136 "--sysroot=$ndk/platforms/$ndk_platform",
137 "--target=$ndk_target",
138 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
142 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
143 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
146 if (current_cpu == "mips64el") {
147 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
148 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
149 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
150 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
152 # Clang will try to link these two files, but not find them. Again, do it manually.
154 "$ndk/platforms/$ndk_platform/usr/lib64/crtbegin_dynamic.o",
155 "$ndk/platforms/$ndk_platform/usr/lib64/crtend_android.o",
160 # Order matters here! Keep these three in exactly this order.
165 if (target_cpu == "arm") {
174 if (sanitize != "") {
175 # You can either pass the sanitizers directly, e.g. "address,undefined",
176 # or pass one of the couple common aliases used by the bots.
177 sanitizers = sanitize
178 if (sanitize == "ASAN") {
179 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"
180 } else if (sanitize == "TSAN") {
181 sanitizers = "thread"
182 } else if (sanitize == "MSAN") {
183 sanitizers = "memory"
187 "-fsanitize=$sanitizers",
188 "-fno-sanitize-recover=$sanitizers",
189 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
191 ldflags += [ "-fsanitize=$sanitizers" ]
192 if (sanitizers == "memory") {
193 cflags += [ "-fsanitize-memory-track-origins" ]
194 cflags_cc += [ "-stdlib=libc++" ]
195 ldflags += [ "-stdlib=libc++" ]
205 "/W3", # Turn on lots of warnings.
207 # Disable a bunch of warnings:
208 "/wd4244", # conversion from 'float' to 'int', possible loss of data
209 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
210 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
212 # Probably only triggers when /EHsc is enabled.
213 "/wd4291", # no matching operator delete found;
214 # memory will not be freed if initialization throws an exception
225 "-Wno-deprecated-declarations",
226 "-Wno-unused-parameter",
228 cflags_cc += [ "-Wnon-virtual-dtor" ]
233 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
236 if (is_android && target_cpu == "x86") {
237 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
238 # We're pretty sure it's actually 8-byte alignment.
239 cflags += [ "-Wno-over-aligned" ]
244 "-Wno-conditional-uninitialized",
246 "-Wno-disabled-macro-expansion",
247 "-Wno-documentation",
248 "-Wno-documentation-unknown-command",
249 "-Wno-double-promotion",
250 "-Wno-exit-time-destructors", # TODO: OK outside libskia
251 "-Wno-float-conversion",
253 "-Wno-format-nonliteral",
254 "-Wno-global-constructors", # TODO: OK outside libskia
255 "-Wno-gnu-zero-variadic-macro-arguments",
256 "-Wno-missing-prototypes",
257 "-Wno-missing-variable-declarations",
259 "-Wno-reserved-id-macro",
261 "-Wno-shift-sign-overflow",
262 "-Wno-sign-conversion",
265 "-Wno-unreachable-code",
266 "-Wno-unreachable-code-break",
267 "-Wno-unreachable-code-return",
268 "-Wno-unused-macros",
269 "-Wno-unused-member-function",
272 "-Wno-abstract-vbase-init",
273 "-Wno-range-loop-analysis",
277 # We are unlikely to want to fix these.
279 "-Wno-covered-switch-default",
281 "-Wno-implicit-fallthrough",
282 "-Wno-missing-noreturn",
283 "-Wno-old-style-cast",
288 "-Wno-c++98-compat-pedantic",
289 "-Wno-undefined-func-template",
295 config("extra_flags") {
296 cflags = extra_cflags
297 cflags_c = extra_cflags_c
298 cflags_cc = extra_cflags_cc
299 ldflags = extra_ldflags
302 config("debug_symbols") {
303 # It's annoying to wait for full debug symbols to push over
304 # to Android devices. -gline-tables-only is a lot slimmer.
306 cflags = [ "-gline-tables-only" ]
309 ldflags = [ "/DEBUG" ]
316 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
318 cflags_cc = [ "/GR-" ]
320 cflags_cc = [ "-fno-rtti" ]
331 defines = [ "NDEBUG" ]
334 config("executable") {
336 ldflags = [ "-Wl,-rpath,@loader_path/." ]
337 } else if (is_linux) {
340 "-Wl,-rpath,\$ORIGIN",
346 lib_dir_switch = "/LIBPATH:"
348 bin = "$windk/VC/bin/amd64"
350 if (target_cpu == "x86") {
352 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
356 rspfile = "{{output}}.rsp"
357 precompiled_header_type = "msvc"
358 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
360 # Label names may have spaces so pdbname must be quoted.
361 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
364 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
366 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
367 description = "compile {{source}}"
371 rspfile = "{{output}}.rsp"
372 precompiled_header_type = "msvc"
373 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
375 # Label names may have spaces so pdbname must be quoted.
376 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
379 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
381 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
382 description = "compile {{source}}"
386 rspfile = "{{output}}.rsp"
388 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
390 # Ignore {{output_extension}} and always use .lib, there's no reason to
391 # allow targets to override this extension on Windows.
392 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
394 default_output_extension = ".lib"
395 default_output_dir = "{{target_out_dir}}"
397 # inputs_newline works around a fixed per-line buffer size in the linker.
398 rspfile_content = "{{inputs_newline}}"
399 description = "link {{output}}"
403 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
404 pdbname = "$exename.pdb"
405 rspfile = "$exename.rsp"
408 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
410 default_output_extension = ".exe"
411 default_output_dir = "{{root_out_dir}}"
416 # inputs_newline works around a fixed per-line buffer size in the linker.
417 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
418 description = "link {{output}}"
422 command = "cmd.exe /c echo > {{output}}"
423 description = "stamp {{output}}"
427 toolchain("gcc_like") {
429 lib_dir_switch = "-L"
432 depfile = "{{output}}.d"
433 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
436 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
438 description = "compile {{source}}"
442 depfile = "{{output}}.d"
443 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
446 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
448 description = "compile {{source}}"
452 depfile = "{{output}}.d"
453 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
456 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
458 description = "compile {{source}}"
462 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
464 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
466 default_output_extension = ".a"
467 output_prefix = "lib"
468 description = "link {{output}}"
472 soname = "{{target_output_name}}{{output_extension}}"
474 rpath = "-Wl,-soname,$soname"
476 rpath = "-Wl,-install_name,@rpath/$soname"
479 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
481 "{{root_out_dir}}/$soname",
483 output_prefix = "lib"
484 default_output_extension = ".so"
485 description = "link {{output}}"
489 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
491 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
493 description = "link {{output}}"
497 command = "touch {{output}}"
498 description = "stamp {{output}}"
502 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
503 description = "copy {{source}} {{output}}"