blob: 7791c1b99970ea627b99cf55aff5e337e583c082 [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() {
Kevin Lubick2677a9a2017-03-28 15:45:41 -04007 extra_asmflags = []
Mike Klein121563e2016-10-04 17:09:13 -04008 extra_cflags = []
9 extra_cflags_c = []
10 extra_cflags_cc = []
11 extra_ldflags = []
mtkleincab0bb72016-08-26 13:43:19 -070012
Herb Derby76073c12016-12-08 19:00:40 -050013 malloc = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070014}
Mike Klein82364ba2016-10-24 16:49:15 -040015
Mike Klein7d302882016-11-03 14:06:31 -040016if (is_ios) {
Matthew Leibowitz3150ec62017-03-14 16:22:32 -040017 if (is_tvos) {
18 sdk = "appletvos"
19 if (target_cpu == "x86" || target_cpu == "x64") {
20 sdk = "appletvsimulator"
21 }
22 } else {
23 sdk = "iphoneos"
24 if (target_cpu == "x86" || target_cpu == "x64") {
25 sdk = "iphonesimulator"
26 }
Mike Klein7a5e0f32017-03-13 09:25:33 -070027 }
28 ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string")
Mike Klein7d302882016-11-03 14:06:31 -040029}
30
mtkleinb9be9792016-09-16 14:44:18 -070031config("default") {
32 asmflags = []
33 cflags = []
34 cflags_c = []
35 cflags_cc = []
36 defines = []
37 ldflags = []
Herb Derby76073c12016-12-08 19:00:40 -050038 libs = []
mtkleinb9be9792016-09-16 14:44:18 -070039
40 if (is_win) {
41 cflags += [
42 "/FS", # Preserve previous PDB behavior.
herbb6318bf2016-09-16 13:29:57 -070043 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040044 "/WX", # Treat warnings as errors.
Ben Wagnere6b274e2017-01-03 17:09:59 -050045 "/utf-8", # Set Source and Executable character sets to UTF-8.
herbb6318bf2016-09-16 13:29:57 -070046 ]
Mike Kleina91ec582017-07-31 16:35:17 -040047 if (is_clang) {
48 cflags += [ "-fms-compatibility-version=19" ] # 2015
49 }
mtkleinb9be9792016-09-16 14:44:18 -070050 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040051 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
52 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070053 "WIN32_LEAN_AND_MEAN",
54 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070055 ]
Mike Klein98adfa82017-07-31 15:46:47 -040056
57 _include_dirs = [
Ben Wagner4e8472c2017-03-20 16:53:05 -040058 #2017
59 "$windk/VC/Tools/MSVC/14.10.25017/include",
60
61 #2015
Mike Kleind3016832016-10-12 15:52:44 -040062 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040063
Mike Kleind3016832016-10-12 15:52:44 -040064 # For local builds.
Ben Wagner4e8472c2017-03-20 16:53:05 -040065 # 2017
66 "$windk/../../../Windows Kits/10/Include/10.0.14393.0/shared",
67 "$windk/../../../Windows Kits/10/Include/10.0.14393.0/ucrt",
68 "$windk/../../../Windows Kits/10/Include/10.0.14393.0/um",
69 "$windk/../../../Windows Kits/10/Include/10.0.14393.0/winrt",
70
71 # 2015
Mike Klein0f61faa2016-10-11 16:26:57 -040072 "$windk/../Windows Kits/8.1/Include/shared",
Ben Wagner4e8472c2017-03-20 16:53:05 -040073 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein3eb71212016-10-11 17:08:53 -040074 "$windk/../Windows Kits/8.1/Include/um",
Brian Osman21d742d2017-01-10 13:31:33 -050075 "$windk/../Windows Kits/8.1/Include/winrt",
Mike Kleincc300a12016-10-12 16:25:27 -040076
Mike Kleind3016832016-10-12 15:52:44 -040077 # For builds using win_toolchain asset.
Brian Osman3f289332017-01-10 10:38:23 -050078 "$windk/win_sdk/Include/10.0.14393.0/shared",
79 "$windk/win_sdk/Include/10.0.14393.0/ucrt",
80 "$windk/win_sdk/Include/10.0.14393.0/um",
Brian Osman21d742d2017-01-10 13:31:33 -050081 "$windk/win_sdk/Include/10.0.14393.0/winrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040082 ]
Mike Klein98adfa82017-07-31 15:46:47 -040083 if (is_clang) {
84 foreach(dir, _include_dirs) {
85 cflags += [
86 "-imsvc",
87 dir,
88 ]
89 }
90 } else {
91 include_dirs = _include_dirs
92 }
93
Mike Klein3eb71212016-10-11 17:08:53 -040094 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040095 # For local builds.
Ben Wagner4e8472c2017-03-20 16:53:05 -040096 # 2017
97 "$windk/../../../Windows Kits/10/Lib/10.0.14393.0/ucrt/$target_cpu",
98 "$windk/../../../Windows Kits/10/Lib/10.0.14393.0/um/$target_cpu",
99
100 #2015
Mike Klein0bc5a762016-10-12 22:42:55 -0400101 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
102 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -0400103
Mike Kleind3016832016-10-12 15:52:44 -0400104 # For builds using win_toolchain asset.
Brian Osman3f289332017-01-10 10:38:23 -0500105 "$windk/win_sdk/Lib/10.0.14393.0/ucrt/$target_cpu",
106 "$windk/win_sdk/Lib/10.0.14393.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -0400107 ]
Ben Wagner4e8472c2017-03-20 16:53:05 -0400108
109 #2017
110 lib_dirs += [ "$windk/VC/Tools/MSVC/14.10.25017/lib/$target_cpu" ]
111
112 #2015
Mike Klein0bc5a762016-10-12 22:42:55 -0400113 if (target_cpu == "x86") {
114 lib_dirs += [ "$windk/VC/lib" ]
115 } else {
116 lib_dirs += [ "$windk/VC/lib/amd64" ]
117 }
mtkleinb9be9792016-09-16 14:44:18 -0700118 } else {
119 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700120 "-fstrict-aliasing",
121 "-fPIC",
herbb6318bf2016-09-16 13:29:57 -0700122 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700123 ]
Mike Klein28f5b772017-04-06 23:04:42 -0400124 cflags_cc += [ "-std=c++11" ]
Mike Kleineec23d12017-03-26 20:11:48 -0400125
126 # The main idea is to slim the exported API, but these flags also improve link time on Mac.
127 # These would make stack traces worse on Linux, so we don't just set them willy-nilly.
Mike Klein8cb66482017-03-28 14:16:22 -0400128 if (is_component_build || is_ios || is_mac) {
Mike Kleineec23d12017-03-26 20:11:48 -0400129 cflags += [ "-fvisibility=hidden" ]
130 cflags_cc += [ "-fvisibility-inlines-hidden" ]
131 }
mtkleinb9be9792016-09-16 14:44:18 -0700132 }
herbb6318bf2016-09-16 13:29:57 -0700133
mtkleinb9be9792016-09-16 14:44:18 -0700134 if (current_cpu == "arm") {
135 cflags += [
136 "-march=armv7-a",
137 "-mfpu=neon",
138 "-mthumb",
139 ]
140 } else if (current_cpu == "mipsel") {
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400141 cflags += [ "-march=mips32r2" ]
142 } else if (current_cpu == "mips64el") {
143 asmflags += [ "-integrated-as" ]
144 cflags += [ "-integrated-as" ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400145 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700146 asmflags += [ "-m32" ]
147 cflags += [
148 "-m32",
149 "-msse2",
150 "-mfpmath=sse",
151 ]
152 ldflags += [ "-m32" ]
153 }
herbb6318bf2016-09-16 13:29:57 -0700154
Herb Derby76073c12016-12-08 19:00:40 -0500155 if (malloc != "" && !is_win) {
156 cflags += [
157 "-fno-builtin-malloc",
158 "-fno-builtin-calloc",
159 "-fno-builtin-realloc",
160 "-fno-builtin-free",
161 ]
162 libs += [ malloc ]
163 }
164
mtkleinb9be9792016-09-16 14:44:18 -0700165 if (is_android) {
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400166 asmflags += [ "--target=$ndk_target" ]
mtkleinb9be9792016-09-16 14:44:18 -0700167 cflags += [
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400168 "--sysroot=$ndk/sysroot",
169 "-isystem$ndk/sysroot/usr/include/$ndk_target",
170 "-D__ANDROID_API__=$ndk_api",
mtkleinb9be9792016-09-16 14:44:18 -0700171 "--target=$ndk_target",
mtkleinb9be9792016-09-16 14:44:18 -0700172 ]
173 cflags_cc += [
174 "-isystem$ndk/sources/android/support/include",
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500175 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/include",
176 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib/include",
mtkleinb9be9792016-09-16 14:44:18 -0700177 ]
178 ldflags += [
179 "--sysroot=$ndk/platforms/$ndk_platform",
180 "--target=$ndk_target",
181 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700182 ]
183 lib_dirs = [
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500184 "$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib",
mtkleinb9be9792016-09-16 14:44:18 -0700185 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
186 ]
herbb6318bf2016-09-16 13:29:57 -0700187
Mike Klein4fdc5432016-10-11 11:21:36 -0400188 if (current_cpu == "mips64el") {
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400189 # The r15b NDK deployed on our bots fails to find /usr/lib64 in the
190 # MIPS64 sysroots, so we must point Clang at /usr/lib64 manually.
Mike Klein4fdc5432016-10-11 11:21:36 -0400191 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein978cceb2016-12-08 10:29:27 -0500192 ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein4fdc5432016-10-11 11:21:36 -0400193 }
194
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500195 libs += [ "gnustl_static" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700196 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700197
Mike Klein7d302882016-11-03 14:06:31 -0400198 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500199 _target = target_cpu
200 if (target_cpu == "arm") {
201 _target = "armv7"
Mike Klein7a5e0f32017-03-13 09:25:33 -0700202 } else if (target_cpu == "x86") {
203 _target = "i386"
204 } else if (target_cpu == "x64") {
205 _target = "x86_64"
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500206 }
Mike Klein4fe2b152017-02-17 15:36:01 -0500207 asmflags += [
208 "-isysroot",
209 ios_sysroot,
210 "-arch",
211 _target,
212 ]
Mike Klein7d302882016-11-03 14:06:31 -0400213 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500214 "-isysroot",
215 ios_sysroot,
216 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500217 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400218 ]
219 cflags_cc += [ "-stdlib=libc++" ]
220 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500221 "-isysroot",
222 ios_sysroot,
223 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500224 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400225 "-stdlib=libc++",
226 ]
Herb Derby76073c12016-12-08 19:00:40 -0500227 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400228 }
229
mtkleinb9be9792016-09-16 14:44:18 -0700230 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500231 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700232 }
233
234 if (sanitize != "") {
235 # You can either pass the sanitizers directly, e.g. "address,undefined",
236 # or pass one of the couple common aliases used by the bots.
237 sanitizers = sanitize
238 if (sanitize == "ASAN") {
Ben Wagnerbee6cac2017-12-04 11:15:58 -0500239 sanitizers = "address,bool,float-cast-overflow,integer-divide-by-zero,nonnull-attribute,null,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
Mike Kleine4781e92017-09-28 11:42:28 -0400240 if (!is_mac) {
Mike Klein46d6c682017-10-05 11:22:09 -0400241 sanitizers += ",function" # Not supported on Mac.
242 }
243 if (!is_debug) {
244 sanitizers += ",object-size" # No-op with somewhat annoying warning at -O0.
Mike Kleine4781e92017-09-28 11:42:28 -0400245 }
mtkleinb9be9792016-09-16 14:44:18 -0700246 } else if (sanitize == "TSAN") {
247 sanitizers = "thread"
248 } else if (sanitize == "MSAN") {
249 sanitizers = "memory"
250 }
251
252 cflags += [
253 "-fsanitize=$sanitizers",
254 "-fno-sanitize-recover=$sanitizers",
255 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
256 ]
257 ldflags += [ "-fsanitize=$sanitizers" ]
258 if (sanitizers == "memory") {
259 cflags += [ "-fsanitize-memory-track-origins" ]
260 cflags_cc += [ "-stdlib=libc++" ]
261 ldflags += [ "-stdlib=libc++" ]
262 }
263 }
264}
265
Mike Klein6e55fef2016-10-26 11:41:47 -0400266config("no_exceptions") {
Mike Klein228276d2017-08-16 13:20:20 +0000267 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
Mike Klein6e55fef2016-10-26 11:41:47 -0400268 if (!is_win) {
269 cflags_cc = [ "-fno-exceptions" ]
270 }
271}
272
Mike Kleinc7165c22016-10-12 23:58:06 -0400273config("warnings") {
274 cflags = []
275 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400276 cflags_objc = []
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400277 cflags_objcc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400278 if (is_win) {
279 cflags += [
280 "/W3", # Turn on lots of warnings.
281
282 # Disable a bunch of warnings:
283 "/wd4244", # conversion from 'float' to 'int', possible loss of data
284 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
285 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
286
287 # Probably only triggers when /EHsc is enabled.
288 "/wd4291", # no matching operator delete found;
289 # memory will not be freed if initialization throws an exception
290 ]
291 } else {
292 cflags += [
293 "-Wall",
294 "-Wextra",
295 "-Winit-self",
296 "-Wpointer-arith",
297 "-Wsign-compare",
298 "-Wvla",
299
300 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500301 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400302 ]
303 cflags_cc += [ "-Wnon-virtual-dtor" ]
Chris Dalton1ef80942017-12-04 12:01:30 -0700304 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400305
Chris Dalton1ef80942017-12-04 12:01:30 -0700306 if (is_clang) {
307 cflags += [
308 "-Weverything",
309 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
310 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400311
Chris Dalton1ef80942017-12-04 12:01:30 -0700312 if (target_cpu == "arm" && is_ios) {
313 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS.
314 # We're pretty sure it's actually 8-byte alignment.
315 cflags += [ "-Wno-over-aligned" ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400316 }
Chris Dalton1ef80942017-12-04 12:01:30 -0700317
318 # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose
319 # their case during copy, causing case-sensitivity mismatch on remote machines.
320 cflags += [
321 "-Wno-nonportable-include-path",
322 "-Wno-nonportable-system-include-path",
323 ]
324
325 # TODO: These would all be really great warnings to turn on.
326 cflags += [
327 "-Wno-cast-align",
328 "-Wno-cast-qual",
329 "-Wno-conditional-uninitialized",
330 "-Wno-conversion",
331 "-Wno-disabled-macro-expansion",
332 "-Wno-documentation",
333 "-Wno-documentation-unknown-command",
334 "-Wno-double-promotion",
335 "-Wno-exit-time-destructors", # TODO: OK outside libskia
336 "-Wno-float-conversion",
337 "-Wno-float-equal",
338 "-Wno-format-nonliteral",
339 "-Wno-global-constructors", # TODO: OK outside libskia
340 "-Wno-gnu-zero-variadic-macro-arguments",
341 "-Wno-missing-prototypes",
342 "-Wno-missing-variable-declarations",
343 "-Wno-pedantic",
344 "-Wno-reserved-id-macro",
345 "-Wno-shadow",
346 "-Wno-shift-sign-overflow",
347 "-Wno-sign-conversion",
348 "-Wno-signed-enum-bitfield",
349 "-Wno-switch-enum",
350 "-Wno-undef",
351 "-Wno-unreachable-code",
352 "-Wno-unreachable-code-break",
353 "-Wno-unreachable-code-return",
354 "-Wno-unused-macros",
355 "-Wno-unused-member-function",
356 "-Wno-unused-template",
357 "-Wno-zero-as-null-pointer-constant",
358 ]
359 cflags_cc += [
360 "-Wno-abstract-vbase-init",
361 "-Wno-weak-vtables",
362 ]
363
364 # We are unlikely to want to fix these.
365 cflags += [
366 "-Wno-covered-switch-default",
367 "-Wno-deprecated",
368 "-Wno-implicit-fallthrough",
369 "-Wno-missing-noreturn",
370 "-Wno-old-style-cast",
371 "-Wno-padded",
Chris Daltond1ec4102017-12-04 13:31:21 -0700372 "-Wno-newline-eof",
Chris Dalton1ef80942017-12-04 12:01:30 -0700373 ]
374 cflags_cc += [
375 "-Wno-c++98-compat",
376 "-Wno-c++98-compat-pedantic",
377 "-Wno-undefined-func-template",
378 ]
379 cflags_objc += [
380 "-Wno-direct-ivar-access",
381 "-Wno-objc-interface-ivars",
382 ]
383 cflags_objcc += [
384 "-Wno-direct-ivar-access",
385 "-Wno-objcc-interface-ivars",
386 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400387 }
388}
Mike Klein50500ad2016-11-16 12:13:44 -0500389config("warnings_except_public_headers") {
Chris Dalton1ef80942017-12-04 12:01:30 -0700390 if (!is_win || is_clang) {
Mike Klein50500ad2016-11-16 12:13:44 -0500391 cflags = [ "-Wno-unused-parameter" ]
392 }
393}
Mike Kleinc7165c22016-10-12 23:58:06 -0400394
Mike Klein121563e2016-10-04 17:09:13 -0400395config("extra_flags") {
Kevin Lubick2677a9a2017-03-28 15:45:41 -0400396 asmflags = extra_asmflags
Mike Klein121563e2016-10-04 17:09:13 -0400397 cflags = extra_cflags
398 cflags_c = extra_cflags_c
399 cflags_cc = extra_cflags_cc
400 ldflags = extra_ldflags
401}
402
mtkleinb9be9792016-09-16 14:44:18 -0700403config("debug_symbols") {
404 # It's annoying to wait for full debug symbols to push over
405 # to Android devices. -gline-tables-only is a lot slimmer.
406 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400407 cflags = [
408 "-gline-tables-only",
409 "-funwind-tables", # Helps make in-process backtraces fuller.
410 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400411 } else if (is_win) {
412 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400413 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400414 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700415 cflags = [ "-g" ]
416 }
417}
418
419config("no_rtti") {
420 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400421 if (is_win) {
422 cflags_cc = [ "/GR-" ]
423 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700424 cflags_cc = [ "-fno-rtti" ]
425 }
426 }
427}
428
429config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400430 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400431 cflags = [
432 "/O2",
433 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400434 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400435 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400436 ldflags = [
437 "/OPT:ICF",
438 "/OPT:REF",
439 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400440 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400441 cflags = [
442 "-O3",
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500443 "-fdata-sections",
444 "-ffunction-sections",
Mike Klein0bcfeac2016-10-19 22:24:10 -0400445 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500446 if (is_mac || is_ios) {
447 ldflags = [ "-dead_strip" ]
448 } else {
449 ldflags = [ "-Wl,--gc-sections" ]
450 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400451 if (target_cpu == "wasm") {
452 # The compiler asks us to add an optimization flag to both cflags
453 # and ldflags to cut down on the local variables,
454 # for performance reasons.
455 # The "linking" step is the conversion to javascript.
456 ldflags += [ "-O3" ]
457 }
herbb6318bf2016-09-16 13:29:57 -0700458 }
mtkleinb9be9792016-09-16 14:44:18 -0700459 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700460}
461
462config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500463 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400464 ldflags = [
465 "-pie",
466 "-rdynamic",
467 ]
Mike Kleinc5875fb2016-12-06 10:46:02 -0500468 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700469 ldflags = [ "-Wl,-rpath,@loader_path/." ]
470 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700471 ldflags = [
472 "-rdynamic",
473 "-Wl,-rpath,\$ORIGIN",
474 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500475 } else if (is_win) {
476 ldflags = [
477 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
478 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
479 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700480 }
481}