blob: 9b3288a4845494c32cc55212c625f5bf039247bd [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++"
15 }
16
Mike Klein0f61faa2016-10-11 16:26:57 -040017 windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0"
herbb6318bf2016-09-16 13:29:57 -070018
Mike Klein121563e2016-10-04 17:09:13 -040019 extra_cflags = []
20 extra_cflags_c = []
21 extra_cflags_cc = []
22 extra_ldflags = []
mtkleincab0bb72016-08-26 13:43:19 -070023
mtklein60b7ab72016-09-20 12:09:12 -070024 cc_wrapper = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070025}
26
Mike Klein461d3282016-10-11 13:51:55 -040027if (!is_win) {
28 is_clang = exec_script("is_clang.py",
29 [
30 cc,
31 cxx,
32 ],
33 "value")
34}
mtkleinf347c512016-09-26 08:40:12 -070035
mtkleinb9be9792016-09-16 14:44:18 -070036config("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.
herbb6318bf2016-09-16 13:29:57 -070047 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040048 "/WX", # Treat warnings as errors.
herbb6318bf2016-09-16 13:29:57 -070049 ]
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 Klein0f61faa2016-10-11 16:26:57 -040056 include_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040057 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -040058
Mike Kleind3016832016-10-12 15:52:44 -040059 # For local builds.
Mike Klein0f61faa2016-10-11 16:26:57 -040060 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein0f61faa2016-10-11 16:26:57 -040061 "$windk/../Windows Kits/8.1/Include/shared",
Mike Klein3eb71212016-10-11 17:08:53 -040062 "$windk/../Windows Kits/8.1/Include/um",
Mike Kleincc300a12016-10-12 16:25:27 -040063
Mike Kleind3016832016-10-12 15:52:44 -040064 # 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 Klein0f61faa2016-10-11 16:26:57 -040068 ]
Mike Klein3eb71212016-10-11 17:08:53 -040069 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -040070 # For local builds.
Mike Klein0bc5a762016-10-12 22:42:55 -040071 "$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 Kleincc300a12016-10-12 16:25:27 -040073
Mike Kleind3016832016-10-12 15:52:44 -040074 # For builds using win_toolchain asset.
Mike Klein0bc5a762016-10-12 22:42:55 -040075 "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu",
76 "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -040077 ]
Mike Klein0bc5a762016-10-12 22:42:55 -040078 if (target_cpu == "x86") {
79 lib_dirs += [ "$windk/VC/lib" ]
80 } else {
81 lib_dirs += [ "$windk/VC/lib/amd64" ]
82 }
mtkleinb9be9792016-09-16 14:44:18 -070083 } else {
84 cflags += [
herbb6318bf2016-09-16 13:29:57 -070085 "-O1",
86 "-fstrict-aliasing",
87 "-fPIC",
88 "-fvisibility=hidden",
herbb6318bf2016-09-16 13:29:57 -070089 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -070090 ]
mtkleinb9be9792016-09-16 14:44:18 -070091 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -070092 "-std=c++11",
93 "-fno-exceptions",
94 "-fno-threadsafe-statics",
95 "-fvisibility-inlines-hidden",
herbb6318bf2016-09-16 13:29:57 -070096 ]
mtkleinb9be9792016-09-16 14:44:18 -070097 }
herbb6318bf2016-09-16 13:29:57 -070098
mtkleinb9be9792016-09-16 14:44:18 -070099 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 Klein5d8cf292016-10-12 19:36:09 -0400110 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700111 asmflags += [ "-m32" ]
112 cflags += [
113 "-m32",
114 "-msse2",
115 "-mfpmath=sse",
116 ]
117 ldflags += [ "-m32" ]
118 }
herbb6318bf2016-09-16 13:29:57 -0700119
mtkleinb9be9792016-09-16 14:44:18 -0700120 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 Klein4fdc5432016-10-11 11:21:36 -0400132 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
133 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
mtkleinb9be9792016-09-16 14:44:18 -0700134 ]
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 ]
herbb6318bf2016-09-16 13:29:57 -0700145
Mike Klein4fdc5432016-10-11 11:21:36 -0400146 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
mtkleinb9be9792016-09-16 14:44:18 -0700159 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" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700167 }
168 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700169
mtkleinb9be9792016-09-16 14:44:18 -0700170 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 Kleinc7165c22016-10-12 23:58:06 -0400200config("warnings") {
201 cflags = []
202 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400203 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400204 if (is_win) {
205 cflags += [
206 "/W3", # Turn on lots of warnings.
207
208 # Disable a bunch of warnings:
209 "/wd4244", # conversion from 'float' to 'int', possible loss of data
210 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
211 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
212
213 # Probably only triggers when /EHsc is enabled.
214 "/wd4291", # no matching operator delete found;
215 # memory will not be freed if initialization throws an exception
216 ]
217 } else {
218 cflags += [
219 "-Wall",
220 "-Wextra",
221 "-Winit-self",
222 "-Wpointer-arith",
223 "-Wsign-compare",
224 "-Wvla",
225
226 "-Wno-deprecated-declarations",
227 "-Wno-unused-parameter",
228 ]
229 cflags_cc += [ "-Wnon-virtual-dtor" ]
230
231 if (is_clang) {
232 cflags += [
233 "-Weverything",
234 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
235 ]
236
237 if (is_android && target_cpu == "x86") {
238 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
239 # We're pretty sure it's actually 8-byte alignment.
240 cflags += [ "-Wno-over-aligned" ]
241 }
242
243 cflags += [
244 "-Wno-cast-align",
245 "-Wno-conditional-uninitialized",
246 "-Wno-conversion",
247 "-Wno-disabled-macro-expansion",
248 "-Wno-documentation",
249 "-Wno-documentation-unknown-command",
250 "-Wno-double-promotion",
251 "-Wno-exit-time-destructors", # TODO: OK outside libskia
252 "-Wno-float-conversion",
253 "-Wno-float-equal",
254 "-Wno-format-nonliteral",
255 "-Wno-global-constructors", # TODO: OK outside libskia
256 "-Wno-gnu-zero-variadic-macro-arguments",
257 "-Wno-missing-prototypes",
258 "-Wno-missing-variable-declarations",
259 "-Wno-pedantic",
260 "-Wno-reserved-id-macro",
261 "-Wno-shadow",
262 "-Wno-shift-sign-overflow",
263 "-Wno-sign-conversion",
264 "-Wno-switch-enum",
265 "-Wno-undef",
266 "-Wno-unreachable-code",
267 "-Wno-unreachable-code-break",
268 "-Wno-unreachable-code-return",
269 "-Wno-unused-macros",
270 "-Wno-unused-member-function",
271 ]
272 cflags_cc += [
273 "-Wno-abstract-vbase-init",
274 "-Wno-range-loop-analysis",
275 "-Wno-weak-vtables",
276 ]
277
278 # We are unlikely to want to fix these.
279 cflags += [
280 "-Wno-covered-switch-default",
281 "-Wno-deprecated",
282 "-Wno-implicit-fallthrough",
283 "-Wno-missing-noreturn",
284 "-Wno-old-style-cast",
285 "-Wno-padded",
286 ]
287 cflags_cc += [
288 "-Wno-c++98-compat",
289 "-Wno-c++98-compat-pedantic",
290 "-Wno-undefined-func-template",
291 ]
Mike Klein43c25262016-10-20 10:17:47 -0400292 cflags_objc += [
293 "-Wno-direct-ivar-access",
294 "-Wno-objc-interface-ivars",
295 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400296 }
297 }
298}
299
Mike Klein121563e2016-10-04 17:09:13 -0400300config("extra_flags") {
301 cflags = extra_cflags
302 cflags_c = extra_cflags_c
303 cflags_cc = extra_cflags_cc
304 ldflags = extra_ldflags
305}
306
mtkleinb9be9792016-09-16 14:44:18 -0700307config("debug_symbols") {
308 # It's annoying to wait for full debug symbols to push over
309 # to Android devices. -gline-tables-only is a lot slimmer.
310 if (is_android) {
311 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400312 } else if (is_win) {
313 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400314 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400315 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700316 cflags = [ "-g" ]
317 }
318}
319
320config("no_rtti") {
321 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400322 if (is_win) {
323 cflags_cc = [ "/GR-" ]
324 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700325 cflags_cc = [ "-fno-rtti" ]
326 }
327 }
328}
329
330config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400331 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400332 cflags = [
333 "/O2",
334 "/Zc:inline",
335 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400336 ldflags = [
337 "/OPT:ICF",
338 "/OPT:REF",
339 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400340 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400341 cflags = [
342 "-O3",
343 "-momit-leaf-frame-pointer",
344 ]
herbb6318bf2016-09-16 13:29:57 -0700345 }
mtkleinb9be9792016-09-16 14:44:18 -0700346 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700347}
348
349config("executable") {
350 if (is_mac) {
351 ldflags = [ "-Wl,-rpath,@loader_path/." ]
352 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700353 ldflags = [
354 "-rdynamic",
355 "-Wl,-rpath,\$ORIGIN",
356 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700357 }
358}
359
herbb6318bf2016-09-16 13:29:57 -0700360toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400361 lib_dir_switch = "/LIBPATH:"
362
Mike Klein0bc5a762016-10-12 22:42:55 -0400363 bin = "$windk/VC/bin/amd64"
364 env_setup = ""
365 if (target_cpu == "x86") {
366 bin += "_x86"
367 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
368 }
herbb6318bf2016-09-16 13:29:57 -0700369
370 tool("cc") {
371 rspfile = "{{output}}.rsp"
372 precompiled_header_type = "msvc"
373 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
374
Mike Klein0f61faa2016-10-11 16:26:57 -0400375 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400376 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700377 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700378 outputs = [
379 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700380 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400381 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400382 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700383 }
384
385 tool("cxx") {
386 rspfile = "{{output}}.rsp"
387 precompiled_header_type = "msvc"
388 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
389
Mike Klein0f61faa2016-10-11 16:26:57 -0400390 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400391 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700392 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700393 outputs = [
394 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
395 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400396 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400397 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700398 }
herbb6318bf2016-09-16 13:29:57 -0700399
400 tool("alink") {
401 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700402
Mike Kleinc756e862016-10-13 14:31:01 -0400403 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700404 outputs = [
405 # Ignore {{output_extension}} and always use .lib, there's no reason to
406 # allow targets to override this extension on Windows.
407 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
408 ]
409 default_output_extension = ".lib"
410 default_output_dir = "{{target_out_dir}}"
411
Mike Klein0f61faa2016-10-11 16:26:57 -0400412 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700413 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400414 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700415 }
416
Mike Klein1a8d6752016-10-17 11:51:11 -0400417 tool("solink") {
418 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
419 libname = "${dllname}.lib"
420 pdbname = "${dllname}.pdb"
421 rspfile = "${dllname}.rsp"
422
423 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
424 outputs = [
425 dllname,
426 libname,
427 pdbname,
428 ]
429 default_output_extension = ".dll"
430 default_output_dir = "{{root_out_dir}}"
431
432 link_output = libname
433 depend_output = libname
434 runtime_outputs = [
435 dllname,
436 pdbname,
437 ]
438
439 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
440 restat = true
441
442 # inputs_newline works around a fixed per-line buffer size in the linker.
443 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
444 description = "link {{output}}"
445 }
446
herbb6318bf2016-09-16 13:29:57 -0700447 tool("link") {
448 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
449 pdbname = "$exename.pdb"
450 rspfile = "$exename.rsp"
451
Mike Klein0bc5a762016-10-12 22:42:55 -0400452 command =
453 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700454
455 default_output_extension = ".exe"
456 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700457 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700458 exename,
459 ]
mtkleinb9be9792016-09-16 14:44:18 -0700460
Mike Klein0f61faa2016-10-11 16:26:57 -0400461 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700462 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400463 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700464 }
465
herbb6318bf2016-09-16 13:29:57 -0700466 tool("stamp") {
Mike Kleind3016832016-10-12 15:52:44 -0400467 command = "cmd.exe /c echo > {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400468 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700469 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400470
471 tool("copy") {
472 cp_py = rebase_path("cp.py")
Mike Klein5bab65b2016-10-17 13:07:56 -0400473 command = "python.bat $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400474 description = "copy {{source}} {{output}}"
475 }
herbb6318bf2016-09-16 13:29:57 -0700476}
477
mtklein7fbfbbe2016-07-21 12:25:45 -0700478toolchain("gcc_like") {
479 lib_switch = "-l"
480 lib_dir_switch = "-L"
481
482 tool("cc") {
483 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400484 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700485 depsformat = "gcc"
486 outputs = [
487 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
488 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400489 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700490 }
491
492 tool("cxx") {
493 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400494 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700495 depsformat = "gcc"
496 outputs = [
497 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
498 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400499 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700500 }
501
Mike Klein43c25262016-10-20 10:17:47 -0400502 tool("objc") {
503 depfile = "{{output}}.d"
504 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
505 depsformat = "gcc"
506 outputs = [
507 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
508 ]
509 description = "compile {{source}}"
510 }
511
512 tool("objcxx") {
513 depfile = "{{output}}.d"
514 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
515 depsformat = "gcc"
516 outputs = [
517 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
518 ]
519 description = "compile {{source}}"
520 }
521
mtklein7fbfbbe2016-07-21 12:25:45 -0700522 tool("asm") {
523 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700524 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700525 depsformat = "gcc"
526 outputs = [
527 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
528 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400529 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700530 }
531
532 tool("alink") {
mtklein349cece2016-08-26 08:13:04 -0700533 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700534 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700535 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700536 ]
537 default_output_extension = ".a"
538 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400539 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700540 }
541
542 tool("solink") {
543 soname = "{{target_output_name}}{{output_extension}}"
544
545 rpath = "-Wl,-soname,$soname"
546 if (is_mac) {
547 rpath = "-Wl,-install_name,@rpath/$soname"
548 }
549
Mike Klein121563e2016-10-04 17:09:13 -0400550 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700551 outputs = [
552 "{{root_out_dir}}/$soname",
553 ]
554 output_prefix = "lib"
555 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400556 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700557 }
558
559 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400560 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700561 outputs = [
562 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
563 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400564 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700565 }
566
567 tool("stamp") {
568 command = "touch {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400569 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700570 }
571
572 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400573 cp_py = rebase_path("cp.py")
574 command = "python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400575 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700576 }
577}