blob: 89485f8e03ed07d15a6e1cac9e0414eda072ab02 [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"
Colin Crossf59b69c2016-07-21 11:14:12 -070019 "strings"
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070020
Colin Cross635c3b02016-05-18 15:37:25 -070021 "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -080022)
23
Colin Cross635c3b02016-05-18 15:37:25 -070024type toolchainFactory func(arch android.Arch) Toolchain
Colin Cross3f40fa42015-01-30 17:27:36 -080025
Colin Crossa1ad8d12016-06-01 17:09:44 -070026var toolchainFactories = make(map[android.OsType]map[android.ArchType]toolchainFactory)
Colin Cross3f40fa42015-01-30 17:27:36 -080027
Colin Crossa1ad8d12016-06-01 17:09:44 -070028func registerToolchainFactory(os android.OsType, arch android.ArchType, factory toolchainFactory) {
29 if toolchainFactories[os] == nil {
30 toolchainFactories[os] = make(map[android.ArchType]toolchainFactory)
31 }
32 toolchainFactories[os][arch] = factory
Colin Cross3f40fa42015-01-30 17:27:36 -080033}
34
Colin Cross97ba0732015-03-23 17:50:24 -070035type Toolchain interface {
Dan Albertbe961682015-03-18 23:38:50 -070036 Name() string
37
Colin Cross3f40fa42015-01-30 17:27:36 -080038 GccRoot() string
39 GccTriple() string
Dan Willemsen34fc3b12015-12-07 12:30:44 -080040 // GccVersion should return a real value, not a ninja reference
Dan Albertbe961682015-03-18 23:38:50 -070041 GccVersion() string
Dan Willemsen34fc3b12015-12-07 12:30:44 -080042
Colin Crossc4bde762015-11-23 16:11:30 -080043 ToolchainCflags() string
44 ToolchainLdflags() string
Colin Cross3f40fa42015-01-30 17:27:36 -080045 Cflags() string
46 Cppflags() string
47 Ldflags() string
48 IncludeFlags() string
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070049 InstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080050
Dan Willemsen490fd492015-11-24 17:53:15 -080051 ClangSupported() bool
Colin Cross3f40fa42015-01-30 17:27:36 -080052 ClangTriple() string
Colin Crossc4bde762015-11-23 16:11:30 -080053 ToolchainClangCflags() string
Dan Willemsene7174922016-03-30 17:33:52 -070054 ToolchainClangLdflags() string
Dan Willemsen32968a22016-01-12 22:25:34 -080055 ClangAsflags() string
Colin Cross3f40fa42015-01-30 17:27:36 -080056 ClangCflags() string
57 ClangCppflags() string
58 ClangLdflags() string
Dan Willemsen6d11dd82015-11-03 14:27:00 -080059 ClangInstructionSetFlags(string) (string, error)
Colin Cross3f40fa42015-01-30 17:27:36 -080060
61 Is64Bit() bool
Dan Willemsen490fd492015-11-24 17:53:15 -080062
63 ShlibSuffix() string
64 ExecutableSuffix() string
Dan Willemsen282a4b02016-03-09 10:30:22 -080065
Colin Cross16b23492016-01-06 14:41:07 -080066 AddressSanitizerRuntimeLibrary() string
Dan Willemsen20acc5c2016-05-25 14:47:21 -070067
68 AvailableLibraries() []string
Colin Cross3f40fa42015-01-30 17:27:36 -080069}
70
Tim Kilbourn1a9bf262015-03-18 12:28:32 -070071type toolchainBase struct {
72}
73
74func (toolchainBase) InstructionSetFlags(s string) (string, error) {
75 if s != "" {
76 return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
77 }
78 return "", nil
79}
80
Dan Willemsen6d11dd82015-11-03 14:27:00 -080081func (toolchainBase) ClangInstructionSetFlags(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
Colin Crossc4bde762015-11-23 16:11:30 -080088func (toolchainBase) ToolchainCflags() string {
89 return ""
90}
91
92func (toolchainBase) ToolchainLdflags() string {
93 return ""
94}
95
96func (toolchainBase) ToolchainClangCflags() string {
97 return ""
98}
99
Dan Willemsene7174922016-03-30 17:33:52 -0700100func (toolchainBase) ToolchainClangLdflags() string {
101 return ""
102}
103
Dan Willemsen490fd492015-11-24 17:53:15 -0800104func (toolchainBase) ClangSupported() bool {
105 return true
106}
107
108func (toolchainBase) ShlibSuffix() string {
109 return ".so"
110}
111
112func (toolchainBase) ExecutableSuffix() string {
113 return ""
114}
115
Dan Willemsen32968a22016-01-12 22:25:34 -0800116func (toolchainBase) ClangAsflags() string {
117 return ""
118}
119
Colin Cross16b23492016-01-06 14:41:07 -0800120func (toolchainBase) AddressSanitizerRuntimeLibrary() string {
121 return ""
122}
123
Dan Willemsen20acc5c2016-05-25 14:47:21 -0700124func (toolchainBase) AvailableLibraries() []string {
125 return []string{}
126}
127
Colin Cross3f40fa42015-01-30 17:27:36 -0800128type toolchain64Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700129 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800130}
131
132func (toolchain64Bit) Is64Bit() bool {
133 return true
134}
135
136type toolchain32Bit struct {
Tim Kilbourn1a9bf262015-03-18 12:28:32 -0700137 toolchainBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800138}
139
140func (toolchain32Bit) Is64Bit() bool {
141 return false
142}
Colin Crossf59b69c2016-07-21 11:14:12 -0700143
144func bionicHeaders(bionicArch, kernelArch string) string {
145 return strings.Join([]string{
146 "-isystem bionic/libc/arch-" + bionicArch + "/include",
147 "-isystem bionic/libc/include",
148 "-isystem bionic/libc/kernel/uapi",
149 "-isystem bionic/libc/kernel/android/uapi",
150 "-isystem bionic/libc/kernel/common",
151 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
152 }, " ")
153}