From f3c8d4c7a7280cdc6622adb4f8e39d51b3786d68 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Jun 2019 19:13:55 +0900 Subject: kbuild: remove headers_{install,check}_all headers_install_all does not make much sense any more because different architectures export different set of uapi/linux/ headers. As you see in include/uapi/linux/Kbuild, the installation of a.out.h, kvm.h, and kvm_para.h is arch-dependent. So, headers_install_all repeats the installation/removal of them. If somebody really thinks it is useful to do headers_install for all architectures, it would be possible by small shell-scripting, but the top Makefile does not have to provide entry targets just for that purpose. Signed-off-by: Masahiro Yamada Acked-by: Sam Ravnborg --- Makefile | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b81e17261250..b4b07e90c969 100644 --- a/Makefile +++ b/Makefile @@ -1181,34 +1181,23 @@ headerdep: #Default location for installed headers export INSTALL_HDR_PATH = $(objtree)/usr -# If we do an all arch process set dst to include/arch-$(SRCARCH) -hdr-dst = $(if $(KBUILD_HEADERS), dst=include/arch-$(SRCARCH), dst=include) - PHONY += archheaders archscripts PHONY += __headers __headers: $(version_h) scripts_basic uapi-asm-generic archheaders archscripts $(Q)$(MAKE) $(build)=scripts build_unifdef -PHONY += headers_install_all -headers_install_all: - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh install - PHONY += headers_install headers_install: __headers $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \ $(error Headers not exportable for the $(SRCARCH) architecture)) $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include - $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi $(hdr-dst) - -PHONY += headers_check_all -headers_check_all: headers_install_all - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh check + $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include PHONY += headers_check headers_check: headers_install $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1 - $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi $(hdr-dst) HDRCHECK=1 + $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include HDRCHECK=1 ifdef CONFIG_HEADERS_CHECK all: headers_check -- cgit From 3a51f9081e7b4c7229e1d3cb5ec74bc27ae4ea84 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Jun 2019 19:13:56 +0900 Subject: kbuild: remove stale dependency between Documentation/ and headers_install Commit 8e2faea877eb ("Make Documenation depend on headers_install") dates back to 2014, which is before Sphinx was introduced for the kernel documentation. Since none of DOC_TARGET requires headers_install, it is strange to run it only for the single target "Documentation/". Signed-off-by: Masahiro Yamada --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b4b07e90c969..5d550ad872a7 100644 --- a/Makefile +++ b/Makefile @@ -1744,8 +1744,7 @@ build-dir = $(patsubst %/,%,$(dir $(build-target))) PHONY += / /: ./ -# Make sure the latest headers are built for Documentation -Documentation/ samples/: headers_install +samples/: headers_install %/: prepare FORCE $(Q)$(MAKE) KBUILD_MODULES=1 $(build)=$(build-dir) -- cgit From 7a739ce51dca77184e5fc7b4ad5696b32a5c9422 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Jun 2019 19:13:57 +0900 Subject: kbuild: make gdb_script depend on prepare0 instead of prepare 'gdb_script' needs headers generated by ./Kbuild, which is visited by 'prepare0'. None of 'gdb_script' depends on 'prepare'. Loosen the dependency. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 5d550ad872a7..4bc9c708bcdd 100644 --- a/Makefile +++ b/Makefile @@ -1540,7 +1540,7 @@ $(DOC_TARGETS): scripts_basic FORCE # --------------------------------------------------------------------------- PHONY += scripts_gdb -scripts_gdb: prepare +scripts_gdb: prepare0 $(Q)$(MAKE) $(build)=scripts/gdb $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py) -- cgit From e949f4c2d6a3df2b7fd00e56c0f081b15284906f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Jun 2019 19:13:59 +0900 Subject: kbuild: add CONFIG_HEADERS_INSTALL and loosen the dependency of samples Commit 5318321d367c ("samples: disable CONFIG_SAMPLES for UML") used a big hammer to fix the build errors under the samples/ directory. Only some samples actually include uapi headers from usr/include. Introduce CONFIG_HEADERS_INSTALL since 'depends on HEADERS_INSTALL' is clearer than 'depends on !UML'. If this option is enabled, uapi headers are installed before starting directory descending. I added 'depends on HEADERS_INSTALL' to per-sample CONFIG options. This allows UML to compile some samples. $ make ARCH=um allmodconfig samples/ [ snip ] CC [M] samples/configfs/configfs_sample.o CC [M] samples/kfifo/bytestream-example.o CC [M] samples/kfifo/dma-example.o CC [M] samples/kfifo/inttype-example.o CC [M] samples/kfifo/record-example.o CC [M] samples/kobject/kobject-example.o CC [M] samples/kobject/kset-example.o CC [M] samples/trace_events/trace-events-sample.o CC [M] samples/trace_printk/trace-printk.o AR samples/vfio-mdev/built-in.a AR samples/built-in.a Signed-off-by: Masahiro Yamada --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 4bc9c708bcdd..f3fd2a549970 100644 --- a/Makefile +++ b/Makefile @@ -1053,9 +1053,6 @@ vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE targets := vmlinux -# Some samples need headers_install. -samples: headers_install - # The actual objects are generated when descending, # make sure no implicit rule kicks in $(sort $(vmlinux-deps)): $(vmlinux-dirs) ; @@ -1199,6 +1196,10 @@ headers_check: headers_install $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include HDRCHECK=1 +ifdef CONFIG_HEADERS_INSTALL +prepare: headers_install +endif + ifdef CONFIG_HEADERS_CHECK all: headers_check endif @@ -1744,7 +1745,6 @@ build-dir = $(patsubst %/,%,$(dir $(build-target))) PHONY += / /: ./ -samples/: headers_install %/: prepare FORCE $(Q)$(MAKE) KBUILD_MODULES=1 $(build)=$(build-dir) -- cgit From 2b8481be3cc3b8dfb2704f4d33668d930474fac8 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Jun 2019 19:14:00 +0900 Subject: kbuild: remove build_unifdef target in scripts/Makefile Since commit 2aedcd098a94 ("kbuild: suppress annoying "... is up to date." message"), if_changed and friends nicely suppress "is up to date" messages. We do not need per-Makefile tricks. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index f3fd2a549970..6abcacface9c 100644 --- a/Makefile +++ b/Makefile @@ -1182,7 +1182,7 @@ PHONY += archheaders archscripts PHONY += __headers __headers: $(version_h) scripts_basic uapi-asm-generic archheaders archscripts - $(Q)$(MAKE) $(build)=scripts build_unifdef + $(Q)$(MAKE) $(build)=scripts scripts/unifdef PHONY += headers_install headers_install: __headers -- cgit From bdd7714b6f4cca75dd1b234306077150060c2f45 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Jun 2019 19:14:01 +0900 Subject: kbuild: build all prerequisites of headers_install simultaneously Currently, scripts/unifdef is compiled after scripts_basic, uapi-asm-generic, archheaders, and archscripts. The proper dependency is just scripts_basic. There is no problem to compile scripts/unifdef and other headers at the same time. Split scripts_unifdef out in order to allow more parallel building. Signed-off-by: Masahiro Yamada --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 6abcacface9c..39ee585b52b1 100644 --- a/Makefile +++ b/Makefile @@ -1181,8 +1181,7 @@ export INSTALL_HDR_PATH = $(objtree)/usr PHONY += archheaders archscripts PHONY += __headers -__headers: $(version_h) scripts_basic uapi-asm-generic archheaders archscripts - $(Q)$(MAKE) $(build)=scripts scripts/unifdef +__headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts PHONY += headers_install headers_install: __headers @@ -1204,6 +1203,10 @@ ifdef CONFIG_HEADERS_CHECK all: headers_check endif +PHONY += scripts_unifdef +scripts_unifdef: scripts_basic + $(Q)$(MAKE) $(build)=scripts scripts/unifdef + # --------------------------------------------------------------------------- # Kernel selftest -- cgit From 59b2bd05f5f4dc62979c2e82ddd384f07e8f10bc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Jun 2019 19:14:02 +0900 Subject: kbuild: add 'headers' target to build up uapi headers in usr/include In Linux build system, build targets and installation targets are separated. Examples are: - 'make vmlinux' -> 'make install' - 'make modules' -> 'make modules_install' - 'make dtbs' -> 'make dtbs_install' - 'make vdso' -> 'make vdso_install' The intention is to run the build targets under the normal privilege, then the installation targets under the root privilege since we need the write permission to the system directories. We have 'make headers_install' but the corresponding 'make headers' stage does not exist. The purpose of headers_install is to provide the kernel interface to C library. So, nobody would try to install headers to /usr/include directly. If 'sudo make INSTALL_HDR_PATH=/usr/include headers_install' were run, some build artifacts in the kernel tree would be owned by root because some of uapi headers are generated by 'uapi-asm-generic', 'archheaders' targets. Anyway, I believe it makes sense to split the header installation into two stages. [1] 'make headers' Process headers in uapi directories by scripts/headers_install.sh and copy them to usr/include [2] 'make headers_install' Copy '*.h' verbatim from usr/include to $(INSTALL_HDR_PATH)/include For the backward compatibility, 'headers_install' depends on 'headers'. Some samples expect uapi headers in usr/include. So, the 'headers' target is useful to build up them in the fixed location usr/include irrespective of INSTALL_HDR_PATH. Another benefit is to stop polluting the final destination with the time-stamp files '.install' and '.check'. Maybe you can see them in your toolchains. Lastly, my main motivation is to prepare for compile-testing uapi headers. To build something, we have to save an object and .*.cmd somewhere. The usr/include/ will be the work directory for that. Signed-off-by: Masahiro Yamada --- Makefile | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 39ee585b52b1..11445a7dd820 100644 --- a/Makefile +++ b/Makefile @@ -262,7 +262,7 @@ old_version_h := include/linux/version.h clean-targets := %clean mrproper cleandocs no-dot-config-targets := $(clean-targets) \ cscope gtags TAGS tags help% %docs check% coccicheck \ - $(version_h) headers_% archheaders archscripts \ + $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg no-sync-config-targets := $(no-dot-config-targets) install %install \ kernelrelease @@ -1178,25 +1178,32 @@ headerdep: #Default location for installed headers export INSTALL_HDR_PATH = $(objtree)/usr -PHONY += archheaders archscripts - -PHONY += __headers -__headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts +quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include + cmd_headers_install = \ + mkdir -p $(INSTALL_HDR_PATH); \ + rsync -mrl --include='*/' --include='*\.h' --exclude='*' \ + usr/include $(INSTALL_HDR_PATH) PHONY += headers_install -headers_install: __headers +headers_install: headers + $(call cmd,headers_install) + +PHONY += archheaders archscripts + +PHONY += headers +headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \ $(error Headers not exportable for the $(SRCARCH) architecture)) $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include PHONY += headers_check -headers_check: headers_install +headers_check: headers $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include HDRCHECK=1 ifdef CONFIG_HEADERS_INSTALL -prepare: headers_install +prepare: headers endif ifdef CONFIG_HEADERS_CHECK -- cgit From d5470d14431e9d39ee2131323589afac2a0bfee4 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Jun 2019 19:14:03 +0900 Subject: kbuild: re-implement Makefile.headersinst without recursion Since commit fcc8487d477a ("uapi: export all headers under uapi directories"), the headers in uapi directories are all exported by default although exceptional cases are still allowed by the syntax 'no-export-headers'. The traditional directory descending has been kept (in a somewhat hacky way), but it is actually unneeded. Get rid of it to simplify the code. Also, handle files one by one instead of the previous per-directory processing. This will emit much more log, but I like it. Signed-off-by: Masahiro Yamada --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 11445a7dd820..507ce2c92065 100644 --- a/Makefile +++ b/Makefile @@ -1194,13 +1194,13 @@ PHONY += headers headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \ $(error Headers not exportable for the $(SRCARCH) architecture)) - $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include - $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include + $(Q)$(MAKE) $(hdr-inst)=include/uapi + $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi PHONY += headers_check headers_check: headers - $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1 - $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include HDRCHECK=1 + $(Q)$(MAKE) $(hdr-inst)=include/uapi HDRCHECK=1 + $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi HDRCHECK=1 ifdef CONFIG_HEADERS_INSTALL prepare: headers -- cgit From a5bae54c106db8734d5ca81e2eb8e0351dd11737 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Jun 2019 19:14:04 +0900 Subject: kbuild: move hdr-inst shorthand to top Makefile Now that hdr-inst is used only in the top Makefile, move it there from scripts/Kbuild.include. Signed-off-by: Masahiro Yamada --- Makefile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 507ce2c92065..e124a3e73bfe 100644 --- a/Makefile +++ b/Makefile @@ -1190,6 +1190,8 @@ headers_install: headers PHONY += archheaders archscripts +hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj + PHONY += headers headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \ -- cgit From e846f0dc57f441e5e93194d39bc9b8ac2ab5e0a4 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Tue, 4 Jun 2019 15:42:48 +0300 Subject: kbuild: add support for ensuring headers are self-contained Sometimes it's useful to be able to explicitly ensure certain headers remain self-contained, i.e. that they are compilable as standalone units, by including and/or forward declaring everything they depend on. Add special target header-test-y where individual Makefiles can add headers to be tested if CONFIG_HEADER_TEST is enabled. This will generate a dummy C file per header that gets built as part of extra-y. Signed-off-by: Jani Nikula Reviewed-by: Sam Ravnborg Signed-off-by: Masahiro Yamada --- Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index e124a3e73bfe..aefdb5661382 100644 --- a/Makefile +++ b/Makefile @@ -1647,6 +1647,7 @@ clean: $(clean-dirs) -o -name '*.dwo' -o -name '*.lst' \ -o -name '*.su' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ + -o -name '*.hdrtest.c' \ -o -name '*.lex.c' -o -name '*.tab.[ch]' \ -o -name '*.asn1.[ch]' \ -o -name '*.symtypes' -o -name 'modules.order' \ -- cgit From 589834b3a0097a4908f4112eac0ca2feb486fa32 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 11 Jun 2019 11:43:31 -0700 Subject: kbuild: Add -Werror=unknown-warning-option to CLANG_FLAGS In commit ebcc5928c5d9 ("arm64: Silence gcc warnings about arch ABI drift"), the arm64 Makefile added -Wno-psabi to KBUILD_CFLAGS, which is a GCC only option so clang rightfully complains: warning: unknown warning option '-Wno-psabi' [-Wunknown-warning-option] https://clang.llvm.org/docs/DiagnosticsReference.html#wunknown-warning-option However, by default, this is merely a warning so the build happily goes on with a slew of these warnings in the process. Commit c3f0d0bc5b01 ("kbuild, LLVMLinux: Add -Werror to cc-option to support clang") worked around this behavior in cc-option by adding -Werror so that unknown flags cause an error. However, this all happens silently and when an unknown flag is added to the build unconditionally like -Wno-psabi, cc-option will always fail because there is always an unknown flag in the list of flags. This manifested as link time failures in the arm64 libstub because -fno-stack-protector didn't get added to KBUILD_CFLAGS. To avoid these weird cryptic failures in the future, make clang behave like gcc and immediately error when it encounters an unknown flag by adding -Werror=unknown-warning-option to CLANG_FLAGS. This can be added unconditionally for clang because it is supported by at least 3.0.0, according to godbolt [1] and 4.0.0, according to its documentation [2], which is far earlier than we typically support. [1]: https://godbolt.org/z/7F7rm3 [2]: https://releases.llvm.org/4.0.0/tools/clang/docs/DiagnosticsReference.html#wunknown-warning-option Link: https://github.com/ClangBuiltLinux/linux/issues/511 Link: https://github.com/ClangBuiltLinux/linux/issues/517 Suggested-by: Peter Smith Signed-off-by: Nathan Chancellor Tested-by: Nick Desaulniers Signed-off-by: Masahiro Yamada --- Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index aefdb5661382..1f35aca4fe05 100644 --- a/Makefile +++ b/Makefile @@ -528,6 +528,7 @@ ifneq ($(GCC_TOOLCHAIN),) CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN) endif CLANG_FLAGS += -no-integrated-as +CLANG_FLAGS += -Werror=unknown-warning-option KBUILD_CFLAGS += $(CLANG_FLAGS) KBUILD_AFLAGS += $(CLANG_FLAGS) export CLANG_FLAGS -- cgit From 50ef0cdf58aea2f03f3d21390d68561ee7be215e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 24 Jun 2019 01:13:27 +0900 Subject: kbuild: fix missed rebuild of modules.builtin Unlike modules.order, modules.builtin is not rebuilt every time. Once modules.builtin is created, it will not be updated until auto.conf or tristate.conf is changed. So, it does not notice a change in Makefile, for example, the rename of modules. Kbuild must always descend into directories for modules.builtin too. Signed-off-by: Masahiro Yamada --- Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 1f35aca4fe05..f8e4f930e497 100644 --- a/Makefile +++ b/Makefile @@ -1292,12 +1292,16 @@ modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh -modules.builtin: $(vmlinux-dirs:%=%/modules.builtin) - $(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin +modbuiltin-dirs := $(addprefix _modbuiltin_, $(vmlinux-dirs)) -%/modules.builtin: include/config/auto.conf include/config/tristate.conf - $(Q)$(MAKE) $(modbuiltin)=$* +modules.builtin: $(modbuiltin-dirs) + $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(vmlinux-dirs)) > $@ +PHONY += $(modbuiltin-dirs) +# tristate.conf is not included from this Makefile. Add it as a prerequisite +# here to make it self-healing in case somebody accidentally removes it. +$(modbuiltin-dirs): include/config/tristate.conf + $(Q)$(MAKE) $(modbuiltin)=$(patsubst _modbuiltin_%,%,$@) # Target to prepare building external modules PHONY += modules_prepare -- cgit From 68980b4704d5d8c8cf2661f9d65a1a20ee455c1b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 24 Jun 2019 01:13:28 +0900 Subject: kbuild: split modules.order build rule out of 'modules' target modules.order is a real target. Split its build rule out like modules.builtin Signed-off-by: Masahiro Yamada --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index f8e4f930e497..c3b6dcd5b177 100644 --- a/Makefile +++ b/Makefile @@ -1286,12 +1286,14 @@ all: modules # using awk while concatenating to the final file. PHONY += modules -modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin - $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order +modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order modules.builtin @$(kecho) ' Building modules, stage 2.'; $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh +modules.order: $(vmlinux-dirs) + $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(vmlinux-dirs)) > $@ + modbuiltin-dirs := $(addprefix _modbuiltin_, $(vmlinux-dirs)) modules.builtin: $(modbuiltin-dirs) -- cgit From 876a0600896c1857c79cb58625ff012b27fea9fd Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Thu, 27 Jun 2019 12:14:48 -0700 Subject: kbuild: Add ability to test Clang's integrated assembler There are some people interested in experimenting with Clang's integrated assembler. To make it easy to do so without source modification, allow the user to specify 'AS=clang' as part of the make command to avoid adding '-no-integrated-as' to the {A,C}FLAGS. Link: https://github.com/ClangBuiltLinux/linux/issues/577 Suggested-by: Dmitry Golovin Signed-off-by: Nathan Chancellor Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers Signed-off-by: Masahiro Yamada --- Makefile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index c3b6dcd5b177..d6c3dbac312b 100644 --- a/Makefile +++ b/Makefile @@ -527,7 +527,9 @@ endif ifneq ($(GCC_TOOLCHAIN),) CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN) endif +ifeq ($(shell $(AS) --version 2>&1 | head -n 1 | grep clang),) CLANG_FLAGS += -no-integrated-as +endif CLANG_FLAGS += -Werror=unknown-warning-option KBUILD_CFLAGS += $(CLANG_FLAGS) KBUILD_AFLAGS += $(CLANG_FLAGS) -- cgit From 4e8fc3f55a38996a56106d6adfac72885ddd97ef Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 25 Jun 2019 17:51:27 +0900 Subject: kbuild: add more hints about SUBDIRS replacement Commit 0126be38d988 ("kbuild: announce removal of SUBDIRS if used") added a hint about the 'SUBDIRS' replacement, but it was not clear enough. Multiple people sent me similar questions, patches. For instance, https://lkml.org/lkml/2019/1/17/456 I did not mean to use M= for building a subdirectory in the kernel tree. From commit 669efc76b317 ("net: hns3: fix compile error"), people already (ab)use M=... to do that because it seems to work to some extent. Documentation/kbuild/kbuild.txt says M= and KBUILD_EXTMOD are used for building external modules. In fact, Kbuild supports the single target '%/' for this purpose, but this may not be noticed much. Kindly add more hints. Makefile:213: ================= WARNING ================ Makefile:214: 'SUBDIRS' will be removed after Linux 5.3 Makefile:215: Makefile:216: If you are building an individual subdirectory Makefile:217: in the kernel tree, you can do like this: Makefile:218: $ make path/to/dir/you/want/to/build/ Makefile:219: (Do not forget the trailing slash) Makefile:220: Makefile:221: If you are building an external module, Makefile:222: Please use 'M=' or 'KBUILD_EXTMOD' instead Makefile:223: ========================================== Suggested-by: Christoph Hellwig Signed-off-by: Masahiro Yamada Acked-by: Sam Ravnborg --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index d6c3dbac312b..eb850190b951 100644 --- a/Makefile +++ b/Makefile @@ -212,6 +212,13 @@ endif ifdef SUBDIRS $(warning ================= WARNING ================) $(warning 'SUBDIRS' will be removed after Linux 5.3) + $(warning ) + $(warning If you are building an individual subdirectory) + $(warning in the kernel tree, you can do like this:) + $(warning $$ make path/to/dir/you/want/to/build/) + $(warning (Do not forget the trailing slash)) + $(warning ) + $(warning If you are building an external module,) $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead) $(warning ==========================================) KBUILD_EXTMOD ?= $(SUBDIRS) -- cgit From d6fc9fcbaa655cff2d2be05e16867d1918f78b85 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 1 Jul 2019 09:58:40 +0900 Subject: kbuild: compile-test exported headers to ensure they are self-contained Multiple people have suggested compile-testing UAPI headers to ensure they can be really included from user-space. "make headers_check" is obviously not enough to catch bugs, and we often leak unresolved references to user-space. Use the new header-test-y syntax to implement it. Please note exported headers are compile-tested with a completely different set of compiler flags. The header search path is set to $(objtree)/usr/include since exported headers should not include unexported ones. We use -std=gnu89 for the kernel space since the kernel code highly depends on GNU extensions. On the other hand, UAPI headers should be written in more standardized C, so they are compiled with -std=c90. This will emit errors if C++ style comments, the keyword 'inline', etc. are used. Please use C style comments (/* ... */), '__inline__', etc. in UAPI headers. There is additional compiler requirement to enable this test because many of UAPI headers include , , , etc. directly or indirectly. You cannot use kernel.org pre-built toolchains [1] since they lack . I reused CONFIG_CC_CAN_LINK to check the system header availability. The intention is slightly different, but a compiler that can link userspace programs provide system headers. For now, a lot of headers need to be excluded because they cannot be compiled standalone, but this is a good start point. [1] https://mirrors.edge.kernel.org/pub/tools/crosstool/index.html Signed-off-by: Masahiro Yamada Reviewed-by: Sam Ravnborg --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index eb850190b951..fca827bc3f77 100644 --- a/Makefile +++ b/Makefile @@ -1378,7 +1378,7 @@ CLEAN_DIRS += $(MODVERDIR) include/ksym CLEAN_FILES += modules.builtin.modinfo # Directories & files removed with 'make mrproper' -MRPROPER_DIRS += include/config usr/include include/generated \ +MRPROPER_DIRS += include/config include/generated \ arch/$(SRCARCH)/include/generated .tmp_objdiff MRPROPER_FILES += .config .config.old .version \ Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \ -- cgit From c93a0368aaa2962e6c89da20f79b8789b42e3387 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 1 Jul 2019 09:58:41 +0900 Subject: kbuild: do not create wrappers for header-test-y header-test-y does not work with headers in sub-directories. For example, you may want to write a Makefile, like this: include/linux/Kbuild: header-test-y += mtd/nand.h This entry will create a wrapper include/linux/mtd/nand.hdrtest.c with the following content: #include "mtd/nand.h" To make this work, we need to add $(srctree)/include/linux to the header search path. It would be tedious to add ccflags-y. Instead, we could change the *.hdrtest.c rule to wrap: #include "nand.h" This works for in-tree build since #include "..." searches in the relative path from the header with this directive. For O=... build, we need to add $(srctree)/include/linux/mtd to the header search path, which will be even more tedious. After all, I thought it would be handier to compile headers directly without creating wrappers. I added a new build rule to compile %.h into %.h.s The target is %.h.s instead of %.h.o because it is slightly faster. Also, as for GCC, an empty assembly is smaller than an empty object. I wrote the build rule: $(CC) $(c_flags) -S -o $@ -x c /dev/null -include $< instead of: $(CC) $(c_flags) -S -o $@ -x c $< Both work fine with GCC, but the latter is bad for Clang. This comes down to the difference in the -Wunused-function policy. GCC does not warn about unused 'static inline' functions at all. Clang does not warn about the ones in included headers, but does about the ones in the source. So, we should handle headers as headers, not as source files. In fact, this has been hidden since commit abb2ea7dfd82 ("compiler, clang: suppress warning for unused static inline functions"), but we should not rely on that. Signed-off-by: Masahiro Yamada Acked-by: Jani Nikula Tested-by: Jani Nikula --- Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index fca827bc3f77..82fccd37a1ad 100644 --- a/Makefile +++ b/Makefile @@ -1663,7 +1663,6 @@ clean: $(clean-dirs) -o -name '*.dwo' -o -name '*.lst' \ -o -name '*.su' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ - -o -name '*.hdrtest.c' \ -o -name '*.lex.c' -o -name '*.tab.[ch]' \ -o -name '*.asn1.[ch]' \ -o -name '*.symtypes' -o -name 'modules.order' \ -- cgit From 43c78d88036e47949a5af2fac0067e7ebaaf7dd0 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 1 Jul 2019 09:58:45 +0900 Subject: kbuild: compile-test kernel headers to ensure they are self-contained The headers in include/ are globally used in the kernel source tree to provide common APIs. They are included from external modules, too. It will be useful to make as many headers self-contained as possible so that we do not have to rely on a specific include order. There are more than 4000 headers in include/. In my rough analysis, 70% of them are already self-contained. With efforts, most of them can be self-contained. For now, we must exclude more than 1000 headers just because they cannot be compiled as standalone units. I added them to header-test-. The blacklist was mostly generated by a script, so the reason of the breakage should be checked later. Signed-off-by: Masahiro Yamada Tested-by: Jani Nikula Reviewed-by: Joel Fernandes (Google) --- Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 82fccd37a1ad..66a3bcb0db69 100644 --- a/Makefile +++ b/Makefile @@ -618,6 +618,7 @@ ifeq ($(KBUILD_EXTMOD),) init-y := init/ drivers-y := drivers/ sound/ drivers-$(CONFIG_SAMPLES) += samples/ +drivers-$(CONFIG_KERNEL_HEADER_TEST) += include/ net-y := net/ libs-y := lib/ core-y := usr/ -- cgit From 75dd47472b92c320304436c9e38638bc04ae7a4a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 6 Jul 2019 12:07:11 +0900 Subject: kbuild: remove src and obj from the top Makefile Replace $(src) and $(obj) with $(srctree) and $(objtree), respectively. Signed-off-by: Masahiro Yamada --- Makefile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 66a3bcb0db69..99336b60f1a4 100644 --- a/Makefile +++ b/Makefile @@ -248,9 +248,6 @@ endif export KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC objtree := . -src := $(srctree) -obj := $(objtree) - VPATH := $(srctree) export srctree objtree VPATH @@ -1717,7 +1714,7 @@ CHECKSTACK_ARCH := $(ARCH) endif checkstack: $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \ - $(PERL) $(src)/scripts/checkstack.pl $(CHECKSTACK_ARCH) + $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) kernelrelease: @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" @@ -1736,11 +1733,11 @@ endif tools/: FORCE $(Q)mkdir -p $(objtree)/tools - $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/ + $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ tools/%: FORCE $(Q)mkdir -p $(objtree)/tools - $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/ $* + $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $* # Single targets # --------------------------------------------------------------------------- -- cgit From 051f278e9d81bed253bf89c66c80b8b921aafa8a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 6 Jul 2019 12:07:12 +0900 Subject: kbuild: replace KBUILD_SRCTREE with boolean building_out_of_srctree Commit 25b146c5b8ce ("kbuild: allow Kbuild to start from any directory") deprecated KBUILD_SRCTREE. It is only used in tools/testing/selftest/ to distinguish out-of-tree build. Replace it with a new boolean flag, building_out_of_srctree. I also replaced the conditional ($(srctree),.) because the next commit will allow an absolute path to be used for $(srctree) even when building in the source tree. Signed-off-by: Masahiro Yamada --- Makefile | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 99336b60f1a4..91ad737ff538 100644 --- a/Makefile +++ b/Makefile @@ -228,9 +228,12 @@ ifeq ("$(origin M)", "command line") KBUILD_EXTMOD := $(M) endif +export KBUILD_CHECKSRC 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 @@ -238,19 +241,13 @@ else else srctree := $(abs_srctree) endif - - # TODO: - # KBUILD_SRC is only used to distinguish in-tree/out-of-tree build. - # Replace it with $(srctree) or something. - KBUILD_SRC := $(abs_srctree) + building_out_of_srctree := 1 endif -export KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC - objtree := . VPATH := $(srctree) -export srctree objtree VPATH +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 @@ -453,7 +450,7 @@ USERINCLUDE := \ LINUXINCLUDE := \ -I$(srctree)/arch/$(SRCARCH)/include \ -I$(objtree)/arch/$(SRCARCH)/include/generated \ - $(if $(filter .,$(srctree)),,-I$(srctree)/include) \ + $(if $(building_out_of_srctree),-I$(srctree)/include) \ -I$(objtree)/include \ $(USERINCLUDE) @@ -514,7 +511,7 @@ PHONY += outputmakefile # At the same time when output Makefile generated, generate .gitignore to # ignore whole output directory outputmakefile: -ifneq ($(srctree),.) +ifdef building_out_of_srctree $(Q)ln -fsn $(srctree) source $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree) $(Q)test -e .gitignore || \ @@ -1101,7 +1098,7 @@ PHONY += prepare archprepare prepare1 prepare3 # and if so do: # 1) Check that make has not been executed in the kernel src $(srctree) prepare3: include/config/kernel.release -ifneq ($(srctree),.) +ifdef building_out_of_srctree @$(kecho) ' Using $(srctree) as source for kernel' $(Q)if [ -f $(srctree)/.config -o \ -d $(srctree)/include/config -o \ -- cgit From 95fd3f87bfbe8edaa5e955e0f858a0a573c09ab6 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 6 Jul 2019 12:07:13 +0900 Subject: kbuild: add a flag to force absolute path for srctree In old days, Kbuild always used an absolute path for $(srctree). Since commit 890676c65d69 ("kbuild: Use relative path when building in the source tree"), $(srctree) is '.' when O= was not passed from the command line. Yet, using absolute paths is useful in some cases even without O=, for instance, to create a cscope file with absolute path tags. 'O=.' was known to work as a workaround to force Kbuild to use absolute paths even when you are building in the source tree. Since commit 25b146c5b8ce ("kbuild: allow Kbuild to start from any directory"), Kbuild is too clever to be tricked. Even if you pass 'O=.' Kbuild notices you are building in the source tree, then use '.' for $(srctree). So, 'make O=. cscope' is no help to create absolute path tags. We cannot force one or the other according to commit e93bc1a0cab3 ("Revert "kbuild: specify absolute paths for cscope""). Both of relative path and absolute path have pros and cons. This commit adds a new flag KBUILD_ABS_SRCTREE to allow users to choose the absolute path for $(srctree). 'make KBUILD_ABS_SRCTREE=1 cscope' will work as a replacement of 'make O=. cscope'. Reported-by: Pawan Gupta Signed-off-by: Masahiro Yamada --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 91ad737ff538..357fd3623144 100644 --- a/Makefile +++ b/Makefile @@ -244,6 +244,10 @@ else building_out_of_srctree := 1 endif +ifneq ($(KBUILD_ABS_SRCTREE),) +srctree := $(abs_srctree) +endif + objtree := . VPATH := $(srctree) -- cgit From 3a475b2166fd6aa5ac76e8c605dffdf7a2a457ee Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 9 Jul 2019 15:26:39 +0200 Subject: kbuild: Inform user to pass ARCH= for make mrproper When cross-compiling an out-of-tree build with an unclean source tree directory, the build fails with: /path/to/kernel/source/tree is not clean, please run 'make mrproper' in the '/path/to/kernel/source/tree' directory. However, doing so does not fix the problem, as "make mrproper" now requires passing the target architecture to the make command, else it won't remove $(srctree)/arch/$(SRCARCH)/include/generated. "git ls-files -o" doesn't give a clue, as it doesn't list (empty) directories, only files. Improve usability by including the ARCH= option in the error output. Fixes: a788b2ed81ab ("kbuild: check arch/$(SRCARCH)/include/generated before out-of-tree build") Signed-off-by: Geert Uytterhoeven Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 357fd3623144..d076840904e2 100644 --- a/Makefile +++ b/Makefile @@ -1107,7 +1107,7 @@ ifdef building_out_of_srctree $(Q)if [ -f $(srctree)/.config -o \ -d $(srctree)/include/config -o \ -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ - echo >&2 " $(srctree) is not clean, please run 'make mrproper'"; \ + echo >&2 " $(srctree) is not clean, please run 'make ARCH=$(ARCH) mrproper'"; \ echo >&2 " in the '$(srctree)' directory.";\ /bin/false; \ fi; -- cgit