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
11 assert(host_os == "mac")
13 import("//build/toolchain/clang.gni")
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 "{{source_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 "{{source_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 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
83 depfile = "{{output}}.d"
84 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} -c {{source}} -o {{output}}"
86 description = "OBJC {{output}}"
88 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
93 depfile = "{{output}}.d"
94 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
96 description = "OBJCXX {{output}}"
98 "{{source_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 build 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, oterwise, 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"
128 link_command = "$ld -shared {{ldflags}} -o $dylib -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
129 replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $temporary_tocname $tocname"
130 extract_toc_command = "{ otool -l $dylib | grep LC_ID_DYLIB -A 5; nm -gP $dylib | cut -f1-2 -d' ' | grep -v U\$\$; true; }"
132 command = "if $does_reexport_command ; then $link_command && $extract_toc_command > $tocname; else $link_command && $extract_toc_command > $temporary_tocname && $replace_command ; fi; fi"
134 rspfile_content = "{{inputs_newline}}"
136 description = "SOLINK {{output}}"
138 # Use this for {{output_extension}} expansions unless a target manually
139 # overrides it (in which case {{output_extension}} will be what the target
141 default_output_extension = ".dylib"
143 output_prefix = "lib"
145 # Since the above commands only updates the .TOC file when it changes, ask
146 # Ninja to check if the timestamp actually changed to know if downstream
147 # dependencies should be recompiled.
150 # Tell GN about the output files. It will link to the dylib but use the
151 # tocname for dependency management.
157 depend_output = tocname
161 outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
162 rspfile = "$outfile.rsp"
163 command = "$ld {{ldflags}} -o $outfile -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
164 description = "LINK $outfile"
165 rspfile_content = "{{inputs_newline}}"
172 command = "touch {{output}}"
173 description = "STAMP {{output}}"
177 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
178 description = "COPY {{source}} {{output}}"
182 current_cpu = invoker.toolchain_cpu
183 current_os = invoker.toolchain_os
185 # These values need to be passed through unchanged.
186 target_os = target_os
187 target_cpu = target_cpu
189 if (defined(invoker.is_clang)) {
190 is_clang = invoker.is_clang
196 mac_toolchain("clang_arm") {
197 toolchain_cpu = "arm"
199 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
201 cc = "${goma_prefix}$prefix/clang"
202 cxx = "${goma_prefix}$prefix/clang++"
207 mac_toolchain("arm") {
208 toolchain_cpu = "arm"
210 cc = "${goma_prefix}/gcc"
211 cxx = "${goma_prefix}/g++"
216 mac_toolchain("clang_x64") {
217 toolchain_cpu = "x64"
219 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
221 cc = "${goma_prefix}$prefix/clang"
222 cxx = "${goma_prefix}$prefix/clang++"
227 mac_toolchain("x64") {
228 toolchain_cpu = "x64"
230 cc = "${goma_prefix}/gcc"
231 cxx = "${goma_prefix}/g++"