Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / 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
23   # Set the GYP header for all toolchains when running under Clang.
24   if (is_gyp) {
25     make_global_settings = make_clang_global_settings
26
27     if (use_goma) {
28       # There is a TODO(yyanagisawa) in common.gypi about the make generator not
29       # supporting CC_wrapper without CC. As a result, we must add a condition
30       # when on the generator when we're not explicitly setting the variables
31       # above (which happens when gyp_header is empty at this point).
32       #
33       # GYP will interpret the file once for each generator, so we have to write
34       # this condition into the GYP file since the user could have more than one
35       # generator set.
36       gyp_header =
37         "'conditions':" +
38         "[['\"<(GENERATOR)\"==\"ninja\"', { 'make_global_settings': [" +
39         make_global_settings +
40         make_goma_global_settings +
41         "]}]],"
42     } else {
43       gyp_header = "'make_global_settings': [" + make_global_settings + "],"
44     }
45   }
46 } else {
47   cc = "gcc"
48   cxx = "g++"
49 }
50 ld = cxx
51
52 # This will copy the gyp-mac-tool to the build directory. We pass in the source
53 # file of the win tool.
54 gyp_mac_tool_source =
55   rebase_path("//tools/gyp/pylib/gyp/mac_tool.py", root_build_dir)
56 exec_script("setup_toolchain.py", [ gyp_mac_tool_source ], "value")
57
58 # Shared toolchain definition. Invocations should set toolchain_os to set the
59 # build args in this definition.
60 template("mac_clang_toolchain") {
61   toolchain(target_name) {
62     # Make these apply to all tools below.
63     lib_prefix = "-l"
64     lib_dir_prefix="-L"
65
66     tool("cc") {
67       command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_pch_c -c \$in -o \$out"
68       description = "CC \$out"
69       depfile = "\$out.d"
70       deps = "gcc"
71     }
72     tool("cxx") {
73       command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_pch_cc -c \$in -o \$out"
74       description = "CXX \$out"
75       depfile = "\$out.d"
76       deps = "gcc"
77     }
78     tool("objc") {
79       command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_objc \$cflags_pch_objc -c \$in -o \$out"
80       description = "OBJC \$out"
81       depfile = "\$out.d"
82       deps = "gcc"
83     }
84     tool("objcxx") {
85       command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_objcc \$cflags_pch_objcc -c \$in -o \$out"
86       description = "OBJCXX \$out"
87       depfile = "\$out.d"
88       deps = "gcc"
89     }
90     tool("alink") {
91       command = "rm -f \$out && ./gyp-mac-tool filter-libtool libtool \$libtool_flags -static -o \$out \$in \$postbuilds"
92       description = "LIBTOOL-STATIC \$out, POSTBUILDS"
93     }
94     tool("solink") {
95       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"
96       description = "SOLINK \$lib, POSTBUILDS"
97       #pool = "link_pool"
98       restat = "1"
99     }
100     tool("link") {
101       command = "$ld \$ldflags -o \$out \$in \$solibs \$libs \$postbuilds"
102       description = "LINK \$out, POSTBUILDS"
103       #pool = "link_pool"
104     }
105     #tool("infoplist") {
106     #  command = "$cc -E -P -Wno-trigraphs -x c \$defines \$in -o \$out && plutil -convert xml1 \$out \$out"
107     #  description = "INFOPLIST \$out"
108     #}
109     #tool("mac_tool") {
110     #  command = "\$env ./gyp-mac-tool \$mactool_cmd \$in \$out"
111     #  description = "MACTOOL \$mactool_cmd \$in"
112     #}
113     #tool("package_framework") {
114     #  command = "./gyp-mac-tool package-framework \$out \$version \$postbuilds && touch \$out"
115     #  description = "PACKAGE FRAMEWORK \$out, POSTBUILDS"
116     #}
117     tool("stamp") {
118       command = "\${postbuilds}touch \$out"
119       description = "STAMP \$out"
120     }
121     tool("copy") {
122       command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)"
123       description = "COPY \$in \$out"
124     }
125
126     toolchain_args() {
127       os = toolchain_os
128     }
129   }
130 }
131
132 # Toolchain representing the target build (either mac or iOS).
133 mac_clang_toolchain("clang") {
134   toolchain_os = os
135 }
136
137 # This toolchain provides a way for iOS target compiles to reference targets
138 # compiled for the host system. It just overrides the OS back to "mac".
139 mac_clang_toolchain("host_clang") {
140   toolchain_os = "mac"
141 }