blob: 6fbff9f1994b4edfcd487cce5e2dd4b6fa183f47 [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{
Dan Willemsen490fd492015-11-24 17:53:15 -080025 "-DUSE_MINGW",
26 "-DWIN32_LEAN_AND_MEAN",
27 "-Wno-unused-parameter",
Dan Willemsen490fd492015-11-24 17:53:15 -080028
29 // Workaround differences in inttypes.h between host and target.
30 //See bug 12708004.
31 "-D__STDC_FORMAT_MACROS",
32 "-D__STDC_CONSTANT_MACROS",
33
34 // Use C99-compliant printf functions (%zd).
35 "-D__USE_MINGW_ANSI_STDIO=1",
Dan Willemsen01fdd3d2016-03-30 00:01:12 -070036 // Admit to using >= Vista. Both are needed because of <_mingw.h>.
37 "-D_WIN32_WINNT=0x0600",
38 "-DWINVER=0x0600",
Dan Willemsen490fd492015-11-24 17:53:15 -080039 // Get 64-bit off_t and related functions.
40 "-D_FILE_OFFSET_BITS=64",
41
Colin Crossb98c8b02016-07-29 13:44:28 -070042 "--sysroot ${WindowsGccRoot}/${WindowsGccTriple}",
Dan Willemsen490fd492015-11-24 17:53:15 -080043 }
Dan Willemsen01f388c2017-11-30 13:31:26 -080044 windowsClangCflags = append(ClangFilterUnknownCflags(windowsCflags), []string{}...)
Dan Willemsen490fd492015-11-24 17:53:15 -080045
46 windowsIncludeFlags = []string{
Colin Crossb98c8b02016-07-29 13:44:28 -070047 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include",
48 "-isystem ${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/include",
Dan Willemsen490fd492015-11-24 17:53:15 -080049 }
50
Dan Willemsen01f388c2017-11-30 13:31:26 -080051 windowsClangCppflags = []string{
52 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3",
53 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3/backward",
54 }
55
56 windowsX86ClangCppflags = []string{
57 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3/${WindowsGccTriple}/32",
58 }
59
60 windowsX8664ClangCppflags = []string{
61 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3/${WindowsGccTriple}",
62 }
63
Dan Willemsen490fd492015-11-24 17:53:15 -080064 windowsLdflags = []string{
Dan Willemsen490fd492015-11-24 17:53:15 -080065 "--enable-stdcall-fixup",
66 }
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070067 windowsClangLdflags = append(ClangFilterUnknownCflags(windowsLdflags), []string{}...)
68 windowsClangLldflags = ClangFilterUnknownLldflags(windowsClangLdflags)
Dan Willemsen07cd0512016-02-03 23:16:33 -080069
70 windowsX86Cflags = []string{
71 "-m32",
72 }
73
74 windowsX8664Cflags = []string{
75 "-m64",
76 }
77
78 windowsX86Ldflags = []string{
79 "-m32",
Dan Willemsen7752bca2017-03-14 13:36:23 -070080 "-Wl,--large-address-aware",
Colin Crossb98c8b02016-07-29 13:44:28 -070081 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
Dan Willemsen07cd0512016-02-03 23:16:33 -080082 }
Dan Willemsen01f388c2017-11-30 13:31:26 -080083 windowsX86ClangLdflags = append(ClangFilterUnknownCflags(windowsX86Ldflags), []string{
84 "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
85 "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
86 "-B${WindowsGccRoot}/${WindowsGccTriple}/lib32",
87 }...)
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070088 windowsX86ClangLldflags = ClangFilterUnknownLldflags(windowsX86ClangLdflags)
Dan Willemsen07cd0512016-02-03 23:16:33 -080089
90 windowsX8664Ldflags = []string{
91 "-m64",
Colin Crossb98c8b02016-07-29 13:44:28 -070092 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
Dan Willemsen07cd0512016-02-03 23:16:33 -080093 }
Dan Willemsen01f388c2017-11-30 13:31:26 -080094 windowsX8664ClangLdflags = append(ClangFilterUnknownCflags(windowsX8664Ldflags), []string{
95 "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
96 "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
97 "-B${WindowsGccRoot}/${WindowsGccTriple}/lib64",
98 }...)
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070099 windowsX8664ClangLldflags = ClangFilterUnknownLldflags(windowsX8664ClangLdflags)
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700100
101 windowsAvailableLibraries = addPrefix([]string{
102 "gdi32",
103 "imagehlp",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -0700104 "iphlpapi",
105 "netapi32",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700106 "ole32",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -0700107 "powrprof",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700108 "psapi",
Kenny Rootb9123492016-09-20 14:49:33 -0700109 "pthread",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700110 "userenv",
111 "uuid",
Colin Cross124fd9a2016-11-21 17:31:08 -0800112 "version",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700113 "ws2_32",
114 }, "-l")
Dan Willemsen490fd492015-11-24 17:53:15 -0800115)
116
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800117const (
118 windowsGccVersion = "4.8"
119)
120
Dan Willemsen490fd492015-11-24 17:53:15 -0800121func init() {
Colin Crossb98c8b02016-07-29 13:44:28 -0700122 pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
Dan Willemsen490fd492015-11-24 17:53:15 -0800123
Colin Crossb98c8b02016-07-29 13:44:28 -0700124 pctx.SourcePathVariable("WindowsGccRoot",
125 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
Dan Willemsen490fd492015-11-24 17:53:15 -0800126
Colin Crossb98c8b02016-07-29 13:44:28 -0700127 pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
Dan Willemsen490fd492015-11-24 17:53:15 -0800128
Colin Crossb98c8b02016-07-29 13:44:28 -0700129 pctx.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " "))
130 pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " "))
Dan Willemsen07cd0512016-02-03 23:16:33 -0800131
Dan Willemsen01f388c2017-11-30 13:31:26 -0800132 pctx.StaticVariable("WindowsClangCflags", strings.Join(windowsClangCflags, " "))
133 pctx.StaticVariable("WindowsClangLdflags", strings.Join(windowsClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700134 pctx.StaticVariable("WindowsClangLldflags", strings.Join(windowsClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800135 pctx.StaticVariable("WindowsClangCppflags", strings.Join(windowsClangCppflags, " "))
136
Colin Crossb98c8b02016-07-29 13:44:28 -0700137 pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " "))
138 pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " "))
139 pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " "))
140 pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " "))
Dan Willemsend352edf2016-05-18 16:06:10 -0700141
Dan Willemsen01f388c2017-11-30 13:31:26 -0800142 pctx.StaticVariable("WindowsX86ClangCflags",
143 strings.Join(ClangFilterUnknownCflags(windowsX86Cflags), " "))
144 pctx.StaticVariable("WindowsX8664ClangCflags",
145 strings.Join(ClangFilterUnknownCflags(windowsX8664Cflags), " "))
146 pctx.StaticVariable("WindowsX86ClangLdflags", strings.Join(windowsX86ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700147 pctx.StaticVariable("WindowsX86ClangLldflags", strings.Join(windowsX86ClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800148 pctx.StaticVariable("WindowsX8664ClangLdflags", strings.Join(windowsX8664ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700149 pctx.StaticVariable("WindowsX8664ClangLldflags", strings.Join(windowsX8664ClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800150 pctx.StaticVariable("WindowsX86ClangCppflags", strings.Join(windowsX86ClangCppflags, " "))
151 pctx.StaticVariable("WindowsX8664ClangCppflags", strings.Join(windowsX8664ClangCppflags, " "))
152
Colin Crossb98c8b02016-07-29 13:44:28 -0700153 pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
Dan Willemsen490fd492015-11-24 17:53:15 -0800154}
155
156type toolchainWindows struct {
Dan Willemsen490fd492015-11-24 17:53:15 -0800157 cFlags, ldFlags string
158}
159
Dan Willemsen07cd0512016-02-03 23:16:33 -0800160type toolchainWindowsX86 struct {
161 toolchain32Bit
162 toolchainWindows
163}
164
165type toolchainWindowsX8664 struct {
166 toolchain64Bit
167 toolchainWindows
168}
169
170func (t *toolchainWindowsX86) Name() string {
Dan Willemsen490fd492015-11-24 17:53:15 -0800171 return "x86"
172}
173
Dan Willemsen07cd0512016-02-03 23:16:33 -0800174func (t *toolchainWindowsX8664) Name() string {
175 return "x86_64"
176}
177
Dan Willemsen490fd492015-11-24 17:53:15 -0800178func (t *toolchainWindows) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700179 return "${config.WindowsGccRoot}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800180}
181
182func (t *toolchainWindows) GccTriple() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700183 return "${config.WindowsGccTriple}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800184}
185
186func (t *toolchainWindows) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800187 return windowsGccVersion
Dan Willemsen490fd492015-11-24 17:53:15 -0800188}
189
Dan Willemsen07cd0512016-02-03 23:16:33 -0800190func (t *toolchainWindowsX86) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700191 return "${config.WindowsCflags} ${config.WindowsX86Cflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800192}
193
194func (t *toolchainWindowsX8664) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700195 return "${config.WindowsCflags} ${config.WindowsX8664Cflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800196}
197
198func (t *toolchainWindows) Cppflags() string {
199 return ""
200}
201
Dan Willemsen07cd0512016-02-03 23:16:33 -0800202func (t *toolchainWindowsX86) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700203 return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800204}
205
206func (t *toolchainWindowsX8664) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700207 return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800208}
209
210func (t *toolchainWindows) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700211 return "${config.WindowsIncludeFlags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800212}
213
Dan Willemsen4f1c3d42017-09-09 01:15:26 -0700214func (t *toolchainWindowsX86) WindresFlags() string {
215 return "-F pe-i386"
216}
217
218func (t *toolchainWindowsX8664) WindresFlags() string {
219 return "-F pe-x86-64"
220}
221
Dan Willemsen490fd492015-11-24 17:53:15 -0800222func (t *toolchainWindows) ClangSupported() bool {
223 return false
224}
225
Dan Willemsen01f388c2017-11-30 13:31:26 -0800226func (t *toolchainWindowsX86) ClangTriple() string {
227 return "i686-windows-gnu"
Dan Willemsen490fd492015-11-24 17:53:15 -0800228}
229
Dan Willemsen01f388c2017-11-30 13:31:26 -0800230func (t *toolchainWindowsX8664) ClangTriple() string {
231 return "x86_64-pc-windows-gnu"
Dan Willemsen490fd492015-11-24 17:53:15 -0800232}
233
Dan Willemsen01f388c2017-11-30 13:31:26 -0800234func (t *toolchainWindowsX86) ClangCflags() string {
235 return "${config.WindowsClangCflags} ${config.WindowsX86ClangCflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800236}
237
Dan Willemsen01f388c2017-11-30 13:31:26 -0800238func (t *toolchainWindowsX8664) ClangCflags() string {
239 return "${config.WindowsClangCflags} ${config.WindowsX8664ClangCflags}"
240}
241
242func (t *toolchainWindowsX86) ClangCppflags() string {
243 return "${config.WindowsClangCppflags} ${config.WindowsX86ClangCppflags}"
244}
245
246func (t *toolchainWindowsX8664) ClangCppflags() string {
247 return "${config.WindowsClangCppflags} ${config.WindowsX8664ClangCppflags}"
248}
249
250func (t *toolchainWindowsX86) ClangLdflags() string {
251 return "${config.WindowsClangLdflags} ${config.WindowsX86ClangLdflags}"
252}
253
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700254func (t *toolchainWindowsX86) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700255 return "${config.WindowsClangLldflags} ${config.WindowsX86ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700256}
257
Dan Willemsen01f388c2017-11-30 13:31:26 -0800258func (t *toolchainWindowsX8664) ClangLdflags() string {
259 return "${config.WindowsClangLdflags} ${config.WindowsX8664ClangLdflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800260}
261
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700262func (t *toolchainWindowsX8664) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700263 return "${config.WindowsClangLldflags} ${config.WindowsX8664ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700264}
265
Dan Willemsen490fd492015-11-24 17:53:15 -0800266func (t *toolchainWindows) ShlibSuffix() string {
267 return ".dll"
268}
269
270func (t *toolchainWindows) ExecutableSuffix() string {
271 return ".exe"
272}
273
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700274func (t *toolchainWindows) AvailableLibraries() []string {
275 return windowsAvailableLibraries
276}
277
Dan Willemsen2e47b342016-11-17 01:02:25 -0800278func (t *toolchainWindows) Bionic() bool {
279 return false
280}
281
Dan Willemsen07cd0512016-02-03 23:16:33 -0800282var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
283var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
Dan Willemsen490fd492015-11-24 17:53:15 -0800284
Colin Cross635c3b02016-05-18 15:37:25 -0700285func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800286 return toolchainWindowsX86Singleton
287}
288
Colin Cross635c3b02016-05-18 15:37:25 -0700289func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800290 return toolchainWindowsX8664Singleton
Dan Willemsen490fd492015-11-24 17:53:15 -0800291}
292
293func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700294 registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
295 registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
Dan Willemsen490fd492015-11-24 17:53:15 -0800296}