mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 1 | # 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 | |
| 6 | declare_args() { |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 7 | ar = "ar" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 8 | cc = "cc" |
| 9 | cxx = "c++" |
mtklein | 8079ba6 | 2016-08-16 09:31:16 -0700 | [diff] [blame] | 10 | |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 11 | if (is_android) { |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 12 | ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar" |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 13 | cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang" |
| 14 | cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++" |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 15 | if (host_os == "win") { |
| 16 | ar = ar + ".exe" |
| 17 | cc = cc + ".exe" |
| 18 | cxx = cxx + ".exe" |
| 19 | } |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 22 | windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 23 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 24 | extra_cflags = [] |
| 25 | extra_cflags_c = [] |
| 26 | extra_cflags_cc = [] |
| 27 | extra_ldflags = [] |
mtklein | cab0bb7 | 2016-08-26 13:43:19 -0700 | [diff] [blame] | 28 | |
mtklein | 60b7ab7 | 2016-09-20 12:09:12 -0700 | [diff] [blame] | 29 | cc_wrapper = "" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 32 | if (host_os == "win") { |
| 33 | python = "python.bat" |
| 34 | stamp = "cmd.exe /c echo >" |
| 35 | } else { |
| 36 | python = "python" |
| 37 | stamp = "touch" |
| 38 | } |
| 39 | |
Mike Klein | 461d328 | 2016-10-11 13:51:55 -0400 | [diff] [blame] | 40 | if (!is_win) { |
| 41 | is_clang = exec_script("is_clang.py", |
| 42 | [ |
| 43 | cc, |
| 44 | cxx, |
| 45 | ], |
| 46 | "value") |
| 47 | } |
mtklein | f347c51 | 2016-09-26 08:40:12 -0700 | [diff] [blame] | 48 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 49 | config("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. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 60 | "/bigobj", # Some of our files are bigger than the regular limits. |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 61 | "/WX", # Treat warnings as errors. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 62 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 63 | defines += [ |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 64 | "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf(). |
| 65 | "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 66 | "WIN32_LEAN_AND_MEAN", |
| 67 | "NOMINMAX", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 68 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 69 | include_dirs = [ |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 70 | "$windk/VC/include", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 71 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 72 | # For local builds. |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 73 | "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt", |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 74 | "$windk/../Windows Kits/8.1/Include/shared", |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 75 | "$windk/../Windows Kits/8.1/Include/um", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 76 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 77 | # 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 Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 81 | ] |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 82 | lib_dirs = [ |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 83 | # For local builds. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 84 | "$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 Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 86 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 87 | # For builds using win_toolchain asset. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 88 | "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu", |
| 89 | "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu", |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 90 | ] |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 91 | if (target_cpu == "x86") { |
| 92 | lib_dirs += [ "$windk/VC/lib" ] |
| 93 | } else { |
| 94 | lib_dirs += [ "$windk/VC/lib/amd64" ] |
| 95 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 96 | } else { |
| 97 | cflags += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 98 | "-O1", |
| 99 | "-fstrict-aliasing", |
| 100 | "-fPIC", |
| 101 | "-fvisibility=hidden", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 102 | "-Werror", |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 103 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 104 | cflags_cc += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 105 | "-std=c++11", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 106 | "-fno-threadsafe-statics", |
| 107 | "-fvisibility-inlines-hidden", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 108 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 109 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 110 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 111 | 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 Klein | 5d8cf29 | 2016-10-12 19:36:09 -0400 | [diff] [blame] | 122 | } else if (current_cpu == "x86" && !is_win) { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 123 | asmflags += [ "-m32" ] |
| 124 | cflags += [ |
| 125 | "-m32", |
| 126 | "-msse2", |
| 127 | "-mfpmath=sse", |
| 128 | ] |
| 129 | ldflags += [ "-m32" ] |
| 130 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 131 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 132 | 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 Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 144 | "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b. |
| 145 | "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 146 | ] |
| 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 | ] |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 157 | |
Mike Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 158 | 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 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 171 | 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" ] |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 181 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 182 | 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 Klein | 6e55fef | 2016-10-26 11:41:47 -0400 | [diff] [blame] | 212 | config("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 Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 219 | config("warnings") { |
| 220 | cflags = [] |
| 221 | cflags_cc = [] |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 222 | cflags_objc = [] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 223 | 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 Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 293 | "-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 Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 310 | cflags_objc += [ |
| 311 | "-Wno-direct-ivar-access", |
| 312 | "-Wno-objc-interface-ivars", |
| 313 | ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 318 | config("extra_flags") { |
| 319 | cflags = extra_cflags |
| 320 | cflags_c = extra_cflags_c |
| 321 | cflags_cc = extra_cflags_cc |
| 322 | ldflags = extra_ldflags |
| 323 | } |
| 324 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 325 | config("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 Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 330 | } else if (is_win) { |
| 331 | cflags = [ "/Zi" ] |
Mike Klein | 5286d6c | 2016-10-13 13:19:25 -0400 | [diff] [blame] | 332 | ldflags = [ "/DEBUG" ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 333 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 334 | cflags = [ "-g" ] |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | config("no_rtti") { |
| 339 | if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 340 | if (is_win) { |
| 341 | cflags_cc = [ "/GR-" ] |
| 342 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 343 | cflags_cc = [ "-fno-rtti" ] |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | config("release") { |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 349 | if (is_win) { |
Mike Klein | 916ca1d | 2016-10-20 13:34:18 -0400 | [diff] [blame] | 350 | cflags = [ |
| 351 | "/O2", |
| 352 | "/Zc:inline", |
Mike Klein | 8ffb260 | 2016-10-20 15:45:02 -0400 | [diff] [blame] | 353 | "/GS-", |
Mike Klein | 916ca1d | 2016-10-20 13:34:18 -0400 | [diff] [blame] | 354 | ] |
Mike Klein | 90a381f | 2016-10-20 13:52:38 -0400 | [diff] [blame] | 355 | ldflags = [ |
| 356 | "/OPT:ICF", |
| 357 | "/OPT:REF", |
| 358 | ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 359 | } else { |
Mike Klein | 0bcfeac | 2016-10-19 22:24:10 -0400 | [diff] [blame] | 360 | cflags = [ |
| 361 | "-O3", |
| 362 | "-momit-leaf-frame-pointer", |
| 363 | ] |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 364 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 365 | defines = [ "NDEBUG" ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | config("executable") { |
| 369 | if (is_mac) { |
| 370 | ldflags = [ "-Wl,-rpath,@loader_path/." ] |
| 371 | } else if (is_linux) { |
mtklein | a846c72 | 2016-09-15 10:44:15 -0700 | [diff] [blame] | 372 | ldflags = [ |
| 373 | "-rdynamic", |
| 374 | "-Wl,-rpath,\$ORIGIN", |
| 375 | ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 379 | toolchain("msvc") { |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 380 | lib_dir_switch = "/LIBPATH:" |
| 381 | |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 382 | 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 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 388 | |
| 389 | tool("cc") { |
| 390 | rspfile = "{{output}}.rsp" |
| 391 | precompiled_header_type = "msvc" |
| 392 | pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" |
| 393 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 394 | # Label names may have spaces so pdbname must be quoted. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 395 | command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\"" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 396 | depsformat = "msvc" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 397 | outputs = [ |
| 398 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 399 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 400 | rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 401 | description = "compile {{source}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | tool("cxx") { |
| 405 | rspfile = "{{output}}.rsp" |
| 406 | precompiled_header_type = "msvc" |
| 407 | pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" |
| 408 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 409 | # Label names may have spaces so pdbname must be quoted. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 410 | command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\"" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 411 | depsformat = "msvc" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 412 | outputs = [ |
| 413 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", |
| 414 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 415 | rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 416 | description = "compile {{source}}" |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 417 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 418 | |
| 419 | tool("alink") { |
| 420 | rspfile = "{{output}}.rsp" |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 421 | |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 422 | command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 423 | 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 Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 431 | # inputs_newline works around a fixed per-line buffer size in the linker. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 432 | rspfile_content = "{{inputs_newline}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 433 | description = "link {{output}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Mike Klein | 1a8d675 | 2016-10-17 11:51:11 -0400 | [diff] [blame] | 436 | 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 | |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 466 | tool("link") { |
| 467 | exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" |
| 468 | pdbname = "$exename.pdb" |
| 469 | rspfile = "$exename.rsp" |
| 470 | |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 471 | command = |
| 472 | "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 473 | |
| 474 | default_output_extension = ".exe" |
| 475 | default_output_dir = "{{root_out_dir}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 476 | outputs = [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 477 | exename, |
| 478 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 479 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 480 | # inputs_newline works around a fixed per-line buffer size in the linker. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 481 | rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 482 | description = "link {{output}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 483 | } |
| 484 | |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 485 | tool("stamp") { |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 486 | command = "$stamp {{output}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 487 | description = "stamp {{output}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 488 | } |
Mike Klein | 1a8d675 | 2016-10-17 11:51:11 -0400 | [diff] [blame] | 489 | |
| 490 | tool("copy") { |
| 491 | cp_py = rebase_path("cp.py") |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 492 | command = "$python $cp_py {{source}} {{output}}" |
Mike Klein | 1a8d675 | 2016-10-17 11:51:11 -0400 | [diff] [blame] | 493 | description = "copy {{source}} {{output}}" |
| 494 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 495 | } |
| 496 | |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 497 | toolchain("gcc_like") { |
| 498 | lib_switch = "-l" |
| 499 | lib_dir_switch = "-L" |
| 500 | |
| 501 | tool("cc") { |
| 502 | depfile = "{{output}}.d" |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 503 | command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 504 | depsformat = "gcc" |
| 505 | outputs = [ |
| 506 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 507 | ] |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 508 | description = "compile {{source}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | tool("cxx") { |
| 512 | depfile = "{{output}}.d" |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 513 | command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 514 | depsformat = "gcc" |
| 515 | outputs = [ |
| 516 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 517 | ] |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 518 | description = "compile {{source}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 521 | 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 | |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 541 | tool("asm") { |
| 542 | depfile = "{{output}}.d" |
mtklein | 60b7ab7 | 2016-09-20 12:09:12 -0700 | [diff] [blame] | 543 | command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 544 | depsformat = "gcc" |
| 545 | outputs = [ |
| 546 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 547 | ] |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 548 | description = "compile {{source}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | tool("alink") { |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 552 | 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 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 561 | outputs = [ |
mtklein | 5db44aa | 2016-07-29 09:10:31 -0700 | [diff] [blame] | 562 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 563 | ] |
| 564 | default_output_extension = ".a" |
| 565 | output_prefix = "lib" |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 566 | description = "link {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 567 | } |
| 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 Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 577 | command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 578 | outputs = [ |
| 579 | "{{root_out_dir}}/$soname", |
| 580 | ] |
| 581 | output_prefix = "lib" |
| 582 | default_output_extension = ".so" |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 583 | description = "link {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | tool("link") { |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 587 | command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 588 | outputs = [ |
| 589 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 590 | ] |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 591 | description = "link {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | tool("stamp") { |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 595 | command = "$stamp {{output}}" |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 596 | description = "stamp {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | tool("copy") { |
Mike Klein | 1a8d675 | 2016-10-17 11:51:11 -0400 | [diff] [blame] | 600 | cp_py = rebase_path("cp.py") |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 601 | command = "$python $cp_py {{source}} {{output}}" |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 602 | description = "copy {{source}} {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 603 | } |
| 604 | } |