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 # Should only be running on Mac.
12 assert(is_mac || is_ios)
14 import("//build/toolchain/clang.gni")
15 import("//build/toolchain/goma.gni")
18 goma_prefix = "$goma_dir/gomacc "
24 cc = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang",
26 cxx = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang++",
33 cxx = goma_prefix + cxx
36 # This will copy the gyp-mac-tool to the build directory. We pass in the source
37 # file of the win tool.
39 rebase_path("//tools/gyp/pylib/gyp/mac_tool.py", root_build_dir)
40 exec_script("setup_toolchain.py", [ gyp_mac_tool_source ])
42 # Shared toolchain definition. Invocations should set toolchain_os to set the
43 # build args in this definition.
44 template("mac_clang_toolchain") {
45 toolchain(target_name) {
46 assert(defined(invoker.cc),
47 "mac_clang_toolchain() must specify a \"cc\" value")
48 assert(defined(invoker.cxx),
49 "mac_clang_toolchain() must specify a \"cxx\" value")
50 assert(defined(invoker.ld),
51 "mac_clang_toolchain() must specify a \"ld\" value")
52 assert(defined(invoker.toolchain_os),
53 "mac_clang_toolchain() must specify a \"toolchain_os\"")
55 # We can't do string interpolation ($ in strings) on things with dots in
56 # them. To allow us to use $cc below, for example, we create copies of
57 # these values in our scope.
62 # Make these apply to all tools below.
67 depfile = "{{output}}.d"
68 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
70 description = "CC {{output}}"
72 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
77 depfile = "{{output}}.d"
78 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
80 description = "CXX {{output}}"
82 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
87 # For GCC we can just use the C compiler to compile assembly.
88 depfile = "{{output}}.d"
89 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
91 description = "ASM {{output}}"
93 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
98 depfile = "{{output}}.d"
99 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} -c {{source}} -o {{output}}"
101 description = "OBJC {{output}}"
103 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
108 depfile = "{{output}}.d"
109 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
111 description = "OBJCXX {{output}}"
113 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
118 command = "rm -f {{output}} && ./gyp-mac-tool filter-libtool libtool -static -o {{output}} {{inputs}}"
119 description = "LIBTOOL-STATIC {{output}}"
121 "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
123 default_output_extension = ".a"
124 output_prefix = "lib"
128 dylib = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # eg "./libfoo.dylib"
129 rspfile = dylib + ".rsp"
131 # These variables are not build into GN but are helpers that implement
132 # (1) linking to produce a .so, (2) extracting the symbols from that file
133 # to a temporary file, (3) if the temporary file has differences from the
134 # existing .TOC file, overwrite it, oterwise, don't change it.
136 # As a special case, if the library reexports symbols from other dynamic
137 # libraries, we always update the .TOC and skip the temporary file and
138 # diffing steps, since that library always needs to be re-linked.
139 tocname = dylib + ".TOC"
140 temporary_tocname = dylib + ".tmp"
142 does_reexport_command = "[ ! -e $dylib -o ! -e $tocname ] || otool -l $dylib | grep -q LC_REEXPORT_DYLIB"
143 link_command = "$ld -shared {{ldflags}} -o $dylib -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
144 replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $temporary_tocname $tocname"
145 extract_toc_command = "{ otool -l $dylib | grep LC_ID_DYLIB -A 5; nm -gP $dylib | cut -f1-2 -d' ' | grep -v U\$\$; true; }"
147 command = "if $does_reexport_command ; then $link_command && $extract_toc_command > $tocname; else $link_command && $extract_toc_command > $temporary_tocname && $replace_command ; fi; fi"
149 rspfile_content = "{{inputs_newline}}"
151 description = "SOLINK {{output}}"
153 # Use this for {{output_extension}} expansions unless a target manually
154 # overrides it (in which case {{output_extension}} will be what the target
156 default_output_extension = ".dylib"
158 output_prefix = "lib"
160 # Since the above commands only updates the .TOC file when it changes, ask
161 # Ninja to check if the timestamp actually changed to know if downstream
162 # dependencies should be recompiled.
165 # Tell GN about the output files. It will link to the dylib but use the
166 # tocname for dependency management.
172 depend_output = tocname
176 outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
177 rspfile = "$outfile.rsp"
178 command = "$ld {{ldflags}} -o $outfile -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
179 description = "LINK $outfile"
180 rspfile_content = "{{inputs_newline}}"
187 command = "touch {{output}}"
188 description = "STAMP {{output}}"
192 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
193 description = "COPY {{source}} {{output}}"
197 current_os = invoker.toolchain_os
202 # Toolchain representing the target build (either mac or iOS).
203 mac_clang_toolchain("clang") {
204 toolchain_os = current_os
207 # This toolchain provides a way for iOS target compiles to reference targets
208 # compiled for the host system. It just overrides the OS back to "mac".
209 mac_clang_toolchain("host_clang") {