blob: 247036e0ed16e65d8dcf2a164425716189d33594 [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}")
Dan Willemsen73d21f22016-05-16 14:22:56 -070032 ctx.Strict("LLVM_PREBUILTS_PATH", "${clangBin}")
33 ctx.Strict("CLANG", "${clangBin}/clang")
34 ctx.Strict("CLANG_CXX", "${clangBin}/clang++")
35 ctx.Strict("LLVM_AS", "${clangBin}/llvm-as")
36 ctx.Strict("LLVM_LINK", "${clangBin}/llvm-link")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080037
38 hostType := common.CurrentHostType()
39 arches := ctx.Config().HostArches[hostType]
40 makeVarsToolchain(ctx, "", common.Host, hostType, arches[0])
41 if len(arches) > 1 {
42 makeVarsToolchain(ctx, "2ND_", common.Host, hostType, arches[1])
43 }
44
45 if winArches, ok := ctx.Config().HostArches[common.Windows]; ok {
46 makeVarsToolchain(ctx, "", common.Host, common.Windows, winArches[0])
47 if len(winArches) > 1 {
48 makeVarsToolchain(ctx, "2ND_", common.Host, common.Windows, winArches[1])
49 }
50 }
51
52 arches = ctx.Config().DeviceArches
53 makeVarsToolchain(ctx, "", common.Device, common.NoHostType, arches[0])
54 if len(arches) > 1 {
55 makeVarsToolchain(ctx, "2ND_", common.Device, common.NoHostType, arches[1])
56 }
57}
58
59func makeVarsToolchain(ctx common.MakeVarsContext, secondPrefix string,
60 hod common.HostOrDevice, ht common.HostType, arch common.Arch) {
61 var typePrefix string
62 if hod.Host() {
63 if ht == common.Windows {
64 typePrefix = "HOST_CROSS_"
65 } else {
66 typePrefix = "HOST_"
67 }
68 } else {
69 typePrefix = "TARGET_"
70 }
71 makePrefix := secondPrefix + typePrefix
72
73 toolchain := toolchainFactories[hod][ht][arch.ArchType](arch)
74
75 globalCflags := fmt.Sprintf("${commonGlobalCflags} ${%sGlobalCflags}", hod)
76
77 ctx.CheckSorted(makePrefix+"GLOBAL_CFLAGS", strings.Join([]string{
78 toolchain.ToolchainCflags(),
79 globalCflags,
80 toolchain.Cflags(),
81 }, " "))
82 ctx.CheckSorted(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
83 toolchain.ToolchainLdflags(),
84 toolchain.Ldflags(),
85 }, " "))
86
87 if toolchain.ClangSupported() {
88 clangPrefix := secondPrefix + "CLANG_" + typePrefix
89 clangExtras := "-target " + toolchain.ClangTriple() + " -B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
90
91 globalClangCflags := fmt.Sprintf("${commonClangGlobalCflags} ${clangExtraCflags} ${%sClangGlobalCflags}", hod)
92
93 ctx.CheckSorted(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
94 toolchain.ToolchainClangCflags(),
95 globalClangCflags,
96 toolchain.ClangCflags(),
97 clangExtras,
98 }, " "))
99 ctx.CheckSorted(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
100 toolchain.ToolchainClangLdflags(),
101 toolchain.ClangLdflags(),
102 clangExtras,
103 }, " "))
104 }
105
106 ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc"))
107 ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++"))
108
109 if ht == common.Darwin {
110 ctx.Strict(makePrefix+"AR", "${macArPath}")
111 } else {
112 ctx.Strict(makePrefix+"AR", gccCmd(toolchain, "ar"))
113 ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf"))
114 ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm"))
115 }
Dan Willemsen73d21f22016-05-16 14:22:56 -0700116
117 if ht == common.Windows {
118 ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump"))
119 }
120
121 if hod.Device() {
122 ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy"))
123 ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld"))
124 ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip"))
125 }
126
127 ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, ""))
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800128}