blob: ec0f5729558256f101268d2dfed88e2e6b1edb46 [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
15package cc
16
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
62 illegalFlags = []string{
63 "-w",
64 }
65)
66
67func init() {
68 if android.BuildOs == android.Linux {
69 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
70 }
71
72 pctx.StaticVariable("commonGlobalCflags", strings.Join(commonGlobalCflags, " "))
73 pctx.StaticVariable("deviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
74 pctx.StaticVariable("hostGlobalCflags", strings.Join(hostGlobalCflags, " "))
75 pctx.StaticVariable("noOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
76
77 pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
78
79 pctx.StaticVariable("commonClangGlobalCflags",
80 strings.Join(append(clangFilterUnknownCflags(commonGlobalCflags), "${clangExtraCflags}"), " "))
81 pctx.StaticVariable("deviceClangGlobalCflags",
82 strings.Join(append(clangFilterUnknownCflags(deviceGlobalCflags), "${clangExtraTargetCflags}"), " "))
83 pctx.StaticVariable("hostClangGlobalCflags",
84 strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " "))
85 pctx.StaticVariable("noOverrideClangGlobalCflags",
86 strings.Join(append(clangFilterUnknownCflags(noOverrideGlobalCflags), "${clangExtraNoOverrideCflags}"), " "))
87
88 pctx.StaticVariable("commonClangGlobalCppflags",
89 strings.Join(append(clangFilterUnknownCflags(commonGlobalCppflags), "${clangExtraCppflags}"), " "))
90
91 // Everything in this list is a crime against abstraction and dependency tracking.
92 // Do not add anything to this list.
93 pctx.PrefixedPathsForOptionalSourceVariable("commonGlobalIncludes", "-isystem ",
94 []string{
95 "system/core/include",
96 "system/media/audio/include",
97 "hardware/libhardware/include",
98 "hardware/libhardware_legacy/include",
99 "hardware/ril/include",
100 "libnativehelper/include",
101 "frameworks/native/include",
102 "frameworks/native/opengl/include",
103 "frameworks/av/include",
104 "frameworks/base/include",
105 })
106 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
107 // with this, since there is no associated library.
108 pctx.PrefixedPathsForOptionalSourceVariable("commonNativehelperInclude", "-I",
109 []string{"libnativehelper/include/nativehelper"})
110
111 pctx.SourcePathVariable("clangDefaultBase", "prebuilts/clang/host")
112 pctx.VariableFunc("clangBase", func(config interface{}) (string, error) {
113 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
114 return override, nil
115 }
116 return "${clangDefaultBase}", nil
117 })
118 pctx.VariableFunc("clangVersion", func(config interface{}) (string, error) {
119 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
120 return override, nil
121 }
122 return "clang-3016494", nil
123 })
124 pctx.StaticVariable("clangPath", "${clangBase}/${HostPrebuiltTag}/${clangVersion}")
125 pctx.StaticVariable("clangBin", "${clangPath}/bin")
126}
127
128var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
129
130func bionicHeaders(bionicArch, kernelArch string) string {
131 return strings.Join([]string{
132 "-isystem bionic/libc/arch-" + bionicArch + "/include",
133 "-isystem bionic/libc/include",
134 "-isystem bionic/libc/kernel/uapi",
135 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
136 "-isystem bionic/libc/kernel/android/uapi",
137 }, " ")
138}