blob: a190b2690841e13a8ae689c3e8a2a4164447c46d [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
15package cc
16
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
Dan Willemsen01fdd3d2016-03-30 00:01:12 -070045 "--sysroot ${windowsGccRoot}/${windowsGccTriple}",
46
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{
Dan Willemsend352edf2016-05-18 16:06:10 -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",
72 }
73
74 windowsX8664Ldflags = []string{
75 "-m64",
76 }
Dan Willemsen490fd492015-11-24 17:53:15 -080077)
78
Dan Willemsen34fc3b12015-12-07 12:30:44 -080079const (
80 windowsGccVersion = "4.8"
81)
82
Dan Willemsen490fd492015-11-24 17:53:15 -080083func init() {
Dan Willemsen34fc3b12015-12-07 12:30:44 -080084 pctx.StaticVariable("windowsGccVersion", windowsGccVersion)
Dan Willemsen490fd492015-11-24 17:53:15 -080085
Dan Willemsen34cc69e2015-09-23 15:26:20 -070086 pctx.SourcePathVariable("windowsGccRoot",
87 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${windowsGccVersion}")
Dan Willemsen490fd492015-11-24 17:53:15 -080088
89 pctx.StaticVariable("windowsGccTriple", "x86_64-w64-mingw32")
90
91 pctx.StaticVariable("windowsCflags", strings.Join(windowsCflags, " "))
92 pctx.StaticVariable("windowsLdflags", strings.Join(windowsLdflags, " "))
Dan Willemsen07cd0512016-02-03 23:16:33 -080093
94 pctx.StaticVariable("windowsX86Cflags", strings.Join(windowsX86Cflags, " "))
95 pctx.StaticVariable("windowsX8664Cflags", strings.Join(windowsX8664Cflags, " "))
96 pctx.StaticVariable("windowsX86Ldflags", strings.Join(windowsX86Ldflags, " "))
97 pctx.StaticVariable("windowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " "))
Dan Willemsend352edf2016-05-18 16:06:10 -070098
99 pctx.StaticVariable("windowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
Dan Willemsen490fd492015-11-24 17:53:15 -0800100}
101
102type toolchainWindows struct {
Dan Willemsen490fd492015-11-24 17:53:15 -0800103 cFlags, ldFlags string
104}
105
Dan Willemsen07cd0512016-02-03 23:16:33 -0800106type toolchainWindowsX86 struct {
107 toolchain32Bit
108 toolchainWindows
109}
110
111type toolchainWindowsX8664 struct {
112 toolchain64Bit
113 toolchainWindows
114}
115
116func (t *toolchainWindowsX86) Name() string {
Dan Willemsen490fd492015-11-24 17:53:15 -0800117 return "x86"
118}
119
Dan Willemsen07cd0512016-02-03 23:16:33 -0800120func (t *toolchainWindowsX8664) Name() string {
121 return "x86_64"
122}
123
Dan Willemsen490fd492015-11-24 17:53:15 -0800124func (t *toolchainWindows) GccRoot() string {
125 return "${windowsGccRoot}"
126}
127
128func (t *toolchainWindows) GccTriple() string {
129 return "${windowsGccTriple}"
130}
131
132func (t *toolchainWindows) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800133 return windowsGccVersion
Dan Willemsen490fd492015-11-24 17:53:15 -0800134}
135
Dan Willemsen07cd0512016-02-03 23:16:33 -0800136func (t *toolchainWindowsX86) Cflags() string {
137 return "${windowsCflags} ${windowsX86Cflags}"
138}
139
140func (t *toolchainWindowsX8664) Cflags() string {
141 return "${windowsCflags} ${windowsX8664Cflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800142}
143
144func (t *toolchainWindows) Cppflags() string {
145 return ""
146}
147
Dan Willemsen07cd0512016-02-03 23:16:33 -0800148func (t *toolchainWindowsX86) Ldflags() string {
149 return "${windowsLdflags} ${windowsX86Ldflags}"
150}
151
152func (t *toolchainWindowsX8664) Ldflags() string {
153 return "${windowsLdflags} ${windowsX8664Ldflags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800154}
155
156func (t *toolchainWindows) IncludeFlags() string {
Dan Willemsend352edf2016-05-18 16:06:10 -0700157 return "${windowsIncludeFlags}"
Dan Willemsen490fd492015-11-24 17:53:15 -0800158}
159
160func (t *toolchainWindows) ClangSupported() bool {
161 return false
162}
163
164func (t *toolchainWindows) ClangTriple() string {
165 panic("Clang is not supported under mingw")
166}
167
168func (t *toolchainWindows) ClangCflags() string {
169 panic("Clang is not supported under mingw")
170}
171
172func (t *toolchainWindows) ClangCppflags() string {
173 panic("Clang is not supported under mingw")
174}
175
176func (t *toolchainWindows) ClangLdflags() string {
177 panic("Clang is not supported under mingw")
178}
179
180func (t *toolchainWindows) ShlibSuffix() string {
181 return ".dll"
182}
183
184func (t *toolchainWindows) ExecutableSuffix() string {
185 return ".exe"
186}
187
Dan Willemsen07cd0512016-02-03 23:16:33 -0800188var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
189var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
Dan Willemsen490fd492015-11-24 17:53:15 -0800190
Colin Cross635c3b02016-05-18 15:37:25 -0700191func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800192 return toolchainWindowsX86Singleton
193}
194
Colin Cross635c3b02016-05-18 15:37:25 -0700195func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
Dan Willemsen07cd0512016-02-03 23:16:33 -0800196 return toolchainWindowsX8664Singleton
Dan Willemsen490fd492015-11-24 17:53:15 -0800197}
198
199func init() {
Colin Cross635c3b02016-05-18 15:37:25 -0700200 registerHostToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
201 registerHostToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
Dan Willemsen490fd492015-11-24 17:53:15 -0800202}