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 15package cc 16 17import ( 18 "fmt" 19 20 "android/soong/common" 21) 22 23type toolchainFactory func(arch common.Arch) Toolchain 24 25var 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 }, 34} 35 36func registerDeviceToolchainFactory(arch common.ArchType, factory toolchainFactory) { 37 toolchainFactories[common.Device][common.NoHostType][arch] = factory 38} 39 40func registerHostToolchainFactory(ht common.HostType, arch common.ArchType, factory toolchainFactory) { 41 toolchainFactories[common.Host][ht][arch] = factory 42} 43 44type Toolchain interface { 45 Name() string 46 47 GccRoot() string 48 GccTriple() string 49 // GccVersion should return a real value, not a ninja reference 50 GccVersion() string 51 52 ToolchainCflags() string 53 ToolchainLdflags() string 54 Cflags() string 55 Cppflags() string 56 Ldflags() string 57 IncludeFlags() string 58 InstructionSetFlags(string) (string, error) 59 60 ClangSupported() bool 61 ClangTriple() string 62 ToolchainClangCflags() string 63 ClangAsflags() string 64 ClangCflags() string 65 ClangCppflags() string 66 ClangLdflags() string 67 ClangInstructionSetFlags(string) (string, error) 68 69 Is64Bit() bool 70 71 ShlibSuffix() string 72 ExecutableSuffix() string 73 74 SystemCppCppflags() string 75 SystemCppLdflags() string 76} 77 78type toolchainBase struct { 79} 80 81func (toolchainBase) InstructionSetFlags(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 88func (toolchainBase) ClangInstructionSetFlags(s string) (string, error) { 89 if s != "" { 90 return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s) 91 } 92 return "", nil 93} 94 95func (toolchainBase) ToolchainCflags() string { 96 return "" 97} 98 99func (toolchainBase) ToolchainLdflags() string { 100 return "" 101} 102 103func (toolchainBase) ToolchainClangCflags() string { 104 return "" 105} 106 107func (toolchainBase) ClangSupported() bool { 108 return true 109} 110 111func (toolchainBase) ShlibSuffix() string { 112 return ".so" 113} 114 115func (toolchainBase) ExecutableSuffix() string { 116 return "" 117} 118 119func (toolchainBase) ClangAsflags() string { 120 return "" 121} 122 123func (toolchainBase) SystemCppCppflags() string { 124 return "" 125} 126 127func (toolchainBase) SystemCppLdflags() string { 128 return "" 129} 130 131type toolchain64Bit struct { 132 toolchainBase 133} 134 135func (toolchain64Bit) Is64Bit() bool { 136 return true 137} 138 139type toolchain32Bit struct { 140 toolchainBase 141} 142 143func (toolchain32Bit) Is64Bit() bool { 144 return false 145} 146