文章目录
- make distclean
- 步骤1:2090-2114行,执行依赖 clean
- 步骤2:2120-2124行,执行依赖 $(mrproper-dirs)
- 步骤3:2118-2129行,执行依赖 mrproper
- 步骤4:2135-2142行,实现 distclean
编译后执行 make distclean V=1
make -f ./scripts/Makefile.clean obj=api
make -f ./scripts/Makefile.clean obj=cmd
make -f ./scripts/Makefile.clean obj=cmd/arm
make -f ./scripts/Makefile.clean obj=cmd/broadcom
make -f ./scripts/Makefile.clean obj=cmd/mvebu
make -f ./scripts/Makefile.clean obj=cmd/riscv
make -f ./scripts/Makefile.clean obj=cmd/sandbox
make -f ./scripts/Makefile.clean obj=cmd/ti
make -f ./scripts/Makefile.clean obj=cmd/x86
make -f ./scripts/Makefile.clean obj=common
make -f ./scripts/Makefile.clean obj=common/init
make -f ./scripts/Makefile.clean obj=disk
make -f ./scripts/Makefile.clean obj=drivers
make -f ./scripts/Makefile.clean obj=drivers/adc
make -f ./scripts/Makefile.clean obj=drivers/ata
make -f ./scripts/Makefile.clean obj=drivers/axi
make -f ./scripts/Makefile.clean obj=drivers/bios_emulator
make -f ./scripts/Makefile.clean obj=drivers/block
make -f ./scripts/Makefile.clean obj=drivers/bootcount
make -f ./scripts/Makefile.clean obj=drivers/bus
make -f ./scripts/Makefile.clean obj=drivers/button
make -f ./scripts/Makefile.clean obj=drivers/cache
make -f ./scripts/Makefile.clean obj=drivers/clk
make -f ./scripts/Makefile.clean obj=drivers/clk/altera
make -f ./scripts/Makefile.clean obj=drivers/clk/analogbits
make -f ./scripts/Makefile.clean obj=drivers/clk/aspeed
make -f ./scripts/Makefile.clean obj=drivers/clk/at91
make -f ./scripts/Makefile.clean obj=drivers/clk/exynos
make -f ./scripts/Makefile.clean obj=drivers/clk/imx
make -f ./scripts/Makefile.clean obj=drivers/clk/intel
make -f ./scripts/Makefile.clean obj=drivers/clk/kendryte
make -f ./scripts/Makefile.clean obj=drivers/clk/mediatek
make -f ./scripts/Makefile.clean obj=drivers/clk/meson
make -f ./scripts/Makefile.clean obj=drivers/clk/microchip
make -f ./scripts/Makefile.clean obj=drivers/clk/mtmips
make -f ./scripts/Makefile.clean obj=drivers/clk/mvebu
make -f ./scripts/Makefile.clean obj=drivers/clk/owl
make -f ./scripts/Makefile.clean obj=drivers/clk/renesas
make -f ./scripts/Makefile.clean obj=drivers/clk/rockchip
make -f ./scripts/Makefile.clean obj=drivers/clk/sifive
make -f ./scripts/Makefile.clean obj=drivers/clk/sunxi
make -f ./scripts/Makefile.clean obj=drivers/clk/tegra
make -f ./scripts/Makefile.clean obj=drivers/clk/ti
make -f ./scripts/Makefile.clean obj=drivers/clk/uniphier
make -f ./scripts/Makefile.clean obj=drivers/core
make -f ./scripts/Makefile.clean obj=drivers/cpu
make -f ./scripts/Makefile.clean obj=drivers/crypto
make -f ./scripts/Makefile.clean obj=drivers/crypto/fsl
make -f ./scripts/Makefile.clean obj=drivers/crypto/rsa_mod_exp
make -f ./scripts/Makefile.clean obj=drivers/ddr/microchip
make -f ./scripts/Makefile.clean obj=drivers/demo
make -f ./scripts/Makefile.clean obj=drivers/dfu
make -f ./scripts/Makefile.clean obj=drivers/fastboot
make -f ./scripts/Makefile.clean obj=drivers/firmware
make -f ./scripts/Makefile.clean obj=drivers/firmware/scmi
make -f ./scripts/Makefile.clean obj=drivers/fpga
make -f ./scripts/Makefile.clean obj=drivers/gpio
make -f ./scripts/Makefile.clean obj=drivers/hwspinlock
make -f ./scripts/Makefile.clean obj=drivers/i2c
make -f ./scripts/Makefile.clean obj=drivers/i2c/muxes
make -f ./scripts/Makefile.clean obj=drivers/input
make -f ./scripts/Makefile.clean obj=drivers/led
make -f ./scripts/Makefile.clean obj=drivers/mailbox
make -f ./scripts/Makefile.clean obj=drivers/memory
make -f ./scripts/Makefile.clean obj=drivers/misc
make -f ./scripts/Makefile.clean obj=drivers/misc/imx8
make -f ./scripts/Makefile.clean obj=drivers/mmc
make -f ./scripts/Makefile.clean obj=drivers/mtd
make -f ./scripts/Makefile.clean obj=drivers/mtd/nand
make -f ./scripts/Makefile.clean obj=drivers/mtd/nand/raw
make -f ./scripts/Makefile.clean obj=drivers/mtd/nand/raw/brcmnand
make -f ./scripts/Makefile.clean obj=drivers/mtd/nand/spi
make -f ./scripts/Makefile.clean obj=drivers/mtd/onenand
make -f ./scripts/Makefile.clean obj=drivers/mtd/spi
make -f ./scripts/Makefile.clean obj=drivers/mtd/ubi
make -f ./scripts/Makefile.clean obj=drivers/mux
make -f ./scripts/Makefile.clean obj=drivers/nvme
make -f ./scripts/Makefile.clean obj=drivers/pch
make -f ./scripts/Makefile.clean obj=drivers/pci
make -f ./scripts/Makefile.clean obj=drivers/pci_endpoint
make -f ./scripts/Makefile.clean obj=drivers/phy
make -f ./scripts/Makefile.clean obj=drivers/phy/allwinner
make -f ./scripts/Makefile.clean obj=drivers/phy/marvell
make -f ./scripts/Makefile.clean obj=drivers/phy/rockchip
make -f ./scripts/Makefile.clean obj=drivers/pinctrl
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/aspeed
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/ath79
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/broadcom
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/exynos
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/intel
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/mediatek
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/meson
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/mscc
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/mtmips
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/mvebu
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/nexell
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/nxp
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/renesas
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/rockchip
make -f ./scripts/Makefile.clean obj=drivers/pinctrl/uniphier
make -f ./scripts/Makefile.clean obj=drivers/power/acpi_pmc
make -f ./scripts/Makefile.clean obj=drivers/pwm
make -f ./scripts/Makefile.clean obj=drivers/qe
make -f ./scripts/Makefile.clean obj=drivers/ram
make -f ./scripts/Makefile.clean obj=drivers/ram/aspeed
make -f ./scripts/Makefile.clean obj=drivers/ram/k3-ddrss
make -f ./scripts/Makefile.clean obj=drivers/ram/mediatek
make -f ./scripts/Makefile.clean obj=drivers/ram/octeon
make -f ./scripts/Makefile.clean obj=drivers/ram/rockchip
make -f ./scripts/Makefile.clean obj=drivers/ram/sifive
make -f ./scripts/Makefile.clean obj=drivers/ram/stm32mp1
make -f ./scripts/Makefile.clean obj=drivers/remoteproc
make -f ./scripts/Makefile.clean obj=drivers/reset
make -f ./scripts/Makefile.clean obj=drivers/rng
make -f ./scripts/Makefile.clean obj=drivers/rtc
make -f ./scripts/Makefile.clean obj=drivers/scsi
make -f ./scripts/Makefile.clean obj=drivers/serial
make -f ./scripts/Makefile.clean obj=drivers/smem
make -f ./scripts/Makefile.clean obj=drivers/soc
make -f ./scripts/Makefile.clean obj=drivers/soc/ti
make -f ./scripts/Makefile.clean obj=drivers/sound
make -f ./scripts/Makefile.clean obj=drivers/spi
make -f ./scripts/Makefile.clean obj=drivers/spmi
make -f ./scripts/Makefile.clean obj=drivers/sysinfo
make -f ./scripts/Makefile.clean obj=drivers/sysreset
make -f ./scripts/Makefile.clean obj=drivers/tee
make -f ./scripts/Makefile.clean obj=drivers/tee/broadcom
make -f ./scripts/Makefile.clean obj=drivers/tee/optee
make -f ./scripts/Makefile.clean obj=drivers/thermal
make -f ./scripts/Makefile.clean obj=drivers/timer
make -f ./scripts/Makefile.clean obj=drivers/tpm
make -f ./scripts/Makefile.clean obj=drivers/ufs
make -f ./scripts/Makefile.clean obj=drivers/video
make -f ./scripts/Makefile.clean obj=drivers/video/bridge
make -f ./scripts/Makefile.clean obj=drivers/video/exynos
make -f ./scripts/Makefile.clean obj=drivers/video/imx
make -f ./scripts/Makefile.clean obj=drivers/video/meson
make -f ./scripts/Makefile.clean obj=drivers/video/nexell
make -f ./scripts/Makefile.clean obj=drivers/video/nexell/soc
make -f ./scripts/Makefile.clean obj=drivers/video/rockchip
make -f ./scripts/Makefile.clean obj=drivers/video/stm32
make -f ./scripts/Makefile.clean obj=drivers/video/sunxi
make -f ./scripts/Makefile.clean obj=drivers/video/tegra4
make -f ./scripts/Makefile.clean obj=drivers/video/ti
make -f ./scripts/Makefile.clean obj=drivers/virtio
make -f ./scripts/Makefile.clean obj=drivers/w1
make -f ./scripts/Makefile.clean obj=drivers/w1-eeprom
make -f ./scripts/Makefile.clean obj=drivers/watchdog
make -f ./scripts/Makefile.clean obj=drivers/xen
make -f ./scripts/Makefile.clean obj=drivers/ddr/altera
make -f ./scripts/Makefile.clean obj=drivers/ddr/fsl
make -f ./scripts/Makefile.clean obj=drivers/dma
make -f ./scripts/Makefile.clean obj=drivers/dma/ti
make -f ./scripts/Makefile.clean obj=drivers/gpio
make -f ./scripts/Makefile.clean obj=drivers/i2c
make -f ./scripts/Makefile.clean obj=drivers/i2c/muxes
make -f ./scripts/Makefile.clean obj=drivers/net
make -f ./scripts/Makefile.clean obj=drivers/net/fsl-mc
make -f ./scripts/Makefile.clean obj=drivers/net/fsl-mc/dpio
make -f ./scripts/Makefile.clean obj=drivers/net/ldpaa_eth
make -f ./scripts/Makefile.clean obj=drivers/net/mscc_eswitch
make -f ./scripts/Makefile.clean obj=drivers/net/octeontx
make -f ./scripts/Makefile.clean obj=drivers/net/octeontx2
make -f ./scripts/Makefile.clean obj=drivers/net/pfe_eth
make -f ./scripts/Makefile.clean obj=drivers/net/qe
make -f ./scripts/Makefile.clean obj=drivers/net/ti
make -f ./scripts/Makefile.clean obj=drivers/net/fm
make -f ./scripts/Makefile.clean obj=drivers/net/phy
make -f ./scripts/Makefile.clean obj=drivers/power
make -f ./scripts/Makefile.clean obj=drivers/power/battery
make -f ./scripts/Makefile.clean obj=drivers/power/domain
make -f ./scripts/Makefile.clean obj=drivers/power/fuel_gauge
make -f ./scripts/Makefile.clean obj=drivers/power/mfd
make -f ./scripts/Makefile.clean obj=drivers/power/pmic
make -f ./scripts/Makefile.clean obj=drivers/power/regulator
make -f ./scripts/Makefile.clean obj=drivers/serial
make -f ./scripts/Makefile.clean obj=drivers/spi
make -f ./scripts/Makefile.clean obj=drivers/usb/cdns3
make -f ./scripts/Makefile.clean obj=drivers/usb/common
make -f ./scripts/Makefile.clean obj=drivers/usb/dwc3
make -f ./scripts/Makefile.clean obj=drivers/usb/emul
make -f ./scripts/Makefile.clean obj=drivers/usb/eth
make -f ./scripts/Makefile.clean obj=drivers/usb/gadget
make -f ./scripts/Makefile.clean obj=drivers/usb/gadget/udc
make -f ./scripts/Makefile.clean obj=drivers/usb/host
make -f ./scripts/Makefile.clean obj=drivers/usb/mtu3
make -f ./scripts/Makefile.clean obj=drivers/usb/musb
make -f ./scripts/Makefile.clean obj=drivers/usb/musb-new
make -f ./scripts/Makefile.clean obj=drivers/usb/phy
make -f ./scripts/Makefile.clean obj=drivers/usb/ulpi
make -f ./scripts/Makefile.clean obj=dts
make -f ./scripts/Makefile.clean obj=dts/../arch/arm/dts
rm -f dts/../arch/arm/dts/bcm37-rpi-3-b.dtb dts/../arch/arm/dts/bcm35-rpi-b-plus.dtb dts/../arch/arm/dts/bcm35-rpi-a-plus.dtb dts/../arch/arm/dts/bcm35-rpi-b.dtb dts/../arch/arm/dts/bcm35-rpi-a.dtb dts/../arch/arm/dts/bcm35-rpi-cm1-io1.dtb dts/../arch/arm/dts/bcm37-rpi-3-b-plus.dtb dts/../arch/arm/dts/bcm35-rpi-zero-w.dtb dts/../arch/arm/dts/bcm35-rpi-b-rev2.dtb dts/../arch/arm/dts/bcm36-rpi-2-b.dtb dts/../arch/arm/dts/bcm37-rpi-3-a-plus.dtb dts/../arch/arm/dts/bcm37-rpi-cm3-io3.dtb dts/../arch/arm/dts/bcm35-rpi-zero.dtb
make -f ./scripts/Makefile.clean obj=dts/../arch/microblaze/dts
make -f ./scripts/Makefile.clean obj=dts/../arch/mips/dts
make -f ./scripts/Makefile.clean obj=dts/../arch/powerpc/dts
make -f ./scripts/Makefile.clean obj=dts/../arch/riscv/dts
make -f ./scripts/Makefile.clean obj=dts/../arch/sandbox/dts
make -f ./scripts/Makefile.clean obj=dts/../arch/x86/dts
rm -f dts/dt.dtb dts/dt.dtb.S
make -f ./scripts/Makefile.clean obj=env
make -f ./scripts/Makefile.clean obj=examples
make -f ./scripts/Makefile.clean obj=fs
make -f ./scripts/Makefile.clean obj=fs/btrfs
make -f ./scripts/Makefile.clean obj=fs/cbfs
make -f ./scripts/Makefile.clean obj=fs/cramfs
make -f ./scripts/Makefile.clean obj=fs/ext4
make -f ./scripts/Makefile.clean obj=fs/fat
make -f ./scripts/Makefile.clean obj=fs/jffs2
make -f ./scripts/Makefile.clean obj=fs/reiserfs
make -f ./scripts/Makefile.clean obj=fs/sandbox
make -f ./scripts/Makefile.clean obj=fs/squashfs
make -f ./scripts/Makefile.clean obj=fs/ubifs
make -f ./scripts/Makefile.clean obj=fs/yaffs2
make -f ./scripts/Makefile.clean obj=fs/zfs
make -f ./scripts/Makefile.clean obj=lib
make -f ./scripts/Makefile.clean obj=lib/acpi
make -f ./scripts/Makefile.clean obj=lib/aes
make -f ./scripts/Makefile.clean obj=lib/at91
make -f ./scripts/Makefile.clean obj=lib/bzip2
make -f ./scripts/Makefile.clean obj=lib/crypto
make -f ./scripts/Makefile.clean obj=lib/dhry
make -f ./scripts/Makefile.clean obj=lib/efi
make -f ./scripts/Makefile.clean obj=lib/efi_driver
make -f ./scripts/Makefile.clean obj=lib/efi_loader
make -f ./scripts/Makefile.clean obj=lib/efi_selftest
make -f ./scripts/Makefile.clean obj=lib/libavb
make -f ./scripts/Makefile.clean obj=lib/libfdt
make -f ./scripts/Makefile.clean obj=lib/lzma
make -f ./scripts/Makefile.clean obj=lib/lzo
make -f ./scripts/Makefile.clean obj=lib/optee
make -f ./scripts/Makefile.clean obj=lib/rsa
make -f ./scripts/Makefile.clean obj=lib/tizen
make -f ./scripts/Makefile.clean obj=lib/zlib
make -f ./scripts/Makefile.clean obj=lib/zstd
make -f ./scripts/Makefile.clean obj=net
make -f ./scripts/Makefile.clean obj=test
make -f ./scripts/Makefile.clean obj=test/cmd
make -f ./scripts/Makefile.clean obj=test/dm
make -f ./scripts/Makefile.clean obj=test/image
make -f ./scripts/Makefile.clean obj=test/lib
make -f ./scripts/Makefile.clean obj=test/log
make -f ./scripts/Makefile.clean obj=test/env
make -f ./scripts/Makefile.clean obj=test/optee
make -f ./scripts/Makefile.clean obj=test/overlay
make -f ./scripts/Makefile.clean obj=tools
make -f ./scripts/Makefile.clean obj=tools/env
make -f ./scripts/Makefile.clean obj=tools/gdb
rm -f tools/mkenvimage tools/dumpimage tools/mkimage tools/proftool tools/fdtgrep tools/spl_size_limit tools/mkenvimage tools/dumpimage tools/mkimage tools/proftool tools/fdtgrep tools/spl_size_limit tools/gen_eth_addr tools/gen_ethaddr_crc tools/img2srec
rm -rf tools/lib tools/common
rm -rf .tmp_versions
rm -f include/bmp_logo.h include/bmp_logo_data.h tools/version.h boot* u-boot* MLO* SPL System.map fit-dtb.blob* u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* idbloader.img flash.bin flash.log defconfig keep-syms-lto.c
make -f ./scripts/Makefile.clean obj=scripts
make -f ./scripts/Makefile.clean obj=scripts/basic
rm -f scripts/basic/fixdep scripts/basic/fixdep
make -f ./scripts/Makefile.clean obj=scripts/dtc
make -f ./scripts/Makefile.clean obj=scripts/dtc/pylibfdt
rm -f scripts/dtc/dtc scripts/dtc/dtc
make -f ./scripts/Makefile.clean obj=scripts/kconfig
rm -f scripts/kconfig/conf
rm -rf include/config include/generated
rm -f .config .config.old include/autoconf.mk include/autoconf.mk.dep include/config.h
make distclean
94 ifeq ("$(origin V)", "command line") 95 KBUILD_VERBOSE = $(V) 96 endif 97 ifndef KBUILD_VERBOSE 98 KBUILD_VERBOSE = 0 99 endif 100 101 ifeq ($(KBUILD_VERBOSE),1) 102 quiet = 103 Q = 104 else 105 quiet=quiet_ 106 Q = @ 107 endif ...... 224 ifeq ($(KBUILD_SRC),) 225 # building in the source tree 226 srctree := . 227 else 228 ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR))) 229 # building in a subdirectory of the source tree 230 srctree := .. 231 else 232 srctree := $(KBUILD_SRC) 233 endif 234 endif ...... 470 export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \ 471 -name CVS -o -name .pc -o -name .hg -o -name .git \) \ 472 -prune -o ...... 2090 clean: rm-dirs := $(CLEAN_DIRS) 2091 clean: rm-files := $(CLEAN_FILES) 2101 clean: $(clean-dirs) 2102 $(call cmd,rmdirs) 2103 $(call cmd,rmfiles) 2104 @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ 2105 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ 2106 -o -name '*.ko.*' -o -name '*.su' -o -name '*.pyc' \ 2107 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 2108 -o -name '*.lex.c' -o -name '*.tab.[ch]' \ 2109 -o -name '*.asn1.[ch]' \ 2110 -o -name '*.symtypes' -o -name 'modules.order' \ 2111 -o -name modules.builtin -o -name '.tmp_*.o.*' \ 2112 -o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \ 2113 -o -name '*.efi' -o -name '*.gcno' -o -name '*.so' \) \ 2114 -type f -print | xargs rm -f ...... 2120 mrproper-dirs := $(addprefix _mrproper_,scripts) 2123 $(mrproper-dirs) : 2124 $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@) ...... 2118 mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS)) 2119 mrproper: rm-files := $(wildcard $(MRPROPER_FILES)) 2126 mrproper: clean $(mrproper-dirs) 2127 $(call cmd,rmdirs) 2128 $(call cmd,rmfiles) 2129 @rm -f arch/*/include/asm/arch ...... 2135 distclean: mrproper 2136 @find $(srctree) $(RCS_FIND_IGNORE) \ 2137 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ 2138 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ 2139 -o -name '.*.rej' -o -name '*%' -o -name 'core' \ 2140 -o -name '*.pyc' \) \ 2141 -type f -print | xargs rm -f 2142 @rm -f boards.cfg CHANGELOG
当在命令行中输入:
make distclean V=1
时,94行条件成立,KBUILD_VERBOSE = 1
,101行条件成立,quiet 和 Q 为空
,则输出整个命令。
输入命令自动匹配顶层 Makefile 的第2135 行并执行,由于目标 distclean 依赖 mrproper, mrproper 依赖 clean 和 $(mrproper-dirs)执行顺序如下:1. 优先执行依赖 clean,即
2090-2114行
2. 再执行依赖$(mrproper-dirs),即2120-2124行
3. 上面两步完成 mrproper 依赖的实现,然后完成 mrproper 最后的实现语句,即2127-2129行
4. 经过上面三步完成 distclean 依赖的实现,最后完成 distclean 的实现语句,即2136-2142行
步骤1:2090-2114行,执行依赖 clean
2090 clean: rm-dirs := $(CLEAN_DIRS)
2091 clean: rm-files := $(CLEAN_FILES)
2092
2093 clean-dirs := $(foreach f,$(u-boot-alldirs),$(if $(wildcard $(srctree)/$f/Makefile),$f))
2094
2095 clean-dirs := $(addprefix _clean_, $(clean-dirs))
2096
2097
2098 $(clean-dirs):
2099 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
2100
2101 clean: $(clean-dirs)
2102 $(call cmd,rmdirs)
2103 $(call cmd,rmfiles)
2104 @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
2105 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
2106 -o -name '*.ko.*' -o -name '*.su' -o -name '*.pyc' \
2107 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
2108 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
2109 -o -name '*.asn1.[ch]' \
2110 -o -name '*.symtypes' -o -name 'modules.order' \
2111 -o -name modules.builtin -o -name '.tmp_*.o.*' \
2112 -o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \
2113 -o -name '*.efi' -o -name '*.gcno' -o -name '*.so' \) \
2114 -type f -print | xargs rm -f
从上面可以看出,clean 依赖
rm-dirs := $(CLEAN_DIRS)
、rm-files := $(CLEAN_FILES)
、$(clean-dirs)
2090行:clean 依赖
rm-dirs := $(CLEAN_DIRS)
,没有实现语句,所以这里只需要将依赖展开即可。
$(CLEAN_DIRS)
在顶层 Makefile 的第2069-2071行中定义,其中的 $(MODVERDIR) 在第466行中定义, foreach 函数、filter-out函数、patsubst函数、firstword函数466 export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions ...... 2069 CLEAN_DIRS += $(MODVERDIR) \ 2070 $(foreach d, spl tpl, $(patsubst %,$d/%, \ 2071 $(filter-out include, $(shell ls -1 $d 2>/dev/null))))
当命令行输入
make M=dir
,则 KBUILD_EXTMOD=dir,否则 KBUILD_EXTMOD 为空。由于命令行没有M=
,所以MODVERDIR = .tmp_versions
。
2070行中的spl、tpl
不存在,所以2070-2071行为空,最终展开为:2090 clean: rm-dirs := .tmp_versions
2091行:clean 依赖
rm-files := $(CLEAN_FILES)
,没有实现语句,所以这里只需要将依赖展开即可。
$(CLEAN_FILES)
在顶层 Makefile 的第2073-2077行中定义,2073 CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h tools/version.h \ 2074 boot* u-boot* MLO* SPL System.map fit-dtb.blob* \ 2075 u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log \ 2076 lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* \ 2077 idbloader.img flash.bin flash.log defconfig keep-syms-lto.c
最终展开为:
2091 clean: rm-files := include/bmp_logo.h include/bmp_logo_data.h tools/version.h boot* u-boot* MLO* SPL System.map fit-dtb.blob* u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* idbloader.img flash.bin flash.log defconfig keep-syms-lto.c
2101行:clean 依赖
$(clean-disrs)
,在第2093-2099行定义:2093 clean-dirs := $(foreach f,$(u-boot-alldirs),$(if $(wildcard $(srctree)/$f/Makefile),$f)) 2095 clean-dirs := $(addprefix _clean_, $(clean-dirs)) 2098 $(clean-dirs): 2099 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
2093行:中的
$(u-boot-alldirs)
在顶层 Makefile 的第792-853行定义:其实就是从变量$(u-boot-alldirs)
中轮询查找相应目录下是否存在 Makefile 文件,将有 Makefile 文件的目录名依次赋值给变量clean-dirs
。最终:$(clean-dirs) = $(u-boot-alldirs)
[即:重新排序去重并且去除目录名最后的/
后的 $(libs-) $(libs-y)]2095行:将变量
$(clean-dirs)
中的所有内容前缀加上_clean_
2099行:$(clean)
在 scripts/Kbuild.include [顶层Makefile第386行中引用]文件的第202行定义: clean := -f $(srctree)/scripts/Makefile.clean obj,
在顶层Makefile中,srctree = .
所以: clean := -f ./scripts/Makefile.clean obj
结果:/scripts/Makefile.clean分析,会将2098行目标中所有包含Makefile的目录及其子目录全部回显出来,执行并回显001-250行
。001 make -f ./scripts/Makefile.clean obj=api 002 make -f ./scripts/Makefile.clean obj=cmd ...... 250 rm -rf tools/lib tools/common
foreach函数、wildcard函数、sort函数、patsubst函数、filter函数、addprefix函数
792 HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n) 793 794 libs-y += lib/ 795 libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/ 796 libs-$(CONFIG_OF_EMBED) += dts/ 797 libs-y += fs/ 798 libs-y += net/ 799 libs-y += disk/ 800 libs-y += drivers/ 801 libs-y += drivers/dma/ 802 libs-y += drivers/gpio/ 803 libs-y += drivers/i2c/ 804 libs-y += drivers/net/ 805 libs-y += drivers/net/phy/ 806 libs-y += drivers/power/ \ 807 drivers/power/domain/ \ 808 drivers/power/fuel_gauge/ \ 809 drivers/power/mfd/ \ 810 drivers/power/pmic/ \ 811 drivers/power/battery/ \ 812 drivers/power/regulator/ 813 libs-y += drivers/spi/ 814 libs-$(CONFIG_FMAN_ENET) += drivers/net/fm/ 815 libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/ 816 libs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/ 817 libs-$(CONFIG_$(SPL_)ALTERA_SDRAM) += drivers/ddr/altera/ 818 libs-y += drivers/serial/ 819 libs-y += drivers/usb/cdns3/ 820 libs-y += drivers/usb/dwc3/ 821 libs-y += drivers/usb/common/ 822 libs-y += drivers/usb/emul/ 823 libs-y += drivers/usb/eth/ 824 libs-$(CONFIG_USB_DEVICE) += drivers/usb/gadget/ 825 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/ 826 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/udc/ 827 libs-y += drivers/usb/host/ 828 libs-y += drivers/usb/mtu3/ 829 libs-y += drivers/usb/musb/ 830 libs-y += drivers/usb/musb-new/ 831 libs-y += drivers/usb/phy/ 832 libs-y += drivers/usb/ulpi/ 833 libs-y += cmd/ 834 libs-y += common/ 835 libs-y += env/ 836 libs-$(CONFIG_API) += api/ 837 ifdef CONFIG_POST 838 libs-y += post/ 839 endif 840 libs-$(CONFIG_UNIT_TEST) += test/ 841 libs-$(CONFIG_UT_ENV) += test/env/ 842 libs-$(CONFIG_UT_OPTEE) += test/optee/ 843 libs-$(CONFIG_UT_OVERLAY) += test/overlay/ 844 845 libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/) 846 847 libs-y := $(sort $(libs-y)) 848 849 u-boot-dirs := $(patsubst %/,%,$(filter %/, $(libs-y))) tools examples 850 851 u-boot-alldirs := $(sort $(u-boot-dirs) $(patsubst %/,%,$(filter %/, $(libs-)))) 852
其中所有的变量都未定义,所以
lib-
和libs-y
变量定义如下:
libs- libs-y dts/ ;drivers/net/fm/;
drivers/ddr/fsl/
;
drivers/ddr/fsl/
;
drivers/ddr/altera/;
drivers/usb/gadget/
;
drivers/usb/gadget/
;
drivers/usb/gadget/udc/;
api/;test/ ;test/env/ ;test/optee/ ;test/overlay/;lib/ ; fs/Cnet/ ; disk/ ; drivers/ ; drivers/dma/ ;drivers/gpio/ ; drivers/i2c/ ; drivers/net/ ; drivers/net/phy/ ; drivers/power/ ; drivers/power/domain/ ; drivers/power/fuel_gauge/ ; drivers/power/mfd/ ; drivers/power/pmic/ ; drivers/power/battery/drivers/power/regulator/ ; drivers/spi/ ; drivers/serial/ ; drivers/usb/cdns3/ ; drivers/usb/dwc3/ ; drivers/usb/common/ ; drivers/usb/emul/ ; drivers/usb/eth/ ; drivers/usb/host/ ; drivers/usb/mtu3/ ; drivers/usb/musb/ ; drivers/usb/musb-new/ ; drivers/usb/phy/ ; drivers/usb/ulpi/ ; cmd/ ; common/ ; env/ ; 第849行,将
$(libs-y)
变量最后一个/
去除后的变量,并且追加tools examples
到变量$(u-boot-dirs)
。
第851行,将$(libs-)
变量最后一个/
去除后的变量 和 变量$(u-boot-dirs)
一起重新排序去重后赋值给变量$(u-boot-alldirs)
。
2102行:call函数、cmd函数分析,cmd_rmdir 函数:
rm -rf $(rm-dirs)
结果:依据上面2090行分析,执行并回显251行
命令。251 rm -rf .tmp_versions
2103行:call函数、cmd函数分析,cmd_rmfiles 函数:
rm -f $(rm-files)
结果:依据上面2091行分析,执行并回显252行
命令。252 rm -f include/bmp_logo.h include/bmp_logo_data.h tools/version.h boot* u-boot* MLO* SPL System.map fit-dtb.blob* u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* idbloader.img flash.bin flash.log defconfig keep-syms-lto.c
2104行:在顶层Makefile中显示只有当命令行上中输入
make M=dir
时,KBUILD_EXTMOD=dir,否则KBUILD_EXTMOD为空,由于命令行上没有输入M,所以KBUILD_EXTMOD为空。顶层Makefile中第470行定义RCS_FIND_IGNORE为:470 export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS -o -name .pc -o -name .hg -o -name .git \) -prune -o
find命令参数 @:
表示不回显 find:
用于查找特定文件或目录的命令(在当前目录下能查找SCCS等 则执行-prune, 否则,就print出来) -name:
查找的名称 -o:
或者 -prune:
忽略一个目录及其之下的文件 -type:
类型【f 表示文件,d 表示目录】 -print:
显示文件名 xargs:
把 find 找出的文件一个一个处理 结果:查找并删除编译后产生的中间文件或目标文件,不回显。
步骤2:2120-2124行,执行依赖 $(mrproper-dirs)
2120 mrproper-dirs := $(addprefix _mrproper_,scripts) 2123 $(mrproper-dirs): 2124 $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
由于addprefix函数、patsubst函数和上面 2099行分析可知,最终展开为:
_mrproper_scripts: make -f ./scripts/Makefile.clean obj=scripts
2124行: /scripts/Makefile.clean分析,
结果:执行并回显253-260行
。253 make -f ./scripts/Makefile.clean obj=scripts 254 make -f ./scripts/Makefile.clean obj=scripts/basic 255 rm -f scripts/basic/fixdep scripts/basic/fixdep 256 make -f ./scripts/Makefile.clean obj=scripts/dtc 257 make -f ./scripts/Makefile.clean obj=scripts/dtc/pylibfdt 258 rm -f scripts/dtc/dtc scripts/dtc/dtc 259 make -f ./scripts/Makefile.clean obj=scripts/kconfig 260 rm -f scripts/kconfig/conf
步骤3:2118-2129行,执行依赖 mrproper
2118 mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS)) 2119 mrproper: rm-files := $(wildcard $(MRPROPER_FILES)) 2126 mrproper: clean $(mrproper-dirs) 2127 $(call cmd,rmdirs) 2128 $(call cmd,rmfiles) 2129 @rm -f arch/*/include/asm/arch
从上面可以看出,mrproper 依赖
rm-dirs := $(wildcard $(MRPROPER_DIRS))
、rm-files := $(wildcard $(MRPROPER_FILES))
、clean
、$(mrproper-dirs)
2118行:mrproper 依赖
rm-dirs := $(wildcard $(MRPROPER_DIRS))
,没有实现语句,所以这里只需要将依赖展开即可。
$(MRPROPER_DIRS)
在顶层 Makefile 的第2080-2081行中定义,2080 MRPROPER_DIRS += include/config include/generated spl tpl \ 2081 .tmp_objdiff doc/output
wildcard 函数分析,最终展开为:
2118 mrproper : rm-dirs :=include/config include/generated #编译后会产生这两个文件夹 或 2118 mrproper : rm-dirs := #未编译定义的文件夹都不存在
结果:执行并回显
261行
。261 rm -rf include/config include/generated #编译后 或 261 rm -f #未编译
2119行:mrproper 依赖
rm-files := $(wildcard $(MRPROPER_FILES))
,没有实现语句,所以这里只需要将依赖展开即可。
$(MRPROPER_FILES)
在顶层 Makefile 的第2084-2086行中定义,2084 MRPROPER_FILES += .config .config.old include/autoconf.mk* include/config.h \ 2085 ctags etags tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \ 2086 drivers/video/fonts/*.S include/asm
wildcard 函数分析,最终展开为:
2091 mrproper : rm-files :=.config .config.old include/autoconf.mk include/autoconf.mk.dep include/config.h #编译后会产生这些文件 或 2091 mrproper : rm-files := #未编译定义的文件都不存在
结果:执行并回显
262行
。262 rm -f .config .config.old include/autoconf.mk include/autoconf.mk.dep include/config.h #编译后 或 262 rm -f #未编译
2126行:依赖
clean
和$(mrproper-dirs)
分别在步骤1和步骤2中实现。
2127行:同2102行分析一样,由于第2102行已经删去了相应文件夹(不回显),所以这里实际执行的是
rm -rf
2128行:同2103行分析一样,由于第2103行已经删去了相应文件(不回显),所以这里实际执行的是
rm -f
2129行:删除
arch/*/include/asm/arch
(不回显)
步骤4:2135-2142行,实现 distclean
2135 distclean: mrproper 2136 @find $(srctree) $(RCS_FIND_IGNORE) \ 2137 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ 2138 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ 2139 -o -name '.*.rej' -o -name '*%' -o -name 'core' \ 2140 -o -name '*.pyc' \) \ 2141 -type f -print | xargs rm -f 2142 @rm -f boards.cfg CHANGELOG
2135行:依赖
mrproper
在步骤3中实现。
2136行:在顶层Makefile中显示只有当命令行上中输入make M=dir
时,KBUILD_EXTMOD=dir,否则KBUILD_EXTMOD为空,由于命令行上没有输入M,所以KBUILD_EXTMOD为空。顶层Makefile中第470行定义RCS_FIND_IGNORE为:470 export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS -o -name .pc -o -name .hg -o -name .git \) -prune -o
find命令参数 @:
表示不回显 find:
用于查找特定文件或目录的命令(在当前目录下能查找SCCS等 则执行-prune, 否则,就print出来) -name:
查找的名称 -o:
或者 -prune:
忽略一个目录及其之下的文件 -type:
类型【f 表示文件,d 表示目录】 -print:
显示文件名 xargs:
把 find 找出的文件一个一个处理 结果:查找并删除编译后产生的中间文件或目标文件,不回显。
2142行:删除boards.cfg CHANGELOG
,不回显。