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"
53 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
55 description = "CC {{output}}"
57 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
62 depfile = "{{output}}.d"
63 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
65 description = "CXX {{output}}"
67 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
72 # For GCC we can just use the C compiler to compile assembly.
73 depfile = "{{output}}.d"
74 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
76 description = "ASM {{output}}"
78 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
83 depfile = "{{output}}.d"
84 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
86 description = "OBJC {{output}}"
88 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
93 depfile = "{{output}}.d"
94 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objcc}} -c {{source}} -o {{output}}"
96 description = "OBJCXX {{output}}"
98 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o",
103 command = "rm -f {{output}} && ./gyp-mac-tool filter-libtool libtool -static -o {{output}} {{inputs}}"
104 description = "LIBTOOL-STATIC {{output}}"
106 "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
108 default_output_extension = ".a"
109 output_prefix = "lib"
113 dylib = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # eg "./libfoo.dylib"
114 rspfile = dylib + ".rsp"
116 # These variables are not built into GN but are helpers that implement
117 # (1) linking to produce a .so, (2) extracting the symbols from that file
118 # to a temporary file, (3) if the temporary file has differences from the
119 # existing .TOC file, overwrite it, otherwise, don't change it.
121 # As a special case, if the library reexports symbols from other dynamic
122 # libraries, we always update the .TOC and skip the temporary file and
123 # diffing steps, since that library always needs to be re-linked.
124 tocname = dylib + ".TOC"
125 temporary_tocname = dylib + ".tmp"
127 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"
130 if (is_component_build) {
131 link_command += " -Wl,-install_name,@rpath/{{target_output_name}}{{output_extension}}"
133 link_command += " {{solibs}} {{libs}}"
135 replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $temporary_tocname $tocname"
136 extract_toc_command = "{ otool -l $dylib | grep LC_ID_DYLIB -A 5; nm -gP $dylib | cut -f1-2 -d' ' | grep -v U\$\$; true; }"
138 command = "if $does_reexport_command ; then $link_command && $extract_toc_command > $tocname; else $link_command && $extract_toc_command > $temporary_tocname && $replace_command ; fi; fi"
140 rspfile_content = "{{inputs_newline}}"
142 description = "SOLINK {{output}}"
144 # Use this for {{output_extension}} expansions unless a target manually
145 # overrides it (in which case {{output_extension}} will be what the target
147 default_output_extension = ".dylib"
149 output_prefix = "lib"
151 # Since the above commands only updates the .TOC file when it changes, ask
152 # Ninja to check if the timestamp actually changed to know if downstream
153 # dependencies should be recompiled.
156 # Tell GN about the output files. It will link to the dylib but use the
157 # tocname for dependency management.
163 depend_output = tocname
167 outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
168 rspfile = "$outfile.rsp"
169 command = "$ld {{ldflags}} -o $outfile -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
170 description = "LINK $outfile"
171 rspfile_content = "{{inputs_newline}}"
178 command = "touch {{output}}"
179 description = "STAMP {{output}}"
183 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
184 description = "COPY {{source}} {{output}}"
188 current_cpu = invoker.toolchain_cpu
189 current_os = invoker.toolchain_os
191 # These values need to be passed through unchanged.
192 target_os = target_os
193 target_cpu = target_cpu
195 if (defined(invoker.is_clang)) {
196 is_clang = invoker.is_clang
202 mac_toolchain("clang_arm") {
203 toolchain_cpu = "arm"
205 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
207 cc = "${goma_prefix}$prefix/clang"
208 cxx = "${goma_prefix}$prefix/clang++"
213 mac_toolchain("ios_clang_arm") {
214 # TODO(GYP): Do we need ios_clang_armv7 and ios_clang_arm64 ?
215 toolchain_cpu = "arm"
218 # TODO(GYP): We need to support being able to use the version of clang
219 # shipped w/ XCode instead of the one pulled from upstream.
220 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
222 cc = "${goma_prefix}$prefix/clang"
223 cxx = "${goma_prefix}$prefix/clang++"
228 mac_toolchain("arm") {
229 toolchain_cpu = "arm"
231 cc = "${goma_prefix}/gcc"
232 cxx = "${goma_prefix}/g++"
237 mac_toolchain("clang_x64") {
238 toolchain_cpu = "x64"
240 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
242 cc = "${goma_prefix}$prefix/clang"
243 cxx = "${goma_prefix}$prefix/clang++"
248 mac_toolchain("x64") {
249 toolchain_cpu = "x64"
251 cc = "${goma_prefix}/gcc"
252 cxx = "${goma_prefix}/g++"