Skip to content

Commit

Permalink
kbuild: use more subdir- for visiting subdirectories while cleaning
Browse files Browse the repository at this point in the history
Documentation/kbuild/makefiles.rst suggests to use "archclean" for
cleaning arch/$(SRCARCH)/boot/, but it is not a hard requirement.

Since commit d92cc4d ("kbuild: require all architectures to have
arch/$(SRCARCH)/Kbuild"), we can use the "subdir- += boot" trick for
all architectures. This can take advantage of the parallel option (-j)
for "make clean".

I also cleaned up the comments in arch/$(SRCARCH)/Makefile. The "archdep"
target no longer exists.

Signed-off-by: Masahiro Yamada <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]>
Acked-by: Michael Ellerman <[email protected]> (powerpc)
  • Loading branch information
masahir0y committed Oct 24, 2021
1 parent 10c6ae2 commit 8212f89
Show file tree
Hide file tree
Showing 42 changed files with 71 additions and 103 deletions.
17 changes: 2 additions & 15 deletions Documentation/kbuild/makefiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1050,22 +1050,9 @@ is not sufficient this sometimes needs to be explicit.
The above assignment instructs kbuild to descend down in the
directory compressed/ when "make clean" is executed.

To support the clean infrastructure in the Makefiles that build the
final bootimage there is an optional target named archclean:

Example::

#arch/x86/Makefile
archclean:
$(Q)$(MAKE) $(clean)=arch/x86/boot

When "make clean" is executed, make will descend down in arch/x86/boot,
and clean as usual. The Makefile located in arch/x86/boot/ may use
the subdir- trick to descend further down.

Note 1: arch/$(SRCARCH)/Makefile cannot use "subdir-", because that file is
included in the top level makefile, and the kbuild infrastructure
is not operational at that point.
included in the top level makefile. Instead, arch/$(SRCARCH)/Kbuild can use
"subdir-".

Note 2: All directories listed in core-y, libs-y, drivers-y and net-y will
be visited during "make clean".
Expand Down
3 changes: 3 additions & 0 deletions arch/alpha/Kbuild
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-y += kernel/ mm/
obj-$(CONFIG_MATHEMU) += math-emu/

# for cleaning
subdir- += boot
3 changes: 0 additions & 3 deletions arch/alpha/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ $(boot)/vmlinux.gz: vmlinux
bootimage bootpfile bootpzfile: vmlinux
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

archheaders:
$(Q)$(MAKE) $(build)=arch/alpha/kernel/syscalls all

Expand Down
3 changes: 3 additions & 0 deletions arch/arc/Kbuild
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
obj-y += kernel/
obj-y += mm/

# for cleaning
subdir- += boot
3 changes: 0 additions & 3 deletions arch/arc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,3 @@ uImage: $(uimage-default-y)
@$(kecho) ' Image $(boot)/uImage is ready'

CLEAN_FILES += $(boot)/uImage

archclean:
$(Q)$(MAKE) $(clean)=$(boot)
3 changes: 3 additions & 0 deletions arch/arm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ obj-y += kernel/ mm/ common/
obj-y += probes/
obj-y += net/
obj-y += crypto/

# for cleaning
subdir- += boot
4 changes: 0 additions & 4 deletions arch/arm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,6 @@ ifeq ($(CONFIG_VDSO),y)
$(Q)$(MAKE) $(build)=arch/arm/vdso $@
endif

# We use MRPROPER_FILES and CLEAN_FILES now
archclean:
$(Q)$(MAKE) $(clean)=$(boot)

# My testing targets (bypasses dependencies)
bp:; $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/bootpImage

Expand Down
3 changes: 3 additions & 0 deletions arch/arm64/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ obj-$(CONFIG_KVM) += kvm/
obj-$(CONFIG_XEN) += xen/
obj-$(subst m,y,$(CONFIG_HYPERV)) += hyperv/
obj-$(CONFIG_CRYPTO) += crypto/

# for cleaning
subdir- += boot
7 changes: 0 additions & 7 deletions arch/arm64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,6 @@ ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS),y)
endif
endif


# We use MRPROPER_FILES and CLEAN_FILES now
archclean:
$(Q)$(MAKE) $(clean)=$(boot)
$(Q)$(MAKE) $(clean)=arch/arm64/kernel/vdso
$(Q)$(MAKE) $(clean)=arch/arm64/kernel/vdso32

ifeq ($(KBUILD_EXTMOD),)
# We need to generate vdso-offsets.h before compiling certain files in kernel/.
# In order to do that, we should use the archprepare target, but we can't since
Expand Down
3 changes: 3 additions & 0 deletions arch/arm64/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ extra-y += $(head-y) vmlinux.lds
ifeq ($(CONFIG_DEBUG_EFI),y)
AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(objtree)/vmlinux)\""
endif

# for cleaning
subdir- += vdso vdso32
3 changes: 3 additions & 0 deletions arch/csky/Kbuild
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only

# for cleaning
subdir- += boot
3 changes: 0 additions & 3 deletions arch/csky/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ all: zImage
zImage Image uImage: vmlinux
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

define archhelp
echo '* zImage - Compressed kernel image (arch/$(ARCH)/boot/zImage)'
echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
Expand Down
3 changes: 3 additions & 0 deletions arch/h8300/Kbuild
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-y += kernel/ mm/ boot/dts/

# for cleaning
subdir- += boot
3 changes: 0 additions & 3 deletions arch/h8300/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ libs-y += arch/$(ARCH)/lib/

boot := arch/h8300/boot

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

vmlinux.srec vmlinux.bin zImage uImage.bin: vmlinux
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@

Expand Down
2 changes: 0 additions & 2 deletions arch/ia64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ vmlinux.bin: vmlinux FORCE
unwcheck: vmlinux
-$(Q)READELF=$(READELF) $(PYTHON3) $(srctree)/arch/ia64/scripts/unwcheck.py $<

archclean:

archheaders:
$(Q)$(MAKE) $(build)=arch/ia64/kernel/syscalls all

Expand Down
4 changes: 1 addition & 3 deletions arch/m68k/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# m68k/Makefile
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies. Remember to do have actions
# for "archclean" and "archdep" for cleaning up and making dependencies for
# this architecture
# architecture-specific flags and dependencies.
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
Expand Down
3 changes: 3 additions & 0 deletions arch/microblaze/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ obj-y += kernel/
obj-y += mm/
obj-$(CONFIG_PCI) += pci/
obj-y += boot/dts/

# for cleaning
subdir- += boot
3 changes: 0 additions & 3 deletions arch/microblaze/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ export DTB

all: linux.bin

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

archheaders:
$(Q)$(MAKE) $(build)=arch/microblaze/kernel/syscalls all

Expand Down
3 changes: 3 additions & 0 deletions arch/mips/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ obj-y += vdso/
ifdef CONFIG_KVM
obj-y += kvm/
endif

# for cleaning
subdir- += boot
8 changes: 1 addition & 7 deletions arch/mips/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
# Copyright (C) 2002, 2003, 2004 Maciej W. Rozycki
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies. Remember to do have actions
# for "archclean" cleaning up for this architecture.
# architecture-specific flags and dependencies.
#

archscripts: scripts_basic
Expand Down Expand Up @@ -426,11 +425,6 @@ endif
$(Q)install -D -m 644 .config $(INSTALL_PATH)/config-$(KERNELRELEASE)
$(Q)install -D -m 644 System.map $(INSTALL_PATH)/System.map-$(KERNELRELEASE)

archclean:
$(Q)$(MAKE) $(clean)=arch/mips/boot
$(Q)$(MAKE) $(clean)=arch/mips/boot/compressed
$(Q)$(MAKE) $(clean)=arch/mips/boot/tools

archheaders:
$(Q)$(MAKE) $(build)=arch/mips/kernel/syscalls all

Expand Down
3 changes: 3 additions & 0 deletions arch/mips/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,6 @@ $(obj)/vmlinux.itb: $(obj)/vmlinux.its $(obj)/vmlinux.bin FORCE

$(obj)/vmlinux.%.itb: $(obj)/vmlinux.%.its $(obj)/vmlinux.bin.% FORCE
$(call if_changed,itb-image,$<)

# for cleaning
subdir- += compressed tools
3 changes: 3 additions & 0 deletions arch/nds32/Kbuild
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only

# for cleaning
subdir- += boot
3 changes: 0 additions & 3 deletions arch/nds32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ prepare: vdso_prepare
vdso_prepare: prepare0
$(Q)$(MAKE) $(build)=arch/nds32/kernel/vdso include/generated/vdso-offsets.h

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

define archhelp
echo ' Image - kernel image (arch/$(ARCH)/boot/Image)'
endef
3 changes: 3 additions & 0 deletions arch/nios2/Kbuild
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only

# for cleaning
subdir- += boot
6 changes: 1 addition & 5 deletions arch/nios2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
# Written by Fredrik Markstrom
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies. Remember to do have actions
# for "archclean" cleaning up for this architecture.
# architecture-specific flags and dependencies.
#
# Nios2 port by Wind River Systems Inc trough:
# [email protected] and [email protected]
Expand Down Expand Up @@ -53,9 +52,6 @@ core-y += $(nios2-boot)/dts/

all: vmImage

archclean:
$(Q)$(MAKE) $(clean)=$(nios2-boot)

$(BOOT_TARGETS): vmlinux
$(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@

Expand Down
3 changes: 3 additions & 0 deletions arch/openrisc/Kbuild
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
obj-y += lib/ kernel/ mm/
obj-y += boot/dts/

# for cleaning
subdir- += boot
7 changes: 1 addition & 6 deletions arch/openrisc/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# BK Id: %F% %I% %G% %U% %#%
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies. Remember to do have actions
# for "archclean" and "archdep" for cleaning up and making dependencies for
# this architecture
# architecture-specific flags and dependencies.
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
Expand Down Expand Up @@ -48,6 +46,3 @@ PHONY += vmlinux.bin

vmlinux.bin: vmlinux
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@

archclean:
$(Q)$(MAKE) $(clean)=$(boot)
3 changes: 3 additions & 0 deletions arch/parisc/Kbuild
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-y += mm/ kernel/ math-emu/

# for cleaning
subdir- += boot
7 changes: 1 addition & 6 deletions arch/parisc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# parisc/Makefile
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies. Remember to do have actions
# for "archclean" and "archdep" for cleaning up and making dependencies for
# this architecture
# architecture-specific flags and dependencies.
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
Expand Down Expand Up @@ -181,8 +179,5 @@ define archhelp
@echo ' zinstall - Install compressed vmlinuz kernel'
endef

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

archheaders:
$(Q)$(MAKE) $(build)=arch/parisc/kernel/syscalls all
3 changes: 3 additions & 0 deletions arch/powerpc/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ obj-$(CONFIG_KVM) += kvm/
obj-$(CONFIG_PERF_EVENTS) += perf/
obj-$(CONFIG_KEXEC_CORE) += kexec/
obj-$(CONFIG_KEXEC_FILE) += purgatory/

# for cleaning
subdir- += boot
7 changes: 1 addition & 6 deletions arch/powerpc/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies. Remember to do have actions
# for "archclean" and "archdep" for cleaning up and making dependencies for
# this architecture.
# architecture-specific flags and dependencies.
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
Expand Down Expand Up @@ -411,9 +409,6 @@ install:
sh -x $(srctree)/$(boot)/install.sh "$(KERNELRELEASE)" vmlinux \
System.map "$(INSTALL_PATH)"

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

ifeq ($(KBUILD_EXTMOD),)
# We need to generate vdso-offsets.h before compiling certain files in kernel/.
# In order to do that, we should use the archprepare target, but we can't since
Expand Down
3 changes: 3 additions & 0 deletions arch/riscv/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

obj-y += kernel/ mm/ net/
obj-$(CONFIG_BUILTIN_DTB) += boot/dts/

# for cleaning
subdir- += boot
7 changes: 1 addition & 6 deletions arch/riscv/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies. Remember to do have actions
# for "archclean" and "archdep" for cleaning up and making dependencies for
# this architecture
# architecture-specific flags and dependencies.
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
Expand Down Expand Up @@ -137,6 +135,3 @@ zinstall: install-image = Image.gz
install zinstall:
$(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \
$(boot)/$(install-image) System.map "$(INSTALL_PATH)"

archclean:
$(Q)$(MAKE) $(clean)=$(boot)
3 changes: 3 additions & 0 deletions arch/s390/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ obj-$(CONFIG_APPLDATA_BASE) += appldata/
obj-y += net/
obj-$(CONFIG_PCI) += pci/
obj-$(CONFIG_ARCH_HAS_KEXEC_PURGATORY) += purgatory/

# for cleaning
subdir- += boot tools
8 changes: 1 addition & 7 deletions arch/s390/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
# s390/Makefile
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies. Remember to do have actions
# for "archclean" and "archdep" for cleaning up and making dependencies for
# this architecture
# architecture-specific flags and dependencies.
#
# Copyright (C) 1994 by Linus Torvalds
#
Expand Down Expand Up @@ -147,10 +145,6 @@ zfcpdump:
vdso_install:
$(Q)$(MAKE) $(build)=arch/$(ARCH)/kernel/vdso64 $@

archclean:
$(Q)$(MAKE) $(clean)=$(boot)
$(Q)$(MAKE) $(clean)=$(tools)

archheaders:
$(Q)$(MAKE) $(build)=$(syscalls) uapi

Expand Down
3 changes: 3 additions & 0 deletions arch/sh/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
obj-y += kernel/ mm/ boards/
obj-$(CONFIG_SH_FPU_EMU) += math-emu/
obj-$(CONFIG_USE_BUILTIN_DTB) += boot/dts/

# for cleaning
subdir- += boot
3 changes: 0 additions & 3 deletions arch/sh/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ compressed: zImage
archprepare:
$(Q)$(MAKE) $(build)=arch/sh/tools include/generated/machtypes.h

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

archheaders:
$(Q)$(MAKE) $(build)=arch/sh/kernel/syscalls all

Expand Down
3 changes: 3 additions & 0 deletions arch/sparc/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ obj-y += math-emu/
obj-y += net/
obj-y += crypto/
obj-$(CONFIG_SPARC64) += vdso/

# for cleaning
subdir- += boot
Loading

0 comments on commit 8212f89

Please sign in to comment.