blob: 4aad9c8ef9b7f4185b55bdcee1dd15f9bcf8d0be [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{
25 "-fno-exceptions", // from build/core/combo/select.mk
26 "-Wno-multichar", // from build/core/combo/select.mk
27
28 "-DUSE_MINGW",
29 "-DWIN32_LEAN_AND_MEAN",
30 "-Wno-unused-parameter",
Dan Willemsen490fd492015-11-24 17:53:15 -080031
32 // Workaround differences in inttypes.h between host and target.
33 //See bug 12708004.
34 "-D__STDC_FORMAT_MACROS",
35 "-D__STDC_CONSTANT_MACROS",
36
37 // Use C99-compliant printf functions (%zd).
38 "-D__USE_MINGW_ANSI_STDIO=1",
Dan Willemsen01fdd3d2016-03-30 00:01:12 -070039 // Admit to using >= Vista. Both are needed because of <_mingw.h>.
40 "-D_WIN32_WINNT=0x0600",
41 "-DWINVER=0x0600",
Dan Willemsen490fd492015-11-24 17:53:15 -080042 // Get 64-bit off_t and related functions.
43 "-D_FILE_OFFSET_BITS=64",
44
Colin Crossb98c8b02016-07-29 13:44:28 -070045 "--sysroot ${WindowsGccRoot}/${WindowsGccTriple}",
Dan Willemsen01fdd3d2016-03-30 00:01:12 -070046
Dan Willemsen490fd492015-11-24 17:53:15 -080047 // HOST_RELEASE_CFLAGS
48 "-O2", // from build/core/combo/select.mk
49 "-g", // from build/core/combo/select.mk
50 "-fno-strict-aliasing", // from build/core/combo/select.mk
51 }
52
53 windowsIncludeFlags = []string{
Colin Crossb98c8b02016-07-29 13:44:28 -070054 "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include",
55 "-isystem ${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/include",
Dan Willemsen490fd492015-11-24 17:53:15 -080056 }
57
58 windowsLdflags = []string{
Dan Willemsen490fd492015-11-24 17:53:15 -080059 "--enable-stdcall-fixup",
60 }
Dan Willemsen07cd0512016-02-03 23:16:33 -080061
62 windowsX86Cflags = []string{
63 "-m32",
64 }
65
66 windowsX8664Cflags = []string{
67 "-m64",
68 }
69
70 windowsX86Ldflags = []string{
71 "-m32",
Colin Crossb98c8b02016-07-29 13:44:28 -070072 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
Dan Willemsen07cd0512016-02-03 23:16:33 -080073 }
74
75 windowsX8664Ldflags = []string{
76 "-m64",
Colin Crossb98c8b02016-07-29 13:44:28 -070077 "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
Dan Willemsen07cd0512016-02-03 23:16:33 -080078 }
Dan Willemsen2b1f0942016-07-20 12:47:47 -070079
80 windowsAvailableLibraries = addPrefix([]string{
81 "gdi32",
82 "imagehlp",
83 "ole32",
84 "psapi",
Kenny Rootb9123492016-09-20 14:49:33 -070085 "pthread",
Dan Willemsen2b1f0942016-07-20 12:47:47 -070086 "userenv",
87 "uuid",
Colin Cross124fd9a2016-11-21 17:31:08 -080088 "version",
Dan Willemsen2b1f0942016-07-20 12:47:47 -070089 "ws2_32",
90 }, "-l")
Dan Willemsen490fd492015-11-24 17:53:15 -080091)
92
Dan Willemsen34fc3b12015-12-07 12:30:44 -080093const (
94 windowsGccVersion = "4.8"
95)
96
Dan Willemsen490fd492015-11-24 17:53:15 -080097func init() {
Colin Crossb98c8b02016-07-29 13:44:28 -070098 pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
Dan Willemsen490fd492015-11-24 17:53:15 -080099
Colin Crossb98c8b02016-07-29 13:44:28 -0700100 pctx.SourcePathVariable("WindowsGccRoot",
101 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
Dan Willemsen490fd492015-11-24 17:53:15 -0800102
Colin Crossb98c8b02016-07-29 13:44:28 -0700103 pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
Dan Willemsen490fd492015-11-24 17:53:15 -0800104
Colin Crossb98c8b02016-07-29 13:44:28 -0700105 pctx.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " "))
106 pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " "))
Dan Willemsen07cd0512016-02-03 23:16:33 -0800107
Colin Crossb98c8b02016-07-29 13:44:28 -0700108 pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " "))
109 pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " "))
110 pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " "))
111 pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " "))
Dan Willemsend352edf2016-05-18 16:06:10 -0700112
Colin Crossb98c8b02016-07-29 13:44:28 -0700113 pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
Dan Willemsen490fd492015-11-24 17:53:15 -0800114}
115
116type toolchainWindows struct {
Dan Willemsen490fd492015-11-24 17:53:15 -0800117 cFlags, ldFlags string
118}
119
Dan Willemsen07cd0512016-02-03 23:16:33 -0800120type toolchainWindowsX86 struct {
121 toolchain32Bit
122 toolchainWindows
123}
124
125type toolchainWindowsX8664 struct {
126 toolchain64Bit
127 toolchainWindows
128}
129
130func (t *toolchainWindowsX86) Name() string {
Dan Willemsen490fd492015-11-24 17:53:15 -0800131 return "x86"
132}
133
Dan Willemsen07cd0512016-02-03 23:16:33 -0800134func (t *toolchainWindowsX8664) Name() string {
135 return "x86_64"
136}
137
Dan Willemsen490fd492015-11-24 17:53:15 -0800138func (t *toolchainWindows) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700139 return "${config.WindowsGccRoot}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800140}
141
142func (t *toolchainWindows) GccTriple() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700143 return "${config.WindowsGccTriple}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800144}
145
146func (t *toolchainWindows) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800147 return windowsGccVersion
Dan Willemsen490fd492015-11-24 17:53:15 -0800148}
149
Dan Willemsen07cd0512016-02-03 23:16:33 -0800150func (t *toolchainWindowsX86) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700151 return "${config.WindowsCflags} ${config.WindowsX86Cflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800152}
153
154func (t *toolchainWindowsX8664) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700155 return "${config.WindowsCflags} ${config.WindowsX8664Cflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800156}
157
158func (t *toolchainWindows) Cppflags() string {
159 return ""
160}
161
Dan Willemsen07cd0512016-02-03 23:16:33 -0800162func (t *toolchainWindowsX86) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700163 return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}"
Dan Willemsen07cd0512016-02-03 23:16:33 -0800164}
165
166func (t *toolchainWindowsX8664) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700167 return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800168}
169
170func (t *toolchainWindows) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700171 return "${config.WindowsIncludeFlags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800172}
173
174func (t *toolchainWindows) ClangSupported() bool {
175 return false
176}
177
178func (t *toolchainWindows) ClangTriple() string {
179 panic("Clang is not supported under mingw")
180}
181
182func (t *toolchainWindows) ClangCflags() string {
183 panic("Clang is not supported under mingw")
184}
185
186func (t *toolchainWindows) ClangCppflags() string {
187 panic("Clang is not supported under mingw")
188}
189
190func (t *toolchainWindows) ClangLdflags() string {
191 panic("Clang is not supported under mingw")
192}
193
194func (t *toolchainWindows) ShlibSuffix() string {
195 return ".dll"
196}
197
198func (t *toolchainWindows) ExecutableSuffix() string {
199 return ".exe"
200}
201
Dan Willemsen2b1f0942016-07-20 12:47:47 -0700202func (t *toolchainWindows) AvailableLibraries() []string {
203 return windowsAvailableLibraries
204}
205
Dan Willemsen2e47b342016-11-17 01:02:25 -0800206func (t *toolchainWindows) Bionic() bool {
207 return false
208}
209
Dan Willemsen07cd0512016-02-03 23:16:33 -0800210var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
211var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
Dan Willemsen490fd492015-11-24 17:53:15 -0800212
Colin Cross635c3b02016-05-18 15:37:25 -0700213func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800214 return toolchainWindowsX86Singleton
215}
216
Colin Cross635c3b02016-05-18 15:37:25 -0700217func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800218 return toolchainWindowsX8664Singleton
Dan Willemsen490fd492015-11-24 17:53:15 -0800219}
220
221func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700222 registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
223 registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
Dan Willemsen490fd492015-11-24 17:53:15 -0800224}