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++" |
| 15 | } |
| 16 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 17 | windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 18 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 19 | extra_cflags = [] |
| 20 | extra_cflags_c = [] |
| 21 | extra_cflags_cc = [] |
| 22 | extra_ldflags = [] |
mtklein | cab0bb7 | 2016-08-26 13:43:19 -0700 | [diff] [blame] | 23 | |
mtklein | 60b7ab7 | 2016-09-20 12:09:12 -0700 | [diff] [blame] | 24 | cc_wrapper = "" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Mike Klein | 461d328 | 2016-10-11 13:51:55 -0400 | [diff] [blame] | 27 | if (!is_win) { |
| 28 | is_clang = exec_script("is_clang.py", |
| 29 | [ |
| 30 | cc, |
| 31 | cxx, |
| 32 | ], |
| 33 | "value") |
| 34 | } |
mtklein | f347c51 | 2016-09-26 08:40:12 -0700 | [diff] [blame] | 35 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 36 | config("default") { |
| 37 | asmflags = [] |
| 38 | cflags = [] |
| 39 | cflags_c = [] |
| 40 | cflags_cc = [] |
| 41 | defines = [] |
| 42 | ldflags = [] |
| 43 | |
| 44 | if (is_win) { |
| 45 | cflags += [ |
| 46 | "/FS", # Preserve previous PDB behavior. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 47 | "/bigobj", # Some of our files are bigger than the regular limits. |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 48 | "/WX", # Treat warnings as errors. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 49 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 50 | defines += [ |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 51 | "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf(). |
| 52 | "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 53 | "WIN32_LEAN_AND_MEAN", |
| 54 | "NOMINMAX", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 55 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 56 | include_dirs = [ |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 57 | "$windk/VC/include", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 58 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 59 | # For local builds. |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 60 | "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt", |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 61 | "$windk/../Windows Kits/8.1/Include/shared", |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 62 | "$windk/../Windows Kits/8.1/Include/um", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 63 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 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", |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 68 | ] |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 69 | lib_dirs = [ |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 70 | # For local builds. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 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", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 73 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 74 | # For builds using win_toolchain asset. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 75 | "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu", |
| 76 | "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu", |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 77 | ] |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 78 | if (target_cpu == "x86") { |
| 79 | lib_dirs += [ "$windk/VC/lib" ] |
| 80 | } else { |
| 81 | lib_dirs += [ "$windk/VC/lib/amd64" ] |
| 82 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 83 | } else { |
| 84 | cflags += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 85 | "-O1", |
| 86 | "-fstrict-aliasing", |
| 87 | "-fPIC", |
| 88 | "-fvisibility=hidden", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 89 | "-Werror", |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 90 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 91 | cflags_cc += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 92 | "-std=c++11", |
| 93 | "-fno-exceptions", |
| 94 | "-fno-threadsafe-statics", |
| 95 | "-fvisibility-inlines-hidden", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 96 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 97 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 98 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 99 | if (current_cpu == "arm") { |
| 100 | cflags += [ |
| 101 | "-march=armv7-a", |
| 102 | "-mfpu=neon", |
| 103 | "-mthumb", |
| 104 | ] |
| 105 | } else if (current_cpu == "mipsel") { |
| 106 | cflags += [ |
| 107 | "-march=mips32r2", |
| 108 | "-mdspr2", |
| 109 | ] |
Mike Klein | 5d8cf29 | 2016-10-12 19:36:09 -0400 | [diff] [blame] | 110 | } else if (current_cpu == "x86" && !is_win) { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 111 | asmflags += [ "-m32" ] |
| 112 | cflags += [ |
| 113 | "-m32", |
| 114 | "-msse2", |
| 115 | "-mfpmath=sse", |
| 116 | ] |
| 117 | ldflags += [ "-m32" ] |
| 118 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 119 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 120 | if (is_android) { |
| 121 | asmflags += [ |
| 122 | "--target=$ndk_target", |
| 123 | "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
| 124 | ] |
| 125 | cflags += [ |
| 126 | "--sysroot=$ndk/platforms/$ndk_platform", |
| 127 | "--target=$ndk_target", |
| 128 | "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
| 129 | ] |
| 130 | cflags_cc += [ |
| 131 | "-isystem$ndk/sources/android/support/include", |
Mike Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 132 | "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b. |
| 133 | "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 134 | ] |
| 135 | ldflags += [ |
| 136 | "--sysroot=$ndk/platforms/$ndk_platform", |
| 137 | "--target=$ndk_target", |
| 138 | "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
| 139 | "-pie", |
| 140 | ] |
| 141 | lib_dirs = [ |
| 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", |
| 144 | ] |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 145 | |
Mike Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 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" ] |
| 151 | ldflags += [ |
| 152 | # Clang will try to link these two files, but not find them. Again, do it manually. |
| 153 | "-nostartfiles", |
| 154 | "$ndk/platforms/$ndk_platform/usr/lib64/crtbegin_dynamic.o", |
| 155 | "$ndk/platforms/$ndk_platform/usr/lib64/crtend_android.o", |
| 156 | ] |
| 157 | } |
| 158 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 159 | libs = [ |
| 160 | # Order matters here! Keep these three in exactly this order. |
| 161 | "c++_static", |
| 162 | "c++abi", |
| 163 | "android_support", |
| 164 | ] |
| 165 | if (target_cpu == "arm") { |
| 166 | libs += [ "unwind" ] |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 167 | } |
| 168 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 169 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 170 | if (is_linux) { |
| 171 | libs = [ "pthread" ] |
| 172 | } |
| 173 | |
| 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" |
| 184 | } |
| 185 | |
| 186 | cflags += [ |
| 187 | "-fsanitize=$sanitizers", |
| 188 | "-fno-sanitize-recover=$sanitizers", |
| 189 | "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"), |
| 190 | ] |
| 191 | ldflags += [ "-fsanitize=$sanitizers" ] |
| 192 | if (sanitizers == "memory") { |
| 193 | cflags += [ "-fsanitize-memory-track-origins" ] |
| 194 | cflags_cc += [ "-stdlib=libc++" ] |
| 195 | ldflags += [ "-stdlib=libc++" ] |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 200 | config("warnings") { |
| 201 | cflags = [] |
| 202 | cflags_cc = [] |
| 203 | if (is_win) { |
| 204 | cflags += [ |
| 205 | "/W3", # Turn on lots of warnings. |
| 206 | |
| 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) |
| 211 | |
| 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 |
| 215 | ] |
| 216 | } else { |
| 217 | cflags += [ |
| 218 | "-Wall", |
| 219 | "-Wextra", |
| 220 | "-Winit-self", |
| 221 | "-Wpointer-arith", |
| 222 | "-Wsign-compare", |
| 223 | "-Wvla", |
| 224 | |
| 225 | "-Wno-deprecated-declarations", |
| 226 | "-Wno-unused-parameter", |
| 227 | ] |
| 228 | cflags_cc += [ "-Wnon-virtual-dtor" ] |
| 229 | |
| 230 | if (is_clang) { |
| 231 | cflags += [ |
| 232 | "-Weverything", |
| 233 | "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings. |
| 234 | ] |
| 235 | |
| 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" ] |
| 240 | } |
| 241 | |
| 242 | cflags += [ |
| 243 | "-Wno-cast-align", |
| 244 | "-Wno-conditional-uninitialized", |
| 245 | "-Wno-conversion", |
| 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", |
| 252 | "-Wno-float-equal", |
| 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", |
| 258 | "-Wno-pedantic", |
| 259 | "-Wno-reserved-id-macro", |
| 260 | "-Wno-shadow", |
| 261 | "-Wno-shift-sign-overflow", |
| 262 | "-Wno-sign-conversion", |
| 263 | "-Wno-switch-enum", |
| 264 | "-Wno-undef", |
| 265 | "-Wno-unreachable-code", |
| 266 | "-Wno-unreachable-code-break", |
| 267 | "-Wno-unreachable-code-return", |
| 268 | "-Wno-unused-macros", |
| 269 | "-Wno-unused-member-function", |
| 270 | ] |
| 271 | cflags_cc += [ |
| 272 | "-Wno-abstract-vbase-init", |
| 273 | "-Wno-range-loop-analysis", |
| 274 | "-Wno-weak-vtables", |
| 275 | ] |
| 276 | |
| 277 | # We are unlikely to want to fix these. |
| 278 | cflags += [ |
| 279 | "-Wno-covered-switch-default", |
| 280 | "-Wno-deprecated", |
| 281 | "-Wno-implicit-fallthrough", |
| 282 | "-Wno-missing-noreturn", |
| 283 | "-Wno-old-style-cast", |
| 284 | "-Wno-padded", |
| 285 | ] |
| 286 | cflags_cc += [ |
| 287 | "-Wno-c++98-compat", |
| 288 | "-Wno-c++98-compat-pedantic", |
| 289 | "-Wno-undefined-func-template", |
| 290 | ] |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 295 | config("extra_flags") { |
| 296 | cflags = extra_cflags |
| 297 | cflags_c = extra_cflags_c |
| 298 | cflags_cc = extra_cflags_cc |
| 299 | ldflags = extra_ldflags |
| 300 | } |
| 301 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 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. |
| 305 | if (is_android) { |
| 306 | cflags = [ "-gline-tables-only" ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 307 | } else if (is_win) { |
| 308 | cflags = [ "/Zi" ] |
Mike Klein | 5286d6c | 2016-10-13 13:19:25 -0400 | [diff] [blame] | 309 | ldflags = [ "/DEBUG" ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 310 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 311 | cflags = [ "-g" ] |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | config("no_rtti") { |
| 316 | if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 317 | if (is_win) { |
| 318 | cflags_cc = [ "/GR-" ] |
| 319 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 320 | cflags_cc = [ "-fno-rtti" ] |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | config("release") { |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 326 | if (is_win) { |
| 327 | cflags = [ "/O2" ] |
| 328 | } else { |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 329 | cflags = [ "-O3" ] |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 330 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 331 | defines = [ "NDEBUG" ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | config("executable") { |
| 335 | if (is_mac) { |
| 336 | ldflags = [ "-Wl,-rpath,@loader_path/." ] |
| 337 | } else if (is_linux) { |
mtklein | a846c72 | 2016-09-15 10:44:15 -0700 | [diff] [blame] | 338 | ldflags = [ |
| 339 | "-rdynamic", |
| 340 | "-Wl,-rpath,\$ORIGIN", |
| 341 | ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 345 | toolchain("msvc") { |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 346 | lib_dir_switch = "/LIBPATH:" |
| 347 | |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 348 | bin = "$windk/VC/bin/amd64" |
| 349 | env_setup = "" |
| 350 | if (target_cpu == "x86") { |
| 351 | bin += "_x86" |
| 352 | env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && " |
| 353 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 354 | |
| 355 | tool("cc") { |
| 356 | rspfile = "{{output}}.rsp" |
| 357 | precompiled_header_type = "msvc" |
| 358 | pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" |
| 359 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 360 | # Label names may have spaces so pdbname must be quoted. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 361 | 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] | 362 | depsformat = "msvc" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 363 | outputs = [ |
| 364 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 365 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 366 | rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame^] | 367 | description = "compile {{source}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | tool("cxx") { |
| 371 | rspfile = "{{output}}.rsp" |
| 372 | precompiled_header_type = "msvc" |
| 373 | pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" |
| 374 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 375 | # Label names may have spaces so pdbname must be quoted. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 376 | 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] | 377 | depsformat = "msvc" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 378 | outputs = [ |
| 379 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", |
| 380 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 381 | rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame^] | 382 | description = "compile {{source}}" |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 383 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 384 | |
| 385 | tool("alink") { |
| 386 | rspfile = "{{output}}.rsp" |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 387 | |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame^] | 388 | command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 389 | outputs = [ |
| 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}}", |
| 393 | ] |
| 394 | default_output_extension = ".lib" |
| 395 | default_output_dir = "{{target_out_dir}}" |
| 396 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 397 | # inputs_newline works around a fixed per-line buffer size in the linker. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 398 | rspfile_content = "{{inputs_newline}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame^] | 399 | description = "link {{output}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | tool("link") { |
| 403 | exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" |
| 404 | pdbname = "$exename.pdb" |
| 405 | rspfile = "$exename.rsp" |
| 406 | |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 407 | command = |
| 408 | "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 409 | |
| 410 | default_output_extension = ".exe" |
| 411 | default_output_dir = "{{root_out_dir}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 412 | outputs = [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 413 | exename, |
| 414 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 415 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 416 | # inputs_newline works around a fixed per-line buffer size in the linker. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 417 | rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame^] | 418 | description = "link {{output}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 419 | } |
| 420 | |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 421 | tool("stamp") { |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 422 | command = "cmd.exe /c echo > {{output}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame^] | 423 | description = "stamp {{output}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 427 | toolchain("gcc_like") { |
| 428 | lib_switch = "-l" |
| 429 | lib_dir_switch = "-L" |
| 430 | |
| 431 | tool("cc") { |
| 432 | depfile = "{{output}}.d" |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 433 | 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] | 434 | depsformat = "gcc" |
| 435 | outputs = [ |
| 436 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 437 | ] |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 438 | description = "$cc_wrapper $cc ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | tool("cxx") { |
| 442 | depfile = "{{output}}.d" |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 443 | 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] | 444 | depsformat = "gcc" |
| 445 | outputs = [ |
| 446 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 447 | ] |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 448 | description = "$cc_wrapper $cxx ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | tool("asm") { |
| 452 | depfile = "{{output}}.d" |
mtklein | 60b7ab7 | 2016-09-20 12:09:12 -0700 | [diff] [blame] | 453 | 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] | 454 | depsformat = "gcc" |
| 455 | outputs = [ |
| 456 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 457 | ] |
mtklein | 60b7ab7 | 2016-09-20 12:09:12 -0700 | [diff] [blame] | 458 | description = "$cc_wrapper $cc ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | tool("alink") { |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 462 | command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 463 | outputs = [ |
mtklein | 5db44aa | 2016-07-29 09:10:31 -0700 | [diff] [blame] | 464 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 465 | ] |
| 466 | default_output_extension = ".a" |
| 467 | output_prefix = "lib" |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 468 | description = "$ar {{output}} ..." |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | tool("solink") { |
| 472 | soname = "{{target_output_name}}{{output_extension}}" |
| 473 | |
| 474 | rpath = "-Wl,-soname,$soname" |
| 475 | if (is_mac) { |
| 476 | rpath = "-Wl,-install_name,@rpath/$soname" |
| 477 | } |
| 478 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 479 | command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 480 | outputs = [ |
| 481 | "{{root_out_dir}}/$soname", |
| 482 | ] |
| 483 | output_prefix = "lib" |
| 484 | default_output_extension = ".so" |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 485 | description = "$cc_wrapper $cxx -shared ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | tool("link") { |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 489 | command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 490 | outputs = [ |
| 491 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 492 | ] |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 493 | description = "$cc_wrapper $cxx ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | tool("stamp") { |
| 497 | command = "touch {{output}}" |
| 498 | } |
| 499 | |
| 500 | tool("copy") { |
| 501 | command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})" |
| 502 | } |
| 503 | } |