Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / build / toolchain / mac / BUILD.gn
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
11 # Should only be running on Mac.
12 assert(is_mac || is_ios)
13
14 import("//build/toolchain/clang.gni")
15 import("//build/toolchain/goma.gni")
16
17 if (is_clang) {
18   cc = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang",
19                    root_build_dir)
20   cxx = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang++",
21                     root_build_dir)
22 } else {
23   cc = "gcc"
24   cxx = "g++"
25 }
26 ld = cxx
27
28 # This will copy the gyp-mac-tool to the build directory. We pass in the source
29 # file of the win tool.
30 gyp_mac_tool_source =
31   rebase_path("//tools/gyp/pylib/gyp/mac_tool.py", root_build_dir)
32 exec_script("setup_toolchain.py", [ gyp_mac_tool_source ], "value")
33
34 # Shared toolchain definition. Invocations should set toolchain_os to set the
35 # build args in this definition.
36 template("mac_clang_toolchain") {
37   toolchain(target_name) {
38     assert(defined(invoker.cc),
39            "mac_clang_toolchain() must specify a \"cc\" value")
40     assert(defined(invoker.cxx),
41            "mac_clang_toolchain() must specify a \"cxx\" value")
42     assert(defined(invoker.ld),
43            "mac_clang_toolchain() must specify a \"ld\" value")
44     assert(defined(invoker.toolchain_os),
45            "mac_clang_toolchain() must specify a \"toolchain_os\"")
46
47     # We can't do string interpolation ($ in strings) on things with dots in
48     # them. To allow us to use $cc below, for example, we create copies of
49     # these values in our scope.
50     cc = invoker.cc
51     cxx = invoker.cxx
52     ld = invoker.ld
53
54     # Make these apply to all tools below.
55     lib_prefix = "-l"
56     lib_dir_prefix="-L"
57
58     tool("cc") {
59       command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_pch_c -c \$in -o \$out"
60       description = "CC \$out"
61       depfile = "\$out.d"
62       deps = "gcc"
63     }
64     tool("cxx") {
65       command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_pch_cc -c \$in -o \$out"
66       description = "CXX \$out"
67       depfile = "\$out.d"
68       deps = "gcc"
69     }
70     tool("objc") {
71       command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_objc \$cflags_pch_objc -c \$in -o \$out"
72       description = "OBJC \$out"
73       depfile = "\$out.d"
74       deps = "gcc"
75     }
76     tool("objcxx") {
77       command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_objcc \$cflags_pch_objcc -c \$in -o \$out"
78       description = "OBJCXX \$out"
79       depfile = "\$out.d"
80       deps = "gcc"
81     }
82     tool("alink") {
83       command = "rm -f \$out && ./gyp-mac-tool filter-libtool libtool \$libtool_flags -static -o \$out \$in \$postbuilds"
84       description = "LIBTOOL-STATIC \$out, POSTBUILDS"
85     }
86     tool("solink") {
87       command = "if [ ! -e \$lib -o ! -e \${lib}.TOC ] || otool -l \$lib | grep -q LC_REEXPORT_DYLIB ; then $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}.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"
88       description = "SOLINK \$lib, POSTBUILDS"
89       #pool = "link_pool"
90       restat = "1"
91     }
92     tool("link") {
93       command = "$ld \$ldflags -o \$out \$in \$solibs \$libs \$postbuilds"
94       description = "LINK \$out, POSTBUILDS"
95       #pool = "link_pool"
96     }
97     #tool("infoplist") {
98     #  command = "$cc -E -P -Wno-trigraphs -x c \$defines \$in -o \$out && plutil -convert xml1 \$out \$out"
99     #  description = "INFOPLIST \$out"
100     #}
101     #tool("mac_tool") {
102     #  command = "\$env ./gyp-mac-tool \$mactool_cmd \$in \$out"
103     #  description = "MACTOOL \$mactool_cmd \$in"
104     #}
105     #tool("package_framework") {
106     #  command = "./gyp-mac-tool package-framework \$out \$version \$postbuilds && touch \$out"
107     #  description = "PACKAGE FRAMEWORK \$out, POSTBUILDS"
108     #}
109     tool("stamp") {
110       command = "\${postbuilds}touch \$out"
111       description = "STAMP \$out"
112     }
113     tool("copy") {
114       command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)"
115       description = "COPY \$in \$out"
116     }
117
118     toolchain_args() {
119       os = invoker.toolchain_os
120     }
121   }
122 }
123
124 # Toolchain representing the target build (either mac or iOS).
125 mac_clang_toolchain("clang") {
126   toolchain_os = os
127 }
128
129 # This toolchain provides a way for iOS target compiles to reference targets
130 # compiled for the host system. It just overrides the OS back to "mac".
131 mac_clang_toolchain("host_clang") {
132   toolchain_os = "mac"
133 }