blob: 354500eb0e0821710622292c7b0f57222628dd7e [file] [log] [blame]
Colin Crossb98c8b02016-07-29 13:44:28 -07001// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package config
16
17import (
18 "strings"
19
20 "android/soong/android"
21)
22
23var (
24 linuxCflags = []string{
Colin Crossb98c8b02016-07-29 13:44:28 -070025 "-fdiagnostics-color",
26
27 "-Wa,--noexecstack",
28
29 "-fPIC",
Colin Crossb98c8b02016-07-29 13:44:28 -070030
31 "-U_FORTIFY_SOURCE",
32 "-D_FORTIFY_SOURCE=2",
33 "-fstack-protector",
34
35 // Workaround differences in inttypes.h between host and target.
36 //See bug 12708004.
37 "-D__STDC_FORMAT_MACROS",
38 "-D__STDC_CONSTANT_MACROS",
Colin Crossb98c8b02016-07-29 13:44:28 -070039 }
40
41 linuxLdflags = []string{
42 "-Wl,-z,noexecstack",
43 "-Wl,-z,relro",
44 "-Wl,-z,now",
45 "-Wl,--no-undefined-version",
46 }
47
48 // Extended cflags
49 linuxX86Cflags = []string{
50 "-msse3",
51 "-mfpmath=sse",
52 "-m32",
53 "-march=prescott",
54 "-D_FILE_OFFSET_BITS=64",
55 "-D_LARGEFILE_SOURCE=1",
56 }
57
58 linuxX8664Cflags = []string{
59 "-m64",
60 }
61
62 linuxX86Ldflags = []string{
63 "-m32",
64 }
65
66 linuxX8664Ldflags = []string{
67 "-m64",
68 }
69
70 linuxClangCflags = append(ClangFilterUnknownCflags(linuxCflags), []string{
71 "--gcc-toolchain=${LinuxGccRoot}",
72 "--sysroot ${LinuxGccRoot}/sysroot",
73 "-fstack-protector-strong",
74 }...)
75
76 linuxClangLdflags = append(ClangFilterUnknownCflags(linuxLdflags), []string{
77 "--gcc-toolchain=${LinuxGccRoot}",
78 "--sysroot ${LinuxGccRoot}/sysroot",
79 }...)
80
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070081 linuxClangLldflags = ClangFilterUnknownLldflags(linuxClangLdflags)
82
Colin Crossb98c8b02016-07-29 13:44:28 -070083 linuxX86ClangLdflags = append(ClangFilterUnknownCflags(linuxX86Ldflags), []string{
84 "-B${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}/32",
85 "-L${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}/32",
86 "-L${LinuxGccRoot}/${LinuxGccTriple}/lib32",
87 }...)
88
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070089 linuxX86ClangLldflags = ClangFilterUnknownLldflags(linuxX86ClangLdflags)
90
Colin Crossb98c8b02016-07-29 13:44:28 -070091 linuxX8664ClangLdflags = append(ClangFilterUnknownCflags(linuxX8664Ldflags), []string{
92 "-B${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}",
93 "-L${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}",
94 "-L${LinuxGccRoot}/${LinuxGccTriple}/lib64",
95 }...)
96
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070097 linuxX8664ClangLldflags = ClangFilterUnknownLldflags(linuxX8664ClangLdflags)
98
Colin Crossb98c8b02016-07-29 13:44:28 -070099 linuxClangCppflags = []string{
100 "-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}",
101 "-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}/backward",
102 }
103
104 linuxX86ClangCppflags = []string{
105 "-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}/${LinuxGccTriple}/32",
106 }
107
108 linuxX8664ClangCppflags = []string{
109 "-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}/${LinuxGccTriple}",
110 }
111
112 linuxAvailableLibraries = addPrefix([]string{
113 "c",
114 "dl",
115 "gcc",
116 "gcc_s",
117 "m",
118 "ncurses",
119 "pthread",
120 "resolv",
121 "rt",
122 "util",
Colin Crossb98c8b02016-07-29 13:44:28 -0700123 }, "-l")
124)
125
126const (
127 linuxGccVersion = "4.8"
128)
129
130func init() {
131 pctx.StaticVariable("LinuxGccVersion", linuxGccVersion)
132
133 pctx.SourcePathVariable("LinuxGccRoot",
134 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-linux-glibc2.15-${LinuxGccVersion}")
135
136 pctx.StaticVariable("LinuxGccTriple", "x86_64-linux")
137
138 pctx.StaticVariable("LinuxCflags", strings.Join(linuxCflags, " "))
139 pctx.StaticVariable("LinuxLdflags", strings.Join(linuxLdflags, " "))
140
141 pctx.StaticVariable("LinuxClangCflags", strings.Join(linuxClangCflags, " "))
142 pctx.StaticVariable("LinuxClangLdflags", strings.Join(linuxClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700143 pctx.StaticVariable("LinuxClangLldflags", strings.Join(linuxClangLldflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -0700144 pctx.StaticVariable("LinuxClangCppflags", strings.Join(linuxClangCppflags, " "))
145
146 // Extended cflags
147 pctx.StaticVariable("LinuxX86Cflags", strings.Join(linuxX86Cflags, " "))
148 pctx.StaticVariable("LinuxX8664Cflags", strings.Join(linuxX8664Cflags, " "))
149 pctx.StaticVariable("LinuxX86Ldflags", strings.Join(linuxX86Ldflags, " "))
150 pctx.StaticVariable("LinuxX8664Ldflags", strings.Join(linuxX8664Ldflags, " "))
151
152 pctx.StaticVariable("LinuxX86ClangCflags",
153 strings.Join(ClangFilterUnknownCflags(linuxX86Cflags), " "))
154 pctx.StaticVariable("LinuxX8664ClangCflags",
155 strings.Join(ClangFilterUnknownCflags(linuxX8664Cflags), " "))
156 pctx.StaticVariable("LinuxX86ClangLdflags", strings.Join(linuxX86ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700157 pctx.StaticVariable("LinuxX86ClangLldflags", strings.Join(linuxX86ClangLldflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -0700158 pctx.StaticVariable("LinuxX8664ClangLdflags", strings.Join(linuxX8664ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700159 pctx.StaticVariable("LinuxX8664ClangLldflags", strings.Join(linuxX8664ClangLldflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -0700160 pctx.StaticVariable("LinuxX86ClangCppflags", strings.Join(linuxX86ClangCppflags, " "))
161 pctx.StaticVariable("LinuxX8664ClangCppflags", strings.Join(linuxX8664ClangCppflags, " "))
Greg Hartman09302be2017-10-04 17:31:43 -0700162 // Yasm flags
163 pctx.StaticVariable("LinuxX86YasmFlags", "-f elf32 -m x86")
164 pctx.StaticVariable("LinuxX8664YasmFlags", "-f elf64 -m amd64")
Colin Crossb98c8b02016-07-29 13:44:28 -0700165}
166
167type toolchainLinux struct {
168 cFlags, ldFlags string
169}
170
171type toolchainLinuxX86 struct {
172 toolchain32Bit
173 toolchainLinux
174}
175
176type toolchainLinuxX8664 struct {
177 toolchain64Bit
178 toolchainLinux
179}
180
181func (t *toolchainLinuxX86) Name() string {
182 return "x86"
183}
184
185func (t *toolchainLinuxX8664) Name() string {
186 return "x86_64"
187}
188
189func (t *toolchainLinux) GccRoot() string {
190 return "${config.LinuxGccRoot}"
191}
192
193func (t *toolchainLinux) GccTriple() string {
194 return "${config.LinuxGccTriple}"
195}
196
197func (t *toolchainLinux) GccVersion() string {
198 return linuxGccVersion
199}
200
201func (t *toolchainLinuxX86) Cflags() string {
202 return "${config.LinuxCflags} ${config.LinuxX86Cflags}"
203}
204
205func (t *toolchainLinuxX8664) Cflags() string {
206 return "${config.LinuxCflags} ${config.LinuxX8664Cflags}"
207}
208
209func (t *toolchainLinux) Cppflags() string {
210 return ""
211}
212
213func (t *toolchainLinuxX86) Ldflags() string {
214 return "${config.LinuxLdflags} ${config.LinuxX86Ldflags}"
215}
216
217func (t *toolchainLinuxX8664) Ldflags() string {
218 return "${config.LinuxLdflags} ${config.LinuxX8664Ldflags}"
219}
220
221func (t *toolchainLinux) IncludeFlags() string {
222 return ""
223}
224
225func (t *toolchainLinuxX86) ClangTriple() string {
226 return "i686-linux-gnu"
227}
228
229func (t *toolchainLinuxX86) ClangCflags() string {
230 return "${config.LinuxClangCflags} ${config.LinuxX86ClangCflags}"
231}
232
233func (t *toolchainLinuxX86) ClangCppflags() string {
234 return "${config.LinuxClangCppflags} ${config.LinuxX86ClangCppflags}"
235}
236
237func (t *toolchainLinuxX8664) ClangTriple() string {
238 return "x86_64-linux-gnu"
239}
240
241func (t *toolchainLinuxX8664) ClangCflags() string {
242 return "${config.LinuxClangCflags} ${config.LinuxX8664ClangCflags}"
243}
244
245func (t *toolchainLinuxX8664) ClangCppflags() string {
246 return "${config.LinuxClangCppflags} ${config.LinuxX8664ClangCppflags}"
247}
248
249func (t *toolchainLinuxX86) ClangLdflags() string {
250 return "${config.LinuxClangLdflags} ${config.LinuxX86ClangLdflags}"
251}
252
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700253func (t *toolchainLinuxX86) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700254 return "${config.LinuxClangLldflags} ${config.LinuxX86ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700255}
256
Colin Crossb98c8b02016-07-29 13:44:28 -0700257func (t *toolchainLinuxX8664) ClangLdflags() string {
258 return "${config.LinuxClangLdflags} ${config.LinuxX8664ClangLdflags}"
259}
260
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700261func (t *toolchainLinuxX8664) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700262 return "${config.LinuxClangLldflags} ${config.LinuxX8664ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700263}
264
Greg Hartman09302be2017-10-04 17:31:43 -0700265func (t *toolchainLinuxX86) YasmFlags() string {
266 return "${config.LinuxX86YasmFlags}"
267}
268
269func (t *toolchainLinuxX8664) YasmFlags() string {
270 return "${config.LinuxX8664YasmFlags}"
271}
272
Colin Crossb98c8b02016-07-29 13:44:28 -0700273func (t *toolchainLinux) AvailableLibraries() []string {
274 return linuxAvailableLibraries
275}
276
Dan Willemsen2e47b342016-11-17 01:02:25 -0800277func (t *toolchainLinux) Bionic() bool {
278 return false
279}
280
Colin Crossb98c8b02016-07-29 13:44:28 -0700281var toolchainLinuxX86Singleton Toolchain = &toolchainLinuxX86{}
282var toolchainLinuxX8664Singleton Toolchain = &toolchainLinuxX8664{}
283
284func linuxX86ToolchainFactory(arch android.Arch) Toolchain {
285 return toolchainLinuxX86Singleton
286}
287
288func linuxX8664ToolchainFactory(arch android.Arch) Toolchain {
289 return toolchainLinuxX8664Singleton
290}
291
292func init() {
293 registerToolchainFactory(android.Linux, android.X86, linuxX86ToolchainFactory)
294 registerToolchainFactory(android.Linux, android.X86_64, linuxX8664ToolchainFactory)
295}