From 16b59cd78595df5d77c535a08537f2d9dae61496 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Aug 2019 00:52:57 +0900 Subject: kbuild: move the Module.symvers check for external module build $(objtree)/Module.symvers is not required for descending into sub-directories. It is needed for the modpost stage. Move the Module.symvers check to the right place. Signed-off-by: Masahiro Yamada --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 1b23f95db176..a083dd9dce4a 100644 --- a/Makefile +++ b/Makefile @@ -1620,10 +1620,10 @@ $(objtree)/Module.symvers: module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD)) PHONY += $(module-dirs) modules -$(module-dirs): prepare $(objtree)/Module.symvers +$(module-dirs): prepare $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@) need-modorder=1 -modules: $(module-dirs) +modules: $(module-dirs) $(objtree)/Module.symvers @$(kecho) ' Building modules, stage 2.'; $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost -- cgit v1.2.3 From d4945049ad668f7472df50aaea98c7fea262e6d4 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Aug 2019 00:53:00 +0900 Subject: kbuild: remove 'make /' support 'make /' is just an alias for 'make ./'; this builds all objects of an external module, but skips the modpost stage. I am not a big fan of 'make /' since it looks as if it were touching the root directory of the system. I like 'make ./' better. I do not know how many people are using it, but let's show a hint if it is used. Also, move it close to the external module rules since this only makes sense for external modules. Signed-off-by: Masahiro Yamada --- Makefile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a083dd9dce4a..f78c50018299 100644 --- a/Makefile +++ b/Makefile @@ -1648,6 +1648,10 @@ $(clean-dirs): clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers +PHONY += / +/: + @echo >&2 '"$(MAKE) /" is no longer supported. Please use "$(MAKE) ./" instead.' + PHONY += help help: @echo ' Building external modules.' @@ -1783,11 +1787,6 @@ endif $(Q)$(MAKE) $(build)=$(build-dir) $(build-target:.ko=.mod) $(Q)echo $(build-target) > $(MODORDER) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost - -# Modules -PHONY += / -/: ./ - %/: prepare FORCE $(Q)$(MAKE) KBUILD_MODULES=1 $(build)=$(build-dir) need-modorder=1 -- cgit v1.2.3 From 125d059b624180b2c441181c797e41354bfe0649 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Aug 2019 00:53:02 +0900 Subject: kbuild: do not descend to ./Kbuild when cleaning 'make clean' descends into ./Kbuild, but does not clean anything since everything is added to no-clean-files. There is no need to descend to ./Kbuild in the first place. We can drop the no-clean-files assignment. With this, there is no more user of no-clean-files. I will keep it for a while to see whether a new user will appear. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/makefiles.rst | 6 ------ Kbuild | 3 --- Makefile | 2 +- 3 files changed, 1 insertion(+), 10 deletions(-) (limited to 'Makefile') diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index f4f0f7ffde2b..54e56a4368f3 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -787,12 +787,6 @@ This will delete the directory debian in the toplevel directory, including all subdirectories. To exclude certain files from make clean, use the $(no-clean-files) variable. -This is only a special case used in the top level Kbuild file: - - Example:: - - #Kbuild - no-clean-files := $(bounds-file) $(offsets-file) Usually kbuild descends down in subdirectories due to "obj-* := dir/", but in the architecture makefiles where the kbuild infrastructure diff --git a/Kbuild b/Kbuild index d40366e967d7..3109ac786e76 100644 --- a/Kbuild +++ b/Kbuild @@ -57,6 +57,3 @@ quiet_cmd_atomics = CALL $< old-atomics: scripts/atomic/check-atomics.sh FORCE $(call cmd,atomics) - -# Keep these three files during make clean -no-clean-files := $(bounds-file) $(offsets-file) $(timeconst-file) diff --git a/Makefile b/Makefile index f78c50018299..c815f16f31e8 100644 --- a/Makefile +++ b/Makefile @@ -1396,7 +1396,7 @@ DISTCLEAN_FILES += tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS # clean: rm-dirs := $(CLEAN_DIRS) clean: rm-files := $(CLEAN_FILES) -clean-dirs := $(addprefix _clean_, . $(vmlinux-alldirs)) +clean-dirs := $(addprefix _clean_, $(vmlinux-alldirs)) PHONY += $(clean-dirs) clean archclean vmlinuxclean $(clean-dirs): -- cgit v1.2.3 From 2042b5486bd311db67b85915ee6291905b72e270 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Aug 2019 00:53:03 +0900 Subject: kbuild: unset variables in top Makefile instead of setting 0 There is no need to set 0 to variables such as config-targets, mixed-targets, etc. Unset instead of setting 0 in order to use 'ifdef' to test them. I also renamed: config-targets -> config-build mixed-targets -> mixed-build dot-config -> need-config to clarify what we are doing. Signed-off-by: Masahiro Yamada --- Makefile | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index c815f16f31e8..6cddcc4ad6ac 100644 --- a/Makefile +++ b/Makefile @@ -272,32 +272,32 @@ no-dot-config-targets := $(clean-targets) \ no-sync-config-targets := $(no-dot-config-targets) install %install \ kernelrelease -config-targets := 0 -mixed-targets := 0 -dot-config := 1 -may-sync-config := 1 +config-build := +mixed-build := +need-config := 1 +may-sync-config := 1 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) - dot-config := 0 + need-config := endif endif ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) - may-sync-config := 0 + may-sync-config := endif endif ifneq ($(KBUILD_EXTMOD),) - may-sync-config := 0 + may-sync-config := endif ifeq ($(KBUILD_EXTMOD),) ifneq ($(filter config %config,$(MAKECMDGOALS)),) - config-targets := 1 + config-build := 1 ifneq ($(words $(MAKECMDGOALS)),1) - mixed-targets := 1 + mixed-build := 1 endif endif endif @@ -305,18 +305,18 @@ endif # For "make -j clean all", "make -j mrproper defconfig all", etc. ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) - mixed-targets := 1 + mixed-build := 1 endif endif # install and modules_install need also be processed one by one ifneq ($(filter install,$(MAKECMDGOALS)),) ifneq ($(filter modules_install,$(MAKECMDGOALS)),) - mixed-targets := 1 + mixed-build := 1 endif endif -ifeq ($(mixed-targets),1) +ifdef mixed-build # =========================================================================== # We're called with mixed targets (*config and build targets). # Handle them one by one. @@ -332,7 +332,7 @@ __build_one_by_one: $(MAKE) -f $(srctree)/Makefile $$i; \ done -else +else # !mixed-build include scripts/Kbuild.include @@ -544,7 +544,7 @@ endif # and from include/config/auto.conf.cmd to detect the compiler upgrade. CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1) -ifeq ($(config-targets),1) +ifdef config-build # =========================================================================== # *config targets only - make sure prerequisites are updated, and descend # in scripts/kconfig to make the *config target @@ -561,7 +561,7 @@ config: scripts_basic outputmakefile FORCE %config: scripts_basic outputmakefile FORCE $(Q)$(MAKE) $(build)=scripts/kconfig $@ -else +else #!config-build # =========================================================================== # Build targets only - this includes vmlinux, arch specific targets, clean # targets and others. In general all targets except *config targets. @@ -604,7 +604,7 @@ endif export KBUILD_MODULES KBUILD_BUILTIN -ifeq ($(dot-config),1) +ifdef need-config include include/config/auto.conf endif @@ -652,8 +652,8 @@ ARCH_AFLAGS := ARCH_CFLAGS := include arch/$(SRCARCH)/Makefile -ifeq ($(dot-config),1) -ifeq ($(may-sync-config),1) +ifdef need-config +ifdef may-sync-config # Read in dependencies to all Kconfig* files, make sure to run syncconfig if # changes are detected. This should be included after arch/$(SRCARCH)/Makefile # because some architectures define CROSS_COMPILE there. @@ -676,7 +676,7 @@ $(KCONFIG_CONFIG): # The syncconfig should be executed only once to make all the targets. %/auto.conf %/auto.conf.cmd %/tristate.conf: $(KCONFIG_CONFIG) $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig -else +else # !may-sync-config # External modules and some install targets need include/generated/autoconf.h # and include/config/auto.conf but do not care if they are up-to-date. # Use auto.conf to trigger the test @@ -692,7 +692,7 @@ include/config/auto.conf: /bin/false) endif # may-sync-config -endif # $(dot-config) +endif # need-config KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) @@ -1809,9 +1809,9 @@ existing-targets := $(wildcard $(sort $(targets))) -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) -endif # ifeq ($(config-targets),1) -endif # ifeq ($(mixed-targets),1) -endif # need-sub-make +endif # config-targets +endif # mixed-build +endif # need-sub-make PHONY += FORCE FORCE: -- cgit v1.2.3 From c99f3918cf0a64b99ac145591c7984891c64baa4 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Aug 2019 00:53:04 +0900 Subject: kbuild: unify vmlinux-dirs and module-dirs rules The in-kernel build and external module build have similar code for descending into sub-directories. Factor out the code into the common place. Signed-off-by: Masahiro Yamada --- Makefile | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 6cddcc4ad6ac..b68954827dd0 100644 --- a/Makefile +++ b/Makefile @@ -1016,6 +1016,8 @@ vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \ $(patsubst %/,%,$(filter %/, $(init-) $(core-) \ $(drivers-) $(net-) $(libs-) $(virt-)))) +build-dirs := $(vmlinux-dirs) + init-y := $(patsubst %/, %/built-in.a, $(init-y)) core-y := $(patsubst %/, %/built-in.a, $(core-y)) drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y)) @@ -1038,7 +1040,7 @@ vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) # Recurse until adjust_autoksyms.sh is satisfied PHONY += autoksyms_recursive ifdef CONFIG_TRIM_UNUSED_KSYMS -autoksyms_recursive: $(vmlinux-deps) modules.order +autoksyms_recursive: descend modules.order $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \ "$(MAKE) -f $(srctree)/Makefile vmlinux" endif @@ -1070,17 +1072,7 @@ targets := vmlinux # The actual objects are generated when descending, # make sure no implicit rule kicks in -$(sort $(vmlinux-deps)): $(vmlinux-dirs) ; - -# Handle descending into subdirectories listed in $(vmlinux-dirs) -# Preset locale variables to speed up the build process. Limit locale -# tweaks to this spot to avoid wrong language settings when running -# make menuconfig etc. -# Error messages still appears in the original language - -PHONY += $(vmlinux-dirs) -$(vmlinux-dirs): prepare - $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 +$(sort $(vmlinux-deps)): descend ; filechk_kernel.release = \ echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" @@ -1302,13 +1294,13 @@ modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order modules.builtin $(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)) > $@ +modules.order: descend + $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@ -modbuiltin-dirs := $(addprefix _modbuiltin_, $(vmlinux-dirs)) +modbuiltin-dirs := $(addprefix _modbuiltin_, $(build-dirs)) modules.builtin: $(modbuiltin-dirs) - $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(vmlinux-dirs)) > $@ + $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@ PHONY += $(modbuiltin-dirs) # tristate.conf is not included from this Makefile. Add it as a prerequisite @@ -1618,12 +1610,9 @@ $(objtree)/Module.symvers: echo " is missing; modules will have no dependencies and modversions."; \ echo ) -module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD)) -PHONY += $(module-dirs) modules -$(module-dirs): prepare - $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@) need-modorder=1 - -modules: $(module-dirs) $(objtree)/Module.symvers +build-dirs := $(KBUILD_EXTMOD) +PHONY += modules +modules: descend $(objtree)/Module.symvers @$(kecho) ' Building modules, stage 2.'; $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost @@ -1665,6 +1654,16 @@ help: PHONY += prepare endif # KBUILD_EXTMOD +# Handle descending into subdirectories listed in $(build-dirs) +# Preset locale variables to speed up the build process. Limit locale +# tweaks to this spot to avoid wrong language settings when running +# make menuconfig etc. +# Error messages still appears in the original language +PHONY += descend $(build-dirs) +descend: $(build-dirs) +$(build-dirs): prepare + $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 + clean: $(clean-dirs) $(call cmd,rmdirs) $(call cmd,rmfiles) -- cgit v1.2.3 From 76cd306d797923aabcf373289b231bf8d9a9340a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Aug 2019 00:53:05 +0900 Subject: kbuild: unify clean-dirs rule for in-kernel and external module Factor out the duplicated code for in-kernel and external module cleaning. Signed-off-by: Masahiro Yamada --- Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b68954827dd0..9661fa37158f 100644 --- a/Makefile +++ b/Makefile @@ -1017,6 +1017,7 @@ vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \ $(drivers-) $(net-) $(libs-) $(virt-)))) build-dirs := $(vmlinux-dirs) +clean-dirs := $(vmlinux-alldirs) init-y := $(patsubst %/, %/built-in.a, $(init-y)) core-y := $(patsubst %/, %/built-in.a, $(core-y)) @@ -1388,11 +1389,8 @@ DISTCLEAN_FILES += tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS # clean: rm-dirs := $(CLEAN_DIRS) clean: rm-files := $(CLEAN_FILES) -clean-dirs := $(addprefix _clean_, $(vmlinux-alldirs)) -PHONY += $(clean-dirs) clean archclean vmlinuxclean -$(clean-dirs): - $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) +PHONY += archclean vmlinuxclean vmlinuxclean: $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean @@ -1629,12 +1627,7 @@ PHONY += _emodinst_post _emodinst_post: _emodinst_ $(call cmd,depmod) -clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD)) - -PHONY += $(clean-dirs) clean -$(clean-dirs): - $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) - +clean-dirs := $(KBUILD_EXTMOD) clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers PHONY += / @@ -1664,6 +1657,11 @@ descend: $(build-dirs) $(build-dirs): prepare $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 +clean-dirs := $(addprefix _clean_, $(clean-dirs)) +PHONY += $(clean-dirs) clean +$(clean-dirs): + $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) + clean: $(clean-dirs) $(call cmd,rmdirs) $(call cmd,rmfiles) -- cgit v1.2.3 From 394053f4a4b3e3eeeaa67b67fc886a9a75bd9e4d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 15 Aug 2019 00:19:18 +0900 Subject: kbuild: make single targets work more correctly Currently, the single target build directly descends into the directory of the target. For example, $ make foo/bar/baz.o ... directly descends into foo/bar/. On the other hand, the normal build usually descends one directory at a time, i.e. descends into foo/, and then foo/bar/. This difference causes some problems. [1] miss subdir-asflags-y, subdir-ccflags-y in upper Makefiles The options in subdir-{as,cc}flags-y take effect in the current and its sub-directories. In other words, they are inherited downward. In the example above, the single target will miss subdir-{as,cc}flags-y if they are defined in foo/Makefile. [2] could be built in a different directory As Documentation/kbuild/modules.rst section 4.3 says, Kbuild can handle files that are spread over several sub-directories. The build rule of foo/bar/baz.o may not necessarily be specified in foo/bar/Makefile. It might be specifies in foo/Makefile as follows: [foo/Makefile] obj-y := bar/baz.o This often happens when a module is so big that its source files are divided into sub-directories. In this case, there is no Makefile in the foo/bar/ directory, yet the single target descends into foo/bar/, then fails due to the missing Makefile. You can still do 'make foo/bar/' for partial building, but cannot do 'make foo/bar/baz.s'. I believe the single target '%.s' is a useful feature for inspecting the compiler output. Some modules work around this issue by putting an empty Makefile in every sub-directory. This commit fixes those problems by making the single target build descend in the same way as the normal build does. Another change is the single target build will observe the CONFIG options. Previously, it allowed users to build the foo.o even when the corresponding CONFIG_FOO is disabled: obj-$(CONFIG_FOO) += foo.o In the new behavior, the single target build will just fail and show "No rule to make target ..." (or "Nothing to be done for ..." if the stale object already exists, but cannot be updated). The disadvantage of this commit is the build speed. Now that the single target build visits every directory and parses lots of Makefiles, it is slower than before. (But, I hope it will not be too slow.) Signed-off-by: Masahiro Yamada --- Makefile | 81 +++++++++++++++++++++++++++++++------------------- scripts/Makefile.build | 45 ++++++++++++++++++++++++---- 2 files changed, 89 insertions(+), 37 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9661fa37158f..68e7ac654f4c 100644 --- a/Makefile +++ b/Makefile @@ -230,6 +230,8 @@ endif export KBUILD_CHECKSRC KBUILD_EXTMOD +extmod-prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) + ifeq ($(abs_srctree),$(abs_objtree)) # building in the source tree srctree := . @@ -271,11 +273,13 @@ no-dot-config-targets := $(clean-targets) \ %asm-generic kernelversion %src-pkg no-sync-config-targets := $(no-dot-config-targets) install %install \ kernelrelease +single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/ config-build := mixed-build := need-config := 1 may-sync-config := 1 +single-build := ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) @@ -302,6 +306,14 @@ ifeq ($(KBUILD_EXTMOD),) endif endif +# We cannot build single targets and the others at the same time +ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),) + single-build := 1 + ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),) + mixed-build := 1 + endif +endif + # For "make -j clean all", "make -j mrproper defconfig all", etc. ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) @@ -1003,7 +1015,7 @@ endif PHONY += prepare0 -export MODORDER := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)modules.order +export MODORDER := $(extmod-prefix)modules.order ifeq ($(KBUILD_EXTMOD),) core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ @@ -1655,7 +1667,7 @@ endif # KBUILD_EXTMOD PHONY += descend $(build-dirs) descend: $(build-dirs) $(build-dirs): prepare - $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 + $(Q)$(MAKE) $(build)=$@ single-build=$(single-build) need-builtin=1 need-modorder=1 clean-dirs := $(addprefix _clean_, $(clean-dirs)) PHONY += $(clean-dirs) clean @@ -1752,40 +1764,47 @@ tools/%: FORCE # Single targets # --------------------------------------------------------------------------- -# Single targets are compatible with: -# - build with mixed source and output -# - build with separate output dir 'make O=...' -# - external modules +# To build individual files in subdirectories, you can do like this: +# +# make foo/bar/baz.s # -# target-dir => where to store outputfile -# build-dir => directory in kernel source tree to use - -build-target = $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD)/)$@ -build-dir = $(patsubst %/,%,$(dir $(build-target))) - -%.i: prepare FORCE - $(Q)$(MAKE) $(build)=$(build-dir) $(build-target) -%.ll: prepare FORCE - $(Q)$(MAKE) $(build)=$(build-dir) $(build-target) -%.lst: prepare FORCE - $(Q)$(MAKE) $(build)=$(build-dir) $(build-target) -%.o: prepare FORCE - $(Q)$(MAKE) $(build)=$(build-dir) $(build-target) -%.s: prepare FORCE - $(Q)$(MAKE) $(build)=$(build-dir) $(build-target) -%.symtypes: prepare FORCE - $(Q)$(MAKE) $(build)=$(build-dir) $(build-target) +# The supported suffixes for single-target are listed in 'single-targets' +# +# To build only under specific subdirectories, you can do like this: +# +# make foo/bar/baz/ + +ifdef single-build + +single-all := $(filter $(single-targets), $(MAKECMDGOALS)) + +# .ko is special because modpost is needed +single-ko := $(sort $(filter %.ko, $(single-all))) +single-no-ko := $(sort $(patsubst %.ko,%.mod, $(single-all))) + +$(single-ko): single_modpost + @: +$(single-no-ko): descend + @: + ifeq ($(KBUILD_EXTMOD),) -# For the single build of an in-tree module, use a temporary file to avoid +# For the single build of in-tree modules, use a temporary file to avoid # the situation of modules_install installing an invalid modules.order. -%.ko: MODORDER := .modules.tmp +MODORDER := .modules.tmp endif -%.ko: prepare FORCE - $(Q)$(MAKE) $(build)=$(build-dir) $(build-target:.ko=.mod) - $(Q)echo $(build-target) > $(MODORDER) + +PHONY += single_modpost +single_modpost: $(single-no-ko) + $(Q){ $(foreach m, $(single-ko), echo $(extmod-prefix)$m;) } > $(MODORDER) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost -%/: prepare FORCE - $(Q)$(MAKE) KBUILD_MODULES=1 $(build)=$(build-dir) need-modorder=1 + +KBUILD_MODULES := 1 + +export KBUILD_SINGLE_TARGETS := $(addprefix $(extmod-prefix), $(single-no-ko)) + +single-build = $(if $(filter-out $@/, $(single-no-ko)),1) + +endif # FIXME Should go into a make.lib or something # =========================================================================== diff --git a/scripts/Makefile.build b/scripts/Makefile.build index f84ccca8d74f..10adf3b558de 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -52,7 +52,7 @@ ifndef obj $(warning kbuild: Makefile.build is included improperly) endif -ifeq ($(MAKECMDGOALS)$(need-modorder),) +ifeq ($(need-modorder),) ifneq ($(obj-m),) $(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.) $(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.) @@ -76,11 +76,6 @@ endif mod-targets := $(patsubst %.o, %.mod, $(obj-m)) -__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ - $(if $(KBUILD_MODULES),$(obj-m) $(mod-targets) $(modorder-target)) \ - $(subdir-ym) $(always) - @: - # Linus' kernel sanity checking tool ifeq ($(KBUILD_CHECKSRC),1) quiet_cmd_checksrc = CHECK $< @@ -487,12 +482,50 @@ targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \ $(call intermediate_targets, .lex.o, .lex.c) \ $(call intermediate_targets, .tab.o, .tab.c .tab.h) +# Build +# --------------------------------------------------------------------------- + +ifdef single-build + +curdir-single := $(sort $(foreach x, $(KBUILD_SINGLE_TARGETS), \ + $(if $(filter $(x) $(basename $(x)).o, $(targets)), $(x)))) + +# Handle single targets without any rule: show "Nothing to be done for ..." or +# "No rule to make target ..." depending on whether the target exists. +unknown-single := $(filter-out $(addsuffix /%, $(subdir-ym)), \ + $(filter $(obj)/%, \ + $(filter-out $(curdir-single), \ + $(KBUILD_SINGLE_TARGETS)))) + +__build: $(curdir-single) $(subdir-ym) +ifneq ($(unknown-single),) + $(Q)$(MAKE) -f /dev/null $(unknown-single) +endif + @: + +ifeq ($(curdir-single),) +# Nothing to do in this directory. Do not include any .*.cmd file for speed-up +targets := +else +targets += $(curdir-single) +endif + +else + +__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ + $(if $(KBUILD_MODULES),$(obj-m) $(mod-targets) $(modorder-target)) \ + $(subdir-ym) $(always) + @: + +endif + # Descending # --------------------------------------------------------------------------- PHONY += $(subdir-ym) $(subdir-ym): $(Q)$(MAKE) $(build)=$@ \ + $(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \ need-builtin=$(if $(filter $@/built-in.a, $(subdir-obj-y)),1) \ need-modorder=$(if $(need-modorder),$(if $(filter $@/modules.order, $(modorder)),1)) -- cgit v1.2.3 From 10df063855822fcea3c0f51dbf534ad643d3cb1b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 15 Aug 2019 01:06:22 +0900 Subject: kbuild: rebuild modules when module linker scripts are updated Currently, the timestamp of module linker scripts are not checked. Add them to the dependency of modules so they are correctly rebuilt. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/makefiles.rst | 5 +++++ Makefile | 3 ++- arch/arm/Makefile | 2 +- arch/arm64/Makefile | 2 +- arch/ia64/Makefile | 2 +- arch/m68k/Makefile | 2 +- arch/parisc/Makefile | 2 +- arch/powerpc/Makefile | 2 +- arch/riscv/Makefile | 2 +- scripts/Makefile.modpost | 5 +++-- 10 files changed, 17 insertions(+), 10 deletions(-) (limited to 'Makefile') diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index 88c384da592e..68ed20ef37dd 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -993,6 +993,11 @@ When kbuild executes, the following steps are followed (roughly): The linker script with full path. Assigned by the top-level Makefile. + KBUILD_LDS_MODULE + + The module linker script with full path. Assigned by the top-level + Makefile and additionally by the arch Makefile. + KBUILD_VMLINUX_OBJS All object files for vmlinux. They are linked to vmlinux in the same diff --git a/Makefile b/Makefile index 68e7ac654f4c..9c524950f4b3 100644 --- a/Makefile +++ b/Makefile @@ -482,7 +482,8 @@ KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := KBUILD_AFLAGS_MODULE := -DMODULE KBUILD_CFLAGS_MODULE := -DMODULE -KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds +KBUILD_LDFLAGS_MODULE := +export KBUILD_LDS_MODULE := $(srctree)/scripts/module-common.lds KBUILD_LDFLAGS := GCC_PLUGINS_CFLAGS := CLANG_FLAGS := diff --git a/arch/arm/Makefile b/arch/arm/Makefile index c3624ca6c0bc..fbe50eec8f34 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -17,7 +17,7 @@ KBUILD_LDFLAGS_MODULE += --be8 endif ifeq ($(CONFIG_ARM_MODULE_PLTS),y) -KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/arm/kernel/module.lds +KBUILD_LDS_MODULE += $(srctree)/arch/arm/kernel/module.lds endif GZFLAGS :=-9 diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 61de992bbea3..d4ed1869e536 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -101,7 +101,7 @@ endif CHECKFLAGS += -D__aarch64__ ifeq ($(CONFIG_ARM64_MODULE_PLTS),y) -KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/arm64/kernel/module.lds +KBUILD_LDS_MODULE += $(srctree)/arch/arm64/kernel/module.lds endif # Default value diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile index 171290f9f1de..5c3bcaee5980 100644 --- a/arch/ia64/Makefile +++ b/arch/ia64/Makefile @@ -20,7 +20,7 @@ CHECKFLAGS += -D__ia64=1 -D__ia64__=1 -D_LP64 -D__LP64__ OBJCOPYFLAGS := --strip-all LDFLAGS_vmlinux := -static -KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/ia64/module.lds +KBUILD_LDS_MODULE += $(srctree)/arch/ia64/module.lds KBUILD_AFLAGS_KERNEL := -mconstant-gp EXTRA := diff --git a/arch/m68k/Makefile b/arch/m68k/Makefile index 482513b9af2c..5d9288384096 100644 --- a/arch/m68k/Makefile +++ b/arch/m68k/Makefile @@ -73,7 +73,7 @@ KBUILD_AFLAGS += -D__uClinux__ endif KBUILD_LDFLAGS := -m m68kelf -KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/m68k/kernel/module.lds +KBUILD_LDS_MODULE += $(srctree)/arch/m68k/kernel/module.lds ifdef CONFIG_SUN3 LDFLAGS_vmlinux = -N diff --git a/arch/parisc/Makefile b/arch/parisc/Makefile index 3b77d729057f..36b834f1c933 100644 --- a/arch/parisc/Makefile +++ b/arch/parisc/Makefile @@ -60,7 +60,7 @@ KBUILD_CFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY=1 \ -DFTRACE_PATCHABLE_FUNCTION_SIZE=$(NOP_COUNT) CC_FLAGS_FTRACE := -fpatchable-function-entry=$(NOP_COUNT),$(shell echo $$(($(NOP_COUNT)-1))) -KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/parisc/kernel/module.lds +KBUILD_LDS_MODULE += $(srctree)/arch/parisc/kernel/module.lds endif OBJCOPY_FLAGS =-O binary -R .note -R .comment -S diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index c345b79414a9..b2227855de20 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile @@ -67,7 +67,7 @@ UTS_MACHINE := $(subst $(space),,$(machine-y)) ifdef CONFIG_PPC32 KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o else -KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/powerpc/kernel/module.lds +KBUILD_LDS_MODULE += $(srctree)/arch/powerpc/kernel/module.lds ifeq ($(call ld-ifversion, -ge, 225000000, y),y) # Have the linker provide sfpr if possible. # There is a corresponding test in arch/powerpc/lib/Makefile diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 7a117be8297c..426d989125a8 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -52,7 +52,7 @@ ifeq ($(CONFIG_CMODEL_MEDANY),y) KBUILD_CFLAGS += -mcmodel=medany endif ifeq ($(CONFIG_MODULE_SECTIONS),y) - KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/riscv/kernel/module.lds + KBUILD_LDS_MODULE += $(srctree)/arch/riscv/kernel/module.lds endif KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index bf15818f6947..905db30d6622 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -126,10 +126,11 @@ quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o = \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - -o $@ $(real-prereqs) ; \ + $(addprefix -T , $(KBUILD_LDS_MODULE)) \ + -o $@ $(filter %.o, $^); \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) -$(modules): %.ko :%.o %.mod.o FORCE +$(modules): %.ko :%.o %.mod.o $(KBUILD_LDS_MODULE) FORCE +$(call if_changed,ld_ko_o) targets += $(modules) -- cgit v1.2.3 From 9b9a3f20cbe0ba9269cde6fff9f9c69907e150cf Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 15 Aug 2019 01:06:23 +0900 Subject: kbuild: split final module linking out into Makefile.modfinal I think splitting the modpost and linking modules into separate Makefiles will be useful especially when more complex build steps come in. The main motivation of this commit is to integrate the proposed klp-convert feature cleanly. I moved the logging 'Building modules, stage 2.' to Makefile.modpost to avoid the code duplication although I do not know whether or not this message is needed in the first place. Signed-off-by: Masahiro Yamada --- Makefile | 2 -- scripts/Makefile.modfinal | 60 +++++++++++++++++++++++++++++++++++ scripts/Makefile.modpost | 79 +++++++---------------------------------------- 3 files changed, 71 insertions(+), 70 deletions(-) create mode 100644 scripts/Makefile.modfinal (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9c524950f4b3..db2ddd53d557 100644 --- a/Makefile +++ b/Makefile @@ -1304,7 +1304,6 @@ all: modules PHONY += modules 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 @@ -1624,7 +1623,6 @@ $(objtree)/Module.symvers: build-dirs := $(KBUILD_EXTMOD) PHONY += modules modules: descend $(objtree)/Module.symvers - @$(kecho) ' Building modules, stage 2.'; $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost PHONY += modules_install diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal new file mode 100644 index 000000000000..c8875f62dd96 --- /dev/null +++ b/scripts/Makefile.modfinal @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: GPL-2.0-only +# =========================================================================== +# Module final link +# =========================================================================== + +PHONY := __modfinal +__modfinal: + +include $(srctree)/scripts/Kbuild.include + +# for c_flags +include $(srctree)/scripts/Makefile.lib + +# find all modules listed in modules.order +modules := $(sort $(shell cat $(MODORDER))) + +__modfinal: $(modules) + @: + +# modname is set to make c_flags define KBUILD_MODNAME +modname = $(notdir $(@:.mod.o=)) + +quiet_cmd_cc_o_c = CC [M] $@ + cmd_cc_o_c = $(CC) $(c_flags) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE) \ + -c -o $@ $< + +%.mod.o: %.mod.c FORCE + $(call if_changed_dep,cc_o_c) + +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) + +quiet_cmd_ld_ko_o = LD [M] $@ + cmd_ld_ko_o = \ + $(LD) -r $(KBUILD_LDFLAGS) \ + $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ + $(addprefix -T , $(KBUILD_LDS_MODULE)) \ + -o $@ $(filter %.o, $^); \ + $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) + +$(modules): %.ko: %.o %.mod.o $(KBUILD_LDS_MODULE) FORCE + +$(call if_changed,ld_ko_o) + +targets += $(modules) $(modules:.ko=.mod.o) + +# Add FORCE to the prequisites of a target to force it to be always rebuilt. +# --------------------------------------------------------------------------- + +PHONY += FORCE +FORCE: + +# Read all saved command lines and dependencies for the $(targets) we +# may be building above, using $(if_changed{,_dep}). As an +# optimization, we don't need to read them if the target does not +# exist, we will rebuild anyway in that case. + +existing-targets := $(wildcard $(sort $(targets))) + +-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) + +.PHONY: $(PHONY) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 905db30d6622..9800a3988f23 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -15,8 +15,6 @@ # 2) modpost is then used to # 3) create one .mod.c file pr. module # 4) create one Module.symvers file with CRC for all exported symbols -# 5) compile all .mod.c files -# 6) final link of the module to a file # Step 3 is used to place certain information in the module's ELF # section, including information such as: @@ -60,13 +58,10 @@ MODPOST = scripts/mod/modpost \ ifdef MODPOST_VMLINUX -__modpost: vmlinux.o +quiet_cmd_modpost = MODPOST vmlinux.o + cmd_modpost = $(MODPOST) vmlinux.o -quiet_cmd_modpost = MODPOST $@ - cmd_modpost = $(MODPOST) $@ - -PHONY += vmlinux.o -vmlinux.o: +__modpost: $(call cmd,modpost) else @@ -83,74 +78,22 @@ include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \ $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile) endif -include scripts/Makefile.lib +MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s -T - $(wildcard vmlinux) # find all modules listed in modules.order modules := $(sort $(shell cat $(MODORDER))) -# Stop after building .o files if NOFINAL is set. Makes compile tests quicker -__modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules)) - @: - -MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s -T - $(wildcard vmlinux) - -# We can go over command line length here, so be careful. +# Read out modules.order instead of expanding $(modules) to pass in modpost. +# Otherwise, allmodconfig would fail with "Argument list too long". quiet_cmd_modpost = MODPOST $(words $(modules)) modules cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) -PHONY += modules-modpost -modules-modpost: +__modpost: + @$(kecho) ' Building modules, stage 2.' $(call cmd,modpost) - -# Declare generated files as targets for modpost -$(modules:.ko=.mod.c): modules-modpost - -# Step 5), compile all *.mod.c files - -# modname is set to make c_flags define KBUILD_MODNAME -modname = $(notdir $(@:.mod.o=)) - -quiet_cmd_cc_o_c = CC [M] $@ - cmd_cc_o_c = $(CC) $(c_flags) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE) \ - -c -o $@ $< - -$(modules:.ko=.mod.o): %.mod.o: %.mod.c FORCE - $(call if_changed_dep,cc_o_c) - -targets += $(modules:.ko=.mod.o) - -ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) - -# Step 6), final link of the modules with optional arch pass after final link -quiet_cmd_ld_ko_o = LD [M] $@ - cmd_ld_ko_o = \ - $(LD) -r $(KBUILD_LDFLAGS) \ - $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - $(addprefix -T , $(KBUILD_LDS_MODULE)) \ - -o $@ $(filter %.o, $^); \ - $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) - -$(modules): %.ko :%.o %.mod.o $(KBUILD_LDS_MODULE) FORCE - +$(call if_changed,ld_ko_o) - -targets += $(modules) - - -# Add FORCE to the prequisites of a target to force it to be always rebuilt. -# --------------------------------------------------------------------------- - -PHONY += FORCE - -FORCE: - -# Read all saved command lines and dependencies for the $(targets) we -# may be building above, using $(if_changed{,_dep}). As an -# optimization, we don't need to read them if the target does not -# exist, we will rebuild anyway in that case. - -existing-targets := $(wildcard $(sort $(targets))) - --include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) +ifneq ($(KBUILD_MODPOST_NOFINAL),1) + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal +endif endif -- cgit v1.2.3 From 46a63d4b0d79cf9e8afa3879acf9f6cf74a84a08 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 21 Aug 2019 16:02:02 +0900 Subject: kbuild: pkg: clean up package files/dirs from the top Makefile I am not a big fan of the $(objtree)/ hack for clean-files/clean-dirs. These are created in the top of $(objtree), so let's clean them up from the top Makefile. Signed-off-by: Masahiro Yamada --- Makefile | 6 ++++-- scripts/Makefile | 2 +- scripts/package/Makefile | 9 --------- 3 files changed, 5 insertions(+), 12 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index db2ddd53d557..69cb3ec35d3c 100644 --- a/Makefile +++ b/Makefile @@ -1386,12 +1386,14 @@ CLEAN_FILES += modules.builtin.modinfo # Directories & files removed with 'make mrproper' MRPROPER_DIRS += include/config include/generated \ - arch/$(SRCARCH)/include/generated .tmp_objdiff + arch/$(SRCARCH)/include/generated .tmp_objdiff \ + debian/ snap/ tar-install/ MRPROPER_FILES += .config .config.old .version \ Module.symvers \ signing_key.pem signing_key.priv signing_key.x509 \ x509.genkey extra_certificates signing_key.x509.keyid \ - signing_key.x509.signer vmlinux-gdb.py + signing_key.x509.signer vmlinux-gdb.py \ + *.spec # Directories & files removed with 'make distclean' DISTCLEAN_DIRS += diff --git a/scripts/Makefile b/scripts/Makefile index 16bcb8087899..c42891e10ba3 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -36,4 +36,4 @@ subdir-$(CONFIG_MODVERSIONS) += genksyms subdir-$(CONFIG_SECURITY_SELINUX) += selinux # Let clean descend into subdirs -subdir- += basic dtc gdb kconfig mod package +subdir- += basic dtc gdb kconfig mod diff --git a/scripts/package/Makefile b/scripts/package/Makefile index ca7f46b562a4..a2d8830f54be 100644 --- a/scripts/package/Makefile +++ b/scripts/package/Makefile @@ -65,8 +65,6 @@ binrpm-pkg: FORCE +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ $(UTS_MACHINE) -bb $(objtree)/binkernel.spec -clean-files += $(objtree)/*.spec - deb-pkg: FORCE $(MAKE) clean $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian @@ -82,8 +80,6 @@ bindeb-pkg: FORCE intdeb-pkg: FORCE +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb -clean-dirs += $(objtree)/debian/ - # snap-pkg # --------------------------------------------------------------------------- snap-pkg: FORCE @@ -98,17 +94,12 @@ snap-pkg: FORCE cd $(objtree)/snap && \ snapcraft --target-arch=$(UTS_MACHINE) -clean-dirs += $(objtree)/snap/ - # tarball targets # --------------------------------------------------------------------------- tar%pkg: FORCE $(MAKE) -f $(srctree)/Makefile +$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@ -clean-dirs += $(objtree)/tar-install/ - - # perf-pkg - generate a source tarball with perf source # --------------------------------------------------------------------------- -- cgit v1.2.3 From 000ec95fbe757401b5da1c9904840085204e5b3d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 21 Aug 2019 16:02:04 +0900 Subject: kbuild: pkg: rename scripts/package/Makefile to scripts/Makefile.package scripts/package/Makefile does not use $(obj) or $(src) at all. It actually generates files and directories in the top of $(objtree). I do not see much sense in descending into scripts/package/. Signed-off-by: Masahiro Yamada --- Makefile | 8 +-- scripts/Makefile.package | 159 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/package/Makefile | 156 ---------------------------------------------- 3 files changed, 162 insertions(+), 161 deletions(-) create mode 100644 scripts/Makefile.package delete mode 100644 scripts/package/Makefile (limited to 'Makefile') diff --git a/Makefile b/Makefile index 69cb3ec35d3c..668e65c47ee1 100644 --- a/Makefile +++ b/Makefile @@ -1445,13 +1445,11 @@ distclean: mrproper # Packaging of the kernel to various formats # --------------------------------------------------------------------------- -package-dir := scripts/package %src-pkg: FORCE - $(Q)$(MAKE) $(build)=$(package-dir) $@ + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ %pkg: include/config/kernel.release FORCE - $(Q)$(MAKE) $(build)=$(package-dir) $@ - + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ # Brief documentation of the typical targets used # --------------------------------------------------------------------------- @@ -1523,7 +1521,7 @@ help: @echo ' or "cd tools; make help"' @echo '' @echo 'Kernel packaging:' - @$(MAKE) $(build)=$(package-dir) help + @$(MAKE) -f $(srctree)/scripts/Makefile.package help @echo '' @echo 'Documentation targets:' @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp diff --git a/scripts/Makefile.package b/scripts/Makefile.package new file mode 100644 index 000000000000..56eadcc48d46 --- /dev/null +++ b/scripts/Makefile.package @@ -0,0 +1,159 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Makefile for the different targets used to generate full packages of a kernel + +include $(srctree)/scripts/Kbuild.include + +# RPM target +# --------------------------------------------------------------------------- +# The rpm target generates two rpm files: +# /usr/src/packages/SRPMS/kernel-2.6.7rc2-1.src.rpm +# /usr/src/packages/RPMS/i386/kernel-2.6.7rc2-1..rpm +# The src.rpm files includes all source for the kernel being built +# The .rpm includes kernel configuration, modules etc. +# +# Process to create the rpm files +# a) clean the kernel +# b) Generate .spec file +# c) Build a tar ball, using symlink to make kernel version +# first entry in the path +# d) and pack the result to a tar.gz file +# e) generate the rpm files, based on kernel.spec +# - Use /. to avoid tar packing just the symlink + +# Note that the rpm-pkg target cannot be used with KBUILD_OUTPUT, +# but the binrpm-pkg target can; for some reason O= gets ignored. + +# Remove hyphens since they have special meaning in RPM filenames +KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) +KDEB_SOURCENAME ?= linux-$(KERNELRELEASE) +KBUILD_PKG_ROOTCMD ?="fakeroot -u" +export KDEB_SOURCENAME +# Include only those top-level files that are needed by make, plus the GPL copy +TAR_CONTENT := $(KBUILD_ALLDIRS) .config .scmversion Makefile \ + Kbuild Kconfig COPYING $(wildcard localversion*) +MKSPEC := $(srctree)/scripts/package/mkspec + +quiet_cmd_src_tar = TAR $(2).tar.gz + cmd_src_tar = \ +if test "$(objtree)" != "$(srctree)"; then \ + echo >&2; \ + echo >&2 " ERROR:"; \ + echo >&2 " Building source tarball is not possible outside the"; \ + echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \ + echo >&2 " binrpm-pkg or bindeb-pkg target instead."; \ + echo >&2; \ + false; \ +fi ; \ +$(srctree)/scripts/setlocalversion --save-scmversion; \ +tar -cz $(RCS_TAR_IGNORE) -f $(2).tar.gz \ + --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3); \ +rm -f $(objtree)/.scmversion + +# rpm-pkg +# --------------------------------------------------------------------------- +PHONY += rpm-pkg +rpm-pkg: + $(MAKE) clean + $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec + $(call cmd,src_tar,$(KERNELPATH),kernel.spec) + +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz \ + --define='_smp_mflags %{nil}' + +# binrpm-pkg +# --------------------------------------------------------------------------- +PHONY += binrpm-pkg +binrpm-pkg: + $(MAKE) -f $(srctree)/Makefile + $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec + +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ + $(UTS_MACHINE) -bb $(objtree)/binkernel.spec + +PHONY += deb-pkg +deb-pkg: + $(MAKE) clean + $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian + $(call cmd,src_tar,$(KDEB_SOURCENAME)) + origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\ + mv $(KDEB_SOURCENAME).tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz + +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -i.git -us -uc + +PHONY += bindeb-pkg +bindeb-pkg: + $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian + +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc + +PHONY += intdeb-pkg +intdeb-pkg: + +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb + +# snap-pkg +# --------------------------------------------------------------------------- +PHONY += snap-pkg +snap-pkg: + rm -rf $(objtree)/snap + mkdir $(objtree)/snap + $(MAKE) clean + $(call cmd,src_tar,$(KERNELPATH)) + sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \ + s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \ + $(srctree)/scripts/package/snapcraft.template > \ + $(objtree)/snap/snapcraft.yaml + cd $(objtree)/snap && \ + snapcraft --target-arch=$(UTS_MACHINE) + +# tarball targets +# --------------------------------------------------------------------------- +tar-pkgs := tar-pkg targz-pkg tarbz2-pkg tarxz-pkg +PHONY += $(tar-pkgs) +$(tar-pkgs): + $(MAKE) -f $(srctree)/Makefile + +$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@ + +# perf-pkg - generate a source tarball with perf source +# --------------------------------------------------------------------------- + +perf-tar=perf-$(KERNELVERSION) + +quiet_cmd_perf_tar = TAR + cmd_perf_tar = \ +git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \ + HEAD^{tree} $$(cd $(srctree); \ + echo $$(cat tools/perf/MANIFEST)) \ + -o $(perf-tar).tar; \ +mkdir -p $(perf-tar); \ +git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \ +(cd $(srctree)/tools/perf; \ +util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \ +tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \ +rm -r $(perf-tar); \ +$(if $(findstring tar-src,$@),, \ +$(if $(findstring bz2,$@),bzip2, \ +$(if $(findstring gz,$@),gzip, \ +$(if $(findstring xz,$@),xz, \ +$(error unknown target $@)))) \ + -f -9 $(perf-tar).tar) + +perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg perf-tarxz-src-pkg +PHONY += $(perf-tar-pkgs) +$(perf-tar-pkgs): + $(call cmd,perf_tar) + +# Help text displayed when executing 'make help' +# --------------------------------------------------------------------------- +PHONY += help +help: + @echo ' rpm-pkg - Build both source and binary RPM kernel packages' + @echo ' binrpm-pkg - Build only the binary kernel RPM package' + @echo ' deb-pkg - Build both source and binary deb kernel packages' + @echo ' bindeb-pkg - Build only the binary kernel deb package' + @echo ' snap-pkg - Build only the binary kernel snap package (will connect to external hosts)' + @echo ' tar-pkg - Build the kernel as an uncompressed tarball' + @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' + @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' + @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' + @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball' + @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball' + @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball' + @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball' + +.PHONY: $(PHONY) diff --git a/scripts/package/Makefile b/scripts/package/Makefile deleted file mode 100644 index 407189d9942a..000000000000 --- a/scripts/package/Makefile +++ /dev/null @@ -1,156 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Makefile for the different targets used to generate full packages of a kernel -# It uses the generic clean infrastructure of kbuild - -# RPM target -# --------------------------------------------------------------------------- -# The rpm target generates two rpm files: -# /usr/src/packages/SRPMS/kernel-2.6.7rc2-1.src.rpm -# /usr/src/packages/RPMS/i386/kernel-2.6.7rc2-1..rpm -# The src.rpm files includes all source for the kernel being built -# The .rpm includes kernel configuration, modules etc. -# -# Process to create the rpm files -# a) clean the kernel -# b) Generate .spec file -# c) Build a tar ball, using symlink to make kernel version -# first entry in the path -# d) and pack the result to a tar.gz file -# e) generate the rpm files, based on kernel.spec -# - Use /. to avoid tar packing just the symlink - -# Note that the rpm-pkg target cannot be used with KBUILD_OUTPUT, -# but the binrpm-pkg target can; for some reason O= gets ignored. - -# Remove hyphens since they have special meaning in RPM filenames -KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) -KDEB_SOURCENAME ?= linux-$(KERNELRELEASE) -KBUILD_PKG_ROOTCMD ?="fakeroot -u" -export KDEB_SOURCENAME -# Include only those top-level files that are needed by make, plus the GPL copy -TAR_CONTENT := $(KBUILD_ALLDIRS) .config .scmversion Makefile \ - Kbuild Kconfig COPYING $(wildcard localversion*) -MKSPEC := $(srctree)/scripts/package/mkspec - -quiet_cmd_src_tar = TAR $(2).tar.gz - cmd_src_tar = \ -if test "$(objtree)" != "$(srctree)"; then \ - echo >&2; \ - echo >&2 " ERROR:"; \ - echo >&2 " Building source tarball is not possible outside the"; \ - echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \ - echo >&2 " binrpm-pkg or bindeb-pkg target instead."; \ - echo >&2; \ - false; \ -fi ; \ -$(srctree)/scripts/setlocalversion --save-scmversion; \ -tar -cz $(RCS_TAR_IGNORE) -f $(2).tar.gz \ - --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3); \ -rm -f $(objtree)/.scmversion - -# rpm-pkg -# --------------------------------------------------------------------------- -PHONY += rpm-pkg -rpm-pkg: - $(MAKE) clean - $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec - $(call cmd,src_tar,$(KERNELPATH),kernel.spec) - +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz \ - --define='_smp_mflags %{nil}' - -# binrpm-pkg -# --------------------------------------------------------------------------- -PHONY += binrpm-pkg -binrpm-pkg: - $(MAKE) -f $(srctree)/Makefile - $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec - +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ - $(UTS_MACHINE) -bb $(objtree)/binkernel.spec - -PHONY += deb-pkg -deb-pkg: - $(MAKE) clean - $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian - $(call cmd,src_tar,$(KDEB_SOURCENAME)) - origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\ - mv $(KDEB_SOURCENAME).tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz - +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -i.git -us -uc - -PHONY += bindeb-pkg -bindeb-pkg: - $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian - +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc - -PHONY += intdeb-pkg -intdeb-pkg: - +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb - -# snap-pkg -# --------------------------------------------------------------------------- -PHONY += snap-pkg -snap-pkg: - rm -rf $(objtree)/snap - mkdir $(objtree)/snap - $(MAKE) clean - $(call cmd,src_tar,$(KERNELPATH)) - sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \ - s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \ - $(srctree)/scripts/package/snapcraft.template > \ - $(objtree)/snap/snapcraft.yaml - cd $(objtree)/snap && \ - snapcraft --target-arch=$(UTS_MACHINE) - -# tarball targets -# --------------------------------------------------------------------------- -tar-pkgs := tar-pkg targz-pkg tarbz2-pkg tarxz-pkg -PHONY += $(tar-pkgs) -$(tar-pkgs): - $(MAKE) -f $(srctree)/Makefile - +$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@ - -# perf-pkg - generate a source tarball with perf source -# --------------------------------------------------------------------------- - -perf-tar=perf-$(KERNELVERSION) - -quiet_cmd_perf_tar = TAR - cmd_perf_tar = \ -git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \ - HEAD^{tree} $$(cd $(srctree); \ - echo $$(cat tools/perf/MANIFEST)) \ - -o $(perf-tar).tar; \ -mkdir -p $(perf-tar); \ -git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \ -(cd $(srctree)/tools/perf; \ -util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \ -tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \ -rm -r $(perf-tar); \ -$(if $(findstring tar-src,$@),, \ -$(if $(findstring bz2,$@),bzip2, \ -$(if $(findstring gz,$@),gzip, \ -$(if $(findstring xz,$@),xz, \ -$(error unknown target $@)))) \ - -f -9 $(perf-tar).tar) - -perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg perf-tarxz-src-pkg -PHONY += $(perf-tar-pkgs) -$(perf-tar-pkgs): - $(call cmd,perf_tar) - -# Help text displayed when executing 'make help' -# --------------------------------------------------------------------------- -PHONY += help -help: - @echo ' rpm-pkg - Build both source and binary RPM kernel packages' - @echo ' binrpm-pkg - Build only the binary kernel RPM package' - @echo ' deb-pkg - Build both source and binary deb kernel packages' - @echo ' bindeb-pkg - Build only the binary kernel deb package' - @echo ' snap-pkg - Build only the binary kernel snap package (will connect to external hosts)' - @echo ' tar-pkg - Build the kernel as an uncompressed tarball' - @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' - @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' - @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' - @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball' - @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball' - @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball' - @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball' -- cgit v1.2.3 From 3e4c6948e78b495708a99c0599e50f0faffb2ade Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 21 Aug 2019 16:03:48 +0900 Subject: kbuild: remove unneeded '+' marker from kselftest-merge This line contains $(MAKE), so Make knows that it will invoke sub-make without help of the '+' marker. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 668e65c47ee1..3f95d1d04b08 100644 --- a/Makefile +++ b/Makefile @@ -1250,7 +1250,7 @@ kselftest-merge: $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!)) $(Q)find $(srctree)/tools/testing/selftests -name config | \ xargs $(srctree)/scripts/kconfig/merge_config.sh -m $(objtree)/.config - +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig + $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig # --------------------------------------------------------------------------- # Devicetree files -- cgit v1.2.3 From bc7b752a7a1c8498f5c48f5b1b63147e32f649dc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Aug 2019 02:33:21 +0900 Subject: kbuild: remove unneeded dependency for $(DOC_TARGETS) Commit 415008af3219 ("docs-rst: convert lsm from DocBook to ReST") stopped using if_changed_rule. There is no more users of if_changed* for the doc targets. Hence, fixdep is unneeded. Remove the dependency on scripts_basic. All the doc targets are phony. The dependency on FORCE is not needed either. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 3f95d1d04b08..48836d17d1e2 100644 --- a/Makefile +++ b/Makefile @@ -1575,7 +1575,7 @@ $(help-board-dirs): help-%: DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ linkcheckdocs dochelp refcheckdocs PHONY += $(DOC_TARGETS) -$(DOC_TARGETS): scripts_basic FORCE +$(DOC_TARGETS): $(Q)$(MAKE) $(build)=Documentation $@ # Misc -- cgit v1.2.3 From 59747fb8693fee55d2184295d2a4b8b91e0203ee Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Aug 2019 13:46:08 +0900 Subject: kbuild: remove 'Using ... as source for kernel' message You already know the location of the source tree without this message. Signed-off-by: Masahiro Yamada --- Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 48836d17d1e2..c79c85126f0c 100644 --- a/Makefile +++ b/Makefile @@ -1115,7 +1115,6 @@ PHONY += prepare archprepare prepare3 # 1) Check that make has not been executed in the kernel src $(srctree) prepare3: include/config/kernel.release ifdef building_out_of_srctree - @$(kecho) ' Using $(srctree) as source for kernel' $(Q)if [ -f $(srctree)/.config -o \ -d $(srctree)/include/config -o \ -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ -- cgit v1.2.3 From 621da4ba0e244ba3cfb2e8a9a9055299ec0ab0d3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Aug 2019 13:46:09 +0900 Subject: kbuild: Inform user to pass ARCH= for make mrproper only when necessary Since commit 3a475b2166fd ("kbuild: Inform user to pass ARCH= for make mrproper"), if you try out-of-tree build with an unclean source tree, it suggests to run 'make ARCH= mrproper'. This looks odd when you are not cross-compiling the kernel. Show the 'ARCH=' part only when ARCH= was given from the command line. If ARCH is the default (native build) or came from the environment, it should simply suggest 'make mrproper' as before. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index c79c85126f0c..d5d0742efeb2 100644 --- a/Makefile +++ b/Makefile @@ -1118,7 +1118,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 ARCH=$(ARCH) mrproper'"; \ + echo >&2 " $(srctree) is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ echo >&2 " in the '$(srctree)' directory.";\ /bin/false; \ fi; -- cgit v1.2.3 From 1a475d5486755fcf48d710cb7dc3a8a5f7bad573 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Aug 2019 13:46:10 +0900 Subject: kbuild: clarify where to run make mrproper when out-of-tree fails If you try out-of-tree build with an unclean source tree, Kbuild suggests to run make mrproper. The path to the source tree may be shown with a relative path, for example, "make O=foo" emits the following: .. is not clean, please run 'make mrproper' in the '..' directory. This is somewhat confusing if you ran "make O=foo" in the source tree. Using the absolute path will be clearer. This commit changes the error message like follows: *** *** The source tree is not clean, please run 'make mrproper' *** in /absolute/path/to/linux *** Signed-off-by: Masahiro Yamada --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index d5d0742efeb2..132cc1209781 100644 --- a/Makefile +++ b/Makefile @@ -1118,8 +1118,10 @@ 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$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ - echo >&2 " in the '$(srctree)' directory.";\ + echo >&2 "***"; \ + echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ + echo >&2 "*** in $(abs_srctree)";\ + echo >&2 "***"; \ /bin/false; \ fi; endif -- cgit v1.2.3 From e8e83a236d36dac639b4846f17fa7c47013b4b95 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Aug 2019 13:46:11 +0900 Subject: kbuild: move the clean srctree check to the outputmakefile target With this commit, the error report is shown earlier, even before running kconfig. Signed-off-by: Masahiro Yamada --- Makefile | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 132cc1209781..37b9a2b83393 100644 --- a/Makefile +++ b/Makefile @@ -519,6 +519,7 @@ scripts_basic: $(Q)rm -f .tmp_quiet_recordmcount PHONY += outputmakefile +# Before starting out-of-tree build, make sure the source tree is clean. # outputmakefile generates a Makefile in the output directory, if using a # separate output directory. This allows convenient use of make in the # output directory. @@ -526,6 +527,15 @@ PHONY += outputmakefile # ignore whole output directory outputmakefile: 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 "***"; \ + echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ + echo >&2 "*** in $(abs_srctree)";\ + echo >&2 "***"; \ + false; \ + fi $(Q)ln -fsn $(srctree) source $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree) $(Q)test -e .gitignore || \ @@ -1110,21 +1120,7 @@ scripts: scripts_basic scripts_dtc PHONY += prepare archprepare prepare3 -# prepare3 is used to check if we are building in a separate output directory, -# and if so do: -# 1) Check that make has not been executed in the kernel src $(srctree) prepare3: include/config/kernel.release -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 "***"; \ - echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ - echo >&2 "*** in $(abs_srctree)";\ - echo >&2 "***"; \ - /bin/false; \ - fi; -endif archprepare: archheaders archscripts scripts prepare3 outputmakefile \ asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h -- cgit v1.2.3 From a5139fb368d2639afc6a3ea7e444f22a3e8ed3be Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Aug 2019 13:46:12 +0900 Subject: kbuild: remove prepare3 target Now prepare3 does nothing but depends on include/config/kernel.release Signed-off-by: Masahiro Yamada --- Makefile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 37b9a2b83393..5458fbaf7fc8 100644 --- a/Makefile +++ b/Makefile @@ -1118,11 +1118,9 @@ scripts: scripts_basic scripts_dtc # archprepare is used in arch Makefiles and when processed asm symlink, # version.h and scripts_basic is processed / created. -PHONY += prepare archprepare prepare3 +PHONY += prepare archprepare -prepare3: include/config/kernel.release - -archprepare: archheaders archscripts scripts prepare3 outputmakefile \ +archprepare: archheaders archscripts scripts include/config/kernel.release outputmakefile \ asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h prepare0: archprepare @@ -1258,11 +1256,11 @@ endif ifneq ($(dtstree),) -%.dtb: prepare3 scripts_dtc +%.dtb: include/config/kernel.release scripts_dtc $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@ PHONY += dtbs dtbs_install dt_binding_check -dtbs dtbs_check: prepare3 scripts_dtc +dtbs dtbs_check: include/config/kernel.release scripts_dtc $(Q)$(MAKE) $(build)=$(dtstree) dtbs_check: export CHECK_DTBS=1 -- cgit v1.2.3 From 36de077b20d05321466f8eaba0ae01b9b18ad93c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Aug 2019 13:46:13 +0900 Subject: kbuild: check clean srctree even earlier Move the outputmakefile target to the leftmost in the prerequisite list so that this is checked first. GNU Make processes the prerequisites left to right. GNU Make will keep to stick to this behavior, and it seems even POSIX standard, according to this: https://lists.gnu.org/archive/html/bug-make/2019-08/msg00030.html The POSIX standard of make is available here: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html Of course, when the parallel option -j given, other targets will be run simultaneously but it is nice to show the error as early as possible. Signed-off-by: Masahiro Yamada --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 5458fbaf7fc8..56593c7fa831 100644 --- a/Makefile +++ b/Makefile @@ -578,10 +578,10 @@ ifdef config-build include arch/$(SRCARCH)/Makefile export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT -config: scripts_basic outputmakefile FORCE +config: outputmakefile scripts_basic FORCE $(Q)$(MAKE) $(build)=scripts/kconfig $@ -%config: scripts_basic outputmakefile FORCE +%config: outputmakefile scripts_basic FORCE $(Q)$(MAKE) $(build)=scripts/kconfig $@ else #!config-build @@ -1120,7 +1120,7 @@ scripts: scripts_basic scripts_dtc PHONY += prepare archprepare -archprepare: archheaders archscripts scripts include/config/kernel.release outputmakefile \ +archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h prepare0: archprepare -- cgit v1.2.3 From e2079e93f562c7f7a030eb7642017ee5eabaaa10 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Mon, 26 Aug 2019 17:41:55 -0700 Subject: kbuild: Do not enable -Wimplicit-fallthrough for clang for now This functionally reverts commit bfd77145f35c ("Makefile: Convert -Wimplicit-fallthrough=3 to just -Wimplicit-fallthrough for clang"). clang enabled support for -Wimplicit-fallthrough in C in r369414 [1], which causes a lot of warnings when building the kernel for two reasons: 1. Clang does not support the /* fall through */ comments. There seems to be a general consensus in the LLVM community that this is not something they want to support. Joe Perches wrote a script to convert all of the comments to a "fallthrough" keyword that will be added to compiler_attributes.h [2] [3], which catches the vast majority of the comments. There doesn't appear to be any consensus in the kernel community when to do this conversion. 2. Clang and GCC disagree about falling through to final case statements with no content or cases that simply break: https://godbolt.org/z/c8csDu This difference contributes at least 50 warnings in an allyesconfig build for x86, not considering other architectures. This difference will need to be discussed to see which compiler is right [4] [5]. [1]: https://github.com/llvm/llvm-project/commit/1e0affb6e564b7361b0aadb38805f26deff4ecfc [2]: https://lore.kernel.org/lkml/61ddbb86d5e68a15e24ccb06d9b399bbf5ce2da7.camel@perches.com/ [3]: https://lore.kernel.org/lkml/1d2830aadbe9d8151728a7df5b88528fc72a0095.1564549413.git.joe@perches.com/ [4]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91432 [5]: https://github.com/ClangBuiltLinux/linux/issues/636 Given these two problems need discussion and coordination, do not enable -Wimplicit-fallthrough with clang right now. Add a comment to explain what is going on as well. This commit should be reverted once these two issues are fully flushed out and resolved. Suggested-by: Masahiro Yamada Signed-off-by: Nathan Chancellor Acked-by: Miguel Ojeda Acked-by: Nick Desaulniers Acked-by: Gustavo A. R. Silva Signed-off-by: Masahiro Yamada --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 56593c7fa831..97f5d1254708 100644 --- a/Makefile +++ b/Makefile @@ -774,6 +774,11 @@ else # These warnings generated too much noise in a regular build. # Use make W=1 to enable them (see scripts/Makefile.extrawarn) KBUILD_CFLAGS += -Wno-unused-but-set-variable + +# Warn about unmarked fall-throughs in switch statement. +# Disabled for clang while comment to attribute conversion happens and +# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed. +KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough,) endif KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) @@ -868,9 +873,6 @@ NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) # warn about C99 declaration after statement KBUILD_CFLAGS += -Wdeclaration-after-statement -# Warn about unmarked fall-throughs in switch statement. -KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough,) - # Variable Length Arrays (VLAs) should not be used anywhere in the kernel KBUILD_CFLAGS += -Wvla -- cgit v1.2.3 From 15f5db60a13748f44e5a14a2573c2cfcdc152f1c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 21 Aug 2019 02:09:40 +0900 Subject: kbuild,arc: add CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 for ARC arch/arc/Makefile overrides -O2 with -O3. This is the only user of ARCH_CFLAGS. There is no user of ARCH_CPPFLAGS or ARCH_AFLAGS. My plan is to remove ARCH_{CPP,A,C}FLAGS after refactoring the ARC Makefile. Currently, ARC has no way to enable -Wmaybe-uninitialized because both -O3 and -Os disable it. Enabling it will be useful for compile-testing. This commit allows allmodconfig (, which defaults to -O2) to enable it. Add CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y to all the defconfig files in arch/arc/configs/ in order to keep the current config settings. Signed-off-by: Masahiro Yamada Acked-by: Vineet Gupta --- Makefile | 10 ++++++---- arch/arc/Makefile | 8 -------- arch/arc/configs/axs101_defconfig | 1 + arch/arc/configs/axs103_defconfig | 1 + arch/arc/configs/axs103_smp_defconfig | 1 + arch/arc/configs/haps_hs_defconfig | 1 + arch/arc/configs/haps_hs_smp_defconfig | 1 + arch/arc/configs/hsdk_defconfig | 1 + arch/arc/configs/nps_defconfig | 1 + arch/arc/configs/nsim_700_defconfig | 1 + arch/arc/configs/nsim_hs_defconfig | 1 + arch/arc/configs/nsim_hs_smp_defconfig | 1 + arch/arc/configs/nsimosci_defconfig | 1 + arch/arc/configs/nsimosci_hs_defconfig | 1 + arch/arc/configs/nsimosci_hs_smp_defconfig | 1 + arch/arc/configs/tb10x_defconfig | 1 + arch/arc/configs/vdk_hs38_defconfig | 1 + arch/arc/configs/vdk_hs38_smp_defconfig | 1 + init/Kconfig | 12 ++++++++++-- 19 files changed, 32 insertions(+), 14 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 97f5d1254708..c27bc98ad28b 100644 --- a/Makefile +++ b/Makefile @@ -723,10 +723,12 @@ KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) -ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE -KBUILD_CFLAGS += -Os -else -KBUILD_CFLAGS += -O2 +ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE +KBUILD_CFLAGS += -O2 +else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 +KBUILD_CFLAGS += -O3 +else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE +KBUILD_CFLAGS += -Os endif ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED diff --git a/arch/arc/Makefile b/arch/arc/Makefile index ee6d1184c2b1..f1c44cccf8d6 100644 --- a/arch/arc/Makefile +++ b/arch/arc/Makefile @@ -48,14 +48,6 @@ endif cfi := $(call as-instr,.cfi_startproc\n.cfi_endproc,-DARC_DW2_UNWIND_AS_CFI) cflags-$(CONFIG_ARC_DW2_UNWIND) += -fasynchronous-unwind-tables $(cfi) -ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE -# Generic build system uses -O2, we want -O3 -# Note: No need to add to cflags-y as that happens anyways -# -# Disable the false maybe-uninitialized warings gcc spits out at -O3 -ARCH_CFLAGS += -O3 $(call cc-disable-warning,maybe-uninitialized,) -endif - # small data is default for elf32 tool-chain. If not usable, disable it # This also allows repurposing GP as scratch reg to gcc reg allocator disable_small_data := y diff --git a/arch/arc/configs/axs101_defconfig b/arch/arc/configs/axs101_defconfig index e31a8ebc3ecc..0016149f9583 100644 --- a/arch/arc/configs/axs101_defconfig +++ b/arch/arc/configs/axs101_defconfig @@ -9,6 +9,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y # CONFIG_VM_EVENT_COUNTERS is not set diff --git a/arch/arc/configs/axs103_defconfig b/arch/arc/configs/axs103_defconfig index e0e8567f0d75..5b031582a1cf 100644 --- a/arch/arc/configs/axs103_defconfig +++ b/arch/arc/configs/axs103_defconfig @@ -9,6 +9,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y # CONFIG_VM_EVENT_COUNTERS is not set diff --git a/arch/arc/configs/axs103_smp_defconfig b/arch/arc/configs/axs103_smp_defconfig index fcbc952bc75b..d4eec39e0112 100644 --- a/arch/arc/configs/axs103_smp_defconfig +++ b/arch/arc/configs/axs103_smp_defconfig @@ -9,6 +9,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y # CONFIG_VM_EVENT_COUNTERS is not set diff --git a/arch/arc/configs/haps_hs_defconfig b/arch/arc/configs/haps_hs_defconfig index 436f2135bdc1..47ff8a97e42d 100644 --- a/arch/arc/configs/haps_hs_defconfig +++ b/arch/arc/configs/haps_hs_defconfig @@ -10,6 +10,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_EXPERT=y CONFIG_PERF_EVENTS=y # CONFIG_COMPAT_BRK is not set diff --git a/arch/arc/configs/haps_hs_smp_defconfig b/arch/arc/configs/haps_hs_smp_defconfig index 33a787c375e2..9685fd5f57a4 100644 --- a/arch/arc/configs/haps_hs_smp_defconfig +++ b/arch/arc/configs/haps_hs_smp_defconfig @@ -10,6 +10,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y # CONFIG_VM_EVENT_COUNTERS is not set diff --git a/arch/arc/configs/hsdk_defconfig b/arch/arc/configs/hsdk_defconfig index 403125d9c9a3..9b9a74444ce2 100644 --- a/arch/arc/configs/hsdk_defconfig +++ b/arch/arc/configs/hsdk_defconfig @@ -9,6 +9,7 @@ CONFIG_NAMESPACES=y # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y CONFIG_BLK_DEV_RAM=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y # CONFIG_VM_EVENT_COUNTERS is not set diff --git a/arch/arc/configs/nps_defconfig b/arch/arc/configs/nps_defconfig index f0a077c00efa..5978d4d7d5b0 100644 --- a/arch/arc/configs/nps_defconfig +++ b/arch/arc/configs/nps_defconfig @@ -6,6 +6,7 @@ CONFIG_HIGH_RES_TIMERS=y CONFIG_IKCONFIG=y CONFIG_IKCONFIG_PROC=y CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_SYSCTL_SYSCALL=y # CONFIG_EPOLL is not set # CONFIG_SIGNALFD is not set diff --git a/arch/arc/configs/nsim_700_defconfig b/arch/arc/configs/nsim_700_defconfig index de398c7b10b3..2b9b11474640 100644 --- a/arch/arc/configs/nsim_700_defconfig +++ b/arch/arc/configs/nsim_700_defconfig @@ -10,6 +10,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_KALLSYMS_ALL=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y diff --git a/arch/arc/configs/nsim_hs_defconfig b/arch/arc/configs/nsim_hs_defconfig index 2dbd34a9ff07..bab3dd255841 100644 --- a/arch/arc/configs/nsim_hs_defconfig +++ b/arch/arc/configs/nsim_hs_defconfig @@ -10,6 +10,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_KALLSYMS_ALL=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y diff --git a/arch/arc/configs/nsim_hs_smp_defconfig b/arch/arc/configs/nsim_hs_smp_defconfig index c7135f1e2583..90d2d50fb8dc 100644 --- a/arch/arc/configs/nsim_hs_smp_defconfig +++ b/arch/arc/configs/nsim_hs_smp_defconfig @@ -8,6 +8,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_KALLSYMS_ALL=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y diff --git a/arch/arc/configs/nsimosci_defconfig b/arch/arc/configs/nsimosci_defconfig index 385a71d3c478..5dd470b6609e 100644 --- a/arch/arc/configs/nsimosci_defconfig +++ b/arch/arc/configs/nsimosci_defconfig @@ -10,6 +10,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_KALLSYMS_ALL=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y diff --git a/arch/arc/configs/nsimosci_hs_defconfig b/arch/arc/configs/nsimosci_hs_defconfig index 248a2c3bdc12..3532e86f7bff 100644 --- a/arch/arc/configs/nsimosci_hs_defconfig +++ b/arch/arc/configs/nsimosci_hs_defconfig @@ -10,6 +10,7 @@ CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_KALLSYMS_ALL=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y diff --git a/arch/arc/configs/nsimosci_hs_smp_defconfig b/arch/arc/configs/nsimosci_hs_smp_defconfig index 1a4bc7b660fb..d90448bee064 100644 --- a/arch/arc/configs/nsimosci_hs_smp_defconfig +++ b/arch/arc/configs/nsimosci_hs_smp_defconfig @@ -8,6 +8,7 @@ CONFIG_IKCONFIG_PROC=y # CONFIG_UTS_NS is not set # CONFIG_PID_NS is not set CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_PERF_EVENTS=y # CONFIG_COMPAT_BRK is not set CONFIG_KPROBES=y diff --git a/arch/arc/configs/tb10x_defconfig b/arch/arc/configs/tb10x_defconfig index dc739bd093e3..3a138f8c7299 100644 --- a/arch/arc/configs/tb10x_defconfig +++ b/arch/arc/configs/tb10x_defconfig @@ -14,6 +14,7 @@ CONFIG_INITRAMFS_SOURCE="../tb10x-rootfs.cpio" CONFIG_INITRAMFS_ROOT_UID=2100 CONFIG_INITRAMFS_ROOT_GID=501 # CONFIG_RD_GZIP is not set +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_SYSCTL_SYSCALL=y CONFIG_KALLSYMS_ALL=y # CONFIG_AIO is not set diff --git a/arch/arc/configs/vdk_hs38_defconfig b/arch/arc/configs/vdk_hs38_defconfig index 0c3b21416819..d7c858df520c 100644 --- a/arch/arc/configs/vdk_hs38_defconfig +++ b/arch/arc/configs/vdk_hs38_defconfig @@ -4,6 +4,7 @@ CONFIG_HIGH_RES_TIMERS=y CONFIG_IKCONFIG=y CONFIG_IKCONFIG_PROC=y CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y # CONFIG_VM_EVENT_COUNTERS is not set diff --git a/arch/arc/configs/vdk_hs38_smp_defconfig b/arch/arc/configs/vdk_hs38_smp_defconfig index f9ad9d3ee702..015c1d43889e 100644 --- a/arch/arc/configs/vdk_hs38_smp_defconfig +++ b/arch/arc/configs/vdk_hs38_smp_defconfig @@ -4,6 +4,7 @@ CONFIG_HIGH_RES_TIMERS=y CONFIG_IKCONFIG=y CONFIG_IKCONFIG_PROC=y CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y CONFIG_EMBEDDED=y CONFIG_PERF_EVENTS=y # CONFIG_VM_EVENT_COUNTERS is not set diff --git a/init/Kconfig b/init/Kconfig index 149efd82447f..92118505dd33 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1209,14 +1209,22 @@ choice default CC_OPTIMIZE_FOR_PERFORMANCE config CC_OPTIMIZE_FOR_PERFORMANCE - bool "Optimize for performance" + bool "Optimize for performance (-O2)" help This is the default optimization level for the kernel, building with the "-O2" compiler flag for best performance and most helpful compile-time warnings. +config CC_OPTIMIZE_FOR_PERFORMANCE_O3 + bool "Optimize more for performance (-O3)" + depends on ARC + imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives + help + Choosing this option will pass "-O3" to your compiler to optimize + the kernel yet more for performance. + config CC_OPTIMIZE_FOR_SIZE - bool "Optimize for size" + bool "Optimize for size (-Os)" imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives help Choosing this option will pass "-Os" to your compiler resulting -- cgit v1.2.3 From 8cc7af751443f7c82d12c7e5061fd2fa2e08a3d4 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 21 Aug 2019 02:09:41 +0900 Subject: kbuild: remove ARCH_{CPP,A,C}FLAGS These flags were added by commit 61754c18752f ("kbuild: Allow arch Makefiles to override {cpp,ld,c}flags") to allow ARC to override -O2. We did not see any other usage after all. Now that ARC switched to CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3, there is no more user of these variables. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/makefiles.rst | 7 ------- Makefile | 14 ++++---------- 2 files changed, 4 insertions(+), 17 deletions(-) (limited to 'Makefile') diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index e9ffdffa3641..6ba9d5365ff3 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -959,13 +959,6 @@ When kbuild executes, the following steps are followed (roughly): $(KBUILD_ARFLAGS) set by the top level Makefile to "D" (deterministic mode) if this option is supported by $(AR). - ARCH_CPPFLAGS, ARCH_AFLAGS, ARCH_CFLAGS Overrides the kbuild defaults - - These variables are appended to the KBUILD_CPPFLAGS, - KBUILD_AFLAGS, and KBUILD_CFLAGS, respectively, after the - top-level Makefile has set any other flags. This provides a - means for an architecture to override the defaults. - KBUILD_LDS The linker script with full path. Assigned by the top-level Makefile. diff --git a/Makefile b/Makefile index c27bc98ad28b..db5706ceecad 100644 --- a/Makefile +++ b/Makefile @@ -668,11 +668,6 @@ RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc export RETPOLINE_CFLAGS export RETPOLINE_VDSO_CFLAGS -# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default -# values of the respective KBUILD_* variables -ARCH_CPPFLAGS := -ARCH_AFLAGS := -ARCH_CFLAGS := include arch/$(SRCARCH)/Makefile ifdef need-config @@ -927,11 +922,10 @@ include scripts/Makefile.kasan include scripts/Makefile.extrawarn include scripts/Makefile.ubsan -# Add any arch overrides and user supplied CPPFLAGS, AFLAGS and CFLAGS as the -# last assignments -KBUILD_CPPFLAGS += $(ARCH_CPPFLAGS) $(KCPPFLAGS) -KBUILD_AFLAGS += $(ARCH_AFLAGS) $(KAFLAGS) -KBUILD_CFLAGS += $(ARCH_CFLAGS) $(KCFLAGS) +# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments +KBUILD_CPPFLAGS += $(KCPPFLAGS) +KBUILD_AFLAGS += $(KAFLAGS) +KBUILD_CFLAGS += $(KCFLAGS) KBUILD_LDFLAGS_MODULE += --build-id LDFLAGS_vmlinux += --build-id -- cgit v1.2.3 From 858805b336be1cabb3d9033adaa3676574d12e37 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 25 Aug 2019 22:28:37 +0900 Subject: kbuild: add $(BASH) to run scripts with bash-extension CONFIG_SHELL falls back to sh when bash is not installed on the system, but nobody is testing such a case since bash is usually installed. So, shell scripts invoked by CONFIG_SHELL are only tested with bash. It makes it difficult to test whether the hashbang #!/bin/sh is real. For example, #!/bin/sh in arch/powerpc/kernel/prom_init_check.sh is false. (I fixed it up) Besides, some shell scripts invoked by CONFIG_SHELL use bash-extension and #!/bin/bash is specified as the hashbang, while CONFIG_SHELL may not always be set to bash. Probably, the right thing to do is to introduce BASH, which is bash by default, and always set CONFIG_SHELL to sh. Replace $(CONFIG_SHELL) with $(BASH) for bash scripts. If somebody tries to add bash-extension to a #!/bin/sh script, it will be caught in testing because /bin/sh is a symlink to dash on some major distributions. Signed-off-by: Masahiro Yamada --- Makefile | 11 +++++------ arch/mips/boot/Makefile | 2 +- arch/powerpc/Makefile.postlink | 2 +- arch/powerpc/kernel/prom_init_check.sh | 2 +- kernel/Makefile | 2 +- scripts/Makefile.lib | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index db5706ceecad..06e1e21c0f45 100644 --- a/Makefile +++ b/Makefile @@ -404,9 +404,7 @@ KCONFIG_CONFIG ?= .config export KCONFIG_CONFIG # SHELL used by kbuild -CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ - else if [ -x /bin/bash ]; then echo /bin/bash; \ - else echo sh; fi ; fi) +CONFIG_SHELL := sh HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null) HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null) @@ -443,6 +441,7 @@ PYTHON = python PYTHON2 = python2 PYTHON3 = python3 CHECK = sparse +BASH = bash CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) @@ -488,7 +487,7 @@ KBUILD_LDFLAGS := GCC_PLUGINS_CFLAGS := CLANG_FLAGS := -export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC +export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE PAHOLE LEX YACC AWK INSTALLKERNEL export PERL PYTHON PYTHON2 PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE @@ -1687,7 +1686,7 @@ clean: $(clean-dirs) # Generate tags for editors # --------------------------------------------------------------------------- quiet_cmd_tags = GEN $@ - cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@ + cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@ tags TAGS cscope gtags: FORCE $(call cmd,tags) @@ -1708,7 +1707,7 @@ versioncheck: | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl coccicheck: - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/$@ + $(Q)$(BASH) $(srctree)/scripts/$@ namespacecheck: $(PERL) $(srctree)/scripts/namespace.pl diff --git a/arch/mips/boot/Makefile b/arch/mips/boot/Makefile index 3ce4dd578370..528bd73d530a 100644 --- a/arch/mips/boot/Makefile +++ b/arch/mips/boot/Makefile @@ -160,7 +160,7 @@ targets += vmlinux.lzo.itb quiet_cmd_itb-image = ITB $@ cmd_itb-image = \ env PATH="$(objtree)/scripts/dtc:$(PATH)" \ - $(CONFIG_SHELL) $(MKIMAGE) \ + $(BASH) $(MKIMAGE) \ -D "-I dts -O dtb -p 500 \ --include $(objtree)/arch/mips \ --warning no-unit_address_vs_reg" \ diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postlink index 83f8e5ba2722..134f12f89b92 100644 --- a/arch/powerpc/Makefile.postlink +++ b/arch/powerpc/Makefile.postlink @@ -18,7 +18,7 @@ quiet_cmd_relocs_check = CHKREL $@ ifdef CONFIG_PPC_BOOK3S_64 cmd_relocs_check = \ $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@" ; \ - $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/unrel_branch_check.sh "$(OBJDUMP)" "$@" + $(BASH) $(srctree)/arch/powerpc/tools/unrel_branch_check.sh "$(OBJDUMP)" "$@" else cmd_relocs_check = \ $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@" diff --git a/arch/powerpc/kernel/prom_init_check.sh b/arch/powerpc/kernel/prom_init_check.sh index 160bef0d553d..78bab17b1396 100644 --- a/arch/powerpc/kernel/prom_init_check.sh +++ b/arch/powerpc/kernel/prom_init_check.sh @@ -33,7 +33,7 @@ OBJ="$2" ERROR=0 -function check_section() +check_section() { file=$1 section=$2 diff --git a/kernel/Makefile b/kernel/Makefile index ef0d95a190b4..6027677f89e8 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -126,7 +126,7 @@ $(obj)/config_data.gz: $(KCONFIG_CONFIG) FORCE $(obj)/kheaders.o: $(obj)/kheaders_data.tar.xz quiet_cmd_genikh = CHK $(obj)/kheaders_data.tar.xz -cmd_genikh = $(CONFIG_SHELL) $(srctree)/kernel/gen_kheaders.sh $@ + cmd_genikh = $(BASH) $(srctree)/kernel/gen_kheaders.sh $@ $(obj)/kheaders_data.tar.xz: FORCE $(call cmd,genikh) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 888e5c830646..7ab17712ab24 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -364,7 +364,7 @@ UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR) UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)' quiet_cmd_uimage = UIMAGE $@ - cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \ + cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \ -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \ -T $(UIMAGE_TYPE) \ -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \ -- cgit v1.2.3 From e27128db62834c5b906585c2d97f0ddd431fa28f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 1 Sep 2019 01:25:55 +0900 Subject: kbuild: rename KBUILD_ENABLE_EXTRA_GCC_CHECKS to KBUILD_EXTRA_WARN KBUILD_ENABLE_EXTRA_GCC_CHECKS started as a switch to add extra warning options for GCC, but now it is a historical misnomer since we use it also for Clang, DTC, and even kernel-doc. Rename it to more sensible, shorter KBUILD_EXTRA_WARN. For the backward compatibility, KBUILD_ENABLE_EXTRA_GCC_CHECKS is still supported (but not advertised in the documentation). I also fixed up 'make help', and updated the documentation. Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor Reviewed-by: Nick Desaulniers Reviewed-by: Sedat Dilek --- Documentation/kbuild/kbuild.rst | 14 +++++++++----- Makefile | 2 +- scripts/Makefile.build | 2 +- scripts/Makefile.extrawarn | 13 +++++++++---- scripts/Makefile.lib | 4 ++-- scripts/genksyms/Makefile | 2 +- 6 files changed, 23 insertions(+), 14 deletions(-) (limited to 'Makefile') diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst index 62f9d86c082c..f1e5dce86af7 100644 --- a/Documentation/kbuild/kbuild.rst +++ b/Documentation/kbuild/kbuild.rst @@ -105,6 +105,15 @@ The output directory can also be specified using "O=...". Setting "O=..." takes precedence over KBUILD_OUTPUT. +KBUILD_EXTRA_WARN +----------------- +Specify the extra build checks. The same value can be assigned by passing +W=... from the command line. + +See `make help` for the list of the supported values. + +Setting "W=..." takes precedence over KBUILD_EXTRA_WARN. + KBUILD_DEBARCH -------------- For the deb-pkg target, allows overriding the normal heuristics deployed by @@ -241,11 +250,6 @@ To get all available archs you can also specify all. E.g.:: $ make ALLSOURCE_ARCHS=all tags -KBUILD_ENABLE_EXTRA_GCC_CHECKS ------------------------------- -If enabled over the make command line with "W=1", it turns on additional -gcc -W... options for more extensive build-time checking. - KBUILD_BUILD_TIMESTAMP ---------------------- Setting this to a date string overrides the timestamp used in the diff --git a/Makefile b/Makefile index 06e1e21c0f45..adc0cabe2382 100644 --- a/Makefile +++ b/Makefile @@ -1538,7 +1538,7 @@ help: @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK (sparse by default)' @echo ' make C=2 [targets] Force check of all c source with $$CHECK' @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections' - @echo ' make W=n [targets] Enable extra gcc checks, n=1,2,3 where' + @echo ' make W=n [targets] Enable extra build checks, n=1,2,3 where' @echo ' 1: warnings which may be relevant and do not occur too often' @echo ' 2: warnings which occur quite often but may still be relevant' @echo ' 3: more obscure warnings, can most likely be ignored' diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 2a21ca86b720..f72aba64d611 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -85,7 +85,7 @@ else ifeq ($(KBUILD_CHECKSRC),2) cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< endif -ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),) +ifneq ($(KBUILD_EXTRA_WARN),) cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< endif diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index d226c5fb13e2..53eb7e0c6a5a 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn @@ -8,14 +8,19 @@ KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) +# backward compatibility +KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS) + ifeq ("$(origin W)", "command line") - export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W) + KBUILD_EXTRA_WARN := $(W) endif +export KBUILD_EXTRA_WARN + # # W=1 - warnings which may be relevant and do not occur too often # -ifneq ($(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) +ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter KBUILD_CFLAGS += -Wmissing-declarations @@ -48,7 +53,7 @@ endif # # W=2 - warnings which occur quite often but may still be relevant # -ifneq ($(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) +ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wcast-align KBUILD_CFLAGS += -Wdisabled-optimization @@ -65,7 +70,7 @@ endif # # W=3 - more obscure warnings, can most likely be ignored # -ifneq ($(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) +ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wbad-function-cast KBUILD_CFLAGS += -Wcast-qual diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 380a7d11a573..4a0cdd6f5909 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -251,7 +251,7 @@ quiet_cmd_gzip = GZIP $@ DTC ?= $(objtree)/scripts/dtc/dtc # Disable noisy checks by default -ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) +ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),) DTC_FLAGS += -Wno-unit_address_vs_reg \ -Wno-unit_address_format \ -Wno-avoid_unnecessary_addr_size \ @@ -262,7 +262,7 @@ DTC_FLAGS += -Wno-unit_address_vs_reg \ -Wno-pci_device_reg endif -ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) +ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),) DTC_FLAGS += -Wnode_name_chars_strict \ -Wproperty_name_chars_strict endif diff --git a/scripts/genksyms/Makefile b/scripts/genksyms/Makefile index baf44ed0a93a..78629f515e78 100644 --- a/scripts/genksyms/Makefile +++ b/scripts/genksyms/Makefile @@ -12,7 +12,7 @@ genksyms-objs := genksyms.o parse.tab.o lex.lex.o # # Just in case, run "$(YACC) --version" without suppressing stderr # so that 'bison: not found' will be displayed if it is missing. -ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) +ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),) quiet_cmd_bison_no_warn = $(quiet_cmd_bison) cmd_bison_no_warn = $(YACC) --version >/dev/null; \ -- cgit v1.2.3