blob: 9b776629d9ef7859f5a0329f9b68f066bbeb3a5c [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
Elliott Hughes5a0401a2016-10-07 13:12:58 -070040 commonGlobalConlyflags = []string{
41 "-std=gnu99",
42 }
43
Colin Cross4d9c2d12016-07-29 12:48:20 -070044 deviceGlobalCflags = []string{
45 "-fdiagnostics-color",
46
47 // TARGET_ERROR_FLAGS
48 "-Werror=return-type",
49 "-Werror=non-virtual-dtor",
50 "-Werror=address",
51 "-Werror=sequence-point",
52 "-Werror=date-time",
53 }
54
55 hostGlobalCflags = []string{}
56
57 commonGlobalCppflags = []string{
58 "-Wsign-promo",
59 }
60
61 noOverrideGlobalCflags = []string{
62 "-Werror=int-to-pointer-cast",
63 "-Werror=pointer-to-int-cast",
64 }
65
Colin Crossb98c8b02016-07-29 13:44:28 -070066 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -070067 "-w",
68 }
69)
70
Colin Crossb98c8b02016-07-29 13:44:28 -070071var pctx = android.NewPackageContext("android/soong/cc/config")
72
Colin Cross4d9c2d12016-07-29 12:48:20 -070073func init() {
74 if android.BuildOs == android.Linux {
75 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
76 }
77
Colin Crossb98c8b02016-07-29 13:44:28 -070078 pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
Elliott Hughes5a0401a2016-10-07 13:12:58 -070079 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -070080 pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
81 pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
82 pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070083
Colin Crossb98c8b02016-07-29 13:44:28 -070084 pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070085
Colin Crossb98c8b02016-07-29 13:44:28 -070086 pctx.StaticVariable("CommonClangGlobalCflags",
87 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
88 pctx.StaticVariable("DeviceClangGlobalCflags",
89 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
90 pctx.StaticVariable("HostClangGlobalCflags",
91 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
92 pctx.StaticVariable("NoOverrideClangGlobalCflags",
93 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070094
Colin Crossb98c8b02016-07-29 13:44:28 -070095 pctx.StaticVariable("CommonClangGlobalCppflags",
96 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070097
Colin Cross1cfd89a2016-09-15 09:30:46 -070098 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -070099 // Do not add anything to this list.
Colin Cross1cfd89a2016-09-15 09:30:46 -0700100 pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700101 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000102 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700103 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700104 "hardware/libhardware/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700105 "frameworks/native/include",
Colin Cross81b4ca62016-09-23 19:20:54 +0000106 })
107 pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalSystemIncludes", "-isystem ",
108 []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700109 "hardware/libhardware_legacy/include",
110 "hardware/ril/include",
111 "libnativehelper/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700112 "frameworks/native/opengl/include",
113 "frameworks/av/include",
114 "frameworks/base/include",
115 })
116 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
117 // with this, since there is no associated library.
Colin Crossb98c8b02016-07-29 13:44:28 -0700118 pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700119 []string{"libnativehelper/include/nativehelper"})
120
Colin Crossb98c8b02016-07-29 13:44:28 -0700121 pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
122 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700123 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
124 return override, nil
125 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700126 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700127 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700128 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700129 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
130 return override, nil
131 }
Stephen Hinesfdab9962016-09-28 08:52:48 -0700132 return "clang-3289846", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700133 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700134 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
135 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
136
137 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/3.8/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700138
139 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
140 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
141 return override + " ", nil
142 }
143 return "", nil
144 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700145}
146
147var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
148
149func bionicHeaders(bionicArch, kernelArch string) string {
150 return strings.Join([]string{
151 "-isystem bionic/libc/arch-" + bionicArch + "/include",
152 "-isystem bionic/libc/include",
153 "-isystem bionic/libc/kernel/uapi",
154 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
155 "-isystem bionic/libc/kernel/android/uapi",
156 }, " ")
157}