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