blob: f1989a27b1f2c960e0def6de83d95eeb77e4ac98 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// 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
Colin Crossb98c8b02016-07-29 13:44:28 -070015package config
Colin Cross4d9c2d12016-07-29 12:48:20 -070016
17import (
18 "strings"
19
20 "android/soong/android"
21)
22
23// Flags used by lots of devices. Putting them in package static variables will save bytes in
24// build.ninja so they aren't repeated for every file
25var (
26 commonGlobalCflags = []string{
27 "-DANDROID",
28 "-fmessage-length=0",
29 "-W",
30 "-Wall",
31 "-Wno-unused",
32 "-Winit-self",
33 "-Wpointer-arith",
34
35 // COMMON_RELEASE_CFLAGS
36 "-DNDEBUG",
37 "-UDEBUG",
38 }
39
40 deviceGlobalCflags = []string{
41 "-fdiagnostics-color",
42
43 // TARGET_ERROR_FLAGS
44 "-Werror=return-type",
45 "-Werror=non-virtual-dtor",
46 "-Werror=address",
47 "-Werror=sequence-point",
48 "-Werror=date-time",
49 }
50
51 hostGlobalCflags = []string{}
52
53 commonGlobalCppflags = []string{
54 "-Wsign-promo",
55 }
56
57 noOverrideGlobalCflags = []string{
58 "-Werror=int-to-pointer-cast",
59 "-Werror=pointer-to-int-cast",
60 }
61
Colin Crossb98c8b02016-07-29 13:44:28 -070062 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -070063 "-w",
64 }
65)
66
Colin Crossb98c8b02016-07-29 13:44:28 -070067var pctx = android.NewPackageContext("android/soong/cc/config")
68
Colin Cross4d9c2d12016-07-29 12:48:20 -070069func init() {
70 if android.BuildOs == android.Linux {
71 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
72 }
73
Colin Crossb98c8b02016-07-29 13:44:28 -070074 pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
75 pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
76 pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
77 pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070078
Colin Crossb98c8b02016-07-29 13:44:28 -070079 pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070080
Colin Crossb98c8b02016-07-29 13:44:28 -070081 pctx.StaticVariable("CommonClangGlobalCflags",
82 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
83 pctx.StaticVariable("DeviceClangGlobalCflags",
84 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
85 pctx.StaticVariable("HostClangGlobalCflags",
86 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
87 pctx.StaticVariable("NoOverrideClangGlobalCflags",
88 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070089
Colin Crossb98c8b02016-07-29 13:44:28 -070090 pctx.StaticVariable("CommonClangGlobalCppflags",
91 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070092
93 // Everything in this list is a crime against abstraction and dependency tracking.
94 // Do not add anything to this list.
Colin Crossb98c8b02016-07-29 13:44:28 -070095 pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalIncludes", "-isystem ",
Colin Cross4d9c2d12016-07-29 12:48:20 -070096 []string{
97 "system/core/include",
98 "system/media/audio/include",
99 "hardware/libhardware/include",
100 "hardware/libhardware_legacy/include",
101 "hardware/ril/include",
102 "libnativehelper/include",
103 "frameworks/native/include",
104 "frameworks/native/opengl/include",
105 "frameworks/av/include",
106 "frameworks/base/include",
107 })
108 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
109 // with this, since there is no associated library.
Colin Crossb98c8b02016-07-29 13:44:28 -0700110 pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700111 []string{"libnativehelper/include/nativehelper"})
112
Colin Crossb98c8b02016-07-29 13:44:28 -0700113 pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
114 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700115 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
116 return override, nil
117 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700118 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700119 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700120 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700121 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
122 return override, nil
123 }
Pirama Arumuga Nainar15690c02016-08-24 09:44:55 -0700124 return "clang-3217047", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700125 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700126 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
127 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
128
129 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/3.8/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700130
131 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
132 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
133 return override + " ", nil
134 }
135 return "", nil
136 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700137}
138
139var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
140
141func bionicHeaders(bionicArch, kernelArch string) string {
142 return strings.Join([]string{
143 "-isystem bionic/libc/arch-" + bionicArch + "/include",
144 "-isystem bionic/libc/include",
145 "-isystem bionic/libc/kernel/uapi",
146 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
147 "-isystem bionic/libc/kernel/android/uapi",
148 }, " ")
149}