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", |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 72 | "-L${WindowsGccRoot}/${WindowsGccTriple}/lib32", |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | windowsX8664Ldflags = []string{ |
| 76 | "-m64", |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 77 | "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64", |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 78 | } |
Dan Willemsen | 2b1f094 | 2016-07-20 12:47:47 -0700 | [diff] [blame] | 79 | |
| 80 | windowsAvailableLibraries = addPrefix([]string{ |
| 81 | "gdi32", |
| 82 | "imagehlp", |
| 83 | "ole32", |
| 84 | "psapi", |
Kenny Root | b912349 | 2016-09-20 14:49:33 -0700 | [diff] [blame^] | 85 | "pthread", |
Dan Willemsen | 2b1f094 | 2016-07-20 12:47:47 -0700 | [diff] [blame] | 86 | "userenv", |
| 87 | "uuid", |
| 88 | "ws2_32", |
| 89 | }, "-l") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 90 | ) |
| 91 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 92 | const ( |
| 93 | windowsGccVersion = "4.8" |
| 94 | ) |
| 95 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 96 | func init() { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 97 | pctx.StaticVariable("WindowsGccVersion", windowsGccVersion) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 98 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 99 | pctx.SourcePathVariable("WindowsGccRoot", |
| 100 | "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 101 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 102 | pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32") |
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.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " ")) |
| 105 | pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " ")) |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 106 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 107 | pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " ")) |
| 108 | pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " ")) |
| 109 | pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " ")) |
| 110 | pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " ")) |
Dan Willemsen | d352edf | 2016-05-18 16:06:10 -0700 | [diff] [blame] | 111 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 112 | pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " ")) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | type toolchainWindows struct { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 116 | cFlags, ldFlags string |
| 117 | } |
| 118 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 119 | type toolchainWindowsX86 struct { |
| 120 | toolchain32Bit |
| 121 | toolchainWindows |
| 122 | } |
| 123 | |
| 124 | type toolchainWindowsX8664 struct { |
| 125 | toolchain64Bit |
| 126 | toolchainWindows |
| 127 | } |
| 128 | |
| 129 | func (t *toolchainWindowsX86) Name() string { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 130 | return "x86" |
| 131 | } |
| 132 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 133 | func (t *toolchainWindowsX8664) Name() string { |
| 134 | return "x86_64" |
| 135 | } |
| 136 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 137 | func (t *toolchainWindows) GccRoot() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 138 | return "${config.WindowsGccRoot}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | func (t *toolchainWindows) GccTriple() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 142 | return "${config.WindowsGccTriple}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | func (t *toolchainWindows) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 146 | return windowsGccVersion |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 149 | func (t *toolchainWindowsX86) Cflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 150 | return "${config.WindowsCflags} ${config.WindowsX86Cflags}" |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | func (t *toolchainWindowsX8664) Cflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 154 | return "${config.WindowsCflags} ${config.WindowsX8664Cflags}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | func (t *toolchainWindows) Cppflags() string { |
| 158 | return "" |
| 159 | } |
| 160 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 161 | func (t *toolchainWindowsX86) Ldflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 162 | return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}" |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | func (t *toolchainWindowsX8664) Ldflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 166 | return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | func (t *toolchainWindows) IncludeFlags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 170 | return "${config.WindowsIncludeFlags}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | func (t *toolchainWindows) ClangSupported() bool { |
| 174 | return false |
| 175 | } |
| 176 | |
| 177 | func (t *toolchainWindows) ClangTriple() string { |
| 178 | panic("Clang is not supported under mingw") |
| 179 | } |
| 180 | |
| 181 | func (t *toolchainWindows) ClangCflags() string { |
| 182 | panic("Clang is not supported under mingw") |
| 183 | } |
| 184 | |
| 185 | func (t *toolchainWindows) ClangCppflags() string { |
| 186 | panic("Clang is not supported under mingw") |
| 187 | } |
| 188 | |
| 189 | func (t *toolchainWindows) ClangLdflags() string { |
| 190 | panic("Clang is not supported under mingw") |
| 191 | } |
| 192 | |
| 193 | func (t *toolchainWindows) ShlibSuffix() string { |
| 194 | return ".dll" |
| 195 | } |
| 196 | |
| 197 | func (t *toolchainWindows) ExecutableSuffix() string { |
| 198 | return ".exe" |
| 199 | } |
| 200 | |
Dan Willemsen | 2b1f094 | 2016-07-20 12:47:47 -0700 | [diff] [blame] | 201 | func (t *toolchainWindows) AvailableLibraries() []string { |
| 202 | return windowsAvailableLibraries |
| 203 | } |
| 204 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 205 | var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{} |
| 206 | var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{} |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 207 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 208 | func windowsX86ToolchainFactory(arch android.Arch) Toolchain { |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 209 | return toolchainWindowsX86Singleton |
| 210 | } |
| 211 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 212 | func windowsX8664ToolchainFactory(arch android.Arch) Toolchain { |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 213 | return toolchainWindowsX8664Singleton |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 217 | registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory) |
| 218 | registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 219 | } |