blob: 4cb8fa47b7922bec7fe8560c07a18339726d9d62 [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",
Dan Willemsen490fd492015-11-24 17:53:15 -080048 }
49
Dan Willemsen01f388c2017-11-30 13:31:26 -080050 windowsClangCppflags = []string{
51 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3",
52 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3/backward",
53 }
54
55 windowsX86ClangCppflags = []string{
56 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3/${WindowsGccTriple}/32",
57 }
58
59 windowsX8664ClangCppflags = []string{
60 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3/${WindowsGccTriple}",
61 }
62
Dan Willemsen490fd492015-11-24 17:53:15 -080063 windowsLdflags = []string{
Dan Willemsen490fd492015-11-24 17:53:15 -080064 "--enable-stdcall-fixup",
65 }
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070066 windowsClangLdflags = append(ClangFilterUnknownCflags(windowsLdflags), []string{}...)
67 windowsClangLldflags = ClangFilterUnknownLldflags(windowsClangLdflags)
Dan Willemsen07cd0512016-02-03 23:16:33 -080068
69 windowsX86Cflags = []string{
70 "-m32",
71 }
72
73 windowsX8664Cflags = []string{
74 "-m64",
75 }
76
77 windowsX86Ldflags = []string{
78 "-m32",
Dan Willemsen7752bca2017-03-14 13:36:23 -070079 "-Wl,--large-address-aware",
Colin Crossb98c8b02016-07-29 13:44:28 -070080 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
Pirama Arumuga Nainarabf1b312018-06-25 16:42:23 -070081 "-static-libgcc",
Dan Willemsen07cd0512016-02-03 23:16:33 -080082 }
Dan Willemsen01f388c2017-11-30 13:31:26 -080083 windowsX86ClangLdflags = append(ClangFilterUnknownCflags(windowsX86Ldflags), []string{
Pirama Arumuga Nainar8a852e72018-06-19 20:07:54 -070084 "-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
Dan Willemsen01f388c2017-11-30 13:31:26 -080085 "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
86 "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
87 "-B${WindowsGccRoot}/${WindowsGccTriple}/lib32",
Pirama Arumuga Nainar8a852e72018-06-19 20:07:54 -070088 "-pthread",
89 // Bug: http://b/109759970 - WAR until issue with ld.bfd's
90 // inability to handle Clang-generated section names is fixed.
91 "-Wl,--allow-multiple-definition",
Dan Willemsen01f388c2017-11-30 13:31:26 -080092 }...)
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070093 windowsX86ClangLldflags = ClangFilterUnknownLldflags(windowsX86ClangLdflags)
Dan Willemsen07cd0512016-02-03 23:16:33 -080094
95 windowsX8664Ldflags = []string{
96 "-m64",
Colin Crossb98c8b02016-07-29 13:44:28 -070097 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
Pirama Arumuga Nainarabf1b312018-06-25 16:42:23 -070098 "-static-libgcc",
Dan Willemsen07cd0512016-02-03 23:16:33 -080099 }
Dan Willemsen01f388c2017-11-30 13:31:26 -0800100 windowsX8664ClangLdflags = append(ClangFilterUnknownCflags(windowsX8664Ldflags), []string{
Pirama Arumuga Nainar8a852e72018-06-19 20:07:54 -0700101 "-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
Dan Willemsen01f388c2017-11-30 13:31:26 -0800102 "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
103 "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
104 "-B${WindowsGccRoot}/${WindowsGccTriple}/lib64",
Pirama Arumuga Nainar8a852e72018-06-19 20:07:54 -0700105 "-pthread",
106 // Bug: http://b/109759970 - WAR until issue with ld.bfd's
107 // inability to handle Clang-generated section names is fixed.
108 "-Wl,--allow-multiple-definition",
Dan Willemsen01f388c2017-11-30 13:31:26 -0800109 }...)
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700110 windowsX8664ClangLldflags = ClangFilterUnknownLldflags(windowsX8664ClangLdflags)
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700111
112 windowsAvailableLibraries = addPrefix([]string{
113 "gdi32",
114 "imagehlp",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -0700115 "iphlpapi",
116 "netapi32",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700117 "ole32",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -0700118 "powrprof",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700119 "psapi",
Kenny Rootb9123492016-09-20 14:49:33 -0700120 "pthread",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700121 "userenv",
122 "uuid",
Colin Cross124fd9a2016-11-21 17:31:08 -0800123 "version",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700124 "ws2_32",
125 }, "-l")
Dan Willemsen490fd492015-11-24 17:53:15 -0800126)
127
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800128const (
129 windowsGccVersion = "4.8"
130)
131
Dan Willemsen490fd492015-11-24 17:53:15 -0800132func init() {
Colin Crossb98c8b02016-07-29 13:44:28 -0700133 pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
Dan Willemsen490fd492015-11-24 17:53:15 -0800134
Colin Crossb98c8b02016-07-29 13:44:28 -0700135 pctx.SourcePathVariable("WindowsGccRoot",
136 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
Dan Willemsen490fd492015-11-24 17:53:15 -0800137
Colin Crossb98c8b02016-07-29 13:44:28 -0700138 pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
Dan Willemsen490fd492015-11-24 17:53:15 -0800139
Colin Crossb98c8b02016-07-29 13:44:28 -0700140 pctx.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " "))
141 pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " "))
Dan Willemsen07cd0512016-02-03 23:16:33 -0800142
Dan Willemsen01f388c2017-11-30 13:31:26 -0800143 pctx.StaticVariable("WindowsClangCflags", strings.Join(windowsClangCflags, " "))
144 pctx.StaticVariable("WindowsClangLdflags", strings.Join(windowsClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700145 pctx.StaticVariable("WindowsClangLldflags", strings.Join(windowsClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800146 pctx.StaticVariable("WindowsClangCppflags", strings.Join(windowsClangCppflags, " "))
147
Colin Crossb98c8b02016-07-29 13:44:28 -0700148 pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " "))
149 pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " "))
150 pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " "))
151 pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " "))
Dan Willemsend352edf2016-05-18 16:06:10 -0700152
Dan Willemsen01f388c2017-11-30 13:31:26 -0800153 pctx.StaticVariable("WindowsX86ClangCflags",
154 strings.Join(ClangFilterUnknownCflags(windowsX86Cflags), " "))
155 pctx.StaticVariable("WindowsX8664ClangCflags",
156 strings.Join(ClangFilterUnknownCflags(windowsX8664Cflags), " "))
157 pctx.StaticVariable("WindowsX86ClangLdflags", strings.Join(windowsX86ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700158 pctx.StaticVariable("WindowsX86ClangLldflags", strings.Join(windowsX86ClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800159 pctx.StaticVariable("WindowsX8664ClangLdflags", strings.Join(windowsX8664ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700160 pctx.StaticVariable("WindowsX8664ClangLldflags", strings.Join(windowsX8664ClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800161 pctx.StaticVariable("WindowsX86ClangCppflags", strings.Join(windowsX86ClangCppflags, " "))
162 pctx.StaticVariable("WindowsX8664ClangCppflags", strings.Join(windowsX8664ClangCppflags, " "))
163
Colin Crossb98c8b02016-07-29 13:44:28 -0700164 pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
Dan Willemsen490fd492015-11-24 17:53:15 -0800165}
166
167type toolchainWindows struct {
Dan Willemsen490fd492015-11-24 17:53:15 -0800168 cFlags, ldFlags string
169}
170
Dan Willemsen07cd0512016-02-03 23:16:33 -0800171type toolchainWindowsX86 struct {
172 toolchain32Bit
173 toolchainWindows
174}
175
176type toolchainWindowsX8664 struct {
177 toolchain64Bit
178 toolchainWindows
179}
180
181func (t *toolchainWindowsX86) Name() string {
Dan Willemsen490fd492015-11-24 17:53:15 -0800182 return "x86"
183}
184
Dan Willemsen07cd0512016-02-03 23:16:33 -0800185func (t *toolchainWindowsX8664) Name() string {
186 return "x86_64"
187}
188
Dan Willemsen490fd492015-11-24 17:53:15 -0800189func (t *toolchainWindows) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700190 return "${config.WindowsGccRoot}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800191}
192
193func (t *toolchainWindows) GccTriple() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700194 return "${config.WindowsGccTriple}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800195}
196
197func (t *toolchainWindows) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800198 return windowsGccVersion
Dan Willemsen490fd492015-11-24 17:53:15 -0800199}
200
Dan Willemsen07cd0512016-02-03 23:16:33 -0800201func (t *toolchainWindowsX86) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700202 return "${config.WindowsCflags} ${config.WindowsX86Cflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800203}
204
205func (t *toolchainWindowsX8664) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700206 return "${config.WindowsCflags} ${config.WindowsX8664Cflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800207}
208
209func (t *toolchainWindows) Cppflags() string {
210 return ""
211}
212
Dan Willemsen07cd0512016-02-03 23:16:33 -0800213func (t *toolchainWindowsX86) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700214 return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800215}
216
217func (t *toolchainWindowsX8664) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700218 return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800219}
220
221func (t *toolchainWindows) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700222 return "${config.WindowsIncludeFlags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800223}
224
Dan Willemsen4f1c3d42017-09-09 01:15:26 -0700225func (t *toolchainWindowsX86) WindresFlags() string {
226 return "-F pe-i386"
227}
228
229func (t *toolchainWindowsX8664) WindresFlags() string {
230 return "-F pe-x86-64"
231}
232
Dan Willemsen490fd492015-11-24 17:53:15 -0800233func (t *toolchainWindows) ClangSupported() bool {
Pirama Arumuga Nainar8a852e72018-06-19 20:07:54 -0700234 return true
Dan Willemsen490fd492015-11-24 17:53:15 -0800235}
236
Dan Willemsen01f388c2017-11-30 13:31:26 -0800237func (t *toolchainWindowsX86) ClangTriple() string {
238 return "i686-windows-gnu"
Dan Willemsen490fd492015-11-24 17:53:15 -0800239}
240
Dan Willemsen01f388c2017-11-30 13:31:26 -0800241func (t *toolchainWindowsX8664) ClangTriple() string {
242 return "x86_64-pc-windows-gnu"
Dan Willemsen490fd492015-11-24 17:53:15 -0800243}
244
Dan Willemsen01f388c2017-11-30 13:31:26 -0800245func (t *toolchainWindowsX86) ClangCflags() string {
246 return "${config.WindowsClangCflags} ${config.WindowsX86ClangCflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800247}
248
Dan Willemsen01f388c2017-11-30 13:31:26 -0800249func (t *toolchainWindowsX8664) ClangCflags() string {
250 return "${config.WindowsClangCflags} ${config.WindowsX8664ClangCflags}"
251}
252
253func (t *toolchainWindowsX86) ClangCppflags() string {
254 return "${config.WindowsClangCppflags} ${config.WindowsX86ClangCppflags}"
255}
256
257func (t *toolchainWindowsX8664) ClangCppflags() string {
258 return "${config.WindowsClangCppflags} ${config.WindowsX8664ClangCppflags}"
259}
260
261func (t *toolchainWindowsX86) ClangLdflags() string {
262 return "${config.WindowsClangLdflags} ${config.WindowsX86ClangLdflags}"
263}
264
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700265func (t *toolchainWindowsX86) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700266 return "${config.WindowsClangLldflags} ${config.WindowsX86ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700267}
268
Dan Willemsen01f388c2017-11-30 13:31:26 -0800269func (t *toolchainWindowsX8664) ClangLdflags() string {
270 return "${config.WindowsClangLdflags} ${config.WindowsX8664ClangLdflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800271}
272
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700273func (t *toolchainWindowsX8664) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700274 return "${config.WindowsClangLldflags} ${config.WindowsX8664ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700275}
276
Dan Willemsen490fd492015-11-24 17:53:15 -0800277func (t *toolchainWindows) ShlibSuffix() string {
278 return ".dll"
279}
280
281func (t *toolchainWindows) ExecutableSuffix() string {
282 return ".exe"
283}
284
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700285func (t *toolchainWindows) AvailableLibraries() []string {
286 return windowsAvailableLibraries
287}
288
Dan Willemsen2e47b342016-11-17 01:02:25 -0800289func (t *toolchainWindows) Bionic() bool {
290 return false
291}
292
Dan Willemsen07cd0512016-02-03 23:16:33 -0800293var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
294var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
Dan Willemsen490fd492015-11-24 17:53:15 -0800295
Colin Cross635c3b02016-05-18 15:37:25 -0700296func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800297 return toolchainWindowsX86Singleton
298}
299
Colin Cross635c3b02016-05-18 15:37:25 -0700300func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800301 return toolchainWindowsX8664Singleton
Dan Willemsen490fd492015-11-24 17:53:15 -0800302}
303
304func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700305 registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
306 registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
Dan Willemsen490fd492015-11-24 17:53:15 -0800307}