Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1 | package cc |
| 2 | |
| 3 | import ( |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 4 | "strings" |
| 5 | |
| 6 | "android/soong/common" |
| 7 | ) |
| 8 | |
| 9 | var ( |
| 10 | darwinCflags = []string{ |
| 11 | "-fno-exceptions", // from build/core/combo/select.mk |
| 12 | "-Wno-multichar", // from build/core/combo/select.mk |
| 13 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 14 | "-fdiagnostics-color", |
| 15 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 16 | "-fPIC", |
| 17 | "-funwind-tables", |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 18 | |
| 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 Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 55 | "-Wl,-rpath,@loader_path/lib", |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | darwinX8664Ldflags = []string{ |
| 59 | "-m64", |
| 60 | "-Wl,-rpath,@loader_path/../lib64", |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 61 | "-Wl,-rpath,@loader_path/lib64", |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 62 | } |
| 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 Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame^] | 77 | const ( |
| 78 | darwinGccVersion = "4.2.1" |
| 79 | ) |
| 80 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 81 | func 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 Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame^] | 85 | pctx.StaticVariable("darwinGccVersion", darwinGccVersion) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 86 | 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 | |
| 113 | type toolchainDarwin struct { |
| 114 | cFlags, ldFlags string |
| 115 | } |
| 116 | |
| 117 | type toolchainDarwinX86 struct { |
| 118 | toolchain32Bit |
| 119 | toolchainDarwin |
| 120 | } |
| 121 | |
| 122 | type toolchainDarwinX8664 struct { |
| 123 | toolchain64Bit |
| 124 | toolchainDarwin |
| 125 | } |
| 126 | |
| 127 | func (t *toolchainDarwinX86) Name() string { |
| 128 | return "x86" |
| 129 | } |
| 130 | |
| 131 | func (t *toolchainDarwinX8664) Name() string { |
| 132 | return "x86_64" |
| 133 | } |
| 134 | |
| 135 | func (t *toolchainDarwin) GccRoot() string { |
| 136 | return "${darwinGccRoot}" |
| 137 | } |
| 138 | |
| 139 | func (t *toolchainDarwin) GccTriple() string { |
| 140 | return "${darwinGccTriple}" |
| 141 | } |
| 142 | |
| 143 | func (t *toolchainDarwin) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame^] | 144 | return darwinGccVersion |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | func (t *toolchainDarwin) Cflags() string { |
| 148 | return "${darwinCflags} ${darwinX86Cflags}" |
| 149 | } |
| 150 | |
| 151 | func (t *toolchainDarwinX8664) Cflags() string { |
| 152 | return "${darwinCflags} ${darwinX8664Cflags}" |
| 153 | } |
| 154 | |
| 155 | func (t *toolchainDarwin) Cppflags() string { |
| 156 | return "${darwinCppflags}" |
| 157 | } |
| 158 | |
| 159 | func (t *toolchainDarwinX86) Ldflags() string { |
| 160 | return "${darwinLdflags} ${darwinX86Ldflags}" |
| 161 | } |
| 162 | |
| 163 | func (t *toolchainDarwinX8664) Ldflags() string { |
| 164 | return "${darwinLdflags} ${darwinX8664Ldflags}" |
| 165 | } |
| 166 | |
| 167 | func (t *toolchainDarwin) IncludeFlags() string { |
| 168 | return "" |
| 169 | } |
| 170 | |
| 171 | func (t *toolchainDarwinX86) ClangTriple() string { |
| 172 | return "i686-darwin-gnu" |
| 173 | } |
| 174 | |
| 175 | func (t *toolchainDarwinX86) ClangCflags() string { |
| 176 | return "${darwinClangCflags} ${darwinX86ClangCflags}" |
| 177 | } |
| 178 | |
| 179 | func (t *toolchainDarwinX86) ClangCppflags() string { |
| 180 | return "${darwinClangCppflags}" |
| 181 | } |
| 182 | |
| 183 | func (t *toolchainDarwinX8664) ClangTriple() string { |
| 184 | return "x86_64-darwin-gnu" |
| 185 | } |
| 186 | |
| 187 | func (t *toolchainDarwinX8664) ClangCflags() string { |
| 188 | return "${darwinClangCflags} ${darwinX8664ClangCflags}" |
| 189 | } |
| 190 | |
| 191 | func (t *toolchainDarwinX8664) ClangCppflags() string { |
| 192 | return "${darwinClangCppflags}" |
| 193 | } |
| 194 | |
| 195 | func (t *toolchainDarwinX86) ClangLdflags() string { |
| 196 | return "${darwinClangLdflags} ${darwinX86ClangLdflags}" |
| 197 | } |
| 198 | |
| 199 | func (t *toolchainDarwinX8664) ClangLdflags() string { |
| 200 | return "${darwinClangLdflags} ${darwinX8664ClangLdflags}" |
| 201 | } |
| 202 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 203 | func (t *toolchainDarwin) ShlibSuffix() string { |
| 204 | return ".dylib" |
| 205 | } |
| 206 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 207 | var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{} |
| 208 | var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{} |
| 209 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 210 | func darwinX86ToolchainFactory(arch common.Arch) Toolchain { |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 211 | return toolchainDarwinX86Singleton |
| 212 | } |
| 213 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 214 | func darwinX8664ToolchainFactory(arch common.Arch) Toolchain { |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 215 | return toolchainDarwinX8664Singleton |
| 216 | } |
| 217 | |
| 218 | func init() { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 219 | registerHostToolchainFactory(common.Darwin, common.X86, darwinX86ToolchainFactory) |
| 220 | registerHostToolchainFactory(common.Darwin, common.X86_64, darwinX8664ToolchainFactory) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 221 | } |