@@ -186,6 +186,10 @@ endif
186186# Old syntax make ... SUBDIRS=$PWD is still supported
187187# Setting the environment variable KBUILD_EXTMOD take precedence
188188ifdef SUBDIRS
189+ $(warning ================= WARNING ================)
190+ $(warning 'SUBDIRS' will be removed after Linux 5.3)
191+ $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
192+ $(warning ==========================================)
189193 KBUILD_EXTMOD ?= $(SUBDIRS )
190194endif
191195
@@ -422,10 +426,10 @@ LINUXINCLUDE := \
422426 -I$(objtree ) /include \
423427 $(USERINCLUDE )
424428
425- KBUILD_AFLAGS := -D__ASSEMBLY__
426- KBUILD_CFLAGS := -Wall -Wundef -Wstrict -prototypes -Wno-trigraphs \
427- -fno-strict-aliasing -fno-common -fshort-wchar \
428- -Werror-implicit-function-declaration \
429+ KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
430+ KBUILD_CFLAGS := -Wall -Wundef -Werror=strict -prototypes -Wno-trigraphs \
431+ -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
432+ -Werror-implicit-function-declaration -Werror=implicit-int \
429433 -Wno-format-security \
430434 -std=gnu89
431435KBUILD_CPPFLAGS := -D__KERNEL__
@@ -487,18 +491,18 @@ endif
487491
488492ifneq ($(shell $(CC ) --version 2>&1 | head -n 1 | grep clang) ,)
489493ifneq ($(CROSS_COMPILE ) ,)
490- CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=% ) )
494+ CLANG_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=% ) )
491495GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD ) ) )
492- CLANG_PREFIX : = --prefix=$(GCC_TOOLCHAIN_DIR )
496+ CLANG_FLAGS + = --prefix=$(GCC_TOOLCHAIN_DIR )
493497GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR ) /..)
494498endif
495499ifneq ($(GCC_TOOLCHAIN ) ,)
496- CLANG_GCC_TC : = --gcc-toolchain=$(GCC_TOOLCHAIN )
500+ CLANG_FLAGS + = --gcc-toolchain=$(GCC_TOOLCHAIN )
497501endif
498- KBUILD_CFLAGS += $( CLANG_TARGET ) $( CLANG_GCC_TC ) $( CLANG_PREFIX )
499- KBUILD_AFLAGS += $(CLANG_TARGET ) $( CLANG_GCC_TC ) $( CLANG_PREFIX )
500- KBUILD_CFLAGS += $(call cc-option, -no-integrated-as )
501- KBUILD_AFLAGS += $( call cc-option, -no-integrated-as)
502+ CLANG_FLAGS += -no-integrated-as
503+ KBUILD_CFLAGS += $(CLANG_FLAGS )
504+ KBUILD_AFLAGS += $(CLANG_FLAGS )
505+ export CLANG_FLAGS
502506endif
503507
504508RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
@@ -510,9 +514,6 @@ RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc
510514export RETPOLINE_CFLAGS
511515export RETPOLINE_VDSO_CFLAGS
512516
513- KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
514- KBUILD_AFLAGS += $(call cc-option,-fno-PIE)
515-
516517# check for 'asm goto'
517518ifeq ($(shell $(CONFIG_SHELL ) $(srctree ) /scripts/gcc-goto.sh $(CC ) $(KBUILD_CFLAGS ) ) , y)
518519 CC_HAVE_ASM_GOTO := 1
@@ -828,12 +829,6 @@ KBUILD_CFLAGS += $(call cc-option,-fno-stack-check,)
828829# conserve stack if available
829830KBUILD_CFLAGS += $(call cc-option,-fconserve-stack)
830831
831- # disallow errors like 'EXPORT_GPL(foo);' with missing header
832- KBUILD_CFLAGS += $(call cc-option,-Werror=implicit-int)
833-
834- # require functions to have arguments in prototypes, not empty 'int foo()'
835- KBUILD_CFLAGS += $(call cc-option,-Werror=strict-prototypes)
836-
837832# Prohibit date/time macros, which would make the build non-deterministic
838833KBUILD_CFLAGS += $(call cc-option,-Werror=date-time)
839834
@@ -1026,14 +1021,13 @@ cmd_link-vmlinux = \
10261021 $(if $(ARCH_POSTLINK ) , $(MAKE ) -f $(ARCH_POSTLINK ) $@ , true)
10271022
10281023vmlinux : scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps ) FORCE
1029- ifdef CONFIG_HEADERS_CHECK
1030- $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
1031- endif
10321024ifdef CONFIG_GDB_SCRIPTS
10331025 $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
10341026endif
10351027 +$(call if_changed,link-vmlinux)
10361028
1029+ targets := vmlinux
1030+
10371031# Build samples along the rest of the kernel. This needs headers_install.
10381032ifdef CONFIG_SAMPLES
10391033vmlinux-dirs += samples
@@ -1051,7 +1045,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
10511045# Error messages still appears in the original language
10521046
10531047PHONY += $(vmlinux-dirs )
1054- $(vmlinux-dirs ) : prepare scripts
1048+ $(vmlinux-dirs ) : prepare
10551049 $(Q )$(MAKE ) $(build ) =$@ need-builtin=1
10561050
10571051define filechk_kernel.release
@@ -1066,7 +1060,7 @@ include/config/kernel.release: $(srctree)/Makefile FORCE
10661060# Carefully list dependencies so we do not try to build scripts twice
10671061# in parallel
10681062PHONY += scripts
1069- scripts : scripts_basic scripts_dtc asm-generic gcc-plugins $( autoksyms_h )
1063+ scripts : scripts_basic scripts_dtc
10701064 $(Q )$(MAKE ) $(build ) =$(@ )
10711065
10721066# Things we need to do before we recursively start building the kernel
@@ -1099,22 +1093,23 @@ prepare2: prepare3 outputmakefile asm-generic
10991093prepare1 : prepare2 $(version_h ) $(autoksyms_h ) include/generated/utsrelease.h
11001094 $(cmd_crmodverdir )
11011095
1102- archprepare : archheaders archscripts prepare1 scripts_basic
1096+ archprepare : archheaders archscripts prepare1 scripts
11031097
1104- prepare0 : archprepare gcc-plugins
1098+ prepare0 : archprepare
1099+ $(Q )$(MAKE ) $(build ) =scripts/mod
11051100 $(Q )$(MAKE ) $(build ) =.
11061101
11071102# All the preparing..
11081103prepare : prepare0 prepare-objtool
11091104
11101105# Support for using generic headers in asm-generic
1106+ asm-generic := -f $(srctree ) /scripts/Makefile.asm-generic obj
1107+
11111108PHONY += asm-generic uapi-asm-generic
11121109asm-generic : uapi-asm-generic
1113- $(Q )$(MAKE ) -f $(srctree ) /scripts/Makefile.asm-generic \
1114- src=asm obj=arch/$(SRCARCH ) /include/generated/asm
1110+ $(Q )$(MAKE ) $(asm-generic ) =arch/$(SRCARCH ) /include/generated/asm
11151111uapi-asm-generic :
1116- $(Q )$(MAKE ) -f $(srctree ) /scripts/Makefile.asm-generic \
1117- src=uapi/asm obj=arch/$(SRCARCH ) /include/generated/uapi/asm
1112+ $(Q )$(MAKE ) $(asm-generic ) =arch/$(SRCARCH ) /include/generated/uapi/asm
11181113
11191114PHONY += prepare-objtool
11201115prepare-objtool : $(objtool_target )
@@ -1199,6 +1194,10 @@ headers_check: headers_install
11991194 $(Q )$(MAKE ) $(hdr-inst ) =include/uapi dst=include HDRCHECK=1
12001195 $(Q )$(MAKE ) $(hdr-inst ) =arch/$(SRCARCH ) /include/uapi $(hdr-dst ) HDRCHECK=1
12011196
1197+ ifdef CONFIG_HEADERS_CHECK
1198+ all : headers_check
1199+ endif
1200+
12021201# ---------------------------------------------------------------------------
12031202# Kernel selftest
12041203
@@ -1283,7 +1282,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
12831282
12841283# Target to prepare building external modules
12851284PHONY += modules_prepare
1286- modules_prepare : prepare scripts
1285+ modules_prepare : prepare
12871286
12881287# Target to install modules
12891288PHONY += modules_install
@@ -1551,9 +1550,6 @@ else # KBUILD_EXTMOD
15511550
15521551# We are always building modules
15531552KBUILD_MODULES := 1
1554- PHONY += crmodverdir
1555- crmodverdir :
1556- $(cmd_crmodverdir )
15571553
15581554PHONY += $(objtree ) /Module.symvers
15591555$(objtree ) /Module.symvers :
@@ -1565,7 +1561,7 @@ $(objtree)/Module.symvers:
15651561
15661562module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD ) )
15671563PHONY += $(module-dirs ) modules
1568- $(module-dirs ) : crmodverdir $(objtree ) /Module.symvers
1564+ $(module-dirs ) : prepare $(objtree ) /Module.symvers
15691565 $(Q )$(MAKE ) $(build ) =$(patsubst _module_% ,% ,$@ )
15701566
15711567modules : $(module-dirs )
@@ -1604,10 +1600,9 @@ help:
16041600 @echo ' clean - remove generated files in module directory only'
16051601 @echo ' '
16061602
1607- # Dummies...
1608- PHONY += prepare scripts
1609- prepare : ;
1610- scripts : ;
1603+ PHONY += prepare
1604+ prepare :
1605+ $(cmd_crmodverdir )
16111606endif # KBUILD_EXTMOD
16121607
16131608clean : $(clean-dirs )
@@ -1712,36 +1707,33 @@ else
17121707 target-dir = $(if $(KBUILD_EXTMOD ) ,$(dir $< ) ,$(dir $@ ) )
17131708endif
17141709
1715- % .s : % .c prepare scripts FORCE
1710+ % .s : % .c prepare FORCE
17161711 $(Q )$(MAKE ) $(build ) =$(build-dir ) $(target-dir )$(notdir $@ )
1717- % .i : % .c prepare scripts FORCE
1712+ % .i : % .c prepare FORCE
17181713 $(Q )$(MAKE ) $(build ) =$(build-dir ) $(target-dir )$(notdir $@ )
1719- % .o : % .c prepare scripts FORCE
1714+ % .o : % .c prepare FORCE
17201715 $(Q )$(MAKE ) $(build ) =$(build-dir ) $(target-dir )$(notdir $@ )
1721- % .lst : % .c prepare scripts FORCE
1716+ % .lst : % .c prepare FORCE
17221717 $(Q )$(MAKE ) $(build ) =$(build-dir ) $(target-dir )$(notdir $@ )
1723- % .s : % .S prepare scripts FORCE
1718+ % .s : % .S prepare FORCE
17241719 $(Q )$(MAKE ) $(build ) =$(build-dir ) $(target-dir )$(notdir $@ )
1725- % .o : % .S prepare scripts FORCE
1720+ % .o : % .S prepare FORCE
17261721 $(Q )$(MAKE ) $(build ) =$(build-dir ) $(target-dir )$(notdir $@ )
1727- % .symtypes : % .c prepare scripts FORCE
1722+ % .symtypes : % .c prepare FORCE
17281723 $(Q )$(MAKE ) $(build ) =$(build-dir ) $(target-dir )$(notdir $@ )
1729- % .ll : % .c prepare scripts FORCE
1724+ % .ll : % .c prepare FORCE
17301725 $(Q )$(MAKE ) $(build ) =$(build-dir ) $(target-dir )$(notdir $@ )
17311726
17321727# Modules
1733- / : prepare scripts FORCE
1734- $(cmd_crmodverdir )
1728+ / : prepare FORCE
17351729 $(Q )$(MAKE ) KBUILD_MODULES=$(if $(CONFIG_MODULES ) ,1) \
17361730 $(build ) =$(build-dir )
17371731# Make sure the latest headers are built for Documentation
17381732Documentation/ samples/ : headers_install
1739- % / : prepare scripts FORCE
1740- $(cmd_crmodverdir )
1733+ % / : prepare FORCE
17411734 $(Q )$(MAKE ) KBUILD_MODULES=$(if $(CONFIG_MODULES ) ,1) \
17421735 $(build ) =$(build-dir )
1743- % .ko : prepare scripts FORCE
1744- $(cmd_crmodverdir )
1736+ % .ko : prepare FORCE
17451737 $(Q )$(MAKE ) KBUILD_MODULES=$(if $(CONFIG_MODULES ) ,1) \
17461738 $(build ) =$(build-dir ) $(@:.ko=.o )
17471739 $(Q )$(MAKE ) -f $(srctree ) /scripts/Makefile.modpost
@@ -1765,13 +1757,12 @@ quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
17651757cmd_crmodverdir = $(Q ) mkdir -p $(MODVERDIR ) \
17661758 $(if $(KBUILD_MODULES ) ,; rm -f $(MODVERDIR ) /* )
17671759
1768- # read all saved command lines
1769- cmd_files := $(wildcard . * .cmd )
1760+ # read saved command lines for existing targets
1761+ existing-targets := $(wildcard $( sort $( targets ) ) )
17701762
1771- ifneq ($(cmd_files ) ,)
1772- $(cmd_files ) : ; # Do not try to update included dependency files
1773- include $(cmd_files )
1774- endif
1763+ cmd_files := $(foreach f,$(existing-targets ) ,$(dir $(f ) ) .$(notdir $(f ) ) .cmd)
1764+ $(cmd_files ) : ; # Do not try to update included dependency files
1765+ -include $(cmd_files )
17751766
17761767endif # ifeq ($(config-targets),1)
17771768endif # ifeq ($(mixed-targets),1)
0 commit comments