Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / build / toolchain / gcc_toolchain.gni
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 # This template defines a toolchain for something that works like gcc
6 # (including clang).
7 #
8 # It requires the following variables specifying the executables to run:
9 #  - cc
10 #  - cxx
11 #  - ar
12 #  - ld
13 # and the following which is used in the toolchain_args
14 #  - toolchain_cpu_arch  (What "cpu_arch" should be set to when invoking a
15 #                         build using this toolchain.)
16 #  - toolchain_os  (What "os" should be set to when invoking a build using this
17 #                   toolchain.)
18 #
19 # Optional parameters:
20 #  - libs_section_prefix
21 #  - libs_section_postfix
22 #      The contents of these strings, if specified, will be placed around
23 #      the libs section of the linker line. It allows one to inject libraries
24 #      at the beginning and end for all targets in a toolchain.
25 #  - solink_libs_section_prefix
26 #  - solink_libs_section_postfix
27 #      Same as libs_section_{pre,post}fix except used for solink instead of link.
28 #  - post_solink
29 #      The content of this string, if specified, will be appended to the solink
30 #      command.
31 #  - deps
32 #      Just forwarded to the toolchain definition.
33 #  - is_clang
34 template("gcc_toolchain") {
35   toolchain(target_name) {
36     assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value")
37     assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value")
38     assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value")
39     assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value")
40     assert(defined(invoker.toolchain_cpu_arch),
41            "gcc_toolchain() must specify a \"toolchain_cpu_arch\"")
42     assert(defined(invoker.toolchain_os),
43            "gcc_toolchain() must specify a \"toolchain_os\"")
44
45     # We can't do string interpolation ($ in strings) on things with dots in
46     # them. To allow us to use $cc below, for example, we create copies of
47     # these values in our scope.
48     cc = invoker.cc
49     cxx = invoker.cxx
50     ar = invoker.ar
51     ld = invoker.ld
52
53     # Bring these into our scope for string interpolation with default values.
54     if (defined(invoker.libs_section_prefix)) {
55       libs_section_prefix = invoker.libs_section_prefix
56     } else {
57       libs_section_prefix = ""
58     }
59
60     if (defined(invoker.libs_section_postfix)) {
61       libs_section_postfix = invoker.libs_section_postfix
62     } else {
63       libs_section_postfix = ""
64     }
65
66     if (defined(invoker.solink_libs_section_prefix)) {
67       solink_libs_section_prefix = invoker.solink_libs_section_prefix
68     } else {
69       solink_libs_section_prefix = ""
70     }
71
72     if (defined(invoker.solink_libs_section_postfix)) {
73       solink_libs_section_postfix = invoker.solink_libs_section_postfix
74     } else {
75       solink_libs_section_postfix = ""
76     }
77
78     # Make these apply to all tools below.
79     lib_prefix = "-l"
80     lib_dir_prefix="-L"
81
82     tool("cc") {
83       # cflags_pch_c
84       command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c -c \$in -o \$out"
85       description = "CC \$out"
86       depfile = "\$out.d"
87       depsformat = "gcc"
88     }
89     tool("cxx") {
90       # cflags_pch_cc
91       command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc -c \$in -o \$out"
92       description = "CXX \$out"
93       depfile = "\$out.d"
94       depsformat = "gcc"
95     }
96     tool("alink") {
97       command = "rm -f \$out && $ar rcs \$out @\$rspfile"
98       description = "AR \$out"
99       rspfile = "\$out.rsp"
100       rspfile_content = "\$in"
101     }
102     tool("solink") {
103       rspfile = "\$out.rsp"
104       rspfile_content = "-Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive $solink_libs_section_prefix \$libs $solink_libs_section_postfix"
105
106       # TODO(cjhopman): There needs to be a way for gn to correctly figure out
107       # the outputs of a solink command.
108
109       link_command = "$ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname @\$rspfile"
110       toc_command = "{ readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.tmp"
111       replace_command = "if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC; fi"
112       command = "$link_command && $toc_command && $replace_command"
113
114       if (defined(invoker.postsolink)) {
115         command += " && " + invoker.postsolink
116       }
117
118       description = "SOLINK \$lib"
119       #pool = "link_pool"
120       restat = "1"
121     }
122     tool("link") {
123       command = "$ld \$ldflags -o \$out -Wl,--start-group @\$rspfile \$solibs -Wl,--end-group $libs_section_prefix \$libs $libs_section_postfix"
124       description = "LINK \$out"
125       rspfile = "\$out.rsp"
126       rspfile_content = "\$in"
127       #pool = "link_pool"
128     }
129     tool("stamp") {
130       command = "\${postbuilds}touch \$out"
131       description = "STAMP \$out"
132     }
133     tool("copy") {
134       command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)"
135       description = "COPY \$in \$out"
136     }
137
138     # When invoking this toolchain not as the default one, these args will be
139     # passed to the build. They are ignored when this is the default toolchain.
140     toolchain_args() {
141       cpu_arch = invoker.toolchain_cpu_arch
142       os = invoker.toolchain_os
143       if (defined(invoker.is_clang)) {
144         is_clang = invoker.is_clang
145       }
146     }
147
148     if (defined(invoker.deps)) {
149       deps = invoker.deps
150     }
151   }
152 }