Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 18 | "fmt" |
| 19 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 20 | "android/soong/android" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 21 | ) |
| 22 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 23 | type toolchainFactory func(arch android.Arch) Toolchain |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 24 | |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame^] | 25 | var toolchainFactories = map[android.HostOrDevice]map[android.HostType]map[android.ArchType]toolchainFactory{ |
| 26 | android.Host: map[android.HostType]map[android.ArchType]toolchainFactory{ |
| 27 | android.Linux: make(map[android.ArchType]toolchainFactory), |
| 28 | android.Darwin: make(map[android.ArchType]toolchainFactory), |
| 29 | android.Windows: make(map[android.ArchType]toolchainFactory), |
| 30 | }, |
| 31 | android.Device: map[android.HostType]map[android.ArchType]toolchainFactory{ |
| 32 | android.NoHostType: make(map[android.ArchType]toolchainFactory), |
| 33 | }, |
| 34 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 35 | |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame^] | 36 | func registerDeviceToolchainFactory(arch android.ArchType, factory toolchainFactory) { |
| 37 | toolchainFactories[android.Device][android.NoHostType][arch] = factory |
| 38 | } |
| 39 | |
| 40 | func registerHostToolchainFactory(ht android.HostType, arch android.ArchType, factory toolchainFactory) { |
| 41 | toolchainFactories[android.Host][ht][arch] = factory |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 42 | } |
| 43 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 44 | type Toolchain interface { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 45 | Name() string |
| 46 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 47 | GccRoot() string |
| 48 | GccTriple() string |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 49 | // GccVersion should return a real value, not a ninja reference |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 50 | GccVersion() string |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 51 | |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame] | 52 | ToolchainCflags() string |
| 53 | ToolchainLdflags() string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 54 | Cflags() string |
| 55 | Cppflags() string |
| 56 | Ldflags() string |
| 57 | IncludeFlags() string |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 58 | InstructionSetFlags(string) (string, error) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 59 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 60 | ClangSupported() bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 61 | ClangTriple() string |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame] | 62 | ToolchainClangCflags() string |
Dan Willemsen | e717492 | 2016-03-30 17:33:52 -0700 | [diff] [blame] | 63 | ToolchainClangLdflags() string |
Dan Willemsen | 32968a2 | 2016-01-12 22:25:34 -0800 | [diff] [blame] | 64 | ClangAsflags() string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 65 | ClangCflags() string |
| 66 | ClangCppflags() string |
| 67 | ClangLdflags() string |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 68 | ClangInstructionSetFlags(string) (string, error) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 69 | |
| 70 | Is64Bit() bool |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 71 | |
| 72 | ShlibSuffix() string |
| 73 | ExecutableSuffix() string |
Dan Willemsen | 282a4b0 | 2016-03-09 10:30:22 -0800 | [diff] [blame] | 74 | |
| 75 | SystemCppCppflags() string |
| 76 | SystemCppLdflags() string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 77 | |
| 78 | AddressSanitizerRuntimeLibrary() string |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 79 | |
| 80 | AvailableLibraries() []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 83 | type toolchainBase struct { |
| 84 | } |
| 85 | |
| 86 | func (toolchainBase) InstructionSetFlags(s string) (string, error) { |
| 87 | if s != "" { |
| 88 | return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s) |
| 89 | } |
| 90 | return "", nil |
| 91 | } |
| 92 | |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 93 | func (toolchainBase) ClangInstructionSetFlags(s string) (string, error) { |
| 94 | if s != "" { |
| 95 | return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s) |
| 96 | } |
| 97 | return "", nil |
| 98 | } |
| 99 | |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame] | 100 | func (toolchainBase) ToolchainCflags() string { |
| 101 | return "" |
| 102 | } |
| 103 | |
| 104 | func (toolchainBase) ToolchainLdflags() string { |
| 105 | return "" |
| 106 | } |
| 107 | |
| 108 | func (toolchainBase) ToolchainClangCflags() string { |
| 109 | return "" |
| 110 | } |
| 111 | |
Dan Willemsen | e717492 | 2016-03-30 17:33:52 -0700 | [diff] [blame] | 112 | func (toolchainBase) ToolchainClangLdflags() string { |
| 113 | return "" |
| 114 | } |
| 115 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 116 | func (toolchainBase) ClangSupported() bool { |
| 117 | return true |
| 118 | } |
| 119 | |
| 120 | func (toolchainBase) ShlibSuffix() string { |
| 121 | return ".so" |
| 122 | } |
| 123 | |
| 124 | func (toolchainBase) ExecutableSuffix() string { |
| 125 | return "" |
| 126 | } |
| 127 | |
Dan Willemsen | 32968a2 | 2016-01-12 22:25:34 -0800 | [diff] [blame] | 128 | func (toolchainBase) ClangAsflags() string { |
| 129 | return "" |
| 130 | } |
| 131 | |
Dan Willemsen | 282a4b0 | 2016-03-09 10:30:22 -0800 | [diff] [blame] | 132 | func (toolchainBase) SystemCppCppflags() string { |
| 133 | return "" |
| 134 | } |
| 135 | |
| 136 | func (toolchainBase) SystemCppLdflags() string { |
| 137 | return "" |
| 138 | } |
| 139 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 140 | func (toolchainBase) AddressSanitizerRuntimeLibrary() string { |
| 141 | return "" |
| 142 | } |
| 143 | |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 144 | func (toolchainBase) AvailableLibraries() []string { |
| 145 | return []string{} |
| 146 | } |
| 147 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 148 | type toolchain64Bit struct { |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 149 | toolchainBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | func (toolchain64Bit) Is64Bit() bool { |
| 153 | return true |
| 154 | } |
| 155 | |
| 156 | type toolchain32Bit struct { |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 157 | toolchainBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | func (toolchain32Bit) Is64Bit() bool { |
| 161 | return false |
| 162 | } |