github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/cc/config/x86_linux_host.go (about) 1 // 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 15 package config 16 17 import ( 18 "strings" 19 20 "android/soong/android" 21 ) 22 23 var ( 24 linuxCflags = []string{ 25 "-fdiagnostics-color", 26 27 "-Wa,--noexecstack", 28 29 "-fPIC", 30 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", 39 } 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 81 linuxX86ClangLdflags = append(ClangFilterUnknownCflags(linuxX86Ldflags), []string{ 82 "-B${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}/32", 83 "-L${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}/32", 84 "-L${LinuxGccRoot}/${LinuxGccTriple}/lib32", 85 }...) 86 87 linuxX8664ClangLdflags = append(ClangFilterUnknownCflags(linuxX8664Ldflags), []string{ 88 "-B${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}", 89 "-L${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}", 90 "-L${LinuxGccRoot}/${LinuxGccTriple}/lib64", 91 }...) 92 93 linuxClangCppflags = []string{ 94 "-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}", 95 "-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}/backward", 96 } 97 98 linuxX86ClangCppflags = []string{ 99 "-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}/${LinuxGccTriple}/32", 100 } 101 102 linuxX8664ClangCppflags = []string{ 103 "-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}/${LinuxGccTriple}", 104 } 105 106 linuxAvailableLibraries = addPrefix([]string{ 107 "c", 108 "dl", 109 "gcc", 110 "gcc_s", 111 "m", 112 "ncurses", 113 "pthread", 114 "resolv", 115 "rt", 116 "util", 117 }, "-l") 118 ) 119 120 const ( 121 linuxGccVersion = "4.8" 122 ) 123 124 func init() { 125 pctx.StaticVariable("LinuxGccVersion", linuxGccVersion) 126 127 pctx.SourcePathVariable("LinuxGccRoot", 128 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-linux-glibc2.15-${LinuxGccVersion}") 129 130 pctx.StaticVariable("LinuxGccTriple", "x86_64-linux") 131 132 pctx.StaticVariable("LinuxCflags", strings.Join(linuxCflags, " ")) 133 pctx.StaticVariable("LinuxLdflags", strings.Join(linuxLdflags, " ")) 134 135 pctx.StaticVariable("LinuxClangCflags", strings.Join(linuxClangCflags, " ")) 136 pctx.StaticVariable("LinuxClangLdflags", strings.Join(linuxClangLdflags, " ")) 137 pctx.StaticVariable("LinuxClangCppflags", strings.Join(linuxClangCppflags, " ")) 138 139 // Extended cflags 140 pctx.StaticVariable("LinuxX86Cflags", strings.Join(linuxX86Cflags, " ")) 141 pctx.StaticVariable("LinuxX8664Cflags", strings.Join(linuxX8664Cflags, " ")) 142 pctx.StaticVariable("LinuxX86Ldflags", strings.Join(linuxX86Ldflags, " ")) 143 pctx.StaticVariable("LinuxX8664Ldflags", strings.Join(linuxX8664Ldflags, " ")) 144 145 pctx.StaticVariable("LinuxX86ClangCflags", 146 strings.Join(ClangFilterUnknownCflags(linuxX86Cflags), " ")) 147 pctx.StaticVariable("LinuxX8664ClangCflags", 148 strings.Join(ClangFilterUnknownCflags(linuxX8664Cflags), " ")) 149 pctx.StaticVariable("LinuxX86ClangLdflags", strings.Join(linuxX86ClangLdflags, " ")) 150 pctx.StaticVariable("LinuxX8664ClangLdflags", strings.Join(linuxX8664ClangLdflags, " ")) 151 pctx.StaticVariable("LinuxX86ClangCppflags", strings.Join(linuxX86ClangCppflags, " ")) 152 pctx.StaticVariable("LinuxX8664ClangCppflags", strings.Join(linuxX8664ClangCppflags, " ")) 153 // Yasm flags 154 pctx.StaticVariable("LinuxX86YasmFlags", "-f elf32 -m x86") 155 pctx.StaticVariable("LinuxX8664YasmFlags", "-f elf64 -m amd64") 156 } 157 158 type toolchainLinux struct { 159 cFlags, ldFlags string 160 } 161 162 type toolchainLinuxX86 struct { 163 toolchain32Bit 164 toolchainLinux 165 } 166 167 type toolchainLinuxX8664 struct { 168 toolchain64Bit 169 toolchainLinux 170 } 171 172 func (t *toolchainLinuxX86) Name() string { 173 return "x86" 174 } 175 176 func (t *toolchainLinuxX8664) Name() string { 177 return "x86_64" 178 } 179 180 func (t *toolchainLinux) GccRoot() string { 181 return "${config.LinuxGccRoot}" 182 } 183 184 func (t *toolchainLinux) GccTriple() string { 185 return "${config.LinuxGccTriple}" 186 } 187 188 func (t *toolchainLinux) GccVersion() string { 189 return linuxGccVersion 190 } 191 192 func (t *toolchainLinuxX86) Cflags() string { 193 return "${config.LinuxCflags} ${config.LinuxX86Cflags}" 194 } 195 196 func (t *toolchainLinuxX8664) Cflags() string { 197 return "${config.LinuxCflags} ${config.LinuxX8664Cflags}" 198 } 199 200 func (t *toolchainLinux) Cppflags() string { 201 return "" 202 } 203 204 func (t *toolchainLinuxX86) Ldflags() string { 205 return "${config.LinuxLdflags} ${config.LinuxX86Ldflags}" 206 } 207 208 func (t *toolchainLinuxX8664) Ldflags() string { 209 return "${config.LinuxLdflags} ${config.LinuxX8664Ldflags}" 210 } 211 212 func (t *toolchainLinux) IncludeFlags() string { 213 return "" 214 } 215 216 func (t *toolchainLinuxX86) ClangTriple() string { 217 return "i686-linux-gnu" 218 } 219 220 func (t *toolchainLinuxX86) ClangCflags() string { 221 return "${config.LinuxClangCflags} ${config.LinuxX86ClangCflags}" 222 } 223 224 func (t *toolchainLinuxX86) ClangCppflags() string { 225 return "${config.LinuxClangCppflags} ${config.LinuxX86ClangCppflags}" 226 } 227 228 func (t *toolchainLinuxX8664) ClangTriple() string { 229 return "x86_64-linux-gnu" 230 } 231 232 func (t *toolchainLinuxX8664) ClangCflags() string { 233 return "${config.LinuxClangCflags} ${config.LinuxX8664ClangCflags}" 234 } 235 236 func (t *toolchainLinuxX8664) ClangCppflags() string { 237 return "${config.LinuxClangCppflags} ${config.LinuxX8664ClangCppflags}" 238 } 239 240 func (t *toolchainLinuxX86) ClangLdflags() string { 241 return "${config.LinuxClangLdflags} ${config.LinuxX86ClangLdflags}" 242 } 243 244 func (t *toolchainLinuxX8664) ClangLdflags() string { 245 return "${config.LinuxClangLdflags} ${config.LinuxX8664ClangLdflags}" 246 } 247 248 func (t *toolchainLinuxX86) YasmFlags() string { 249 return "${config.LinuxX86YasmFlags}" 250 } 251 252 func (t *toolchainLinuxX8664) YasmFlags() string { 253 return "${config.LinuxX8664YasmFlags}" 254 } 255 256 func (t *toolchainLinux) AvailableLibraries() []string { 257 return linuxAvailableLibraries 258 } 259 260 func (t *toolchainLinux) Bionic() bool { 261 return false 262 } 263 264 var toolchainLinuxX86Singleton Toolchain = &toolchainLinuxX86{} 265 var toolchainLinuxX8664Singleton Toolchain = &toolchainLinuxX8664{} 266 267 func linuxX86ToolchainFactory(arch android.Arch) Toolchain { 268 return toolchainLinuxX86Singleton 269 } 270 271 func linuxX8664ToolchainFactory(arch android.Arch) Toolchain { 272 return toolchainLinuxX8664Singleton 273 } 274 275 func init() { 276 registerToolchainFactory(android.Linux, android.X86, linuxX86ToolchainFactory) 277 registerToolchainFactory(android.Linux, android.X86_64, linuxX8664ToolchainFactory) 278 }