blob: 0f500b6fbc78dd0f0c3459aab32166dc59c4fb25 [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",
Jerome Gaillard82bb8b12018-12-04 12:36:49 +000036 // Admit to using >= Windows 7. Both are needed because of <_mingw.h>.
37 "-D_WIN32_WINNT=0x0601",
38 "-DWINVER=0x0601",
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
Pirama Arumuga Nainara403cc72018-08-08 10:28:12 -070050 windowsClangCppflags = []string{}
Dan Willemsen01f388c2017-11-30 13:31:26 -080051
Pirama Arumuga Nainara403cc72018-08-08 10:28:12 -070052 windowsX86ClangCppflags = []string{}
Dan Willemsen01f388c2017-11-30 13:31:26 -080053
Pirama Arumuga Nainara403cc72018-08-08 10:28:12 -070054 windowsX8664ClangCppflags = []string{}
Dan Willemsen01f388c2017-11-30 13:31:26 -080055
Dan Willemsen490fd492015-11-24 17:53:15 -080056 windowsLdflags = []string{
Dan Willemsen490fd492015-11-24 17:53:15 -080057 "--enable-stdcall-fixup",
Pirama Arumuga Nainar191f6462018-08-30 12:37:56 -070058 "-Wl,--dynamicbase",
59 "-Wl,--nxcompat",
Dan Willemsen490fd492015-11-24 17:53:15 -080060 }
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070061 windowsClangLdflags = append(ClangFilterUnknownCflags(windowsLdflags), []string{}...)
62 windowsClangLldflags = ClangFilterUnknownLldflags(windowsClangLdflags)
Dan Willemsen07cd0512016-02-03 23:16:33 -080063
64 windowsX86Cflags = []string{
65 "-m32",
66 }
67
68 windowsX8664Cflags = []string{
69 "-m64",
70 }
71
72 windowsX86Ldflags = []string{
73 "-m32",
Dan Willemsen7752bca2017-03-14 13:36:23 -070074 "-Wl,--large-address-aware",
Colin Crossb98c8b02016-07-29 13:44:28 -070075 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
Dan Willemsen07cd0512016-02-03 23:16:33 -080076 }
Dan Willemsen01f388c2017-11-30 13:31:26 -080077 windowsX86ClangLdflags = append(ClangFilterUnknownCflags(windowsX86Ldflags), []string{
Pirama Arumuga Nainar8a852e72018-06-19 20:07:54 -070078 "-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
Dan Willemsen01f388c2017-11-30 13:31:26 -080079 "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
80 "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
81 "-B${WindowsGccRoot}/${WindowsGccTriple}/lib32",
82 }...)
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070083 windowsX86ClangLldflags = ClangFilterUnknownLldflags(windowsX86ClangLdflags)
Dan Willemsen07cd0512016-02-03 23:16:33 -080084
85 windowsX8664Ldflags = []string{
86 "-m64",
Colin Crossb98c8b02016-07-29 13:44:28 -070087 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
Pirama Arumuga Nainar191f6462018-08-30 12:37:56 -070088 "-Wl,--high-entropy-va",
Dan Willemsen07cd0512016-02-03 23:16:33 -080089 }
Dan Willemsen01f388c2017-11-30 13:31:26 -080090 windowsX8664ClangLdflags = append(ClangFilterUnknownCflags(windowsX8664Ldflags), []string{
Pirama Arumuga Nainar8a852e72018-06-19 20:07:54 -070091 "-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
Dan Willemsen01f388c2017-11-30 13:31:26 -080092 "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
93 "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
94 "-B${WindowsGccRoot}/${WindowsGccTriple}/lib64",
95 }...)
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070096 windowsX8664ClangLldflags = ClangFilterUnknownLldflags(windowsX8664ClangLdflags)
Dan Willemsen2b1f0942016-07-20 12:47:47 -070097
98 windowsAvailableLibraries = addPrefix([]string{
99 "gdi32",
100 "imagehlp",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -0700101 "iphlpapi",
102 "netapi32",
Jerome Gaillard7f7f34f2019-01-18 17:14:08 +0000103 "oleaut32",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700104 "ole32",
Jerome Gaillard7f7f34f2019-01-18 17:14:08 +0000105 "opengl32",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -0700106 "powrprof",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700107 "psapi",
Kenny Rootb9123492016-09-20 14:49:33 -0700108 "pthread",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700109 "userenv",
110 "uuid",
Colin Cross124fd9a2016-11-21 17:31:08 -0800111 "version",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700112 "ws2_32",
Jerome Gaillard7f7f34f2019-01-18 17:14:08 +0000113 "windowscodecs",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700114 }, "-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
Dan Willemsen01f388c2017-11-30 13:31:26 -0800129 pctx.StaticVariable("WindowsClangCflags", strings.Join(windowsClangCflags, " "))
130 pctx.StaticVariable("WindowsClangLdflags", strings.Join(windowsClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700131 pctx.StaticVariable("WindowsClangLldflags", strings.Join(windowsClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800132 pctx.StaticVariable("WindowsClangCppflags", strings.Join(windowsClangCppflags, " "))
133
Dan Willemsen01f388c2017-11-30 13:31:26 -0800134 pctx.StaticVariable("WindowsX86ClangCflags",
135 strings.Join(ClangFilterUnknownCflags(windowsX86Cflags), " "))
136 pctx.StaticVariable("WindowsX8664ClangCflags",
137 strings.Join(ClangFilterUnknownCflags(windowsX8664Cflags), " "))
138 pctx.StaticVariable("WindowsX86ClangLdflags", strings.Join(windowsX86ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700139 pctx.StaticVariable("WindowsX86ClangLldflags", strings.Join(windowsX86ClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800140 pctx.StaticVariable("WindowsX8664ClangLdflags", strings.Join(windowsX8664ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700141 pctx.StaticVariable("WindowsX8664ClangLldflags", strings.Join(windowsX8664ClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800142 pctx.StaticVariable("WindowsX86ClangCppflags", strings.Join(windowsX86ClangCppflags, " "))
143 pctx.StaticVariable("WindowsX8664ClangCppflags", strings.Join(windowsX8664ClangCppflags, " "))
144
Colin Crossb98c8b02016-07-29 13:44:28 -0700145 pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
Jerome Gaillard80fec092018-11-29 15:34:32 +0000146 // Yasm flags
147 pctx.StaticVariable("WindowsX86YasmFlags", "-f win32 -m x86")
148 pctx.StaticVariable("WindowsX8664YasmFlags", "-f win64 -m amd64")
Dan Willemsen490fd492015-11-24 17:53:15 -0800149}
150
151type toolchainWindows struct {
Dan Willemsen490fd492015-11-24 17:53:15 -0800152 cFlags, ldFlags string
153}
154
Dan Willemsen07cd0512016-02-03 23:16:33 -0800155type toolchainWindowsX86 struct {
156 toolchain32Bit
157 toolchainWindows
158}
159
160type toolchainWindowsX8664 struct {
161 toolchain64Bit
162 toolchainWindows
163}
164
165func (t *toolchainWindowsX86) Name() string {
Dan Willemsen490fd492015-11-24 17:53:15 -0800166 return "x86"
167}
168
Dan Willemsen07cd0512016-02-03 23:16:33 -0800169func (t *toolchainWindowsX8664) Name() string {
170 return "x86_64"
171}
172
Dan Willemsen490fd492015-11-24 17:53:15 -0800173func (t *toolchainWindows) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700174 return "${config.WindowsGccRoot}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800175}
176
177func (t *toolchainWindows) GccTriple() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700178 return "${config.WindowsGccTriple}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800179}
180
181func (t *toolchainWindows) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800182 return windowsGccVersion
Dan Willemsen490fd492015-11-24 17:53:15 -0800183}
184
Dan Willemsen490fd492015-11-24 17:53:15 -0800185func (t *toolchainWindows) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700186 return "${config.WindowsIncludeFlags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800187}
188
Dan Willemsen4f1c3d42017-09-09 01:15:26 -0700189func (t *toolchainWindowsX86) WindresFlags() string {
190 return "-F pe-i386"
191}
192
193func (t *toolchainWindowsX8664) WindresFlags() string {
194 return "-F pe-x86-64"
195}
196
Dan Willemsen01f388c2017-11-30 13:31:26 -0800197func (t *toolchainWindowsX86) ClangTriple() string {
198 return "i686-windows-gnu"
Dan Willemsen490fd492015-11-24 17:53:15 -0800199}
200
Dan Willemsen01f388c2017-11-30 13:31:26 -0800201func (t *toolchainWindowsX8664) ClangTriple() string {
202 return "x86_64-pc-windows-gnu"
Dan Willemsen490fd492015-11-24 17:53:15 -0800203}
204
Dan Willemsen01f388c2017-11-30 13:31:26 -0800205func (t *toolchainWindowsX86) ClangCflags() string {
206 return "${config.WindowsClangCflags} ${config.WindowsX86ClangCflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800207}
208
Dan Willemsen01f388c2017-11-30 13:31:26 -0800209func (t *toolchainWindowsX8664) ClangCflags() string {
210 return "${config.WindowsClangCflags} ${config.WindowsX8664ClangCflags}"
211}
212
213func (t *toolchainWindowsX86) ClangCppflags() string {
214 return "${config.WindowsClangCppflags} ${config.WindowsX86ClangCppflags}"
215}
216
217func (t *toolchainWindowsX8664) ClangCppflags() string {
218 return "${config.WindowsClangCppflags} ${config.WindowsX8664ClangCppflags}"
219}
220
221func (t *toolchainWindowsX86) ClangLdflags() string {
222 return "${config.WindowsClangLdflags} ${config.WindowsX86ClangLdflags}"
223}
224
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700225func (t *toolchainWindowsX86) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700226 return "${config.WindowsClangLldflags} ${config.WindowsX86ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700227}
228
Dan Willemsen01f388c2017-11-30 13:31:26 -0800229func (t *toolchainWindowsX8664) ClangLdflags() string {
230 return "${config.WindowsClangLdflags} ${config.WindowsX8664ClangLdflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800231}
232
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700233func (t *toolchainWindowsX8664) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700234 return "${config.WindowsClangLldflags} ${config.WindowsX8664ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700235}
236
Jerome Gaillard80fec092018-11-29 15:34:32 +0000237func (t *toolchainWindowsX86) YasmFlags() string {
238 return "${config.WindowsX86YasmFlags}"
239}
240
241func (t *toolchainWindowsX8664) YasmFlags() string {
242 return "${config.WindowsX8664YasmFlags}"
243}
244
Dan Willemsen490fd492015-11-24 17:53:15 -0800245func (t *toolchainWindows) ShlibSuffix() string {
246 return ".dll"
247}
248
249func (t *toolchainWindows) ExecutableSuffix() string {
250 return ".exe"
251}
252
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700253func (t *toolchainWindows) AvailableLibraries() []string {
254 return windowsAvailableLibraries
255}
256
Dan Willemsen2e47b342016-11-17 01:02:25 -0800257func (t *toolchainWindows) Bionic() bool {
258 return false
259}
260
Dan Willemsen07cd0512016-02-03 23:16:33 -0800261var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
262var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
Dan Willemsen490fd492015-11-24 17:53:15 -0800263
Colin Cross635c3b02016-05-18 15:37:25 -0700264func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800265 return toolchainWindowsX86Singleton
266}
267
Colin Cross635c3b02016-05-18 15:37:25 -0700268func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800269 return toolchainWindowsX8664Singleton
Dan Willemsen490fd492015-11-24 17:53:15 -0800270}
271
272func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700273 registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
274 registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
Dan Willemsen490fd492015-11-24 17:53:15 -0800275}