162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ciVERSION = 6 362306a36Sopenharmony_ciPATCHLEVEL = 6 462306a36Sopenharmony_ciSUBLEVEL = 23 562306a36Sopenharmony_ciEXTRAVERSION = 662306a36Sopenharmony_ciNAME = Hurr durr I'ma ninja sloth 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci# *DOCUMENTATION* 962306a36Sopenharmony_ci# To see a list of typical targets execute "make help" 1062306a36Sopenharmony_ci# More info can be located in ./README 1162306a36Sopenharmony_ci# Comments in this file are targeted only to the developer, do not 1262306a36Sopenharmony_ci# expect to learn how to build the kernel reading this file. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciifeq ($(filter undefine,$(.FEATURES)),) 1562306a36Sopenharmony_ci$(error GNU Make >= 3.82 is required. Your Make version is $(MAKE_VERSION)) 1662306a36Sopenharmony_ciendif 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci$(if $(filter __%, $(MAKECMDGOALS)), \ 1962306a36Sopenharmony_ci $(error targets prefixed with '__' are only for internal use)) 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci# That's our default target when none is given on the command line 2262306a36Sopenharmony_ciPHONY := __all 2362306a36Sopenharmony_ci__all: 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci# We are using a recursive build, so we need to do a little thinking 2662306a36Sopenharmony_ci# to get the ordering right. 2762306a36Sopenharmony_ci# 2862306a36Sopenharmony_ci# Most importantly: sub-Makefiles should only ever modify files in 2962306a36Sopenharmony_ci# their own directory. If in some directory we have a dependency on 3062306a36Sopenharmony_ci# a file in another dir (which doesn't happen often, but it's often 3162306a36Sopenharmony_ci# unavoidable when linking the built-in.a targets which finally 3262306a36Sopenharmony_ci# turn into vmlinux), we will call a sub make in that other dir, and 3362306a36Sopenharmony_ci# after that we are sure that everything which is in that other dir 3462306a36Sopenharmony_ci# is now up to date. 3562306a36Sopenharmony_ci# 3662306a36Sopenharmony_ci# The only cases where we need to modify files which have global 3762306a36Sopenharmony_ci# effects are thus separated out and done before the recursive 3862306a36Sopenharmony_ci# descending is started. They are now explicitly listed as the 3962306a36Sopenharmony_ci# prepare rule. 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_cithis-makefile := $(lastword $(MAKEFILE_LIST)) 4262306a36Sopenharmony_ciexport abs_srctree := $(realpath $(dir $(this-makefile))) 4362306a36Sopenharmony_ciexport abs_objtree := $(CURDIR) 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ciifneq ($(sub_make_done),1) 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci# Do not use make's built-in rules and variables 4862306a36Sopenharmony_ci# (this increases performance and avoids hard-to-debug behaviour) 4962306a36Sopenharmony_ciMAKEFLAGS += -rR 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci# Avoid funny character set dependencies 5262306a36Sopenharmony_ciunexport LC_ALL 5362306a36Sopenharmony_ciLC_COLLATE=C 5462306a36Sopenharmony_ciLC_NUMERIC=C 5562306a36Sopenharmony_ciexport LC_COLLATE LC_NUMERIC 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci# Avoid interference with shell env settings 5862306a36Sopenharmony_ciunexport GREP_OPTIONS 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci# Beautify output 6162306a36Sopenharmony_ci# --------------------------------------------------------------------------- 6262306a36Sopenharmony_ci# 6362306a36Sopenharmony_ci# Most of build commands in Kbuild start with "cmd_". You can optionally define 6462306a36Sopenharmony_ci# "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from 6562306a36Sopenharmony_ci# that command is printed by default. 6662306a36Sopenharmony_ci# 6762306a36Sopenharmony_ci# e.g.) 6862306a36Sopenharmony_ci# quiet_cmd_depmod = DEPMOD $(MODLIB) 6962306a36Sopenharmony_ci# cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE) 7062306a36Sopenharmony_ci# 7162306a36Sopenharmony_ci# A simple variant is to prefix commands with $(Q) - that's useful 7262306a36Sopenharmony_ci# for commands that shall be hidden in non-verbose mode. 7362306a36Sopenharmony_ci# 7462306a36Sopenharmony_ci# $(Q)$(MAKE) $(build)=scripts/basic 7562306a36Sopenharmony_ci# 7662306a36Sopenharmony_ci# If KBUILD_VERBOSE contains 1, the whole command is echoed. 7762306a36Sopenharmony_ci# If KBUILD_VERBOSE contains 2, the reason for rebuilding is printed. 7862306a36Sopenharmony_ci# 7962306a36Sopenharmony_ci# To put more focus on warnings, be less verbose as default 8062306a36Sopenharmony_ci# Use 'make V=1' to see the full commands 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ciifeq ("$(origin V)", "command line") 8362306a36Sopenharmony_ci KBUILD_VERBOSE = $(V) 8462306a36Sopenharmony_ciendif 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciquiet = quiet_ 8762306a36Sopenharmony_ciQ = @ 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciifneq ($(findstring 1, $(KBUILD_VERBOSE)),) 9062306a36Sopenharmony_ci quiet = 9162306a36Sopenharmony_ci Q = 9262306a36Sopenharmony_ciendif 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci# If the user is running make -s (silent mode), suppress echoing of 9562306a36Sopenharmony_ci# commands 9662306a36Sopenharmony_ci# make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ciifeq ($(filter 3.%,$(MAKE_VERSION)),) 9962306a36Sopenharmony_cishort-opts := $(firstword -$(MAKEFLAGS)) 10062306a36Sopenharmony_cielse 10162306a36Sopenharmony_cishort-opts := $(filter-out --%,$(MAKEFLAGS)) 10262306a36Sopenharmony_ciendif 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ciifneq ($(findstring s,$(short-opts)),) 10562306a36Sopenharmony_ciquiet=silent_ 10662306a36Sopenharmony_cioverride KBUILD_VERBOSE := 10762306a36Sopenharmony_ciendif 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ciexport quiet Q KBUILD_VERBOSE 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci# Call a source code checker (by default, "sparse") as part of the 11262306a36Sopenharmony_ci# C compilation. 11362306a36Sopenharmony_ci# 11462306a36Sopenharmony_ci# Use 'make C=1' to enable checking of only re-compiled files. 11562306a36Sopenharmony_ci# Use 'make C=2' to enable checking of *all* source files, regardless 11662306a36Sopenharmony_ci# of whether they are re-compiled or not. 11762306a36Sopenharmony_ci# 11862306a36Sopenharmony_ci# See the file "Documentation/dev-tools/sparse.rst" for more details, 11962306a36Sopenharmony_ci# including where to get the "sparse" utility. 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ciifeq ("$(origin C)", "command line") 12262306a36Sopenharmony_ci KBUILD_CHECKSRC = $(C) 12362306a36Sopenharmony_ciendif 12462306a36Sopenharmony_ciifndef KBUILD_CHECKSRC 12562306a36Sopenharmony_ci KBUILD_CHECKSRC = 0 12662306a36Sopenharmony_ciendif 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ciexport KBUILD_CHECKSRC 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci# Enable "clippy" (a linter) as part of the Rust compilation. 13162306a36Sopenharmony_ci# 13262306a36Sopenharmony_ci# Use 'make CLIPPY=1' to enable it. 13362306a36Sopenharmony_ciifeq ("$(origin CLIPPY)", "command line") 13462306a36Sopenharmony_ci KBUILD_CLIPPY := $(CLIPPY) 13562306a36Sopenharmony_ciendif 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ciexport KBUILD_CLIPPY 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci# Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the 14062306a36Sopenharmony_ci# directory of external module to build. Setting M= takes precedence. 14162306a36Sopenharmony_ciifeq ("$(origin M)", "command line") 14262306a36Sopenharmony_ci KBUILD_EXTMOD := $(M) 14362306a36Sopenharmony_ciendif 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci$(if $(word 2, $(KBUILD_EXTMOD)), \ 14662306a36Sopenharmony_ci $(error building multiple external modules is not supported)) 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci$(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \ 14962306a36Sopenharmony_ci $(error module directory path cannot contain '$x'))) 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci# Remove trailing slashes 15262306a36Sopenharmony_ciifneq ($(filter %/, $(KBUILD_EXTMOD)),) 15362306a36Sopenharmony_ciKBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).) 15462306a36Sopenharmony_ciendif 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ciexport KBUILD_EXTMOD 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci# Kbuild will save output files in the current working directory. 15962306a36Sopenharmony_ci# This does not need to match to the root of the kernel source tree. 16062306a36Sopenharmony_ci# 16162306a36Sopenharmony_ci# For example, you can do this: 16262306a36Sopenharmony_ci# 16362306a36Sopenharmony_ci# cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile 16462306a36Sopenharmony_ci# 16562306a36Sopenharmony_ci# If you want to save output files in a different location, there are 16662306a36Sopenharmony_ci# two syntaxes to specify it. 16762306a36Sopenharmony_ci# 16862306a36Sopenharmony_ci# 1) O= 16962306a36Sopenharmony_ci# Use "make O=dir/to/store/output/files/" 17062306a36Sopenharmony_ci# 17162306a36Sopenharmony_ci# 2) Set KBUILD_OUTPUT 17262306a36Sopenharmony_ci# Set the environment variable KBUILD_OUTPUT to point to the output directory. 17362306a36Sopenharmony_ci# export KBUILD_OUTPUT=dir/to/store/output/files/; make 17462306a36Sopenharmony_ci# 17562306a36Sopenharmony_ci# The O= assignment takes precedence over the KBUILD_OUTPUT environment 17662306a36Sopenharmony_ci# variable. 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci# Do we want to change the working directory? 17962306a36Sopenharmony_ciifeq ("$(origin O)", "command line") 18062306a36Sopenharmony_ci KBUILD_OUTPUT := $(O) 18162306a36Sopenharmony_ciendif 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ciifneq ($(KBUILD_OUTPUT),) 18462306a36Sopenharmony_ci# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot 18562306a36Sopenharmony_ci# expand a shell special character '~'. We use a somewhat tedious way here. 18662306a36Sopenharmony_ciabs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) 18762306a36Sopenharmony_ci$(if $(abs_objtree),, \ 18862306a36Sopenharmony_ci $(error failed to create output directory "$(KBUILD_OUTPUT)")) 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci# $(realpath ...) resolves symlinks 19162306a36Sopenharmony_ciabs_objtree := $(realpath $(abs_objtree)) 19262306a36Sopenharmony_ciendif # ifneq ($(KBUILD_OUTPUT),) 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ciifneq ($(words $(subst :, ,$(abs_srctree))), 1) 19562306a36Sopenharmony_ci$(error source directory cannot contain spaces or colons) 19662306a36Sopenharmony_ciendif 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ciifneq ($(filter 3.%,$(MAKE_VERSION)),) 19962306a36Sopenharmony_ci# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x 20062306a36Sopenharmony_ci# We need to invoke sub-make to avoid implicit rules in the top Makefile. 20162306a36Sopenharmony_cineed-sub-make := 1 20262306a36Sopenharmony_ci# Cancel implicit rules for this Makefile. 20362306a36Sopenharmony_ci$(this-makefile): ; 20462306a36Sopenharmony_ciendif 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ciexport sub_make_done := 1 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ciendif # sub_make_done 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ciifeq ($(abs_objtree),$(CURDIR)) 21162306a36Sopenharmony_ci# Suppress "Entering directory ..." if we are at the final work directory. 21262306a36Sopenharmony_cino-print-directory := --no-print-directory 21362306a36Sopenharmony_cielse 21462306a36Sopenharmony_ci# Recursion to show "Entering directory ..." 21562306a36Sopenharmony_cineed-sub-make := 1 21662306a36Sopenharmony_ciendif 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ciifeq ($(filter --no-print-directory, $(MAKEFLAGS)),) 21962306a36Sopenharmony_ci# If --no-print-directory is unset, recurse once again to set it. 22062306a36Sopenharmony_ci# You may end up recursing into __sub-make twice. This is needed due to the 22162306a36Sopenharmony_ci# behavior change in GNU Make 4.4.1. 22262306a36Sopenharmony_cineed-sub-make := 1 22362306a36Sopenharmony_ciendif 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ciifeq ($(need-sub-make),1) 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ciPHONY += $(MAKECMDGOALS) __sub-make 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make 23062306a36Sopenharmony_ci @: 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ci# Invoke a second make in the output directory, passing relevant variables 23362306a36Sopenharmony_ci__sub-make: 23462306a36Sopenharmony_ci $(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \ 23562306a36Sopenharmony_ci -f $(abs_srctree)/Makefile $(MAKECMDGOALS) 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_cielse # need-sub-make 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci# We process the rest of the Makefile if this is the final invocation of make 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ciifeq ($(abs_srctree),$(abs_objtree)) 24262306a36Sopenharmony_ci # building in the source tree 24362306a36Sopenharmony_ci srctree := . 24462306a36Sopenharmony_ci building_out_of_srctree := 24562306a36Sopenharmony_cielse 24662306a36Sopenharmony_ci ifeq ($(abs_srctree)/,$(dir $(abs_objtree))) 24762306a36Sopenharmony_ci # building in a subdirectory of the source tree 24862306a36Sopenharmony_ci srctree := .. 24962306a36Sopenharmony_ci else 25062306a36Sopenharmony_ci srctree := $(abs_srctree) 25162306a36Sopenharmony_ci endif 25262306a36Sopenharmony_ci building_out_of_srctree := 1 25362306a36Sopenharmony_ciendif 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_ciifneq ($(KBUILD_ABS_SRCTREE),) 25662306a36Sopenharmony_cisrctree := $(abs_srctree) 25762306a36Sopenharmony_ciendif 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ciobjtree := . 26062306a36Sopenharmony_ciVPATH := $(srctree) 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ciexport building_out_of_srctree srctree objtree VPATH 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ci# To make sure we do not include .config for any of the *config targets 26562306a36Sopenharmony_ci# catch them early, and hand them over to scripts/kconfig/Makefile 26662306a36Sopenharmony_ci# It is allowed to specify more targets when calling make, including 26762306a36Sopenharmony_ci# mixing *config targets and build targets. 26862306a36Sopenharmony_ci# For example 'make oldconfig all'. 26962306a36Sopenharmony_ci# Detect when mixed targets is specified, and make a second invocation 27062306a36Sopenharmony_ci# of make so .config is not included in this case either (for *config). 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_civersion_h := include/generated/uapi/linux/version.h 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_ciclean-targets := %clean mrproper cleandocs 27562306a36Sopenharmony_cino-dot-config-targets := $(clean-targets) \ 27662306a36Sopenharmony_ci cscope gtags TAGS tags help% %docs check% coccicheck \ 27762306a36Sopenharmony_ci $(version_h) headers headers_% archheaders archscripts \ 27862306a36Sopenharmony_ci %asm-generic kernelversion %src-pkg dt_binding_check \ 27962306a36Sopenharmony_ci outputmakefile rustavailable rustfmt rustfmtcheck 28062306a36Sopenharmony_ci# Installation targets should not require compiler. Unfortunately, vdso_install 28162306a36Sopenharmony_ci# is an exception where build artifacts may be updated. This must be fixed. 28262306a36Sopenharmony_cino-compiler-targets := $(no-dot-config-targets) install dtbs_install \ 28362306a36Sopenharmony_ci headers_install modules_install modules_sign kernelrelease image_name 28462306a36Sopenharmony_cino-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \ 28562306a36Sopenharmony_ci image_name 28662306a36Sopenharmony_cisingle-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %.symtypes %/ 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ciconfig-build := 28962306a36Sopenharmony_cimixed-build := 29062306a36Sopenharmony_cineed-config := 1 29162306a36Sopenharmony_cineed-compiler := 1 29262306a36Sopenharmony_cimay-sync-config := 1 29362306a36Sopenharmony_cisingle-build := 29462306a36Sopenharmony_ci 29562306a36Sopenharmony_ciifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) 29662306a36Sopenharmony_ci ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) 29762306a36Sopenharmony_ci need-config := 29862306a36Sopenharmony_ci endif 29962306a36Sopenharmony_ciendif 30062306a36Sopenharmony_ci 30162306a36Sopenharmony_ciifneq ($(filter $(no-compiler-targets), $(MAKECMDGOALS)),) 30262306a36Sopenharmony_ci ifeq ($(filter-out $(no-compiler-targets), $(MAKECMDGOALS)),) 30362306a36Sopenharmony_ci need-compiler := 30462306a36Sopenharmony_ci endif 30562306a36Sopenharmony_ciendif 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_ciifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) 30862306a36Sopenharmony_ci ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) 30962306a36Sopenharmony_ci may-sync-config := 31062306a36Sopenharmony_ci endif 31162306a36Sopenharmony_ciendif 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ciifneq ($(KBUILD_EXTMOD),) 31462306a36Sopenharmony_ci may-sync-config := 31562306a36Sopenharmony_ciendif 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_ciifeq ($(KBUILD_EXTMOD),) 31862306a36Sopenharmony_ci ifneq ($(filter %config,$(MAKECMDGOALS)),) 31962306a36Sopenharmony_ci config-build := 1 32062306a36Sopenharmony_ci ifneq ($(words $(MAKECMDGOALS)),1) 32162306a36Sopenharmony_ci mixed-build := 1 32262306a36Sopenharmony_ci endif 32362306a36Sopenharmony_ci endif 32462306a36Sopenharmony_ciendif 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ci# We cannot build single targets and the others at the same time 32762306a36Sopenharmony_ciifneq ($(filter $(single-targets), $(MAKECMDGOALS)),) 32862306a36Sopenharmony_ci single-build := 1 32962306a36Sopenharmony_ci ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),) 33062306a36Sopenharmony_ci mixed-build := 1 33162306a36Sopenharmony_ci endif 33262306a36Sopenharmony_ciendif 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci# For "make -j clean all", "make -j mrproper defconfig all", etc. 33562306a36Sopenharmony_ciifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) 33662306a36Sopenharmony_ci ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) 33762306a36Sopenharmony_ci mixed-build := 1 33862306a36Sopenharmony_ci endif 33962306a36Sopenharmony_ciendif 34062306a36Sopenharmony_ci 34162306a36Sopenharmony_ci# install and modules_install need also be processed one by one 34262306a36Sopenharmony_ciifneq ($(filter install,$(MAKECMDGOALS)),) 34362306a36Sopenharmony_ci ifneq ($(filter modules_install,$(MAKECMDGOALS)),) 34462306a36Sopenharmony_ci mixed-build := 1 34562306a36Sopenharmony_ci endif 34662306a36Sopenharmony_ciendif 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_ciifdef mixed-build 34962306a36Sopenharmony_ci# =========================================================================== 35062306a36Sopenharmony_ci# We're called with mixed targets (*config and build targets). 35162306a36Sopenharmony_ci# Handle them one by one. 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ciPHONY += $(MAKECMDGOALS) __build_one_by_one 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ci$(MAKECMDGOALS): __build_one_by_one 35662306a36Sopenharmony_ci @: 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci__build_one_by_one: 35962306a36Sopenharmony_ci $(Q)set -e; \ 36062306a36Sopenharmony_ci for i in $(MAKECMDGOALS); do \ 36162306a36Sopenharmony_ci $(MAKE) -f $(srctree)/Makefile $$i; \ 36262306a36Sopenharmony_ci done 36362306a36Sopenharmony_ci 36462306a36Sopenharmony_cielse # !mixed-build 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ciinclude $(srctree)/scripts/Kbuild.include 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ci# Read KERNELRELEASE from include/config/kernel.release (if it exists) 36962306a36Sopenharmony_ciKERNELRELEASE = $(call read-file, include/config/kernel.release) 37062306a36Sopenharmony_ciKERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) 37162306a36Sopenharmony_ciexport VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ciinclude $(srctree)/scripts/subarch.include 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_ci# Cross compiling and selecting different set of gcc/bin-utils 37662306a36Sopenharmony_ci# --------------------------------------------------------------------------- 37762306a36Sopenharmony_ci# 37862306a36Sopenharmony_ci# When performing cross compilation for other architectures ARCH shall be set 37962306a36Sopenharmony_ci# to the target architecture. (See arch/* for the possibilities). 38062306a36Sopenharmony_ci# ARCH can be set during invocation of make: 38162306a36Sopenharmony_ci# make ARCH=ia64 38262306a36Sopenharmony_ci# Another way is to have ARCH set in the environment. 38362306a36Sopenharmony_ci# The default ARCH is the host where make is executed. 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_ci# CROSS_COMPILE specify the prefix used for all executables used 38662306a36Sopenharmony_ci# during compilation. Only gcc and related bin-utils executables 38762306a36Sopenharmony_ci# are prefixed with $(CROSS_COMPILE). 38862306a36Sopenharmony_ci# CROSS_COMPILE can be set on the command line 38962306a36Sopenharmony_ci# make CROSS_COMPILE=ia64-linux- 39062306a36Sopenharmony_ci# Alternatively CROSS_COMPILE can be set in the environment. 39162306a36Sopenharmony_ci# Default value for CROSS_COMPILE is not to prefix executables 39262306a36Sopenharmony_ci# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile 39362306a36Sopenharmony_ciARCH ?= $(SUBARCH) 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_ci# Architecture as present in compile.h 39662306a36Sopenharmony_ciUTS_MACHINE := $(ARCH) 39762306a36Sopenharmony_ciSRCARCH := $(ARCH) 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_ci# Additional ARCH settings for x86 40062306a36Sopenharmony_ciifeq ($(ARCH),i386) 40162306a36Sopenharmony_ci SRCARCH := x86 40262306a36Sopenharmony_ciendif 40362306a36Sopenharmony_ciifeq ($(ARCH),x86_64) 40462306a36Sopenharmony_ci SRCARCH := x86 40562306a36Sopenharmony_ciendif 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci# Additional ARCH settings for sparc 40862306a36Sopenharmony_ciifeq ($(ARCH),sparc32) 40962306a36Sopenharmony_ci SRCARCH := sparc 41062306a36Sopenharmony_ciendif 41162306a36Sopenharmony_ciifeq ($(ARCH),sparc64) 41262306a36Sopenharmony_ci SRCARCH := sparc 41362306a36Sopenharmony_ciendif 41462306a36Sopenharmony_ci 41562306a36Sopenharmony_ci# Additional ARCH settings for parisc 41662306a36Sopenharmony_ciifeq ($(ARCH),parisc64) 41762306a36Sopenharmony_ci SRCARCH := parisc 41862306a36Sopenharmony_ciendif 41962306a36Sopenharmony_ci 42062306a36Sopenharmony_ciexport cross_compiling := 42162306a36Sopenharmony_ciifneq ($(SRCARCH),$(SUBARCH)) 42262306a36Sopenharmony_cicross_compiling := 1 42362306a36Sopenharmony_ciendif 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_ciKCONFIG_CONFIG ?= .config 42662306a36Sopenharmony_ciexport KCONFIG_CONFIG 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_ci# SHELL used by kbuild 42962306a36Sopenharmony_ciCONFIG_SHELL := sh 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ciHOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null) 43262306a36Sopenharmony_ciHOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null) 43362306a36Sopenharmony_ciHOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null) 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ciifneq ($(LLVM),) 43662306a36Sopenharmony_ciifneq ($(filter %/,$(LLVM)),) 43762306a36Sopenharmony_ciLLVM_PREFIX := $(LLVM) 43862306a36Sopenharmony_cielse ifneq ($(filter -%,$(LLVM)),) 43962306a36Sopenharmony_ciLLVM_SUFFIX := $(LLVM) 44062306a36Sopenharmony_ciendif 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_ciHOSTCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX) 44362306a36Sopenharmony_ciHOSTCXX = $(LLVM_PREFIX)clang++$(LLVM_SUFFIX) 44462306a36Sopenharmony_cielse 44562306a36Sopenharmony_ciHOSTCC = gcc 44662306a36Sopenharmony_ciHOSTCXX = g++ 44762306a36Sopenharmony_ciendif 44862306a36Sopenharmony_ciHOSTRUSTC = rustc 44962306a36Sopenharmony_ciHOSTPKG_CONFIG = pkg-config 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ciKBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \ 45262306a36Sopenharmony_ci -O2 -fomit-frame-pointer -std=gnu11 45362306a36Sopenharmony_ciKBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS) 45462306a36Sopenharmony_ciKBUILD_USERLDFLAGS := $(USERLDFLAGS) 45562306a36Sopenharmony_ci 45662306a36Sopenharmony_ci# These flags apply to all Rust code in the tree, including the kernel and 45762306a36Sopenharmony_ci# host programs. 45862306a36Sopenharmony_ciexport rust_common_flags := --edition=2021 \ 45962306a36Sopenharmony_ci -Zbinary_dep_depinfo=y \ 46062306a36Sopenharmony_ci -Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \ 46162306a36Sopenharmony_ci -Dunreachable_pub -Dnon_ascii_idents \ 46262306a36Sopenharmony_ci -Wmissing_docs \ 46362306a36Sopenharmony_ci -Drustdoc::missing_crate_level_docs \ 46462306a36Sopenharmony_ci -Dclippy::correctness -Dclippy::style \ 46562306a36Sopenharmony_ci -Dclippy::suspicious -Dclippy::complexity \ 46662306a36Sopenharmony_ci -Dclippy::perf \ 46762306a36Sopenharmony_ci -Dclippy::let_unit_value -Dclippy::mut_mut \ 46862306a36Sopenharmony_ci -Dclippy::needless_bitwise_bool \ 46962306a36Sopenharmony_ci -Dclippy::needless_continue \ 47062306a36Sopenharmony_ci -Dclippy::no_mangle_with_rust_abi \ 47162306a36Sopenharmony_ci -Wclippy::dbg_macro 47262306a36Sopenharmony_ci 47362306a36Sopenharmony_ciKBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS) 47462306a36Sopenharmony_ciKBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) 47562306a36Sopenharmony_ciKBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \ 47662306a36Sopenharmony_ci -Zallow-features= $(HOSTRUSTFLAGS) 47762306a36Sopenharmony_ciKBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) 47862306a36Sopenharmony_ciKBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS) 47962306a36Sopenharmony_ci 48062306a36Sopenharmony_ci# Make variables (CC, etc...) 48162306a36Sopenharmony_ciCPP = $(CC) -E 48262306a36Sopenharmony_ciifneq ($(LLVM),) 48362306a36Sopenharmony_ciCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX) 48462306a36Sopenharmony_ciLD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX) 48562306a36Sopenharmony_ciAR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX) 48662306a36Sopenharmony_ciNM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX) 48762306a36Sopenharmony_ciOBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX) 48862306a36Sopenharmony_ciOBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX) 48962306a36Sopenharmony_ciREADELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX) 49062306a36Sopenharmony_ciSTRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX) 49162306a36Sopenharmony_cielse 49262306a36Sopenharmony_ciCC = $(CROSS_COMPILE)gcc 49362306a36Sopenharmony_ciLD = $(CROSS_COMPILE)ld 49462306a36Sopenharmony_ciAR = $(CROSS_COMPILE)ar 49562306a36Sopenharmony_ciNM = $(CROSS_COMPILE)nm 49662306a36Sopenharmony_ciOBJCOPY = $(CROSS_COMPILE)objcopy 49762306a36Sopenharmony_ciOBJDUMP = $(CROSS_COMPILE)objdump 49862306a36Sopenharmony_ciREADELF = $(CROSS_COMPILE)readelf 49962306a36Sopenharmony_ciSTRIP = $(CROSS_COMPILE)strip 50062306a36Sopenharmony_ciendif 50162306a36Sopenharmony_ciRUSTC = rustc 50262306a36Sopenharmony_ciRUSTDOC = rustdoc 50362306a36Sopenharmony_ciRUSTFMT = rustfmt 50462306a36Sopenharmony_ciCLIPPY_DRIVER = clippy-driver 50562306a36Sopenharmony_ciBINDGEN = bindgen 50662306a36Sopenharmony_ciCARGO = cargo 50762306a36Sopenharmony_ciPAHOLE = pahole 50862306a36Sopenharmony_ciRESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids 50962306a36Sopenharmony_ciLEX = flex 51062306a36Sopenharmony_ciYACC = bison 51162306a36Sopenharmony_ciAWK = awk 51262306a36Sopenharmony_ciINSTALLKERNEL := installkernel 51362306a36Sopenharmony_ciPERL = perl 51462306a36Sopenharmony_ciPYTHON3 = python3 51562306a36Sopenharmony_ciCHECK = sparse 51662306a36Sopenharmony_ciBASH = bash 51762306a36Sopenharmony_ciKGZIP = gzip 51862306a36Sopenharmony_ciKBZIP2 = bzip2 51962306a36Sopenharmony_ciKLZOP = lzop 52062306a36Sopenharmony_ciLZMA = lzma 52162306a36Sopenharmony_ciLZ4 = lz4c 52262306a36Sopenharmony_ciXZ = xz 52362306a36Sopenharmony_ciZSTD = zstd 52462306a36Sopenharmony_ci 52562306a36Sopenharmony_ciPAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh) 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_ciCHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ 52862306a36Sopenharmony_ci -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) 52962306a36Sopenharmony_ciNOSTDINC_FLAGS := 53062306a36Sopenharmony_ciCFLAGS_MODULE = 53162306a36Sopenharmony_ciRUSTFLAGS_MODULE = 53262306a36Sopenharmony_ciAFLAGS_MODULE = 53362306a36Sopenharmony_ciLDFLAGS_MODULE = 53462306a36Sopenharmony_ciCFLAGS_KERNEL = 53562306a36Sopenharmony_ciRUSTFLAGS_KERNEL = 53662306a36Sopenharmony_ciAFLAGS_KERNEL = 53762306a36Sopenharmony_ciLDFLAGS_vmlinux = 53862306a36Sopenharmony_ci 53962306a36Sopenharmony_ci# Use USERINCLUDE when you must reference the UAPI directories only. 54062306a36Sopenharmony_ciUSERINCLUDE := \ 54162306a36Sopenharmony_ci -I$(srctree)/arch/$(SRCARCH)/include/uapi \ 54262306a36Sopenharmony_ci -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \ 54362306a36Sopenharmony_ci -I$(srctree)/include/uapi \ 54462306a36Sopenharmony_ci -I$(objtree)/include/generated/uapi \ 54562306a36Sopenharmony_ci -include $(srctree)/include/linux/compiler-version.h \ 54662306a36Sopenharmony_ci -include $(srctree)/include/linux/kconfig.h 54762306a36Sopenharmony_ci 54862306a36Sopenharmony_ci# Use LINUXINCLUDE when you must reference the include/ directory. 54962306a36Sopenharmony_ci# Needed to be compatible with the O= option 55062306a36Sopenharmony_ciLINUXINCLUDE := \ 55162306a36Sopenharmony_ci -I$(srctree)/arch/$(SRCARCH)/include \ 55262306a36Sopenharmony_ci -I$(objtree)/arch/$(SRCARCH)/include/generated \ 55362306a36Sopenharmony_ci $(if $(building_out_of_srctree),-I$(srctree)/include) \ 55462306a36Sopenharmony_ci -I$(objtree)/include \ 55562306a36Sopenharmony_ci $(USERINCLUDE) 55662306a36Sopenharmony_ci 55762306a36Sopenharmony_ciKBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE 55862306a36Sopenharmony_ci 55962306a36Sopenharmony_ciKBUILD_CFLAGS := 56062306a36Sopenharmony_ciKBUILD_CFLAGS += -std=gnu11 56162306a36Sopenharmony_ciKBUILD_CFLAGS += -fshort-wchar 56262306a36Sopenharmony_ciKBUILD_CFLAGS += -funsigned-char 56362306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-common 56462306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-PIE 56562306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-strict-aliasing 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ciKBUILD_CPPFLAGS := -D__KERNEL__ 56862306a36Sopenharmony_ciKBUILD_RUSTFLAGS := $(rust_common_flags) \ 56962306a36Sopenharmony_ci --target=$(objtree)/scripts/target.json \ 57062306a36Sopenharmony_ci -Cpanic=abort -Cembed-bitcode=n -Clto=n \ 57162306a36Sopenharmony_ci -Cforce-unwind-tables=n -Ccodegen-units=1 \ 57262306a36Sopenharmony_ci -Csymbol-mangling-version=v0 \ 57362306a36Sopenharmony_ci -Crelocation-model=static \ 57462306a36Sopenharmony_ci -Zfunction-sections=n \ 57562306a36Sopenharmony_ci -Dclippy::float_arithmetic 57662306a36Sopenharmony_ci 57762306a36Sopenharmony_ciKBUILD_AFLAGS_KERNEL := 57862306a36Sopenharmony_ciKBUILD_CFLAGS_KERNEL := 57962306a36Sopenharmony_ciKBUILD_RUSTFLAGS_KERNEL := 58062306a36Sopenharmony_ciKBUILD_AFLAGS_MODULE := -DMODULE 58162306a36Sopenharmony_ciKBUILD_CFLAGS_MODULE := -DMODULE 58262306a36Sopenharmony_ciKBUILD_RUSTFLAGS_MODULE := --cfg MODULE 58362306a36Sopenharmony_ciKBUILD_LDFLAGS_MODULE := 58462306a36Sopenharmony_ciKBUILD_LDFLAGS := 58562306a36Sopenharmony_ciCLANG_FLAGS := 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_ciifeq ($(KBUILD_CLIPPY),1) 58862306a36Sopenharmony_ci RUSTC_OR_CLIPPY_QUIET := CLIPPY 58962306a36Sopenharmony_ci RUSTC_OR_CLIPPY = $(CLIPPY_DRIVER) 59062306a36Sopenharmony_cielse 59162306a36Sopenharmony_ci RUSTC_OR_CLIPPY_QUIET := RUSTC 59262306a36Sopenharmony_ci RUSTC_OR_CLIPPY = $(RUSTC) 59362306a36Sopenharmony_ciendif 59462306a36Sopenharmony_ci 59562306a36Sopenharmony_ciifdef RUST_LIB_SRC 59662306a36Sopenharmony_ci export RUST_LIB_SRC 59762306a36Sopenharmony_ciendif 59862306a36Sopenharmony_ci 59962306a36Sopenharmony_ci# Allows the usage of unstable features in stable compilers. 60062306a36Sopenharmony_ciexport RUSTC_BOOTSTRAP := 1 60162306a36Sopenharmony_ci 60262306a36Sopenharmony_ciexport ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG 60362306a36Sopenharmony_ciexport RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN CARGO 60462306a36Sopenharmony_ciexport HOSTRUSTC KBUILD_HOSTRUSTFLAGS 60562306a36Sopenharmony_ciexport CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL 60662306a36Sopenharmony_ciexport PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX 60762306a36Sopenharmony_ciexport KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD 60862306a36Sopenharmony_ciexport KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE 60962306a36Sopenharmony_ciexport KBUILD_USERCFLAGS KBUILD_USERLDFLAGS 61062306a36Sopenharmony_ci 61162306a36Sopenharmony_ciexport KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS 61262306a36Sopenharmony_ciexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE 61362306a36Sopenharmony_ciexport KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE 61462306a36Sopenharmony_ciexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE 61562306a36Sopenharmony_ciexport KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE 61662306a36Sopenharmony_ciexport KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL 61762306a36Sopenharmony_ciexport PAHOLE_FLAGS 61862306a36Sopenharmony_ci 61962306a36Sopenharmony_ci# Files to ignore in find ... statements 62062306a36Sopenharmony_ci 62162306a36Sopenharmony_ciexport RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \ 62262306a36Sopenharmony_ci -name CVS -o -name .pc -o -name .hg -o -name .git \) \ 62362306a36Sopenharmony_ci -prune -o 62462306a36Sopenharmony_ciexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \ 62562306a36Sopenharmony_ci --exclude CVS --exclude .pc --exclude .hg --exclude .git 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_ci# =========================================================================== 62862306a36Sopenharmony_ci# Rules shared between *config targets and build targets 62962306a36Sopenharmony_ci 63062306a36Sopenharmony_ci# Basic helpers built in scripts/basic/ 63162306a36Sopenharmony_ciPHONY += scripts_basic 63262306a36Sopenharmony_ciscripts_basic: 63362306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=scripts/basic 63462306a36Sopenharmony_ci 63562306a36Sopenharmony_ciPHONY += outputmakefile 63662306a36Sopenharmony_ciifdef building_out_of_srctree 63762306a36Sopenharmony_ci# Before starting out-of-tree build, make sure the source tree is clean. 63862306a36Sopenharmony_ci# outputmakefile generates a Makefile in the output directory, if using a 63962306a36Sopenharmony_ci# separate output directory. This allows convenient use of make in the 64062306a36Sopenharmony_ci# output directory. 64162306a36Sopenharmony_ci# At the same time when output Makefile generated, generate .gitignore to 64262306a36Sopenharmony_ci# ignore whole output directory 64362306a36Sopenharmony_ci 64462306a36Sopenharmony_ciquiet_cmd_makefile = GEN Makefile 64562306a36Sopenharmony_ci cmd_makefile = { \ 64662306a36Sopenharmony_ci echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \ 64762306a36Sopenharmony_ci echo "include $(srctree)/Makefile"; \ 64862306a36Sopenharmony_ci } > Makefile 64962306a36Sopenharmony_ci 65062306a36Sopenharmony_cioutputmakefile: 65162306a36Sopenharmony_ci @if [ -f $(srctree)/.config -o \ 65262306a36Sopenharmony_ci -d $(srctree)/include/config -o \ 65362306a36Sopenharmony_ci -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ 65462306a36Sopenharmony_ci echo >&2 "***"; \ 65562306a36Sopenharmony_ci echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ 65662306a36Sopenharmony_ci echo >&2 "*** in $(abs_srctree)";\ 65762306a36Sopenharmony_ci echo >&2 "***"; \ 65862306a36Sopenharmony_ci false; \ 65962306a36Sopenharmony_ci fi 66062306a36Sopenharmony_ci $(Q)ln -fsn $(srctree) source 66162306a36Sopenharmony_ci $(call cmd,makefile) 66262306a36Sopenharmony_ci $(Q)test -e .gitignore || \ 66362306a36Sopenharmony_ci { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore 66462306a36Sopenharmony_ciendif 66562306a36Sopenharmony_ci 66662306a36Sopenharmony_ci# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included. 66762306a36Sopenharmony_ci# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile. 66862306a36Sopenharmony_ci# CC_VERSION_TEXT is referenced from Kconfig (so it needs export), 66962306a36Sopenharmony_ci# and from include/config/auto.conf.cmd to detect the compiler upgrade. 67062306a36Sopenharmony_ciCC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1)) 67162306a36Sopenharmony_ci 67262306a36Sopenharmony_ciifneq ($(findstring clang,$(CC_VERSION_TEXT)),) 67362306a36Sopenharmony_ciinclude $(srctree)/scripts/Makefile.clang 67462306a36Sopenharmony_ciendif 67562306a36Sopenharmony_ci 67662306a36Sopenharmony_ci# Include this also for config targets because some architectures need 67762306a36Sopenharmony_ci# cc-cross-prefix to determine CROSS_COMPILE. 67862306a36Sopenharmony_ciifdef need-compiler 67962306a36Sopenharmony_ciinclude $(srctree)/scripts/Makefile.compiler 68062306a36Sopenharmony_ciendif 68162306a36Sopenharmony_ci 68262306a36Sopenharmony_ciifdef config-build 68362306a36Sopenharmony_ci# =========================================================================== 68462306a36Sopenharmony_ci# *config targets only - make sure prerequisites are updated, and descend 68562306a36Sopenharmony_ci# in scripts/kconfig to make the *config target 68662306a36Sopenharmony_ci 68762306a36Sopenharmony_ci# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. 68862306a36Sopenharmony_ci# KBUILD_DEFCONFIG may point out an alternative default configuration 68962306a36Sopenharmony_ci# used for 'make defconfig' 69062306a36Sopenharmony_ciinclude $(srctree)/arch/$(SRCARCH)/Makefile 69162306a36Sopenharmony_ciexport KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT 69262306a36Sopenharmony_ci 69362306a36Sopenharmony_ciconfig: outputmakefile scripts_basic FORCE 69462306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=scripts/kconfig $@ 69562306a36Sopenharmony_ci 69662306a36Sopenharmony_ci%config: outputmakefile scripts_basic FORCE 69762306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=scripts/kconfig $@ 69862306a36Sopenharmony_ci 69962306a36Sopenharmony_cielse #!config-build 70062306a36Sopenharmony_ci# =========================================================================== 70162306a36Sopenharmony_ci# Build targets only - this includes vmlinux, arch specific targets, clean 70262306a36Sopenharmony_ci# targets and others. In general all targets except *config targets. 70362306a36Sopenharmony_ci 70462306a36Sopenharmony_ci# If building an external module we do not care about the all: rule 70562306a36Sopenharmony_ci# but instead __all depend on modules 70662306a36Sopenharmony_ciPHONY += all 70762306a36Sopenharmony_ciifeq ($(KBUILD_EXTMOD),) 70862306a36Sopenharmony_ci__all: all 70962306a36Sopenharmony_cielse 71062306a36Sopenharmony_ci__all: modules 71162306a36Sopenharmony_ciendif 71262306a36Sopenharmony_ci 71362306a36Sopenharmony_citargets := 71462306a36Sopenharmony_ci 71562306a36Sopenharmony_ci# Decide whether to build built-in, modular, or both. 71662306a36Sopenharmony_ci# Normally, just do built-in. 71762306a36Sopenharmony_ci 71862306a36Sopenharmony_ciKBUILD_MODULES := 71962306a36Sopenharmony_ciKBUILD_BUILTIN := 1 72062306a36Sopenharmony_ci 72162306a36Sopenharmony_ci# If we have only "make modules", don't compile built-in objects. 72262306a36Sopenharmony_ciifeq ($(MAKECMDGOALS),modules) 72362306a36Sopenharmony_ci KBUILD_BUILTIN := 72462306a36Sopenharmony_ciendif 72562306a36Sopenharmony_ci 72662306a36Sopenharmony_ci# If we have "make <whatever> modules", compile modules 72762306a36Sopenharmony_ci# in addition to whatever we do anyway. 72862306a36Sopenharmony_ci# Just "make" or "make all" shall build modules as well 72962306a36Sopenharmony_ci 73062306a36Sopenharmony_ciifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),) 73162306a36Sopenharmony_ci KBUILD_MODULES := 1 73262306a36Sopenharmony_ciendif 73362306a36Sopenharmony_ci 73462306a36Sopenharmony_ciifeq ($(MAKECMDGOALS),) 73562306a36Sopenharmony_ci KBUILD_MODULES := 1 73662306a36Sopenharmony_ciendif 73762306a36Sopenharmony_ci 73862306a36Sopenharmony_ciexport KBUILD_MODULES KBUILD_BUILTIN 73962306a36Sopenharmony_ci 74062306a36Sopenharmony_ciifdef need-config 74162306a36Sopenharmony_ciinclude include/config/auto.conf 74262306a36Sopenharmony_ciendif 74362306a36Sopenharmony_ci 74462306a36Sopenharmony_ciifeq ($(KBUILD_EXTMOD),) 74562306a36Sopenharmony_ci# Objects we will link into vmlinux / subdirs we need to visit 74662306a36Sopenharmony_cicore-y := 74762306a36Sopenharmony_cidrivers-y := 74862306a36Sopenharmony_cilibs-y := lib/ 74962306a36Sopenharmony_ciendif # KBUILD_EXTMOD 75062306a36Sopenharmony_ci 75162306a36Sopenharmony_ci# The all: target is the default when no target is given on the 75262306a36Sopenharmony_ci# command line. 75362306a36Sopenharmony_ci# This allow a user to issue only 'make' to build a kernel including modules 75462306a36Sopenharmony_ci# Defaults to vmlinux, but the arch makefile usually adds further targets 75562306a36Sopenharmony_ciall: vmlinux 75662306a36Sopenharmony_ci 75762306a36Sopenharmony_ciCFLAGS_GCOV := -fprofile-arcs -ftest-coverage 75862306a36Sopenharmony_ciifdef CONFIG_CC_IS_GCC 75962306a36Sopenharmony_ciCFLAGS_GCOV += -fno-tree-loop-im 76062306a36Sopenharmony_ciendif 76162306a36Sopenharmony_ciexport CFLAGS_GCOV 76262306a36Sopenharmony_ci 76362306a36Sopenharmony_ci# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later. 76462306a36Sopenharmony_ciifdef CONFIG_FUNCTION_TRACER 76562306a36Sopenharmony_ci CC_FLAGS_FTRACE := -pg 76662306a36Sopenharmony_ciendif 76762306a36Sopenharmony_ci 76862306a36Sopenharmony_ciinclude $(srctree)/arch/$(SRCARCH)/Makefile 76962306a36Sopenharmony_ci 77062306a36Sopenharmony_ciifdef need-config 77162306a36Sopenharmony_ciifdef may-sync-config 77262306a36Sopenharmony_ci# Read in dependencies to all Kconfig* files, make sure to run syncconfig if 77362306a36Sopenharmony_ci# changes are detected. This should be included after arch/$(SRCARCH)/Makefile 77462306a36Sopenharmony_ci# because some architectures define CROSS_COMPILE there. 77562306a36Sopenharmony_ciinclude include/config/auto.conf.cmd 77662306a36Sopenharmony_ci 77762306a36Sopenharmony_ci$(KCONFIG_CONFIG): 77862306a36Sopenharmony_ci @echo >&2 '***' 77962306a36Sopenharmony_ci @echo >&2 '*** Configuration file "$@" not found!' 78062306a36Sopenharmony_ci @echo >&2 '***' 78162306a36Sopenharmony_ci @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or' 78262306a36Sopenharmony_ci @echo >&2 '*** "make menuconfig" or "make xconfig").' 78362306a36Sopenharmony_ci @echo >&2 '***' 78462306a36Sopenharmony_ci @/bin/false 78562306a36Sopenharmony_ci 78662306a36Sopenharmony_ci# The actual configuration files used during the build are stored in 78762306a36Sopenharmony_ci# include/generated/ and include/config/. Update them if .config is newer than 78862306a36Sopenharmony_ci# include/config/auto.conf (which mirrors .config). 78962306a36Sopenharmony_ci# 79062306a36Sopenharmony_ci# This exploits the 'multi-target pattern rule' trick. 79162306a36Sopenharmony_ci# The syncconfig should be executed only once to make all the targets. 79262306a36Sopenharmony_ci# (Note: use the grouped target '&:' when we bump to GNU Make 4.3) 79362306a36Sopenharmony_ci# 79462306a36Sopenharmony_ci# Do not use $(call cmd,...) here. That would suppress prompts from syncconfig, 79562306a36Sopenharmony_ci# so you cannot notice that Kconfig is waiting for the user input. 79662306a36Sopenharmony_ci%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h %/generated/rustc_cfg: $(KCONFIG_CONFIG) 79762306a36Sopenharmony_ci $(Q)$(kecho) " SYNC $@" 79862306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig 79962306a36Sopenharmony_cielse # !may-sync-config 80062306a36Sopenharmony_ci# External modules and some install targets need include/generated/autoconf.h 80162306a36Sopenharmony_ci# and include/config/auto.conf but do not care if they are up-to-date. 80262306a36Sopenharmony_ci# Use auto.conf to trigger the test 80362306a36Sopenharmony_ciPHONY += include/config/auto.conf 80462306a36Sopenharmony_ci 80562306a36Sopenharmony_ciinclude/config/auto.conf: 80662306a36Sopenharmony_ci @test -e include/generated/autoconf.h -a -e $@ || ( \ 80762306a36Sopenharmony_ci echo >&2; \ 80862306a36Sopenharmony_ci echo >&2 " ERROR: Kernel configuration is invalid."; \ 80962306a36Sopenharmony_ci echo >&2 " include/generated/autoconf.h or $@ are missing.";\ 81062306a36Sopenharmony_ci echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \ 81162306a36Sopenharmony_ci echo >&2 ; \ 81262306a36Sopenharmony_ci /bin/false) 81362306a36Sopenharmony_ci 81462306a36Sopenharmony_ciendif # may-sync-config 81562306a36Sopenharmony_ciendif # need-config 81662306a36Sopenharmony_ci 81762306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-delete-null-pointer-checks 81862306a36Sopenharmony_ci 81962306a36Sopenharmony_ciifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE 82062306a36Sopenharmony_ciKBUILD_CFLAGS += -O2 82162306a36Sopenharmony_ciKBUILD_RUSTFLAGS += -Copt-level=2 82262306a36Sopenharmony_cielse ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE 82362306a36Sopenharmony_ciKBUILD_CFLAGS += -Os 82462306a36Sopenharmony_ciKBUILD_RUSTFLAGS += -Copt-level=s 82562306a36Sopenharmony_ciendif 82662306a36Sopenharmony_ci 82762306a36Sopenharmony_ci# Always set `debug-assertions` and `overflow-checks` because their default 82862306a36Sopenharmony_ci# depends on `opt-level` and `debug-assertions`, respectively. 82962306a36Sopenharmony_ciKBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n) 83062306a36Sopenharmony_ciKBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n) 83162306a36Sopenharmony_ci 83262306a36Sopenharmony_ci# Tell gcc to never replace conditional load with a non-conditional one 83362306a36Sopenharmony_ciifdef CONFIG_CC_IS_GCC 83462306a36Sopenharmony_ci# gcc-10 renamed --param=allow-store-data-races=0 to 83562306a36Sopenharmony_ci# -fno-allow-store-data-races. 83662306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) 83762306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) 83862306a36Sopenharmony_ciendif 83962306a36Sopenharmony_ci 84062306a36Sopenharmony_ciifdef CONFIG_READABLE_ASM 84162306a36Sopenharmony_ci# Disable optimizations that make assembler listings hard to read. 84262306a36Sopenharmony_ci# reorder blocks reorders the control in the function 84362306a36Sopenharmony_ci# ipa clone creates specialized cloned functions 84462306a36Sopenharmony_ci# partial inlining inlines only parts of functions 84562306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining 84662306a36Sopenharmony_ciendif 84762306a36Sopenharmony_ci 84862306a36Sopenharmony_cistackp-flags-y := -fno-stack-protector 84962306a36Sopenharmony_cistackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector 85062306a36Sopenharmony_cistackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong 85162306a36Sopenharmony_ci 85262306a36Sopenharmony_ciKBUILD_CFLAGS += $(stackp-flags-y) 85362306a36Sopenharmony_ci 85462306a36Sopenharmony_ciKBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings 85562306a36Sopenharmony_ciKBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y) 85662306a36Sopenharmony_ci 85762306a36Sopenharmony_ciifdef CONFIG_FRAME_POINTER 85862306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls 85962306a36Sopenharmony_ciKBUILD_RUSTFLAGS += -Cforce-frame-pointers=y 86062306a36Sopenharmony_cielse 86162306a36Sopenharmony_ci# Some targets (ARM with Thumb2, for example), can't be built with frame 86262306a36Sopenharmony_ci# pointers. For those, we don't have FUNCTION_TRACER automatically 86362306a36Sopenharmony_ci# select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is 86462306a36Sopenharmony_ci# incompatible with -fomit-frame-pointer with current GCC, so we don't use 86562306a36Sopenharmony_ci# -fomit-frame-pointer with FUNCTION_TRACER. 86662306a36Sopenharmony_ci# In the Rust target specification, "frame-pointer" is set explicitly 86762306a36Sopenharmony_ci# to "may-omit". 86862306a36Sopenharmony_ciifndef CONFIG_FUNCTION_TRACER 86962306a36Sopenharmony_ciKBUILD_CFLAGS += -fomit-frame-pointer 87062306a36Sopenharmony_ciendif 87162306a36Sopenharmony_ciendif 87262306a36Sopenharmony_ci 87362306a36Sopenharmony_ci# Initialize all stack variables with a 0xAA pattern. 87462306a36Sopenharmony_ciifdef CONFIG_INIT_STACK_ALL_PATTERN 87562306a36Sopenharmony_ciKBUILD_CFLAGS += -ftrivial-auto-var-init=pattern 87662306a36Sopenharmony_ciendif 87762306a36Sopenharmony_ci 87862306a36Sopenharmony_ci# Initialize all stack variables with a zero value. 87962306a36Sopenharmony_ciifdef CONFIG_INIT_STACK_ALL_ZERO 88062306a36Sopenharmony_ciKBUILD_CFLAGS += -ftrivial-auto-var-init=zero 88162306a36Sopenharmony_ciifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER 88262306a36Sopenharmony_ci# https://github.com/llvm/llvm-project/issues/44842 88362306a36Sopenharmony_ciCC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang 88462306a36Sopenharmony_ciexport CC_AUTO_VAR_INIT_ZERO_ENABLER 88562306a36Sopenharmony_ciKBUILD_CFLAGS += $(CC_AUTO_VAR_INIT_ZERO_ENABLER) 88662306a36Sopenharmony_ciendif 88762306a36Sopenharmony_ciendif 88862306a36Sopenharmony_ci 88962306a36Sopenharmony_ci# While VLAs have been removed, GCC produces unreachable stack probes 89062306a36Sopenharmony_ci# for the randomize_kstack_offset feature. Disable it for all compilers. 89162306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection) 89262306a36Sopenharmony_ci 89362306a36Sopenharmony_ci# Clear used registers at func exit (to reduce data lifetime and ROP gadgets). 89462306a36Sopenharmony_ciifdef CONFIG_ZERO_CALL_USED_REGS 89562306a36Sopenharmony_ciKBUILD_CFLAGS += -fzero-call-used-regs=used-gpr 89662306a36Sopenharmony_ciendif 89762306a36Sopenharmony_ci 89862306a36Sopenharmony_ciifdef CONFIG_FUNCTION_TRACER 89962306a36Sopenharmony_ciifdef CONFIG_FTRACE_MCOUNT_USE_CC 90062306a36Sopenharmony_ci CC_FLAGS_FTRACE += -mrecord-mcount 90162306a36Sopenharmony_ci ifdef CONFIG_HAVE_NOP_MCOUNT 90262306a36Sopenharmony_ci ifeq ($(call cc-option-yn, -mnop-mcount),y) 90362306a36Sopenharmony_ci CC_FLAGS_FTRACE += -mnop-mcount 90462306a36Sopenharmony_ci CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT 90562306a36Sopenharmony_ci endif 90662306a36Sopenharmony_ci endif 90762306a36Sopenharmony_ciendif 90862306a36Sopenharmony_ciifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL 90962306a36Sopenharmony_ci ifdef CONFIG_HAVE_OBJTOOL_NOP_MCOUNT 91062306a36Sopenharmony_ci CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT 91162306a36Sopenharmony_ci endif 91262306a36Sopenharmony_ciendif 91362306a36Sopenharmony_ciifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT 91462306a36Sopenharmony_ci ifdef CONFIG_HAVE_C_RECORDMCOUNT 91562306a36Sopenharmony_ci BUILD_C_RECORDMCOUNT := y 91662306a36Sopenharmony_ci export BUILD_C_RECORDMCOUNT 91762306a36Sopenharmony_ci endif 91862306a36Sopenharmony_ciendif 91962306a36Sopenharmony_ciifdef CONFIG_HAVE_FENTRY 92062306a36Sopenharmony_ci # s390-linux-gnu-gcc did not support -mfentry until gcc-9. 92162306a36Sopenharmony_ci ifeq ($(call cc-option-yn, -mfentry),y) 92262306a36Sopenharmony_ci CC_FLAGS_FTRACE += -mfentry 92362306a36Sopenharmony_ci CC_FLAGS_USING += -DCC_USING_FENTRY 92462306a36Sopenharmony_ci endif 92562306a36Sopenharmony_ciendif 92662306a36Sopenharmony_ciexport CC_FLAGS_FTRACE 92762306a36Sopenharmony_ciKBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING) 92862306a36Sopenharmony_ciKBUILD_AFLAGS += $(CC_FLAGS_USING) 92962306a36Sopenharmony_ciendif 93062306a36Sopenharmony_ci 93162306a36Sopenharmony_ci# We trigger additional mismatches with less inlining 93262306a36Sopenharmony_ciifdef CONFIG_DEBUG_SECTION_MISMATCH 93362306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-inline-functions-called-once 93462306a36Sopenharmony_ciendif 93562306a36Sopenharmony_ci 93662306a36Sopenharmony_ci# `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0). 93762306a36Sopenharmony_ciifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION 93862306a36Sopenharmony_ciKBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections 93962306a36Sopenharmony_ciKBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y 94062306a36Sopenharmony_ciLDFLAGS_vmlinux += --gc-sections 94162306a36Sopenharmony_ciendif 94262306a36Sopenharmony_ci 94362306a36Sopenharmony_ciifdef CONFIG_SHADOW_CALL_STACK 94462306a36Sopenharmony_ciifndef CONFIG_DYNAMIC_SCS 94562306a36Sopenharmony_ciCC_FLAGS_SCS := -fsanitize=shadow-call-stack 94662306a36Sopenharmony_ciKBUILD_CFLAGS += $(CC_FLAGS_SCS) 94762306a36Sopenharmony_ciendif 94862306a36Sopenharmony_ciexport CC_FLAGS_SCS 94962306a36Sopenharmony_ciendif 95062306a36Sopenharmony_ci 95162306a36Sopenharmony_ciifdef CONFIG_LTO_CLANG 95262306a36Sopenharmony_ciifdef CONFIG_LTO_CLANG_THIN 95362306a36Sopenharmony_ciCC_FLAGS_LTO := -flto=thin -fsplit-lto-unit 95462306a36Sopenharmony_ciKBUILD_LDFLAGS += --thinlto-cache-dir=$(extmod_prefix).thinlto-cache 95562306a36Sopenharmony_cielse 95662306a36Sopenharmony_ciCC_FLAGS_LTO := -flto 95762306a36Sopenharmony_ciendif 95862306a36Sopenharmony_ciCC_FLAGS_LTO += -fvisibility=hidden 95962306a36Sopenharmony_ci 96062306a36Sopenharmony_ci# Limit inlining across translation units to reduce binary size 96162306a36Sopenharmony_ciKBUILD_LDFLAGS += -mllvm -import-instr-limit=5 96262306a36Sopenharmony_ci 96362306a36Sopenharmony_ci# Check for frame size exceeding threshold during prolog/epilog insertion 96462306a36Sopenharmony_ci# when using lld < 13.0.0. 96562306a36Sopenharmony_ciifneq ($(CONFIG_FRAME_WARN),0) 96662306a36Sopenharmony_ciifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) 96762306a36Sopenharmony_ciKBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN) 96862306a36Sopenharmony_ciendif 96962306a36Sopenharmony_ciendif 97062306a36Sopenharmony_ciendif 97162306a36Sopenharmony_ci 97262306a36Sopenharmony_ciifdef CONFIG_LTO 97362306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO) 97462306a36Sopenharmony_ciKBUILD_AFLAGS += -fno-lto 97562306a36Sopenharmony_ciexport CC_FLAGS_LTO 97662306a36Sopenharmony_ciendif 97762306a36Sopenharmony_ci 97862306a36Sopenharmony_ciifdef CONFIG_CFI_CLANG 97962306a36Sopenharmony_ciCC_FLAGS_CFI := -fsanitize=kcfi 98062306a36Sopenharmony_ciKBUILD_CFLAGS += $(CC_FLAGS_CFI) 98162306a36Sopenharmony_ciexport CC_FLAGS_CFI 98262306a36Sopenharmony_ciendif 98362306a36Sopenharmony_ci 98462306a36Sopenharmony_ciifneq ($(CONFIG_FUNCTION_ALIGNMENT),0) 98562306a36Sopenharmony_ciKBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT) 98662306a36Sopenharmony_ciendif 98762306a36Sopenharmony_ci 98862306a36Sopenharmony_ci# arch Makefile may override CC so keep this after arch Makefile is included 98962306a36Sopenharmony_ciNOSTDINC_FLAGS += -nostdinc 99062306a36Sopenharmony_ci 99162306a36Sopenharmony_ci# To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, 99262306a36Sopenharmony_ci# the kernel uses only C99 flexible arrays for dynamically sized trailing 99362306a36Sopenharmony_ci# arrays. Enforce this for everything that may examine structure sizes and 99462306a36Sopenharmony_ci# perform bounds checking. 99562306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3) 99662306a36Sopenharmony_ci 99762306a36Sopenharmony_ci# disable invalid "can't wrap" optimizations for signed / pointers 99862306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-strict-overflow 99962306a36Sopenharmony_ci 100062306a36Sopenharmony_ci# Make sure -fstack-check isn't enabled (like gentoo apparently did) 100162306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-stack-check 100262306a36Sopenharmony_ci 100362306a36Sopenharmony_ci# conserve stack if available 100462306a36Sopenharmony_ciifdef CONFIG_CC_IS_GCC 100562306a36Sopenharmony_ciKBUILD_CFLAGS += -fconserve-stack 100662306a36Sopenharmony_ciendif 100762306a36Sopenharmony_ci 100862306a36Sopenharmony_ci# change __FILE__ to the relative path from the srctree 100962306a36Sopenharmony_ciKBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) 101062306a36Sopenharmony_ci 101162306a36Sopenharmony_ci# include additional Makefiles when needed 101262306a36Sopenharmony_ciinclude-y := scripts/Makefile.extrawarn 101362306a36Sopenharmony_ciinclude-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug 101462306a36Sopenharmony_ciinclude-$(CONFIG_KASAN) += scripts/Makefile.kasan 101562306a36Sopenharmony_ciinclude-$(CONFIG_KCSAN) += scripts/Makefile.kcsan 101662306a36Sopenharmony_ciinclude-$(CONFIG_KMSAN) += scripts/Makefile.kmsan 101762306a36Sopenharmony_ciinclude-$(CONFIG_UBSAN) += scripts/Makefile.ubsan 101862306a36Sopenharmony_ciinclude-$(CONFIG_KCOV) += scripts/Makefile.kcov 101962306a36Sopenharmony_ciinclude-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct 102062306a36Sopenharmony_ciinclude-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins 102162306a36Sopenharmony_ci 102262306a36Sopenharmony_ciinclude $(addprefix $(srctree)/, $(include-y)) 102362306a36Sopenharmony_ci 102462306a36Sopenharmony_ci# scripts/Makefile.gcc-plugins is intentionally included last. 102562306a36Sopenharmony_ci# Do not add $(call cc-option,...) below this line. When you build the kernel 102662306a36Sopenharmony_ci# from the clean source tree, the GCC plugins do not exist at this point. 102762306a36Sopenharmony_ci 102862306a36Sopenharmony_ci# Add user supplied CPPFLAGS, AFLAGS, CFLAGS and RUSTFLAGS as the last assignments 102962306a36Sopenharmony_ciKBUILD_CPPFLAGS += $(KCPPFLAGS) 103062306a36Sopenharmony_ciKBUILD_AFLAGS += $(KAFLAGS) 103162306a36Sopenharmony_ciKBUILD_CFLAGS += $(KCFLAGS) 103262306a36Sopenharmony_ciKBUILD_RUSTFLAGS += $(KRUSTFLAGS) 103362306a36Sopenharmony_ci 103462306a36Sopenharmony_ciKBUILD_LDFLAGS_MODULE += --build-id=sha1 103562306a36Sopenharmony_ciLDFLAGS_vmlinux += --build-id=sha1 103662306a36Sopenharmony_ci 103762306a36Sopenharmony_ciKBUILD_LDFLAGS += -z noexecstack 103862306a36Sopenharmony_ciifeq ($(CONFIG_LD_IS_BFD),y) 103962306a36Sopenharmony_ciKBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments) 104062306a36Sopenharmony_ciendif 104162306a36Sopenharmony_ci 104262306a36Sopenharmony_ciifeq ($(CONFIG_STRIP_ASM_SYMS),y) 104362306a36Sopenharmony_ciLDFLAGS_vmlinux += -X 104462306a36Sopenharmony_ciendif 104562306a36Sopenharmony_ci 104662306a36Sopenharmony_ciifeq ($(CONFIG_RELR),y) 104762306a36Sopenharmony_ci# ld.lld before 15 did not support -z pack-relative-relocs. 104862306a36Sopenharmony_ciLDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs) 104962306a36Sopenharmony_ciendif 105062306a36Sopenharmony_ci 105162306a36Sopenharmony_ci# We never want expected sections to be placed heuristically by the 105262306a36Sopenharmony_ci# linker. All sections should be explicitly named in the linker script. 105362306a36Sopenharmony_ciifdef CONFIG_LD_ORPHAN_WARN 105462306a36Sopenharmony_ciLDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL) 105562306a36Sopenharmony_ciendif 105662306a36Sopenharmony_ci 105762306a36Sopenharmony_ci# Align the bit size of userspace programs with the kernel 105862306a36Sopenharmony_ciKBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) 105962306a36Sopenharmony_ciKBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) 106062306a36Sopenharmony_ci 106162306a36Sopenharmony_ci# make the checker run with the right architecture 106262306a36Sopenharmony_ciCHECKFLAGS += --arch=$(ARCH) 106362306a36Sopenharmony_ci 106462306a36Sopenharmony_ci# insure the checker run with the right endianness 106562306a36Sopenharmony_ciCHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian) 106662306a36Sopenharmony_ci 106762306a36Sopenharmony_ci# the checker needs the correct machine size 106862306a36Sopenharmony_ciCHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32) 106962306a36Sopenharmony_ci 107062306a36Sopenharmony_ci# Default kernel image to build when no specific target is given. 107162306a36Sopenharmony_ci# KBUILD_IMAGE may be overruled on the command line or 107262306a36Sopenharmony_ci# set in the environment 107362306a36Sopenharmony_ci# Also any assignments in arch/$(ARCH)/Makefile take precedence over 107462306a36Sopenharmony_ci# this default value 107562306a36Sopenharmony_ciexport KBUILD_IMAGE ?= vmlinux 107662306a36Sopenharmony_ci 107762306a36Sopenharmony_ci# 107862306a36Sopenharmony_ci# INSTALL_PATH specifies where to place the updated kernel and system map 107962306a36Sopenharmony_ci# images. Default is /boot, but you can set it to other values 108062306a36Sopenharmony_ciexport INSTALL_PATH ?= /boot 108162306a36Sopenharmony_ci 108262306a36Sopenharmony_ci# 108362306a36Sopenharmony_ci# INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots. 108462306a36Sopenharmony_ci# Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as 108562306a36Sopenharmony_ci# an argument if needed. Otherwise it defaults to the kernel install path 108662306a36Sopenharmony_ci# 108762306a36Sopenharmony_ciexport INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE) 108862306a36Sopenharmony_ci 108962306a36Sopenharmony_ci# 109062306a36Sopenharmony_ci# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory 109162306a36Sopenharmony_ci# relocations required by build roots. This is not defined in the 109262306a36Sopenharmony_ci# makefile but the argument can be passed to make if needed. 109362306a36Sopenharmony_ci# 109462306a36Sopenharmony_ci 109562306a36Sopenharmony_ciMODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) 109662306a36Sopenharmony_ciexport MODLIB 109762306a36Sopenharmony_ci 109862306a36Sopenharmony_ciPHONY += prepare0 109962306a36Sopenharmony_ci 110062306a36Sopenharmony_ciexport extmod_prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) 110162306a36Sopenharmony_ciexport MODORDER := $(extmod_prefix)modules.order 110262306a36Sopenharmony_ciexport MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps 110362306a36Sopenharmony_ci 110462306a36Sopenharmony_ciifeq ($(KBUILD_EXTMOD),) 110562306a36Sopenharmony_ci 110662306a36Sopenharmony_cibuild-dir := . 110762306a36Sopenharmony_ciclean-dirs := $(sort . Documentation \ 110862306a36Sopenharmony_ci $(patsubst %/,%,$(filter %/, $(core-) \ 110962306a36Sopenharmony_ci $(drivers-) $(libs-)))) 111062306a36Sopenharmony_ci 111162306a36Sopenharmony_ciexport ARCH_CORE := $(core-y) 111262306a36Sopenharmony_ciexport ARCH_LIB := $(filter %/, $(libs-y)) 111362306a36Sopenharmony_ciexport ARCH_DRIVERS := $(drivers-y) $(drivers-m) 111462306a36Sopenharmony_ci# Externally visible symbols (used by link-vmlinux.sh) 111562306a36Sopenharmony_ci 111662306a36Sopenharmony_ciKBUILD_VMLINUX_OBJS := ./built-in.a 111762306a36Sopenharmony_ciifdef CONFIG_MODULES 111862306a36Sopenharmony_ciKBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) 111962306a36Sopenharmony_ciKBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y)) 112062306a36Sopenharmony_cielse 112162306a36Sopenharmony_ciKBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y)) 112262306a36Sopenharmony_ciendif 112362306a36Sopenharmony_ci 112462306a36Sopenharmony_ciexport KBUILD_VMLINUX_LIBS 112562306a36Sopenharmony_ciexport KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds 112662306a36Sopenharmony_ci 112762306a36Sopenharmony_ciifdef CONFIG_TRIM_UNUSED_KSYMS 112862306a36Sopenharmony_ci# For the kernel to actually contain only the needed exported symbols, 112962306a36Sopenharmony_ci# we have to build modules as well to determine what those symbols are. 113062306a36Sopenharmony_ciKBUILD_MODULES := 1 113162306a36Sopenharmony_ciendif 113262306a36Sopenharmony_ci 113362306a36Sopenharmony_ci# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14 113462306a36Sopenharmony_ciquiet_cmd_ar_vmlinux.a = AR $@ 113562306a36Sopenharmony_ci cmd_ar_vmlinux.a = \ 113662306a36Sopenharmony_ci rm -f $@; \ 113762306a36Sopenharmony_ci $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \ 113862306a36Sopenharmony_ci $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt) 113962306a36Sopenharmony_ci 114062306a36Sopenharmony_citargets += vmlinux.a 114162306a36Sopenharmony_civmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE 114262306a36Sopenharmony_ci $(call if_changed,ar_vmlinux.a) 114362306a36Sopenharmony_ci 114462306a36Sopenharmony_ciPHONY += vmlinux_o 114562306a36Sopenharmony_civmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS) 114662306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o 114762306a36Sopenharmony_ci 114862306a36Sopenharmony_civmlinux.o modules.builtin.modinfo modules.builtin: vmlinux_o 114962306a36Sopenharmony_ci @: 115062306a36Sopenharmony_ci 115162306a36Sopenharmony_ciPHONY += vmlinux 115262306a36Sopenharmony_ci# LDFLAGS_vmlinux in the top Makefile defines linker flags for the top vmlinux, 115362306a36Sopenharmony_ci# not for decompressors. LDFLAGS_vmlinux in arch/*/boot/compressed/Makefile is 115462306a36Sopenharmony_ci# unrelated; the decompressors just happen to have the same base name, 115562306a36Sopenharmony_ci# arch/*/boot/compressed/vmlinux. 115662306a36Sopenharmony_ci# Export LDFLAGS_vmlinux only to scripts/Makefile.vmlinux. 115762306a36Sopenharmony_ci# 115862306a36Sopenharmony_ci# _LDFLAGS_vmlinux is a workaround for the 'private export' bug: 115962306a36Sopenharmony_ci# https://savannah.gnu.org/bugs/?61463 116062306a36Sopenharmony_ci# For Make > 4.4, the following simple code will work: 116162306a36Sopenharmony_ci# vmlinux: private export LDFLAGS_vmlinux := $(LDFLAGS_vmlinux) 116262306a36Sopenharmony_civmlinux: private _LDFLAGS_vmlinux := $(LDFLAGS_vmlinux) 116362306a36Sopenharmony_civmlinux: export LDFLAGS_vmlinux = $(_LDFLAGS_vmlinux) 116462306a36Sopenharmony_civmlinux: vmlinux.o $(KBUILD_LDS) modpost 116562306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux 116662306a36Sopenharmony_ci 116762306a36Sopenharmony_ci# The actual objects are generated when descending, 116862306a36Sopenharmony_ci# make sure no implicit rule kicks in 116962306a36Sopenharmony_ci$(sort $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)): . ; 117062306a36Sopenharmony_ci 117162306a36Sopenharmony_ciifeq ($(origin KERNELRELEASE),file) 117262306a36Sopenharmony_cifilechk_kernel.release = $(srctree)/scripts/setlocalversion $(srctree) 117362306a36Sopenharmony_cielse 117462306a36Sopenharmony_cifilechk_kernel.release = echo $(KERNELRELEASE) 117562306a36Sopenharmony_ciendif 117662306a36Sopenharmony_ci 117762306a36Sopenharmony_ci# Store (new) KERNELRELEASE string in include/config/kernel.release 117862306a36Sopenharmony_ciinclude/config/kernel.release: FORCE 117962306a36Sopenharmony_ci $(call filechk,kernel.release) 118062306a36Sopenharmony_ci 118162306a36Sopenharmony_ci# Additional helpers built in scripts/ 118262306a36Sopenharmony_ci# Carefully list dependencies so we do not try to build scripts twice 118362306a36Sopenharmony_ci# in parallel 118462306a36Sopenharmony_ciPHONY += scripts 118562306a36Sopenharmony_ciscripts: scripts_basic scripts_dtc 118662306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=$(@) 118762306a36Sopenharmony_ci 118862306a36Sopenharmony_ci# Things we need to do before we recursively start building the kernel 118962306a36Sopenharmony_ci# or the modules are listed in "prepare". 119062306a36Sopenharmony_ci# A multi level approach is used. prepareN is processed before prepareN-1. 119162306a36Sopenharmony_ci# archprepare is used in arch Makefiles and when processed asm symlink, 119262306a36Sopenharmony_ci# version.h and scripts_basic is processed / created. 119362306a36Sopenharmony_ci 119462306a36Sopenharmony_ciPHONY += prepare archprepare 119562306a36Sopenharmony_ci 119662306a36Sopenharmony_ciarchprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ 119762306a36Sopenharmony_ci asm-generic $(version_h) include/generated/utsrelease.h \ 119862306a36Sopenharmony_ci include/generated/compile.h include/generated/autoconf.h remove-stale-files 119962306a36Sopenharmony_ci 120062306a36Sopenharmony_ciprepare0: archprepare 120162306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=scripts/mod 120262306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=. prepare 120362306a36Sopenharmony_ci 120462306a36Sopenharmony_ci# All the preparing.. 120562306a36Sopenharmony_ciprepare: prepare0 120662306a36Sopenharmony_ciifdef CONFIG_RUST 120762306a36Sopenharmony_ci $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh 120862306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=rust 120962306a36Sopenharmony_ciendif 121062306a36Sopenharmony_ci 121162306a36Sopenharmony_ciPHONY += remove-stale-files 121262306a36Sopenharmony_ciremove-stale-files: 121362306a36Sopenharmony_ci $(Q)$(srctree)/scripts/remove-stale-files 121462306a36Sopenharmony_ci 121562306a36Sopenharmony_ci# Support for using generic headers in asm-generic 121662306a36Sopenharmony_ciasm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj 121762306a36Sopenharmony_ci 121862306a36Sopenharmony_ciPHONY += asm-generic uapi-asm-generic 121962306a36Sopenharmony_ciasm-generic: uapi-asm-generic 122062306a36Sopenharmony_ci $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \ 122162306a36Sopenharmony_ci generic=include/asm-generic 122262306a36Sopenharmony_ciuapi-asm-generic: 122362306a36Sopenharmony_ci $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \ 122462306a36Sopenharmony_ci generic=include/uapi/asm-generic 122562306a36Sopenharmony_ci 122662306a36Sopenharmony_ci# Generate some files 122762306a36Sopenharmony_ci# --------------------------------------------------------------------------- 122862306a36Sopenharmony_ci 122962306a36Sopenharmony_ci# KERNELRELEASE can change from a few different places, meaning version.h 123062306a36Sopenharmony_ci# needs to be updated, so this check is forced on all builds 123162306a36Sopenharmony_ci 123262306a36Sopenharmony_ciuts_len := 64 123362306a36Sopenharmony_cidefine filechk_utsrelease.h 123462306a36Sopenharmony_ci if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \ 123562306a36Sopenharmony_ci echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \ 123662306a36Sopenharmony_ci exit 1; \ 123762306a36Sopenharmony_ci fi; \ 123862306a36Sopenharmony_ci echo \#define UTS_RELEASE \"$(KERNELRELEASE)\" 123962306a36Sopenharmony_ciendef 124062306a36Sopenharmony_ci 124162306a36Sopenharmony_cidefine filechk_version.h 124262306a36Sopenharmony_ci if [ $(SUBLEVEL) -gt 255 ]; then \ 124362306a36Sopenharmony_ci echo \#define LINUX_VERSION_CODE $(shell \ 124462306a36Sopenharmony_ci expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \ 124562306a36Sopenharmony_ci else \ 124662306a36Sopenharmony_ci echo \#define LINUX_VERSION_CODE $(shell \ 124762306a36Sopenharmony_ci expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ 124862306a36Sopenharmony_ci fi; \ 124962306a36Sopenharmony_ci echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ 125062306a36Sopenharmony_ci ((c) > 255 ? 255 : (c)))'; \ 125162306a36Sopenharmony_ci echo \#define LINUX_VERSION_MAJOR $(VERSION); \ 125262306a36Sopenharmony_ci echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \ 125362306a36Sopenharmony_ci echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL) 125462306a36Sopenharmony_ciendef 125562306a36Sopenharmony_ci 125662306a36Sopenharmony_ci$(version_h): PATCHLEVEL := $(or $(PATCHLEVEL), 0) 125762306a36Sopenharmony_ci$(version_h): SUBLEVEL := $(or $(SUBLEVEL), 0) 125862306a36Sopenharmony_ci$(version_h): FORCE 125962306a36Sopenharmony_ci $(call filechk,version.h) 126062306a36Sopenharmony_ci 126162306a36Sopenharmony_ciinclude/generated/utsrelease.h: include/config/kernel.release FORCE 126262306a36Sopenharmony_ci $(call filechk,utsrelease.h) 126362306a36Sopenharmony_ci 126462306a36Sopenharmony_cifilechk_compile.h = $(srctree)/scripts/mkcompile_h \ 126562306a36Sopenharmony_ci "$(UTS_MACHINE)" "$(CONFIG_CC_VERSION_TEXT)" "$(LD)" 126662306a36Sopenharmony_ci 126762306a36Sopenharmony_ciinclude/generated/compile.h: FORCE 126862306a36Sopenharmony_ci $(call filechk,compile.h) 126962306a36Sopenharmony_ci 127062306a36Sopenharmony_ciPHONY += headerdep 127162306a36Sopenharmony_ciheaderdep: 127262306a36Sopenharmony_ci $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \ 127362306a36Sopenharmony_ci $(srctree)/scripts/headerdep.pl -I$(srctree)/include 127462306a36Sopenharmony_ci 127562306a36Sopenharmony_ci# --------------------------------------------------------------------------- 127662306a36Sopenharmony_ci# Kernel headers 127762306a36Sopenharmony_ci 127862306a36Sopenharmony_ci#Default location for installed headers 127962306a36Sopenharmony_ciexport INSTALL_HDR_PATH = $(objtree)/usr 128062306a36Sopenharmony_ci 128162306a36Sopenharmony_ciquiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include 128262306a36Sopenharmony_ci cmd_headers_install = \ 128362306a36Sopenharmony_ci mkdir -p $(INSTALL_HDR_PATH); \ 128462306a36Sopenharmony_ci rsync -mrl --include='*/' --include='*\.h' --exclude='*' \ 128562306a36Sopenharmony_ci usr/include $(INSTALL_HDR_PATH) 128662306a36Sopenharmony_ci 128762306a36Sopenharmony_ciPHONY += headers_install 128862306a36Sopenharmony_ciheaders_install: headers 128962306a36Sopenharmony_ci $(call cmd,headers_install) 129062306a36Sopenharmony_ci 129162306a36Sopenharmony_ciPHONY += archheaders archscripts 129262306a36Sopenharmony_ci 129362306a36Sopenharmony_cihdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj 129462306a36Sopenharmony_ci 129562306a36Sopenharmony_ciPHONY += headers 129662306a36Sopenharmony_ciheaders: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts 129762306a36Sopenharmony_ci $(if $(filter um, $(SRCARCH)), $(error Headers not exportable for UML)) 129862306a36Sopenharmony_ci $(Q)$(MAKE) $(hdr-inst)=include/uapi 129962306a36Sopenharmony_ci $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi 130062306a36Sopenharmony_ci 130162306a36Sopenharmony_ciifdef CONFIG_HEADERS_INSTALL 130262306a36Sopenharmony_ciprepare: headers 130362306a36Sopenharmony_ciendif 130462306a36Sopenharmony_ci 130562306a36Sopenharmony_ciPHONY += scripts_unifdef 130662306a36Sopenharmony_ciscripts_unifdef: scripts_basic 130762306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=scripts scripts/unifdef 130862306a36Sopenharmony_ci 130962306a36Sopenharmony_ci# --------------------------------------------------------------------------- 131062306a36Sopenharmony_ci# Install 131162306a36Sopenharmony_ci 131262306a36Sopenharmony_ci# Many distributions have the custom install script, /sbin/installkernel. 131362306a36Sopenharmony_ci# If DKMS is installed, 'make install' will eventually recurse back 131462306a36Sopenharmony_ci# to this Makefile to build and install external modules. 131562306a36Sopenharmony_ci# Cancel sub_make_done so that options such as M=, V=, etc. are parsed. 131662306a36Sopenharmony_ci 131762306a36Sopenharmony_ciquiet_cmd_install = INSTALL $(INSTALL_PATH) 131862306a36Sopenharmony_ci cmd_install = unset sub_make_done; $(srctree)/scripts/install.sh 131962306a36Sopenharmony_ci 132062306a36Sopenharmony_ci# --------------------------------------------------------------------------- 132162306a36Sopenharmony_ci# Tools 132262306a36Sopenharmony_ci 132362306a36Sopenharmony_ciifdef CONFIG_OBJTOOL 132462306a36Sopenharmony_ciprepare: tools/objtool 132562306a36Sopenharmony_ciendif 132662306a36Sopenharmony_ci 132762306a36Sopenharmony_ciifdef CONFIG_BPF 132862306a36Sopenharmony_ciifdef CONFIG_DEBUG_INFO_BTF 132962306a36Sopenharmony_ciprepare: tools/bpf/resolve_btfids 133062306a36Sopenharmony_ciendif 133162306a36Sopenharmony_ciendif 133262306a36Sopenharmony_ci 133362306a36Sopenharmony_ciPHONY += resolve_btfids_clean 133462306a36Sopenharmony_ci 133562306a36Sopenharmony_ciresolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids 133662306a36Sopenharmony_ci 133762306a36Sopenharmony_ci# tools/bpf/resolve_btfids directory might not exist 133862306a36Sopenharmony_ci# in output directory, skip its clean in that case 133962306a36Sopenharmony_ciresolve_btfids_clean: 134062306a36Sopenharmony_ciifneq ($(wildcard $(resolve_btfids_O)),) 134162306a36Sopenharmony_ci $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean 134262306a36Sopenharmony_ciendif 134362306a36Sopenharmony_ci 134462306a36Sopenharmony_ci# Clear a bunch of variables before executing the submake 134562306a36Sopenharmony_ciifeq ($(quiet),silent_) 134662306a36Sopenharmony_citools_silent=s 134762306a36Sopenharmony_ciendif 134862306a36Sopenharmony_ci 134962306a36Sopenharmony_citools/: FORCE 135062306a36Sopenharmony_ci $(Q)mkdir -p $(objtree)/tools 135162306a36Sopenharmony_ci $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ 135262306a36Sopenharmony_ci 135362306a36Sopenharmony_citools/%: FORCE 135462306a36Sopenharmony_ci $(Q)mkdir -p $(objtree)/tools 135562306a36Sopenharmony_ci $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $* 135662306a36Sopenharmony_ci 135762306a36Sopenharmony_ci# --------------------------------------------------------------------------- 135862306a36Sopenharmony_ci# Kernel selftest 135962306a36Sopenharmony_ci 136062306a36Sopenharmony_ciPHONY += kselftest 136162306a36Sopenharmony_cikselftest: headers 136262306a36Sopenharmony_ci $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests 136362306a36Sopenharmony_ci 136462306a36Sopenharmony_cikselftest-%: headers FORCE 136562306a36Sopenharmony_ci $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $* 136662306a36Sopenharmony_ci 136762306a36Sopenharmony_ciPHONY += kselftest-merge 136862306a36Sopenharmony_cikselftest-merge: 136962306a36Sopenharmony_ci $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!)) 137062306a36Sopenharmony_ci $(Q)find $(srctree)/tools/testing/selftests -name config | \ 137162306a36Sopenharmony_ci xargs $(srctree)/scripts/kconfig/merge_config.sh -m $(objtree)/.config 137262306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig 137362306a36Sopenharmony_ci 137462306a36Sopenharmony_ci# --------------------------------------------------------------------------- 137562306a36Sopenharmony_ci# Devicetree files 137662306a36Sopenharmony_ci 137762306a36Sopenharmony_ciifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),) 137862306a36Sopenharmony_cidtstree := arch/$(SRCARCH)/boot/dts 137962306a36Sopenharmony_ciendif 138062306a36Sopenharmony_ci 138162306a36Sopenharmony_ciifneq ($(dtstree),) 138262306a36Sopenharmony_ci 138362306a36Sopenharmony_ci%.dtb: dtbs_prepare 138462306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@ 138562306a36Sopenharmony_ci 138662306a36Sopenharmony_ci%.dtbo: dtbs_prepare 138762306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@ 138862306a36Sopenharmony_ci 138962306a36Sopenharmony_ciPHONY += dtbs dtbs_prepare dtbs_install dtbs_check 139062306a36Sopenharmony_cidtbs: dtbs_prepare 139162306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=$(dtstree) 139262306a36Sopenharmony_ci 139362306a36Sopenharmony_ci# include/config/kernel.release is actually needed when installing DTBs because 139462306a36Sopenharmony_ci# INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make 139562306a36Sopenharmony_ci# dtbs_install depend on it as dtbs_install may run as root. 139662306a36Sopenharmony_cidtbs_prepare: include/config/kernel.release scripts_dtc 139762306a36Sopenharmony_ci 139862306a36Sopenharmony_ciifneq ($(filter dtbs_check, $(MAKECMDGOALS)),) 139962306a36Sopenharmony_ciexport CHECK_DTBS=y 140062306a36Sopenharmony_ciendif 140162306a36Sopenharmony_ci 140262306a36Sopenharmony_ciifneq ($(CHECK_DTBS),) 140362306a36Sopenharmony_cidtbs_prepare: dt_binding_check 140462306a36Sopenharmony_ciendif 140562306a36Sopenharmony_ci 140662306a36Sopenharmony_cidtbs_check: dtbs 140762306a36Sopenharmony_ci 140862306a36Sopenharmony_cidtbs_install: 140962306a36Sopenharmony_ci $(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH) 141062306a36Sopenharmony_ci 141162306a36Sopenharmony_ciifdef CONFIG_OF_EARLY_FLATTREE 141262306a36Sopenharmony_ciall: dtbs 141362306a36Sopenharmony_ciendif 141462306a36Sopenharmony_ci 141562306a36Sopenharmony_ciendif 141662306a36Sopenharmony_ci 141762306a36Sopenharmony_ciPHONY += scripts_dtc 141862306a36Sopenharmony_ciscripts_dtc: scripts_basic 141962306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=scripts/dtc 142062306a36Sopenharmony_ci 142162306a36Sopenharmony_ciifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),) 142262306a36Sopenharmony_ciexport CHECK_DT_BINDING=y 142362306a36Sopenharmony_ciendif 142462306a36Sopenharmony_ci 142562306a36Sopenharmony_ciPHONY += dt_binding_check 142662306a36Sopenharmony_cidt_binding_check: scripts_dtc 142762306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings 142862306a36Sopenharmony_ci 142962306a36Sopenharmony_ciPHONY += dt_compatible_check 143062306a36Sopenharmony_cidt_compatible_check: dt_binding_check 143162306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings $@ 143262306a36Sopenharmony_ci 143362306a36Sopenharmony_ci# --------------------------------------------------------------------------- 143462306a36Sopenharmony_ci# Modules 143562306a36Sopenharmony_ci 143662306a36Sopenharmony_ciifdef CONFIG_MODULES 143762306a36Sopenharmony_ci 143862306a36Sopenharmony_ci# By default, build modules as well 143962306a36Sopenharmony_ci 144062306a36Sopenharmony_ciall: modules 144162306a36Sopenharmony_ci 144262306a36Sopenharmony_ci# When we're building modules with modversions, we need to consider 144362306a36Sopenharmony_ci# the built-in objects during the descend as well, in order to 144462306a36Sopenharmony_ci# make sure the checksums are up to date before we record them. 144562306a36Sopenharmony_ciifdef CONFIG_MODVERSIONS 144662306a36Sopenharmony_ci KBUILD_BUILTIN := 1 144762306a36Sopenharmony_ciendif 144862306a36Sopenharmony_ci 144962306a36Sopenharmony_ci# Build modules 145062306a36Sopenharmony_ci# 145162306a36Sopenharmony_ci 145262306a36Sopenharmony_ci# *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFO_BTF_MODULES 145362306a36Sopenharmony_ci# is an exception. 145462306a36Sopenharmony_ciifdef CONFIG_DEBUG_INFO_BTF_MODULES 145562306a36Sopenharmony_ciKBUILD_BUILTIN := 1 145662306a36Sopenharmony_cimodules: vmlinux 145762306a36Sopenharmony_ciendif 145862306a36Sopenharmony_ci 145962306a36Sopenharmony_cimodules: modules_prepare 146062306a36Sopenharmony_ci 146162306a36Sopenharmony_ci# Target to prepare building external modules 146262306a36Sopenharmony_cimodules_prepare: prepare 146362306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=scripts scripts/module.lds 146462306a36Sopenharmony_ci 146562306a36Sopenharmony_ciendif # CONFIG_MODULES 146662306a36Sopenharmony_ci 146762306a36Sopenharmony_ci### 146862306a36Sopenharmony_ci# Cleaning is done on three levels. 146962306a36Sopenharmony_ci# make clean Delete most generated files 147062306a36Sopenharmony_ci# Leave enough to build external modules 147162306a36Sopenharmony_ci# make mrproper Delete the current configuration, and all generated files 147262306a36Sopenharmony_ci# make distclean Remove editor backup files, patch leftover files and the like 147362306a36Sopenharmony_ci 147462306a36Sopenharmony_ci# Directories & files removed with 'make clean' 147562306a36Sopenharmony_ciCLEAN_FILES += vmlinux.symvers modules-only.symvers \ 147662306a36Sopenharmony_ci modules.builtin modules.builtin.modinfo modules.nsdeps \ 147762306a36Sopenharmony_ci compile_commands.json .thinlto-cache rust/test \ 147862306a36Sopenharmony_ci rust-project.json .vmlinux.objs .vmlinux.export.c 147962306a36Sopenharmony_ci 148062306a36Sopenharmony_ci# Directories & files removed with 'make mrproper' 148162306a36Sopenharmony_ciMRPROPER_FILES += include/config include/generated \ 148262306a36Sopenharmony_ci arch/$(SRCARCH)/include/generated .objdiff \ 148362306a36Sopenharmony_ci debian snap tar-install \ 148462306a36Sopenharmony_ci .config .config.old .version \ 148562306a36Sopenharmony_ci Module.symvers \ 148662306a36Sopenharmony_ci certs/signing_key.pem \ 148762306a36Sopenharmony_ci certs/x509.genkey \ 148862306a36Sopenharmony_ci vmlinux-gdb.py \ 148962306a36Sopenharmony_ci kernel.spec rpmbuild \ 149062306a36Sopenharmony_ci rust/libmacros.so 149162306a36Sopenharmony_ci 149262306a36Sopenharmony_ci# clean - Delete most, but leave enough to build external modules 149362306a36Sopenharmony_ci# 149462306a36Sopenharmony_ciclean: rm-files := $(CLEAN_FILES) 149562306a36Sopenharmony_ci 149662306a36Sopenharmony_ciPHONY += archclean vmlinuxclean 149762306a36Sopenharmony_ci 149862306a36Sopenharmony_civmlinuxclean: 149962306a36Sopenharmony_ci $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean 150062306a36Sopenharmony_ci $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean) 150162306a36Sopenharmony_ci 150262306a36Sopenharmony_ciclean: archclean vmlinuxclean resolve_btfids_clean 150362306a36Sopenharmony_ci 150462306a36Sopenharmony_ci# mrproper - Delete all generated files, including .config 150562306a36Sopenharmony_ci# 150662306a36Sopenharmony_cimrproper: rm-files := $(wildcard $(MRPROPER_FILES)) 150762306a36Sopenharmony_cimrproper-dirs := $(addprefix _mrproper_,scripts) 150862306a36Sopenharmony_ci 150962306a36Sopenharmony_ciPHONY += $(mrproper-dirs) mrproper 151062306a36Sopenharmony_ci$(mrproper-dirs): 151162306a36Sopenharmony_ci $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@) 151262306a36Sopenharmony_ci 151362306a36Sopenharmony_cimrproper: clean $(mrproper-dirs) 151462306a36Sopenharmony_ci $(call cmd,rmfiles) 151562306a36Sopenharmony_ci @find . $(RCS_FIND_IGNORE) \ 151662306a36Sopenharmony_ci \( -name '*.rmeta' \) \ 151762306a36Sopenharmony_ci -type f -print | xargs rm -f 151862306a36Sopenharmony_ci 151962306a36Sopenharmony_ci# distclean 152062306a36Sopenharmony_ci# 152162306a36Sopenharmony_ciPHONY += distclean 152262306a36Sopenharmony_ci 152362306a36Sopenharmony_cidistclean: mrproper 152462306a36Sopenharmony_ci @find . $(RCS_FIND_IGNORE) \ 152562306a36Sopenharmony_ci \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ 152662306a36Sopenharmony_ci -o -name '*.bak' -o -name '#*#' -o -name '*%' \ 152762306a36Sopenharmony_ci -o -name 'core' -o -name tags -o -name TAGS -o -name 'cscope*' \ 152862306a36Sopenharmony_ci -o -name GPATH -o -name GRTAGS -o -name GSYMS -o -name GTAGS \) \ 152962306a36Sopenharmony_ci -type f -print | xargs rm -f 153062306a36Sopenharmony_ci 153162306a36Sopenharmony_ci 153262306a36Sopenharmony_ci# Packaging of the kernel to various formats 153362306a36Sopenharmony_ci# --------------------------------------------------------------------------- 153462306a36Sopenharmony_ci 153562306a36Sopenharmony_ci%src-pkg: FORCE 153662306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ 153762306a36Sopenharmony_ci%pkg: include/config/kernel.release FORCE 153862306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ 153962306a36Sopenharmony_ci 154062306a36Sopenharmony_ci# Brief documentation of the typical targets used 154162306a36Sopenharmony_ci# --------------------------------------------------------------------------- 154262306a36Sopenharmony_ci 154362306a36Sopenharmony_ciboards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig) 154462306a36Sopenharmony_ciboards := $(sort $(notdir $(boards))) 154562306a36Sopenharmony_ciboard-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig)) 154662306a36Sopenharmony_ciboard-dirs := $(sort $(notdir $(board-dirs:/=))) 154762306a36Sopenharmony_ci 154862306a36Sopenharmony_ciPHONY += help 154962306a36Sopenharmony_cihelp: 155062306a36Sopenharmony_ci @echo 'Cleaning targets:' 155162306a36Sopenharmony_ci @echo ' clean - Remove most generated files but keep the config and' 155262306a36Sopenharmony_ci @echo ' enough build support to build external modules' 155362306a36Sopenharmony_ci @echo ' mrproper - Remove all generated files + config + various backup files' 155462306a36Sopenharmony_ci @echo ' distclean - mrproper + remove editor backup and patch files' 155562306a36Sopenharmony_ci @echo '' 155662306a36Sopenharmony_ci @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help 155762306a36Sopenharmony_ci @echo '' 155862306a36Sopenharmony_ci @echo 'Other generic targets:' 155962306a36Sopenharmony_ci @echo ' all - Build all targets marked with [*]' 156062306a36Sopenharmony_ci @echo '* vmlinux - Build the bare kernel' 156162306a36Sopenharmony_ci @echo '* modules - Build all modules' 156262306a36Sopenharmony_ci @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)' 156362306a36Sopenharmony_ci @echo ' dir/ - Build all files in dir and below' 156462306a36Sopenharmony_ci @echo ' dir/file.[ois] - Build specified target only' 156562306a36Sopenharmony_ci @echo ' dir/file.ll - Build the LLVM assembly file' 156662306a36Sopenharmony_ci @echo ' (requires compiler support for LLVM assembly generation)' 156762306a36Sopenharmony_ci @echo ' dir/file.lst - Build specified mixed source/assembly target only' 156862306a36Sopenharmony_ci @echo ' (requires a recent binutils and recent build (System.map))' 156962306a36Sopenharmony_ci @echo ' dir/file.ko - Build module including final link' 157062306a36Sopenharmony_ci @echo ' modules_prepare - Set up for building external modules' 157162306a36Sopenharmony_ci @echo ' tags/TAGS - Generate tags file for editors' 157262306a36Sopenharmony_ci @echo ' cscope - Generate cscope index' 157362306a36Sopenharmony_ci @echo ' gtags - Generate GNU GLOBAL index' 157462306a36Sopenharmony_ci @echo ' kernelrelease - Output the release version string (use with make -s)' 157562306a36Sopenharmony_ci @echo ' kernelversion - Output the version stored in Makefile (use with make -s)' 157662306a36Sopenharmony_ci @echo ' image_name - Output the image name (use with make -s)' 157762306a36Sopenharmony_ci @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \ 157862306a36Sopenharmony_ci echo ' (default: $(INSTALL_HDR_PATH))'; \ 157962306a36Sopenharmony_ci echo '' 158062306a36Sopenharmony_ci @echo 'Static analysers:' 158162306a36Sopenharmony_ci @echo ' checkstack - Generate a list of stack hogs' 158262306a36Sopenharmony_ci @echo ' versioncheck - Sanity check on version.h usage' 158362306a36Sopenharmony_ci @echo ' includecheck - Check for duplicate included header files' 158462306a36Sopenharmony_ci @echo ' export_report - List the usages of all exported symbols' 158562306a36Sopenharmony_ci @echo ' headerdep - Detect inclusion cycles in headers' 158662306a36Sopenharmony_ci @echo ' coccicheck - Check with Coccinelle' 158762306a36Sopenharmony_ci @echo ' clang-analyzer - Check with clang static analyzer' 158862306a36Sopenharmony_ci @echo ' clang-tidy - Check with clang-tidy' 158962306a36Sopenharmony_ci @echo '' 159062306a36Sopenharmony_ci @echo 'Tools:' 159162306a36Sopenharmony_ci @echo ' nsdeps - Generate missing symbol namespace dependencies' 159262306a36Sopenharmony_ci @echo '' 159362306a36Sopenharmony_ci @echo 'Kernel selftest:' 159462306a36Sopenharmony_ci @echo ' kselftest - Build and run kernel selftest' 159562306a36Sopenharmony_ci @echo ' Build, install, and boot kernel before' 159662306a36Sopenharmony_ci @echo ' running kselftest on it' 159762306a36Sopenharmony_ci @echo ' Run as root for full coverage' 159862306a36Sopenharmony_ci @echo ' kselftest-all - Build kernel selftest' 159962306a36Sopenharmony_ci @echo ' kselftest-install - Build and install kernel selftest' 160062306a36Sopenharmony_ci @echo ' kselftest-clean - Remove all generated kselftest files' 160162306a36Sopenharmony_ci @echo ' kselftest-merge - Merge all the config dependencies of' 160262306a36Sopenharmony_ci @echo ' kselftest to existing .config.' 160362306a36Sopenharmony_ci @echo '' 160462306a36Sopenharmony_ci @echo 'Rust targets:' 160562306a36Sopenharmony_ci @echo ' rustavailable - Checks whether the Rust toolchain is' 160662306a36Sopenharmony_ci @echo ' available and, if not, explains why.' 160762306a36Sopenharmony_ci @echo ' rustfmt - Reformat all the Rust code in the kernel' 160862306a36Sopenharmony_ci @echo ' rustfmtcheck - Checks if all the Rust code in the kernel' 160962306a36Sopenharmony_ci @echo ' is formatted, printing a diff otherwise.' 161062306a36Sopenharmony_ci @echo ' rustdoc - Generate Rust documentation' 161162306a36Sopenharmony_ci @echo ' (requires kernel .config)' 161262306a36Sopenharmony_ci @echo ' rusttest - Runs the Rust tests' 161362306a36Sopenharmony_ci @echo ' (requires kernel .config; downloads external repos)' 161462306a36Sopenharmony_ci @echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file' 161562306a36Sopenharmony_ci @echo ' (requires kernel .config)' 161662306a36Sopenharmony_ci @echo ' dir/file.[os] - Build specified target only' 161762306a36Sopenharmony_ci @echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.' 161862306a36Sopenharmony_ci @echo ' Run with RUSTFMT=n to skip reformatting if needed.' 161962306a36Sopenharmony_ci @echo ' The output is not intended to be compilable.' 162062306a36Sopenharmony_ci @echo ' dir/file.ll - Build the LLVM assembly file' 162162306a36Sopenharmony_ci @echo '' 162262306a36Sopenharmony_ci @$(if $(dtstree), \ 162362306a36Sopenharmony_ci echo 'Devicetree:'; \ 162462306a36Sopenharmony_ci echo '* dtbs - Build device tree blobs for enabled boards'; \ 162562306a36Sopenharmony_ci echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \ 162662306a36Sopenharmony_ci echo ' dt_binding_check - Validate device tree binding documents'; \ 162762306a36Sopenharmony_ci echo ' dtbs_check - Validate device tree source files';\ 162862306a36Sopenharmony_ci echo '') 162962306a36Sopenharmony_ci 163062306a36Sopenharmony_ci @echo 'Userspace tools targets:' 163162306a36Sopenharmony_ci @echo ' use "make tools/help"' 163262306a36Sopenharmony_ci @echo ' or "cd tools; make help"' 163362306a36Sopenharmony_ci @echo '' 163462306a36Sopenharmony_ci @echo 'Kernel packaging:' 163562306a36Sopenharmony_ci @$(MAKE) -f $(srctree)/scripts/Makefile.package help 163662306a36Sopenharmony_ci @echo '' 163762306a36Sopenharmony_ci @echo 'Documentation targets:' 163862306a36Sopenharmony_ci @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp 163962306a36Sopenharmony_ci @echo '' 164062306a36Sopenharmony_ci @echo 'Architecture specific targets ($(SRCARCH)):' 164162306a36Sopenharmony_ci @$(or $(archhelp),\ 164262306a36Sopenharmony_ci echo ' No architecture specific help defined for $(SRCARCH)') 164362306a36Sopenharmony_ci @echo '' 164462306a36Sopenharmony_ci @$(if $(boards), \ 164562306a36Sopenharmony_ci $(foreach b, $(boards), \ 164662306a36Sopenharmony_ci printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ 164762306a36Sopenharmony_ci echo '') 164862306a36Sopenharmony_ci @$(if $(board-dirs), \ 164962306a36Sopenharmony_ci $(foreach b, $(board-dirs), \ 165062306a36Sopenharmony_ci printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \ 165162306a36Sopenharmony_ci printf " %-16s - Show all of the above\\n" help-boards; \ 165262306a36Sopenharmony_ci echo '') 165362306a36Sopenharmony_ci 165462306a36Sopenharmony_ci @echo ' make V=n [targets] 1: verbose build' 165562306a36Sopenharmony_ci @echo ' 2: give reason for rebuild of target' 165662306a36Sopenharmony_ci @echo ' V=1 and V=2 can be combined with V=12' 165762306a36Sopenharmony_ci @echo ' make O=dir [targets] Locate all output files in "dir", including .config' 165862306a36Sopenharmony_ci @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK' 165962306a36Sopenharmony_ci @echo ' (sparse by default)' 166062306a36Sopenharmony_ci @echo ' make C=2 [targets] Force check of all c source with $$CHECK' 166162306a36Sopenharmony_ci @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections' 166262306a36Sopenharmony_ci @echo ' make W=n [targets] Enable extra build checks, n=1,2,3 where' 166362306a36Sopenharmony_ci @echo ' 1: warnings which may be relevant and do not occur too often' 166462306a36Sopenharmony_ci @echo ' 2: warnings which occur quite often but may still be relevant' 166562306a36Sopenharmony_ci @echo ' 3: more obscure warnings, can most likely be ignored' 166662306a36Sopenharmony_ci @echo ' e: warnings are being treated as errors' 166762306a36Sopenharmony_ci @echo ' Multiple levels can be combined with W=12 or W=123' 166862306a36Sopenharmony_ci @$(if $(dtstree), \ 166962306a36Sopenharmony_ci echo ' make CHECK_DTBS=1 [targets] Check all generated dtb files against schema'; \ 167062306a36Sopenharmony_ci echo ' This can be applied both to "dtbs" and to individual "foo.dtb" targets' ; \ 167162306a36Sopenharmony_ci ) 167262306a36Sopenharmony_ci @echo '' 167362306a36Sopenharmony_ci @echo 'Execute "make" or "make all" to build all targets marked with [*] ' 167462306a36Sopenharmony_ci @echo 'For further info see the ./README file' 167562306a36Sopenharmony_ci 167662306a36Sopenharmony_ci 167762306a36Sopenharmony_cihelp-board-dirs := $(addprefix help-,$(board-dirs)) 167862306a36Sopenharmony_ci 167962306a36Sopenharmony_cihelp-boards: $(help-board-dirs) 168062306a36Sopenharmony_ci 168162306a36Sopenharmony_ciboards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig))) 168262306a36Sopenharmony_ci 168362306a36Sopenharmony_ci$(help-board-dirs): help-%: 168462306a36Sopenharmony_ci @echo 'Architecture specific targets ($(SRCARCH) $*):' 168562306a36Sopenharmony_ci @$(if $(boards-per-dir), \ 168662306a36Sopenharmony_ci $(foreach b, $(boards-per-dir), \ 168762306a36Sopenharmony_ci printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \ 168862306a36Sopenharmony_ci echo '') 168962306a36Sopenharmony_ci 169062306a36Sopenharmony_ci 169162306a36Sopenharmony_ci# Documentation targets 169262306a36Sopenharmony_ci# --------------------------------------------------------------------------- 169362306a36Sopenharmony_ciDOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ 169462306a36Sopenharmony_ci linkcheckdocs dochelp refcheckdocs texinfodocs infodocs 169562306a36Sopenharmony_ciPHONY += $(DOC_TARGETS) 169662306a36Sopenharmony_ci$(DOC_TARGETS): 169762306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=Documentation $@ 169862306a36Sopenharmony_ci 169962306a36Sopenharmony_ci 170062306a36Sopenharmony_ci# Rust targets 170162306a36Sopenharmony_ci# --------------------------------------------------------------------------- 170262306a36Sopenharmony_ci 170362306a36Sopenharmony_ci# "Is Rust available?" target 170462306a36Sopenharmony_ciPHONY += rustavailable 170562306a36Sopenharmony_cirustavailable: 170662306a36Sopenharmony_ci $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh && echo "Rust is available!" 170762306a36Sopenharmony_ci 170862306a36Sopenharmony_ci# Documentation target 170962306a36Sopenharmony_ci# 171062306a36Sopenharmony_ci# Using the singular to avoid running afoul of `no-dot-config-targets`. 171162306a36Sopenharmony_ciPHONY += rustdoc 171262306a36Sopenharmony_cirustdoc: prepare 171362306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=rust $@ 171462306a36Sopenharmony_ci 171562306a36Sopenharmony_ci# Testing target 171662306a36Sopenharmony_ciPHONY += rusttest 171762306a36Sopenharmony_cirusttest: prepare 171862306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=rust $@ 171962306a36Sopenharmony_ci 172062306a36Sopenharmony_ci# Formatting targets 172162306a36Sopenharmony_ciPHONY += rustfmt rustfmtcheck 172262306a36Sopenharmony_ci 172362306a36Sopenharmony_ci# We skip `rust/alloc` since we want to minimize the diff w.r.t. upstream. 172462306a36Sopenharmony_ci# 172562306a36Sopenharmony_ci# We match using absolute paths since `find` does not resolve them 172662306a36Sopenharmony_ci# when matching, which is a problem when e.g. `srctree` is `..`. 172762306a36Sopenharmony_ci# We `grep` afterwards in order to remove the directory entry itself. 172862306a36Sopenharmony_cirustfmt: 172962306a36Sopenharmony_ci $(Q)find $(abs_srctree) -type f -name '*.rs' \ 173062306a36Sopenharmony_ci -o -path $(abs_srctree)/rust/alloc -prune \ 173162306a36Sopenharmony_ci -o -path $(abs_objtree)/rust/test -prune \ 173262306a36Sopenharmony_ci | grep -Fv $(abs_srctree)/rust/alloc \ 173362306a36Sopenharmony_ci | grep -Fv $(abs_objtree)/rust/test \ 173462306a36Sopenharmony_ci | grep -Fv generated \ 173562306a36Sopenharmony_ci | xargs $(RUSTFMT) $(rustfmt_flags) 173662306a36Sopenharmony_ci 173762306a36Sopenharmony_cirustfmtcheck: rustfmt_flags = --check 173862306a36Sopenharmony_cirustfmtcheck: rustfmt 173962306a36Sopenharmony_ci 174062306a36Sopenharmony_ci# Misc 174162306a36Sopenharmony_ci# --------------------------------------------------------------------------- 174262306a36Sopenharmony_ci 174362306a36Sopenharmony_ciPHONY += misc-check 174462306a36Sopenharmony_cimisc-check: 174562306a36Sopenharmony_ci $(Q)$(srctree)/scripts/misc-check 174662306a36Sopenharmony_ci 174762306a36Sopenharmony_ciall: misc-check 174862306a36Sopenharmony_ci 174962306a36Sopenharmony_ciPHONY += scripts_gdb 175062306a36Sopenharmony_ciscripts_gdb: prepare0 175162306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=scripts/gdb 175262306a36Sopenharmony_ci $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py) 175362306a36Sopenharmony_ci 175462306a36Sopenharmony_ciifdef CONFIG_GDB_SCRIPTS 175562306a36Sopenharmony_ciall: scripts_gdb 175662306a36Sopenharmony_ciendif 175762306a36Sopenharmony_ci 175862306a36Sopenharmony_cielse # KBUILD_EXTMOD 175962306a36Sopenharmony_ci 176062306a36Sopenharmony_cifilechk_kernel.release = echo $(KERNELRELEASE) 176162306a36Sopenharmony_ci 176262306a36Sopenharmony_ci### 176362306a36Sopenharmony_ci# External module support. 176462306a36Sopenharmony_ci# When building external modules the kernel used as basis is considered 176562306a36Sopenharmony_ci# read-only, and no consistency checks are made and the make 176662306a36Sopenharmony_ci# system is not used on the basis kernel. If updates are required 176762306a36Sopenharmony_ci# in the basis kernel ordinary make commands (without M=...) must be used. 176862306a36Sopenharmony_ci 176962306a36Sopenharmony_ci# We are always building only modules. 177062306a36Sopenharmony_ciKBUILD_BUILTIN := 177162306a36Sopenharmony_ciKBUILD_MODULES := 1 177262306a36Sopenharmony_ci 177362306a36Sopenharmony_cibuild-dir := $(KBUILD_EXTMOD) 177462306a36Sopenharmony_ci 177562306a36Sopenharmony_cicompile_commands.json: $(extmod_prefix)compile_commands.json 177662306a36Sopenharmony_ciPHONY += compile_commands.json 177762306a36Sopenharmony_ci 177862306a36Sopenharmony_ciclean-dirs := $(KBUILD_EXTMOD) 177962306a36Sopenharmony_ciclean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \ 178062306a36Sopenharmony_ci $(KBUILD_EXTMOD)/compile_commands.json $(KBUILD_EXTMOD)/.thinlto-cache 178162306a36Sopenharmony_ci 178262306a36Sopenharmony_ciPHONY += prepare 178362306a36Sopenharmony_ci# now expand this into a simple variable to reduce the cost of shell evaluations 178462306a36Sopenharmony_ciprepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT) 178562306a36Sopenharmony_ciprepare: 178662306a36Sopenharmony_ci @if [ "$(CC_VERSION_TEXT)" != "$(CONFIG_CC_VERSION_TEXT)" ]; then \ 178762306a36Sopenharmony_ci echo >&2 "warning: the compiler differs from the one used to build the kernel"; \ 178862306a36Sopenharmony_ci echo >&2 " The kernel was built by: $(CONFIG_CC_VERSION_TEXT)"; \ 178962306a36Sopenharmony_ci echo >&2 " You are using: $(CC_VERSION_TEXT)"; \ 179062306a36Sopenharmony_ci fi 179162306a36Sopenharmony_ci 179262306a36Sopenharmony_ciPHONY += help 179362306a36Sopenharmony_cihelp: 179462306a36Sopenharmony_ci @echo ' Building external modules.' 179562306a36Sopenharmony_ci @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target' 179662306a36Sopenharmony_ci @echo '' 179762306a36Sopenharmony_ci @echo ' modules - default target, build the module(s)' 179862306a36Sopenharmony_ci @echo ' modules_install - install the module' 179962306a36Sopenharmony_ci @echo ' clean - remove generated files in module directory only' 180062306a36Sopenharmony_ci @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file' 180162306a36Sopenharmony_ci @echo '' 180262306a36Sopenharmony_ci 180362306a36Sopenharmony_ciifndef CONFIG_MODULES 180462306a36Sopenharmony_cimodules modules_install: __external_modules_error 180562306a36Sopenharmony_ci__external_modules_error: 180662306a36Sopenharmony_ci @echo >&2 '***' 180762306a36Sopenharmony_ci @echo >&2 '*** The present kernel disabled CONFIG_MODULES.' 180862306a36Sopenharmony_ci @echo >&2 '*** You cannot build or install external modules.' 180962306a36Sopenharmony_ci @echo >&2 '***' 181062306a36Sopenharmony_ci @false 181162306a36Sopenharmony_ciendif 181262306a36Sopenharmony_ci 181362306a36Sopenharmony_ciendif # KBUILD_EXTMOD 181462306a36Sopenharmony_ci 181562306a36Sopenharmony_ci# --------------------------------------------------------------------------- 181662306a36Sopenharmony_ci# Modules 181762306a36Sopenharmony_ci 181862306a36Sopenharmony_ciPHONY += modules modules_install modules_sign modules_prepare 181962306a36Sopenharmony_ci 182062306a36Sopenharmony_cimodules_install: 182162306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \ 182262306a36Sopenharmony_ci sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y) 182362306a36Sopenharmony_ci 182462306a36Sopenharmony_ciifeq ($(CONFIG_MODULE_SIG),y) 182562306a36Sopenharmony_ci# modules_sign is a subset of modules_install. 182662306a36Sopenharmony_ci# 'make modules_install modules_sign' is equivalent to 'make modules_install'. 182762306a36Sopenharmony_cimodules_sign: modules_install 182862306a36Sopenharmony_ci @: 182962306a36Sopenharmony_cielse 183062306a36Sopenharmony_cimodules_sign: 183162306a36Sopenharmony_ci @echo >&2 '***' 183262306a36Sopenharmony_ci @echo >&2 '*** CONFIG_MODULE_SIG is disabled. You cannot sign modules.' 183362306a36Sopenharmony_ci @echo >&2 '***' 183462306a36Sopenharmony_ci @false 183562306a36Sopenharmony_ciendif 183662306a36Sopenharmony_ci 183762306a36Sopenharmony_ciifdef CONFIG_MODULES 183862306a36Sopenharmony_ci 183962306a36Sopenharmony_ci$(MODORDER): $(build-dir) 184062306a36Sopenharmony_ci @: 184162306a36Sopenharmony_ci 184262306a36Sopenharmony_ci# KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. 184362306a36Sopenharmony_ci# This is solely useful to speed up test compiles. 184462306a36Sopenharmony_cimodules: modpost 184562306a36Sopenharmony_ciifneq ($(KBUILD_MODPOST_NOFINAL),1) 184662306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal 184762306a36Sopenharmony_ciendif 184862306a36Sopenharmony_ci 184962306a36Sopenharmony_ciPHONY += modules_check 185062306a36Sopenharmony_cimodules_check: $(MODORDER) 185162306a36Sopenharmony_ci $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< 185262306a36Sopenharmony_ci 185362306a36Sopenharmony_cielse # CONFIG_MODULES 185462306a36Sopenharmony_ci 185562306a36Sopenharmony_cimodules: 185662306a36Sopenharmony_ci @: 185762306a36Sopenharmony_ci 185862306a36Sopenharmony_ciKBUILD_MODULES := 185962306a36Sopenharmony_ci 186062306a36Sopenharmony_ciendif # CONFIG_MODULES 186162306a36Sopenharmony_ci 186262306a36Sopenharmony_ciPHONY += modpost 186362306a36Sopenharmony_cimodpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \ 186462306a36Sopenharmony_ci $(if $(KBUILD_MODULES), modules_check) 186562306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 186662306a36Sopenharmony_ci 186762306a36Sopenharmony_ci# Single targets 186862306a36Sopenharmony_ci# --------------------------------------------------------------------------- 186962306a36Sopenharmony_ci# To build individual files in subdirectories, you can do like this: 187062306a36Sopenharmony_ci# 187162306a36Sopenharmony_ci# make foo/bar/baz.s 187262306a36Sopenharmony_ci# 187362306a36Sopenharmony_ci# The supported suffixes for single-target are listed in 'single-targets' 187462306a36Sopenharmony_ci# 187562306a36Sopenharmony_ci# To build only under specific subdirectories, you can do like this: 187662306a36Sopenharmony_ci# 187762306a36Sopenharmony_ci# make foo/bar/baz/ 187862306a36Sopenharmony_ci 187962306a36Sopenharmony_ciifdef single-build 188062306a36Sopenharmony_ci 188162306a36Sopenharmony_ci# .ko is special because modpost is needed 188262306a36Sopenharmony_cisingle-ko := $(sort $(filter %.ko, $(MAKECMDGOALS))) 188362306a36Sopenharmony_cisingle-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \ 188462306a36Sopenharmony_ci $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko))) 188562306a36Sopenharmony_ci 188662306a36Sopenharmony_ci$(single-ko): single_modules 188762306a36Sopenharmony_ci @: 188862306a36Sopenharmony_ci$(single-no-ko): $(build-dir) 188962306a36Sopenharmony_ci @: 189062306a36Sopenharmony_ci 189162306a36Sopenharmony_ci# Remove MODORDER when done because it is not the real one. 189262306a36Sopenharmony_ciPHONY += single_modules 189362306a36Sopenharmony_cisingle_modules: $(single-no-ko) modules_prepare 189462306a36Sopenharmony_ci $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$(m:%.ko=%.o);) } > $(MODORDER) 189562306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 189662306a36Sopenharmony_ciifneq ($(KBUILD_MODPOST_NOFINAL),1) 189762306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal 189862306a36Sopenharmony_ciendif 189962306a36Sopenharmony_ci $(Q)rm -f $(MODORDER) 190062306a36Sopenharmony_ci 190162306a36Sopenharmony_cisingle-goals := $(addprefix $(build-dir)/, $(single-no-ko)) 190262306a36Sopenharmony_ci 190362306a36Sopenharmony_ciKBUILD_MODULES := 1 190462306a36Sopenharmony_ci 190562306a36Sopenharmony_ciendif 190662306a36Sopenharmony_ci 190762306a36Sopenharmony_ci# Preset locale variables to speed up the build process. Limit locale 190862306a36Sopenharmony_ci# tweaks to this spot to avoid wrong language settings when running 190962306a36Sopenharmony_ci# make menuconfig etc. 191062306a36Sopenharmony_ci# Error messages still appears in the original language 191162306a36Sopenharmony_ciPHONY += $(build-dir) 191262306a36Sopenharmony_ci$(build-dir): prepare 191362306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals) 191462306a36Sopenharmony_ci 191562306a36Sopenharmony_ciclean-dirs := $(addprefix _clean_, $(clean-dirs)) 191662306a36Sopenharmony_ciPHONY += $(clean-dirs) clean 191762306a36Sopenharmony_ci$(clean-dirs): 191862306a36Sopenharmony_ci $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) 191962306a36Sopenharmony_ci 192062306a36Sopenharmony_ciclean: $(clean-dirs) 192162306a36Sopenharmony_ci $(call cmd,rmfiles) 192262306a36Sopenharmony_ci @find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ 192362306a36Sopenharmony_ci \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \ 192462306a36Sopenharmony_ci -o -name '*.ko.*' \ 192562306a36Sopenharmony_ci -o -name '*.dtb' -o -name '*.dtbo' \ 192662306a36Sopenharmony_ci -o -name '*.dtb.S' -o -name '*.dtbo.S' \ 192762306a36Sopenharmony_ci -o -name '*.dt.yaml' \ 192862306a36Sopenharmony_ci -o -name '*.dwo' -o -name '*.lst' \ 192962306a36Sopenharmony_ci -o -name '*.su' -o -name '*.mod' \ 193062306a36Sopenharmony_ci -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 193162306a36Sopenharmony_ci -o -name '*.lex.c' -o -name '*.tab.[ch]' \ 193262306a36Sopenharmony_ci -o -name '*.asn1.[ch]' \ 193362306a36Sopenharmony_ci -o -name '*.symtypes' -o -name 'modules.order' \ 193462306a36Sopenharmony_ci -o -name '*.c.[012]*.*' \ 193562306a36Sopenharmony_ci -o -name '*.ll' \ 193662306a36Sopenharmony_ci -o -name '*.gcno' \ 193762306a36Sopenharmony_ci -o -name '*.*.symversions' \) -type f -print \ 193862306a36Sopenharmony_ci -o -name '.tmp_*' -print \ 193962306a36Sopenharmony_ci | xargs rm -rf 194062306a36Sopenharmony_ci 194162306a36Sopenharmony_ci# Generate tags for editors 194262306a36Sopenharmony_ci# --------------------------------------------------------------------------- 194362306a36Sopenharmony_ciquiet_cmd_tags = GEN $@ 194462306a36Sopenharmony_ci cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@ 194562306a36Sopenharmony_ci 194662306a36Sopenharmony_citags TAGS cscope gtags: FORCE 194762306a36Sopenharmony_ci $(call cmd,tags) 194862306a36Sopenharmony_ci 194962306a36Sopenharmony_ci# IDE support targets 195062306a36Sopenharmony_ciPHONY += rust-analyzer 195162306a36Sopenharmony_cirust-analyzer: 195262306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=rust $@ 195362306a36Sopenharmony_ci 195462306a36Sopenharmony_ci# Script to generate missing namespace dependencies 195562306a36Sopenharmony_ci# --------------------------------------------------------------------------- 195662306a36Sopenharmony_ci 195762306a36Sopenharmony_ciPHONY += nsdeps 195862306a36Sopenharmony_cinsdeps: export KBUILD_NSDEPS=1 195962306a36Sopenharmony_cinsdeps: modules 196062306a36Sopenharmony_ci $(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps 196162306a36Sopenharmony_ci 196262306a36Sopenharmony_ci# Clang Tooling 196362306a36Sopenharmony_ci# --------------------------------------------------------------------------- 196462306a36Sopenharmony_ci 196562306a36Sopenharmony_ciquiet_cmd_gen_compile_commands = GEN $@ 196662306a36Sopenharmony_ci cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs)) 196762306a36Sopenharmony_ci 196862306a36Sopenharmony_ci$(extmod_prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \ 196962306a36Sopenharmony_ci $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \ 197062306a36Sopenharmony_ci $(if $(CONFIG_MODULES), $(MODORDER)) FORCE 197162306a36Sopenharmony_ci $(call if_changed,gen_compile_commands) 197262306a36Sopenharmony_ci 197362306a36Sopenharmony_citargets += $(extmod_prefix)compile_commands.json 197462306a36Sopenharmony_ci 197562306a36Sopenharmony_ciPHONY += clang-tidy clang-analyzer 197662306a36Sopenharmony_ci 197762306a36Sopenharmony_ciifdef CONFIG_CC_IS_CLANG 197862306a36Sopenharmony_ciquiet_cmd_clang_tools = CHECK $< 197962306a36Sopenharmony_ci cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $< 198062306a36Sopenharmony_ci 198162306a36Sopenharmony_ciclang-tidy clang-analyzer: $(extmod_prefix)compile_commands.json 198262306a36Sopenharmony_ci $(call cmd,clang_tools) 198362306a36Sopenharmony_cielse 198462306a36Sopenharmony_ciclang-tidy clang-analyzer: 198562306a36Sopenharmony_ci @echo "$@ requires CC=clang" >&2 198662306a36Sopenharmony_ci @false 198762306a36Sopenharmony_ciendif 198862306a36Sopenharmony_ci 198962306a36Sopenharmony_ci# Scripts to check various things for consistency 199062306a36Sopenharmony_ci# --------------------------------------------------------------------------- 199162306a36Sopenharmony_ci 199262306a36Sopenharmony_ciPHONY += includecheck versioncheck coccicheck export_report 199362306a36Sopenharmony_ci 199462306a36Sopenharmony_ciincludecheck: 199562306a36Sopenharmony_ci find $(srctree)/* $(RCS_FIND_IGNORE) \ 199662306a36Sopenharmony_ci -name '*.[hcS]' -type f -print | sort \ 199762306a36Sopenharmony_ci | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl 199862306a36Sopenharmony_ci 199962306a36Sopenharmony_civersioncheck: 200062306a36Sopenharmony_ci find $(srctree)/* $(RCS_FIND_IGNORE) \ 200162306a36Sopenharmony_ci -name '*.[hcS]' -type f -print | sort \ 200262306a36Sopenharmony_ci | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl 200362306a36Sopenharmony_ci 200462306a36Sopenharmony_cicoccicheck: 200562306a36Sopenharmony_ci $(Q)$(BASH) $(srctree)/scripts/$@ 200662306a36Sopenharmony_ci 200762306a36Sopenharmony_ciexport_report: 200862306a36Sopenharmony_ci $(PERL) $(srctree)/scripts/export_report.pl 200962306a36Sopenharmony_ci 201062306a36Sopenharmony_ciPHONY += checkstack kernelrelease kernelversion image_name 201162306a36Sopenharmony_ci 201262306a36Sopenharmony_ci# UML needs a little special treatment here. It wants to use the host 201362306a36Sopenharmony_ci# toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone 201462306a36Sopenharmony_ci# else wants $(ARCH), including people doing cross-builds, which means 201562306a36Sopenharmony_ci# that $(SUBARCH) doesn't work here. 201662306a36Sopenharmony_ciifeq ($(ARCH), um) 201762306a36Sopenharmony_ciCHECKSTACK_ARCH := $(SUBARCH) 201862306a36Sopenharmony_cielse 201962306a36Sopenharmony_ciCHECKSTACK_ARCH := $(ARCH) 202062306a36Sopenharmony_ciendif 202162306a36Sopenharmony_cicheckstack: 202262306a36Sopenharmony_ci $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \ 202362306a36Sopenharmony_ci $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) 202462306a36Sopenharmony_ci 202562306a36Sopenharmony_cikernelrelease: 202662306a36Sopenharmony_ci @$(filechk_kernel.release) 202762306a36Sopenharmony_ci 202862306a36Sopenharmony_cikernelversion: 202962306a36Sopenharmony_ci @echo $(KERNELVERSION) 203062306a36Sopenharmony_ci 203162306a36Sopenharmony_ciimage_name: 203262306a36Sopenharmony_ci @echo $(KBUILD_IMAGE) 203362306a36Sopenharmony_ci 203462306a36Sopenharmony_ciPHONY += run-command 203562306a36Sopenharmony_cirun-command: 203662306a36Sopenharmony_ci $(Q)$(KBUILD_RUN_COMMAND) 203762306a36Sopenharmony_ci 203862306a36Sopenharmony_ciquiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) 203962306a36Sopenharmony_ci cmd_rmfiles = rm -rf $(rm-files) 204062306a36Sopenharmony_ci 204162306a36Sopenharmony_ci# read saved command lines for existing targets 204262306a36Sopenharmony_ciexisting-targets := $(wildcard $(sort $(targets))) 204362306a36Sopenharmony_ci 204462306a36Sopenharmony_ci-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 204562306a36Sopenharmony_ci 204662306a36Sopenharmony_ciendif # config-build 204762306a36Sopenharmony_ciendif # mixed-build 204862306a36Sopenharmony_ciendif # need-sub-make 204962306a36Sopenharmony_ci 205062306a36Sopenharmony_ciPHONY += FORCE 205162306a36Sopenharmony_ciFORCE: 205262306a36Sopenharmony_ci 205362306a36Sopenharmony_ci# Declare the contents of the PHONY variable as phony. We keep that 205462306a36Sopenharmony_ci# information in a variable so we can use it in if_changed and friends. 205562306a36Sopenharmony_ci.PHONY: $(PHONY) 2056