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 | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 20 | "android/soong/common" |
| 21 | ) |
| 22 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 23 | type toolchainFactory func(arch common.Arch) Toolchain |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 24 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 25 | var toolchainFactories = map[common.HostOrDevice]map[common.HostType]map[common.ArchType]toolchainFactory{ |
| 26 | common.Host: map[common.HostType]map[common.ArchType]toolchainFactory{ |
| 27 | common.Linux: make(map[common.ArchType]toolchainFactory), |
| 28 | common.Darwin: make(map[common.ArchType]toolchainFactory), |
| 29 | common.Windows: make(map[common.ArchType]toolchainFactory), |
| 30 | }, |
| 31 | common.Device: map[common.HostType]map[common.ArchType]toolchainFactory{ |
| 32 | common.NoHostType: make(map[common.ArchType]toolchainFactory), |
| 33 | }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 36 | func registerDeviceToolchainFactory(arch common.ArchType, factory toolchainFactory) { |
| 37 | toolchainFactories[common.Device][common.NoHostType][arch] = factory |
| 38 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 39 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 40 | func registerHostToolchainFactory(ht common.HostType, arch common.ArchType, factory toolchainFactory) { |
| 41 | toolchainFactories[common.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 |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 63 | ClangCflags() string |
| 64 | ClangCppflags() string |
| 65 | ClangLdflags() string |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 66 | ClangInstructionSetFlags(string) (string, error) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 67 | |
| 68 | Is64Bit() bool |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 69 | |
| 70 | ShlibSuffix() string |
| 71 | ExecutableSuffix() string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 74 | type toolchainBase struct { |
| 75 | } |
| 76 | |
| 77 | func (toolchainBase) InstructionSetFlags(s string) (string, error) { |
| 78 | if s != "" { |
| 79 | return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s) |
| 80 | } |
| 81 | return "", nil |
| 82 | } |
| 83 | |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 84 | func (toolchainBase) ClangInstructionSetFlags(s string) (string, error) { |
| 85 | if s != "" { |
| 86 | return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s) |
| 87 | } |
| 88 | return "", nil |
| 89 | } |
| 90 | |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame] | 91 | func (toolchainBase) ToolchainCflags() string { |
| 92 | return "" |
| 93 | } |
| 94 | |
| 95 | func (toolchainBase) ToolchainLdflags() string { |
| 96 | return "" |
| 97 | } |
| 98 | |
| 99 | func (toolchainBase) ToolchainClangCflags() 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 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 115 | type toolchain64Bit struct { |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 116 | toolchainBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | func (toolchain64Bit) Is64Bit() bool { |
| 120 | return true |
| 121 | } |
| 122 | |
| 123 | type toolchain32Bit struct { |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 124 | toolchainBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | func (toolchain32Bit) Is64Bit() bool { |
| 128 | return false |
| 129 | } |