blob: 2e2ee5a43ccab33db575f8fcb1b2815dd297992c [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
Colin Cross16b23492016-01-06 14:41:07 -080065 AddressSanitizerRuntimeLibrary() string
Dan Willemsen20acc5c2016-05-25 14:47:21 -070066
67 AvailableLibraries() []string
Colin Cross3f40fa42015-01-30 17:27:36 -080068}
69
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070070type toolchainBase struct {
71}
72
73func (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 Willemsen6d11dd82015-11-03 14:27:00 -080080func (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 Crossc4bde762015-11-23 16:11:30 -080087func (toolchainBase) ToolchainCflags() string {
88 return ""
89}
90
91func (toolchainBase) ToolchainLdflags() string {
92 return ""
93}
94
95func (toolchainBase) ToolchainClangCflags() string {
96 return ""
97}
98
Dan Willemsene7174922016-03-30 17:33:52 -070099func (toolchainBase) ToolchainClangLdflags() string {
100 return ""
101}
102
Dan Willemsen490fd492015-11-24 17:53:15 -0800103func (toolchainBase) ClangSupported() bool {
104 return true
105}
106
107func (toolchainBase) ShlibSuffix() string {
108 return ".so"
109}
110
111func (toolchainBase) ExecutableSuffix() string {
112 return ""
113}
114
Dan Willemsen32968a22016-01-12 22:25:34 -0800115func (toolchainBase) ClangAsflags() string {
116 return ""
117}
118
Colin Cross16b23492016-01-06 14:41:07 -0800119func (toolchainBase) AddressSanitizerRuntimeLibrary() string {
120 return ""
121}
122
Dan Willemsen20acc5c2016-05-25 14:47:21 -0700123func (toolchainBase) AvailableLibraries() []string {
124 return []string{}
125}
126
Colin Cross3f40fa42015-01-30 17:27:36 -0800127type toolchain64Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700128 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800129}
130
131func (toolchain64Bit) Is64Bit() bool {
132 return true
133}
134
135type toolchain32Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700136 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800137}
138
139func (toolchain32Bit) Is64Bit() bool {
140 return false
141}