• 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	"path/filepath"
19	"strings"
20
21	"android/soong/android"
22)
23
24var (
25	windowsCflags = []string{
26		"-DUSE_MINGW",
27		"-DWIN32_LEAN_AND_MEAN",
28		"-Wno-unused-parameter",
29
30		// Workaround differences in inttypes.h between host and target.
31		//See bug 12708004.
32		"-D__STDC_FORMAT_MACROS",
33		"-D__STDC_CONSTANT_MACROS",
34
35		// Use C99-compliant printf functions (%zd).
36		"-D__USE_MINGW_ANSI_STDIO=1",
37		// Admit to using >= Windows 7. Both are needed because of <_mingw.h>.
38		"-D_WIN32_WINNT=0x0601",
39		"-DWINVER=0x0601",
40		// Get 64-bit off_t and related functions.
41		"-D_FILE_OFFSET_BITS=64",
42
43		// Don't adjust the layout of bitfields like msvc does.
44		"-mno-ms-bitfields",
45
46		"--sysroot ${WindowsGccRoot}/${WindowsGccTriple}",
47	}
48
49	windowsIncludeFlags = []string{
50		"-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include",
51	}
52
53	windowsCppflags = []string{}
54
55	windowsX86Cppflags = []string{
56		// Use SjLj exceptions for 32-bit.  libgcc_eh implements SjLj
57		// exception model for 32-bit.
58		"-fsjlj-exceptions",
59	}
60
61	windowsX8664Cppflags = []string{}
62
63	windowsLdflags = []string{
64		"-Wl,--dynamicbase",
65		"-Wl,--nxcompat",
66	}
67	windowsLldflags = append(windowsLdflags, []string{
68		"-Wl,--Xlink=-Brepro", // Enable deterministic build
69	}...)
70
71	windowsX86Cflags = []string{
72		"-m32",
73	}
74
75	windowsX8664Cflags = []string{
76		"-m64",
77	}
78
79	windowsX86Ldflags = []string{
80		"-m32",
81		"-Wl,--large-address-aware",
82		"-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
83		"-static-libgcc",
84
85		"-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
86		"-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
87		"-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
88		"-B${WindowsGccRoot}/${WindowsGccTriple}/lib32",
89	}
90
91	windowsX8664Ldflags = []string{
92		"-m64",
93		"-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
94		"-Wl,--high-entropy-va",
95		"-static-libgcc",
96
97		"-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
98		"-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
99		"-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
100		"-B${WindowsGccRoot}/${WindowsGccTriple}/lib64",
101	}
102
103	windowsAvailableLibraries = addPrefix([]string{
104		"gdi32",
105		"imagehlp",
106		"iphlpapi",
107		"netapi32",
108		"oleaut32",
109		"ole32",
110		"opengl32",
111		"powrprof",
112		"psapi",
113		"pthread",
114		"userenv",
115		"uuid",
116		"version",
117		"ws2_32",
118		"windowscodecs",
119	}, "-l")
120)
121
122const (
123	windowsGccVersion = "4.8"
124)
125
126func init() {
127	pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
128
129	pctx.SourcePathVariable("WindowsGccRoot",
130		"prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
131
132	pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
133
134	pctx.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " "))
135	pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " "))
136	pctx.StaticVariable("WindowsLldflags", strings.Join(windowsLldflags, " "))
137	pctx.StaticVariable("WindowsCppflags", strings.Join(windowsCppflags, " "))
138
139	pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " "))
140	pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " "))
141	pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " "))
142	pctx.StaticVariable("WindowsX86Lldflags", strings.Join(windowsX86Ldflags, " "))
143	pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " "))
144	pctx.StaticVariable("WindowsX8664Lldflags", strings.Join(windowsX8664Ldflags, " "))
145	pctx.StaticVariable("WindowsX86Cppflags", strings.Join(windowsX86Cppflags, " "))
146	pctx.StaticVariable("WindowsX8664Cppflags", strings.Join(windowsX8664Cppflags, " "))
147
148	pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
149	// Yasm flags
150	pctx.StaticVariable("WindowsX86YasmFlags", "-f win32 -m x86")
151	pctx.StaticVariable("WindowsX8664YasmFlags", "-f win64 -m amd64")
152}
153
154type toolchainWindows struct {
155	cFlags, ldFlags string
156	toolchainBase
157	toolchainNoCrt
158}
159
160type toolchainWindowsX86 struct {
161	toolchain32Bit
162	toolchainWindows
163}
164
165type toolchainWindowsX8664 struct {
166	toolchain64Bit
167	toolchainWindows
168}
169
170func (t *toolchainWindowsX86) Name() string {
171	return "x86"
172}
173
174func (t *toolchainWindowsX8664) Name() string {
175	return "x86_64"
176}
177
178func (t *toolchainWindows) ToolchainCflags() string {
179	return "-B" + filepath.Join("${config.WindowsGccRoot}", "${config.WindowsGccTriple}", "bin")
180}
181
182func (t *toolchainWindows) ToolchainLdflags() string {
183	return "-B" + filepath.Join("${config.WindowsGccRoot}", "${config.WindowsGccTriple}", "bin")
184}
185
186func (t *toolchainWindows) IncludeFlags() string {
187	return "${config.WindowsIncludeFlags}"
188}
189
190func (t *toolchainWindowsX86) ClangTriple() string {
191	return "i686-windows-gnu"
192}
193
194func (t *toolchainWindowsX8664) ClangTriple() string {
195	return "x86_64-pc-windows-gnu"
196}
197
198func (t *toolchainWindowsX86) Cflags() string {
199	return "${config.WindowsCflags} ${config.WindowsX86Cflags}"
200}
201
202func (t *toolchainWindowsX8664) Cflags() string {
203	return "${config.WindowsCflags} ${config.WindowsX8664Cflags}"
204}
205
206func (t *toolchainWindowsX86) Cppflags() string {
207	return "${config.WindowsCppflags} ${config.WindowsX86Cppflags}"
208}
209
210func (t *toolchainWindowsX8664) Cppflags() string {
211	return "${config.WindowsCppflags} ${config.WindowsX8664Cppflags}"
212}
213
214func (t *toolchainWindowsX86) Ldflags() string {
215	return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}"
216}
217
218func (t *toolchainWindowsX86) Lldflags() string {
219	return "${config.WindowsLldflags} ${config.WindowsX86Lldflags}"
220}
221
222func (t *toolchainWindowsX8664) Ldflags() string {
223	return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}"
224}
225
226func (t *toolchainWindowsX8664) Lldflags() string {
227	return "${config.WindowsLldflags} ${config.WindowsX8664Lldflags}"
228}
229
230func (t *toolchainWindowsX86) YasmFlags() string {
231	return "${config.WindowsX86YasmFlags}"
232}
233
234func (t *toolchainWindowsX8664) YasmFlags() string {
235	return "${config.WindowsX8664YasmFlags}"
236}
237
238func (t *toolchainWindows) ShlibSuffix() string {
239	return ".dll"
240}
241
242func (t *toolchainWindows) ExecutableSuffix() string {
243	return ".exe"
244}
245
246func (t *toolchainWindows) AvailableLibraries() []string {
247	return windowsAvailableLibraries
248}
249
250func (t *toolchainWindows) Bionic() bool {
251	return false
252}
253
254var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
255var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
256
257func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
258	return toolchainWindowsX86Singleton
259}
260
261func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
262	return toolchainWindowsX8664Singleton
263}
264
265func init() {
266	registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
267	registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
268}
269