| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 # the existing .TOC file, overwrite it, otherwise, don't change it. | 142 # the existing .TOC file, overwrite it, otherwise, don't change it. |
| 132 # | 143 # |
| 133 # As a special case, if the library reexports symbols from other dynamic | 144 # As a special case, if the library reexports symbols from other dynamic |
| 134 # libraries, we always update the .TOC and skip the temporary file and | 145 # libraries, we always update the .TOC and skip the temporary file and |
| 135 # diffing steps, since that library always needs to be re-linked. | 146 # diffing steps, since that library always needs to be re-linked. |
| 136 tocname = dylib + ".TOC" | 147 tocname = dylib + ".TOC" |
| 137 temporary_tocname = dylib + ".tmp" | 148 temporary_tocname = dylib + ".tmp" |
| 138 | 149 |
| 139 does_reexport_command = "[ ! -e \"$dylib\" -o ! -e \"$tocname\" ] || otool
-l \"$dylib\" | grep -q LC_REEXPORT_DYLIB" | 150 does_reexport_command = "[ ! -e \"$dylib\" -o ! -e \"$tocname\" ] || otool
-l \"$dylib\" | grep -q LC_REEXPORT_DYLIB" |
| 140 | 151 |
| 141 link_command = "$ld -shared " | 152 link_command = "$linker_driver $ld -shared " |
| 142 if (is_component_build) { | 153 if (is_component_build) { |
| 143 link_command += " -Wl,-install_name,@rpath/\"{{target_output_name}}{{out
put_extension}}\" " | 154 link_command += " -Wl,-install_name,@rpath/\"{{target_output_name}}{{out
put_extension}}\" " |
| 144 } | 155 } |
| 156 link_command += dsym_switch |
| 145 link_command += "{{ldflags}} -o \"$dylib\" -Wl,-filelist,\"$rspfile\" {{li
bs}} {{solibs}}" | 157 link_command += "{{ldflags}} -o \"$dylib\" -Wl,-filelist,\"$rspfile\" {{li
bs}} {{solibs}}" |
| 146 | 158 |
| 147 replace_command = "if ! cmp -s \"$temporary_tocname\" \"$tocname\"; then m
v \"$temporary_tocname\" \"$tocname\"" | 159 replace_command = "if ! cmp -s \"$temporary_tocname\" \"$tocname\"; then m
v \"$temporary_tocname\" \"$tocname\"" |
| 148 extract_toc_command = "{ otool -l \"$dylib\" | grep LC_ID_DYLIB -A 5; nm -
gP \"$dylib\" | cut -f1-2 -d' ' | grep -v U\$\$; true; }" | 160 extract_toc_command = "{ otool -l \"$dylib\" | grep LC_ID_DYLIB -A 5; nm -
gP \"$dylib\" | cut -f1-2 -d' ' | grep -v U\$\$; true; }" |
| 149 | 161 |
| 150 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" | 162 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" |
| 151 | 163 |
| 152 rspfile_content = "{{inputs_newline}}" | 164 rspfile_content = "{{inputs_newline}}" |
| 153 | 165 |
| 154 description = "SOLINK {{output}}" | 166 description = "SOLINK {{output}}" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 167 restat = true | 179 restat = true |
| 168 | 180 |
| 169 # Tell GN about the output files. It will link to the dylib but use the | 181 # Tell GN about the output files. It will link to the dylib but use the |
| 170 # tocname for dependency management. | 182 # tocname for dependency management. |
| 171 outputs = [ | 183 outputs = [ |
| 172 dylib, | 184 dylib, |
| 173 tocname, | 185 tocname, |
| 174 ] | 186 ] |
| 175 link_output = dylib | 187 link_output = dylib |
| 176 depend_output = tocname | 188 depend_output = tocname |
| 189 |
| 190 if (enable_dsyms) { |
| 191 outputs += [ dylib + ".dSYM/" ] |
| 192 } |
| 177 } | 193 } |
| 178 | 194 |
| 179 tool("solink_module") { | 195 tool("solink_module") { |
| 180 sofile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" # eg
"./libfoo.so" | 196 sofile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" # eg
"./libfoo.so" |
| 181 rspfile = sofile + ".rsp" | 197 rspfile = sofile + ".rsp" |
| 182 | 198 |
| 183 link_command = | 199 link_command = "$linker_driver $ld -bundle {{ldflags}} -o \"$sofile\" -Wl,
-filelist,\"$rspfile\"" |
| 184 "$ld -bundle {{ldflags}} -o \"$sofile\" -Wl,-filelist,\"$rspfile\"" | |
| 185 if (is_component_build) { | 200 if (is_component_build) { |
| 186 link_command += " -Wl,-install_name,@rpath/{{target_output_name}}{{outpu
t_extension}}" | 201 link_command += " -Wl,-install_name,@rpath/{{target_output_name}}{{outpu
t_extension}}" |
| 187 } | 202 } |
| 203 link_command += dsym_switch |
| 188 link_command += " {{solibs}} {{libs}}" | 204 link_command += " {{solibs}} {{libs}}" |
| 189 command = link_command | 205 command = link_command |
| 190 | 206 |
| 191 rspfile_content = "{{inputs_newline}}" | 207 rspfile_content = "{{inputs_newline}}" |
| 192 | 208 |
| 193 description = "SOLINK_MODULE {{output}}" | 209 description = "SOLINK_MODULE {{output}}" |
| 194 | 210 |
| 195 # Use this for {{output_extension}} expansions unless a target manually | 211 # Use this for {{output_extension}} expansions unless a target manually |
| 196 # overrides it (in which case {{output_extension}} will be what the target | 212 # overrides it (in which case {{output_extension}} will be what the target |
| 197 # specifies). | 213 # specifies). |
| 198 default_output_dir = "{{root_out_dir}}" | 214 default_output_dir = "{{root_out_dir}}" |
| 199 default_output_extension = ".so" | 215 default_output_extension = ".so" |
| 200 | 216 |
| 201 outputs = [ | 217 outputs = [ |
| 202 sofile, | 218 sofile, |
| 203 ] | 219 ] |
| 220 |
| 221 if (enable_dsyms) { |
| 222 outputs += [ sofile + ".dSYM/" ] |
| 223 } |
| 204 } | 224 } |
| 205 | 225 |
| 206 tool("link") { | 226 tool("link") { |
| 207 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" | 227 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" |
| 208 rspfile = "$outfile.rsp" | 228 rspfile = "$outfile.rsp" |
| 209 | 229 |
| 210 # Note about --filelist: Apple's linker reads the file list file and | 230 # Note about --filelist: Apple's linker reads the file list file and |
| 211 # interprets each newline-separated chunk of text as a file name. It | 231 # interprets each newline-separated chunk of text as a file name. It |
| 212 # doesn't do the things one would expect from the shell like unescaping | 232 # doesn't do the things one would expect from the shell like unescaping |
| 213 # or handling quotes. In contrast, when Ninja finds a file name with | 233 # or handling quotes. In contrast, when Ninja finds a file name with |
| 214 # spaces, it single-quotes them in $inputs_newline as it would normally | 234 # spaces, it single-quotes them in $inputs_newline as it would normally |
| 215 # do for command-line arguments. Thus any source names with spaces, or | 235 # do for command-line arguments. Thus any source names with spaces, or |
| 216 # label names with spaces (which GN bases the output paths on) will be | 236 # label names with spaces (which GN bases the output paths on) will be |
| 217 # corrupted by this process. Don't use spaces for source files or labels. | 237 # corrupted by this process. Don't use spaces for source files or labels. |
| 218 command = "$ld {{ldflags}} -o \"$outfile\" -Wl,-filelist,\"$rspfile\" {{so
libs}} {{libs}}" | 238 command = "$linker_driver $ld $dsym_switch {{ldflags}} -o \"$outfile\" -Wl
,-filelist,\"$rspfile\" {{solibs}} {{libs}}" |
| 219 description = "LINK $outfile" | 239 description = "LINK $outfile" |
| 220 rspfile_content = "{{inputs_newline}}" | 240 rspfile_content = "{{inputs_newline}}" |
| 221 outputs = [ | 241 outputs = [ |
| 222 outfile, | 242 outfile, |
| 223 ] | 243 ] |
| 224 | 244 |
| 245 if (enable_dsyms) { |
| 246 outputs += [ outfile + ".dSYM/" ] |
| 247 } |
| 248 |
| 225 default_output_dir = "{{root_out_dir}}" | 249 default_output_dir = "{{root_out_dir}}" |
| 226 } | 250 } |
| 227 | 251 |
| 228 # These two are really entirely generic, but have to be repeated in | 252 # These two are really entirely generic, but have to be repeated in |
| 229 # each toolchain because GN doesn't allow a template to be used here. | 253 # each toolchain because GN doesn't allow a template to be used here. |
| 230 # See //build/toolchain/toolchain.gni for details. | 254 # See //build/toolchain/toolchain.gni for details. |
| 231 tool("stamp") { | 255 tool("stamp") { |
| 232 command = stamp_command | 256 command = stamp_command |
| 233 description = stamp_description | 257 description = stamp_description |
| 234 } | 258 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } | 380 } |
| 357 | 381 |
| 358 mac_toolchain("x64") { | 382 mac_toolchain("x64") { |
| 359 toolchain_cpu = "x64" | 383 toolchain_cpu = "x64" |
| 360 toolchain_os = "mac" | 384 toolchain_os = "mac" |
| 361 cc = "${goma_prefix}/gcc" | 385 cc = "${goma_prefix}/gcc" |
| 362 cxx = "${goma_prefix}/g++" | 386 cxx = "${goma_prefix}/g++" |
| 363 ld = cxx | 387 ld = cxx |
| 364 is_clang = false | 388 is_clang = false |
| 365 } | 389 } |
| OLD | NEW |