blob: 5d6a82ae38864bda6cafd8ae3fba12a64cef15fa [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) {
332 cflags = [ "/O2" ]
333 } else {
herbb6318bf2016-09-16 13:29:57 -0700334 cflags = [ "-O3" ]
herbb6318bf2016-09-16 13:29:57 -0700335 }
mtkleinb9be9792016-09-16 14:44:18 -0700336 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700337}
338
339config("executable") {
340 if (is_mac) {
341 ldflags = [ "-Wl,-rpath,@loader_path/." ]
342 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700343 ldflags = [
344 "-rdynamic",
345 "-Wl,-rpath,\$ORIGIN",
346 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700347 }
348}
349
herbb6318bf2016-09-16 13:29:57 -0700350toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400351 lib_dir_switch = "/LIBPATH:"
352
Mike Klein0bc5a762016-10-12 22:42:55 -0400353 bin = "$windk/VC/bin/amd64"
354 env_setup = ""
355 if (target_cpu == "x86") {
356 bin += "_x86"
357 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
358 }
herbb6318bf2016-09-16 13:29:57 -0700359
360 tool("cc") {
361 rspfile = "{{output}}.rsp"
362 precompiled_header_type = "msvc"
363 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
364
Mike Klein0f61faa2016-10-11 16:26:57 -0400365 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400366 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700367 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700368 outputs = [
369 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700370 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400371 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400372 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700373 }
374
375 tool("cxx") {
376 rspfile = "{{output}}.rsp"
377 precompiled_header_type = "msvc"
378 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
379
Mike Klein0f61faa2016-10-11 16:26:57 -0400380 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400381 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700382 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700383 outputs = [
384 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
385 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400386 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400387 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700388 }
herbb6318bf2016-09-16 13:29:57 -0700389
390 tool("alink") {
391 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700392
Mike Kleinc756e862016-10-13 14:31:01 -0400393 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700394 outputs = [
395 # Ignore {{output_extension}} and always use .lib, there's no reason to
396 # allow targets to override this extension on Windows.
397 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
398 ]
399 default_output_extension = ".lib"
400 default_output_dir = "{{target_out_dir}}"
401
Mike Klein0f61faa2016-10-11 16:26:57 -0400402 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700403 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400404 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700405 }
406
Mike Klein1a8d6752016-10-17 11:51:11 -0400407 tool("solink") {
408 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
409 libname = "${dllname}.lib"
410 pdbname = "${dllname}.pdb"
411 rspfile = "${dllname}.rsp"
412
413 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
414 outputs = [
415 dllname,
416 libname,
417 pdbname,
418 ]
419 default_output_extension = ".dll"
420 default_output_dir = "{{root_out_dir}}"
421
422 link_output = libname
423 depend_output = libname
424 runtime_outputs = [
425 dllname,
426 pdbname,
427 ]
428
429 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
430 restat = true
431
432 # inputs_newline works around a fixed per-line buffer size in the linker.
433 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
434 description = "link {{output}}"
435 }
436
herbb6318bf2016-09-16 13:29:57 -0700437 tool("link") {
438 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
439 pdbname = "$exename.pdb"
440 rspfile = "$exename.rsp"
441
Mike Klein0bc5a762016-10-12 22:42:55 -0400442 command =
443 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700444
445 default_output_extension = ".exe"
446 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700447 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700448 exename,
449 ]
mtkleinb9be9792016-09-16 14:44:18 -0700450
Mike Klein0f61faa2016-10-11 16:26:57 -0400451 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700452 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400453 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700454 }
455
herbb6318bf2016-09-16 13:29:57 -0700456 tool("stamp") {
Mike Kleind3016832016-10-12 15:52:44 -0400457 command = "cmd.exe /c echo > {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400458 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700459 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400460
461 tool("copy") {
462 cp_py = rebase_path("cp.py")
Mike Klein5bab65b2016-10-17 13:07:56 -0400463 command = "python.bat $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400464 description = "copy {{source}} {{output}}"
465 }
herbb6318bf2016-09-16 13:29:57 -0700466}
467
mtklein7fbfbbe2016-07-21 12:25:45 -0700468toolchain("gcc_like") {
469 lib_switch = "-l"
470 lib_dir_switch = "-L"
471
472 tool("cc") {
473 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400474 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700475 depsformat = "gcc"
476 outputs = [
477 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
478 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400479 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700480 }
481
482 tool("cxx") {
483 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400484 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -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
Mike Klein43c25262016-10-20 10:17:47 -0400492 tool("objc") {
493 depfile = "{{output}}.d"
494 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
495 depsformat = "gcc"
496 outputs = [
497 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
498 ]
499 description = "compile {{source}}"
500 }
501
502 tool("objcxx") {
503 depfile = "{{output}}.d"
504 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{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
mtklein7fbfbbe2016-07-21 12:25:45 -0700512 tool("asm") {
513 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700514 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700515 depsformat = "gcc"
516 outputs = [
517 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
518 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400519 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700520 }
521
522 tool("alink") {
mtklein349cece2016-08-26 08:13:04 -0700523 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700524 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700525 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700526 ]
527 default_output_extension = ".a"
528 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400529 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700530 }
531
532 tool("solink") {
533 soname = "{{target_output_name}}{{output_extension}}"
534
535 rpath = "-Wl,-soname,$soname"
536 if (is_mac) {
537 rpath = "-Wl,-install_name,@rpath/$soname"
538 }
539
Mike Klein121563e2016-10-04 17:09:13 -0400540 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700541 outputs = [
542 "{{root_out_dir}}/$soname",
543 ]
544 output_prefix = "lib"
545 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400546 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700547 }
548
549 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400550 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700551 outputs = [
552 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
553 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400554 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700555 }
556
557 tool("stamp") {
558 command = "touch {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400559 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700560 }
561
562 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400563 cp_py = rebase_path("cp.py")
564 command = "python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400565 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700566 }
567}