@@ -212,6 +212,13 @@ endif
212212ifdef SUBDIRS
213213 $(warning ================= WARNING ================)
214214 $(warning 'SUBDIRS' will be removed after Linux 5.3)
215+ $(warning )
216+ $(warning If you are building an individual subdirectory)
217+ $(warning in the kernel tree, you can do like this :)
218+ $(warning $$ make path/to/dir/you/want/to/build/)
219+ $(warning (Do not forget the trailing slash))
220+ $(warning )
221+ $(warning If you are building an external module,)
215222 $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
216223 $(warning ==========================================)
217224 KBUILD_EXTMOD ?= $(SUBDIRS )
@@ -221,32 +228,30 @@ ifeq ("$(origin M)", "command line")
221228 KBUILD_EXTMOD := $(M )
222229endif
223230
231+ export KBUILD_CHECKSRC KBUILD_EXTMOD
232+
224233ifeq ($(abs_srctree ) ,$(abs_objtree ) )
225234 # building in the source tree
226235 srctree := .
236+ building_out_of_srctree :=
227237else
228238 ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))
229239 # building in a subdirectory of the source tree
230240 srctree := ..
231241 else
232242 srctree := $(abs_srctree )
233243 endif
234-
235- # TODO:
236- # KBUILD_SRC is only used to distinguish in-tree/out-of-tree build.
237- # Replace it with $(srctree) or something.
238- KBUILD_SRC := $(abs_srctree)
244+ building_out_of_srctree := 1
239245endif
240246
241- export KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC
247+ ifneq ($(KBUILD_ABS_SRCTREE ) ,)
248+ srctree := $(abs_srctree )
249+ endif
242250
243251objtree := .
244- src := $(srctree )
245- obj := $(objtree )
246-
247252VPATH := $(srctree )
248253
249- export srctree objtree VPATH
254+ export building_out_of_srctree srctree objtree VPATH
250255
251256# To make sure we do not include .config for any of the *config targets
252257# catch them early, and hand them over to scripts/kconfig/Makefile
@@ -262,7 +267,7 @@ old_version_h := include/linux/version.h
262267clean-targets := %clean mrproper cleandocs
263268no-dot-config-targets := $(clean-targets ) \
264269 cscope gtags TAGS tags help% %docs check% coccicheck \
265- $(version_h ) headers_% archheaders archscripts \
270+ $(version_h ) headers headers_% archheaders archscripts \
266271 %asm-generic kernelversion %src-pkg
267272no-sync-config-targets := $(no-dot-config-targets ) install %install \
268273 kernelrelease
@@ -449,7 +454,7 @@ USERINCLUDE := \
449454LINUXINCLUDE := \
450455 -I$(srctree ) /arch/$(SRCARCH ) /include \
451456 -I$(objtree ) /arch/$(SRCARCH ) /include/generated \
452- $(if $(filter ., $( srctree ) ) , ,-I$(srctree ) /include) \
457+ $(if $(building_out_of_srctree ) ,-I$(srctree ) /include) \
453458 -I$(objtree ) /include \
454459 $(USERINCLUDE )
455460
@@ -510,7 +515,7 @@ PHONY += outputmakefile
510515# At the same time when output Makefile generated, generate .gitignore to
511516# ignore whole output directory
512517outputmakefile :
513- ifneq ( $( srctree ) ,.)
518+ ifdef building_out_of_srctree
514519 $(Q)ln -fsn $(srctree) source
515520 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
516521 $(Q)test -e .gitignore || \
@@ -527,7 +532,10 @@ endif
527532ifneq ($(GCC_TOOLCHAIN ) ,)
528533CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN )
529534endif
535+ ifeq ($(shell $(AS ) --version 2>&1 | head -n 1 | grep clang) ,)
530536CLANG_FLAGS += -no-integrated-as
537+ endif
538+ CLANG_FLAGS += -Werror=unknown-warning-option
531539KBUILD_CFLAGS += $(CLANG_FLAGS )
532540KBUILD_AFLAGS += $(CLANG_FLAGS )
533541export CLANG_FLAGS
@@ -608,6 +616,7 @@ ifeq ($(KBUILD_EXTMOD),)
608616init-y := init/
609617drivers-y := drivers/ sound/
610618drivers-$(CONFIG_SAMPLES) += samples/
619+ drivers-$(CONFIG_KERNEL_HEADER_TEST) += include/
611620net-y := net/
612621libs-y := lib/
613622core-y := usr/
@@ -1053,9 +1062,6 @@ vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
10531062
10541063targets := vmlinux
10551064
1056- # Some samples need headers_install.
1057- samples : headers_install
1058-
10591065# The actual objects are generated when descending,
10601066# make sure no implicit rule kicks in
10611067$(sort $(vmlinux-deps ) ) : $(vmlinux-dirs ) ;
@@ -1096,12 +1102,12 @@ PHONY += prepare archprepare prepare1 prepare3
10961102# and if so do:
10971103# 1) Check that make has not been executed in the kernel src $(srctree)
10981104prepare3 : include/config/kernel.release
1099- ifneq ( $( srctree ) ,.)
1105+ ifdef building_out_of_srctree
11001106 @$(kecho) ' Using $(srctree) as source for kernel'
11011107 $(Q)if [ -f $(srctree)/.config -o \
11021108 -d $(srctree)/include/config -o \
11031109 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
1104- echo >&2 " $(srctree) is not clean, please run 'make mrproper'"; \
1110+ echo >&2 " $(srctree) is not clean, please run 'make ARCH=$(ARCH) mrproper'"; \
11051111 echo >&2 " in the '$(srctree)' directory.";\
11061112 /bin/false; \
11071113 fi;
@@ -1181,39 +1187,44 @@ headerdep:
11811187# Default location for installed headers
11821188export INSTALL_HDR_PATH = $(objtree ) /usr
11831189
1184- # If we do an all arch process set dst to include/arch-$(SRCARCH)
1185- hdr-dst = $(if $(KBUILD_HEADERS ) , dst=include/arch-$(SRCARCH ) , dst=include)
1190+ quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH ) /include
1191+ cmd_headers_install = \
1192+ mkdir -p $(INSTALL_HDR_PATH ) ; \
1193+ rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
1194+ usr/include $(INSTALL_HDR_PATH )
11861195
1187- PHONY += archheaders archscripts
1196+ PHONY += headers_install
1197+ headers_install : headers
1198+ $(call cmd,headers_install)
11881199
1189- PHONY += __headers
1190- __headers : $(version_h ) scripts_basic uapi-asm-generic archheaders archscripts
1191- $(Q )$(MAKE ) $(build ) =scripts build_unifdef
1200+ PHONY += archheaders archscripts
11921201
1193- PHONY += headers_install_all
1194- headers_install_all :
1195- $(Q )$(CONFIG_SHELL ) $(srctree ) /scripts/headers.sh install
1202+ hdr-inst := -f $(srctree ) /scripts/Makefile.headersinst obj
11961203
1197- PHONY += headers_install
1198- headers_install : __headers
1204+ PHONY += headers
1205+ headers : $( version_h ) scripts_unifdef uapi-asm-generic archheaders archscripts
11991206 $(if $(wildcard $(srctree ) /arch/$(SRCARCH ) /include/uapi/asm/Kbuild) ,, \
12001207 $(error Headers not exportable for the $(SRCARCH ) architecture) )
1201- $(Q )$(MAKE ) $(hdr-inst ) =include/uapi dst=include
1202- $(Q )$(MAKE ) $(hdr-inst ) =arch/$(SRCARCH ) /include/uapi $(hdr-dst )
1203-
1204- PHONY += headers_check_all
1205- headers_check_all : headers_install_all
1206- $(Q )$(CONFIG_SHELL ) $(srctree ) /scripts/headers.sh check
1208+ $(Q )$(MAKE ) $(hdr-inst ) =include/uapi
1209+ $(Q )$(MAKE ) $(hdr-inst ) =arch/$(SRCARCH ) /include/uapi
12071210
12081211PHONY += headers_check
1209- headers_check : headers_install
1210- $(Q )$(MAKE ) $(hdr-inst ) =include/uapi dst=include HDRCHECK=1
1211- $(Q )$(MAKE ) $(hdr-inst ) =arch/$(SRCARCH ) /include/uapi $(hdr-dst ) HDRCHECK=1
1212+ headers_check : headers
1213+ $(Q )$(MAKE ) $(hdr-inst ) =include/uapi HDRCHECK=1
1214+ $(Q )$(MAKE ) $(hdr-inst ) =arch/$(SRCARCH ) /include/uapi HDRCHECK=1
1215+
1216+ ifdef CONFIG_HEADERS_INSTALL
1217+ prepare : headers
1218+ endif
12121219
12131220ifdef CONFIG_HEADERS_CHECK
12141221all : headers_check
12151222endif
12161223
1224+ PHONY += scripts_unifdef
1225+ scripts_unifdef : scripts_basic
1226+ $(Q )$(MAKE ) $(build ) =scripts scripts/unifdef
1227+
12171228# ---------------------------------------------------------------------------
12181229# Kernel selftest
12191230
@@ -1283,18 +1294,24 @@ all: modules
12831294# using awk while concatenating to the final file.
12841295
12851296PHONY += modules
1286- modules : $(vmlinux-dirs ) $(if $(KBUILD_BUILTIN ) ,vmlinux) modules.builtin
1287- $(Q )$(AWK ) ' !x[$$0]++' $(vmlinux-dirs:%=$(objtree ) /%/modules.order ) > $(objtree ) /modules.order
1297+ modules : $(if $(KBUILD_BUILTIN ) ,vmlinux) modules.order modules.builtin
12881298 @$(kecho ) ' Building modules, stage 2.' ;
12891299 $(Q )$(MAKE ) -f $(srctree ) /scripts/Makefile.modpost
12901300 $(Q )$(CONFIG_SHELL ) $(srctree ) /scripts/modules-check.sh
12911301
1292- modules.builtin : $(vmlinux-dirs:%=%/modules.builtin )
1293- $(Q )$(AWK ) ' !x[$$0]++' $^ > $(objtree ) /modules.builtin
1302+ modules.order : $(vmlinux-dirs )
1303+ $(Q )$(AWK ) ' !x[$$0]++' $(addsuffix /$@ , $(vmlinux-dirs ) ) > $@
1304+
1305+ modbuiltin-dirs := $(addprefix _modbuiltin_, $(vmlinux-dirs ) )
12941306
1295- % / modules.builtin : include/config/auto.conf include/config/tristate.conf
1296- $(Q )$(MAKE ) $( modbuiltin ) = $*
1307+ modules.builtin : $( modbuiltin-dirs )
1308+ $(Q )$(AWK ) ' !x[$$0]++ ' $( addsuffix / $@ , $( vmlinux-dirs ) ) > $@
12971309
1310+ PHONY += $(modbuiltin-dirs )
1311+ # tristate.conf is not included from this Makefile. Add it as a prerequisite
1312+ # here to make it self-healing in case somebody accidentally removes it.
1313+ $(modbuiltin-dirs ) : include/config/tristate.conf
1314+ $(Q )$(MAKE ) $(modbuiltin ) =$(patsubst _modbuiltin_% ,% ,$@ )
12981315
12991316# Target to prepare building external modules
13001317PHONY += modules_prepare
@@ -1360,7 +1377,7 @@ CLEAN_DIRS += $(MODVERDIR) include/ksym
13601377CLEAN_FILES += modules.builtin.modinfo
13611378
13621379# Directories & files removed with 'make mrproper'
1363- MRPROPER_DIRS += include/config usr/include include/generated \
1380+ MRPROPER_DIRS += include/config include/generated \
13641381 arch/$(SRCARCH ) /include/generated .tmp_objdiff
13651382MRPROPER_FILES += .config .config.old .version \
13661383 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
@@ -1551,7 +1568,7 @@ $(DOC_TARGETS): scripts_basic FORCE
15511568# ---------------------------------------------------------------------------
15521569
15531570PHONY += scripts_gdb
1554- scripts_gdb : prepare
1571+ scripts_gdb : prepare0
15551572 $(Q )$(MAKE ) $(build ) =scripts/gdb
15561573 $(Q ) ln -fsn $(abspath $(srctree ) /scripts/gdb/vmlinux-gdb.py)
15571574
@@ -1698,7 +1715,7 @@ CHECKSTACK_ARCH := $(ARCH)
16981715endif
16991716checkstack :
17001717 $(OBJDUMP ) -d vmlinux $$(find . -name '*.ko' ) | \
1701- $(PERL ) $(src ) /scripts/checkstack.pl $(CHECKSTACK_ARCH )
1718+ $(PERL ) $(srctree ) /scripts/checkstack.pl $(CHECKSTACK_ARCH )
17021719
17031720kernelrelease :
17041721 @echo " $( KERNELVERSION) $$ ($( CONFIG_SHELL) $( srctree) /scripts/setlocalversion $( srctree) )"
@@ -1717,11 +1734,11 @@ endif
17171734
17181735tools/ : FORCE
17191736 $(Q ) mkdir -p $(objtree ) /tools
1720- $(Q )$(MAKE ) LDFLAGS= MAKEFLAGS=" $( tools_silent) $( filter --j% -j,$( MAKEFLAGS) ) " O=$(abspath $(objtree ) ) subdir=tools -C $(src ) /tools/
1737+ $(Q )$(MAKE ) LDFLAGS= MAKEFLAGS=" $( tools_silent) $( filter --j% -j,$( MAKEFLAGS) ) " O=$(abspath $(objtree ) ) subdir=tools -C $(srctree ) /tools/
17211738
17221739tools/% : FORCE
17231740 $(Q ) mkdir -p $(objtree ) /tools
1724- $(Q )$(MAKE ) LDFLAGS= MAKEFLAGS=" $( tools_silent) $( filter --j% -j,$( MAKEFLAGS) ) " O=$(abspath $(objtree ) ) subdir=tools -C $(src ) /tools/ $*
1741+ $(Q )$(MAKE ) LDFLAGS= MAKEFLAGS=" $( tools_silent) $( filter --j% -j,$( MAKEFLAGS) ) " O=$(abspath $(objtree ) ) subdir=tools -C $(srctree ) /tools/ $*
17251742
17261743# Single targets
17271744# ---------------------------------------------------------------------------
@@ -1755,8 +1772,6 @@ build-dir = $(patsubst %/,%,$(dir $(build-target)))
17551772PHONY += /
17561773/ : ./
17571774
1758- # Make sure the latest headers are built for Documentation
1759- Documentation/ samples/ : headers_install
17601775% / : prepare FORCE
17611776 $(Q )$(MAKE ) KBUILD_MODULES=1 $(build ) =$(build-dir )
17621777
0 commit comments