blob: 5e4d02ff38a85573a664da08757b42b90cf4a89e [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 Albertbe961682015-03-18 23:38:50 -070049 GccVersion() string
Colin Crossc4bde762015-11-23 16:11:30 -080050 ToolchainCflags() string
51 ToolchainLdflags() string
Colin Cross3f40fa42015-01-30 17:27:36 -080052 Cflags() string
53 Cppflags() string
54 Ldflags() string
55 IncludeFlags() string
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070056 InstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080057
Dan Willemsen490fd492015-11-24 17:53:15 -080058 ClangSupported() bool
Colin Cross3f40fa42015-01-30 17:27:36 -080059 ClangTriple() string
Colin Crossc4bde762015-11-23 16:11:30 -080060 ToolchainClangCflags() string
Colin Cross3f40fa42015-01-30 17:27:36 -080061 ClangCflags() string
62 ClangCppflags() string
63 ClangLdflags() string
Dan Willemsen6d11dd82015-11-03 14:27:00 -080064 ClangInstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080065
66 Is64Bit() bool
Dan Willemsen490fd492015-11-24 17:53:15 -080067
68 ShlibSuffix() string
69 ExecutableSuffix() string
Colin Cross3f40fa42015-01-30 17:27:36 -080070}
71
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070072type toolchainBase struct {
73}
74
75func (toolchainBase) InstructionSetFlags(s string) (string, error) {
76 if s != "" {
77 return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
78 }
79 return "", nil
80}
81
Dan Willemsen6d11dd82015-11-03 14:27:00 -080082func (toolchainBase) ClangInstructionSetFlags(s string) (string, error) {
83 if s != "" {
84 return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
85 }
86 return "", nil
87}
88
Colin Crossc4bde762015-11-23 16:11:30 -080089func (toolchainBase) ToolchainCflags() string {
90 return ""
91}
92
93func (toolchainBase) ToolchainLdflags() string {
94 return ""
95}
96
97func (toolchainBase) ToolchainClangCflags() string {
98 return ""
99}
100
Dan Willemsen490fd492015-11-24 17:53:15 -0800101func (toolchainBase) ClangSupported() bool {
102 return true
103}
104
105func (toolchainBase) ShlibSuffix() string {
106 return ".so"
107}
108
109func (toolchainBase) ExecutableSuffix() string {
110 return ""
111}
112
Colin Cross3f40fa42015-01-30 17:27:36 -0800113type toolchain64Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700114 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800115}
116
117func (toolchain64Bit) Is64Bit() bool {
118 return true
119}
120
121type toolchain32Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700122 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800123}
124
125func (toolchain32Bit) Is64Bit() bool {
126 return false
127}