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