1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # TODO(brettw) Use "gcc_toolchain.gni" like the Linux toolchains. This requires
6 # some enhancements since the commands on Mac are slightly different than on
10 import("//build/config/ios/ios_sdk.gni")
12 assert(host_os == "mac")
14 import("//build/toolchain/clang.gni")
15 import("//build/toolchain/goma.gni")
18 goma_prefix = "$goma_dir/gomacc "
23 # This will copy the gyp-mac-tool to the build directory. We pass in the source
24 # file of the win tool.
26 rebase_path("//tools/gyp/pylib/gyp/mac_tool.py", root_build_dir)
27 exec_script("setup_toolchain.py", [ gyp_mac_tool_source ])
29 # Shared toolchain definition. Invocations should set toolchain_os to set the
30 # build args in this definition.
31 template("mac_toolchain") {
32 toolchain(target_name) {
33 assert(defined(invoker.cc), "mac_toolchain() must specify a \"cc\" value")
34 assert(defined(invoker.cxx), "mac_toolchain() must specify a \"cxx\" value")
35 assert(defined(invoker.ld), "mac_toolchain() must specify a \"ld\" value")
36 assert(defined(invoker.toolchain_cpu),
37 "mac_toolchain() must specify a \"toolchain_cpu\"")
38 assert(defined(invoker.toolchain_os),
39 "mac_toolchain() must specify a \"toolchain_os\"")
41 # We can't do string interpolation ($ in strings) on things with dots in
42 # them. To allow us to use $cc below, for example, we create copies of
43 # these values in our scope.
48 # Make these apply to all tools below.
53 depfile = "{{output}}.d"
54 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
56 description = "CC {{output}}"
58 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
63 depfile = "{{output}}.d"
64 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
66 description = "CXX {{output}}"
68 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
73 # For GCC we can just use the C compiler to compile assembly.
74 depfile = "{{output}}.d"
75 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
77 description = "ASM {{output}}"
79 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
84 depfile = "{{output}}.d"
85 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} -c {{source}} -o {{output}}"
87 description = "OBJC {{output}}"
89 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
94 depfile = "{{output}}.d"
95 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
97 description = "OBJCXX {{output}}"
99 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
104 command = "rm -f {{output}} && ./gyp-mac-tool filter-libtool libtool -static -o {{output}} {{inputs}}"
105 description = "LIBTOOL-STATIC {{output}}"
107 "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
109 default_output_extension = ".a"
110 output_prefix = "lib"
114 dylib = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # eg "./libfoo.dylib"
115 rspfile = dylib + ".rsp"
117 # These variables are not built into GN but are helpers that implement
118 # (1) linking to produce a .so, (2) extracting the symbols from that file
119 # to a temporary file, (3) if the temporary file has differences from the
120 # existing .TOC file, overwrite it, oterwise, don't change it.
122 # As a special case, if the library reexports symbols from other dynamic
123 # libraries, we always update the .TOC and skip the temporary file and
124 # diffing steps, since that library always needs to be re-linked.
125 tocname = dylib + ".TOC"
126 temporary_tocname = dylib + ".tmp"
128 does_reexport_command = "[ ! -e $dylib -o ! -e $tocname ] || otool -l $dylib | grep -q LC_REEXPORT_DYLIB"
129 link_command = "$ld -shared {{ldflags}} -o $dylib -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
130 replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $temporary_tocname $tocname"
131 extract_toc_command = "{ otool -l $dylib | grep LC_ID_DYLIB -A 5; nm -gP $dylib | cut -f1-2 -d' ' | grep -v U\$\$; true; }"
133 command = "if $does_reexport_command ; then $link_command && $extract_toc_command > $tocname; else $link_command && $extract_toc_command > $temporary_tocname && $replace_command ; fi; fi"
135 rspfile_content = "{{inputs_newline}}"
137 description = "SOLINK {{output}}"
139 # Use this for {{output_extension}} expansions unless a target manually
140 # overrides it (in which case {{output_extension}} will be what the target
142 default_output_extension = ".dylib"
144 output_prefix = "lib"
146 # Since the above commands only updates the .TOC file when it changes, ask
147 # Ninja to check if the timestamp actually changed to know if downstream
148 # dependencies should be recompiled.
151 # Tell GN about the output files. It will link to the dylib but use the
152 # tocname for dependency management.
158 depend_output = tocname
162 outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
163 rspfile = "$outfile.rsp"
164 command = "$ld {{ldflags}} -o $outfile -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
165 description = "LINK $outfile"
166 rspfile_content = "{{inputs_newline}}"
173 command = "touch {{output}}"
174 description = "STAMP {{output}}"
178 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
179 description = "COPY {{source}} {{output}}"
183 current_cpu = invoker.toolchain_cpu
184 current_os = invoker.toolchain_os
186 # These values need to be passed through unchanged.
187 target_os = target_os
188 target_cpu = target_cpu
190 if (defined(invoker.is_clang)) {
191 is_clang = invoker.is_clang
197 mac_toolchain("clang_arm") {
198 toolchain_cpu = "arm"
200 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
202 cc = "${goma_prefix}$prefix/clang"
203 cxx = "${goma_prefix}$prefix/clang++"
208 mac_toolchain("ios_clang_arm") {
209 # TODO(GYP): Do we need ios_clang_armv7 and ios_clang_arm64 ?
210 toolchain_cpu = "arm"
213 # TODO(GYP): We need to support being able to use the version of clang
214 # shipped w/ XCode instead of the one pulled from upstream.
215 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
217 cc = "${goma_prefix}$prefix/clang"
218 cxx = "${goma_prefix}$prefix/clang++"
223 mac_toolchain("arm") {
224 toolchain_cpu = "arm"
226 cc = "${goma_prefix}/gcc"
227 cxx = "${goma_prefix}/g++"
232 mac_toolchain("clang_x64") {
233 toolchain_cpu = "x64"
235 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
237 cc = "${goma_prefix}$prefix/clang"
238 cxx = "${goma_prefix}$prefix/clang++"
243 mac_toolchain("x64") {
244 toolchain_cpu = "x64"
246 cc = "${goma_prefix}/gcc"
247 cxx = "${goma_prefix}/g++"