Separate cc.go
Split cc.go into files per module type, plus files for the compiler,
linker, and installer stages.
Change-Id: Id44c03f42fcd180950ccd008d4de0c144ea3597b
diff --git a/cc/global.go b/cc/global.go
new file mode 100644
index 0000000..ec0f572
--- /dev/null
+++ b/cc/global.go
@@ -0,0 +1,138 @@
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+import (
+ "strings"
+
+ "android/soong/android"
+)
+
+// Flags used by lots of devices. Putting them in package static variables will save bytes in
+// build.ninja so they aren't repeated for every file
+var (
+ commonGlobalCflags = []string{
+ "-DANDROID",
+ "-fmessage-length=0",
+ "-W",
+ "-Wall",
+ "-Wno-unused",
+ "-Winit-self",
+ "-Wpointer-arith",
+
+ // COMMON_RELEASE_CFLAGS
+ "-DNDEBUG",
+ "-UDEBUG",
+ }
+
+ deviceGlobalCflags = []string{
+ "-fdiagnostics-color",
+
+ // TARGET_ERROR_FLAGS
+ "-Werror=return-type",
+ "-Werror=non-virtual-dtor",
+ "-Werror=address",
+ "-Werror=sequence-point",
+ "-Werror=date-time",
+ }
+
+ hostGlobalCflags = []string{}
+
+ commonGlobalCppflags = []string{
+ "-Wsign-promo",
+ }
+
+ noOverrideGlobalCflags = []string{
+ "-Werror=int-to-pointer-cast",
+ "-Werror=pointer-to-int-cast",
+ }
+
+ illegalFlags = []string{
+ "-w",
+ }
+)
+
+func init() {
+ if android.BuildOs == android.Linux {
+ commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
+ }
+
+ pctx.StaticVariable("commonGlobalCflags", strings.Join(commonGlobalCflags, " "))
+ pctx.StaticVariable("deviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
+ pctx.StaticVariable("hostGlobalCflags", strings.Join(hostGlobalCflags, " "))
+ pctx.StaticVariable("noOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
+
+ pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
+
+ pctx.StaticVariable("commonClangGlobalCflags",
+ strings.Join(append(clangFilterUnknownCflags(commonGlobalCflags), "${clangExtraCflags}"), " "))
+ pctx.StaticVariable("deviceClangGlobalCflags",
+ strings.Join(append(clangFilterUnknownCflags(deviceGlobalCflags), "${clangExtraTargetCflags}"), " "))
+ pctx.StaticVariable("hostClangGlobalCflags",
+ strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " "))
+ pctx.StaticVariable("noOverrideClangGlobalCflags",
+ strings.Join(append(clangFilterUnknownCflags(noOverrideGlobalCflags), "${clangExtraNoOverrideCflags}"), " "))
+
+ pctx.StaticVariable("commonClangGlobalCppflags",
+ strings.Join(append(clangFilterUnknownCflags(commonGlobalCppflags), "${clangExtraCppflags}"), " "))
+
+ // Everything in this list is a crime against abstraction and dependency tracking.
+ // Do not add anything to this list.
+ pctx.PrefixedPathsForOptionalSourceVariable("commonGlobalIncludes", "-isystem ",
+ []string{
+ "system/core/include",
+ "system/media/audio/include",
+ "hardware/libhardware/include",
+ "hardware/libhardware_legacy/include",
+ "hardware/ril/include",
+ "libnativehelper/include",
+ "frameworks/native/include",
+ "frameworks/native/opengl/include",
+ "frameworks/av/include",
+ "frameworks/base/include",
+ })
+ // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
+ // with this, since there is no associated library.
+ pctx.PrefixedPathsForOptionalSourceVariable("commonNativehelperInclude", "-I",
+ []string{"libnativehelper/include/nativehelper"})
+
+ pctx.SourcePathVariable("clangDefaultBase", "prebuilts/clang/host")
+ pctx.VariableFunc("clangBase", func(config interface{}) (string, error) {
+ if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
+ return override, nil
+ }
+ return "${clangDefaultBase}", nil
+ })
+ pctx.VariableFunc("clangVersion", func(config interface{}) (string, error) {
+ if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
+ return override, nil
+ }
+ return "clang-3016494", nil
+ })
+ pctx.StaticVariable("clangPath", "${clangBase}/${HostPrebuiltTag}/${clangVersion}")
+ pctx.StaticVariable("clangBin", "${clangPath}/bin")
+}
+
+var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
+
+func bionicHeaders(bionicArch, kernelArch string) string {
+ return strings.Join([]string{
+ "-isystem bionic/libc/arch-" + bionicArch + "/include",
+ "-isystem bionic/libc/include",
+ "-isystem bionic/libc/kernel/uapi",
+ "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
+ "-isystem bionic/libc/kernel/android/uapi",
+ }, " ")
+}