Home | History | Annotate | Download | only in config
      1 // 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 
     15 package config
     16 
     17 import (
     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
     25 var (
     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 	commonGlobalConlyflags = []string{}
     41 
     42 	deviceGlobalCflags = []string{
     43 		"-fdiagnostics-color",
     44 
     45 		// TARGET_ERROR_FLAGS
     46 		"-Werror=return-type",
     47 		"-Werror=non-virtual-dtor",
     48 		"-Werror=address",
     49 		"-Werror=sequence-point",
     50 		"-Werror=date-time",
     51 	}
     52 
     53 	hostGlobalCflags = []string{}
     54 
     55 	commonGlobalCppflags = []string{
     56 		"-Wsign-promo",
     57 	}
     58 
     59 	noOverrideGlobalCflags = []string{
     60 		"-Werror=int-to-pointer-cast",
     61 		"-Werror=pointer-to-int-cast",
     62 	}
     63 
     64 	IllegalFlags = []string{
     65 		"-w",
     66 	}
     67 
     68 	CStdVersion               = "gnu99"
     69 	CppStdVersion             = "gnu++14"
     70 	GccCppStdVersion          = "gnu++11"
     71 	ExperimentalCStdVersion   = "gnu11"
     72 	ExperimentalCppStdVersion = "gnu++1z"
     73 )
     74 
     75 var pctx = android.NewPackageContext("android/soong/cc/config")
     76 
     77 func init() {
     78 	if android.BuildOs == android.Linux {
     79 		commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
     80 	}
     81 
     82 	pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
     83 	pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
     84 	pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
     85 	pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
     86 	pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
     87 
     88 	pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
     89 
     90 	pctx.StaticVariable("CommonClangGlobalCflags",
     91 		strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
     92 	pctx.StaticVariable("DeviceClangGlobalCflags",
     93 		strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
     94 	pctx.StaticVariable("HostClangGlobalCflags",
     95 		strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
     96 	pctx.StaticVariable("NoOverrideClangGlobalCflags",
     97 		strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
     98 
     99 	pctx.StaticVariable("CommonClangGlobalCppflags",
    100 		strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
    101 
    102 	// Everything in these lists is a crime against abstraction and dependency tracking.
    103 	// Do not add anything to this list.
    104 	pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalIncludes", "-I",
    105 		[]string{
    106 			"system/core/include",
    107 			"system/media/audio/include",
    108 			"hardware/libhardware/include",
    109 			"hardware/libhardware_legacy/include",
    110 			"hardware/ril/include",
    111 			"libnativehelper/include",
    112 			"frameworks/native/include",
    113 			"frameworks/native/opengl/include",
    114 		})
    115 	pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalSystemIncludes", "-isystem ",
    116 		[]string{
    117 			"frameworks/av/include",
    118 		})
    119 	// This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
    120 	// with this, since there is no associated library.
    121 	pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I",
    122 		[]string{"libnativehelper/include/nativehelper"})
    123 
    124 	pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
    125 	pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
    126 		if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
    127 			return override, nil
    128 		}
    129 		return "${ClangDefaultBase}", nil
    130 	})
    131 	pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
    132 		if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
    133 			return override, nil
    134 		}
    135 		return "clang-3859424", nil
    136 	})
    137 	pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
    138 	pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
    139 
    140 	pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
    141 		if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
    142 			return override, nil
    143 		}
    144 		return "4.0", nil
    145 	})
    146 	pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
    147 
    148 	// These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
    149 	// being used for the rest of the build process.
    150 	pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
    151 	pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
    152 	pctx.SourcePathVariable("RSReleaseVersion", "3.8")
    153 	pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
    154 	pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
    155 
    156 	pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
    157 		if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
    158 			return override + " ", nil
    159 		}
    160 		return "", nil
    161 	})
    162 }
    163 
    164 var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
    165 
    166 func bionicHeaders(bionicArch, kernelArch string) string {
    167 	return strings.Join([]string{
    168 		"-isystem bionic/libc/arch-" + bionicArch + "/include",
    169 		"-isystem bionic/libc/include",
    170 		"-isystem bionic/libc/kernel/uapi",
    171 		"-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
    172 		"-isystem bionic/libc/kernel/android/uapi",
    173 	}, " ")
    174 }
    175 
    176 func VndkLibraries() []string {
    177 	return []string{}
    178 }
    179 
    180 // This needs to be kept up to date with the list in system/core/rootdir/etc/ld.config.txt:
    181 // [vendor]
    182 // namespace.default.link.system.shared_libs
    183 func LLndkLibraries() []string {
    184 	return []string{"libc", "libm", "libdl", "liblog", "libandroid_net", "ld-android"}
    185 }
    186