1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0 2*4882a593SmuzhiyunVERSION = 5 3*4882a593SmuzhiyunPATCHLEVEL = 10 4*4882a593SmuzhiyunSUBLEVEL = 160 5*4882a593SmuzhiyunEXTRAVERSION = 6*4882a593SmuzhiyunNAME = Dare mighty things 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun# *DOCUMENTATION* 9*4882a593Smuzhiyun# To see a list of typical targets execute "make help" 10*4882a593Smuzhiyun# More info can be located in ./README 11*4882a593Smuzhiyun# Comments in this file are targeted only to the developer, do not 12*4882a593Smuzhiyun# expect to learn how to build the kernel reading this file. 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun$(if $(filter __%, $(MAKECMDGOALS)), \ 15*4882a593Smuzhiyun $(error targets prefixed with '__' are only for internal use)) 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun# That's our default target when none is given on the command line 18*4882a593SmuzhiyunPHONY := __all 19*4882a593Smuzhiyun__all: 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun# We are using a recursive build, so we need to do a little thinking 22*4882a593Smuzhiyun# to get the ordering right. 23*4882a593Smuzhiyun# 24*4882a593Smuzhiyun# Most importantly: sub-Makefiles should only ever modify files in 25*4882a593Smuzhiyun# their own directory. If in some directory we have a dependency on 26*4882a593Smuzhiyun# a file in another dir (which doesn't happen often, but it's often 27*4882a593Smuzhiyun# unavoidable when linking the built-in.a targets which finally 28*4882a593Smuzhiyun# turn into vmlinux), we will call a sub make in that other dir, and 29*4882a593Smuzhiyun# after that we are sure that everything which is in that other dir 30*4882a593Smuzhiyun# is now up to date. 31*4882a593Smuzhiyun# 32*4882a593Smuzhiyun# The only cases where we need to modify files which have global 33*4882a593Smuzhiyun# effects are thus separated out and done before the recursive 34*4882a593Smuzhiyun# descending is started. They are now explicitly listed as the 35*4882a593Smuzhiyun# prepare rule. 36*4882a593Smuzhiyun 37*4882a593Smuzhiyunifneq ($(sub_make_done),1) 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun# Do not use make's built-in rules and variables 40*4882a593Smuzhiyun# (this increases performance and avoids hard-to-debug behaviour) 41*4882a593SmuzhiyunMAKEFLAGS += -rR 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun# Avoid funny character set dependencies 44*4882a593Smuzhiyununexport LC_ALL 45*4882a593SmuzhiyunLC_COLLATE=C 46*4882a593SmuzhiyunLC_NUMERIC=C 47*4882a593Smuzhiyunexport LC_COLLATE LC_NUMERIC 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun# Avoid interference with shell env settings 50*4882a593Smuzhiyununexport GREP_OPTIONS 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun# Beautify output 53*4882a593Smuzhiyun# --------------------------------------------------------------------------- 54*4882a593Smuzhiyun# 55*4882a593Smuzhiyun# Normally, we echo the whole command before executing it. By making 56*4882a593Smuzhiyun# that echo $($(quiet)$(cmd)), we now have the possibility to set 57*4882a593Smuzhiyun# $(quiet) to choose other forms of output instead, e.g. 58*4882a593Smuzhiyun# 59*4882a593Smuzhiyun# quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@ 60*4882a593Smuzhiyun# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 61*4882a593Smuzhiyun# 62*4882a593Smuzhiyun# If $(quiet) is empty, the whole command will be printed. 63*4882a593Smuzhiyun# If it is set to "quiet_", only the short version will be printed. 64*4882a593Smuzhiyun# If it is set to "silent_", nothing will be printed at all, since 65*4882a593Smuzhiyun# the variable $(silent_cmd_cc_o_c) doesn't exist. 66*4882a593Smuzhiyun# 67*4882a593Smuzhiyun# A simple variant is to prefix commands with $(Q) - that's useful 68*4882a593Smuzhiyun# for commands that shall be hidden in non-verbose mode. 69*4882a593Smuzhiyun# 70*4882a593Smuzhiyun# $(Q)ln $@ :< 71*4882a593Smuzhiyun# 72*4882a593Smuzhiyun# If KBUILD_VERBOSE equals 0 then the above command will be hidden. 73*4882a593Smuzhiyun# If KBUILD_VERBOSE equals 1 then the above command is displayed. 74*4882a593Smuzhiyun# If KBUILD_VERBOSE equals 2 then give the reason why each target is rebuilt. 75*4882a593Smuzhiyun# 76*4882a593Smuzhiyun# To put more focus on warnings, be less verbose as default 77*4882a593Smuzhiyun# Use 'make V=1' to see the full commands 78*4882a593Smuzhiyun 79*4882a593Smuzhiyunifeq ("$(origin V)", "command line") 80*4882a593Smuzhiyun KBUILD_VERBOSE = $(V) 81*4882a593Smuzhiyunendif 82*4882a593Smuzhiyunifndef KBUILD_VERBOSE 83*4882a593Smuzhiyun KBUILD_VERBOSE = 0 84*4882a593Smuzhiyunendif 85*4882a593Smuzhiyun 86*4882a593Smuzhiyunifeq ($(KBUILD_VERBOSE),1) 87*4882a593Smuzhiyun quiet = 88*4882a593Smuzhiyun Q = 89*4882a593Smuzhiyunelse 90*4882a593Smuzhiyun quiet=quiet_ 91*4882a593Smuzhiyun Q = @ 92*4882a593Smuzhiyunendif 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun# If the user is running make -s (silent mode), suppress echoing of 95*4882a593Smuzhiyun# commands 96*4882a593Smuzhiyun 97*4882a593Smuzhiyunifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) 98*4882a593Smuzhiyun quiet=silent_ 99*4882a593Smuzhiyunendif 100*4882a593Smuzhiyun 101*4882a593Smuzhiyunexport quiet Q KBUILD_VERBOSE 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun# Kbuild will save output files in the current working directory. 104*4882a593Smuzhiyun# This does not need to match to the root of the kernel source tree. 105*4882a593Smuzhiyun# 106*4882a593Smuzhiyun# For example, you can do this: 107*4882a593Smuzhiyun# 108*4882a593Smuzhiyun# cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile 109*4882a593Smuzhiyun# 110*4882a593Smuzhiyun# If you want to save output files in a different location, there are 111*4882a593Smuzhiyun# two syntaxes to specify it. 112*4882a593Smuzhiyun# 113*4882a593Smuzhiyun# 1) O= 114*4882a593Smuzhiyun# Use "make O=dir/to/store/output/files/" 115*4882a593Smuzhiyun# 116*4882a593Smuzhiyun# 2) Set KBUILD_OUTPUT 117*4882a593Smuzhiyun# Set the environment variable KBUILD_OUTPUT to point to the output directory. 118*4882a593Smuzhiyun# export KBUILD_OUTPUT=dir/to/store/output/files/; make 119*4882a593Smuzhiyun# 120*4882a593Smuzhiyun# The O= assignment takes precedence over the KBUILD_OUTPUT environment 121*4882a593Smuzhiyun# variable. 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun# Do we want to change the working directory? 124*4882a593Smuzhiyunifeq ("$(origin O)", "command line") 125*4882a593Smuzhiyun KBUILD_OUTPUT := $(O) 126*4882a593Smuzhiyunendif 127*4882a593Smuzhiyun 128*4882a593Smuzhiyunifneq ($(KBUILD_OUTPUT),) 129*4882a593Smuzhiyun# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot 130*4882a593Smuzhiyun# expand a shell special character '~'. We use a somewhat tedious way here. 131*4882a593Smuzhiyunabs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) 132*4882a593Smuzhiyun$(if $(abs_objtree),, \ 133*4882a593Smuzhiyun $(error failed to create output directory "$(KBUILD_OUTPUT)")) 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun# $(realpath ...) resolves symlinks 136*4882a593Smuzhiyunabs_objtree := $(realpath $(abs_objtree)) 137*4882a593Smuzhiyunelse 138*4882a593Smuzhiyunabs_objtree := $(CURDIR) 139*4882a593Smuzhiyunendif # ifneq ($(KBUILD_OUTPUT),) 140*4882a593Smuzhiyun 141*4882a593Smuzhiyunifeq ($(abs_objtree),$(CURDIR)) 142*4882a593Smuzhiyun# Suppress "Entering directory ..." unless we are changing the work directory. 143*4882a593SmuzhiyunMAKEFLAGS += --no-print-directory 144*4882a593Smuzhiyunelse 145*4882a593Smuzhiyunneed-sub-make := 1 146*4882a593Smuzhiyunendif 147*4882a593Smuzhiyun 148*4882a593Smuzhiyunabs_srctree := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) 149*4882a593Smuzhiyun 150*4882a593Smuzhiyunifneq ($(words $(subst :, ,$(abs_srctree))), 1) 151*4882a593Smuzhiyun$(error source directory cannot contain spaces or colons) 152*4882a593Smuzhiyunendif 153*4882a593Smuzhiyun 154*4882a593Smuzhiyunifneq ($(abs_srctree),$(abs_objtree)) 155*4882a593Smuzhiyun# Look for make include files relative to root of kernel src 156*4882a593Smuzhiyun# 157*4882a593Smuzhiyun# This does not become effective immediately because MAKEFLAGS is re-parsed 158*4882a593Smuzhiyun# once after the Makefile is read. We need to invoke sub-make. 159*4882a593SmuzhiyunMAKEFLAGS += --include-dir=$(abs_srctree) 160*4882a593Smuzhiyunneed-sub-make := 1 161*4882a593Smuzhiyunendif 162*4882a593Smuzhiyun 163*4882a593Smuzhiyunthis-makefile := $(lastword $(MAKEFILE_LIST)) 164*4882a593Smuzhiyun 165*4882a593Smuzhiyunifneq ($(filter 3.%,$(MAKE_VERSION)),) 166*4882a593Smuzhiyun# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x 167*4882a593Smuzhiyun# We need to invoke sub-make to avoid implicit rules in the top Makefile. 168*4882a593Smuzhiyunneed-sub-make := 1 169*4882a593Smuzhiyun# Cancel implicit rules for this Makefile. 170*4882a593Smuzhiyun$(this-makefile): ; 171*4882a593Smuzhiyunendif 172*4882a593Smuzhiyun 173*4882a593Smuzhiyunexport abs_srctree abs_objtree 174*4882a593Smuzhiyunexport sub_make_done := 1 175*4882a593Smuzhiyun 176*4882a593Smuzhiyunifeq ($(need-sub-make),1) 177*4882a593Smuzhiyun 178*4882a593SmuzhiyunPHONY += $(MAKECMDGOALS) __sub-make 179*4882a593Smuzhiyun 180*4882a593Smuzhiyun$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make 181*4882a593Smuzhiyun @: 182*4882a593Smuzhiyun 183*4882a593Smuzhiyun# Invoke a second make in the output directory, passing relevant variables 184*4882a593Smuzhiyun__sub-make: 185*4882a593Smuzhiyun $(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS) 186*4882a593Smuzhiyun 187*4882a593Smuzhiyunendif # need-sub-make 188*4882a593Smuzhiyunendif # sub_make_done 189*4882a593Smuzhiyun 190*4882a593Smuzhiyun# We process the rest of the Makefile if this is the final invocation of make 191*4882a593Smuzhiyunifeq ($(need-sub-make),) 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun# Do not print "Entering directory ...", 194*4882a593Smuzhiyun# but we want to display it when entering to the output directory 195*4882a593Smuzhiyun# so that IDEs/editors are able to understand relative filenames. 196*4882a593SmuzhiyunMAKEFLAGS += --no-print-directory 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun# Call a source code checker (by default, "sparse") as part of the 199*4882a593Smuzhiyun# C compilation. 200*4882a593Smuzhiyun# 201*4882a593Smuzhiyun# Use 'make C=1' to enable checking of only re-compiled files. 202*4882a593Smuzhiyun# Use 'make C=2' to enable checking of *all* source files, regardless 203*4882a593Smuzhiyun# of whether they are re-compiled or not. 204*4882a593Smuzhiyun# 205*4882a593Smuzhiyun# See the file "Documentation/dev-tools/sparse.rst" for more details, 206*4882a593Smuzhiyun# including where to get the "sparse" utility. 207*4882a593Smuzhiyun 208*4882a593Smuzhiyunifeq ("$(origin C)", "command line") 209*4882a593Smuzhiyun KBUILD_CHECKSRC = $(C) 210*4882a593Smuzhiyunendif 211*4882a593Smuzhiyunifndef KBUILD_CHECKSRC 212*4882a593Smuzhiyun KBUILD_CHECKSRC = 0 213*4882a593Smuzhiyunendif 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun# Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the 216*4882a593Smuzhiyun# directory of external module to build. Setting M= takes precedence. 217*4882a593Smuzhiyunifeq ("$(origin M)", "command line") 218*4882a593Smuzhiyun KBUILD_EXTMOD := $(M) 219*4882a593Smuzhiyunendif 220*4882a593Smuzhiyun 221*4882a593Smuzhiyun$(if $(word 2, $(KBUILD_EXTMOD)), \ 222*4882a593Smuzhiyun $(error building multiple external modules is not supported)) 223*4882a593Smuzhiyun 224*4882a593Smuzhiyunexport KBUILD_CHECKSRC KBUILD_EXTMOD 225*4882a593Smuzhiyun 226*4882a593Smuzhiyunextmod-prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun# ANDROID: set up mixed-build support. mixed-build allows device kernel modules 229*4882a593Smuzhiyun# to be compiled against a GKI kernel. This approach still uses the headers and 230*4882a593Smuzhiyun# Kbuild from device kernel, so care must be taken to ensure that those headers match. 231*4882a593Smuzhiyunifdef KBUILD_MIXED_TREE 232*4882a593Smuzhiyun# Need vmlinux.symvers for modpost and System.map for depmod, check whether they exist in KBUILD_MIXED_TREE 233*4882a593Smuzhiyunrequired_mixed_files=vmlinux.symvers System.map 234*4882a593Smuzhiyun$(if $(filter-out $(words $(required_mixed_files)), \ 235*4882a593Smuzhiyun $(words $(wildcard $(add-prefix $(KBUILD_MIXED_TREE)/,$(required_mixed_files))))),,\ 236*4882a593Smuzhiyun $(error KBUILD_MIXED_TREE=$(KBUILD_MIXED_TREE) doesn't contain $(required_mixed_files))) 237*4882a593Smuzhiyunendif 238*4882a593Smuzhiyun 239*4882a593Smuzhiyunmixed-build-prefix = $(if $(KBUILD_MIXED_TREE),$(KBUILD_MIXED_TREE)/) 240*4882a593Smuzhiyunexport KBUILD_MIXED_TREE 241*4882a593Smuzhiyun 242*4882a593Smuzhiyunifeq ($(abs_srctree),$(abs_objtree)) 243*4882a593Smuzhiyun # building in the source tree 244*4882a593Smuzhiyun srctree := . 245*4882a593Smuzhiyun building_out_of_srctree := 246*4882a593Smuzhiyunelse 247*4882a593Smuzhiyun ifeq ($(abs_srctree)/,$(dir $(abs_objtree))) 248*4882a593Smuzhiyun # building in a subdirectory of the source tree 249*4882a593Smuzhiyun srctree := .. 250*4882a593Smuzhiyun else 251*4882a593Smuzhiyun srctree := $(abs_srctree) 252*4882a593Smuzhiyun endif 253*4882a593Smuzhiyun building_out_of_srctree := 1 254*4882a593Smuzhiyunendif 255*4882a593Smuzhiyun 256*4882a593Smuzhiyunifneq ($(KBUILD_ABS_SRCTREE),) 257*4882a593Smuzhiyunsrctree := $(abs_srctree) 258*4882a593Smuzhiyunendif 259*4882a593Smuzhiyun 260*4882a593Smuzhiyunobjtree := . 261*4882a593SmuzhiyunVPATH := $(srctree) 262*4882a593Smuzhiyun 263*4882a593Smuzhiyunexport building_out_of_srctree srctree objtree VPATH 264*4882a593Smuzhiyun 265*4882a593Smuzhiyun# To make sure we do not include .config for any of the *config targets 266*4882a593Smuzhiyun# catch them early, and hand them over to scripts/kconfig/Makefile 267*4882a593Smuzhiyun# It is allowed to specify more targets when calling make, including 268*4882a593Smuzhiyun# mixing *config targets and build targets. 269*4882a593Smuzhiyun# For example 'make oldconfig all'. 270*4882a593Smuzhiyun# Detect when mixed targets is specified, and make a second invocation 271*4882a593Smuzhiyun# of make so .config is not included in this case either (for *config). 272*4882a593Smuzhiyun 273*4882a593Smuzhiyunversion_h := include/generated/uapi/linux/version.h 274*4882a593Smuzhiyunold_version_h := include/linux/version.h 275*4882a593Smuzhiyun 276*4882a593Smuzhiyunclean-targets := %clean mrproper cleandocs 277*4882a593Smuzhiyunno-dot-config-targets := $(clean-targets) \ 278*4882a593Smuzhiyun cscope gtags TAGS tags help% %docs check% coccicheck \ 279*4882a593Smuzhiyun $(version_h) headers headers_% archheaders archscripts \ 280*4882a593Smuzhiyun %asm-generic kernelversion %src-pkg dt_binding_check \ 281*4882a593Smuzhiyun outputmakefile 282*4882a593Smuzhiyunno-sync-config-targets := $(no-dot-config-targets) %install kernelrelease \ 283*4882a593Smuzhiyun image_name 284*4882a593Smuzhiyunsingle-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/ 285*4882a593Smuzhiyun 286*4882a593Smuzhiyunconfig-build := 287*4882a593Smuzhiyunmixed-build := 288*4882a593Smuzhiyunneed-config := 1 289*4882a593Smuzhiyunmay-sync-config := 1 290*4882a593Smuzhiyunsingle-build := 291*4882a593Smuzhiyun 292*4882a593Smuzhiyunifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) 293*4882a593Smuzhiyun ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) 294*4882a593Smuzhiyun need-config := 295*4882a593Smuzhiyun endif 296*4882a593Smuzhiyunendif 297*4882a593Smuzhiyun 298*4882a593Smuzhiyunifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) 299*4882a593Smuzhiyun ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) 300*4882a593Smuzhiyun may-sync-config := 301*4882a593Smuzhiyun endif 302*4882a593Smuzhiyunendif 303*4882a593Smuzhiyun 304*4882a593Smuzhiyunifneq ($(KBUILD_EXTMOD),) 305*4882a593Smuzhiyun may-sync-config := 306*4882a593Smuzhiyunendif 307*4882a593Smuzhiyun 308*4882a593Smuzhiyunifeq ($(KBUILD_EXTMOD),) 309*4882a593Smuzhiyun ifneq ($(filter %config,$(MAKECMDGOALS)),) 310*4882a593Smuzhiyun config-build := 1 311*4882a593Smuzhiyun ifneq ($(words $(MAKECMDGOALS)),1) 312*4882a593Smuzhiyun mixed-build := 1 313*4882a593Smuzhiyun endif 314*4882a593Smuzhiyun endif 315*4882a593Smuzhiyunendif 316*4882a593Smuzhiyun 317*4882a593Smuzhiyun# We cannot build single targets and the others at the same time 318*4882a593Smuzhiyunifneq ($(filter $(single-targets), $(MAKECMDGOALS)),) 319*4882a593Smuzhiyun single-build := 1 320*4882a593Smuzhiyun ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),) 321*4882a593Smuzhiyun mixed-build := 1 322*4882a593Smuzhiyun endif 323*4882a593Smuzhiyunendif 324*4882a593Smuzhiyun 325*4882a593Smuzhiyun# For "make -j clean all", "make -j mrproper defconfig all", etc. 326*4882a593Smuzhiyunifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) 327*4882a593Smuzhiyun ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) 328*4882a593Smuzhiyun mixed-build := 1 329*4882a593Smuzhiyun endif 330*4882a593Smuzhiyunendif 331*4882a593Smuzhiyun 332*4882a593Smuzhiyun# install and modules_install need also be processed one by one 333*4882a593Smuzhiyunifneq ($(filter install,$(MAKECMDGOALS)),) 334*4882a593Smuzhiyun ifneq ($(filter modules_install,$(MAKECMDGOALS)),) 335*4882a593Smuzhiyun mixed-build := 1 336*4882a593Smuzhiyun endif 337*4882a593Smuzhiyunendif 338*4882a593Smuzhiyun 339*4882a593Smuzhiyunifdef mixed-build 340*4882a593Smuzhiyun# =========================================================================== 341*4882a593Smuzhiyun# We're called with mixed targets (*config and build targets). 342*4882a593Smuzhiyun# Handle them one by one. 343*4882a593Smuzhiyun 344*4882a593SmuzhiyunPHONY += $(MAKECMDGOALS) __build_one_by_one 345*4882a593Smuzhiyun 346*4882a593Smuzhiyun$(MAKECMDGOALS): __build_one_by_one 347*4882a593Smuzhiyun @: 348*4882a593Smuzhiyun 349*4882a593Smuzhiyun__build_one_by_one: 350*4882a593Smuzhiyun $(Q)set -e; \ 351*4882a593Smuzhiyun for i in $(MAKECMDGOALS); do \ 352*4882a593Smuzhiyun $(MAKE) -f $(srctree)/Makefile $$i; \ 353*4882a593Smuzhiyun done 354*4882a593Smuzhiyun 355*4882a593Smuzhiyunelse # !mixed-build 356*4882a593Smuzhiyun 357*4882a593Smuzhiyuninclude scripts/Kbuild.include 358*4882a593Smuzhiyun 359*4882a593Smuzhiyun# Read KERNELRELEASE from include/config/kernel.release (if it exists) 360*4882a593SmuzhiyunKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) 361*4882a593SmuzhiyunKERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) 362*4882a593Smuzhiyunexport VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION 363*4882a593Smuzhiyun 364*4882a593Smuzhiyuninclude scripts/subarch.include 365*4882a593Smuzhiyun 366*4882a593Smuzhiyun# Cross compiling and selecting different set of gcc/bin-utils 367*4882a593Smuzhiyun# --------------------------------------------------------------------------- 368*4882a593Smuzhiyun# 369*4882a593Smuzhiyun# When performing cross compilation for other architectures ARCH shall be set 370*4882a593Smuzhiyun# to the target architecture. (See arch/* for the possibilities). 371*4882a593Smuzhiyun# ARCH can be set during invocation of make: 372*4882a593Smuzhiyun# make ARCH=ia64 373*4882a593Smuzhiyun# Another way is to have ARCH set in the environment. 374*4882a593Smuzhiyun# The default ARCH is the host where make is executed. 375*4882a593Smuzhiyun 376*4882a593Smuzhiyun# CROSS_COMPILE specify the prefix used for all executables used 377*4882a593Smuzhiyun# during compilation. Only gcc and related bin-utils executables 378*4882a593Smuzhiyun# are prefixed with $(CROSS_COMPILE). 379*4882a593Smuzhiyun# CROSS_COMPILE can be set on the command line 380*4882a593Smuzhiyun# make CROSS_COMPILE=ia64-linux- 381*4882a593Smuzhiyun# Alternatively CROSS_COMPILE can be set in the environment. 382*4882a593Smuzhiyun# Default value for CROSS_COMPILE is not to prefix executables 383*4882a593Smuzhiyun# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile 384*4882a593SmuzhiyunARCH ?= $(SUBARCH) 385*4882a593Smuzhiyun 386*4882a593Smuzhiyun# Architecture as present in compile.h 387*4882a593SmuzhiyunUTS_MACHINE := $(ARCH) 388*4882a593SmuzhiyunSRCARCH := $(ARCH) 389*4882a593Smuzhiyun 390*4882a593Smuzhiyun# Additional ARCH settings for x86 391*4882a593Smuzhiyunifeq ($(ARCH),i386) 392*4882a593Smuzhiyun SRCARCH := x86 393*4882a593Smuzhiyunendif 394*4882a593Smuzhiyunifeq ($(ARCH),x86_64) 395*4882a593Smuzhiyun SRCARCH := x86 396*4882a593Smuzhiyunendif 397*4882a593Smuzhiyun 398*4882a593Smuzhiyun# Additional ARCH settings for sparc 399*4882a593Smuzhiyunifeq ($(ARCH),sparc32) 400*4882a593Smuzhiyun SRCARCH := sparc 401*4882a593Smuzhiyunendif 402*4882a593Smuzhiyunifeq ($(ARCH),sparc64) 403*4882a593Smuzhiyun SRCARCH := sparc 404*4882a593Smuzhiyunendif 405*4882a593Smuzhiyun 406*4882a593Smuzhiyun# Additional ARCH settings for sh 407*4882a593Smuzhiyunifeq ($(ARCH),sh64) 408*4882a593Smuzhiyun SRCARCH := sh 409*4882a593Smuzhiyunendif 410*4882a593Smuzhiyun 411*4882a593SmuzhiyunKCONFIG_CONFIG ?= .config 412*4882a593Smuzhiyunexport KCONFIG_CONFIG 413*4882a593Smuzhiyun 414*4882a593Smuzhiyun# Default file for 'make defconfig'. This may be overridden by arch-Makefile. 415*4882a593Smuzhiyunexport KBUILD_DEFCONFIG := defconfig 416*4882a593Smuzhiyun 417*4882a593Smuzhiyun# SHELL used by kbuild 418*4882a593SmuzhiyunCONFIG_SHELL := sh 419*4882a593Smuzhiyun 420*4882a593SmuzhiyunHOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null) 421*4882a593SmuzhiyunHOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null) 422*4882a593SmuzhiyunHOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null) 423*4882a593Smuzhiyun 424*4882a593Smuzhiyunifneq ($(LLVM),) 425*4882a593SmuzhiyunHOSTCC = clang 426*4882a593SmuzhiyunHOSTCXX = clang++ 427*4882a593Smuzhiyunelse 428*4882a593SmuzhiyunHOSTCC = gcc 429*4882a593SmuzhiyunHOSTCXX = g++ 430*4882a593Smuzhiyunendif 431*4882a593Smuzhiyun 432*4882a593SmuzhiyunKBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \ 433*4882a593Smuzhiyun -O2 -fomit-frame-pointer -std=gnu89 434*4882a593SmuzhiyunKBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS) 435*4882a593SmuzhiyunKBUILD_USERLDFLAGS := $(USERLDFLAGS) 436*4882a593Smuzhiyun 437*4882a593SmuzhiyunKBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS) 438*4882a593SmuzhiyunKBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) 439*4882a593SmuzhiyunKBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) 440*4882a593SmuzhiyunKBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS) 441*4882a593Smuzhiyun 442*4882a593Smuzhiyun# Make variables (CC, etc...) 443*4882a593SmuzhiyunCPP = $(CC) -E 444*4882a593Smuzhiyunifneq ($(LLVM),) 445*4882a593SmuzhiyunCC = clang 446*4882a593SmuzhiyunLD = ld.lld 447*4882a593SmuzhiyunAR = llvm-ar 448*4882a593SmuzhiyunNM = llvm-nm 449*4882a593SmuzhiyunOBJCOPY = llvm-objcopy 450*4882a593SmuzhiyunOBJDUMP = llvm-objdump 451*4882a593SmuzhiyunREADELF = llvm-readelf 452*4882a593SmuzhiyunSTRIP = llvm-strip 453*4882a593Smuzhiyunelse 454*4882a593SmuzhiyunCC = $(CROSS_COMPILE)gcc 455*4882a593SmuzhiyunLD = $(CROSS_COMPILE)ld 456*4882a593SmuzhiyunAR = $(CROSS_COMPILE)ar 457*4882a593SmuzhiyunNM = $(CROSS_COMPILE)nm 458*4882a593SmuzhiyunOBJCOPY = $(CROSS_COMPILE)objcopy 459*4882a593SmuzhiyunOBJDUMP = $(CROSS_COMPILE)objdump 460*4882a593SmuzhiyunREADELF = $(CROSS_COMPILE)readelf 461*4882a593SmuzhiyunSTRIP = $(CROSS_COMPILE)strip 462*4882a593Smuzhiyunendif 463*4882a593SmuzhiyunPAHOLE = pahole 464*4882a593SmuzhiyunRESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids 465*4882a593SmuzhiyunLEX = flex 466*4882a593SmuzhiyunYACC = bison 467*4882a593SmuzhiyunAWK = awk 468*4882a593SmuzhiyunINSTALLKERNEL := installkernel 469*4882a593SmuzhiyunDEPMOD = depmod 470*4882a593SmuzhiyunPERL = perl 471*4882a593SmuzhiyunPYTHON = python 472*4882a593SmuzhiyunPYTHON3 = python3 473*4882a593SmuzhiyunCHECK = sparse 474*4882a593SmuzhiyunBASH = bash 475*4882a593SmuzhiyunKGZIP = gzip 476*4882a593SmuzhiyunKBZIP2 = bzip2 477*4882a593SmuzhiyunKLZOP = lzop 478*4882a593SmuzhiyunLZMA = lzma 479*4882a593SmuzhiyunLZ4 = lz4 480*4882a593SmuzhiyunXZ = xz 481*4882a593SmuzhiyunZSTD = zstd 482*4882a593Smuzhiyun 483*4882a593Smuzhiyun# Use the wrapper for the compiler. This wrapper scans for new 484*4882a593Smuzhiyun# warnings and causes the build to stop upon encountering them. 485*4882a593Smuzhiyunifeq ($(CC),$(CROSS_COMPILE)gcc) 486*4882a593Smuzhiyunifneq ($(wildcard $(srctree)/scripts/gcc-wrapper.py),) 487*4882a593SmuzhiyunCC = $(abspath $(srctree)/scripts/gcc-wrapper.py) $(CROSS_COMPILE)gcc 488*4882a593Smuzhiyunendif 489*4882a593Smuzhiyunendif 490*4882a593Smuzhiyun 491*4882a593SmuzhiyunPAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh) 492*4882a593Smuzhiyun 493*4882a593SmuzhiyunCHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ 494*4882a593Smuzhiyun -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) 495*4882a593SmuzhiyunNOSTDINC_FLAGS := 496*4882a593SmuzhiyunCFLAGS_MODULE = 497*4882a593SmuzhiyunAFLAGS_MODULE = 498*4882a593SmuzhiyunLDFLAGS_MODULE = 499*4882a593SmuzhiyunCFLAGS_KERNEL = 500*4882a593SmuzhiyunAFLAGS_KERNEL = 501*4882a593SmuzhiyunLDFLAGS_vmlinux = 502*4882a593Smuzhiyun 503*4882a593Smuzhiyun# Use USERINCLUDE when you must reference the UAPI directories only. 504*4882a593SmuzhiyunUSERINCLUDE := \ 505*4882a593Smuzhiyun -I$(srctree)/arch/$(SRCARCH)/include/uapi \ 506*4882a593Smuzhiyun -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \ 507*4882a593Smuzhiyun -I$(srctree)/include/uapi \ 508*4882a593Smuzhiyun -I$(objtree)/include/generated/uapi \ 509*4882a593Smuzhiyun -include $(srctree)/include/linux/kconfig.h 510*4882a593Smuzhiyun 511*4882a593Smuzhiyun# Use LINUXINCLUDE when you must reference the include/ directory. 512*4882a593Smuzhiyun# Needed to be compatible with the O= option 513*4882a593SmuzhiyunLINUXINCLUDE := \ 514*4882a593Smuzhiyun -I$(srctree)/arch/$(SRCARCH)/include \ 515*4882a593Smuzhiyun -I$(objtree)/arch/$(SRCARCH)/include/generated \ 516*4882a593Smuzhiyun $(if $(building_out_of_srctree),-I$(srctree)/include) \ 517*4882a593Smuzhiyun -I$(objtree)/include \ 518*4882a593Smuzhiyun $(USERINCLUDE) 519*4882a593Smuzhiyun 520*4882a593SmuzhiyunKBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE 521*4882a593SmuzhiyunKBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ 522*4882a593Smuzhiyun -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ 523*4882a593Smuzhiyun -Werror=implicit-function-declaration -Werror=implicit-int \ 524*4882a593Smuzhiyun -Werror=return-type -Wno-format-security \ 525*4882a593Smuzhiyun -std=gnu89 526*4882a593SmuzhiyunKBUILD_CPPFLAGS := -D__KERNEL__ 527*4882a593SmuzhiyunKBUILD_AFLAGS_KERNEL := 528*4882a593SmuzhiyunKBUILD_CFLAGS_KERNEL := 529*4882a593SmuzhiyunKBUILD_AFLAGS_MODULE := -DMODULE 530*4882a593SmuzhiyunKBUILD_CFLAGS_MODULE := -DMODULE 531*4882a593SmuzhiyunKBUILD_LDFLAGS_MODULE := 532*4882a593SmuzhiyunKBUILD_LDFLAGS := 533*4882a593SmuzhiyunCLANG_FLAGS := 534*4882a593Smuzhiyun 535*4882a593Smuzhiyunexport ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC 536*4882a593Smuzhiyunexport CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL 537*4882a593Smuzhiyunexport PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX 538*4882a593Smuzhiyunexport KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD 539*4882a593Smuzhiyunexport KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE 540*4882a593Smuzhiyunexport KBUILD_USERCFLAGS KBUILD_USERLDFLAGS 541*4882a593Smuzhiyun 542*4882a593Smuzhiyunexport KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS 543*4882a593Smuzhiyunexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE 544*4882a593Smuzhiyunexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE 545*4882a593Smuzhiyunexport KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE 546*4882a593Smuzhiyunexport KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL 547*4882a593Smuzhiyunexport PAHOLE_FLAGS 548*4882a593Smuzhiyun 549*4882a593Smuzhiyun# Files to ignore in find ... statements 550*4882a593Smuzhiyun 551*4882a593Smuzhiyunexport RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \ 552*4882a593Smuzhiyun -name CVS -o -name .pc -o -name .hg -o -name .git \) \ 553*4882a593Smuzhiyun -prune -o 554*4882a593Smuzhiyunexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \ 555*4882a593Smuzhiyun --exclude CVS --exclude .pc --exclude .hg --exclude .git 556*4882a593Smuzhiyun 557*4882a593Smuzhiyun# =========================================================================== 558*4882a593Smuzhiyun# Rules shared between *config targets and build targets 559*4882a593Smuzhiyun 560*4882a593Smuzhiyun# Basic helpers built in scripts/basic/ 561*4882a593SmuzhiyunPHONY += scripts_basic 562*4882a593Smuzhiyunscripts_basic: 563*4882a593Smuzhiyun cp drivers/net/can/rockchip/forlinx_canfd.lo drivers/net/can/rockchip/forlinx_canfd.o 564*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=scripts/basic 565*4882a593Smuzhiyun $(Q)rm -f .tmp_quiet_recordmcount 566*4882a593Smuzhiyun 567*4882a593SmuzhiyunPHONY += outputmakefile 568*4882a593Smuzhiyun# Before starting out-of-tree build, make sure the source tree is clean. 569*4882a593Smuzhiyun# outputmakefile generates a Makefile in the output directory, if using a 570*4882a593Smuzhiyun# separate output directory. This allows convenient use of make in the 571*4882a593Smuzhiyun# output directory. 572*4882a593Smuzhiyun# At the same time when output Makefile generated, generate .gitignore to 573*4882a593Smuzhiyun# ignore whole output directory 574*4882a593Smuzhiyunoutputmakefile: 575*4882a593Smuzhiyunifdef building_out_of_srctree 576*4882a593Smuzhiyun $(Q)if [ -f $(srctree)/.config -o \ 577*4882a593Smuzhiyun -d $(srctree)/include/config -o \ 578*4882a593Smuzhiyun -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ 579*4882a593Smuzhiyun echo >&2 "***"; \ 580*4882a593Smuzhiyun echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ 581*4882a593Smuzhiyun echo >&2 "*** in $(abs_srctree)";\ 582*4882a593Smuzhiyun echo >&2 "***"; \ 583*4882a593Smuzhiyun false; \ 584*4882a593Smuzhiyun fi 585*4882a593Smuzhiyun $(Q)ln -fsn $(srctree) source 586*4882a593Smuzhiyun $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree) 587*4882a593Smuzhiyun $(Q)test -e .gitignore || \ 588*4882a593Smuzhiyun { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore 589*4882a593Smuzhiyunendif 590*4882a593Smuzhiyun 591*4882a593Smuzhiyunifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),) 592*4882a593Smuzhiyunifneq ($(CROSS_COMPILE),) 593*4882a593SmuzhiyunCLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) 594*4882a593SmuzhiyunGCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) 595*4882a593SmuzhiyunCLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) 596*4882a593SmuzhiyunGCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..) 597*4882a593Smuzhiyunendif 598*4882a593Smuzhiyunifneq ($(GCC_TOOLCHAIN),) 599*4882a593SmuzhiyunCLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN) 600*4882a593Smuzhiyunendif 601*4882a593Smuzhiyunifneq ($(LLVM_IAS),1) 602*4882a593SmuzhiyunCLANG_FLAGS += -no-integrated-as 603*4882a593Smuzhiyunendif 604*4882a593SmuzhiyunCLANG_FLAGS += -Werror=unknown-warning-option 605*4882a593SmuzhiyunKBUILD_CFLAGS += $(CLANG_FLAGS) 606*4882a593SmuzhiyunKBUILD_AFLAGS += $(CLANG_FLAGS) 607*4882a593Smuzhiyunexport CLANG_FLAGS 608*4882a593Smuzhiyunendif 609*4882a593Smuzhiyun 610*4882a593Smuzhiyun# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included. 611*4882a593Smuzhiyun# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile. 612*4882a593Smuzhiyun# CC_VERSION_TEXT is referenced from Kconfig (so it needs export), 613*4882a593Smuzhiyun# and from include/config/auto.conf.cmd to detect the compiler upgrade. 614*4882a593SmuzhiyunCC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1) 615*4882a593Smuzhiyun 616*4882a593Smuzhiyunifdef config-build 617*4882a593Smuzhiyun# =========================================================================== 618*4882a593Smuzhiyun# *config targets only - make sure prerequisites are updated, and descend 619*4882a593Smuzhiyun# in scripts/kconfig to make the *config target 620*4882a593Smuzhiyun 621*4882a593Smuzhiyun# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. 622*4882a593Smuzhiyun# KBUILD_DEFCONFIG may point out an alternative default configuration 623*4882a593Smuzhiyun# used for 'make defconfig' 624*4882a593Smuzhiyuninclude arch/$(SRCARCH)/Makefile 625*4882a593Smuzhiyunexport KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT 626*4882a593Smuzhiyun 627*4882a593Smuzhiyunconfig: outputmakefile scripts_basic FORCE 628*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=scripts/kconfig $@ 629*4882a593Smuzhiyun 630*4882a593Smuzhiyun%config: outputmakefile scripts_basic FORCE 631*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=scripts/kconfig $@ 632*4882a593Smuzhiyun 633*4882a593Smuzhiyunelse #!config-build 634*4882a593Smuzhiyun# =========================================================================== 635*4882a593Smuzhiyun# Build targets only - this includes vmlinux, arch specific targets, clean 636*4882a593Smuzhiyun# targets and others. In general all targets except *config targets. 637*4882a593Smuzhiyun 638*4882a593Smuzhiyun# If building an external module we do not care about the all: rule 639*4882a593Smuzhiyun# but instead __all depend on modules 640*4882a593SmuzhiyunPHONY += all 641*4882a593Smuzhiyunifeq ($(KBUILD_EXTMOD),) 642*4882a593Smuzhiyun__all: all 643*4882a593Smuzhiyunelse 644*4882a593Smuzhiyun__all: modules 645*4882a593Smuzhiyunendif 646*4882a593Smuzhiyun 647*4882a593Smuzhiyun# Decide whether to build built-in, modular, or both. 648*4882a593Smuzhiyun# Normally, just do built-in. 649*4882a593Smuzhiyun 650*4882a593SmuzhiyunKBUILD_MODULES := 651*4882a593SmuzhiyunKBUILD_BUILTIN := 1 652*4882a593Smuzhiyun 653*4882a593Smuzhiyun# If we have only "make modules", don't compile built-in objects. 654*4882a593Smuzhiyunifeq ($(MAKECMDGOALS),modules) 655*4882a593Smuzhiyun KBUILD_BUILTIN := 656*4882a593Smuzhiyunendif 657*4882a593Smuzhiyun 658*4882a593Smuzhiyun# If we have "make <whatever> modules", compile modules 659*4882a593Smuzhiyun# in addition to whatever we do anyway. 660*4882a593Smuzhiyun# Just "make" or "make all" shall build modules as well 661*4882a593Smuzhiyun 662*4882a593Smuzhiyunifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),) 663*4882a593Smuzhiyun KBUILD_MODULES := 1 664*4882a593Smuzhiyunendif 665*4882a593Smuzhiyun 666*4882a593Smuzhiyunifeq ($(MAKECMDGOALS),) 667*4882a593Smuzhiyun KBUILD_MODULES := 1 668*4882a593Smuzhiyunendif 669*4882a593Smuzhiyun 670*4882a593Smuzhiyunexport KBUILD_MODULES KBUILD_BUILTIN 671*4882a593Smuzhiyun 672*4882a593Smuzhiyunifdef need-config 673*4882a593Smuzhiyuninclude include/config/auto.conf 674*4882a593Smuzhiyunendif 675*4882a593Smuzhiyun 676*4882a593Smuzhiyunifeq ($(KBUILD_EXTMOD),) 677*4882a593Smuzhiyun# Objects we will link into vmlinux / subdirs we need to visit 678*4882a593Smuzhiyuncore-y := init/ usr/ 679*4882a593Smuzhiyundrivers-y := drivers/ sound/ 680*4882a593Smuzhiyundrivers-$(CONFIG_SAMPLES) += samples/ 681*4882a593Smuzhiyundrivers-y += net/ virt/ 682*4882a593Smuzhiyunlibs-y := lib/ 683*4882a593Smuzhiyunendif # KBUILD_EXTMOD 684*4882a593Smuzhiyun 685*4882a593Smuzhiyunifndef KBUILD_MIXED_TREE 686*4882a593Smuzhiyun# The all: target is the default when no target is given on the 687*4882a593Smuzhiyun# command line. 688*4882a593Smuzhiyun# This allow a user to issue only 'make' to build a kernel including modules 689*4882a593Smuzhiyun# Defaults to vmlinux, but the arch makefile usually adds further targets 690*4882a593Smuzhiyunall: vmlinux 691*4882a593Smuzhiyunendif 692*4882a593Smuzhiyun 693*4882a593SmuzhiyunCFLAGS_GCOV := -fprofile-arcs -ftest-coverage \ 694*4882a593Smuzhiyun $(call cc-option,-fno-tree-loop-im) \ 695*4882a593Smuzhiyun $(call cc-disable-warning,maybe-uninitialized,) 696*4882a593Smuzhiyunexport CFLAGS_GCOV 697*4882a593Smuzhiyun 698*4882a593Smuzhiyun# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later. 699*4882a593Smuzhiyunifdef CONFIG_FUNCTION_TRACER 700*4882a593Smuzhiyun CC_FLAGS_FTRACE := -pg 701*4882a593Smuzhiyunendif 702*4882a593Smuzhiyun 703*4882a593Smuzhiyunifdef CONFIG_CC_IS_GCC 704*4882a593SmuzhiyunRETPOLINE_CFLAGS := $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) 705*4882a593SmuzhiyunRETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch-cs-prefix) 706*4882a593SmuzhiyunRETPOLINE_VDSO_CFLAGS := $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register) 707*4882a593Smuzhiyunendif 708*4882a593Smuzhiyunifdef CONFIG_CC_IS_CLANG 709*4882a593SmuzhiyunRETPOLINE_CFLAGS := -mretpoline-external-thunk 710*4882a593SmuzhiyunRETPOLINE_VDSO_CFLAGS := -mretpoline 711*4882a593Smuzhiyunendif 712*4882a593Smuzhiyun 713*4882a593Smuzhiyunifdef CONFIG_RETHUNK 714*4882a593SmuzhiyunRETHUNK_CFLAGS := -mfunction-return=thunk-extern 715*4882a593SmuzhiyunRETPOLINE_CFLAGS += $(RETHUNK_CFLAGS) 716*4882a593Smuzhiyunendif 717*4882a593Smuzhiyun 718*4882a593Smuzhiyunexport RETPOLINE_CFLAGS 719*4882a593Smuzhiyunexport RETPOLINE_VDSO_CFLAGS 720*4882a593Smuzhiyun 721*4882a593Smuzhiyuninclude arch/$(SRCARCH)/Makefile 722*4882a593Smuzhiyun 723*4882a593Smuzhiyunifdef need-config 724*4882a593Smuzhiyunifdef may-sync-config 725*4882a593Smuzhiyun# Read in dependencies to all Kconfig* files, make sure to run syncconfig if 726*4882a593Smuzhiyun# changes are detected. This should be included after arch/$(SRCARCH)/Makefile 727*4882a593Smuzhiyun# because some architectures define CROSS_COMPILE there. 728*4882a593Smuzhiyuninclude include/config/auto.conf.cmd 729*4882a593Smuzhiyun 730*4882a593Smuzhiyun$(KCONFIG_CONFIG): 731*4882a593Smuzhiyun @echo >&2 '***' 732*4882a593Smuzhiyun @echo >&2 '*** Configuration file "$@" not found!' 733*4882a593Smuzhiyun @echo >&2 '***' 734*4882a593Smuzhiyun @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or' 735*4882a593Smuzhiyun @echo >&2 '*** "make menuconfig" or "make xconfig").' 736*4882a593Smuzhiyun @echo >&2 '***' 737*4882a593Smuzhiyun @/bin/false 738*4882a593Smuzhiyun 739*4882a593Smuzhiyun# The actual configuration files used during the build are stored in 740*4882a593Smuzhiyun# include/generated/ and include/config/. Update them if .config is newer than 741*4882a593Smuzhiyun# include/config/auto.conf (which mirrors .config). 742*4882a593Smuzhiyun# 743*4882a593Smuzhiyun# This exploits the 'multi-target pattern rule' trick. 744*4882a593Smuzhiyun# The syncconfig should be executed only once to make all the targets. 745*4882a593Smuzhiyun# (Note: use the grouped target '&:' when we bump to GNU Make 4.3) 746*4882a593Smuzhiyun# 747*4882a593Smuzhiyun# Do not use $(call cmd,...) here. That would suppress prompts from syncconfig, 748*4882a593Smuzhiyun# so you cannot notice that Kconfig is waiting for the user input. 749*4882a593Smuzhiyun%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h: $(KCONFIG_CONFIG) 750*4882a593Smuzhiyun $(Q)$(kecho) " SYNC $@" 751*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig 752*4882a593Smuzhiyunelse # !may-sync-config 753*4882a593Smuzhiyun# External modules and some install targets need include/generated/autoconf.h 754*4882a593Smuzhiyun# and include/config/auto.conf but do not care if they are up-to-date. 755*4882a593Smuzhiyun# Use auto.conf to trigger the test 756*4882a593SmuzhiyunPHONY += include/config/auto.conf 757*4882a593Smuzhiyun 758*4882a593Smuzhiyuninclude/config/auto.conf: 759*4882a593Smuzhiyun $(Q)test -e include/generated/autoconf.h -a -e $@ || ( \ 760*4882a593Smuzhiyun echo >&2; \ 761*4882a593Smuzhiyun echo >&2 " ERROR: Kernel configuration is invalid."; \ 762*4882a593Smuzhiyun echo >&2 " include/generated/autoconf.h or $@ are missing.";\ 763*4882a593Smuzhiyun echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \ 764*4882a593Smuzhiyun echo >&2 ; \ 765*4882a593Smuzhiyun /bin/false) 766*4882a593Smuzhiyun 767*4882a593Smuzhiyunendif # may-sync-config 768*4882a593Smuzhiyunendif # need-config 769*4882a593Smuzhiyun 770*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) 771*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) 772*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) 773*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) 774*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) 775*4882a593Smuzhiyun 776*4882a593Smuzhiyunifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE 777*4882a593SmuzhiyunKBUILD_CFLAGS += -O2 778*4882a593Smuzhiyunelse ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 779*4882a593SmuzhiyunKBUILD_CFLAGS += -O3 780*4882a593Smuzhiyunelse ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE 781*4882a593SmuzhiyunKBUILD_CFLAGS += -Os 782*4882a593Smuzhiyunendif 783*4882a593Smuzhiyun 784*4882a593Smuzhiyun# Tell gcc to never replace conditional load with a non-conditional one 785*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) 786*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) 787*4882a593Smuzhiyun 788*4882a593Smuzhiyunifdef CONFIG_READABLE_ASM 789*4882a593Smuzhiyun# Disable optimizations that make assembler listings hard to read. 790*4882a593Smuzhiyun# reorder blocks reorders the control in the function 791*4882a593Smuzhiyun# ipa clone creates specialized cloned functions 792*4882a593Smuzhiyun# partial inlining inlines only parts of functions 793*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \ 794*4882a593Smuzhiyun $(call cc-option,-fno-ipa-cp-clone,) \ 795*4882a593Smuzhiyun $(call cc-option,-fno-partial-inlining) 796*4882a593Smuzhiyunendif 797*4882a593Smuzhiyun 798*4882a593Smuzhiyunifneq ($(CONFIG_FRAME_WARN),0) 799*4882a593SmuzhiyunKBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) 800*4882a593Smuzhiyunendif 801*4882a593Smuzhiyun 802*4882a593Smuzhiyunstackp-flags-y := -fno-stack-protector 803*4882a593Smuzhiyunstackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector 804*4882a593Smuzhiyunstackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong 805*4882a593Smuzhiyun 806*4882a593SmuzhiyunKBUILD_CFLAGS += $(stackp-flags-y) 807*4882a593Smuzhiyun 808*4882a593SmuzhiyunKBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror 809*4882a593SmuzhiyunKBUILD_CFLAGS += $(KBUILD_CFLAGS-y) 810*4882a593Smuzhiyun 811*4882a593Smuzhiyunifdef CONFIG_CC_IS_CLANG 812*4882a593SmuzhiyunKBUILD_CPPFLAGS += -Qunused-arguments 813*4882a593SmuzhiyunKBUILD_CFLAGS += -Wno-format-invalid-specifier 814*4882a593SmuzhiyunKBUILD_CFLAGS += -Wno-gnu 815*4882a593Smuzhiyun# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the 816*4882a593Smuzhiyun# source of a reference will be _MergedGlobals and not on of the whitelisted names. 817*4882a593Smuzhiyun# See modpost pattern 2 818*4882a593SmuzhiyunKBUILD_CFLAGS += -mno-global-merge 819*4882a593Smuzhiyunelse 820*4882a593Smuzhiyun 821*4882a593Smuzhiyun# Warn about unmarked fall-throughs in switch statement. 822*4882a593Smuzhiyun# Disabled for clang while comment to attribute conversion happens and 823*4882a593Smuzhiyun# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed. 824*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough,) 825*4882a593Smuzhiyunendif 826*4882a593Smuzhiyun 827*4882a593Smuzhiyun# These warnings generated too much noise in a regular build. 828*4882a593Smuzhiyun# Use make W=1 to enable them (see scripts/Makefile.extrawarn) 829*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) 830*4882a593Smuzhiyun 831*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) 832*4882a593Smuzhiyunifdef CONFIG_FRAME_POINTER 833*4882a593SmuzhiyunKBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls 834*4882a593Smuzhiyunelse 835*4882a593Smuzhiyun# Some targets (ARM with Thumb2, for example), can't be built with frame 836*4882a593Smuzhiyun# pointers. For those, we don't have FUNCTION_TRACER automatically 837*4882a593Smuzhiyun# select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is 838*4882a593Smuzhiyun# incompatible with -fomit-frame-pointer with current GCC, so we don't use 839*4882a593Smuzhiyun# -fomit-frame-pointer with FUNCTION_TRACER. 840*4882a593Smuzhiyunifndef CONFIG_FUNCTION_TRACER 841*4882a593SmuzhiyunKBUILD_CFLAGS += -fomit-frame-pointer 842*4882a593Smuzhiyunendif 843*4882a593Smuzhiyunendif 844*4882a593Smuzhiyun 845*4882a593Smuzhiyun# Initialize all stack variables with a 0xAA pattern. 846*4882a593Smuzhiyunifdef CONFIG_INIT_STACK_ALL_PATTERN 847*4882a593SmuzhiyunKBUILD_CFLAGS += -ftrivial-auto-var-init=pattern 848*4882a593Smuzhiyunendif 849*4882a593Smuzhiyun 850*4882a593Smuzhiyun# Initialize all stack variables with a zero value. 851*4882a593Smuzhiyunifdef CONFIG_INIT_STACK_ALL_ZERO 852*4882a593SmuzhiyunKBUILD_CFLAGS += -ftrivial-auto-var-init=zero 853*4882a593Smuzhiyunifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER 854*4882a593Smuzhiyun# https://github.com/llvm/llvm-project/issues/44842 855*4882a593SmuzhiyunKBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang 856*4882a593Smuzhiyunendif 857*4882a593Smuzhiyunendif 858*4882a593Smuzhiyun 859*4882a593SmuzhiyunDEBUG_CFLAGS := 860*4882a593Smuzhiyun 861*4882a593Smuzhiyun# Workaround for GCC versions < 5.0 862*4882a593Smuzhiyun# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 863*4882a593Smuzhiyunifdef CONFIG_CC_IS_GCC 864*4882a593SmuzhiyunDEBUG_CFLAGS += $(call cc-ifversion, -lt, 0500, $(call cc-option, -fno-var-tracking-assignments)) 865*4882a593Smuzhiyunendif 866*4882a593Smuzhiyun 867*4882a593Smuzhiyunifdef CONFIG_DEBUG_INFO 868*4882a593Smuzhiyun 869*4882a593Smuzhiyunifdef CONFIG_DEBUG_INFO_SPLIT 870*4882a593SmuzhiyunDEBUG_CFLAGS += -gsplit-dwarf 871*4882a593Smuzhiyunelse 872*4882a593SmuzhiyunDEBUG_CFLAGS += -g 873*4882a593Smuzhiyunendif 874*4882a593Smuzhiyun 875*4882a593Smuzhiyunifeq ($(LLVM_IAS),1) 876*4882a593SmuzhiyunKBUILD_AFLAGS += -g 877*4882a593Smuzhiyunelse 878*4882a593SmuzhiyunKBUILD_AFLAGS += -Wa,-gdwarf-2 879*4882a593Smuzhiyunendif 880*4882a593Smuzhiyun 881*4882a593Smuzhiyunifdef CONFIG_DEBUG_INFO_DWARF4 882*4882a593SmuzhiyunDEBUG_CFLAGS += -gdwarf-4 883*4882a593Smuzhiyunendif 884*4882a593Smuzhiyun 885*4882a593Smuzhiyunifdef CONFIG_DEBUG_INFO_REDUCED 886*4882a593SmuzhiyunDEBUG_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \ 887*4882a593Smuzhiyun $(call cc-option,-fno-var-tracking) 888*4882a593Smuzhiyunendif 889*4882a593Smuzhiyun 890*4882a593Smuzhiyunifdef CONFIG_DEBUG_INFO_COMPRESSED 891*4882a593SmuzhiyunDEBUG_CFLAGS += -gz=zlib 892*4882a593SmuzhiyunKBUILD_AFLAGS += -gz=zlib 893*4882a593SmuzhiyunKBUILD_LDFLAGS += --compress-debug-sections=zlib 894*4882a593Smuzhiyunendif 895*4882a593Smuzhiyun 896*4882a593Smuzhiyunendif # CONFIG_DEBUG_INFO 897*4882a593Smuzhiyun 898*4882a593SmuzhiyunKBUILD_CFLAGS += $(DEBUG_CFLAGS) 899*4882a593Smuzhiyunexport DEBUG_CFLAGS 900*4882a593Smuzhiyun 901*4882a593Smuzhiyunifdef CONFIG_FUNCTION_TRACER 902*4882a593Smuzhiyunifdef CONFIG_FTRACE_MCOUNT_USE_CC 903*4882a593Smuzhiyun CC_FLAGS_FTRACE += -mrecord-mcount 904*4882a593Smuzhiyun ifdef CONFIG_HAVE_NOP_MCOUNT 905*4882a593Smuzhiyun ifeq ($(call cc-option-yn, -mnop-mcount),y) 906*4882a593Smuzhiyun CC_FLAGS_FTRACE += -mnop-mcount 907*4882a593Smuzhiyun CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT 908*4882a593Smuzhiyun endif 909*4882a593Smuzhiyun endif 910*4882a593Smuzhiyunendif 911*4882a593Smuzhiyunifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL 912*4882a593Smuzhiyun CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT 913*4882a593Smuzhiyunendif 914*4882a593Smuzhiyunifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT 915*4882a593Smuzhiyun ifdef CONFIG_HAVE_C_RECORDMCOUNT 916*4882a593Smuzhiyun BUILD_C_RECORDMCOUNT := y 917*4882a593Smuzhiyun export BUILD_C_RECORDMCOUNT 918*4882a593Smuzhiyun endif 919*4882a593Smuzhiyunendif 920*4882a593Smuzhiyunifdef CONFIG_HAVE_FENTRY 921*4882a593Smuzhiyun ifeq ($(call cc-option-yn, -mfentry),y) 922*4882a593Smuzhiyun CC_FLAGS_FTRACE += -mfentry 923*4882a593Smuzhiyun CC_FLAGS_USING += -DCC_USING_FENTRY 924*4882a593Smuzhiyun endif 925*4882a593Smuzhiyunendif 926*4882a593Smuzhiyunexport CC_FLAGS_FTRACE 927*4882a593SmuzhiyunKBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING) 928*4882a593SmuzhiyunKBUILD_AFLAGS += $(CC_FLAGS_USING) 929*4882a593Smuzhiyunendif 930*4882a593Smuzhiyun 931*4882a593Smuzhiyun# We trigger additional mismatches with less inlining 932*4882a593Smuzhiyunifdef CONFIG_DEBUG_SECTION_MISMATCH 933*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once) 934*4882a593Smuzhiyunendif 935*4882a593Smuzhiyun 936*4882a593Smuzhiyunifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION 937*4882a593SmuzhiyunKBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections 938*4882a593SmuzhiyunLDFLAGS_vmlinux += --gc-sections 939*4882a593Smuzhiyunendif 940*4882a593Smuzhiyun 941*4882a593Smuzhiyunifdef CONFIG_SHADOW_CALL_STACK 942*4882a593SmuzhiyunCC_FLAGS_SCS := -fsanitize=shadow-call-stack 943*4882a593SmuzhiyunKBUILD_CFLAGS += $(CC_FLAGS_SCS) 944*4882a593Smuzhiyunexport CC_FLAGS_SCS 945*4882a593Smuzhiyunendif 946*4882a593Smuzhiyun 947*4882a593Smuzhiyunifdef CONFIG_LTO_CLANG 948*4882a593Smuzhiyunifdef CONFIG_LTO_CLANG_THIN 949*4882a593SmuzhiyunCC_FLAGS_LTO := -flto=thin -fsplit-lto-unit 950*4882a593SmuzhiyunKBUILD_LDFLAGS += --thinlto-cache-dir=$(extmod-prefix).thinlto-cache 951*4882a593Smuzhiyunelse 952*4882a593SmuzhiyunCC_FLAGS_LTO := -flto 953*4882a593Smuzhiyunendif 954*4882a593Smuzhiyun 955*4882a593Smuzhiyunifeq ($(SRCARCH),x86) 956*4882a593Smuzhiyun# TODO(b/182572011): Revert workaround for compiler / linker bug. 957*4882a593SmuzhiyunCC_FLAGS_LTO += -fvisibility=hidden 958*4882a593Smuzhiyunelse 959*4882a593SmuzhiyunCC_FLAGS_LTO += -fvisibility=default 960*4882a593Smuzhiyunendif 961*4882a593Smuzhiyun 962*4882a593Smuzhiyun# Limit inlining across translation units to reduce binary size 963*4882a593SmuzhiyunKBUILD_LDFLAGS += -mllvm -import-instr-limit=5 964*4882a593Smuzhiyunendif 965*4882a593Smuzhiyun 966*4882a593Smuzhiyunifdef CONFIG_LTO 967*4882a593SmuzhiyunKBUILD_CFLAGS += $(CC_FLAGS_LTO) 968*4882a593Smuzhiyunexport CC_FLAGS_LTO 969*4882a593Smuzhiyunendif 970*4882a593Smuzhiyun 971*4882a593Smuzhiyunifdef CONFIG_CFI_CLANG 972*4882a593SmuzhiyunCC_FLAGS_CFI := -fsanitize=cfi \ 973*4882a593Smuzhiyun -fsanitize-cfi-cross-dso \ 974*4882a593Smuzhiyun -fno-sanitize-cfi-canonical-jump-tables \ 975*4882a593Smuzhiyun -fno-sanitize-blacklist 976*4882a593Smuzhiyun 977*4882a593Smuzhiyunifdef CONFIG_CFI_PERMISSIVE 978*4882a593SmuzhiyunCC_FLAGS_CFI += -fsanitize-recover=cfi \ 979*4882a593Smuzhiyun -fno-sanitize-trap=cfi 980*4882a593Smuzhiyunelse 981*4882a593Smuzhiyunifndef CONFIG_UBSAN_TRAP 982*4882a593SmuzhiyunCC_FLAGS_CFI += -ftrap-function=__ubsan_handle_cfi_check_fail_abort 983*4882a593Smuzhiyunendif 984*4882a593Smuzhiyunendif 985*4882a593Smuzhiyun 986*4882a593Smuzhiyun# If LTO flags are filtered out, we must also filter out CFI. 987*4882a593SmuzhiyunCC_FLAGS_LTO += $(CC_FLAGS_CFI) 988*4882a593SmuzhiyunKBUILD_CFLAGS += $(CC_FLAGS_CFI) 989*4882a593Smuzhiyunexport CC_FLAGS_CFI 990*4882a593Smuzhiyunendif 991*4882a593Smuzhiyun 992*4882a593Smuzhiyunifdef CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_32B 993*4882a593SmuzhiyunKBUILD_CFLAGS += -falign-functions=32 994*4882a593Smuzhiyunendif 995*4882a593Smuzhiyun 996*4882a593Smuzhiyun# arch Makefile may override CC so keep this after arch Makefile is included 997*4882a593SmuzhiyunNOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) 998*4882a593Smuzhiyun 999*4882a593Smuzhiyun# warn about C99 declaration after statement 1000*4882a593SmuzhiyunKBUILD_CFLAGS += -Wdeclaration-after-statement 1001*4882a593Smuzhiyun 1002*4882a593Smuzhiyun# Variable Length Arrays (VLAs) should not be used anywhere in the kernel 1003*4882a593SmuzhiyunKBUILD_CFLAGS += -Wvla 1004*4882a593Smuzhiyun 1005*4882a593Smuzhiyun# disable pointer signed / unsigned warnings in gcc 4.0 1006*4882a593SmuzhiyunKBUILD_CFLAGS += -Wno-pointer-sign 1007*4882a593Smuzhiyun 1008*4882a593Smuzhiyun# disable stringop warnings in gcc 8+ 1009*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) 1010*4882a593Smuzhiyun 1011*4882a593Smuzhiyun# We'll want to enable this eventually, but it's not going away for 5.7 at least 1012*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, zero-length-bounds) 1013*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, array-bounds) 1014*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) 1015*4882a593Smuzhiyun 1016*4882a593Smuzhiyun# Another good warning that we'll want to enable eventually 1017*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, restrict) 1018*4882a593Smuzhiyun 1019*4882a593Smuzhiyun# Enabled with W=2, disabled by default as noisy 1020*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized) 1021*4882a593Smuzhiyun 1022*4882a593Smuzhiyun# disable invalid "can't wrap" optimizations for signed / pointers 1023*4882a593SmuzhiyunKBUILD_CFLAGS += -fno-strict-overflow 1024*4882a593Smuzhiyun 1025*4882a593Smuzhiyun# Make sure -fstack-check isn't enabled (like gentoo apparently did) 1026*4882a593SmuzhiyunKBUILD_CFLAGS += -fno-stack-check 1027*4882a593Smuzhiyun 1028*4882a593Smuzhiyun# conserve stack if available 1029*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,-fconserve-stack) 1030*4882a593Smuzhiyun 1031*4882a593Smuzhiyun# Prohibit date/time macros, which would make the build non-deterministic 1032*4882a593SmuzhiyunKBUILD_CFLAGS += -Werror=date-time 1033*4882a593Smuzhiyun 1034*4882a593Smuzhiyun# enforce correct pointer usage 1035*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types) 1036*4882a593Smuzhiyun 1037*4882a593Smuzhiyun# Require designated initializers for all marked structures 1038*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) 1039*4882a593Smuzhiyun 1040*4882a593Smuzhiyun# change __FILE__ to the relative path from the srctree 1041*4882a593SmuzhiyunKBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) 1042*4882a593Smuzhiyun 1043*4882a593Smuzhiyun# include additional Makefiles when needed 1044*4882a593Smuzhiyuninclude-y := scripts/Makefile.extrawarn 1045*4882a593Smuzhiyuninclude-$(CONFIG_KASAN) += scripts/Makefile.kasan 1046*4882a593Smuzhiyuninclude-$(CONFIG_KCSAN) += scripts/Makefile.kcsan 1047*4882a593Smuzhiyuninclude-$(CONFIG_UBSAN) += scripts/Makefile.ubsan 1048*4882a593Smuzhiyuninclude-$(CONFIG_KCOV) += scripts/Makefile.kcov 1049*4882a593Smuzhiyuninclude-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins 1050*4882a593Smuzhiyun 1051*4882a593Smuzhiyuninclude $(addprefix $(srctree)/, $(include-y)) 1052*4882a593Smuzhiyun 1053*4882a593Smuzhiyun# scripts/Makefile.gcc-plugins is intentionally included last. 1054*4882a593Smuzhiyun# Do not add $(call cc-option,...) below this line. When you build the kernel 1055*4882a593Smuzhiyun# from the clean source tree, the GCC plugins do not exist at this point. 1056*4882a593Smuzhiyun 1057*4882a593Smuzhiyun# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments 1058*4882a593SmuzhiyunKBUILD_CPPFLAGS += $(KCPPFLAGS) 1059*4882a593SmuzhiyunKBUILD_AFLAGS += $(KAFLAGS) 1060*4882a593SmuzhiyunKBUILD_CFLAGS += $(KCFLAGS) 1061*4882a593Smuzhiyun 1062*4882a593SmuzhiyunKBUILD_LDFLAGS_MODULE += --build-id=sha1 1063*4882a593SmuzhiyunLDFLAGS_vmlinux += --build-id=sha1 1064*4882a593Smuzhiyun 1065*4882a593SmuzhiyunKBUILD_LDFLAGS += -z noexecstack 1066*4882a593SmuzhiyunKBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments) 1067*4882a593Smuzhiyun 1068*4882a593Smuzhiyunifeq ($(CONFIG_STRIP_ASM_SYMS),y) 1069*4882a593SmuzhiyunLDFLAGS_vmlinux += $(call ld-option, -X,) 1070*4882a593Smuzhiyunendif 1071*4882a593Smuzhiyun 1072*4882a593Smuzhiyunifeq ($(CONFIG_RELR),y) 1073*4882a593SmuzhiyunLDFLAGS_vmlinux += --pack-dyn-relocs=relr --use-android-relr-tags 1074*4882a593Smuzhiyunendif 1075*4882a593Smuzhiyun 1076*4882a593Smuzhiyun# We never want expected sections to be placed heuristically by the 1077*4882a593Smuzhiyun# linker. All sections should be explicitly named in the linker script. 1078*4882a593Smuzhiyunifdef CONFIG_LD_ORPHAN_WARN 1079*4882a593SmuzhiyunLDFLAGS_vmlinux += --orphan-handling=warn 1080*4882a593Smuzhiyunendif 1081*4882a593Smuzhiyun 1082*4882a593Smuzhiyun# Align the bit size of userspace programs with the kernel 1083*4882a593SmuzhiyunKBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) 1084*4882a593SmuzhiyunKBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) 1085*4882a593Smuzhiyun 1086*4882a593Smuzhiyun# make the checker run with the right architecture 1087*4882a593SmuzhiyunCHECKFLAGS += --arch=$(ARCH) 1088*4882a593Smuzhiyun 1089*4882a593Smuzhiyun# insure the checker run with the right endianness 1090*4882a593SmuzhiyunCHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian) 1091*4882a593Smuzhiyun 1092*4882a593Smuzhiyun# the checker needs the correct machine size 1093*4882a593SmuzhiyunCHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32) 1094*4882a593Smuzhiyun 1095*4882a593Smuzhiyun# Default kernel image to build when no specific target is given. 1096*4882a593Smuzhiyun# KBUILD_IMAGE may be overruled on the command line or 1097*4882a593Smuzhiyun# set in the environment 1098*4882a593Smuzhiyun# Also any assignments in arch/$(ARCH)/Makefile take precedence over 1099*4882a593Smuzhiyun# this default value 1100*4882a593Smuzhiyunexport KBUILD_IMAGE ?= vmlinux 1101*4882a593Smuzhiyun 1102*4882a593Smuzhiyun# 1103*4882a593Smuzhiyun# INSTALL_PATH specifies where to place the updated kernel and system map 1104*4882a593Smuzhiyun# images. Default is /boot, but you can set it to other values 1105*4882a593Smuzhiyunexport INSTALL_PATH ?= /boot 1106*4882a593Smuzhiyun 1107*4882a593Smuzhiyun# 1108*4882a593Smuzhiyun# INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots. 1109*4882a593Smuzhiyun# Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as 1110*4882a593Smuzhiyun# an argument if needed. Otherwise it defaults to the kernel install path 1111*4882a593Smuzhiyun# 1112*4882a593Smuzhiyunexport INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE) 1113*4882a593Smuzhiyun 1114*4882a593Smuzhiyun# 1115*4882a593Smuzhiyun# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory 1116*4882a593Smuzhiyun# relocations required by build roots. This is not defined in the 1117*4882a593Smuzhiyun# makefile but the argument can be passed to make if needed. 1118*4882a593Smuzhiyun# 1119*4882a593Smuzhiyun 1120*4882a593SmuzhiyunMODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) 1121*4882a593Smuzhiyunexport MODLIB 1122*4882a593Smuzhiyun 1123*4882a593Smuzhiyun# 1124*4882a593Smuzhiyun# INSTALL_MOD_STRIP, if defined, will cause modules to be 1125*4882a593Smuzhiyun# stripped after they are installed. If INSTALL_MOD_STRIP is '1', then 1126*4882a593Smuzhiyun# the default option --strip-debug will be used. Otherwise, 1127*4882a593Smuzhiyun# INSTALL_MOD_STRIP value will be used as the options to the strip command. 1128*4882a593Smuzhiyun 1129*4882a593Smuzhiyunifdef INSTALL_MOD_STRIP 1130*4882a593Smuzhiyunifeq ($(INSTALL_MOD_STRIP),1) 1131*4882a593Smuzhiyunmod_strip_cmd = $(STRIP) --strip-debug 1132*4882a593Smuzhiyunelse 1133*4882a593Smuzhiyunmod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP) 1134*4882a593Smuzhiyunendif # INSTALL_MOD_STRIP=1 1135*4882a593Smuzhiyunelse 1136*4882a593Smuzhiyunmod_strip_cmd = true 1137*4882a593Smuzhiyunendif # INSTALL_MOD_STRIP 1138*4882a593Smuzhiyunexport mod_strip_cmd 1139*4882a593Smuzhiyun 1140*4882a593Smuzhiyun# CONFIG_MODULE_COMPRESS, if defined, will cause module to be compressed 1141*4882a593Smuzhiyun# after they are installed in agreement with CONFIG_MODULE_COMPRESS_GZIP 1142*4882a593Smuzhiyun# or CONFIG_MODULE_COMPRESS_XZ. 1143*4882a593Smuzhiyun 1144*4882a593Smuzhiyunmod_compress_cmd = true 1145*4882a593Smuzhiyunifdef CONFIG_MODULE_COMPRESS 1146*4882a593Smuzhiyun ifdef CONFIG_MODULE_COMPRESS_GZIP 1147*4882a593Smuzhiyun mod_compress_cmd = $(KGZIP) -n -f 1148*4882a593Smuzhiyun endif # CONFIG_MODULE_COMPRESS_GZIP 1149*4882a593Smuzhiyun ifdef CONFIG_MODULE_COMPRESS_XZ 1150*4882a593Smuzhiyun mod_compress_cmd = $(XZ) -f 1151*4882a593Smuzhiyun endif # CONFIG_MODULE_COMPRESS_XZ 1152*4882a593Smuzhiyunendif # CONFIG_MODULE_COMPRESS 1153*4882a593Smuzhiyunexport mod_compress_cmd 1154*4882a593Smuzhiyun 1155*4882a593Smuzhiyunifdef CONFIG_MODULE_SIG_ALL 1156*4882a593Smuzhiyun$(eval $(call config_filename,MODULE_SIG_KEY)) 1157*4882a593Smuzhiyun 1158*4882a593Smuzhiyunmod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509 1159*4882a593Smuzhiyunelse 1160*4882a593Smuzhiyunmod_sign_cmd = true 1161*4882a593Smuzhiyunendif 1162*4882a593Smuzhiyunexport mod_sign_cmd 1163*4882a593Smuzhiyun 1164*4882a593SmuzhiyunHOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf) 1165*4882a593Smuzhiyun 1166*4882a593Smuzhiyunhas_libelf := $(call try-run,\ 1167*4882a593Smuzhiyun echo "int main() {}" | \ 1168*4882a593Smuzhiyun $(HOSTCC) $(KBUILD_HOSTCFLAGS) -xc -o /dev/null $(KBUILD_HOSTLDFLAGS) $(HOST_LIBELF_LIBS) -,1,0) 1169*4882a593Smuzhiyun 1170*4882a593Smuzhiyunifdef CONFIG_STACK_VALIDATION 1171*4882a593Smuzhiyun ifeq ($(has_libelf),1) 1172*4882a593Smuzhiyun objtool_target := tools/objtool FORCE 1173*4882a593Smuzhiyun else 1174*4882a593Smuzhiyun SKIP_STACK_VALIDATION := 1 1175*4882a593Smuzhiyun export SKIP_STACK_VALIDATION 1176*4882a593Smuzhiyun endif 1177*4882a593Smuzhiyunendif 1178*4882a593Smuzhiyun 1179*4882a593SmuzhiyunPHONY += resolve_btfids_clean 1180*4882a593Smuzhiyun 1181*4882a593Smuzhiyunresolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids 1182*4882a593Smuzhiyun 1183*4882a593Smuzhiyun# tools/bpf/resolve_btfids directory might not exist 1184*4882a593Smuzhiyun# in output directory, skip its clean in that case 1185*4882a593Smuzhiyunresolve_btfids_clean: 1186*4882a593Smuzhiyunifneq ($(wildcard $(resolve_btfids_O)),) 1187*4882a593Smuzhiyun $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean 1188*4882a593Smuzhiyunendif 1189*4882a593Smuzhiyun 1190*4882a593Smuzhiyunifdef CONFIG_BPF 1191*4882a593Smuzhiyunifdef CONFIG_DEBUG_INFO_BTF 1192*4882a593Smuzhiyun ifeq ($(has_libelf),1) 1193*4882a593Smuzhiyun resolve_btfids_target := tools/bpf/resolve_btfids FORCE 1194*4882a593Smuzhiyun else 1195*4882a593Smuzhiyun ERROR_RESOLVE_BTFIDS := 1 1196*4882a593Smuzhiyun endif 1197*4882a593Smuzhiyunendif # CONFIG_DEBUG_INFO_BTF 1198*4882a593Smuzhiyunendif # CONFIG_BPF 1199*4882a593Smuzhiyun 1200*4882a593SmuzhiyunPHONY += prepare0 1201*4882a593Smuzhiyun 1202*4882a593Smuzhiyunexport MODORDER := $(extmod-prefix)modules.order 1203*4882a593Smuzhiyunexport MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps 1204*4882a593Smuzhiyun 1205*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1206*4882a593Smuzhiyun# Kernel headers 1207*4882a593Smuzhiyun 1208*4882a593SmuzhiyunPHONY += headers 1209*4882a593Smuzhiyun 1210*4882a593Smuzhiyun#Default location for installed headers 1211*4882a593Smuzhiyunifeq ($(KBUILD_EXTMOD),) 1212*4882a593SmuzhiyunPHONY += archheaders archscripts 1213*4882a593Smuzhiyunhdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj 1214*4882a593Smuzhiyunheaders: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts 1215*4882a593Smuzhiyunelse 1216*4882a593Smuzhiyunhdr-prefix = $(KBUILD_EXTMOD)/ 1217*4882a593Smuzhiyunhdr-inst := -f $(srctree)/scripts/Makefile.headersinst dst=$(KBUILD_EXTMOD)/usr/include objtree=$(objtree)/$(KBUILD_EXTMOD) obj 1218*4882a593Smuzhiyunendif 1219*4882a593Smuzhiyun 1220*4882a593Smuzhiyunexport INSTALL_HDR_PATH = $(objtree)/$(hdr-prefix)usr 1221*4882a593Smuzhiyun 1222*4882a593Smuzhiyunquiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include 1223*4882a593Smuzhiyun cmd_headers_install = \ 1224*4882a593Smuzhiyun mkdir -p $(INSTALL_HDR_PATH); \ 1225*4882a593Smuzhiyun rsync -mrl --include='*/' --include='*\.h' --exclude='*' \ 1226*4882a593Smuzhiyun $(hdr-prefix)usr/include $(INSTALL_HDR_PATH); 1227*4882a593Smuzhiyun 1228*4882a593SmuzhiyunPHONY += headers_install 1229*4882a593Smuzhiyunheaders_install: headers 1230*4882a593Smuzhiyun $(call cmd,headers_install) 1231*4882a593Smuzhiyun 1232*4882a593Smuzhiyunheaders: 1233*4882a593Smuzhiyunifeq ($(KBUILD_EXTMOD),) 1234*4882a593Smuzhiyun $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \ 1235*4882a593Smuzhiyun $(error Headers not exportable for the $(SRCARCH) architecture)) 1236*4882a593Smuzhiyunendif 1237*4882a593Smuzhiyun $(Q)$(MAKE) $(hdr-inst)=$(hdr-prefix)include/uapi 1238*4882a593Smuzhiyun $(Q)$(MAKE) $(hdr-inst)=$(hdr-prefix)arch/$(SRCARCH)/include/uapi 1239*4882a593Smuzhiyun 1240*4882a593Smuzhiyunifeq ($(KBUILD_EXTMOD),) 1241*4882a593Smuzhiyuncore-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ io_uring/ 1242*4882a593Smuzhiyun 1243*4882a593Smuzhiyunvmlinux-dirs := $(patsubst %/,%,$(filter %/, \ 1244*4882a593Smuzhiyun $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ 1245*4882a593Smuzhiyun $(libs-y) $(libs-m))) 1246*4882a593Smuzhiyun 1247*4882a593Smuzhiyunvmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \ 1248*4882a593Smuzhiyun $(patsubst %/,%,$(filter %/, $(core-) \ 1249*4882a593Smuzhiyun $(drivers-) $(libs-)))) 1250*4882a593Smuzhiyun 1251*4882a593Smuzhiyunbuild-dirs := $(vmlinux-dirs) 1252*4882a593Smuzhiyunclean-dirs := $(vmlinux-alldirs) 1253*4882a593Smuzhiyun 1254*4882a593Smuzhiyunsubdir-modorder := $(addsuffix /modules.order, $(build-dirs)) 1255*4882a593Smuzhiyun 1256*4882a593Smuzhiyun# Externally visible symbols (used by link-vmlinux.sh) 1257*4882a593SmuzhiyunKBUILD_VMLINUX_OBJS := $(head-y) $(patsubst %/,%/built-in.a, $(core-y)) 1258*4882a593SmuzhiyunKBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y))) 1259*4882a593Smuzhiyunifdef CONFIG_MODULES 1260*4882a593SmuzhiyunKBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) 1261*4882a593SmuzhiyunKBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y)) 1262*4882a593Smuzhiyunelse 1263*4882a593SmuzhiyunKBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y)) 1264*4882a593Smuzhiyunendif 1265*4882a593SmuzhiyunKBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y)) 1266*4882a593Smuzhiyun 1267*4882a593Smuzhiyunexport KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS 1268*4882a593Smuzhiyunexport KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds 1269*4882a593Smuzhiyun# used by scripts/Makefile.package 1270*4882a593Smuzhiyunexport KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) LICENSES arch include scripts tools) 1271*4882a593Smuzhiyun 1272*4882a593Smuzhiyunvmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) 1273*4882a593Smuzhiyun 1274*4882a593Smuzhiyun# Recurse until adjust_autoksyms.sh is satisfied 1275*4882a593SmuzhiyunPHONY += autoksyms_recursive 1276*4882a593Smuzhiyunifdef CONFIG_TRIM_UNUSED_KSYMS 1277*4882a593Smuzhiyun# For the kernel to actually contain only the needed exported symbols, 1278*4882a593Smuzhiyun# we have to build modules as well to determine what those symbols are. 1279*4882a593Smuzhiyun# (this can be evaluated only once include/config/auto.conf has been included) 1280*4882a593SmuzhiyunKBUILD_MODULES := 1 1281*4882a593Smuzhiyun 1282*4882a593Smuzhiyunautoksyms_recursive: descend modules.order 1283*4882a593Smuzhiyun $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \ 1284*4882a593Smuzhiyun "$(MAKE) -f $(srctree)/Makefile autoksyms_recursive" 1285*4882a593Smuzhiyunendif 1286*4882a593Smuzhiyun 1287*4882a593Smuzhiyunautoksyms_h := $(if $(CONFIG_TRIM_UNUSED_KSYMS), include/generated/autoksyms.h) 1288*4882a593Smuzhiyun 1289*4882a593Smuzhiyunquiet_cmd_autoksyms_h = GEN $@ 1290*4882a593Smuzhiyun cmd_autoksyms_h = mkdir -p $(dir $@); \ 1291*4882a593Smuzhiyun $(CONFIG_SHELL) $(srctree)/scripts/gen_autoksyms.sh $@ 1292*4882a593Smuzhiyun 1293*4882a593Smuzhiyun$(autoksyms_h): 1294*4882a593Smuzhiyun $(call cmd,autoksyms_h) 1295*4882a593Smuzhiyun 1296*4882a593SmuzhiyunARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) 1297*4882a593Smuzhiyun 1298*4882a593Smuzhiyun# Final link of vmlinux with optional arch pass after final link 1299*4882a593Smuzhiyuncmd_link-vmlinux = \ 1300*4882a593Smuzhiyun $(CONFIG_SHELL) $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \ 1301*4882a593Smuzhiyun $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 1302*4882a593Smuzhiyun 1303*4882a593Smuzhiyunifndef KBUILD_MIXED_TREE 1304*4882a593Smuzhiyunvmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE 1305*4882a593Smuzhiyun +$(call if_changed,link-vmlinux) 1306*4882a593Smuzhiyunendif 1307*4882a593Smuzhiyun 1308*4882a593Smuzhiyuntargets := vmlinux 1309*4882a593Smuzhiyun 1310*4882a593Smuzhiyun# The actual objects are generated when descending, 1311*4882a593Smuzhiyun# make sure no implicit rule kicks in 1312*4882a593Smuzhiyun$(sort $(vmlinux-deps) $(subdir-modorder)): descend ; 1313*4882a593Smuzhiyun 1314*4882a593Smuzhiyunfilechk_kernel.release = \ 1315*4882a593Smuzhiyun echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion \ 1316*4882a593Smuzhiyun $(srctree) $(BRANCH) $(KMI_GENERATION))" 1317*4882a593Smuzhiyun 1318*4882a593Smuzhiyun# Store (new) KERNELRELEASE string in include/config/kernel.release 1319*4882a593Smuzhiyuninclude/config/kernel.release: FORCE 1320*4882a593Smuzhiyun $(call filechk,kernel.release) 1321*4882a593Smuzhiyun 1322*4882a593Smuzhiyun# Additional helpers built in scripts/ 1323*4882a593Smuzhiyun# Carefully list dependencies so we do not try to build scripts twice 1324*4882a593Smuzhiyun# in parallel 1325*4882a593SmuzhiyunPHONY += scripts 1326*4882a593Smuzhiyunscripts: scripts_basic scripts_dtc 1327*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=$(@) 1328*4882a593Smuzhiyun 1329*4882a593Smuzhiyun# Things we need to do before we recursively start building the kernel 1330*4882a593Smuzhiyun# or the modules are listed in "prepare". 1331*4882a593Smuzhiyun# A multi level approach is used. prepareN is processed before prepareN-1. 1332*4882a593Smuzhiyun# archprepare is used in arch Makefiles and when processed asm symlink, 1333*4882a593Smuzhiyun# version.h and scripts_basic is processed / created. 1334*4882a593Smuzhiyun 1335*4882a593SmuzhiyunPHONY += prepare archprepare 1336*4882a593Smuzhiyun 1337*4882a593Smuzhiyunarchprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ 1338*4882a593Smuzhiyun asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h \ 1339*4882a593Smuzhiyun include/generated/autoconf.h 1340*4882a593Smuzhiyun 1341*4882a593Smuzhiyunprepare0: archprepare 1342*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=scripts/mod 1343*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=. 1344*4882a593Smuzhiyun 1345*4882a593Smuzhiyun# All the preparing.. 1346*4882a593Smuzhiyunprepare: prepare0 prepare-objtool prepare-resolve_btfids 1347*4882a593Smuzhiyun 1348*4882a593Smuzhiyun# Support for using generic headers in asm-generic 1349*4882a593Smuzhiyunasm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj 1350*4882a593Smuzhiyun 1351*4882a593SmuzhiyunPHONY += asm-generic uapi-asm-generic 1352*4882a593Smuzhiyunasm-generic: uapi-asm-generic 1353*4882a593Smuzhiyun $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \ 1354*4882a593Smuzhiyun generic=include/asm-generic 1355*4882a593Smuzhiyunuapi-asm-generic: 1356*4882a593Smuzhiyun $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \ 1357*4882a593Smuzhiyun generic=include/uapi/asm-generic 1358*4882a593Smuzhiyun 1359*4882a593SmuzhiyunPHONY += prepare-objtool prepare-resolve_btfids 1360*4882a593Smuzhiyunprepare-objtool: $(objtool_target) 1361*4882a593Smuzhiyunifeq ($(SKIP_STACK_VALIDATION),1) 1362*4882a593Smuzhiyunifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL 1363*4882a593Smuzhiyun @echo "error: Cannot generate __mcount_loc for CONFIG_DYNAMIC_FTRACE=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2 1364*4882a593Smuzhiyun @false 1365*4882a593Smuzhiyunendif 1366*4882a593Smuzhiyunifdef CONFIG_UNWINDER_ORC 1367*4882a593Smuzhiyun @echo "error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2 1368*4882a593Smuzhiyun @false 1369*4882a593Smuzhiyunelse 1370*4882a593Smuzhiyun @echo "warning: Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2 1371*4882a593Smuzhiyunendif 1372*4882a593Smuzhiyunendif 1373*4882a593Smuzhiyun 1374*4882a593Smuzhiyunprepare-resolve_btfids: $(resolve_btfids_target) 1375*4882a593Smuzhiyunifeq ($(ERROR_RESOLVE_BTFIDS),1) 1376*4882a593Smuzhiyun @echo "error: Cannot resolve BTF IDs for CONFIG_DEBUG_INFO_BTF, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2 1377*4882a593Smuzhiyun @false 1378*4882a593Smuzhiyunendif 1379*4882a593Smuzhiyun# Generate some files 1380*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1381*4882a593Smuzhiyun 1382*4882a593Smuzhiyun# KERNELRELEASE can change from a few different places, meaning version.h 1383*4882a593Smuzhiyun# needs to be updated, so this check is forced on all builds 1384*4882a593Smuzhiyun 1385*4882a593Smuzhiyunuts_len := 64 1386*4882a593Smuzhiyunifneq (,$(BUILD_NUMBER)) 1387*4882a593Smuzhiyun UTS_RELEASE=$(KERNELRELEASE)-ab$(BUILD_NUMBER) 1388*4882a593Smuzhiyunelse 1389*4882a593Smuzhiyun UTS_RELEASE=$(KERNELRELEASE) 1390*4882a593Smuzhiyunendif 1391*4882a593Smuzhiyundefine filechk_utsrelease.h 1392*4882a593Smuzhiyun if [ `echo -n "$(UTS_RELEASE)" | wc -c ` -gt $(uts_len) ]; then \ 1393*4882a593Smuzhiyun echo '"$(UTS_RELEASE)" exceeds $(uts_len) characters' >&2; \ 1394*4882a593Smuzhiyun exit 1; \ 1395*4882a593Smuzhiyun fi; \ 1396*4882a593Smuzhiyun echo \#define UTS_RELEASE \"$(UTS_RELEASE)\" 1397*4882a593Smuzhiyunendef 1398*4882a593Smuzhiyun 1399*4882a593Smuzhiyundefine filechk_version.h 1400*4882a593Smuzhiyun if [ $(SUBLEVEL) -gt 255 ]; then \ 1401*4882a593Smuzhiyun echo \#define LINUX_VERSION_CODE $(shell \ 1402*4882a593Smuzhiyun expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \ 1403*4882a593Smuzhiyun else \ 1404*4882a593Smuzhiyun echo \#define LINUX_VERSION_CODE $(shell \ 1405*4882a593Smuzhiyun expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ 1406*4882a593Smuzhiyun fi; \ 1407*4882a593Smuzhiyun echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ 1408*4882a593Smuzhiyun ((c) > 255 ? 255 : (c)))' 1409*4882a593Smuzhiyunendef 1410*4882a593Smuzhiyun 1411*4882a593Smuzhiyun$(version_h): PATCHLEVEL := $(if $(PATCHLEVEL), $(PATCHLEVEL), 0) 1412*4882a593Smuzhiyun$(version_h): SUBLEVEL := $(if $(SUBLEVEL), $(SUBLEVEL), 0) 1413*4882a593Smuzhiyun$(version_h): FORCE 1414*4882a593Smuzhiyun $(call filechk,version.h) 1415*4882a593Smuzhiyun $(Q)rm -f $(old_version_h) 1416*4882a593Smuzhiyun 1417*4882a593Smuzhiyuninclude/generated/utsrelease.h: include/config/kernel.release FORCE 1418*4882a593Smuzhiyun $(call filechk,utsrelease.h) 1419*4882a593Smuzhiyun 1420*4882a593SmuzhiyunPHONY += headerdep 1421*4882a593Smuzhiyunheaderdep: 1422*4882a593Smuzhiyun $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \ 1423*4882a593Smuzhiyun $(srctree)/scripts/headerdep.pl -I$(srctree)/include 1424*4882a593Smuzhiyun 1425*4882a593Smuzhiyun# Deprecated. It is no-op now. 1426*4882a593SmuzhiyunPHONY += headers_check 1427*4882a593Smuzhiyunheaders_check: 1428*4882a593Smuzhiyun @: 1429*4882a593Smuzhiyun 1430*4882a593Smuzhiyunifdef CONFIG_HEADERS_INSTALL 1431*4882a593Smuzhiyunprepare: headers 1432*4882a593Smuzhiyunendif 1433*4882a593Smuzhiyun 1434*4882a593SmuzhiyunPHONY += scripts_unifdef 1435*4882a593Smuzhiyunscripts_unifdef: scripts_basic 1436*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=scripts scripts/unifdef 1437*4882a593Smuzhiyun 1438*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1439*4882a593Smuzhiyun# Kernel selftest 1440*4882a593Smuzhiyun 1441*4882a593SmuzhiyunPHONY += kselftest 1442*4882a593Smuzhiyunkselftest: 1443*4882a593Smuzhiyun $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests 1444*4882a593Smuzhiyun 1445*4882a593Smuzhiyunkselftest-%: FORCE 1446*4882a593Smuzhiyun $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $* 1447*4882a593Smuzhiyun 1448*4882a593SmuzhiyunPHONY += kselftest-merge 1449*4882a593Smuzhiyunkselftest-merge: 1450*4882a593Smuzhiyun $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!)) 1451*4882a593Smuzhiyun $(Q)find $(srctree)/tools/testing/selftests -name config | \ 1452*4882a593Smuzhiyun xargs $(srctree)/scripts/kconfig/merge_config.sh -m $(objtree)/.config 1453*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig 1454*4882a593Smuzhiyun 1455*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1456*4882a593Smuzhiyun# Devicetree files 1457*4882a593Smuzhiyun 1458*4882a593Smuzhiyunifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),) 1459*4882a593Smuzhiyundtstree := arch/$(SRCARCH)/boot/dts 1460*4882a593Smuzhiyunendif 1461*4882a593Smuzhiyun 1462*4882a593Smuzhiyunifneq ($(dtstree),) 1463*4882a593Smuzhiyun 1464*4882a593Smuzhiyun%.dtb: include/config/kernel.release scripts_dtc 1465*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@ 1466*4882a593Smuzhiyun 1467*4882a593SmuzhiyunPHONY += dtbs dtbs_install dtbs_check 1468*4882a593Smuzhiyundtbs: include/config/kernel.release scripts_dtc 1469*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=$(dtstree) 1470*4882a593Smuzhiyun 1471*4882a593Smuzhiyunifneq ($(filter dtbs_check, $(MAKECMDGOALS)),) 1472*4882a593Smuzhiyunexport CHECK_DTBS=y 1473*4882a593Smuzhiyundtbs: dt_binding_check 1474*4882a593Smuzhiyunendif 1475*4882a593Smuzhiyun 1476*4882a593Smuzhiyundtbs_check: dtbs 1477*4882a593Smuzhiyun 1478*4882a593Smuzhiyundtbs_install: 1479*4882a593Smuzhiyun $(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH) 1480*4882a593Smuzhiyun 1481*4882a593Smuzhiyunifdef CONFIG_OF_EARLY_FLATTREE 1482*4882a593Smuzhiyunall: dtbs 1483*4882a593Smuzhiyunendif 1484*4882a593Smuzhiyun 1485*4882a593Smuzhiyunendif 1486*4882a593Smuzhiyun 1487*4882a593SmuzhiyunPHONY += scripts_dtc 1488*4882a593Smuzhiyunscripts_dtc: scripts_basic 1489*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=scripts/dtc 1490*4882a593Smuzhiyun 1491*4882a593Smuzhiyunifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),) 1492*4882a593Smuzhiyunexport CHECK_DT_BINDING=y 1493*4882a593Smuzhiyunendif 1494*4882a593Smuzhiyun 1495*4882a593SmuzhiyunPHONY += dt_binding_check 1496*4882a593Smuzhiyundt_binding_check: scripts_dtc 1497*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings 1498*4882a593Smuzhiyun 1499*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1500*4882a593Smuzhiyun# Modules 1501*4882a593Smuzhiyun 1502*4882a593Smuzhiyunifdef CONFIG_MODULES 1503*4882a593Smuzhiyun 1504*4882a593Smuzhiyun# By default, build modules as well 1505*4882a593Smuzhiyun 1506*4882a593Smuzhiyunall: modules 1507*4882a593Smuzhiyun 1508*4882a593Smuzhiyun# When we're building modules with modversions, we need to consider 1509*4882a593Smuzhiyun# the built-in objects during the descend as well, in order to 1510*4882a593Smuzhiyun# make sure the checksums are up to date before we record them. 1511*4882a593Smuzhiyunifdef CONFIG_MODVERSIONS 1512*4882a593Smuzhiyun KBUILD_BUILTIN := 1 1513*4882a593Smuzhiyunendif 1514*4882a593Smuzhiyun 1515*4882a593Smuzhiyun# Build modules 1516*4882a593Smuzhiyun# 1517*4882a593Smuzhiyun# A module can be listed more than once in obj-m resulting in 1518*4882a593Smuzhiyun# duplicate lines in modules.order files. Those are removed 1519*4882a593Smuzhiyun# using awk while concatenating to the final file. 1520*4882a593Smuzhiyun 1521*4882a593SmuzhiyunPHONY += modules 1522*4882a593Smuzhiyun# if KBUILD_BUILTIN && !KBUILD_MIXED_TREE, depend on vmlinux 1523*4882a593Smuzhiyunmodules: $(if $(KBUILD_BUILTIN), $(if $(KBUILD_MIXED_TREE),,vmlinux)) 1524*4882a593Smuzhiyunmodules: modules_check modules_prepare 1525*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 1526*4882a593Smuzhiyun 1527*4882a593SmuzhiyunPHONY += modules_check 1528*4882a593Smuzhiyunmodules_check: modules.order 1529*4882a593Smuzhiyun $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< 1530*4882a593Smuzhiyun 1531*4882a593Smuzhiyuncmd_modules_order = $(AWK) '!x[$$0]++' $(real-prereqs) > $@ 1532*4882a593Smuzhiyun 1533*4882a593Smuzhiyunmodules.order: $(subdir-modorder) FORCE 1534*4882a593Smuzhiyun $(call if_changed,modules_order) 1535*4882a593Smuzhiyun 1536*4882a593Smuzhiyuntargets += modules.order 1537*4882a593Smuzhiyun 1538*4882a593Smuzhiyun# Target to prepare building external modules 1539*4882a593SmuzhiyunPHONY += modules_prepare 1540*4882a593Smuzhiyunmodules_prepare: prepare 1541*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=scripts scripts/module.lds 1542*4882a593Smuzhiyun 1543*4882a593Smuzhiyun# Target to install modules 1544*4882a593SmuzhiyunPHONY += modules_install 1545*4882a593Smuzhiyunmodules_install: _modinst_ _modinst_post 1546*4882a593Smuzhiyun 1547*4882a593SmuzhiyunPHONY += _modinst_ 1548*4882a593Smuzhiyun_modinst_: 1549*4882a593Smuzhiyun @rm -rf $(MODLIB)/kernel 1550*4882a593Smuzhiyun @rm -f $(MODLIB)/source 1551*4882a593Smuzhiyun @mkdir -p $(MODLIB)/kernel 1552*4882a593Smuzhiyun @ln -s $(abspath $(srctree)) $(MODLIB)/source 1553*4882a593Smuzhiyun @if [ ! $(objtree) -ef $(MODLIB)/build ]; then \ 1554*4882a593Smuzhiyun rm -f $(MODLIB)/build ; \ 1555*4882a593Smuzhiyun ln -s $(CURDIR) $(MODLIB)/build ; \ 1556*4882a593Smuzhiyun fi 1557*4882a593Smuzhiyun @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order 1558*4882a593Smuzhiyun @cp -f $(mixed-build-prefix)modules.builtin $(MODLIB)/ 1559*4882a593Smuzhiyun @cp -f $(or $(mixed-build-prefix),$(objtree)/)modules.builtin.modinfo $(MODLIB)/ 1560*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst 1561*4882a593Smuzhiyun 1562*4882a593Smuzhiyun# This depmod is only for convenience to give the initial 1563*4882a593Smuzhiyun# boot a modules.dep even before / is mounted read-write. However the 1564*4882a593Smuzhiyun# boot script depmod is the master version. 1565*4882a593SmuzhiyunPHONY += _modinst_post 1566*4882a593Smuzhiyun_modinst_post: _modinst_ 1567*4882a593Smuzhiyun $(call cmd,depmod) 1568*4882a593Smuzhiyun 1569*4882a593Smuzhiyunifeq ($(CONFIG_MODULE_SIG), y) 1570*4882a593SmuzhiyunPHONY += modules_sign 1571*4882a593Smuzhiyunmodules_sign: 1572*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign 1573*4882a593Smuzhiyunendif 1574*4882a593Smuzhiyun 1575*4882a593Smuzhiyunelse # CONFIG_MODULES 1576*4882a593Smuzhiyun 1577*4882a593Smuzhiyun# Modules not configured 1578*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1579*4882a593Smuzhiyun 1580*4882a593SmuzhiyunPHONY += modules modules_install 1581*4882a593Smuzhiyunmodules modules_install: 1582*4882a593Smuzhiyun @echo >&2 1583*4882a593Smuzhiyun @echo >&2 "The present kernel configuration has modules disabled." 1584*4882a593Smuzhiyun @echo >&2 "Type 'make config' and enable loadable module support." 1585*4882a593Smuzhiyun @echo >&2 "Then build a kernel with module support enabled." 1586*4882a593Smuzhiyun @echo >&2 1587*4882a593Smuzhiyun @exit 1 1588*4882a593Smuzhiyun 1589*4882a593Smuzhiyunendif # CONFIG_MODULES 1590*4882a593Smuzhiyun 1591*4882a593Smuzhiyun### 1592*4882a593Smuzhiyun# Cleaning is done on three levels. 1593*4882a593Smuzhiyun# make clean Delete most generated files 1594*4882a593Smuzhiyun# Leave enough to build external modules 1595*4882a593Smuzhiyun# make mrproper Delete the current configuration, and all generated files 1596*4882a593Smuzhiyun# make distclean Remove editor backup files, patch leftover files and the like 1597*4882a593Smuzhiyun 1598*4882a593Smuzhiyun# Directories & files removed with 'make clean' 1599*4882a593SmuzhiyunCLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \ 1600*4882a593Smuzhiyun modules.builtin modules.builtin.modinfo modules.nsdeps \ 1601*4882a593Smuzhiyun compile_commands.json .thinlto-cache 1602*4882a593Smuzhiyun 1603*4882a593Smuzhiyun# Directories & files removed with 'make mrproper' 1604*4882a593SmuzhiyunMRPROPER_FILES += include/config include/generated \ 1605*4882a593Smuzhiyun arch/$(SRCARCH)/include/generated .tmp_objdiff \ 1606*4882a593Smuzhiyun debian snap tar-install \ 1607*4882a593Smuzhiyun .config .config.old .version \ 1608*4882a593Smuzhiyun Module.symvers \ 1609*4882a593Smuzhiyun signing_key.pem signing_key.priv signing_key.x509 \ 1610*4882a593Smuzhiyun x509.genkey extra_certificates signing_key.x509.keyid \ 1611*4882a593Smuzhiyun signing_key.x509.signer vmlinux-gdb.py \ 1612*4882a593Smuzhiyun *.spec 1613*4882a593Smuzhiyun 1614*4882a593Smuzhiyun# Directories & files removed with 'make distclean' 1615*4882a593SmuzhiyunDISTCLEAN_FILES += tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS 1616*4882a593Smuzhiyun 1617*4882a593Smuzhiyun# clean - Delete most, but leave enough to build external modules 1618*4882a593Smuzhiyun# 1619*4882a593Smuzhiyunclean: rm-files := $(CLEAN_FILES) 1620*4882a593Smuzhiyun 1621*4882a593SmuzhiyunPHONY += archclean vmlinuxclean 1622*4882a593Smuzhiyun 1623*4882a593Smuzhiyunvmlinuxclean: 1624*4882a593Smuzhiyun $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean 1625*4882a593Smuzhiyun $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean) 1626*4882a593Smuzhiyun 1627*4882a593Smuzhiyunclean: archclean vmlinuxclean resolve_btfids_clean 1628*4882a593Smuzhiyun 1629*4882a593Smuzhiyun# mrproper - Delete all generated files, including .config 1630*4882a593Smuzhiyun# 1631*4882a593Smuzhiyunmrproper: rm-files := $(wildcard $(MRPROPER_FILES)) 1632*4882a593Smuzhiyunmrproper-dirs := $(addprefix _mrproper_,scripts) 1633*4882a593Smuzhiyun 1634*4882a593SmuzhiyunPHONY += $(mrproper-dirs) mrproper 1635*4882a593Smuzhiyun$(mrproper-dirs): 1636*4882a593Smuzhiyun $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@) 1637*4882a593Smuzhiyun 1638*4882a593Smuzhiyunmrproper: clean $(mrproper-dirs) 1639*4882a593Smuzhiyun $(call cmd,rmfiles) 1640*4882a593Smuzhiyun 1641*4882a593Smuzhiyun# distclean 1642*4882a593Smuzhiyun# 1643*4882a593Smuzhiyundistclean: rm-files := $(wildcard $(DISTCLEAN_FILES)) 1644*4882a593Smuzhiyun 1645*4882a593SmuzhiyunPHONY += distclean 1646*4882a593Smuzhiyun 1647*4882a593Smuzhiyundistclean: mrproper 1648*4882a593Smuzhiyun $(call cmd,rmfiles) 1649*4882a593Smuzhiyun @find $(srctree) $(RCS_FIND_IGNORE) \ 1650*4882a593Smuzhiyun \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ 1651*4882a593Smuzhiyun -o -name '*.bak' -o -name '#*#' -o -name '*%' \ 1652*4882a593Smuzhiyun -o -name 'core' \) \ 1653*4882a593Smuzhiyun -type f -print | xargs rm -f 1654*4882a593Smuzhiyun 1655*4882a593Smuzhiyun 1656*4882a593Smuzhiyun# Packaging of the kernel to various formats 1657*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1658*4882a593Smuzhiyun 1659*4882a593Smuzhiyun%src-pkg: FORCE 1660*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ 1661*4882a593Smuzhiyun%pkg: include/config/kernel.release FORCE 1662*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ 1663*4882a593Smuzhiyun 1664*4882a593Smuzhiyun# Brief documentation of the typical targets used 1665*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1666*4882a593Smuzhiyun 1667*4882a593Smuzhiyunboards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig) 1668*4882a593Smuzhiyunboards := $(sort $(notdir $(boards))) 1669*4882a593Smuzhiyunboard-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig)) 1670*4882a593Smuzhiyunboard-dirs := $(sort $(notdir $(board-dirs:/=))) 1671*4882a593Smuzhiyun 1672*4882a593SmuzhiyunPHONY += help 1673*4882a593Smuzhiyunhelp: 1674*4882a593Smuzhiyun @echo 'Cleaning targets:' 1675*4882a593Smuzhiyun @echo ' clean - Remove most generated files but keep the config and' 1676*4882a593Smuzhiyun @echo ' enough build support to build external modules' 1677*4882a593Smuzhiyun @echo ' mrproper - Remove all generated files + config + various backup files' 1678*4882a593Smuzhiyun @echo ' distclean - mrproper + remove editor backup and patch files' 1679*4882a593Smuzhiyun @echo '' 1680*4882a593Smuzhiyun @echo 'Configuration targets:' 1681*4882a593Smuzhiyun @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help 1682*4882a593Smuzhiyun @echo '' 1683*4882a593Smuzhiyun @echo 'Other generic targets:' 1684*4882a593Smuzhiyun @echo ' all - Build all targets marked with [*]' 1685*4882a593Smuzhiyun @echo '* vmlinux - Build the bare kernel' 1686*4882a593Smuzhiyun @echo '* modules - Build all modules' 1687*4882a593Smuzhiyun @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)' 1688*4882a593Smuzhiyun @echo ' dir/ - Build all files in dir and below' 1689*4882a593Smuzhiyun @echo ' dir/file.[ois] - Build specified target only' 1690*4882a593Smuzhiyun @echo ' dir/file.ll - Build the LLVM assembly file' 1691*4882a593Smuzhiyun @echo ' (requires compiler support for LLVM assembly generation)' 1692*4882a593Smuzhiyun @echo ' dir/file.lst - Build specified mixed source/assembly target only' 1693*4882a593Smuzhiyun @echo ' (requires a recent binutils and recent build (System.map))' 1694*4882a593Smuzhiyun @echo ' dir/file.ko - Build module including final link' 1695*4882a593Smuzhiyun @echo ' modules_prepare - Set up for building external modules' 1696*4882a593Smuzhiyun @echo ' tags/TAGS - Generate tags file for editors' 1697*4882a593Smuzhiyun @echo ' cscope - Generate cscope index' 1698*4882a593Smuzhiyun @echo ' gtags - Generate GNU GLOBAL index' 1699*4882a593Smuzhiyun @echo ' kernelrelease - Output the release version string (use with make -s)' 1700*4882a593Smuzhiyun @echo ' kernelversion - Output the version stored in Makefile (use with make -s)' 1701*4882a593Smuzhiyun @echo ' image_name - Output the image name (use with make -s)' 1702*4882a593Smuzhiyun @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \ 1703*4882a593Smuzhiyun echo ' (default: $(INSTALL_HDR_PATH))'; \ 1704*4882a593Smuzhiyun echo '' 1705*4882a593Smuzhiyun @echo 'Static analysers:' 1706*4882a593Smuzhiyun @echo ' checkstack - Generate a list of stack hogs' 1707*4882a593Smuzhiyun @echo ' versioncheck - Sanity check on version.h usage' 1708*4882a593Smuzhiyun @echo ' includecheck - Check for duplicate included header files' 1709*4882a593Smuzhiyun @echo ' export_report - List the usages of all exported symbols' 1710*4882a593Smuzhiyun @echo ' headerdep - Detect inclusion cycles in headers' 1711*4882a593Smuzhiyun @echo ' coccicheck - Check with Coccinelle' 1712*4882a593Smuzhiyun @echo ' clang-analyzer - Check with clang static analyzer' 1713*4882a593Smuzhiyun @echo ' clang-tidy - Check with clang-tidy' 1714*4882a593Smuzhiyun @echo '' 1715*4882a593Smuzhiyun @echo 'Tools:' 1716*4882a593Smuzhiyun @echo ' nsdeps - Generate missing symbol namespace dependencies' 1717*4882a593Smuzhiyun @echo '' 1718*4882a593Smuzhiyun @echo 'Kernel selftest:' 1719*4882a593Smuzhiyun @echo ' kselftest - Build and run kernel selftest' 1720*4882a593Smuzhiyun @echo ' Build, install, and boot kernel before' 1721*4882a593Smuzhiyun @echo ' running kselftest on it' 1722*4882a593Smuzhiyun @echo ' Run as root for full coverage' 1723*4882a593Smuzhiyun @echo ' kselftest-all - Build kernel selftest' 1724*4882a593Smuzhiyun @echo ' kselftest-install - Build and install kernel selftest' 1725*4882a593Smuzhiyun @echo ' kselftest-clean - Remove all generated kselftest files' 1726*4882a593Smuzhiyun @echo ' kselftest-merge - Merge all the config dependencies of' 1727*4882a593Smuzhiyun @echo ' kselftest to existing .config.' 1728*4882a593Smuzhiyun @echo '' 1729*4882a593Smuzhiyun @$(if $(dtstree), \ 1730*4882a593Smuzhiyun echo 'Devicetree:'; \ 1731*4882a593Smuzhiyun echo '* dtbs - Build device tree blobs for enabled boards'; \ 1732*4882a593Smuzhiyun echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \ 1733*4882a593Smuzhiyun echo ' dt_binding_check - Validate device tree binding documents'; \ 1734*4882a593Smuzhiyun echo ' dtbs_check - Validate device tree source files';\ 1735*4882a593Smuzhiyun echo '') 1736*4882a593Smuzhiyun 1737*4882a593Smuzhiyun @echo 'Userspace tools targets:' 1738*4882a593Smuzhiyun @echo ' use "make tools/help"' 1739*4882a593Smuzhiyun @echo ' or "cd tools; make help"' 1740*4882a593Smuzhiyun @echo '' 1741*4882a593Smuzhiyun @echo 'Kernel packaging:' 1742*4882a593Smuzhiyun @$(MAKE) -f $(srctree)/scripts/Makefile.package help 1743*4882a593Smuzhiyun @echo '' 1744*4882a593Smuzhiyun @echo 'Documentation targets:' 1745*4882a593Smuzhiyun @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp 1746*4882a593Smuzhiyun @echo '' 1747*4882a593Smuzhiyun @echo 'Architecture specific targets ($(SRCARCH)):' 1748*4882a593Smuzhiyun @$(if $(archhelp),$(archhelp),\ 1749*4882a593Smuzhiyun echo ' No architecture specific help defined for $(SRCARCH)') 1750*4882a593Smuzhiyun @echo '' 1751*4882a593Smuzhiyun @$(if $(boards), \ 1752*4882a593Smuzhiyun $(foreach b, $(boards), \ 1753*4882a593Smuzhiyun printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ 1754*4882a593Smuzhiyun echo '') 1755*4882a593Smuzhiyun @$(if $(board-dirs), \ 1756*4882a593Smuzhiyun $(foreach b, $(board-dirs), \ 1757*4882a593Smuzhiyun printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \ 1758*4882a593Smuzhiyun printf " %-16s - Show all of the above\\n" help-boards; \ 1759*4882a593Smuzhiyun echo '') 1760*4882a593Smuzhiyun 1761*4882a593Smuzhiyun @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' 1762*4882a593Smuzhiyun @echo ' make V=2 [targets] 2 => give reason for rebuild of target' 1763*4882a593Smuzhiyun @echo ' make O=dir [targets] Locate all output files in "dir", including .config' 1764*4882a593Smuzhiyun @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK' 1765*4882a593Smuzhiyun @echo ' (sparse by default)' 1766*4882a593Smuzhiyun @echo ' make C=2 [targets] Force check of all c source with $$CHECK' 1767*4882a593Smuzhiyun @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections' 1768*4882a593Smuzhiyun @echo ' make W=n [targets] Enable extra build checks, n=1,2,3 where' 1769*4882a593Smuzhiyun @echo ' 1: warnings which may be relevant and do not occur too often' 1770*4882a593Smuzhiyun @echo ' 2: warnings which occur quite often but may still be relevant' 1771*4882a593Smuzhiyun @echo ' 3: more obscure warnings, can most likely be ignored' 1772*4882a593Smuzhiyun @echo ' Multiple levels can be combined with W=12 or W=123' 1773*4882a593Smuzhiyun @echo '' 1774*4882a593Smuzhiyun @echo 'Execute "make" or "make all" to build all targets marked with [*] ' 1775*4882a593Smuzhiyun @echo 'For further info see the ./README file' 1776*4882a593Smuzhiyun 1777*4882a593Smuzhiyun 1778*4882a593Smuzhiyunhelp-board-dirs := $(addprefix help-,$(board-dirs)) 1779*4882a593Smuzhiyun 1780*4882a593Smuzhiyunhelp-boards: $(help-board-dirs) 1781*4882a593Smuzhiyun 1782*4882a593Smuzhiyunboards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig))) 1783*4882a593Smuzhiyun 1784*4882a593Smuzhiyun$(help-board-dirs): help-%: 1785*4882a593Smuzhiyun @echo 'Architecture specific targets ($(SRCARCH) $*):' 1786*4882a593Smuzhiyun @$(if $(boards-per-dir), \ 1787*4882a593Smuzhiyun $(foreach b, $(boards-per-dir), \ 1788*4882a593Smuzhiyun printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \ 1789*4882a593Smuzhiyun echo '') 1790*4882a593Smuzhiyun 1791*4882a593Smuzhiyun 1792*4882a593Smuzhiyun# Documentation targets 1793*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1794*4882a593SmuzhiyunDOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ 1795*4882a593Smuzhiyun linkcheckdocs dochelp refcheckdocs 1796*4882a593SmuzhiyunPHONY += $(DOC_TARGETS) 1797*4882a593Smuzhiyun$(DOC_TARGETS): 1798*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=Documentation $@ 1799*4882a593Smuzhiyun 1800*4882a593Smuzhiyun# Misc 1801*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1802*4882a593Smuzhiyun 1803*4882a593SmuzhiyunPHONY += scripts_gdb 1804*4882a593Smuzhiyunscripts_gdb: prepare0 1805*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=scripts/gdb 1806*4882a593Smuzhiyun $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py) 1807*4882a593Smuzhiyun 1808*4882a593Smuzhiyunifdef CONFIG_GDB_SCRIPTS 1809*4882a593Smuzhiyunall: scripts_gdb 1810*4882a593Smuzhiyunendif 1811*4882a593Smuzhiyun 1812*4882a593Smuzhiyunelse # KBUILD_EXTMOD 1813*4882a593Smuzhiyun 1814*4882a593Smuzhiyun### 1815*4882a593Smuzhiyun# External module support. 1816*4882a593Smuzhiyun# When building external modules the kernel used as basis is considered 1817*4882a593Smuzhiyun# read-only, and no consistency checks are made and the make 1818*4882a593Smuzhiyun# system is not used on the basis kernel. If updates are required 1819*4882a593Smuzhiyun# in the basis kernel ordinary make commands (without M=...) must 1820*4882a593Smuzhiyun# be used. 1821*4882a593Smuzhiyun# 1822*4882a593Smuzhiyun# The following are the only valid targets when building external 1823*4882a593Smuzhiyun# modules. 1824*4882a593Smuzhiyun# make M=dir clean Delete all automatically generated files 1825*4882a593Smuzhiyun# make M=dir modules Make all modules in specified dir 1826*4882a593Smuzhiyun# make M=dir Same as 'make M=dir modules' 1827*4882a593Smuzhiyun# make M=dir modules_install 1828*4882a593Smuzhiyun# Install the modules built in the module directory 1829*4882a593Smuzhiyun# Assumes install directory is already created 1830*4882a593Smuzhiyun 1831*4882a593Smuzhiyun# We are always building only modules. 1832*4882a593SmuzhiyunKBUILD_BUILTIN := 1833*4882a593SmuzhiyunKBUILD_MODULES := 1 1834*4882a593Smuzhiyun 1835*4882a593Smuzhiyunbuild-dirs := $(KBUILD_EXTMOD) 1836*4882a593SmuzhiyunPHONY += modules 1837*4882a593Smuzhiyunmodules: $(MODORDER) 1838*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 1839*4882a593Smuzhiyun 1840*4882a593Smuzhiyun$(MODORDER): descend 1841*4882a593Smuzhiyun @: 1842*4882a593Smuzhiyun 1843*4882a593SmuzhiyunPHONY += modules_install 1844*4882a593Smuzhiyunmodules_install: _emodinst_ _emodinst_post 1845*4882a593Smuzhiyun 1846*4882a593Smuzhiyuninstall-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra) 1847*4882a593SmuzhiyunPHONY += _emodinst_ 1848*4882a593Smuzhiyun_emodinst_: 1849*4882a593Smuzhiyun $(Q)mkdir -p $(MODLIB)/$(install-dir) 1850*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst 1851*4882a593Smuzhiyun 1852*4882a593SmuzhiyunPHONY += _emodinst_post 1853*4882a593Smuzhiyun_emodinst_post: _emodinst_ 1854*4882a593Smuzhiyun $(call cmd,depmod) 1855*4882a593Smuzhiyun 1856*4882a593Smuzhiyuncompile_commands.json: $(extmod-prefix)compile_commands.json 1857*4882a593SmuzhiyunPHONY += compile_commands.json 1858*4882a593Smuzhiyun 1859*4882a593Smuzhiyunclean-dirs := $(KBUILD_EXTMOD) 1860*4882a593Smuzhiyunclean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \ 1861*4882a593Smuzhiyun $(KBUILD_EXTMOD)/compile_commands.json $(KBUILD_EXTMOD)/.thinlto-cache 1862*4882a593Smuzhiyun 1863*4882a593SmuzhiyunPHONY += help 1864*4882a593Smuzhiyunhelp: 1865*4882a593Smuzhiyun @echo ' Building external modules.' 1866*4882a593Smuzhiyun @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target' 1867*4882a593Smuzhiyun @echo '' 1868*4882a593Smuzhiyun @echo ' modules - default target, build the module(s)' 1869*4882a593Smuzhiyun @echo ' modules_install - install the module' 1870*4882a593Smuzhiyun @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH' 1871*4882a593Smuzhiyun @echo ' (default: $(abspath $(INSTALL_HDR_PATH)))' 1872*4882a593Smuzhiyun @echo ' clean - remove generated files in module directory only' 1873*4882a593Smuzhiyun @echo '' 1874*4882a593Smuzhiyun 1875*4882a593Smuzhiyun# no-op for external module builds 1876*4882a593SmuzhiyunPHONY += prepare modules_prepare 1877*4882a593Smuzhiyun 1878*4882a593Smuzhiyunendif # KBUILD_EXTMOD 1879*4882a593Smuzhiyun 1880*4882a593Smuzhiyun# Single targets 1881*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1882*4882a593Smuzhiyun# To build individual files in subdirectories, you can do like this: 1883*4882a593Smuzhiyun# 1884*4882a593Smuzhiyun# make foo/bar/baz.s 1885*4882a593Smuzhiyun# 1886*4882a593Smuzhiyun# The supported suffixes for single-target are listed in 'single-targets' 1887*4882a593Smuzhiyun# 1888*4882a593Smuzhiyun# To build only under specific subdirectories, you can do like this: 1889*4882a593Smuzhiyun# 1890*4882a593Smuzhiyun# make foo/bar/baz/ 1891*4882a593Smuzhiyun 1892*4882a593Smuzhiyunifdef single-build 1893*4882a593Smuzhiyun 1894*4882a593Smuzhiyun# .ko is special because modpost is needed 1895*4882a593Smuzhiyunsingle-ko := $(sort $(filter %.ko, $(MAKECMDGOALS))) 1896*4882a593Smuzhiyunsingle-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS))) 1897*4882a593Smuzhiyun 1898*4882a593Smuzhiyun$(single-ko): single_modpost 1899*4882a593Smuzhiyun @: 1900*4882a593Smuzhiyun$(single-no-ko): descend 1901*4882a593Smuzhiyun @: 1902*4882a593Smuzhiyun 1903*4882a593Smuzhiyunifeq ($(KBUILD_EXTMOD),) 1904*4882a593Smuzhiyun# For the single build of in-tree modules, use a temporary file to avoid 1905*4882a593Smuzhiyun# the situation of modules_install installing an invalid modules.order. 1906*4882a593SmuzhiyunMODORDER := .modules.tmp 1907*4882a593Smuzhiyunendif 1908*4882a593Smuzhiyun 1909*4882a593SmuzhiyunPHONY += single_modpost 1910*4882a593Smuzhiyunsingle_modpost: $(single-no-ko) modules_prepare 1911*4882a593Smuzhiyun $(Q){ $(foreach m, $(single-ko), echo $(extmod-prefix)$m;) } > $(MODORDER) 1912*4882a593Smuzhiyun $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 1913*4882a593Smuzhiyun 1914*4882a593SmuzhiyunKBUILD_MODULES := 1 1915*4882a593Smuzhiyun 1916*4882a593Smuzhiyunexport KBUILD_SINGLE_TARGETS := $(addprefix $(extmod-prefix), $(single-no-ko)) 1917*4882a593Smuzhiyun 1918*4882a593Smuzhiyun# trim unrelated directories 1919*4882a593Smuzhiyunbuild-dirs := $(foreach d, $(build-dirs), \ 1920*4882a593Smuzhiyun $(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d))) 1921*4882a593Smuzhiyun 1922*4882a593Smuzhiyunendif 1923*4882a593Smuzhiyun 1924*4882a593Smuzhiyunifndef CONFIG_MODULES 1925*4882a593SmuzhiyunKBUILD_MODULES := 1926*4882a593Smuzhiyunendif 1927*4882a593Smuzhiyun 1928*4882a593Smuzhiyun# Handle descending into subdirectories listed in $(build-dirs) 1929*4882a593Smuzhiyun# Preset locale variables to speed up the build process. Limit locale 1930*4882a593Smuzhiyun# tweaks to this spot to avoid wrong language settings when running 1931*4882a593Smuzhiyun# make menuconfig etc. 1932*4882a593Smuzhiyun# Error messages still appears in the original language 1933*4882a593SmuzhiyunPHONY += descend $(build-dirs) 1934*4882a593Smuzhiyundescend: $(build-dirs) 1935*4882a593Smuzhiyun$(build-dirs): prepare 1936*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=$@ \ 1937*4882a593Smuzhiyun single-build=$(if $(filter-out $@/, $(filter $@/%, $(KBUILD_SINGLE_TARGETS))),1) \ 1938*4882a593Smuzhiyun $(if $(KBUILD_MIXED_TREE),,need-builtin=1) need-modorder=1 1939*4882a593Smuzhiyun 1940*4882a593Smuzhiyunclean-dirs := $(addprefix _clean_, $(clean-dirs)) 1941*4882a593SmuzhiyunPHONY += $(clean-dirs) clean 1942*4882a593Smuzhiyun$(clean-dirs): 1943*4882a593Smuzhiyun $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) 1944*4882a593Smuzhiyun 1945*4882a593Smuzhiyunclean: $(clean-dirs) 1946*4882a593Smuzhiyun $(call cmd,rmfiles) 1947*4882a593Smuzhiyun @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ 1948*4882a593Smuzhiyun \( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \ 1949*4882a593Smuzhiyun -o -name '*.ko.*' \ 1950*4882a593Smuzhiyun -o -name '*.dtb' -o -name '*.dtb.S' -o -name '*.dt.yaml' \ 1951*4882a593Smuzhiyun -o -name '*.dwo' -o -name '*.lst' \ 1952*4882a593Smuzhiyun -o -name '*.su' -o -name '*.mod' \ 1953*4882a593Smuzhiyun -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 1954*4882a593Smuzhiyun -o -name '*.lex.c' -o -name '*.tab.[ch]' \ 1955*4882a593Smuzhiyun -o -name '*.asn1.[ch]' \ 1956*4882a593Smuzhiyun -o -name '*.symtypes' -o -name 'modules.order' \ 1957*4882a593Smuzhiyun -o -name '.tmp_*.o.*' \ 1958*4882a593Smuzhiyun -o -name '*.c.[012]*.*' \ 1959*4882a593Smuzhiyun -o -name '*.ll' \ 1960*4882a593Smuzhiyun -o -name '*.gcno' \ 1961*4882a593Smuzhiyun -o -name '*.*.symversions' \) -type f -print | xargs rm -f 1962*4882a593Smuzhiyun 1963*4882a593Smuzhiyun# Generate tags for editors 1964*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1965*4882a593Smuzhiyunquiet_cmd_tags = GEN $@ 1966*4882a593Smuzhiyun cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@ 1967*4882a593Smuzhiyun 1968*4882a593Smuzhiyuntags TAGS cscope gtags: FORCE 1969*4882a593Smuzhiyun $(call cmd,tags) 1970*4882a593Smuzhiyun 1971*4882a593Smuzhiyun# Script to generate missing namespace dependencies 1972*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1973*4882a593Smuzhiyun 1974*4882a593SmuzhiyunPHONY += nsdeps 1975*4882a593Smuzhiyunnsdeps: export KBUILD_NSDEPS=1 1976*4882a593Smuzhiyunnsdeps: modules 1977*4882a593Smuzhiyun $(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps 1978*4882a593Smuzhiyun 1979*4882a593Smuzhiyun# Clang Tooling 1980*4882a593Smuzhiyun# --------------------------------------------------------------------------- 1981*4882a593Smuzhiyun 1982*4882a593Smuzhiyunquiet_cmd_gen_compile_commands = GEN $@ 1983*4882a593Smuzhiyun cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs)) 1984*4882a593Smuzhiyun 1985*4882a593Smuzhiyun$(extmod-prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \ 1986*4882a593Smuzhiyun $(if $(KBUILD_EXTMOD),,$(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)) \ 1987*4882a593Smuzhiyun $(if $(CONFIG_MODULES), $(MODORDER)) FORCE 1988*4882a593Smuzhiyun $(call if_changed,gen_compile_commands) 1989*4882a593Smuzhiyun 1990*4882a593Smuzhiyuntargets += $(extmod-prefix)compile_commands.json 1991*4882a593Smuzhiyun 1992*4882a593SmuzhiyunPHONY += clang-tidy clang-analyzer 1993*4882a593Smuzhiyun 1994*4882a593Smuzhiyunifdef CONFIG_CC_IS_CLANG 1995*4882a593Smuzhiyunquiet_cmd_clang_tools = CHECK $< 1996*4882a593Smuzhiyun cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $< 1997*4882a593Smuzhiyun 1998*4882a593Smuzhiyunclang-tidy clang-analyzer: $(extmod-prefix)compile_commands.json 1999*4882a593Smuzhiyun $(call cmd,clang_tools) 2000*4882a593Smuzhiyunelse 2001*4882a593Smuzhiyunclang-tidy clang-analyzer: 2002*4882a593Smuzhiyun @echo "$@ requires CC=clang" >&2 2003*4882a593Smuzhiyun @false 2004*4882a593Smuzhiyunendif 2005*4882a593Smuzhiyun 2006*4882a593Smuzhiyun# Scripts to check various things for consistency 2007*4882a593Smuzhiyun# --------------------------------------------------------------------------- 2008*4882a593Smuzhiyun 2009*4882a593SmuzhiyunPHONY += includecheck versioncheck coccicheck export_report 2010*4882a593Smuzhiyun 2011*4882a593Smuzhiyunincludecheck: 2012*4882a593Smuzhiyun find $(srctree)/* $(RCS_FIND_IGNORE) \ 2013*4882a593Smuzhiyun -name '*.[hcS]' -type f -print | sort \ 2014*4882a593Smuzhiyun | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl 2015*4882a593Smuzhiyun 2016*4882a593Smuzhiyunversioncheck: 2017*4882a593Smuzhiyun find $(srctree)/* $(RCS_FIND_IGNORE) \ 2018*4882a593Smuzhiyun -name '*.[hcS]' -type f -print | sort \ 2019*4882a593Smuzhiyun | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl 2020*4882a593Smuzhiyun 2021*4882a593Smuzhiyuncoccicheck: 2022*4882a593Smuzhiyun $(Q)$(BASH) $(srctree)/scripts/$@ 2023*4882a593Smuzhiyun 2024*4882a593Smuzhiyunexport_report: 2025*4882a593Smuzhiyun $(PERL) $(srctree)/scripts/export_report.pl 2026*4882a593Smuzhiyun 2027*4882a593SmuzhiyunPHONY += checkstack kernelrelease kernelversion image_name 2028*4882a593Smuzhiyun 2029*4882a593Smuzhiyun# UML needs a little special treatment here. It wants to use the host 2030*4882a593Smuzhiyun# toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone 2031*4882a593Smuzhiyun# else wants $(ARCH), including people doing cross-builds, which means 2032*4882a593Smuzhiyun# that $(SUBARCH) doesn't work here. 2033*4882a593Smuzhiyunifeq ($(ARCH), um) 2034*4882a593SmuzhiyunCHECKSTACK_ARCH := $(SUBARCH) 2035*4882a593Smuzhiyunelse 2036*4882a593SmuzhiyunCHECKSTACK_ARCH := $(ARCH) 2037*4882a593Smuzhiyunendif 2038*4882a593Smuzhiyuncheckstack: 2039*4882a593Smuzhiyun $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \ 2040*4882a593Smuzhiyun $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) 2041*4882a593Smuzhiyun 2042*4882a593Smuzhiyunkernelrelease: 2043*4882a593Smuzhiyun @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion \ 2044*4882a593Smuzhiyun $(srctree) $(BRANCH) $(KMI_GENERATION))" 2045*4882a593Smuzhiyun 2046*4882a593Smuzhiyunkernelversion: 2047*4882a593Smuzhiyun @echo $(KERNELVERSION) 2048*4882a593Smuzhiyun 2049*4882a593Smuzhiyunimage_name: 2050*4882a593Smuzhiyun @echo $(KBUILD_IMAGE) 2051*4882a593Smuzhiyun 2052*4882a593Smuzhiyun# Clear a bunch of variables before executing the submake 2053*4882a593Smuzhiyun 2054*4882a593Smuzhiyunifeq ($(quiet),silent_) 2055*4882a593Smuzhiyuntools_silent=s 2056*4882a593Smuzhiyunendif 2057*4882a593Smuzhiyun 2058*4882a593Smuzhiyuntools/: FORCE 2059*4882a593Smuzhiyun $(Q)mkdir -p $(objtree)/tools 2060*4882a593Smuzhiyun $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ 2061*4882a593Smuzhiyun 2062*4882a593Smuzhiyuntools/%: FORCE 2063*4882a593Smuzhiyun $(Q)mkdir -p $(objtree)/tools 2064*4882a593Smuzhiyun $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $* 2065*4882a593Smuzhiyun 2066*4882a593Smuzhiyunquiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) 2067*4882a593Smuzhiyun cmd_rmfiles = rm -rf $(rm-files) 2068*4882a593Smuzhiyun 2069*4882a593Smuzhiyun# Run depmod only if we have System.map and depmod is executable 2070*4882a593Smuzhiyunquiet_cmd_depmod = DEPMOD $(KERNELRELEASE) 2071*4882a593Smuzhiyun cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ 2072*4882a593Smuzhiyun $(KERNELRELEASE) $(mixed-build-prefix) 2073*4882a593Smuzhiyun 2074*4882a593Smuzhiyun# read saved command lines for existing targets 2075*4882a593Smuzhiyunexisting-targets := $(wildcard $(sort $(targets))) 2076*4882a593Smuzhiyun 2077*4882a593Smuzhiyun-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 2078*4882a593Smuzhiyun 2079*4882a593Smuzhiyunendif # config-build 2080*4882a593Smuzhiyunendif # mixed-build 2081*4882a593Smuzhiyunendif # need-sub-make 2082*4882a593Smuzhiyun 2083*4882a593SmuzhiyunPHONY += FORCE 2084*4882a593SmuzhiyunFORCE: 2085*4882a593Smuzhiyun 2086*4882a593Smuzhiyun# Declare the contents of the PHONY variable as phony. We keep that 2087*4882a593Smuzhiyun# information in a variable so we can use it in if_changed and friends. 2088*4882a593Smuzhiyun.PHONY: $(PHONY) 2089