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/goma.gni")
17 goma_prefix = "$goma_dir/gomacc "
22 # This will copy the gyp-mac-tool to the build directory. We pass in the source
23 # file of the win tool.
25 rebase_path("//tools/gyp/pylib/gyp/mac_tool.py", root_build_dir)
26 exec_script("setup_toolchain.py", [ gyp_mac_tool_source ])
28 # Shared toolchain definition. Invocations should set toolchain_os to set the
29 # build args in this definition.
30 template("mac_toolchain") {
31 toolchain(target_name) {
32 assert(defined(invoker.cc), "mac_toolchain() must specify a \"cc\" value")
33 assert(defined(invoker.cxx), "mac_toolchain() must specify a \"cxx\" value")
34 assert(defined(invoker.ld), "mac_toolchain() must specify a \"ld\" value")
35 assert(defined(invoker.toolchain_cpu),
36 "mac_toolchain() must specify a \"toolchain_cpu\"")
37 assert(defined(invoker.toolchain_os),
38 "mac_toolchain() must specify a \"toolchain_os\"")
40 # We can't do string interpolation ($ in strings) on things with dots in
41 # them. To allow us to use $cc below, for example, we create copies of
42 # these values in our scope.
47 # Make these apply to all tools below.
52 depfile = "{{output}}.d"
54 # TODO:(andybons): enable this when GCC PCH support in the binary has been
56 #precompiled_header_type = "gcc"
57 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
59 description = "CC {{output}}"
61 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
66 depfile = "{{output}}.d"
68 # TODO:(andybons): enable this when GCC PCH support in the binary has been
70 #precompiled_header_type = "gcc"
71 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
73 description = "CXX {{output}}"
75 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
80 # For GCC we can just use the C compiler to compile assembly.
81 depfile = "{{output}}.d"
82 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
84 description = "ASM {{output}}"
86 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
91 depfile = "{{output}}.d"
92 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
94 # TODO:(andybons): enable this when GCC PCH support in the binary has been
96 #precompiled_header_type = "gcc"
97 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} -c {{source}} -o {{output}}"
99 description = "OBJC {{output}}"
101 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
106 depfile = "{{output}}.d"
107 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objcc}} -c {{source}} -o {{output}}"
109 # TODO:(andybons): enable this when GCC PCH support in the binary has been
111 #precompiled_header_type = "gcc"
113 description = "OBJCXX {{output}}"
115 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
120 command = "rm -f {{output}} && ./gyp-mac-tool filter-libtool libtool -static -o {{output}} {{inputs}}"
121 description = "LIBTOOL-STATIC {{output}}"
123 "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
125 default_output_extension = ".a"
126 output_prefix = "lib"
130 dylib = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # eg "./libfoo.dylib"
131 rspfile = dylib + ".rsp"
133 # These variables are not built into GN but are helpers that implement
134 # (1) linking to produce a .so, (2) extracting the symbols from that file
135 # to a temporary file, (3) if the temporary file has differences from the
136 # existing .TOC file, overwrite it, otherwise, don't change it.
138 # As a special case, if the library reexports symbols from other dynamic
139 # libraries, we always update the .TOC and skip the temporary file and
140 # diffing steps, since that library always needs to be re-linked.
141 tocname = dylib + ".TOC"
142 temporary_tocname = dylib + ".tmp"
144 does_reexport_command = "[ ! -e $dylib -o ! -e $tocname ] || otool -l $dylib | grep -q LC_REEXPORT_DYLIB"
146 link_command = "$ld -shared {{ldflags}} -o $dylib -Wl,-filelist,$rspfile"
147 if (is_component_build) {
148 link_command += " -Wl,-install_name,@rpath/{{target_output_name}}{{output_extension}}"
150 link_command += " {{solibs}} {{libs}}"
152 replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $temporary_tocname $tocname"
153 extract_toc_command = "{ otool -l $dylib | grep LC_ID_DYLIB -A 5; nm -gP $dylib | cut -f1-2 -d' ' | grep -v U\$\$; true; }"
155 command = "if $does_reexport_command ; then $link_command && $extract_toc_command > $tocname; else $link_command && $extract_toc_command > $temporary_tocname && $replace_command ; fi; fi"
157 rspfile_content = "{{inputs_newline}}"
159 description = "SOLINK {{output}}"
161 # Use this for {{output_extension}} expansions unless a target manually
162 # overrides it (in which case {{output_extension}} will be what the target
164 default_output_extension = ".dylib"
166 output_prefix = "lib"
168 # Since the above commands only updates the .TOC file when it changes, ask
169 # Ninja to check if the timestamp actually changed to know if downstream
170 # dependencies should be recompiled.
173 # Tell GN about the output files. It will link to the dylib but use the
174 # tocname for dependency management.
180 depend_output = tocname
184 outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
185 rspfile = "$outfile.rsp"
186 command = "$ld {{ldflags}} -o $outfile -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
187 description = "LINK $outfile"
188 rspfile_content = "{{inputs_newline}}"
195 command = "touch {{output}}"
196 description = "STAMP {{output}}"
200 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
201 description = "COPY {{source}} {{output}}"
205 current_cpu = invoker.toolchain_cpu
206 current_os = invoker.toolchain_os
208 # These values need to be passed through unchanged.
209 target_os = target_os
210 target_cpu = target_cpu
212 if (defined(invoker.is_clang)) {
213 is_clang = invoker.is_clang
219 mac_toolchain("clang_arm") {
220 toolchain_cpu = "arm"
222 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
224 cc = "${goma_prefix}$prefix/clang"
225 cxx = "${goma_prefix}$prefix/clang++"
230 mac_toolchain("ios_clang_arm") {
231 # TODO(GYP): Do we need ios_clang_armv7 and ios_clang_arm64 ?
232 toolchain_cpu = "arm"
235 # TODO(GYP): We need to support being able to use the version of clang
236 # shipped w/ XCode instead of the one pulled from upstream.
237 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
239 cc = "${goma_prefix}$prefix/clang"
240 cxx = "${goma_prefix}$prefix/clang++"
245 mac_toolchain("arm") {
246 toolchain_cpu = "arm"
248 cc = "${goma_prefix}/gcc"
249 cxx = "${goma_prefix}/g++"
254 mac_toolchain("clang_x64") {
255 toolchain_cpu = "x64"
257 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
259 cc = "${goma_prefix}$prefix/clang"
260 cxx = "${goma_prefix}$prefix/clang++"
265 mac_toolchain("x64") {
266 toolchain_cpu = "x64"
268 cc = "${goma_prefix}/gcc"
269 cxx = "${goma_prefix}/g++"