blob: 43e8c85e8d5e34190133302b4701db60b288ca68 [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",
Pirama Arumuga Nainar105cab22019-10-15 13:56:29 -070076 "-static-libgcc",
Dan Willemsen07cd0512016-02-03 23:16:33 -080077 }
Dan Willemsen01f388c2017-11-30 13:31:26 -080078 windowsX86ClangLdflags = append(ClangFilterUnknownCflags(windowsX86Ldflags), []string{
Pirama Arumuga Nainar8a852e72018-06-19 20:07:54 -070079 "-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
Dan Willemsen01f388c2017-11-30 13:31:26 -080080 "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
81 "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
82 "-B${WindowsGccRoot}/${WindowsGccTriple}/lib32",
83 }...)
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070084 windowsX86ClangLldflags = ClangFilterUnknownLldflags(windowsX86ClangLdflags)
Dan Willemsen07cd0512016-02-03 23:16:33 -080085
86 windowsX8664Ldflags = []string{
87 "-m64",
Colin Crossb98c8b02016-07-29 13:44:28 -070088 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
Pirama Arumuga Nainar191f6462018-08-30 12:37:56 -070089 "-Wl,--high-entropy-va",
Pirama Arumuga Nainar105cab22019-10-15 13:56:29 -070090 "-static-libgcc",
Dan Willemsen07cd0512016-02-03 23:16:33 -080091 }
Dan Willemsen01f388c2017-11-30 13:31:26 -080092 windowsX8664ClangLdflags = append(ClangFilterUnknownCflags(windowsX8664Ldflags), []string{
Pirama Arumuga Nainar8a852e72018-06-19 20:07:54 -070093 "-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
Dan Willemsen01f388c2017-11-30 13:31:26 -080094 "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
95 "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
96 "-B${WindowsGccRoot}/${WindowsGccTriple}/lib64",
97 }...)
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070098 windowsX8664ClangLldflags = ClangFilterUnknownLldflags(windowsX8664ClangLdflags)
Dan Willemsen2b1f0942016-07-20 12:47:47 -070099
100 windowsAvailableLibraries = addPrefix([]string{
101 "gdi32",
102 "imagehlp",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -0700103 "iphlpapi",
104 "netapi32",
Jerome Gaillard7f7f34f2019-01-18 17:14:08 +0000105 "oleaut32",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700106 "ole32",
Jerome Gaillard7f7f34f2019-01-18 17:14:08 +0000107 "opengl32",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -0700108 "powrprof",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700109 "psapi",
Kenny Rootb9123492016-09-20 14:49:33 -0700110 "pthread",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700111 "userenv",
112 "uuid",
Colin Cross124fd9a2016-11-21 17:31:08 -0800113 "version",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700114 "ws2_32",
Jerome Gaillard7f7f34f2019-01-18 17:14:08 +0000115 "windowscodecs",
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700116 }, "-l")
Dan Willemsen490fd492015-11-24 17:53:15 -0800117)
118
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800119const (
120 windowsGccVersion = "4.8"
121)
122
Dan Willemsen490fd492015-11-24 17:53:15 -0800123func init() {
Colin Crossb98c8b02016-07-29 13:44:28 -0700124 pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
Dan Willemsen490fd492015-11-24 17:53:15 -0800125
Colin Crossb98c8b02016-07-29 13:44:28 -0700126 pctx.SourcePathVariable("WindowsGccRoot",
127 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
Dan Willemsen490fd492015-11-24 17:53:15 -0800128
Colin Crossb98c8b02016-07-29 13:44:28 -0700129 pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
Dan Willemsen490fd492015-11-24 17:53:15 -0800130
Dan Willemsen01f388c2017-11-30 13:31:26 -0800131 pctx.StaticVariable("WindowsClangCflags", strings.Join(windowsClangCflags, " "))
132 pctx.StaticVariable("WindowsClangLdflags", strings.Join(windowsClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700133 pctx.StaticVariable("WindowsClangLldflags", strings.Join(windowsClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800134 pctx.StaticVariable("WindowsClangCppflags", strings.Join(windowsClangCppflags, " "))
135
Dan Willemsen01f388c2017-11-30 13:31:26 -0800136 pctx.StaticVariable("WindowsX86ClangCflags",
137 strings.Join(ClangFilterUnknownCflags(windowsX86Cflags), " "))
138 pctx.StaticVariable("WindowsX8664ClangCflags",
139 strings.Join(ClangFilterUnknownCflags(windowsX8664Cflags), " "))
140 pctx.StaticVariable("WindowsX86ClangLdflags", strings.Join(windowsX86ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700141 pctx.StaticVariable("WindowsX86ClangLldflags", strings.Join(windowsX86ClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800142 pctx.StaticVariable("WindowsX8664ClangLdflags", strings.Join(windowsX8664ClangLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700143 pctx.StaticVariable("WindowsX8664ClangLldflags", strings.Join(windowsX8664ClangLldflags, " "))
Dan Willemsen01f388c2017-11-30 13:31:26 -0800144 pctx.StaticVariable("WindowsX86ClangCppflags", strings.Join(windowsX86ClangCppflags, " "))
145 pctx.StaticVariable("WindowsX8664ClangCppflags", strings.Join(windowsX8664ClangCppflags, " "))
146
Colin Crossb98c8b02016-07-29 13:44:28 -0700147 pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
Jerome Gaillard80fec092018-11-29 15:34:32 +0000148 // Yasm flags
149 pctx.StaticVariable("WindowsX86YasmFlags", "-f win32 -m x86")
150 pctx.StaticVariable("WindowsX8664YasmFlags", "-f win64 -m amd64")
Dan Willemsen490fd492015-11-24 17:53:15 -0800151}
152
153type toolchainWindows struct {
Dan Willemsen490fd492015-11-24 17:53:15 -0800154 cFlags, ldFlags string
155}
156
Dan Willemsen07cd0512016-02-03 23:16:33 -0800157type toolchainWindowsX86 struct {
158 toolchain32Bit
159 toolchainWindows
160}
161
162type toolchainWindowsX8664 struct {
163 toolchain64Bit
164 toolchainWindows
165}
166
167func (t *toolchainWindowsX86) Name() string {
Dan Willemsen490fd492015-11-24 17:53:15 -0800168 return "x86"
169}
170
Dan Willemsen07cd0512016-02-03 23:16:33 -0800171func (t *toolchainWindowsX8664) Name() string {
172 return "x86_64"
173}
174
Dan Willemsen490fd492015-11-24 17:53:15 -0800175func (t *toolchainWindows) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700176 return "${config.WindowsGccRoot}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800177}
178
179func (t *toolchainWindows) GccTriple() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700180 return "${config.WindowsGccTriple}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800181}
182
183func (t *toolchainWindows) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800184 return windowsGccVersion
Dan Willemsen490fd492015-11-24 17:53:15 -0800185}
186
Dan Willemsen490fd492015-11-24 17:53:15 -0800187func (t *toolchainWindows) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700188 return "${config.WindowsIncludeFlags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800189}
190
Dan Willemsen4f1c3d42017-09-09 01:15:26 -0700191func (t *toolchainWindowsX86) WindresFlags() string {
192 return "-F pe-i386"
193}
194
195func (t *toolchainWindowsX8664) WindresFlags() string {
196 return "-F pe-x86-64"
197}
198
Dan Willemsen01f388c2017-11-30 13:31:26 -0800199func (t *toolchainWindowsX86) ClangTriple() string {
200 return "i686-windows-gnu"
Dan Willemsen490fd492015-11-24 17:53:15 -0800201}
202
Dan Willemsen01f388c2017-11-30 13:31:26 -0800203func (t *toolchainWindowsX8664) ClangTriple() string {
204 return "x86_64-pc-windows-gnu"
Dan Willemsen490fd492015-11-24 17:53:15 -0800205}
206
Dan Willemsen01f388c2017-11-30 13:31:26 -0800207func (t *toolchainWindowsX86) ClangCflags() string {
208 return "${config.WindowsClangCflags} ${config.WindowsX86ClangCflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800209}
210
Dan Willemsen01f388c2017-11-30 13:31:26 -0800211func (t *toolchainWindowsX8664) ClangCflags() string {
212 return "${config.WindowsClangCflags} ${config.WindowsX8664ClangCflags}"
213}
214
215func (t *toolchainWindowsX86) ClangCppflags() string {
216 return "${config.WindowsClangCppflags} ${config.WindowsX86ClangCppflags}"
217}
218
219func (t *toolchainWindowsX8664) ClangCppflags() string {
220 return "${config.WindowsClangCppflags} ${config.WindowsX8664ClangCppflags}"
221}
222
223func (t *toolchainWindowsX86) ClangLdflags() string {
224 return "${config.WindowsClangLdflags} ${config.WindowsX86ClangLdflags}"
225}
226
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700227func (t *toolchainWindowsX86) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700228 return "${config.WindowsClangLldflags} ${config.WindowsX86ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700229}
230
Dan Willemsen01f388c2017-11-30 13:31:26 -0800231func (t *toolchainWindowsX8664) ClangLdflags() string {
232 return "${config.WindowsClangLdflags} ${config.WindowsX8664ClangLdflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800233}
234
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700235func (t *toolchainWindowsX8664) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700236 return "${config.WindowsClangLldflags} ${config.WindowsX8664ClangLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700237}
238
Jerome Gaillard80fec092018-11-29 15:34:32 +0000239func (t *toolchainWindowsX86) YasmFlags() string {
240 return "${config.WindowsX86YasmFlags}"
241}
242
243func (t *toolchainWindowsX8664) YasmFlags() string {
244 return "${config.WindowsX8664YasmFlags}"
245}
246
Dan Willemsen490fd492015-11-24 17:53:15 -0800247func (t *toolchainWindows) ShlibSuffix() string {
248 return ".dll"
249}
250
251func (t *toolchainWindows) ExecutableSuffix() string {
252 return ".exe"
253}
254
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700255func (t *toolchainWindows) AvailableLibraries() []string {
256 return windowsAvailableLibraries
257}
258
Dan Willemsen2e47b342016-11-17 01:02:25 -0800259func (t *toolchainWindows) Bionic() bool {
260 return false
261}
262
Dan Willemsen07cd0512016-02-03 23:16:33 -0800263var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
264var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
Dan Willemsen490fd492015-11-24 17:53:15 -0800265
Colin Cross635c3b02016-05-18 15:37:25 -0700266func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800267 return toolchainWindowsX86Singleton
268}
269
Colin Cross635c3b02016-05-18 15:37:25 -0700270func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800271 return toolchainWindowsX8664Singleton
Dan Willemsen490fd492015-11-24 17:53:15 -0800272}
273
274func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700275 registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
276 registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
Dan Willemsen490fd492015-11-24 17:53:15 -0800277}