• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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
15package config
16
17import (
18	"strings"
19
20	"android/soong/android"
21)
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",
31
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",
39		// Admit to using >= Vista. Both are needed because of <_mingw.h>.
40		"-D_WIN32_WINNT=0x0600",
41		"-DWINVER=0x0600",
42		// Get 64-bit off_t and related functions.
43		"-D_FILE_OFFSET_BITS=64",
44
45		"--sysroot ${WindowsGccRoot}/${WindowsGccTriple}",
46
47		// 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{
54		"-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include",
55		"-isystem ${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/include",
56	}
57
58	windowsLdflags = []string{
59		"--enable-stdcall-fixup",
60	}
61
62	windowsX86Cflags = []string{
63		"-m32",
64	}
65
66	windowsX8664Cflags = []string{
67		"-m64",
68	}
69
70	windowsX86Ldflags = []string{
71		"-m32",
72		"-Wl,--large-address-aware",
73		"-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
74	}
75
76	windowsX8664Ldflags = []string{
77		"-m64",
78		"-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
79	}
80
81	windowsAvailableLibraries = addPrefix([]string{
82		"gdi32",
83		"imagehlp",
84		"ole32",
85		"psapi",
86		"pthread",
87		"userenv",
88		"uuid",
89		"version",
90		"ws2_32",
91	}, "-l")
92)
93
94const (
95	windowsGccVersion = "4.8"
96)
97
98func init() {
99	pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
100
101	pctx.SourcePathVariable("WindowsGccRoot",
102		"prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
103
104	pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
105
106	pctx.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " "))
107	pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " "))
108
109	pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " "))
110	pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " "))
111	pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " "))
112	pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " "))
113
114	pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
115}
116
117type toolchainWindows struct {
118	cFlags, ldFlags string
119}
120
121type toolchainWindowsX86 struct {
122	toolchain32Bit
123	toolchainWindows
124}
125
126type toolchainWindowsX8664 struct {
127	toolchain64Bit
128	toolchainWindows
129}
130
131func (t *toolchainWindowsX86) Name() string {
132	return "x86"
133}
134
135func (t *toolchainWindowsX8664) Name() string {
136	return "x86_64"
137}
138
139func (t *toolchainWindows) GccRoot() string {
140	return "${config.WindowsGccRoot}"
141}
142
143func (t *toolchainWindows) GccTriple() string {
144	return "${config.WindowsGccTriple}"
145}
146
147func (t *toolchainWindows) GccVersion() string {
148	return windowsGccVersion
149}
150
151func (t *toolchainWindowsX86) Cflags() string {
152	return "${config.WindowsCflags} ${config.WindowsX86Cflags}"
153}
154
155func (t *toolchainWindowsX8664) Cflags() string {
156	return "${config.WindowsCflags} ${config.WindowsX8664Cflags}"
157}
158
159func (t *toolchainWindows) Cppflags() string {
160	return ""
161}
162
163func (t *toolchainWindowsX86) Ldflags() string {
164	return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}"
165}
166
167func (t *toolchainWindowsX8664) Ldflags() string {
168	return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}"
169}
170
171func (t *toolchainWindows) IncludeFlags() string {
172	return "${config.WindowsIncludeFlags}"
173}
174
175func (t *toolchainWindows) ClangSupported() bool {
176	return false
177}
178
179func (t *toolchainWindows) ClangTriple() string {
180	panic("Clang is not supported under mingw")
181}
182
183func (t *toolchainWindows) ClangCflags() string {
184	panic("Clang is not supported under mingw")
185}
186
187func (t *toolchainWindows) ClangCppflags() string {
188	panic("Clang is not supported under mingw")
189}
190
191func (t *toolchainWindows) ClangLdflags() string {
192	panic("Clang is not supported under mingw")
193}
194
195func (t *toolchainWindows) ShlibSuffix() string {
196	return ".dll"
197}
198
199func (t *toolchainWindows) ExecutableSuffix() string {
200	return ".exe"
201}
202
203func (t *toolchainWindows) AvailableLibraries() []string {
204	return windowsAvailableLibraries
205}
206
207func (t *toolchainWindows) Bionic() bool {
208	return false
209}
210
211var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
212var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
213
214func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
215	return toolchainWindowsX86Singleton
216}
217
218func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
219	return toolchainWindowsX8664Singleton
220}
221
222func init() {
223	registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
224	registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
225}
226