blob: c9bafe61aeae87918e3433f5bff6ab5fff75bfa1 [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 }
44
45 windowsIncludeFlags = []string{
Colin Crossb98c8b02016-07-29 13:44:28 -070046 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include",
47 "-isystem ${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/include",
Dan Willemsen490fd492015-11-24 17:53:15 -080048 }
49
50 windowsLdflags = []string{
Dan Willemsen490fd492015-11-24 17:53:15 -080051 "--enable-stdcall-fixup",
52 }
Dan Willemsen07cd0512016-02-03 23:16:33 -080053
54 windowsX86Cflags = []string{
55 "-m32",
56 }
57
58 windowsX8664Cflags = []string{
59 "-m64",
60 }
61
62 windowsX86Ldflags = []string{
63 "-m32",
Dan Willemsen7752bca2017-03-14 13:36:23 -070064 "-Wl,--large-address-aware",
Colin Crossb98c8b02016-07-29 13:44:28 -070065 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
Dan Willemsen07cd0512016-02-03 23:16:33 -080066 }
67
68 windowsX8664Ldflags = []string{
69 "-m64",
Colin Crossb98c8b02016-07-29 13:44:28 -070070 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
Dan Willemsen07cd0512016-02-03 23:16:33 -080071 }
Dan Willemsen2b1f0942016-07-20 12:47:47 -070072
73 windowsAvailableLibraries = addPrefix([]string{
74 "gdi32",
75 "imagehlp",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -070076 "iphlpapi",
77 "netapi32",
Dan Willemsen2b1f0942016-07-20 12:47:47 -070078 "ole32",
Dan Willemsenb18cf7a2017-09-09 01:42:00 -070079 "powrprof",
Dan Willemsen2b1f0942016-07-20 12:47:47 -070080 "psapi",
Kenny Rootb9123492016-09-20 14:49:33 -070081 "pthread",
Dan Willemsen2b1f0942016-07-20 12:47:47 -070082 "userenv",
83 "uuid",
Colin Cross124fd9a2016-11-21 17:31:08 -080084 "version",
Dan Willemsen2b1f0942016-07-20 12:47:47 -070085 "ws2_32",
86 }, "-l")
Dan Willemsen490fd492015-11-24 17:53:15 -080087)
88
Dan Willemsen34fc3b12015-12-07 12:30:44 -080089const (
90 windowsGccVersion = "4.8"
91)
92
Dan Willemsen490fd492015-11-24 17:53:15 -080093func init() {
Colin Crossb98c8b02016-07-29 13:44:28 -070094 pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
Dan Willemsen490fd492015-11-24 17:53:15 -080095
Colin Crossb98c8b02016-07-29 13:44:28 -070096 pctx.SourcePathVariable("WindowsGccRoot",
97 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
Dan Willemsen490fd492015-11-24 17:53:15 -080098
Colin Crossb98c8b02016-07-29 13:44:28 -070099 pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
Dan Willemsen490fd492015-11-24 17:53:15 -0800100
Colin Crossb98c8b02016-07-29 13:44:28 -0700101 pctx.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " "))
102 pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " "))
Dan Willemsen07cd0512016-02-03 23:16:33 -0800103
Colin Crossb98c8b02016-07-29 13:44:28 -0700104 pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " "))
105 pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " "))
106 pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " "))
107 pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " "))
Dan Willemsend352edf2016-05-18 16:06:10 -0700108
Colin Crossb98c8b02016-07-29 13:44:28 -0700109 pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
Dan Willemsen490fd492015-11-24 17:53:15 -0800110}
111
112type toolchainWindows struct {
Dan Willemsen490fd492015-11-24 17:53:15 -0800113 cFlags, ldFlags string
114}
115
Dan Willemsen07cd0512016-02-03 23:16:33 -0800116type toolchainWindowsX86 struct {
117 toolchain32Bit
118 toolchainWindows
119}
120
121type toolchainWindowsX8664 struct {
122 toolchain64Bit
123 toolchainWindows
124}
125
126func (t *toolchainWindowsX86) Name() string {
Dan Willemsen490fd492015-11-24 17:53:15 -0800127 return "x86"
128}
129
Dan Willemsen07cd0512016-02-03 23:16:33 -0800130func (t *toolchainWindowsX8664) Name() string {
131 return "x86_64"
132}
133
Dan Willemsen490fd492015-11-24 17:53:15 -0800134func (t *toolchainWindows) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700135 return "${config.WindowsGccRoot}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800136}
137
138func (t *toolchainWindows) GccTriple() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700139 return "${config.WindowsGccTriple}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800140}
141
142func (t *toolchainWindows) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800143 return windowsGccVersion
Dan Willemsen490fd492015-11-24 17:53:15 -0800144}
145
Dan Willemsen07cd0512016-02-03 23:16:33 -0800146func (t *toolchainWindowsX86) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700147 return "${config.WindowsCflags} ${config.WindowsX86Cflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800148}
149
150func (t *toolchainWindowsX8664) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700151 return "${config.WindowsCflags} ${config.WindowsX8664Cflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800152}
153
154func (t *toolchainWindows) Cppflags() string {
155 return ""
156}
157
Dan Willemsen07cd0512016-02-03 23:16:33 -0800158func (t *toolchainWindowsX86) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700159 return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800160}
161
162func (t *toolchainWindowsX8664) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700163 return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800164}
165
166func (t *toolchainWindows) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700167 return "${config.WindowsIncludeFlags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800168}
169
Dan Willemsen4f1c3d42017-09-09 01:15:26 -0700170func (t *toolchainWindowsX86) WindresFlags() string {
171 return "-F pe-i386"
172}
173
174func (t *toolchainWindowsX8664) WindresFlags() string {
175 return "-F pe-x86-64"
176}
177
Dan Willemsen490fd492015-11-24 17:53:15 -0800178func (t *toolchainWindows) ClangSupported() bool {
179 return false
180}
181
182func (t *toolchainWindows) ClangTriple() string {
183 panic("Clang is not supported under mingw")
184}
185
186func (t *toolchainWindows) ClangCflags() string {
187 panic("Clang is not supported under mingw")
188}
189
190func (t *toolchainWindows) ClangCppflags() string {
191 panic("Clang is not supported under mingw")
192}
193
194func (t *toolchainWindows) ClangLdflags() string {
195 panic("Clang is not supported under mingw")
196}
197
198func (t *toolchainWindows) ShlibSuffix() string {
199 return ".dll"
200}
201
202func (t *toolchainWindows) ExecutableSuffix() string {
203 return ".exe"
204}
205
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700206func (t *toolchainWindows) AvailableLibraries() []string {
207 return windowsAvailableLibraries
208}
209
Dan Willemsen2e47b342016-11-17 01:02:25 -0800210func (t *toolchainWindows) Bionic() bool {
211 return false
212}
213
Dan Willemsen07cd0512016-02-03 23:16:33 -0800214var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
215var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
Dan Willemsen490fd492015-11-24 17:53:15 -0800216
Colin Cross635c3b02016-05-18 15:37:25 -0700217func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800218 return toolchainWindowsX86Singleton
219}
220
Colin Cross635c3b02016-05-18 15:37:25 -0700221func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800222 return toolchainWindowsX8664Singleton
Dan Willemsen490fd492015-11-24 17:53:15 -0800223}
224
225func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700226 registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
227 registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
Dan Willemsen490fd492015-11-24 17:53:15 -0800228}