Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 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 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 15 | package config |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 20 | "android/soong/android" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 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", |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 31 | |
| 32 | // Workaround differences in inttypes.h between host and target. |
| 33 | //See bug 12708004. |
| 34 | "-D__STDC_FORMAT_MACROS", |
| 35 | "-D__STDC_CONSTANT_MACROS", |
| 36 | |
| 37 | // Use C99-compliant printf functions (%zd). |
| 38 | "-D__USE_MINGW_ANSI_STDIO=1", |
Dan Willemsen | 01fdd3d | 2016-03-30 00:01:12 -0700 | [diff] [blame] | 39 | // Admit to using >= Vista. Both are needed because of <_mingw.h>. |
| 40 | "-D_WIN32_WINNT=0x0600", |
| 41 | "-DWINVER=0x0600", |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 42 | // Get 64-bit off_t and related functions. |
| 43 | "-D_FILE_OFFSET_BITS=64", |
| 44 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 45 | "--sysroot ${WindowsGccRoot}/${WindowsGccTriple}", |
Dan Willemsen | 01fdd3d | 2016-03-30 00:01:12 -0700 | [diff] [blame] | 46 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 47 | // HOST_RELEASE_CFLAGS |
| 48 | "-O2", // from build/core/combo/select.mk |
| 49 | "-g", // from build/core/combo/select.mk |
| 50 | "-fno-strict-aliasing", // from build/core/combo/select.mk |
| 51 | } |
| 52 | |
| 53 | windowsIncludeFlags = []string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 54 | "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include", |
| 55 | "-isystem ${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/include", |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | windowsLdflags = []string{ |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 59 | "--enable-stdcall-fixup", |
| 60 | } |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 61 | |
| 62 | windowsX86Cflags = []string{ |
| 63 | "-m32", |
| 64 | } |
| 65 | |
| 66 | windowsX8664Cflags = []string{ |
| 67 | "-m64", |
| 68 | } |
| 69 | |
| 70 | windowsX86Ldflags = []string{ |
| 71 | "-m32", |
Dan Willemsen | 7752bca | 2017-03-14 13:36:23 -0700 | [diff] [blame] | 72 | "-Wl,--large-address-aware", |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 73 | "-L${WindowsGccRoot}/${WindowsGccTriple}/lib32", |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | windowsX8664Ldflags = []string{ |
| 77 | "-m64", |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 78 | "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64", |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 79 | } |
Dan Willemsen | 2b1f094 | 2016-07-20 12:47:47 -0700 | [diff] [blame] | 80 | |
| 81 | windowsAvailableLibraries = addPrefix([]string{ |
| 82 | "gdi32", |
| 83 | "imagehlp", |
Dan Willemsen | b18cf7a | 2017-09-09 01:42:00 -0700 | [diff] [blame] | 84 | "iphlpapi", |
| 85 | "netapi32", |
Dan Willemsen | 2b1f094 | 2016-07-20 12:47:47 -0700 | [diff] [blame] | 86 | "ole32", |
Dan Willemsen | b18cf7a | 2017-09-09 01:42:00 -0700 | [diff] [blame] | 87 | "powrprof", |
Dan Willemsen | 2b1f094 | 2016-07-20 12:47:47 -0700 | [diff] [blame] | 88 | "psapi", |
Kenny Root | b912349 | 2016-09-20 14:49:33 -0700 | [diff] [blame] | 89 | "pthread", |
Dan Willemsen | 2b1f094 | 2016-07-20 12:47:47 -0700 | [diff] [blame] | 90 | "userenv", |
| 91 | "uuid", |
Colin Cross | 124fd9a | 2016-11-21 17:31:08 -0800 | [diff] [blame] | 92 | "version", |
Dan Willemsen | 2b1f094 | 2016-07-20 12:47:47 -0700 | [diff] [blame] | 93 | "ws2_32", |
| 94 | }, "-l") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 95 | ) |
| 96 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 97 | const ( |
| 98 | windowsGccVersion = "4.8" |
| 99 | ) |
| 100 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 101 | func init() { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 102 | pctx.StaticVariable("WindowsGccVersion", windowsGccVersion) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 103 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 104 | pctx.SourcePathVariable("WindowsGccRoot", |
| 105 | "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 106 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 107 | pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 108 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 109 | pctx.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " ")) |
| 110 | pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " ")) |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 111 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 112 | pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " ")) |
| 113 | pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " ")) |
| 114 | pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " ")) |
| 115 | pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " ")) |
Dan Willemsen | d352edf | 2016-05-18 16:06:10 -0700 | [diff] [blame] | 116 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 117 | pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " ")) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | type toolchainWindows struct { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 121 | cFlags, ldFlags string |
| 122 | } |
| 123 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 124 | type toolchainWindowsX86 struct { |
| 125 | toolchain32Bit |
| 126 | toolchainWindows |
| 127 | } |
| 128 | |
| 129 | type toolchainWindowsX8664 struct { |
| 130 | toolchain64Bit |
| 131 | toolchainWindows |
| 132 | } |
| 133 | |
| 134 | func (t *toolchainWindowsX86) Name() string { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 135 | return "x86" |
| 136 | } |
| 137 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 138 | func (t *toolchainWindowsX8664) Name() string { |
| 139 | return "x86_64" |
| 140 | } |
| 141 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 142 | func (t *toolchainWindows) GccRoot() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 143 | return "${config.WindowsGccRoot}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | func (t *toolchainWindows) GccTriple() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 147 | return "${config.WindowsGccTriple}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | func (t *toolchainWindows) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 151 | return windowsGccVersion |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 154 | func (t *toolchainWindowsX86) Cflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 155 | return "${config.WindowsCflags} ${config.WindowsX86Cflags}" |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | func (t *toolchainWindowsX8664) Cflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 159 | return "${config.WindowsCflags} ${config.WindowsX8664Cflags}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | func (t *toolchainWindows) Cppflags() string { |
| 163 | return "" |
| 164 | } |
| 165 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 166 | func (t *toolchainWindowsX86) Ldflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 167 | return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}" |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | func (t *toolchainWindowsX8664) Ldflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 171 | return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | func (t *toolchainWindows) IncludeFlags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 175 | return "${config.WindowsIncludeFlags}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 178 | func (t *toolchainWindowsX86) WindresFlags() string { |
| 179 | return "-F pe-i386" |
| 180 | } |
| 181 | |
| 182 | func (t *toolchainWindowsX8664) WindresFlags() string { |
| 183 | return "-F pe-x86-64" |
| 184 | } |
| 185 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 186 | func (t *toolchainWindows) ClangSupported() bool { |
| 187 | return false |
| 188 | } |
| 189 | |
| 190 | func (t *toolchainWindows) ClangTriple() string { |
| 191 | panic("Clang is not supported under mingw") |
| 192 | } |
| 193 | |
| 194 | func (t *toolchainWindows) ClangCflags() string { |
| 195 | panic("Clang is not supported under mingw") |
| 196 | } |
| 197 | |
| 198 | func (t *toolchainWindows) ClangCppflags() string { |
| 199 | panic("Clang is not supported under mingw") |
| 200 | } |
| 201 | |
| 202 | func (t *toolchainWindows) ClangLdflags() string { |
| 203 | panic("Clang is not supported under mingw") |
| 204 | } |
| 205 | |
| 206 | func (t *toolchainWindows) ShlibSuffix() string { |
| 207 | return ".dll" |
| 208 | } |
| 209 | |
| 210 | func (t *toolchainWindows) ExecutableSuffix() string { |
| 211 | return ".exe" |
| 212 | } |
| 213 | |
Dan Willemsen | 2b1f094 | 2016-07-20 12:47:47 -0700 | [diff] [blame] | 214 | func (t *toolchainWindows) AvailableLibraries() []string { |
| 215 | return windowsAvailableLibraries |
| 216 | } |
| 217 | |
Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 218 | func (t *toolchainWindows) Bionic() bool { |
| 219 | return false |
| 220 | } |
| 221 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 222 | var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{} |
| 223 | var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{} |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 224 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 225 | func windowsX86ToolchainFactory(arch android.Arch) Toolchain { |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 226 | return toolchainWindowsX86Singleton |
| 227 | } |
| 228 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 229 | func windowsX8664ToolchainFactory(arch android.Arch) Toolchain { |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 230 | return toolchainWindowsX8664Singleton |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 234 | registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory) |
| 235 | registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 236 | } |