OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 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 |
| 7 # Linux. |
| 8 |
| 9 import("../goma.gni") |
| 10 import("//build/config/ios/ios_sdk.gni") |
| 11 import("//build/config/mac/mac_sdk.gni") |
| 12 |
| 13 assert(host_os == "mac") |
| 14 |
| 15 import("//build/toolchain/clang.gni") |
| 16 import("//build/toolchain/goma.gni") |
| 17 import("//build/config/sysroot.gni") |
| 18 |
| 19 if (use_goma) { |
| 20 goma_prefix = "$goma_dir/gomacc " |
| 21 } else { |
| 22 goma_prefix = "" |
| 23 } |
| 24 |
| 25 # This will copy the gyp-mac-tool to the build directory. We pass in the source |
| 26 # file of the win tool. |
| 27 gyp_mac_tool_source = |
| 28 rebase_path("//tools/gyp/pylib/gyp/mac_tool.py", root_build_dir) |
| 29 exec_script("setup_toolchain.py", [ gyp_mac_tool_source ]) |
| 30 |
| 31 # Shared toolchain definition. Invocations should set toolchain_os to set the |
| 32 # build args in this definition. |
| 33 template("mac_toolchain") { |
| 34 toolchain(target_name) { |
| 35 assert(defined(invoker.cc), "mac_toolchain() must specify a \"cc\" value") |
| 36 assert(defined(invoker.cxx), "mac_toolchain() must specify a \"cxx\" value") |
| 37 assert(defined(invoker.ld), "mac_toolchain() must specify a \"ld\" value") |
| 38 assert(defined(invoker.toolchain_cpu), |
| 39 "mac_toolchain() must specify a \"toolchain_cpu\"") |
| 40 assert(defined(invoker.toolchain_os), |
| 41 "mac_toolchain() must specify a \"toolchain_os\"") |
| 42 |
| 43 # We can't do string interpolation ($ in strings) on things with dots in |
| 44 # them. To allow us to use $cc below, for example, we create copies of |
| 45 # these values in our scope. |
| 46 cc = invoker.cc |
| 47 cxx = invoker.cxx |
| 48 ld = invoker.ld |
| 49 |
| 50 # Make these apply to all tools below. |
| 51 lib_switch = "-l" |
| 52 lib_dir_switch = "-L" |
| 53 |
| 54 sysroot_flags = "" |
| 55 |
| 56 if (defined(invoker.sysroot_flags)) { |
| 57 sysroot_flags = invoker.sysroot_flags |
| 58 } |
| 59 |
| 60 toolchain_flags = "" |
| 61 if (invoker.toolchain_cpu == "i386") { |
| 62 toolchain_flags = "-m32" |
| 63 } |
| 64 |
| 65 tool("cc") { |
| 66 depfile = "{{output}}.d" |
| 67 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} $sysroot_fla
gs $toolchain_flags {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
| 68 depsformat = "gcc" |
| 69 description = "CC {{output}}" |
| 70 outputs = [ |
| 71 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", |
| 72 ] |
| 73 } |
| 74 |
| 75 tool("cxx") { |
| 76 depfile = "{{output}}.d" |
| 77 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} $sysroot_fl
ags $toolchain_flags {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" |
| 78 depsformat = "gcc" |
| 79 description = "CXX {{output}}" |
| 80 outputs = [ |
| 81 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", |
| 82 ] |
| 83 } |
| 84 |
| 85 tool("asm") { |
| 86 # For GCC we can just use the C compiler to compile assembly. |
| 87 depfile = "{{output}}.d" |
| 88 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} $sysroot_fla
gs $toolchain_flags {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
| 89 depsformat = "gcc" |
| 90 description = "ASM {{output}}" |
| 91 outputs = [ |
| 92 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", |
| 93 ] |
| 94 } |
| 95 |
| 96 tool("objc") { |
| 97 depfile = "{{output}}.d" |
| 98 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} $sysroot_fl
ags $toolchain_flags {{cflags}} {{cflags_c}} {{cflags_objc}} -c {{source}} -o {{
output}}" |
| 99 depsformat = "gcc" |
| 100 description = "OBJC {{output}}" |
| 101 outputs = [ |
| 102 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", |
| 103 ] |
| 104 } |
| 105 |
| 106 tool("objcxx") { |
| 107 depfile = "{{output}}.d" |
| 108 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} $sysroot_fl
ags $toolchain_flags {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o
{{output}}" |
| 109 depsformat = "gcc" |
| 110 description = "OBJCXX {{output}}" |
| 111 outputs = [ |
| 112 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.o", |
| 113 ] |
| 114 } |
| 115 |
| 116 tool("alink") { |
| 117 command = "rm -f {{output}} && ./gyp-mac-tool filter-libtool libtool -stat
ic -o {{output}} {{inputs}}" |
| 118 description = "LIBTOOL-STATIC {{output}}" |
| 119 outputs = [ |
| 120 "{{target_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 121 ] |
| 122 default_output_extension = ".a" |
| 123 output_prefix = "lib" |
| 124 } |
| 125 |
| 126 tool("solink") { |
| 127 dylib = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # e
g "./libfoo.dylib" |
| 128 rspfile = dylib + ".rsp" |
| 129 |
| 130 # These variables are not build into GN but are helpers that implement |
| 131 # (1) linking to produce a .so, (2) extracting the symbols from that file |
| 132 # to a temporary file, (3) if the temporary file has differences from the |
| 133 # existing .TOC file, overwrite it, oterwise, don't change it. |
| 134 # |
| 135 # 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 |
| 137 # diffing steps, since that library always needs to be re-linked. |
| 138 tocname = dylib + ".TOC" |
| 139 temporary_tocname = dylib + ".tmp" |
| 140 |
| 141 does_reexport_command = "[ ! -e $dylib -o ! -e $tocname ] || otool -l $dyl
ib | grep -q LC_REEXPORT_DYLIB" |
| 142 link_command = "$ld -shared $sysroot_flags $toolchain_flags {{ldflags}} -o
$dylib -Wl,-filelist,$rspfile {{solibs}} {{libs}}" |
| 143 replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $tempo
rary_tocname $tocname" |
| 144 extract_toc_command = "{ otool -l $dylib | grep LC_ID_DYLIB -A 5; nm -gP $
dylib | cut -f1-2 -d' ' | grep -v U\$\$; true; }" |
| 145 |
| 146 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" |
| 147 |
| 148 rspfile_content = "{{inputs_newline}}" |
| 149 |
| 150 description = "SOLINK {{output}}" |
| 151 |
| 152 # Use this for {{output_extension}} expansions unless a target manually |
| 153 # overrides it (in which case {{output_extension}} will be what the target |
| 154 # specifies). |
| 155 default_output_extension = ".dylib" |
| 156 |
| 157 output_prefix = "lib" |
| 158 |
| 159 # Since the above commands only updates the .TOC file when it changes, ask |
| 160 # Ninja to check if the timestamp actually changed to know if downstream |
| 161 # dependencies should be recompiled. |
| 162 restat = true |
| 163 |
| 164 # Tell GN about the output files. It will link to the dylib but use the |
| 165 # tocname for dependency management. |
| 166 outputs = [ |
| 167 dylib, |
| 168 tocname, |
| 169 ] |
| 170 link_output = dylib |
| 171 depend_output = tocname |
| 172 } |
| 173 |
| 174 tool("link") { |
| 175 outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" |
| 176 rspfile = "$outfile.rsp" |
| 177 |
| 178 command = "$ld $sysroot_flags $toolchain_flags {{ldflags}} -Xlinker -rpath
-Xlinker @executable_path/Frameworks -o $outfile -Wl,-filelist,$rspfile {{solib
s}} {{libs}}" |
| 179 description = "LINK $outfile" |
| 180 rspfile_content = "{{inputs_newline}}" |
| 181 outputs = [ |
| 182 outfile, |
| 183 ] |
| 184 } |
| 185 |
| 186 tool("stamp") { |
| 187 command = "touch {{output}}" |
| 188 description = "STAMP {{output}}" |
| 189 } |
| 190 |
| 191 tool("copy") { |
| 192 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} &
& cp -af {{source}} {{output}})" |
| 193 description = "COPY {{source}} {{output}}" |
| 194 } |
| 195 |
| 196 toolchain_args() { |
| 197 current_cpu = invoker.toolchain_cpu |
| 198 current_os = invoker.toolchain_os |
| 199 |
| 200 # These values need to be passed through unchanged. |
| 201 target_os = target_os |
| 202 target_cpu = target_cpu |
| 203 |
| 204 if (defined(invoker.is_clang)) { |
| 205 is_clang = invoker.is_clang |
| 206 } |
| 207 } |
| 208 } |
| 209 } |
| 210 |
| 211 # Toolchain used for iOS device targets. |
| 212 mac_toolchain("ios_clang_arm") { |
| 213 toolchain_cpu = "arm" |
| 214 toolchain_os = "mac" |
| 215 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin", |
| 216 root_build_dir) |
| 217 cc = "${goma_prefix}$prefix/clang" |
| 218 cxx = "${goma_prefix}$prefix/clang++" |
| 219 ld = cxx |
| 220 is_clang = true |
| 221 sysroot_flags = "-isysroot $ios_device_sdk_path -miphoneos-version-min=$ios_de
ployment_target" |
| 222 } |
| 223 |
| 224 # Toolchain used for iOS simulator targets. |
| 225 mac_toolchain("ios_clang_x64") { |
| 226 toolchain_cpu = "x64" |
| 227 toolchain_os = "mac" |
| 228 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin", |
| 229 root_build_dir) |
| 230 cc = "${goma_prefix}$prefix/clang" |
| 231 cxx = "${goma_prefix}$prefix/clang++" |
| 232 ld = cxx |
| 233 is_clang = true |
| 234 sysroot_flags = "-isysroot $ios_simulator_sdk_path -mios-simulator-version-min
=$ios_deployment_target" |
| 235 } |
| 236 |
| 237 # Toolchain used for Mac host targets. |
| 238 mac_toolchain("clang_x64") { |
| 239 toolchain_cpu = "x64" |
| 240 toolchain_os = "mac" |
| 241 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin", |
| 242 root_build_dir) |
| 243 cc = "${goma_prefix}$prefix/clang" |
| 244 cxx = "${goma_prefix}$prefix/clang++" |
| 245 ld = cxx |
| 246 is_clang = true |
| 247 sysroot_flags = "-isysroot $mac_sdk_path -mmacosx-version-min=$mac_sdk_min" |
| 248 } |
| 249 |
| 250 # Toolchain used for Mac host (i386) targets. |
| 251 mac_toolchain("clang_i386") { |
| 252 toolchain_cpu = "i386" |
| 253 toolchain_os = "mac" |
| 254 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin", |
| 255 root_build_dir) |
| 256 cc = "${goma_prefix}$prefix/clang" |
| 257 cxx = "${goma_prefix}$prefix/clang++" |
| 258 ld = cxx |
| 259 is_clang = true |
| 260 sysroot_flags = "-isysroot $mac_sdk_path -mmacosx-version-min=$mac_sdk_min" |
| 261 } |
OLD | NEW |