| 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") |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 # them. To allow us to use $cc below, for example, we create copies of | 42 # them. To allow us to use $cc below, for example, we create copies of |
| 43 # these values in our scope. | 43 # these values in our scope. |
| 44 cc = invoker.cc | 44 cc = invoker.cc |
| 45 cxx = invoker.cxx | 45 cxx = invoker.cxx |
| 46 ld = invoker.ld | 46 ld = invoker.ld |
| 47 | 47 |
| 48 # Make these apply to all tools below. | 48 # Make these apply to all tools below. |
| 49 lib_switch = "-l" | 49 lib_switch = "-l" |
| 50 lib_dir_switch = "-L" | 50 lib_dir_switch = "-L" |
| 51 | 51 |
| 52 # Object files go in this directory. Use label_name instead of |
| 53 # target_output_name since labels will generally have no spaces and will be |
| 54 # unique in the directory. |
| 55 # TODO(brettw) enable the label_name variant when binary support is rolled i
n to GN. |
| 56 #object_subdir = "{{target_out_dir}}/{{label_name}}" |
| 57 object_subdir = "{{target_out_dir}}/{{target_output_name}}" |
| 58 |
| 52 tool("cc") { | 59 tool("cc") { |
| 53 depfile = "{{output}}.d" | 60 depfile = "{{output}}.d" |
| 54 precompiled_header_type = "gcc" | 61 precompiled_header_type = "gcc" |
| 55 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {
{cflags_c}} -c {{source}} -o {{output}}" | 62 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {
{cflags_c}} -c {{source}} -o {{output}}" |
| 56 depsformat = "gcc" | 63 depsformat = "gcc" |
| 57 description = "CC {{output}}" | 64 description = "CC {{output}}" |
| 58 outputs = [ | 65 outputs = [ |
| 59 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", | 66 "$object_subdir/{{source_name_part}}.o", |
| 60 ] | 67 ] |
| 61 } | 68 } |
| 62 | 69 |
| 63 tool("cxx") { | 70 tool("cxx") { |
| 64 depfile = "{{output}}.d" | 71 depfile = "{{output}}.d" |
| 65 precompiled_header_type = "gcc" | 72 precompiled_header_type = "gcc" |
| 66 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}}
{{cflags_cc}} -c {{source}} -o {{output}}" | 73 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}}
{{cflags_cc}} -c {{source}} -o {{output}}" |
| 67 depsformat = "gcc" | 74 depsformat = "gcc" |
| 68 description = "CXX {{output}}" | 75 description = "CXX {{output}}" |
| 69 outputs = [ | 76 outputs = [ |
| 70 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", | 77 "$object_subdir/{{source_name_part}}.o", |
| 71 ] | 78 ] |
| 72 } | 79 } |
| 73 | 80 |
| 74 tool("asm") { | 81 tool("asm") { |
| 75 # For GCC we can just use the C compiler to compile assembly. | 82 # For GCC we can just use the C compiler to compile assembly. |
| 76 depfile = "{{output}}.d" | 83 depfile = "{{output}}.d" |
| 77 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}}
-c {{source}} -o {{output}}" | 84 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}}
-c {{source}} -o {{output}}" |
| 78 depsformat = "gcc" | 85 depsformat = "gcc" |
| 79 description = "ASM {{output}}" | 86 description = "ASM {{output}}" |
| 80 outputs = [ | 87 outputs = [ |
| 81 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", | 88 "$object_subdir/{{source_name_part}}.o", |
| 82 ] | 89 ] |
| 83 } | 90 } |
| 84 | 91 |
| 85 tool("objc") { | 92 tool("objc") { |
| 86 depfile = "{{output}}.d" | 93 depfile = "{{output}}.d" |
| 87 precompiled_header_type = "gcc" | 94 precompiled_header_type = "gcc" |
| 88 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {
{cflags_objc}} -c {{source}} -o {{output}}" | 95 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {
{cflags_objc}} -c {{source}} -o {{output}}" |
| 89 depsformat = "gcc" | 96 depsformat = "gcc" |
| 90 description = "OBJC {{output}}" | 97 description = "OBJC {{output}}" |
| 91 outputs = [ | 98 outputs = [ |
| 92 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", | 99 "$object_subdir/{{source_name_part}}.o", |
| 93 ] | 100 ] |
| 94 } | 101 } |
| 95 | 102 |
| 96 tool("objcxx") { | 103 tool("objcxx") { |
| 97 depfile = "{{output}}.d" | 104 depfile = "{{output}}.d" |
| 98 precompiled_header_type = "gcc" | 105 precompiled_header_type = "gcc" |
| 99 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}}
{{cflags_objcc}} -c {{source}} -o {{output}}" | 106 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}}
{{cflags_objcc}} -c {{source}} -o {{output}}" |
| 100 depsformat = "gcc" | 107 depsformat = "gcc" |
| 101 description = "OBJCXX {{output}}" | 108 description = "OBJCXX {{output}}" |
| 102 outputs = [ | 109 outputs = [ |
| 103 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", | 110 "$object_subdir/{{source_name_part}}.o", |
| 104 ] | 111 ] |
| 105 } | 112 } |
| 106 | 113 |
| 107 tool("alink") { | 114 tool("alink") { |
| 108 command = "rm -f {{output}} && ./gyp-mac-tool filter-libtool libtool -stat
ic -o {{output}} {{inputs}}" | 115 command = "rm -f {{output}} && ./gyp-mac-tool filter-libtool libtool -stat
ic -o {{output}} {{inputs}}" |
| 109 description = "LIBTOOL-STATIC {{output}}" | 116 description = "LIBTOOL-STATIC {{output}}" |
| 110 outputs = [ | 117 outputs = [ |
| 111 "{{target_out_dir}}/{{target_output_name}}{{output_extension}}", | 118 "{{target_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 112 ] | 119 ] |
| 113 default_output_extension = ".a" | 120 default_output_extension = ".a" |
| 114 output_prefix = "lib" | 121 output_prefix = "lib" |
| 115 } | 122 } |
| 116 | 123 |
| 117 tool("solink") { | 124 tool("solink") { |
| 118 dylib = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # e
g "./libfoo.dylib" | 125 dylib = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # e
g "./libfoo.dylib" |
| 119 rspfile = dylib + ".rsp" | 126 rspfile = dylib + ".rsp" |
| 120 | 127 |
| 121 # These variables are not built into GN but are helpers that implement | 128 # These variables are not built into GN but are helpers that implement |
| 122 # (1) linking to produce a .dylib, (2) extracting the symbols from that | 129 # (1) linking to produce a .dylib, (2) extracting the symbols from that |
| 123 # file to a temporary file, (3) if the temporary file has differences from | 130 # file to a temporary file, (3) if the temporary file has differences from |
| 124 # the existing .TOC file, overwrite it, otherwise, don't change it. | 131 # the existing .TOC file, overwrite it, otherwise, don't change it. |
| 125 # | 132 # |
| 126 # As a special case, if the library reexports symbols from other dynamic | 133 # As a special case, if the library reexports symbols from other dynamic |
| 127 # libraries, we always update the .TOC and skip the temporary file and | 134 # libraries, we always update the .TOC and skip the temporary file and |
| 128 # diffing steps, since that library always needs to be re-linked. | 135 # diffing steps, since that library always needs to be re-linked. |
| 129 tocname = dylib + ".TOC" | 136 tocname = dylib + ".TOC" |
| 130 temporary_tocname = dylib + ".tmp" | 137 temporary_tocname = dylib + ".tmp" |
| 131 | 138 |
| 132 does_reexport_command = "[ ! -e $dylib -o ! -e $tocname ] || otool -l $dyl
ib | grep -q LC_REEXPORT_DYLIB" | 139 does_reexport_command = "[ ! -e \"$dylib\" -o ! -e \"$tocname\" ] || otool
-l \"$dylib\" | grep -q LC_REEXPORT_DYLIB" |
| 133 | 140 |
| 134 link_command = | 141 link_command = |
| 135 "$ld -shared {{ldflags}} -o \"$dylib\" -Wl,-filelist,\"$rspfile\"" | 142 "$ld -shared {{ldflags}} -o \"$dylib\" -Wl,-filelist,\"$rspfile\"" |
| 136 if (is_component_build) { | 143 if (is_component_build) { |
| 137 link_command += " -Wl,-install_name,@rpath/{{target_output_name}}{{outpu
t_extension}}" | 144 link_command += " -Wl,-install_name,@rpath/{{target_output_name}}{{outpu
t_extension}}" |
| 138 } | 145 } |
| 139 link_command += " {{solibs}} {{libs}}" | 146 link_command += " {{solibs}} {{libs}}" |
| 140 | 147 |
| 141 replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $tempo
rary_tocname $tocname" | 148 replace_command = "if ! cmp -s \"$temporary_tocname\" \"$tocname\"; then m
v \"$temporary_tocname\" \"$tocname\"" |
| 142 extract_toc_command = "{ otool -l $dylib | grep LC_ID_DYLIB -A 5; nm -gP $
dylib | cut -f1-2 -d' ' | grep -v U\$\$; true; }" | 149 extract_toc_command = "{ otool -l \"$dylib\" | grep LC_ID_DYLIB -A 5; nm -
gP \"$dylib\" | cut -f1-2 -d' ' | grep -v U\$\$; true; }" |
| 143 | 150 |
| 144 command = "if $does_reexport_command ; then $link_command && $extract_toc_
command > $tocname; else $link_command && $extract_toc_command > $temporary_tocn
ame && $replace_command ; fi; fi" | 151 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" |
| 145 | 152 |
| 146 rspfile_content = "{{inputs_newline}}" | 153 rspfile_content = "{{inputs_newline}}" |
| 147 | 154 |
| 148 description = "SOLINK {{output}}" | 155 description = "SOLINK {{output}}" |
| 149 | 156 |
| 150 # Use this for {{output_extension}} expansions unless a target manually | 157 # Use this for {{output_extension}} expansions unless a target manually |
| 151 # overrides it (in which case {{output_extension}} will be what the target | 158 # overrides it (in which case {{output_extension}} will be what the target |
| 152 # specifies). | 159 # specifies). |
| 153 default_output_extension = ".dylib" | 160 default_output_extension = ".dylib" |
| 154 | 161 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 default_output_extension = ".so" | 198 default_output_extension = ".so" |
| 192 | 199 |
| 193 outputs = [ | 200 outputs = [ |
| 194 sofile, | 201 sofile, |
| 195 ] | 202 ] |
| 196 } | 203 } |
| 197 | 204 |
| 198 tool("link") { | 205 tool("link") { |
| 199 outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" | 206 outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" |
| 200 rspfile = "$outfile.rsp" | 207 rspfile = "$outfile.rsp" |
| 208 |
| 209 # Note about --filelist: Apple's linker reads the file list file and |
| 210 # interprets each newline-separated chunk of text as a file name. It |
| 211 # doesn't do the things one would expect from the shell like unescaping |
| 212 # or handling quotes. In contrast, when Ninja finds a file name with |
| 213 # spaces, it single-quotes them in $inputs_newline as it would normally |
| 214 # do for command-line arguments. Thus any source names with spaces, or |
| 215 # label names with spaces (which GN bases the output paths on) will be |
| 216 # corrupted by this process. Don't use spaces for source files or labels. |
| 201 command = "$ld {{ldflags}} -o \"$outfile\" -Wl,-filelist,\"$rspfile\" {{so
libs}} {{libs}}" | 217 command = "$ld {{ldflags}} -o \"$outfile\" -Wl,-filelist,\"$rspfile\" {{so
libs}} {{libs}}" |
| 202 description = "LINK $outfile" | 218 description = "LINK $outfile" |
| 203 rspfile_content = "{{inputs_newline}}" | 219 rspfile_content = "{{inputs_newline}}" |
| 204 outputs = [ | 220 outputs = [ |
| 205 outfile, | 221 outfile, |
| 206 ] | 222 ] |
| 207 } | 223 } |
| 208 | 224 |
| 209 # These two are really entirely generic, but have to be repeated in | 225 # These two are really entirely generic, but have to be repeated in |
| 210 # each toolchain because GN doesn't allow a template to be used here. | 226 # each toolchain because GN doesn't allow a template to be used here. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 296 } |
| 281 | 297 |
| 282 mac_toolchain("x64") { | 298 mac_toolchain("x64") { |
| 283 toolchain_cpu = "x64" | 299 toolchain_cpu = "x64" |
| 284 toolchain_os = "mac" | 300 toolchain_os = "mac" |
| 285 cc = "${goma_prefix}/gcc" | 301 cc = "${goma_prefix}/gcc" |
| 286 cxx = "${goma_prefix}/g++" | 302 cxx = "${goma_prefix}/g++" |
| 287 ld = cxx | 303 ld = cxx |
| 288 is_clang = false | 304 is_clang = false |
| 289 } | 305 } |
| OLD | NEW |