blob: 00a4f712a6989bd78908ded9c4a8b8682de207f1 [file] [log] [blame]
Dan Willemsen4b7d5de2016-01-12 23:20:28 -08001// Copyright 2016 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 (
18 "fmt"
19 "path/filepath"
20 "strings"
21
22 "android/soong/common"
23)
24
25func init() {
26 common.RegisterMakeVarsProvider(pctx, makeVarsProvider)
27}
28
29func makeVarsProvider(ctx common.MakeVarsContext) {
30 ctx.Strict("LLVM_PREBUILTS_VERSION", "${clangVersion}")
31 ctx.Strict("LLVM_PREBUILTS_BASE", "${clangBase}")
32
33 hostType := common.CurrentHostType()
34 arches := ctx.Config().HostArches[hostType]
35 makeVarsToolchain(ctx, "", common.Host, hostType, arches[0])
36 if len(arches) > 1 {
37 makeVarsToolchain(ctx, "2ND_", common.Host, hostType, arches[1])
38 }
39
40 if winArches, ok := ctx.Config().HostArches[common.Windows]; ok {
41 makeVarsToolchain(ctx, "", common.Host, common.Windows, winArches[0])
42 if len(winArches) > 1 {
43 makeVarsToolchain(ctx, "2ND_", common.Host, common.Windows, winArches[1])
44 }
45 }
46
47 arches = ctx.Config().DeviceArches
48 makeVarsToolchain(ctx, "", common.Device, common.NoHostType, arches[0])
49 if len(arches) > 1 {
50 makeVarsToolchain(ctx, "2ND_", common.Device, common.NoHostType, arches[1])
51 }
52}
53
54func makeVarsToolchain(ctx common.MakeVarsContext, secondPrefix string,
55 hod common.HostOrDevice, ht common.HostType, arch common.Arch) {
56 var typePrefix string
57 if hod.Host() {
58 if ht == common.Windows {
59 typePrefix = "HOST_CROSS_"
60 } else {
61 typePrefix = "HOST_"
62 }
63 } else {
64 typePrefix = "TARGET_"
65 }
66 makePrefix := secondPrefix + typePrefix
67
68 toolchain := toolchainFactories[hod][ht][arch.ArchType](arch)
69
70 globalCflags := fmt.Sprintf("${commonGlobalCflags} ${%sGlobalCflags}", hod)
71
72 ctx.CheckSorted(makePrefix+"GLOBAL_CFLAGS", strings.Join([]string{
73 toolchain.ToolchainCflags(),
74 globalCflags,
75 toolchain.Cflags(),
76 }, " "))
77 ctx.CheckSorted(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
78 toolchain.ToolchainLdflags(),
79 toolchain.Ldflags(),
80 }, " "))
81
82 if toolchain.ClangSupported() {
83 clangPrefix := secondPrefix + "CLANG_" + typePrefix
84 clangExtras := "-target " + toolchain.ClangTriple() + " -B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
85
86 globalClangCflags := fmt.Sprintf("${commonClangGlobalCflags} ${clangExtraCflags} ${%sClangGlobalCflags}", hod)
87
88 ctx.CheckSorted(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
89 toolchain.ToolchainClangCflags(),
90 globalClangCflags,
91 toolchain.ClangCflags(),
92 clangExtras,
93 }, " "))
94 ctx.CheckSorted(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
95 toolchain.ToolchainClangLdflags(),
96 toolchain.ClangLdflags(),
97 clangExtras,
98 }, " "))
99 }
100
101 ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc"))
102 ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++"))
103
104 if ht == common.Darwin {
105 ctx.Strict(makePrefix+"AR", "${macArPath}")
106 } else {
107 ctx.Strict(makePrefix+"AR", gccCmd(toolchain, "ar"))
108 ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf"))
109 ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm"))
110 }
111}