blob: 8556a645ab50771e96b6f3eb4095e807fb04f1ee [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
20 "android/soong/common"
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 "-m32",
32
33 // Workaround differences in inttypes.h between host and target.
34 //See bug 12708004.
35 "-D__STDC_FORMAT_MACROS",
36 "-D__STDC_CONSTANT_MACROS",
37
38 // Use C99-compliant printf functions (%zd).
39 "-D__USE_MINGW_ANSI_STDIO=1",
40 // Admit to using >= Win2K. Both are needed because of <_mingw.h>.
41 "-D_WIN32_WINNT=0x0500",
42 "-DWINVER=0x0500",
43 // Get 64-bit off_t and related functions.
44 "-D_FILE_OFFSET_BITS=64",
45
46 // HOST_RELEASE_CFLAGS
47 "-O2", // from build/core/combo/select.mk
48 "-g", // from build/core/combo/select.mk
49 "-fno-strict-aliasing", // from build/core/combo/select.mk
50 }
51
52 windowsIncludeFlags = []string{
53 "-I${windowsGccRoot}/${windowsGccTriple}/include",
54 "-I${windowsGccRoot}/lib/gcc/${windowsGccTriple}/4.8.3/include",
55 }
56
57 windowsLdflags = []string{
58 "-m32",
59 "-L${windowsGccRoot}/${windowsGccTriple}",
60 "--enable-stdcall-fixup",
61 }
62)
63
Dan Willemsen34fc3b12015-12-07 12:30:44 -080064const (
65 windowsGccVersion = "4.8"
66)
67
Dan Willemsen490fd492015-11-24 17:53:15 -080068func init() {
Dan Willemsen34fc3b12015-12-07 12:30:44 -080069 pctx.StaticVariable("windowsGccVersion", windowsGccVersion)
Dan Willemsen490fd492015-11-24 17:53:15 -080070
Dan Willemsen34cc69e2015-09-23 15:26:20 -070071 pctx.SourcePathVariable("windowsGccRoot",
72 "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${windowsGccVersion}")
Dan Willemsen490fd492015-11-24 17:53:15 -080073
74 pctx.StaticVariable("windowsGccTriple", "x86_64-w64-mingw32")
75
76 pctx.StaticVariable("windowsCflags", strings.Join(windowsCflags, " "))
77 pctx.StaticVariable("windowsLdflags", strings.Join(windowsLdflags, " "))
78}
79
80type toolchainWindows struct {
81 toolchain32Bit
82
83 cFlags, ldFlags string
84}
85
86func (t *toolchainWindows) Name() string {
87 return "x86"
88}
89
90func (t *toolchainWindows) GccRoot() string {
91 return "${windowsGccRoot}"
92}
93
94func (t *toolchainWindows) GccTriple() string {
95 return "${windowsGccTriple}"
96}
97
98func (t *toolchainWindows) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -080099 return windowsGccVersion
Dan Willemsen490fd492015-11-24 17:53:15 -0800100}
101
102func (t *toolchainWindows) Cflags() string {
103 return "${windowsCflags}"
104}
105
106func (t *toolchainWindows) Cppflags() string {
107 return ""
108}
109
110func (t *toolchainWindows) Ldflags() string {
111 return "${windowsLdflags}"
112}
113
114func (t *toolchainWindows) IncludeFlags() string {
115 return ""
116}
117
118func (t *toolchainWindows) ClangSupported() bool {
119 return false
120}
121
122func (t *toolchainWindows) ClangTriple() string {
123 panic("Clang is not supported under mingw")
124}
125
126func (t *toolchainWindows) ClangCflags() string {
127 panic("Clang is not supported under mingw")
128}
129
130func (t *toolchainWindows) ClangCppflags() string {
131 panic("Clang is not supported under mingw")
132}
133
134func (t *toolchainWindows) ClangLdflags() string {
135 panic("Clang is not supported under mingw")
136}
137
138func (t *toolchainWindows) ShlibSuffix() string {
139 return ".dll"
140}
141
142func (t *toolchainWindows) ExecutableSuffix() string {
143 return ".exe"
144}
145
146var toolchainWindowsSingleton Toolchain = &toolchainWindows{}
147
148func windowsToolchainFactory(arch common.Arch) Toolchain {
149 return toolchainWindowsSingleton
150}
151
152func init() {
153 registerHostToolchainFactory(common.Windows, common.X86, windowsToolchainFactory)
154}