Linus TorvaldsLinux 5.4219d5436 years agoHistory
1828 lines · 59.5 KB · Makefile
RawDownload
# SPDX-License-Identifier: GPL-2.0VERSION = 5PATCHLEVEL = 4SUBLEVEL = 0EXTRAVERSION =NAME = Kleptomaniac Octopus # *DOCUMENTATION*# To see a list of typical targets execute "make help"# More info can be located in ./README# Comments in this file are targeted only to the developer, do not# expect to learn how to build the kernel reading this file. # That's our default target when none is given on the command linePHONY := _all_all: # We are using a recursive build, so we need to do a little thinking# to get the ordering right.## Most importantly: sub-Makefiles should only ever modify files in# their own directory. If in some directory we have a dependency on# a file in another dir (which doesn't happen often, but it's often# unavoidable when linking the built-in.a targets which finally# turn into vmlinux), we will call a sub make in that other dir, and# after that we are sure that everything which is in that other dir# is now up to date.## The only cases where we need to modify files which have global# effects are thus separated out and done before the recursive# descending is started. They are now explicitly listed as the# prepare rule. ifneq ($(sub_make_done),1) # Do not use make's built-in rules and variables# (this increases performance and avoids hard-to-debug behaviour)MAKEFLAGS += -rR # Avoid funny character set dependenciesunexport LC_ALLLC_COLLATE=CLC_NUMERIC=Cexport LC_COLLATE LC_NUMERIC # Avoid interference with shell env settingsunexport GREP_OPTIONS # Beautify output# ---------------------------------------------------------------------------## Normally, we echo the whole command before executing it. By making# that echo $($(quiet)$(cmd)), we now have the possibility to set# $(quiet) to choose other forms of output instead, e.g.##         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<## If $(quiet) is empty, the whole command will be printed.# If it is set to "quiet_", only the short version will be printed.# If it is set to "silent_", nothing will be printed at all, since# the variable $(silent_cmd_cc_o_c) doesn't exist.## A simple variant is to prefix commands with $(Q) - that's useful# for commands that shall be hidden in non-verbose mode.##	$(Q)ln $@ :<## If KBUILD_VERBOSE equals 0 then the above command will be hidden.# If KBUILD_VERBOSE equals 1 then the above command is displayed.## To put more focus on warnings, be less verbose as default# Use 'make V=1' to see the full commands ifeq ("$(origin V)", "command line")  KBUILD_VERBOSE = $(V)endififndef KBUILD_VERBOSE  KBUILD_VERBOSE = 0endif ifeq ($(KBUILD_VERBOSE),1)  quiet =  Q =else  quiet=quiet_  Q = @endif # If the user is running make -s (silent mode), suppress echoing of# commands ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)  quiet=silent_endif export quiet Q KBUILD_VERBOSE # Kbuild will save output files in the current working directory.# This does not need to match to the root of the kernel source tree.## For example, you can do this:##  cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile## If you want to save output files in a different location, there are# two syntaxes to specify it.## 1) O=# Use "make O=dir/to/store/output/files/"## 2) Set KBUILD_OUTPUT# Set the environment variable KBUILD_OUTPUT to point to the output directory.# export KBUILD_OUTPUT=dir/to/store/output/files/; make## The O= assignment takes precedence over the KBUILD_OUTPUT environment# variable. # Do we want to change the working directory?ifeq ("$(origin O)", "command line")  KBUILD_OUTPUT := $(O)endif ifneq ($(KBUILD_OUTPUT),)# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot# expand a shell special character '~'. We use a somewhat tedious way here.abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)$(if $(abs_objtree),, \     $(error failed to create output directory "$(KBUILD_OUTPUT)")) # $(realpath ...) resolves symlinksabs_objtree := $(realpath $(abs_objtree))elseabs_objtree := $(CURDIR)endif # ifneq ($(KBUILD_OUTPUT),) ifeq ($(abs_objtree),$(CURDIR))# Suppress "Entering directory ..." unless we are changing the work directory.MAKEFLAGS += --no-print-directoryelseneed-sub-make := 1endif abs_srctree := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) ifneq ($(words $(subst :, ,$(abs_srctree))), 1)$(error source directory cannot contain spaces or colons)endif ifneq ($(abs_srctree),$(abs_objtree))# Look for make include files relative to root of kernel src## This does not become effective immediately because MAKEFLAGS is re-parsed# once after the Makefile is read. We need to invoke sub-make.MAKEFLAGS += --include-dir=$(abs_srctree)need-sub-make := 1endif ifneq ($(filter 3.%,$(MAKE_VERSION)),)# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x# We need to invoke sub-make to avoid implicit rules in the top Makefile.need-sub-make := 1# Cancel implicit rules for this Makefile.$(lastword $(MAKEFILE_LIST)): ;endif export abs_srctree abs_objtreeexport sub_make_done := 1 ifeq ($(need-sub-make),1) PHONY += $(MAKECMDGOALS) sub-make $(filter-out _all sub-make $(lastword $(MAKEFILE_LIST)), $(MAKECMDGOALS)) _all: sub-make	@: # Invoke a second make in the output directory, passing relevant variablessub-make:	$(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS) endif # need-sub-makeendif # sub_make_done # We process the rest of the Makefile if this is the final invocation of makeifeq ($(need-sub-make),) # Do not print "Entering directory ...",# but we want to display it when entering to the output directory# so that IDEs/editors are able to understand relative filenames.MAKEFLAGS += --no-print-directory # Call a source code checker (by default, "sparse") as part of the# C compilation.## Use 'make C=1' to enable checking of only re-compiled files.# Use 'make C=2' to enable checking of *all* source files, regardless# of whether they are re-compiled or not.## See the file "Documentation/dev-tools/sparse.rst" for more details,# including where to get the "sparse" utility. ifeq ("$(origin C)", "command line")  KBUILD_CHECKSRC = $(C)endififndef KBUILD_CHECKSRC  KBUILD_CHECKSRC = 0endif # Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the# directory of external module to build. Setting M= takes precedence.ifeq ("$(origin M)", "command line")  KBUILD_EXTMOD := $(M)endif export KBUILD_CHECKSRC KBUILD_EXTMOD extmod-prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) ifeq ($(abs_srctree),$(abs_objtree))        # building in the source tree        srctree := .	building_out_of_srctree :=else        ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))                # building in a subdirectory of the source tree                srctree := ..        else                srctree := $(abs_srctree)        endif	building_out_of_srctree := 1endif ifneq ($(KBUILD_ABS_SRCTREE),)srctree := $(abs_srctree)endif objtree		:= .VPATH		:= $(srctree) export building_out_of_srctree srctree objtree VPATH # To make sure we do not include .config for any of the *config targets# catch them early, and hand them over to scripts/kconfig/Makefile# It is allowed to specify more targets when calling make, including# mixing *config targets and build targets.# For example 'make oldconfig all'.# Detect when mixed targets is specified, and make a second invocation# of make so .config is not included in this case either (for *config). version_h := include/generated/uapi/linux/version.hold_version_h := include/linux/version.h clean-targets := %clean mrproper cleandocsno-dot-config-targets := $(clean-targets) \			 cscope gtags TAGS tags help% %docs check% coccicheck \			 $(version_h) headers headers_% archheaders archscripts \			 %asm-generic kernelversion %src-pkgno-sync-config-targets := $(no-dot-config-targets) install %install \			   kernelreleasesingle-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/ config-build	:=mixed-build	:=need-config	:= 1may-sync-config	:= 1single-build	:= ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)		need-config :=	endifendif ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)	ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)		may-sync-config :=	endifendif ifneq ($(KBUILD_EXTMOD),)	may-sync-config :=endif ifeq ($(KBUILD_EXTMOD),)        ifneq ($(filter config %config,$(MAKECMDGOALS)),)		config-build := 1                ifneq ($(words $(MAKECMDGOALS)),1)			mixed-build := 1                endif        endifendif # We cannot build single targets and the others at the same timeifneq ($(filter $(single-targets), $(MAKECMDGOALS)),)	single-build := 1	ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),)		mixed-build := 1	endifendif # For "make -j clean all", "make -j mrproper defconfig all", etc.ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)        ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)		mixed-build := 1        endifendif # install and modules_install need also be processed one by oneifneq ($(filter install,$(MAKECMDGOALS)),)        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)		mixed-build := 1        endifendif ifdef mixed-build# ===========================================================================# We're called with mixed targets (*config and build targets).# Handle them one by one. PHONY += $(MAKECMDGOALS) __build_one_by_one $(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one	@: __build_one_by_one:	$(Q)set -e; \	for i in $(MAKECMDGOALS); do \		$(MAKE) -f $(srctree)/Makefile $$i; \	done else # !mixed-build include scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists)KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION include scripts/subarch.include # Cross compiling and selecting different set of gcc/bin-utils# ---------------------------------------------------------------------------## When performing cross compilation for other architectures ARCH shall be set# to the target architecture. (See arch/* for the possibilities).# ARCH can be set during invocation of make:# make ARCH=ia64# Another way is to have ARCH set in the environment.# The default ARCH is the host where make is executed. # CROSS_COMPILE specify the prefix used for all executables used# during compilation. Only gcc and related bin-utils executables# are prefixed with $(CROSS_COMPILE).# CROSS_COMPILE can be set on the command line# make CROSS_COMPILE=ia64-linux-# Alternatively CROSS_COMPILE can be set in the environment.# Default value for CROSS_COMPILE is not to prefix executables# Note: Some architectures assign CROSS_COMPILE in their arch/*/MakefileARCH		?= $(SUBARCH) # Architecture as present in compile.hUTS_MACHINE 	:= $(ARCH)SRCARCH 	:= $(ARCH) # Additional ARCH settings for x86ifeq ($(ARCH),i386)        SRCARCH := x86endififeq ($(ARCH),x86_64)        SRCARCH := x86endif # Additional ARCH settings for sparcifeq ($(ARCH),sparc32)       SRCARCH := sparcendififeq ($(ARCH),sparc64)       SRCARCH := sparcendif # Additional ARCH settings for shifeq ($(ARCH),sh64)       SRCARCH := shendif KCONFIG_CONFIG	?= .configexport KCONFIG_CONFIG # SHELL used by kbuildCONFIG_SHELL := sh HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null) HOSTCC       = gccHOSTCXX      = g++KBUILD_HOSTCFLAGS   := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \		-fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \		$(HOSTCFLAGS)KBUILD_HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)KBUILD_HOSTLDFLAGS  := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)KBUILD_HOSTLDLIBS   := $(HOST_LFS_LIBS) $(HOSTLDLIBS) # Make variables (CC, etc...)AS		= $(CROSS_COMPILE)asLD		= $(CROSS_COMPILE)ldCC		= $(CROSS_COMPILE)gccCPP		= $(CC) -EAR		= $(CROSS_COMPILE)arNM		= $(CROSS_COMPILE)nmSTRIP		= $(CROSS_COMPILE)stripOBJCOPY		= $(CROSS_COMPILE)objcopyOBJDUMP		= $(CROSS_COMPILE)objdumpOBJSIZE		= $(CROSS_COMPILE)sizePAHOLE		= paholeLEX		= flexYACC		= bisonAWK		= awkINSTALLKERNEL  := installkernelDEPMOD		= /sbin/depmodPERL		= perlPYTHON		= pythonPYTHON2		= python2PYTHON3		= python3CHECK		= sparseBASH		= bash CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \		  -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)NOSTDINC_FLAGS :=CFLAGS_MODULE   =AFLAGS_MODULE   =LDFLAGS_MODULE  =CFLAGS_KERNEL	=AFLAGS_KERNEL	=LDFLAGS_vmlinux = # Use USERINCLUDE when you must reference the UAPI directories only.USERINCLUDE    := \		-I$(srctree)/arch/$(SRCARCH)/include/uapi \		-I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \		-I$(srctree)/include/uapi \		-I$(objtree)/include/generated/uapi \                -include $(srctree)/include/linux/kconfig.h # Use LINUXINCLUDE when you must reference the include/ directory.# Needed to be compatible with the O= optionLINUXINCLUDE    := \		-I$(srctree)/arch/$(SRCARCH)/include \		-I$(objtree)/arch/$(SRCARCH)/include/generated \		$(if $(building_out_of_srctree),-I$(srctree)/include) \		-I$(objtree)/include \		$(USERINCLUDE) KBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-PIEKBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \		   -Werror=implicit-function-declaration -Werror=implicit-int \		   -Wno-format-security \		   -std=gnu89KBUILD_CPPFLAGS := -D__KERNEL__KBUILD_AFLAGS_KERNEL :=KBUILD_CFLAGS_KERNEL :=KBUILD_AFLAGS_MODULE  := -DMODULEKBUILD_CFLAGS_MODULE  := -DMODULEKBUILD_LDFLAGS_MODULE :=export KBUILD_LDS_MODULE := $(srctree)/scripts/module-common.ldsKBUILD_LDFLAGS :=GCC_PLUGINS_CFLAGS :=CLANG_FLAGS := export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CCexport CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE PAHOLE LEX YACC AWK INSTALLKERNELexport PERL PYTHON PYTHON2 PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXXexport KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGSexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULEexport CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSANexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULEexport KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULEexport KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL # Files to ignore in find ... statements export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \			  -name CVS -o -name .pc -o -name .hg -o -name .git \) \			  -prune -oexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \			 --exclude CVS --exclude .pc --exclude .hg --exclude .git # ===========================================================================# Rules shared between *config targets and build targets # Basic helpers built in scripts/basic/PHONY += scripts_basicscripts_basic:	$(Q)$(MAKE) $(build)=scripts/basic

Lines 1–500 of 1828.