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 | |
| 15 | package cc |
| 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 | |
Dan Willemsen | 01fdd3d | 2016-03-30 00:01:12 -0700 | [diff] [blame] | 45 | "--sysroot ${windowsGccRoot}/${windowsGccTriple}", |
| 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{ |
Dan Willemsen | d352edf | 2016-05-18 16:06:10 -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", |
| 72 | } |
| 73 | |
| 74 | windowsX8664Ldflags = []string{ |
| 75 | "-m64", |
| 76 | } |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 77 | ) |
| 78 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 79 | const ( |
| 80 | windowsGccVersion = "4.8" |
| 81 | ) |
| 82 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 83 | func init() { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 84 | pctx.StaticVariable("windowsGccVersion", windowsGccVersion) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 85 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 86 | pctx.SourcePathVariable("windowsGccRoot", |
| 87 | "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${windowsGccVersion}") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 88 | |
| 89 | pctx.StaticVariable("windowsGccTriple", "x86_64-w64-mingw32") |
| 90 | |
| 91 | pctx.StaticVariable("windowsCflags", strings.Join(windowsCflags, " ")) |
| 92 | pctx.StaticVariable("windowsLdflags", strings.Join(windowsLdflags, " ")) |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 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, " ")) |
Dan Willemsen | d352edf | 2016-05-18 16:06:10 -0700 | [diff] [blame^] | 98 | |
| 99 | pctx.StaticVariable("windowsIncludeFlags", strings.Join(windowsIncludeFlags, " ")) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | type toolchainWindows struct { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 103 | cFlags, ldFlags string |
| 104 | } |
| 105 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 106 | type toolchainWindowsX86 struct { |
| 107 | toolchain32Bit |
| 108 | toolchainWindows |
| 109 | } |
| 110 | |
| 111 | type toolchainWindowsX8664 struct { |
| 112 | toolchain64Bit |
| 113 | toolchainWindows |
| 114 | } |
| 115 | |
| 116 | func (t *toolchainWindowsX86) Name() string { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 117 | return "x86" |
| 118 | } |
| 119 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 120 | func (t *toolchainWindowsX8664) Name() string { |
| 121 | return "x86_64" |
| 122 | } |
| 123 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 124 | func (t *toolchainWindows) GccRoot() string { |
| 125 | return "${windowsGccRoot}" |
| 126 | } |
| 127 | |
| 128 | func (t *toolchainWindows) GccTriple() string { |
| 129 | return "${windowsGccTriple}" |
| 130 | } |
| 131 | |
| 132 | func (t *toolchainWindows) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 133 | return windowsGccVersion |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 136 | func (t *toolchainWindowsX86) Cflags() string { |
| 137 | return "${windowsCflags} ${windowsX86Cflags}" |
| 138 | } |
| 139 | |
| 140 | func (t *toolchainWindowsX8664) Cflags() string { |
| 141 | return "${windowsCflags} ${windowsX8664Cflags}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | func (t *toolchainWindows) Cppflags() string { |
| 145 | return "" |
| 146 | } |
| 147 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 148 | func (t *toolchainWindowsX86) Ldflags() string { |
| 149 | return "${windowsLdflags} ${windowsX86Ldflags}" |
| 150 | } |
| 151 | |
| 152 | func (t *toolchainWindowsX8664) Ldflags() string { |
| 153 | return "${windowsLdflags} ${windowsX8664Ldflags}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | func (t *toolchainWindows) IncludeFlags() string { |
Dan Willemsen | d352edf | 2016-05-18 16:06:10 -0700 | [diff] [blame^] | 157 | return "${windowsIncludeFlags}" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | func (t *toolchainWindows) ClangSupported() bool { |
| 161 | return false |
| 162 | } |
| 163 | |
| 164 | func (t *toolchainWindows) ClangTriple() string { |
| 165 | panic("Clang is not supported under mingw") |
| 166 | } |
| 167 | |
| 168 | func (t *toolchainWindows) ClangCflags() string { |
| 169 | panic("Clang is not supported under mingw") |
| 170 | } |
| 171 | |
| 172 | func (t *toolchainWindows) ClangCppflags() string { |
| 173 | panic("Clang is not supported under mingw") |
| 174 | } |
| 175 | |
| 176 | func (t *toolchainWindows) ClangLdflags() string { |
| 177 | panic("Clang is not supported under mingw") |
| 178 | } |
| 179 | |
| 180 | func (t *toolchainWindows) ShlibSuffix() string { |
| 181 | return ".dll" |
| 182 | } |
| 183 | |
| 184 | func (t *toolchainWindows) ExecutableSuffix() string { |
| 185 | return ".exe" |
| 186 | } |
| 187 | |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 188 | var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{} |
| 189 | var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{} |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 190 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 191 | func windowsX86ToolchainFactory(arch android.Arch) Toolchain { |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 192 | return toolchainWindowsX86Singleton |
| 193 | } |
| 194 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 195 | func windowsX8664ToolchainFactory(arch android.Arch) Toolchain { |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 196 | return toolchainWindowsX8664Singleton |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | func init() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 200 | registerHostToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory) |
| 201 | registerHostToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 202 | } |