OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # TODO(brettw) Use "gcc_toolchain.gni" like the Linux toolchains. This requires | 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 | 6 # some enhancements since the commands on Mac are slightly different than on |
7 # Linux. | 7 # Linux. |
8 | 8 |
9 import("../goma.gni") | 9 import("../goma.gni") |
10 import("//build/config/ios/ios_sdk.gni") | 10 import("//build/config/ios/ios_sdk.gni") |
11 import("//build/config/mac/mac_sdk.gni") | 11 import("//build/config/mac/mac_sdk.gni") |
| 12 import("//build/config/mac/symbols.gni") |
12 | 13 |
13 assert(host_os == "mac") | 14 assert(host_os == "mac") |
14 | 15 |
15 import("//build/toolchain/goma.gni") | 16 import("//build/toolchain/goma.gni") |
16 import("//build/toolchain/toolchain.gni") | 17 import("//build/toolchain/toolchain.gni") |
17 | 18 |
18 if (use_goma) { | 19 if (use_goma) { |
19 goma_prefix = "$goma_dir/gomacc " | 20 goma_prefix = "$goma_dir/gomacc " |
20 } else { | 21 } else { |
21 goma_prefix = "" | 22 goma_prefix = "" |
(...skipping 17 matching lines...) Expand all Loading... |
39 assert(defined(invoker.toolchain_os), | 40 assert(defined(invoker.toolchain_os), |
40 "mac_toolchain() must specify a \"toolchain_os\"") | 41 "mac_toolchain() must specify a \"toolchain_os\"") |
41 | 42 |
42 # We can't do string interpolation ($ in strings) on things with dots in | 43 # We can't do string interpolation ($ in strings) on things with dots in |
43 # them. To allow us to use $cc below, for example, we create copies of | 44 # them. To allow us to use $cc below, for example, we create copies of |
44 # these values in our scope. | 45 # these values in our scope. |
45 cc = invoker.cc | 46 cc = invoker.cc |
46 cxx = invoker.cxx | 47 cxx = invoker.cxx |
47 ld = invoker.ld | 48 ld = invoker.ld |
48 | 49 |
| 50 linker_driver = |
| 51 rebase_path("//build/toolchain/mac/linker_driver.py", root_build_dir) |
| 52 |
49 # Make these apply to all tools below. | 53 # Make these apply to all tools below. |
50 lib_switch = "-l" | 54 lib_switch = "-l" |
51 lib_dir_switch = "-L" | 55 lib_dir_switch = "-L" |
52 | 56 |
53 # Object files go in this directory. Use label_name instead of | 57 # Object files go in this directory. Use label_name instead of |
54 # target_output_name since labels will generally have no spaces and will be | 58 # target_output_name since labels will generally have no spaces and will be |
55 # unique in the directory. | 59 # unique in the directory. |
56 object_subdir = "{{target_out_dir}}/{{label_name}}" | 60 object_subdir = "{{target_out_dir}}/{{label_name}}" |
57 | 61 |
| 62 # If dSYMs are enabled, this flag will be added to the link tools. |
| 63 if (enable_dsyms) { |
| 64 dsym_switch = " -Wcrl,dsym," + rebase_path(root_out_dir) + " " |
| 65 } else { |
| 66 dsym_switch = "" |
| 67 } |
| 68 |
58 tool("cc") { | 69 tool("cc") { |
59 depfile = "{{output}}.d" | 70 depfile = "{{output}}.d" |
60 precompiled_header_type = "gcc" | 71 precompiled_header_type = "gcc" |
61 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {
{cflags_c}} -c {{source}} -o {{output}}" | 72 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {
{cflags_c}} -c {{source}} -o {{output}}" |
62 depsformat = "gcc" | 73 depsformat = "gcc" |
63 description = "CC {{output}}" | 74 description = "CC {{output}}" |
64 outputs = [ | 75 outputs = [ |
65 "$object_subdir/{{source_name_part}}.o", | 76 "$object_subdir/{{source_name_part}}.o", |
66 ] | 77 ] |
67 } | 78 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 # the existing .TOC file, overwrite it, otherwise, don't change it. | 144 # the existing .TOC file, overwrite it, otherwise, don't change it. |
134 # | 145 # |
135 # As a special case, if the library reexports symbols from other dynamic | 146 # As a special case, if the library reexports symbols from other dynamic |
136 # libraries, we always update the .TOC and skip the temporary file and | 147 # libraries, we always update the .TOC and skip the temporary file and |
137 # diffing steps, since that library always needs to be re-linked. | 148 # diffing steps, since that library always needs to be re-linked. |
138 tocname = dylib + ".TOC" | 149 tocname = dylib + ".TOC" |
139 temporary_tocname = dylib + ".tmp" | 150 temporary_tocname = dylib + ".tmp" |
140 | 151 |
141 does_reexport_command = "[ ! -e \"$dylib\" -o ! -e \"$tocname\" ] || otool
-l \"$dylib\" | grep -q LC_REEXPORT_DYLIB" | 152 does_reexport_command = "[ ! -e \"$dylib\" -o ! -e \"$tocname\" ] || otool
-l \"$dylib\" | grep -q LC_REEXPORT_DYLIB" |
142 | 153 |
143 link_command = "$ld -shared " | 154 link_command = "$linker_driver $ld -shared " |
144 if (is_component_build) { | 155 if (is_component_build) { |
145 link_command += " -Wl,-install_name,@rpath/\"{{target_output_name}}{{out
put_extension}}\" " | 156 link_command += " -Wl,-install_name,@rpath/\"{{target_output_name}}{{out
put_extension}}\" " |
146 } | 157 } |
| 158 link_command += dsym_switch |
147 link_command += "{{ldflags}} -o \"$dylib\" -Wl,-filelist,\"$rspfile\" {{li
bs}} {{solibs}}" | 159 link_command += "{{ldflags}} -o \"$dylib\" -Wl,-filelist,\"$rspfile\" {{li
bs}} {{solibs}}" |
148 | 160 |
149 replace_command = "if ! cmp -s \"$temporary_tocname\" \"$tocname\"; then m
v \"$temporary_tocname\" \"$tocname\"" | 161 replace_command = "if ! cmp -s \"$temporary_tocname\" \"$tocname\"; then m
v \"$temporary_tocname\" \"$tocname\"" |
150 extract_toc_command = "{ otool -l \"$dylib\" | grep LC_ID_DYLIB -A 5; nm -
gP \"$dylib\" | cut -f1-2 -d' ' | grep -v U\$\$; true; }" | 162 extract_toc_command = "{ otool -l \"$dylib\" | grep LC_ID_DYLIB -A 5; nm -
gP \"$dylib\" | cut -f1-2 -d' ' | grep -v U\$\$; true; }" |
151 | 163 |
152 command = "if $does_reexport_command ; then $link_command && $extract_toc_
command > \"$tocname\"; else $link_command && $extract_toc_command > \"$temporar
y_tocname\" && $replace_command ; fi; fi" | 164 command = "if $does_reexport_command ; then $link_command && $extract_toc_
command > \"$tocname\"; else $link_command && $extract_toc_command > \"$temporar
y_tocname\" && $replace_command ; fi; fi" |
153 | 165 |
154 rspfile_content = "{{inputs_newline}}" | 166 rspfile_content = "{{inputs_newline}}" |
155 | 167 |
156 description = "SOLINK {{output}}" | 168 description = "SOLINK {{output}}" |
(...skipping 12 matching lines...) Expand all Loading... |
169 restat = true | 181 restat = true |
170 | 182 |
171 # Tell GN about the output files. It will link to the dylib but use the | 183 # Tell GN about the output files. It will link to the dylib but use the |
172 # tocname for dependency management. | 184 # tocname for dependency management. |
173 outputs = [ | 185 outputs = [ |
174 dylib, | 186 dylib, |
175 tocname, | 187 tocname, |
176 ] | 188 ] |
177 link_output = dylib | 189 link_output = dylib |
178 depend_output = tocname | 190 depend_output = tocname |
| 191 |
| 192 if (enable_dsyms) { |
| 193 outputs += [ dylib + ".dSYM/" ] |
| 194 } |
179 } | 195 } |
180 | 196 |
181 tool("solink_module") { | 197 tool("solink_module") { |
182 sofile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" # eg
"./libfoo.so" | 198 sofile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" # eg
"./libfoo.so" |
183 rspfile = sofile + ".rsp" | 199 rspfile = sofile + ".rsp" |
184 | 200 |
185 link_command = | 201 link_command = "$linker_driver $ld -bundle {{ldflags}} -o \"$sofile\" -Wl,
-filelist,\"$rspfile\"" |
186 "$ld -bundle {{ldflags}} -o \"$sofile\" -Wl,-filelist,\"$rspfile\"" | |
187 if (is_component_build) { | 202 if (is_component_build) { |
188 link_command += " -Wl,-install_name,@rpath/{{target_output_name}}{{outpu
t_extension}}" | 203 link_command += " -Wl,-install_name,@rpath/{{target_output_name}}{{outpu
t_extension}}" |
189 } | 204 } |
| 205 link_command += dsym_switch |
190 link_command += " {{solibs}} {{libs}}" | 206 link_command += " {{solibs}} {{libs}}" |
191 command = link_command | 207 command = link_command |
192 | 208 |
193 rspfile_content = "{{inputs_newline}}" | 209 rspfile_content = "{{inputs_newline}}" |
194 | 210 |
195 description = "SOLINK_MODULE {{output}}" | 211 description = "SOLINK_MODULE {{output}}" |
196 | 212 |
197 # Use this for {{output_extension}} expansions unless a target manually | 213 # Use this for {{output_extension}} expansions unless a target manually |
198 # overrides it (in which case {{output_extension}} will be what the target | 214 # overrides it (in which case {{output_extension}} will be what the target |
199 # specifies). | 215 # specifies). |
200 default_output_dir = "{{root_out_dir}}" | 216 default_output_dir = "{{root_out_dir}}" |
201 default_output_extension = ".so" | 217 default_output_extension = ".so" |
202 | 218 |
203 outputs = [ | 219 outputs = [ |
204 sofile, | 220 sofile, |
205 ] | 221 ] |
| 222 |
| 223 if (enable_dsyms) { |
| 224 outputs += [ sofile + ".dSYM/" ] |
| 225 } |
206 } | 226 } |
207 | 227 |
208 tool("link") { | 228 tool("link") { |
209 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" | 229 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" |
210 rspfile = "$outfile.rsp" | 230 rspfile = "$outfile.rsp" |
211 | 231 |
212 # Note about --filelist: Apple's linker reads the file list file and | 232 # Note about --filelist: Apple's linker reads the file list file and |
213 # interprets each newline-separated chunk of text as a file name. It | 233 # interprets each newline-separated chunk of text as a file name. It |
214 # doesn't do the things one would expect from the shell like unescaping | 234 # doesn't do the things one would expect from the shell like unescaping |
215 # or handling quotes. In contrast, when Ninja finds a file name with | 235 # or handling quotes. In contrast, when Ninja finds a file name with |
216 # spaces, it single-quotes them in $inputs_newline as it would normally | 236 # spaces, it single-quotes them in $inputs_newline as it would normally |
217 # do for command-line arguments. Thus any source names with spaces, or | 237 # do for command-line arguments. Thus any source names with spaces, or |
218 # label names with spaces (which GN bases the output paths on) will be | 238 # label names with spaces (which GN bases the output paths on) will be |
219 # corrupted by this process. Don't use spaces for source files or labels. | 239 # corrupted by this process. Don't use spaces for source files or labels. |
220 command = "$ld {{ldflags}} -o \"$outfile\" -Wl,-filelist,\"$rspfile\" {{so
libs}} {{libs}}" | 240 command = "$linker_driver $ld $dsym_switch {{ldflags}} -o \"$outfile\" -Wl
,-filelist,\"$rspfile\" {{solibs}} {{libs}}" |
221 description = "LINK $outfile" | 241 description = "LINK $outfile" |
222 rspfile_content = "{{inputs_newline}}" | 242 rspfile_content = "{{inputs_newline}}" |
223 outputs = [ | 243 outputs = [ |
224 outfile, | 244 outfile, |
225 ] | 245 ] |
226 | 246 |
| 247 if (enable_dsyms) { |
| 248 outputs += [ outfile + ".dSYM/" ] |
| 249 } |
| 250 |
227 default_output_dir = "{{root_out_dir}}" | 251 default_output_dir = "{{root_out_dir}}" |
228 } | 252 } |
229 | 253 |
230 # These two are really entirely generic, but have to be repeated in | 254 # These two are really entirely generic, but have to be repeated in |
231 # each toolchain because GN doesn't allow a template to be used here. | 255 # each toolchain because GN doesn't allow a template to be used here. |
232 # See //build/toolchain/toolchain.gni for details. | 256 # See //build/toolchain/toolchain.gni for details. |
233 tool("stamp") { | 257 tool("stamp") { |
234 command = stamp_command | 258 command = stamp_command |
235 description = stamp_description | 259 description = stamp_description |
236 } | 260 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 376 } |
353 | 377 |
354 mac_toolchain("x64") { | 378 mac_toolchain("x64") { |
355 toolchain_cpu = "x64" | 379 toolchain_cpu = "x64" |
356 toolchain_os = "mac" | 380 toolchain_os = "mac" |
357 cc = "${goma_prefix}/gcc" | 381 cc = "${goma_prefix}/gcc" |
358 cxx = "${goma_prefix}/g++" | 382 cxx = "${goma_prefix}/g++" |
359 ld = cxx | 383 ld = cxx |
360 is_clang = false | 384 is_clang = false |
361 } | 385 } |
OLD | NEW |