blob: 99c76f1c77a25d6e7b6546d1445fdf2ad78bc88e [file] [log] [blame]
Dan Willemsen490fd492015-11-24 17:53:15 -08001// 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 Crossb98c8b02016-07-29 13:44:28 -070015package config
Dan Willemsen490fd492015-11-24 17:53:15 -080016
17import (
18 "strings"
19
Colin Cross635c3b02016-05-18 15:37:25 -070020 "android/soong/android"
Dan Willemsen490fd492015-11-24 17:53:15 -080021)
22
23var (
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 Willemsen490fd492015-11-24 17:53:15 -080031
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 Willemsen01fdd3d2016-03-30 00:01:12 -070039 // Admit to using >= Vista. Both are needed because of <_mingw.h>.
40 "-D_WIN32_WINNT=0x0600",
41 "-DWINVER=0x0600",
Dan Willemsen490fd492015-11-24 17:53:15 -080042 // Get 64-bit off_t and related functions.
43 "-D_FILE_OFFSET_BITS=64",
44
Colin Crossb98c8b02016-07-29 13:44:28 -070045 "--sysroot ${WindowsGccRoot}/${WindowsGccTriple}",
Dan Willemsen01fdd3d2016-03-30 00:01:12 -070046
Dan Willemsen490fd492015-11-24 17:53:15 -080047 // 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 Crossb98c8b02016-07-29 13:44:28 -070054 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include",
55 "-isystem ${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/include",
Dan Willemsen490fd492015-11-24 17:53:15 -080056 }
57
58 windowsLdflags = []string{
Dan Willemsen490fd492015-11-24 17:53:15 -080059 "--enable-stdcall-fixup",
60 }
Dan Willemsen07cd0512016-02-03 23:16:33 -080061
62 windowsX86Cflags = []string{
63 "-m32",
64 }
65
66 windowsX8664Cflags = []string{
67 "-m64",
68 }
69
70 windowsX86Ldflags = []string{
71 "-m32",
Dan Willemsen7752bca2017-03-14 13:36:23 -070072 "-Wl,--large-address-aware",
Colin Crossb98c8b02016-07-29 13:44:28 -070073 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
Dan Willemsen07cd0512016-02-03 23:16:33 -080074 }
75
76 windowsX8664Ldflags = []string{
77 "-m64",
Colin Crossb98c8b02016-07-29 13:44:28 -070078 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
Dan Willemsen07cd0512016-02-03 23:16:33 -080079 }
Dan Willemsen2b1f0942016-07-20 12:47:47 -070080
81 windowsAvailableLibraries = addPrefix([]string{
82 "gdi32",
83 "imagehlp",
84 "ole32",
85 "psapi",
Kenny Rootb9123492016-09-20 14:49:33 -070086 "pthread",
Dan Willemsen2b1f0942016-07-20 12:47:47 -070087 "userenv",
88 "uuid",
Colin Cross124fd9a2016-11-21 17:31:08 -080089 "version",
Dan Willemsen2b1f0942016-07-20 12:47:47 -070090 "ws2_32",
91 }, "-l")
Dan Willemsen490fd492015-11-24 17:53:15 -080092)
93
Dan Willemsen34fc3b12015-12-07 12:30:44 -080094const (
95 windowsGccVersion = "4.8"
96)
97
Dan Willemsen490fd492015-11-24 17:53:15 -080098func init() {
Colin Crossb98c8b02016-07-29 13:44:28 -070099 pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
Dan Willemsen490fd492015-11-24 17:53:15 -0800100
Colin Crossb98c8b02016-07-29 13:44:28 -0700101 pctx.SourcePathVariable("WindowsGccRoot",
102 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
Dan Willemsen490fd492015-11-24 17:53:15 -0800103
Colin Crossb98c8b02016-07-29 13:44:28 -0700104 pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
Dan Willemsen490fd492015-11-24 17:53:15 -0800105
Colin Crossb98c8b02016-07-29 13:44:28 -0700106 pctx.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " "))
107 pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " "))
Dan Willemsen07cd0512016-02-03 23:16:33 -0800108
Colin Crossb98c8b02016-07-29 13:44:28 -0700109 pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " "))
110 pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " "))
111 pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " "))
112 pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " "))
Dan Willemsend352edf2016-05-18 16:06:10 -0700113
Colin Crossb98c8b02016-07-29 13:44:28 -0700114 pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
Dan Willemsen490fd492015-11-24 17:53:15 -0800115}
116
117type toolchainWindows struct {
Dan Willemsen490fd492015-11-24 17:53:15 -0800118 cFlags, ldFlags string
119}
120
Dan Willemsen07cd0512016-02-03 23:16:33 -0800121type toolchainWindowsX86 struct {
122 toolchain32Bit
123 toolchainWindows
124}
125
126type toolchainWindowsX8664 struct {
127 toolchain64Bit
128 toolchainWindows
129}
130
131func (t *toolchainWindowsX86) Name() string {
Dan Willemsen490fd492015-11-24 17:53:15 -0800132 return "x86"
133}
134
Dan Willemsen07cd0512016-02-03 23:16:33 -0800135func (t *toolchainWindowsX8664) Name() string {
136 return "x86_64"
137}
138
Dan Willemsen490fd492015-11-24 17:53:15 -0800139func (t *toolchainWindows) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700140 return "${config.WindowsGccRoot}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800141}
142
143func (t *toolchainWindows) GccTriple() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700144 return "${config.WindowsGccTriple}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800145}
146
147func (t *toolchainWindows) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800148 return windowsGccVersion
Dan Willemsen490fd492015-11-24 17:53:15 -0800149}
150
Dan Willemsen07cd0512016-02-03 23:16:33 -0800151func (t *toolchainWindowsX86) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700152 return "${config.WindowsCflags} ${config.WindowsX86Cflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800153}
154
155func (t *toolchainWindowsX8664) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700156 return "${config.WindowsCflags} ${config.WindowsX8664Cflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800157}
158
159func (t *toolchainWindows) Cppflags() string {
160 return ""
161}
162
Dan Willemsen07cd0512016-02-03 23:16:33 -0800163func (t *toolchainWindowsX86) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700164 return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800165}
166
167func (t *toolchainWindowsX8664) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700168 return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800169}
170
171func (t *toolchainWindows) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700172 return "${config.WindowsIncludeFlags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800173}
174
Dan Willemsen4f1c3d42017-09-09 01:15:26 -0700175func (t *toolchainWindowsX86) WindresFlags() string {
176 return "-F pe-i386"
177}
178
179func (t *toolchainWindowsX8664) WindresFlags() string {
180 return "-F pe-x86-64"
181}
182
Dan Willemsen490fd492015-11-24 17:53:15 -0800183func (t *toolchainWindows) ClangSupported() bool {
184 return false
185}
186
187func (t *toolchainWindows) ClangTriple() string {
188 panic("Clang is not supported under mingw")
189}
190
191func (t *toolchainWindows) ClangCflags() string {
192 panic("Clang is not supported under mingw")
193}
194
195func (t *toolchainWindows) ClangCppflags() string {
196 panic("Clang is not supported under mingw")
197}
198
199func (t *toolchainWindows) ClangLdflags() string {
200 panic("Clang is not supported under mingw")
201}
202
203func (t *toolchainWindows) ShlibSuffix() string {
204 return ".dll"
205}
206
207func (t *toolchainWindows) ExecutableSuffix() string {
208 return ".exe"
209}
210
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700211func (t *toolchainWindows) AvailableLibraries() []string {
212 return windowsAvailableLibraries
213}
214
Dan Willemsen2e47b342016-11-17 01:02:25 -0800215func (t *toolchainWindows) Bionic() bool {
216 return false
217}
218
Dan Willemsen07cd0512016-02-03 23:16:33 -0800219var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
220var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
Dan Willemsen490fd492015-11-24 17:53:15 -0800221
Colin Cross635c3b02016-05-18 15:37:25 -0700222func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800223 return toolchainWindowsX86Singleton
224}
225
Colin Cross635c3b02016-05-18 15:37:25 -0700226func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800227 return toolchainWindowsX8664Singleton
Dan Willemsen490fd492015-11-24 17:53:15 -0800228}
229
230func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700231 registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
232 registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
Dan Willemsen490fd492015-11-24 17:53:15 -0800233}