blob: 87657ef5383542194baa030c6ca21075a4d4552c [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// 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 (
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070018 "fmt"
19
Colin Cross635c3b02016-05-18 15:37:25 -070020 "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -080021)
22
Colin Cross635c3b02016-05-18 15:37:25 -070023type toolchainFactory func(arch android.Arch) Toolchain
Colin Cross3f40fa42015-01-30 17:27:36 -080024
Colin Crossa1ad8d12016-06-01 17:09:44 -070025var toolchainFactories = make(map[android.OsType]map[android.ArchType]toolchainFactory)
Colin Cross3f40fa42015-01-30 17:27:36 -080026
Colin Crossa1ad8d12016-06-01 17:09:44 -070027func 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 Cross3f40fa42015-01-30 17:27:36 -080032}
33
Colin Cross97ba0732015-03-23 17:50:24 -070034type Toolchain interface {
Dan Albertbe961682015-03-18 23:38:50 -070035 Name() string
36
Colin Cross3f40fa42015-01-30 17:27:36 -080037 GccRoot() string
38 GccTriple() string
Dan Willemsen34fc3b12015-12-07 12:30:44 -080039 // GccVersion should return a real value, not a ninja reference
Dan Albertbe961682015-03-18 23:38:50 -070040 GccVersion() string
Dan Willemsen34fc3b12015-12-07 12:30:44 -080041
Colin Crossc4bde762015-11-23 16:11:30 -080042 ToolchainCflags() string
43 ToolchainLdflags() string
Colin Cross3f40fa42015-01-30 17:27:36 -080044 Cflags() string
45 Cppflags() string
46 Ldflags() string
47 IncludeFlags() string
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070048 InstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080049
Dan Willemsen490fd492015-11-24 17:53:15 -080050 ClangSupported() bool
Colin Cross3f40fa42015-01-30 17:27:36 -080051 ClangTriple() string
Colin Crossc4bde762015-11-23 16:11:30 -080052 ToolchainClangCflags() string
Dan Willemsene7174922016-03-30 17:33:52 -070053 ToolchainClangLdflags() string
Dan Willemsen32968a22016-01-12 22:25:34 -080054 ClangAsflags() string
Colin Cross3f40fa42015-01-30 17:27:36 -080055 ClangCflags() string
56 ClangCppflags() string
57 ClangLdflags() string
Dan Willemsen6d11dd82015-11-03 14:27:00 -080058 ClangInstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080059
60 Is64Bit() bool
Dan Willemsen490fd492015-11-24 17:53:15 -080061
62 ShlibSuffix() string
63 ExecutableSuffix() string
Dan Willemsen282a4b02016-03-09 10:30:22 -080064
65 SystemCppCppflags() string
66 SystemCppLdflags() string
Colin Cross16b23492016-01-06 14:41:07 -080067
68 AddressSanitizerRuntimeLibrary() string
Dan Willemsen20acc5c2016-05-25 14:47:21 -070069
70 AvailableLibraries() []string
Colin Cross3f40fa42015-01-30 17:27:36 -080071}
72
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070073type toolchainBase struct {
74}
75
76func (toolchainBase) InstructionSetFlags(s string) (string, error) {
77 if s != "" {
78 return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
79 }
80 return "", nil
81}
82
Dan Willemsen6d11dd82015-11-03 14:27:00 -080083func (toolchainBase) ClangInstructionSetFlags(s string) (string, error) {
84 if s != "" {
85 return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
86 }
87 return "", nil
88}
89
Colin Crossc4bde762015-11-23 16:11:30 -080090func (toolchainBase) ToolchainCflags() string {
91 return ""
92}
93
94func (toolchainBase) ToolchainLdflags() string {
95 return ""
96}
97
98func (toolchainBase) ToolchainClangCflags() string {
99 return ""
100}
101
Dan Willemsene7174922016-03-30 17:33:52 -0700102func (toolchainBase) ToolchainClangLdflags() string {
103 return ""
104}
105
Dan Willemsen490fd492015-11-24 17:53:15 -0800106func (toolchainBase) ClangSupported() bool {
107 return true
108}
109
110func (toolchainBase) ShlibSuffix() string {
111 return ".so"
112}
113
114func (toolchainBase) ExecutableSuffix() string {
115 return ""
116}
117
Dan Willemsen32968a22016-01-12 22:25:34 -0800118func (toolchainBase) ClangAsflags() string {
119 return ""
120}
121
Dan Willemsen282a4b02016-03-09 10:30:22 -0800122func (toolchainBase) SystemCppCppflags() string {
123 return ""
124}
125
126func (toolchainBase) SystemCppLdflags() string {
127 return ""
128}
129
Colin Cross16b23492016-01-06 14:41:07 -0800130func (toolchainBase) AddressSanitizerRuntimeLibrary() string {
131 return ""
132}
133
Dan Willemsen20acc5c2016-05-25 14:47:21 -0700134func (toolchainBase) AvailableLibraries() []string {
135 return []string{}
136}
137
Colin Cross3f40fa42015-01-30 17:27:36 -0800138type toolchain64Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700139 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800140}
141
142func (toolchain64Bit) Is64Bit() bool {
143 return true
144}
145
146type toolchain32Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700147 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800148}
149
150func (toolchain32Bit) Is64Bit() bool {
151 return false
152}