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 var (
     24 	// Flags used by lots of devices.  Putting them in package static variables
     25 	// will save bytes in build.ninja so they aren't repeated for every file
     26 	commonGlobalCflags = []string{
     27 		"-DANDROID",
     28 		"-fmessage-length=0",
     29 		"-W",
     30 		"-Wall",
     31 		"-Wno-unused",
     32 		"-Winit-self",
     33 		"-Wpointer-arith",
     34 
     35 		// Make paths in deps files relative
     36 		"-no-canonical-prefixes",
     37 		"-fno-canonical-system-headers",
     38 
     39 		"-DNDEBUG",
     40 		"-UDEBUG",
     41 
     42 		"-fno-exceptions",
     43 		"-Wno-multichar",
     44 
     45 		"-O2",
     46 		"-g",
     47 
     48 		"-fno-strict-aliasing",
     49 	}
     50 
     51 	commonGlobalConlyflags = []string{}
     52 
     53 	deviceGlobalCflags = []string{
     54 		"-fdiagnostics-color",
     55 
     56 		"-ffunction-sections",
     57 		"-fdata-sections",
     58 		"-fno-short-enums",
     59 		"-funwind-tables",
     60 		"-fstack-protector-strong",
     61 		"-Wa,--noexecstack",
     62 		"-D_FORTIFY_SOURCE=2",
     63 
     64 		"-Wstrict-aliasing=2",
     65 
     66 		"-Werror=return-type",
     67 		"-Werror=non-virtual-dtor",
     68 		"-Werror=address",
     69 		"-Werror=sequence-point",
     70 		"-Werror=date-time",
     71 		"-Werror=format-security",
     72 	}
     73 
     74 	deviceGlobalCppflags = []string{
     75 		"-fvisibility-inlines-hidden",
     76 	}
     77 
     78 	deviceGlobalLdflags = []string{
     79 		"-Wl,-z,noexecstack",
     80 		"-Wl,-z,relro",
     81 		"-Wl,-z,now",
     82 		"-Wl,--build-id=md5",
     83 		"-Wl,--warn-shared-textrel",
     84 		"-Wl,--fatal-warnings",
     85 		"-Wl,--no-undefined-version",
     86 		"-Wl,--exclude-libs,libgcc.a",
     87 		"-Wl,--exclude-libs,libgcc_stripped.a",
     88 	}
     89 
     90 	deviceGlobalLldflags = append(ClangFilterUnknownLldflags(deviceGlobalLdflags),
     91 		[]string{
     92 			"-fuse-ld=lld",
     93 		}...)
     94 
     95 	hostGlobalCflags = []string{}
     96 
     97 	hostGlobalCppflags = []string{}
     98 
     99 	hostGlobalLdflags = []string{}
    100 
    101 	hostGlobalLldflags = []string{"-fuse-ld=lld"}
    102 
    103 	commonGlobalCppflags = []string{
    104 		"-Wsign-promo",
    105 	}
    106 
    107 	noOverrideGlobalCflags = []string{
    108 		"-Werror=int-to-pointer-cast",
    109 		"-Werror=pointer-to-int-cast",
    110 	}
    111 
    112 	IllegalFlags = []string{
    113 		"-w",
    114 	}
    115 
    116 	CStdVersion               = "gnu99"
    117 	CppStdVersion             = "gnu++17"
    118 	ExperimentalCStdVersion   = "gnu11"
    119 	ExperimentalCppStdVersion = "gnu++2a"
    120 
    121 	NdkMaxPrebuiltVersionInt = 27
    122 
    123 	// prebuilts/clang default settings.
    124 	ClangDefaultBase         = "prebuilts/clang/host"
    125 	ClangDefaultVersion      = "clang-r353983c"
    126 	ClangDefaultShortVersion = "9.0.3"
    127 
    128 	// Directories with warnings from Android.bp files.
    129 	WarningAllowedProjects = []string{
    130 		"device/",
    131 		"vendor/",
    132 	}
    133 
    134 	// Directories with warnings from Android.mk files.
    135 	WarningAllowedOldProjects = []string{}
    136 )
    137 
    138 var pctx = android.NewPackageContext("android/soong/cc/config")
    139 
    140 func init() {
    141 	if android.BuildOs == android.Linux {
    142 		commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
    143 	}
    144 
    145 	pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
    146 	pctx.StaticVariable("DeviceGlobalCppflags", strings.Join(deviceGlobalCppflags, " "))
    147 	pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " "))
    148 	pctx.StaticVariable("DeviceGlobalLldflags", strings.Join(deviceGlobalLldflags, " "))
    149 	pctx.StaticVariable("HostGlobalCppflags", strings.Join(hostGlobalCppflags, " "))
    150 	pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " "))
    151 	pctx.StaticVariable("HostGlobalLldflags", strings.Join(hostGlobalLldflags, " "))
    152 
    153 	pctx.StaticVariable("CommonClangGlobalCflags",
    154 		strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
    155 	pctx.VariableFunc("DeviceClangGlobalCflags", func(ctx android.PackageVarContext) string {
    156 		if ctx.Config().Fuchsia() {
    157 			return strings.Join(ClangFilterUnknownCflags(deviceGlobalCflags), " ")
    158 		} else {
    159 			return strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " ")
    160 		}
    161 	})
    162 	pctx.StaticVariable("HostClangGlobalCflags",
    163 		strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
    164 	pctx.StaticVariable("NoOverrideClangGlobalCflags",
    165 		strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
    166 
    167 	pctx.StaticVariable("CommonClangGlobalCppflags",
    168 		strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
    169 
    170 	pctx.StaticVariable("ClangExternalCflags", "${ClangExtraExternalCflags}")
    171 
    172 	// Everything in these lists is a crime against abstraction and dependency tracking.
    173 	// Do not add anything to this list.
    174 	pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
    175 		[]string{
    176 			"system/core/include",
    177 			"system/media/audio/include",
    178 			"hardware/libhardware/include",
    179 			"hardware/libhardware_legacy/include",
    180 			"hardware/ril/include",
    181 			"frameworks/native/include",
    182 			"frameworks/native/opengl/include",
    183 			"frameworks/av/include",
    184 		})
    185 	// This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
    186 	// with this, since there is no associated library.
    187 	pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
    188 		[]string{"libnativehelper/include_jni"})
    189 
    190 	pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
    191 	pctx.VariableFunc("ClangBase", func(ctx android.PackageVarContext) string {
    192 		if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
    193 			return override
    194 		}
    195 		return "${ClangDefaultBase}"
    196 	})
    197 	pctx.VariableFunc("ClangVersion", func(ctx android.PackageVarContext) string {
    198 		if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
    199 			return override
    200 		}
    201 		return ClangDefaultVersion
    202 	})
    203 	pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
    204 	pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
    205 	pctx.StaticVariable("ClangTidyShellPath", "build/soong/scripts/clang-tidy.sh")
    206 
    207 	pctx.VariableFunc("ClangShortVersion", func(ctx android.PackageVarContext) string {
    208 		if override := ctx.Config().Getenv("LLVM_RELEASE_VERSION"); override != "" {
    209 			return override
    210 		}
    211 		return ClangDefaultShortVersion
    212 	})
    213 	pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
    214 
    215 	// These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
    216 	// being used for the rest of the build process.
    217 	pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
    218 	pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
    219 	pctx.SourcePathVariable("RSReleaseVersion", "3.8")
    220 	pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
    221 	pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
    222 
    223 	pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
    224 		[]string{
    225 			"external/clang/lib/Headers",
    226 			"frameworks/rs/script_api/include",
    227 		})
    228 
    229 	pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
    230 		if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
    231 			return override + " "
    232 		}
    233 		return ""
    234 	})
    235 }
    236 
    237 var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
    238 
    239 func bionicHeaders(kernelArch string) string {
    240 	return strings.Join([]string{
    241 		"-isystem bionic/libc/include",
    242 		"-isystem bionic/libc/kernel/uapi",
    243 		"-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
    244 		"-isystem bionic/libc/kernel/android/scsi",
    245 		"-isystem bionic/libc/kernel/android/uapi",
    246 	}, " ")
    247 }
    248