blob: 1f51384a5b4eece8f4d7503e1ebed9445de3a3f6 [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 Cross3f40fa42015-01-30 17:27:36 -080020 "android/soong/common"
21)
22
Colin Crossc5c24ad2015-11-20 15:35:00 -080023type toolchainFactory func(arch common.Arch) Toolchain
Colin Cross3f40fa42015-01-30 17:27:36 -080024
Dan Willemsen490fd492015-11-24 17:53:15 -080025var 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 Cross3f40fa42015-01-30 17:27:36 -080034}
35
Dan Willemsen490fd492015-11-24 17:53:15 -080036func registerDeviceToolchainFactory(arch common.ArchType, factory toolchainFactory) {
37 toolchainFactories[common.Device][common.NoHostType][arch] = factory
38}
Colin Cross3f40fa42015-01-30 17:27:36 -080039
Dan Willemsen490fd492015-11-24 17:53:15 -080040func registerHostToolchainFactory(ht common.HostType, arch common.ArchType, factory toolchainFactory) {
41 toolchainFactories[common.Host][ht][arch] = factory
Colin Cross3f40fa42015-01-30 17:27:36 -080042}
43
Colin Cross97ba0732015-03-23 17:50:24 -070044type Toolchain interface {
Dan Albertbe961682015-03-18 23:38:50 -070045 Name() string
46
Colin Cross3f40fa42015-01-30 17:27:36 -080047 GccRoot() string
48 GccTriple() string
Dan Willemsen34fc3b12015-12-07 12:30:44 -080049 // GccVersion should return a real value, not a ninja reference
Dan Albertbe961682015-03-18 23:38:50 -070050 GccVersion() string
Dan Willemsen34fc3b12015-12-07 12:30:44 -080051
Colin Crossc4bde762015-11-23 16:11:30 -080052 ToolchainCflags() string
53 ToolchainLdflags() string
Colin Cross3f40fa42015-01-30 17:27:36 -080054 Cflags() string
55 Cppflags() string
56 Ldflags() string
57 IncludeFlags() string
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070058 InstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080059
Dan Willemsen490fd492015-11-24 17:53:15 -080060 ClangSupported() bool
Colin Cross3f40fa42015-01-30 17:27:36 -080061 ClangTriple() string
Colin Crossc4bde762015-11-23 16:11:30 -080062 ToolchainClangCflags() string
Dan Willemsen32968a22016-01-12 22:25:34 -080063 ClangAsflags() string
Colin Cross3f40fa42015-01-30 17:27:36 -080064 ClangCflags() string
65 ClangCppflags() string
66 ClangLdflags() string
Dan Willemsen6d11dd82015-11-03 14:27:00 -080067 ClangInstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080068
69 Is64Bit() bool
Dan Willemsen490fd492015-11-24 17:53:15 -080070
71 ShlibSuffix() string
72 ExecutableSuffix() string
Dan Willemsen282a4b02016-03-09 10:30:22 -080073
74 SystemCppCppflags() string
75 SystemCppLdflags() string
Colin Cross3f40fa42015-01-30 17:27:36 -080076}
77
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070078type 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
Dan Willemsen6d11dd82015-11-03 14:27:00 -080088func (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
Colin Crossc4bde762015-11-23 16:11:30 -080095func (toolchainBase) ToolchainCflags() string {
96 return ""
97}
98
99func (toolchainBase) ToolchainLdflags() string {
100 return ""
101}
102
103func (toolchainBase) ToolchainClangCflags() string {
104 return ""
105}
106
Dan Willemsen490fd492015-11-24 17:53:15 -0800107func (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
Dan Willemsen32968a22016-01-12 22:25:34 -0800119func (toolchainBase) ClangAsflags() string {
120 return ""
121}
122
Dan Willemsen282a4b02016-03-09 10:30:22 -0800123func (toolchainBase) SystemCppCppflags() string {
124 return ""
125}
126
127func (toolchainBase) SystemCppLdflags() string {
128 return ""
129}
130
Colin Cross3f40fa42015-01-30 17:27:36 -0800131type toolchain64Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700132 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800133}
134
135func (toolchain64Bit) Is64Bit() bool {
136 return true
137}
138
139type toolchain32Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700140 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800141}
142
143func (toolchain32Bit) Is64Bit() bool {
144 return false
145}