1 // 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 15 package cc 16 17 import ( 18 "strings" 19 20 "android/soong/common" 21 ) 22 23 var ( 24 windowsCflags = []string{ 25 "-fno-exceptions", // from build/core/combo/select.mk 26 "-Wno-multichar", // from build/core/combo/select.mk 27 28 "-DUSE_MINGW", 29 "-DWIN32_LEAN_AND_MEAN", 30 "-Wno-unused-parameter", 31 "-m32", 32 33 // Workaround differences in inttypes.h between host and target. 34 //See bug 12708004. 35 "-D__STDC_FORMAT_MACROS", 36 "-D__STDC_CONSTANT_MACROS", 37 38 // Use C99-compliant printf functions (%zd). 39 "-D__USE_MINGW_ANSI_STDIO=1", 40 // Admit to using >= Win2K. Both are needed because of <_mingw.h>. 41 "-D_WIN32_WINNT=0x0500", 42 "-DWINVER=0x0500", 43 // Get 64-bit off_t and related functions. 44 "-D_FILE_OFFSET_BITS=64", 45 46 // HOST_RELEASE_CFLAGS 47 "-O2", // from build/core/combo/select.mk 48 "-g", // from build/core/combo/select.mk 49 "-fno-strict-aliasing", // from build/core/combo/select.mk 50 } 51 52 windowsIncludeFlags = []string{ 53 "-I${windowsGccRoot}/${windowsGccTriple}/include", 54 "-I${windowsGccRoot}/lib/gcc/${windowsGccTriple}/4.8.3/include", 55 } 56 57 windowsLdflags = []string{ 58 "-L${windowsGccRoot}/${windowsGccTriple}", 59 "--enable-stdcall-fixup", 60 } 61 62 windowsX86Cflags = []string{ 63 "-m32", 64 } 65 66 windowsX8664Cflags = []string{ 67 "-m64", 68 } 69 70 windowsX86Ldflags = []string{ 71 "-m32", 72 } 73 74 windowsX8664Ldflags = []string{ 75 "-m64", 76 } 77 ) 78 79 const ( 80 windowsGccVersion = "4.8" 81 ) 82 83 func init() { 84 pctx.StaticVariable("windowsGccVersion", windowsGccVersion) 85 86 pctx.SourcePathVariable("windowsGccRoot", 87 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${windowsGccVersion}") 88 89 pctx.StaticVariable("windowsGccTriple", "x86_64-w64-mingw32") 90 91 pctx.StaticVariable("windowsCflags", strings.Join(windowsCflags, " ")) 92 pctx.StaticVariable("windowsLdflags", strings.Join(windowsLdflags, " ")) 93 94 pctx.StaticVariable("windowsX86Cflags", strings.Join(windowsX86Cflags, " ")) 95 pctx.StaticVariable("windowsX8664Cflags", strings.Join(windowsX8664Cflags, " ")) 96 pctx.StaticVariable("windowsX86Ldflags", strings.Join(windowsX86Ldflags, " ")) 97 pctx.StaticVariable("windowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " ")) 98 } 99 100 type toolchainWindows struct { 101 cFlags, ldFlags string 102 } 103 104 type toolchainWindowsX86 struct { 105 toolchain32Bit 106 toolchainWindows 107 } 108 109 type toolchainWindowsX8664 struct { 110 toolchain64Bit 111 toolchainWindows 112 } 113 114 func (t *toolchainWindowsX86) Name() string { 115 return "x86" 116 } 117 118 func (t *toolchainWindowsX8664) Name() string { 119 return "x86_64" 120 } 121 122 func (t *toolchainWindows) GccRoot() string { 123 return "${windowsGccRoot}" 124 } 125 126 func (t *toolchainWindows) GccTriple() string { 127 return "${windowsGccTriple}" 128 } 129 130 func (t *toolchainWindows) GccVersion() string { 131 return windowsGccVersion 132 } 133 134 func (t *toolchainWindowsX86) Cflags() string { 135 return "${windowsCflags} ${windowsX86Cflags}" 136 } 137 138 func (t *toolchainWindowsX8664) Cflags() string { 139 return "${windowsCflags} ${windowsX8664Cflags}" 140 } 141 142 func (t *toolchainWindows) Cppflags() string { 143 return "" 144 } 145 146 func (t *toolchainWindowsX86) Ldflags() string { 147 return "${windowsLdflags} ${windowsX86Ldflags}" 148 } 149 150 func (t *toolchainWindowsX8664) Ldflags() string { 151 return "${windowsLdflags} ${windowsX8664Ldflags}" 152 } 153 154 func (t *toolchainWindows) IncludeFlags() string { 155 return "" 156 } 157 158 func (t *toolchainWindows) ClangSupported() bool { 159 return false 160 } 161 162 func (t *toolchainWindows) ClangTriple() string { 163 panic("Clang is not supported under mingw") 164 } 165 166 func (t *toolchainWindows) ClangCflags() string { 167 panic("Clang is not supported under mingw") 168 } 169 170 func (t *toolchainWindows) ClangCppflags() string { 171 panic("Clang is not supported under mingw") 172 } 173 174 func (t *toolchainWindows) ClangLdflags() string { 175 panic("Clang is not supported under mingw") 176 } 177 178 func (t *toolchainWindows) ShlibSuffix() string { 179 return ".dll" 180 } 181 182 func (t *toolchainWindows) ExecutableSuffix() string { 183 return ".exe" 184 } 185 186 var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{} 187 var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{} 188 189 func windowsX86ToolchainFactory(arch common.Arch) Toolchain { 190 return toolchainWindowsX86Singleton 191 } 192 193 func windowsX8664ToolchainFactory(arch common.Arch) Toolchain { 194 return toolchainWindowsX8664Singleton 195 } 196 197 func init() { 198 registerHostToolchainFactory(common.Windows, common.X86, windowsX86ToolchainFactory) 199 registerHostToolchainFactory(common.Windows, common.X86_64, windowsX8664ToolchainFactory) 200 } 201