blob: c3372fe6f1fcf3c62d28ba16661f6d24b8453d21 [file] [log] [blame]
Colin Cross023f1e82015-11-23 16:15:10 -08001// Copyright 2015 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 cc
16
17import (
18 "strings"
19
20 "android/soong/common"
21)
22
23var (
24 mipsCflags = []string{
25 "-fno-exceptions", // from build/core/combo/select.mk
26 "-Wno-multichar", // from build/core/combo/select.mk
27 "-O2",
28 "-fomit-frame-pointer",
29 "-fno-strict-aliasing",
30 "-funswitch-loops",
31 "-U__unix",
32 "-U__unix__",
33 "-Umips",
34 "-ffunction-sections",
35 "-fdata-sections",
36 "-funwind-tables",
37 "-Wa,--noexecstack",
38 "-Werror=format-security",
39 "-D_FORTIFY_SOURCE=2",
40 "-no-canonical-prefixes",
41 "-fno-canonical-system-headers",
42
43 // TARGET_RELEASE_CFLAGS
44 "-DNDEBUG",
45 "-g",
46 "-Wstrict-aliasing=2",
47 "-fgcse-after-reload",
48 "-frerun-cse-after-loop",
49 "-frename-registers",
50 }
51
52 mipsCppflags = []string{
53 "-fvisibility-inlines-hidden",
54 }
55
56 mipsLdflags = []string{
57 "-Wl,-z,noexecstack",
58 "-Wl,-z,relro",
59 "-Wl,-z,now",
60 "-Wl,--build-id=md5",
61 "-Wl,--warn-shared-textrel",
62 "-Wl,--fatal-warnings",
63 "-Wl,--allow-shlib-undefined",
64 }
65
66 mipsToolchainLdflags = []string{
67 "-Wl,-melf32ltsmip",
68 }
69
70 mipsArchVariantCflags = map[string][]string{
71 "mips32-fp": []string{
72 "-mips32",
73 "-mfp32",
74 "-modd-spreg",
75 "-mno-synci",
76 },
77 "mips32r2-fp": []string{
78 "-mips32r2",
79 "-mfp32",
80 "-modd-spreg",
81 "-mno-synci",
82 },
83 "mips32r2-fp-xburst": []string{
84 "-mips32r2",
85 "-mfp32",
86 "-modd-spreg",
87 "-mno-fused-madd",
88 "-Wa,-mmxu",
89 "-mno-synci",
90 },
91 "mips32r2dsp-fp": []string{
92 "-mips32r2",
93 "-mfp32",
94 "-modd-spreg",
95 "-mdsp",
96 "-msynci",
97 },
98 "mips32r2dspr2-fp": []string{
99 "-mips32r2",
100 "-mfp32",
101 "-modd-spreg",
102 "-mdspr2",
103 "-msynci",
104 },
105 "mips32r6": []string{
106 "-mips32r6",
107 "-mfp64",
108 "-mno-odd-spreg",
109 "-msynci",
110 },
111 }
112)
113
114func init() {
115 common.RegisterArchFeatures(common.Mips, "mips32r6",
116 "rev6")
117
118 pctx.StaticVariable("mipsGccVersion", "4.9")
119
120 pctx.StaticVariable("mipsGccRoot",
121 "prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${armGccVersion}")
122
123 pctx.StaticVariable("mipsGccTriple", "mips64el-linux-android")
124
125 pctx.StaticVariable("mipsToolchainLdflags", strings.Join(mipsToolchainLdflags, " "))
126 pctx.StaticVariable("mipsCflags", strings.Join(mipsCflags, " "))
127 pctx.StaticVariable("mipsLdflags", strings.Join(mipsLdflags, " "))
128 pctx.StaticVariable("mipsCppflags", strings.Join(mipsCppflags, " "))
129 pctx.StaticVariable("mipsIncludeFlags", strings.Join([]string{
130 "-isystem ${LibcRoot}/arch-mips/include",
131 "-isystem ${LibcRoot}/include",
132 "-isystem ${LibcRoot}/kernel/uapi",
133 "-isystem ${LibcRoot}/kernel/uapi/asm-mips",
134 "-isystem ${LibmRoot}/include",
135 "-isystem ${LibmRoot}/include/mips",
136 }, " "))
137
138 // Clang cflags
139 pctx.StaticVariable("mipsClangTriple", "mipsel-linux-android")
140 pctx.StaticVariable("mipsClangCflags", strings.Join(clangFilterUnknownCflags(mipsCflags), " "))
141 pctx.StaticVariable("mipsClangLdflags", strings.Join(clangFilterUnknownCflags(mipsLdflags), " "))
142 pctx.StaticVariable("mipsClangCppflags", strings.Join(clangFilterUnknownCflags(mipsCppflags), " "))
143
144 // Extended cflags
145
146 // Architecture variant cflags
147 for variant, cflags := range mipsArchVariantCflags {
148 pctx.StaticVariable("mips"+variant+"VariantCflags", strings.Join(cflags, " "))
149 pctx.StaticVariable("mips"+variant+"VariantClangCflags",
150 strings.Join(clangFilterUnknownCflags(cflags), " "))
151 }
152}
153
154type toolchainMips struct {
155 toolchain32Bit
156 cflags, clangCflags string
157 toolchainCflags, toolchainClangCflags string
158}
159
160func (t *toolchainMips) Name() string {
161 return "mips"
162}
163
164func (t *toolchainMips) GccRoot() string {
165 return "${mipsGccRoot}"
166}
167
168func (t *toolchainMips) GccTriple() string {
169 return "${mipsGccTriple}"
170}
171
172func (t *toolchainMips) GccVersion() string {
173 return "${mipsGccVersion}"
174}
175
176func (t *toolchainMips) ToolchainLdflags() string {
177 return "${mipsToolchainLdflags}"
178}
179
180func (t *toolchainMips) ToolchainCflags() string {
181 return t.toolchainCflags
182}
183
184func (t *toolchainMips) Cflags() string {
185 return t.cflags
186}
187
188func (t *toolchainMips) Cppflags() string {
189 return "${mipsCppflags}"
190}
191
192func (t *toolchainMips) Ldflags() string {
193 return "${mipsLdflags}"
194}
195
196func (t *toolchainMips) IncludeFlags() string {
197 return "${mipsIncludeFlags}"
198}
199
200func (t *toolchainMips) ClangTriple() string {
201 return "${mipsClangTriple}"
202}
203
204func (t *toolchainMips) ToolchainClangCflags() string {
205 return t.toolchainClangCflags
206}
207
208func (t *toolchainMips) ClangCflags() string {
209 return t.clangCflags
210}
211
212func (t *toolchainMips) ClangCppflags() string {
213 return "${mipsClangCppflags}"
214}
215
216func (t *toolchainMips) ClangLdflags() string {
217 return "${mipsClangLdflags}"
218}
219
220func mipsToolchainFactory(arch common.Arch) Toolchain {
221 return &toolchainMips{
222 cflags: "${mipsCflags}",
223 clangCflags: "${mipsClangCflags}",
224 toolchainCflags: "${mips" + arch.ArchVariant + "VariantCflags}",
225 toolchainClangCflags: "${mips" + arch.ArchVariant + "VariantClangCflags}",
226 }
227}
228
229func init() {
Dan Willemsen490fd492015-11-24 17:53:15 -0800230 registerDeviceToolchainFactory(common.Mips, mipsToolchainFactory)
Colin Cross023f1e82015-11-23 16:15:10 -0800231}