• 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		"-DUSE_MINGW",
26		"-DWIN32_LEAN_AND_MEAN",
27		"-Wno-unused-parameter",
28
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",
36		// Admit to using >= Windows 7. Both are needed because of <_mingw.h>.
37		"-D_WIN32_WINNT=0x0601",
38		"-DWINVER=0x0601",
39		// Get 64-bit off_t and related functions.
40		"-D_FILE_OFFSET_BITS=64",
41
42		"--sysroot ${WindowsGccRoot}/${WindowsGccTriple}",
43	}
44	windowsClangCflags = append(ClangFilterUnknownCflags(windowsCflags), []string{}...)
45
46	windowsIncludeFlags = []string{
47		"-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include",
48	}
49
50	windowsClangCppflags = []string{}
51
52	windowsX86ClangCppflags = []string{}
53
54	windowsX8664ClangCppflags = []string{}
55
56	windowsLdflags = []string{
57		"--enable-stdcall-fixup",
58		"-Wl,--dynamicbase",
59		"-Wl,--nxcompat",
60	}
61	windowsClangLdflags  = append(ClangFilterUnknownCflags(windowsLdflags), []string{}...)
62	windowsClangLldflags = ClangFilterUnknownLldflags(windowsClangLdflags)
63
64	windowsX86Cflags = []string{
65		"-m32",
66	}
67
68	windowsX8664Cflags = []string{
69		"-m64",
70	}
71
72	windowsX86Ldflags = []string{
73		"-m32",
74		"-Wl,--large-address-aware",
75		"-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
76	}
77	windowsX86ClangLdflags = append(ClangFilterUnknownCflags(windowsX86Ldflags), []string{
78		"-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
79		"-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	}...)
83	windowsX86ClangLldflags = ClangFilterUnknownLldflags(windowsX86ClangLdflags)
84
85	windowsX8664Ldflags = []string{
86		"-m64",
87		"-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
88		"-Wl,--high-entropy-va",
89	}
90	windowsX8664ClangLdflags = append(ClangFilterUnknownCflags(windowsX8664Ldflags), []string{
91		"-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
92		"-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
93		"-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
94		"-B${WindowsGccRoot}/${WindowsGccTriple}/lib64",
95	}...)
96	windowsX8664ClangLldflags = ClangFilterUnknownLldflags(windowsX8664ClangLdflags)
97
98	windowsAvailableLibraries = addPrefix([]string{
99		"gdi32",
100		"imagehlp",
101		"iphlpapi",
102		"netapi32",
103		"oleaut32",
104		"ole32",
105		"opengl32",
106		"powrprof",
107		"psapi",
108		"pthread",
109		"userenv",
110		"uuid",
111		"version",
112		"ws2_32",
113		"windowscodecs",
114	}, "-l")
115)
116
117const (
118	windowsGccVersion = "4.8"
119)
120
121func init() {
122	pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
123
124	pctx.SourcePathVariable("WindowsGccRoot",
125		"prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
126
127	pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
128
129	pctx.StaticVariable("WindowsClangCflags", strings.Join(windowsClangCflags, " "))
130	pctx.StaticVariable("WindowsClangLdflags", strings.Join(windowsClangLdflags, " "))
131	pctx.StaticVariable("WindowsClangLldflags", strings.Join(windowsClangLldflags, " "))
132	pctx.StaticVariable("WindowsClangCppflags", strings.Join(windowsClangCppflags, " "))
133
134	pctx.StaticVariable("WindowsX86ClangCflags",
135		strings.Join(ClangFilterUnknownCflags(windowsX86Cflags), " "))
136	pctx.StaticVariable("WindowsX8664ClangCflags",
137		strings.Join(ClangFilterUnknownCflags(windowsX8664Cflags), " "))
138	pctx.StaticVariable("WindowsX86ClangLdflags", strings.Join(windowsX86ClangLdflags, " "))
139	pctx.StaticVariable("WindowsX86ClangLldflags", strings.Join(windowsX86ClangLldflags, " "))
140	pctx.StaticVariable("WindowsX8664ClangLdflags", strings.Join(windowsX8664ClangLdflags, " "))
141	pctx.StaticVariable("WindowsX8664ClangLldflags", strings.Join(windowsX8664ClangLldflags, " "))
142	pctx.StaticVariable("WindowsX86ClangCppflags", strings.Join(windowsX86ClangCppflags, " "))
143	pctx.StaticVariable("WindowsX8664ClangCppflags", strings.Join(windowsX8664ClangCppflags, " "))
144
145	pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
146	// Yasm flags
147	pctx.StaticVariable("WindowsX86YasmFlags", "-f win32 -m x86")
148	pctx.StaticVariable("WindowsX8664YasmFlags", "-f win64 -m amd64")
149}
150
151type toolchainWindows struct {
152	cFlags, ldFlags string
153}
154
155type toolchainWindowsX86 struct {
156	toolchain32Bit
157	toolchainWindows
158}
159
160type toolchainWindowsX8664 struct {
161	toolchain64Bit
162	toolchainWindows
163}
164
165func (t *toolchainWindowsX86) Name() string {
166	return "x86"
167}
168
169func (t *toolchainWindowsX8664) Name() string {
170	return "x86_64"
171}
172
173func (t *toolchainWindows) GccRoot() string {
174	return "${config.WindowsGccRoot}"
175}
176
177func (t *toolchainWindows) GccTriple() string {
178	return "${config.WindowsGccTriple}"
179}
180
181func (t *toolchainWindows) GccVersion() string {
182	return windowsGccVersion
183}
184
185func (t *toolchainWindows) IncludeFlags() string {
186	return "${config.WindowsIncludeFlags}"
187}
188
189func (t *toolchainWindowsX86) WindresFlags() string {
190	return "-F pe-i386"
191}
192
193func (t *toolchainWindowsX8664) WindresFlags() string {
194	return "-F pe-x86-64"
195}
196
197func (t *toolchainWindowsX86) ClangTriple() string {
198	return "i686-windows-gnu"
199}
200
201func (t *toolchainWindowsX8664) ClangTriple() string {
202	return "x86_64-pc-windows-gnu"
203}
204
205func (t *toolchainWindowsX86) ClangCflags() string {
206	return "${config.WindowsClangCflags} ${config.WindowsX86ClangCflags}"
207}
208
209func (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
225func (t *toolchainWindowsX86) ClangLldflags() string {
226	return "${config.WindowsClangLldflags} ${config.WindowsX86ClangLldflags}"
227}
228
229func (t *toolchainWindowsX8664) ClangLdflags() string {
230	return "${config.WindowsClangLdflags} ${config.WindowsX8664ClangLdflags}"
231}
232
233func (t *toolchainWindowsX8664) ClangLldflags() string {
234	return "${config.WindowsClangLldflags} ${config.WindowsX8664ClangLldflags}"
235}
236
237func (t *toolchainWindowsX86) YasmFlags() string {
238	return "${config.WindowsX86YasmFlags}"
239}
240
241func (t *toolchainWindowsX8664) YasmFlags() string {
242	return "${config.WindowsX8664YasmFlags}"
243}
244
245func (t *toolchainWindows) ShlibSuffix() string {
246	return ".dll"
247}
248
249func (t *toolchainWindows) ExecutableSuffix() string {
250	return ".exe"
251}
252
253func (t *toolchainWindows) AvailableLibraries() []string {
254	return windowsAvailableLibraries
255}
256
257func (t *toolchainWindows) Bionic() bool {
258	return false
259}
260
261var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
262var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
263
264func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
265	return toolchainWindowsX86Singleton
266}
267
268func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
269	return toolchainWindowsX8664Singleton
270}
271
272func init() {
273	registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
274	registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
275}
276