blob: ebb19f1a1f96b74eff0db53dd33f429968878bc2 [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
Dan Willemsenb436fde2016-05-16 18:04:45 -070077 ctx.StrictSorted(makePrefix+"GLOBAL_CFLAGS", strings.Join([]string{
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080078 toolchain.ToolchainCflags(),
79 globalCflags,
80 toolchain.Cflags(),
81 }, " "))
Dan Willemsenb436fde2016-05-16 18:04:45 -070082 ctx.StrictSorted(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080083 toolchain.ToolchainLdflags(),
84 toolchain.Ldflags(),
85 }, " "))
86
87 if toolchain.ClangSupported() {
88 clangPrefix := secondPrefix + "CLANG_" + typePrefix
Dan Willemsen3772da12016-05-16 18:01:46 -070089 clangExtras := "-target " + toolchain.ClangTriple()
90 if ht != common.Darwin {
91 clangExtras += " -B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
92 }
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080093
94 globalClangCflags := fmt.Sprintf("${commonClangGlobalCflags} ${clangExtraCflags} ${%sClangGlobalCflags}", hod)
95
Dan Willemsenb436fde2016-05-16 18:04:45 -070096 ctx.StrictSorted(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080097 toolchain.ToolchainClangCflags(),
98 globalClangCflags,
99 toolchain.ClangCflags(),
100 clangExtras,
101 }, " "))
Dan Willemsenb436fde2016-05-16 18:04:45 -0700102 ctx.StrictSorted(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800103 toolchain.ToolchainClangLdflags(),
104 toolchain.ClangLdflags(),
105 clangExtras,
106 }, " "))
107 }
108
109 ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc"))
110 ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++"))
111
112 if ht == common.Darwin {
113 ctx.Strict(makePrefix+"AR", "${macArPath}")
114 } else {
115 ctx.Strict(makePrefix+"AR", gccCmd(toolchain, "ar"))
116 ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf"))
117 ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm"))
118 }
Dan Willemsen73d21f22016-05-16 14:22:56 -0700119
120 if ht == common.Windows {
121 ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump"))
122 }
123
124 if hod.Device() {
125 ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy"))
126 ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld"))
127 ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip"))
128 }
129
130 ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, ""))
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800131}