summaryrefslogtreecommitdiffstats
path: root/build/toolchain/mac/BUILD.gn
blob: d70774d14f832343dba96f9bd4c5992581e41090 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# TODO(brettw) Use "gcc_toolchain.gni" like the Linux toolchains. This requires
# some enhancements since the commands on Mac are slightly different than on
# Linux.

import("../goma.gni")

# Should only be running on Mac.
assert(is_mac || is_ios)

import("//build/toolchain/clang.gni")
import("//build/toolchain/goma.gni")

if (is_clang) {
  cc = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang",
                   root_build_dir)
  cxx = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang++",
                    root_build_dir)
} else {
  cc = "gcc"
  cxx = "g++"
}
ld = cxx

# This will copy the gyp-mac-tool to the build directory. We pass in the source
# file of the win tool.
gyp_mac_tool_source =
  rebase_path("//tools/gyp/pylib/gyp/mac_tool.py", root_build_dir)
exec_script("setup_toolchain.py", [ gyp_mac_tool_source ], "value")

# Shared toolchain definition. Invocations should set toolchain_os to set the
# build args in this definition.
template("mac_clang_toolchain") {
  toolchain(target_name) {
    assert(defined(invoker.cc),
           "mac_clang_toolchain() must specify a \"cc\" value")
    assert(defined(invoker.cxx),
           "mac_clang_toolchain() must specify a \"cxx\" value")
    assert(defined(invoker.ld),
           "mac_clang_toolchain() must specify a \"ld\" value")
    assert(defined(invoker.toolchain_os),
           "mac_clang_toolchain() must specify a \"toolchain_os\"")

    # We can't do string interpolation ($ in strings) on things with dots in
    # them. To allow us to use $cc below, for example, we create copies of
    # these values in our scope.
    cc = invoker.cc
    cxx = invoker.cxx
    ld = invoker.ld

    # Make these apply to all tools below.
    lib_prefix = "-l"
    lib_dir_prefix="-L"

    tool("cc") {
      command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_pch_c -c \$in -o \$out"
      description = "CC \$out"
      depfile = "\$out.d"
      deps = "gcc"
    }
    tool("cxx") {
      command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_pch_cc -c \$in -o \$out"
      description = "CXX \$out"
      depfile = "\$out.d"
      deps = "gcc"
    }
    tool("objc") {
      command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_objc \$cflags_pch_objc -c \$in -o \$out"
      description = "OBJC \$out"
      depfile = "\$out.d"
      deps = "gcc"
    }
    tool("objcxx") {
      command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_objcc \$cflags_pch_objcc -c \$in -o \$out"
      description = "OBJCXX \$out"
      depfile = "\$out.d"
      deps = "gcc"
    }
    tool("alink") {
      command = "rm -f \$out && ./gyp-mac-tool filter-libtool libtool \$libtool_flags -static -o \$out @\$rspfile \$postbuilds"
      description = "LIBTOOL-STATIC \$out"
      rspfile = "\$out.rsp"
      rspfile_content = "\$in"
    }
    tool("solink") {
      command = "if [ ! -e \$lib -o ! -e \${lib}.TOC ] || otool -l \$lib | grep -q LC_REEXPORT_DYLIB ; then $ld -shared \$ldflags -o \$lib @\$rspfile \$solibs \$libs \$postbuilds && { otool -l \$lib | grep LC_ID_DYLIB -A 5; nm -gP \$lib | cut -f1-2 -d' ' | grep -v U\$\$; true; } > \${lib}.TOC; else $ld -shared \$ldflags -o \$lib \$in \$solibs \$libs \$postbuilds && { otool -l \$lib | grep LC_ID_DYLIB -A 5; nm -gP \$lib | cut -f1-2 -d' ' | grep -v U\$\$; true; } > \${lib}.tmp && if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC ; fi; fi"
      description = "SOLINK \$lib"
      rspfile = "\$out.rsp"
      rspfile_content = "\$in"
      #pool = "link_pool"
      restat = "1"
    }
    tool("link") {
      command = "$ld \$ldflags -o \$out @\$rspfile \$solibs \$libs \$postbuilds"
      description = "LINK \$out"
      rspfile = "\$out.rsp"
      rspfile_content = "\$in"
      #pool = "link_pool"
    }
    #tool("infoplist") {
    #  command = "$cc -E -P -Wno-trigraphs -x c \$defines \$in -o \$out && plutil -convert xml1 \$out \$out"
    #  description = "INFOPLIST \$out"
    #}
    #tool("mac_tool") {
    #  command = "\$env ./gyp-mac-tool \$mactool_cmd \$in \$out"
    #  description = "MACTOOL \$mactool_cmd \$in"
    #}
    #tool("package_framework") {
    #  command = "./gyp-mac-tool package-framework \$out \$version \$postbuilds && touch \$out"
    #  description = "PACKAGE FRAMEWORK \$out, POSTBUILDS"
    #}
    tool("stamp") {
      command = "\${postbuilds}touch \$out"
      description = "STAMP \$out"
    }
    tool("copy") {
      command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)"
      description = "COPY \$in \$out"
    }

    toolchain_args() {
      os = invoker.toolchain_os
    }
  }
}

# Toolchain representing the target build (either mac or iOS).
mac_clang_toolchain("clang") {
  toolchain_os = os
}

# This toolchain provides a way for iOS target compiles to reference targets
# compiled for the host system. It just overrides the OS back to "mac".
mac_clang_toolchain("host_clang") {
  toolchain_os = "mac"
}