blob: ba6b81aa18904ce0d589935fb3b12fe4e387df6f [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
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800114const (
115 mipsGccVersion = "4.9"
116)
117
Colin Cross023f1e82015-11-23 16:15:10 -0800118func init() {
119 common.RegisterArchFeatures(common.Mips, "mips32r6",
120 "rev6")
121
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800122 pctx.StaticVariable("mipsGccVersion", mipsGccVersion)
Colin Cross023f1e82015-11-23 16:15:10 -0800123
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124 pctx.SourcePathVariable("mipsGccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800125 "prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${mipsGccVersion}")
Colin Cross023f1e82015-11-23 16:15:10 -0800126
127 pctx.StaticVariable("mipsGccTriple", "mips64el-linux-android")
128
129 pctx.StaticVariable("mipsToolchainLdflags", strings.Join(mipsToolchainLdflags, " "))
130 pctx.StaticVariable("mipsCflags", strings.Join(mipsCflags, " "))
131 pctx.StaticVariable("mipsLdflags", strings.Join(mipsLdflags, " "))
132 pctx.StaticVariable("mipsCppflags", strings.Join(mipsCppflags, " "))
133 pctx.StaticVariable("mipsIncludeFlags", strings.Join([]string{
134 "-isystem ${LibcRoot}/arch-mips/include",
135 "-isystem ${LibcRoot}/include",
136 "-isystem ${LibcRoot}/kernel/uapi",
137 "-isystem ${LibcRoot}/kernel/uapi/asm-mips",
138 "-isystem ${LibmRoot}/include",
139 "-isystem ${LibmRoot}/include/mips",
140 }, " "))
141
142 // Clang cflags
143 pctx.StaticVariable("mipsClangTriple", "mipsel-linux-android")
144 pctx.StaticVariable("mipsClangCflags", strings.Join(clangFilterUnknownCflags(mipsCflags), " "))
145 pctx.StaticVariable("mipsClangLdflags", strings.Join(clangFilterUnknownCflags(mipsLdflags), " "))
146 pctx.StaticVariable("mipsClangCppflags", strings.Join(clangFilterUnknownCflags(mipsCppflags), " "))
147
148 // Extended cflags
149
150 // Architecture variant cflags
151 for variant, cflags := range mipsArchVariantCflags {
152 pctx.StaticVariable("mips"+variant+"VariantCflags", strings.Join(cflags, " "))
153 pctx.StaticVariable("mips"+variant+"VariantClangCflags",
154 strings.Join(clangFilterUnknownCflags(cflags), " "))
155 }
156}
157
158type toolchainMips struct {
159 toolchain32Bit
160 cflags, clangCflags string
161 toolchainCflags, toolchainClangCflags string
162}
163
164func (t *toolchainMips) Name() string {
165 return "mips"
166}
167
168func (t *toolchainMips) GccRoot() string {
169 return "${mipsGccRoot}"
170}
171
172func (t *toolchainMips) GccTriple() string {
173 return "${mipsGccTriple}"
174}
175
176func (t *toolchainMips) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800177 return mipsGccVersion
Colin Cross023f1e82015-11-23 16:15:10 -0800178}
179
180func (t *toolchainMips) ToolchainLdflags() string {
181 return "${mipsToolchainLdflags}"
182}
183
184func (t *toolchainMips) ToolchainCflags() string {
185 return t.toolchainCflags
186}
187
188func (t *toolchainMips) Cflags() string {
189 return t.cflags
190}
191
192func (t *toolchainMips) Cppflags() string {
193 return "${mipsCppflags}"
194}
195
196func (t *toolchainMips) Ldflags() string {
197 return "${mipsLdflags}"
198}
199
200func (t *toolchainMips) IncludeFlags() string {
201 return "${mipsIncludeFlags}"
202}
203
204func (t *toolchainMips) ClangTriple() string {
205 return "${mipsClangTriple}"
206}
207
208func (t *toolchainMips) ToolchainClangCflags() string {
209 return t.toolchainClangCflags
210}
211
212func (t *toolchainMips) ClangCflags() string {
213 return t.clangCflags
214}
215
216func (t *toolchainMips) ClangCppflags() string {
217 return "${mipsClangCppflags}"
218}
219
220func (t *toolchainMips) ClangLdflags() string {
221 return "${mipsClangLdflags}"
222}
223
224func mipsToolchainFactory(arch common.Arch) Toolchain {
225 return &toolchainMips{
226 cflags: "${mipsCflags}",
227 clangCflags: "${mipsClangCflags}",
228 toolchainCflags: "${mips" + arch.ArchVariant + "VariantCflags}",
229 toolchainClangCflags: "${mips" + arch.ArchVariant + "VariantClangCflags}",
230 }
231}
232
233func init() {
Dan Willemsen490fd492015-11-24 17:53:15 -0800234 registerDeviceToolchainFactory(common.Mips, mipsToolchainFactory)
Colin Cross023f1e82015-11-23 16:15:10 -0800235}