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