blob: 108bb85e3e9c3ebb602b9176469ae049202a9d94 [file] [log] [blame]
Colin Cross0af4b842015-04-30 16:36:18 -07001package cc
2
3import (
Colin Cross0af4b842015-04-30 16:36:18 -07004 "strings"
5
6 "android/soong/common"
7)
8
9var (
10 darwinCflags = []string{
11 "-fno-exceptions", // from build/core/combo/select.mk
12 "-Wno-multichar", // from build/core/combo/select.mk
13
Dan Willemsen490fd492015-11-24 17:53:15 -080014 "-fdiagnostics-color",
15
Colin Cross0af4b842015-04-30 16:36:18 -070016 "-fPIC",
17 "-funwind-tables",
Colin Cross0af4b842015-04-30 16:36:18 -070018
19 // Workaround differences in inttypes.h between host and target.
20 //See bug 12708004.
21 "-D__STDC_FORMAT_MACROS",
22 "-D__STDC_CONSTANT_MACROS",
23
24 // HOST_RELEASE_CFLAGS
25 "-O2", // from build/core/combo/select.mk
26 "-g", // from build/core/combo/select.mk
27 "-fno-strict-aliasing", // from build/core/combo/select.mk
28 "-isysroot ${macSdkRoot}",
29 "-mmacosx-version-min=10.9",
30 "-DMACOSX_DEPLOYMENT_TARGET=10.9",
31 }
32
33 darwinCppflags = []string{
34 "-isystem ${macSdkPath}/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
35 }
36
37 darwinLdflags = []string{
38 "-isysroot ${macSdkRoot}",
39 "-Wl,-syslibroot,${macSdkRoot}",
40 "-mmacosx-version-min=10.9",
41 }
42
43 // Extended cflags
44 darwinX86Cflags = []string{
45 "-m32",
46 }
47
48 darwinX8664Cflags = []string{
49 "-m64",
50 }
51
52 darwinX86Ldflags = []string{
53 "-m32",
54 "-Wl,-rpath,@loader_path/../lib",
Dan Willemsen3bf6b472015-09-11 17:41:10 -070055 "-Wl,-rpath,@loader_path/lib",
Colin Cross0af4b842015-04-30 16:36:18 -070056 }
57
58 darwinX8664Ldflags = []string{
59 "-m64",
60 "-Wl,-rpath,@loader_path/../lib64",
Dan Willemsen3bf6b472015-09-11 17:41:10 -070061 "-Wl,-rpath,@loader_path/lib64",
Colin Cross0af4b842015-04-30 16:36:18 -070062 }
63
64 darwinClangCflags = append([]string{
65 "-integrated-as",
66 }, clangFilterUnknownCflags(darwinCflags)...)
67
68 darwinClangLdflags = clangFilterUnknownCflags(darwinLdflags)
69
70 darwinX86ClangLdflags = clangFilterUnknownCflags(darwinX86Ldflags)
71
72 darwinX8664ClangLdflags = clangFilterUnknownCflags(darwinX8664Ldflags)
73
74 darwinClangCppflags = clangFilterUnknownCflags(darwinCppflags)
75)
76
Dan Willemsen34fc3b12015-12-07 12:30:44 -080077const (
78 darwinGccVersion = "4.2.1"
79)
80
Colin Cross0af4b842015-04-30 16:36:18 -070081func init() {
82 pctx.StaticVariable("macSdkPath", "/Applications/Xcode.app/Contents/Developer")
83 pctx.StaticVariable("macSdkRoot", "${macSdkPath}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk")
84
Dan Willemsen34fc3b12015-12-07 12:30:44 -080085 pctx.StaticVariable("darwinGccVersion", darwinGccVersion)
Colin Cross0af4b842015-04-30 16:36:18 -070086 pctx.StaticVariable("darwinGccRoot",
87 "${SrcDir}/prebuilts/gcc/${HostPrebuiltTag}/host/i686-apple-darwin-${darwinGccVersion}")
88
89 pctx.StaticVariable("darwinGccTriple", "i686-apple-darwin11")
90
91 pctx.StaticVariable("darwinCflags", strings.Join(darwinCflags, " "))
92 pctx.StaticVariable("darwinLdflags", strings.Join(darwinLdflags, " "))
93 pctx.StaticVariable("darwinCppflags", strings.Join(darwinCppflags, " "))
94
95 pctx.StaticVariable("darwinClangCflags", strings.Join(darwinClangCflags, " "))
96 pctx.StaticVariable("darwinClangLdflags", strings.Join(darwinClangLdflags, " "))
97 pctx.StaticVariable("darwinClangCppflags", strings.Join(darwinClangCppflags, " "))
98
99 // Extended cflags
100 pctx.StaticVariable("darwinX86Cflags", strings.Join(darwinX86Cflags, " "))
101 pctx.StaticVariable("darwinX8664Cflags", strings.Join(darwinX8664Cflags, " "))
102 pctx.StaticVariable("darwinX86Ldflags", strings.Join(darwinX86Ldflags, " "))
103 pctx.StaticVariable("darwinX8664Ldflags", strings.Join(darwinX8664Ldflags, " "))
104
105 pctx.StaticVariable("darwinX86ClangCflags",
106 strings.Join(clangFilterUnknownCflags(darwinX86Cflags), " "))
107 pctx.StaticVariable("darwinX8664ClangCflags",
108 strings.Join(clangFilterUnknownCflags(darwinX8664Cflags), " "))
109 pctx.StaticVariable("darwinX86ClangLdflags", strings.Join(darwinX86ClangLdflags, " "))
110 pctx.StaticVariable("darwinX8664ClangLdflags", strings.Join(darwinX8664ClangLdflags, " "))
111}
112
113type toolchainDarwin struct {
114 cFlags, ldFlags string
115}
116
117type toolchainDarwinX86 struct {
118 toolchain32Bit
119 toolchainDarwin
120}
121
122type toolchainDarwinX8664 struct {
123 toolchain64Bit
124 toolchainDarwin
125}
126
127func (t *toolchainDarwinX86) Name() string {
128 return "x86"
129}
130
131func (t *toolchainDarwinX8664) Name() string {
132 return "x86_64"
133}
134
135func (t *toolchainDarwin) GccRoot() string {
136 return "${darwinGccRoot}"
137}
138
139func (t *toolchainDarwin) GccTriple() string {
140 return "${darwinGccTriple}"
141}
142
143func (t *toolchainDarwin) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800144 return darwinGccVersion
Colin Cross0af4b842015-04-30 16:36:18 -0700145}
146
147func (t *toolchainDarwin) Cflags() string {
148 return "${darwinCflags} ${darwinX86Cflags}"
149}
150
151func (t *toolchainDarwinX8664) Cflags() string {
152 return "${darwinCflags} ${darwinX8664Cflags}"
153}
154
155func (t *toolchainDarwin) Cppflags() string {
156 return "${darwinCppflags}"
157}
158
159func (t *toolchainDarwinX86) Ldflags() string {
160 return "${darwinLdflags} ${darwinX86Ldflags}"
161}
162
163func (t *toolchainDarwinX8664) Ldflags() string {
164 return "${darwinLdflags} ${darwinX8664Ldflags}"
165}
166
167func (t *toolchainDarwin) IncludeFlags() string {
168 return ""
169}
170
171func (t *toolchainDarwinX86) ClangTriple() string {
172 return "i686-darwin-gnu"
173}
174
175func (t *toolchainDarwinX86) ClangCflags() string {
176 return "${darwinClangCflags} ${darwinX86ClangCflags}"
177}
178
179func (t *toolchainDarwinX86) ClangCppflags() string {
180 return "${darwinClangCppflags}"
181}
182
183func (t *toolchainDarwinX8664) ClangTriple() string {
184 return "x86_64-darwin-gnu"
185}
186
187func (t *toolchainDarwinX8664) ClangCflags() string {
188 return "${darwinClangCflags} ${darwinX8664ClangCflags}"
189}
190
191func (t *toolchainDarwinX8664) ClangCppflags() string {
192 return "${darwinClangCppflags}"
193}
194
195func (t *toolchainDarwinX86) ClangLdflags() string {
196 return "${darwinClangLdflags} ${darwinX86ClangLdflags}"
197}
198
199func (t *toolchainDarwinX8664) ClangLdflags() string {
200 return "${darwinClangLdflags} ${darwinX8664ClangLdflags}"
201}
202
Dan Willemsen490fd492015-11-24 17:53:15 -0800203func (t *toolchainDarwin) ShlibSuffix() string {
204 return ".dylib"
205}
206
Colin Cross0af4b842015-04-30 16:36:18 -0700207var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{}
208var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{}
209
Colin Crossc5c24ad2015-11-20 15:35:00 -0800210func darwinX86ToolchainFactory(arch common.Arch) Toolchain {
Colin Cross0af4b842015-04-30 16:36:18 -0700211 return toolchainDarwinX86Singleton
212}
213
Colin Crossc5c24ad2015-11-20 15:35:00 -0800214func darwinX8664ToolchainFactory(arch common.Arch) Toolchain {
Colin Cross0af4b842015-04-30 16:36:18 -0700215 return toolchainDarwinX8664Singleton
216}
217
218func init() {
Dan Willemsen490fd492015-11-24 17:53:15 -0800219 registerHostToolchainFactory(common.Darwin, common.X86, darwinX86ToolchainFactory)
220 registerHostToolchainFactory(common.Darwin, common.X86_64, darwinX8664ToolchainFactory)
Colin Cross0af4b842015-04-30 16:36:18 -0700221}