[U-Boot] [PATCH 33/34] Kbuild: use scripts/Makefile.clean
Masahiro Yamada
yamada.m at jp.panasonic.com
Wed Dec 11 12:01:55 CET 2013
This commit refactors cleaning targets such as
clean, clobber, mrpropper, distclean
with scripts/Makefile.clean.
By using scripts/Makefile.clean, we can recursively descend
into subdirectories and delete generated files there.
We do not need add a big list of generated files
to the "clean" target.
Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
---
We can delete ugly stuff like follows:
clean:
@rm -f $(obj)examples/standalone/82559_eeprom \
$(obj)examples/standalone/atmel_df_pow2 \
$(obj)examples/standalone/eepro100_eeprom \
$(obj)examples/standalone/hello_world \
$(obj)examples/standalone/interrupt \
$(obj)examples/standalone/mem_to_mem_idma2intr \
$(obj)examples/standalone/sched \
$(obj)examples/standalone/smc911{11,x}_eeprom \
$(obj)examples/standalone/test_burst \
$(obj)examples/standalone/timer
@rm -f $(obj)examples/api/demo{,.bin}
@rm -f $(obj)tools/bmp_logo $(obj)tools/easylogo/easylogo \
$(obj)tools/env/{fw_printenv,fw_setenv} \
$(obj)tools/envcrc \
$(obj)tools/gdb/{astest,gdbcont,gdbsend} \
$(obj)tools/gen_eth_addr $(obj)tools/img2srec \
$(obj)tools/mk{env,}image $(obj)tools/mpc86x_clk \
$(obj)tools/mk{$(BOARD),}spl \
$(obj)tools/mxsboot \
$(obj)tools/ncb $(obj)tools/ubsha1 \
$(obj)tools/kernel-doc/docproc \
$(obj)tools/proftool
@rm -f $(obj)board/cray/L1/{bootscript.c,bootscript.image} \
$(obj)board/matrix_vision/*/bootscript.img \
$(obj)board/voiceblue/eeprom \
$(obj)u-boot.lds \
$(obj)arch/blackfin/cpu/bootrom-asm-offsets.[chs] \
$(obj)arch/blackfin/cpu/init.{lds,elf}
By the way, I am keeping "make clobber" for now.
Do we need "make clobber"?
If we like 3-level cleaning targets, clean, mrproper, distclean,
like Linux Kernel, we can squash "clobber" to "clean".
Makefile | 186 ++++++++++++++++++++++++++-------------------
arch/blackfin/cpu/Makefile | 1 +
board/cray/L1/Makefile | 2 +
dts/Makefile | 12 +--
scripts/Makefile | 2 +
scripts/Makefile.clean | 4 +
6 files changed, 121 insertions(+), 86 deletions(-)
create mode 100644 scripts/Makefile
diff --git a/Makefile b/Makefile
index ad05007..bd450e7 100644
--- a/Makefile
+++ b/Makefile
@@ -1074,91 +1074,106 @@ include/license.h: tools/bin2header COPYING
cat COPYING | gzip -9 -c | ./tools/bin2header license_gzip > include/license.h
#########################################################################
+###
+# Cleaning is done on three levels.
+# make clean Delete most generated files
+# Leave enough to build external modules
+# make mrproper Delete the current configuration, and all generated files
+# make distclean Remove editor backup files, patch leftover files and the like
+
+# Directories & files removed with 'make clean'
+CLEAN_DIRS += $(MODVERDIR)
+CLEAN_FILES += u-boot.lds include/bmp_logo.h include/bmp_logo_data.h \
+ board/*/config.tmp board/*/*/config.tmp dts/*.tmp \
+ include/autoconf.mk include/autoconf.mk.dep \
+ include/spl-autoconf.mk include/tpl-autoconf.mk
+
+# Directories & files removed with 'make clobber'
+CLOBBER_DIRS += tpl \
+ $(patsubst %/,spl/%, $(filter-out Makefile, $(filter %/, \
+ $(shell ls -1 --file-type spl 2>/dev/null))))
+CLOBBER_FILES += u-boot u-boot.map u-boot.hex u-boot.img $(ALL-y) \
+ u-boot.kwb u-boot.pbl u-boot.imx u-boot-with-spl.imx \
+ u-boot-with-nand-spl.imx u-boot.ubl u-boot.ais u-boot.dtb \
+ u-boot.sb u-boot.spr MLO MLO.byteswap SPL \
+ $(patsubst %,spl/%, $(filter-out Makefile %/, \
+ $(shell ls -1 --file-type spl 2>/dev/null))) \
+ $(addprefix nand_spl/, u-boot.lds u-boot.lst System.map \
+ u-boot-nand_spl.lds u-boot-spl u-boot-spl.map)
+
+# Directories & files removed with 'make mrproper'
+MRPROPER_DIRS += include/config include/generated
+MRPROPER_FILES += .config .config.old \
+ tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
+ include/config.h include/config.mk
+
+# clean - Delete most, but leave enough to build external modules
+#
+clean: rm-dirs := $(CLEAN_DIRS)
+clean: rm-files := $(CLEAN_FILES)
+
+clean-dirs := $(foreach f,$(u-boot-alldirs),$(if $(wildcard $f/Makefile),$f))
+
+clean-dirs := $(addprefix _clean_, $(clean-dirs) doc/DocBook)
+
+PHONY += $(clean-dirs) clean archclean
+$(clean-dirs):
+ $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
+
+# TODO: Do not use *.cfgtmp
+clean: $(clean-dirs)
+ $(call cmd,rmdirs)
+ $(call cmd,rmfiles)
+ @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
+ \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
+ -o -name '*.ko.*' -o -name '*.su' -o -name '*.cfgtmp' \
+ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
+ -o -name '*.symtypes' -o -name 'modules.order' \
+ -o -name modules.builtin -o -name '.tmp_*.o.*' \
+ -o -name '*.gcno' \) -type f -print | xargs rm -f
+ @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
+ -path './nand_spl/*' -type l -print | xargs rm -f
+
+# clobber
+#
+clobber: rm-dirs := $(CLOBBER_DIRS)
+clobber: rm-files := $(CLOBBER_FILES)
-#########################################################################
-
-clean:
- @rm -f examples/standalone/atmel_df_pow2 \
- examples/standalone/hello_world \
- examples/standalone/interrupt \
- examples/standalone/mem_to_mem_idma2intr \
- examples/standalone/sched \
- examples/standalone/smc911{11,x}_eeprom \
- examples/standalone/test_burst \
- examples/standalone/timer
- @rm -f examples/api/demo{,.bin}
- @rm -f tools/bmp_logo tools/easylogo/easylogo \
- tools/env/fw_printenv \
- tools/envcrc \
- tools/gdb/{gdbcont,gdbsend} \
- tools/gen_eth_addr tools/img2srec \
- tools/mk{env,}image tools/mpc86x_clk \
- tools/mk{$(BOARD),exynos}spl \
- tools/mxsboot \
- tools/ncb tools/ubsha1 \
- tools/kernel-doc/docproc \
- tools/proftool
- @rm -f board/cray/L1/{bootscript.c,bootscript.image} \
- board/matrix_vision/*/bootscript.img \
- spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl \
- u-boot.lds \
- arch/blackfin/cpu/init.{lds,elf}
- @rm -f include/bmp_logo.h
- @rm -f include/bmp_logo_data.h
- @rm -f lib/asm-offsets.s
- @rm -f include/generated/asm-offsets.h
- @rm -f $(CPUDIR)/$(SOC)/asm-offsets.s
- @rm -f $(TIMESTAMP_FILE) $(VERSION_FILE)
- @$(MAKE) -f $(srctree)/doc/DocBook/Makefile cleandocs
- @find $(OBJTREE) -type f \
- \( -name 'core' -o -name '*.bak' -o -name '*~' -o -name '*.su' \
- -o -name '*.o' -o -name '*.a' -o -name '*.exe' -o -name '*.cmd' \
- -o -name '*.cfgtmp' \) -print \
- | xargs rm -f
+PHONY += clobber
clobber: clean
- @find $(OBJTREE) -type f \( -name '*.srec' \
- -o -name '*.bin' -o -name u-boot.img \) \
- -print0 | xargs -0 rm -f
- @rm -f *.bak ctags etags TAGS \
- cscope.* *.*~
- @rm -f u-boot u-boot.map u-boot.hex $(ALL-y)
- @rm -f u-boot.kwb
- @rm -f u-boot.pbl
- @rm -f u-boot.imx
- @rm -f u-boot-with-spl.imx
- @rm -f u-boot-with-nand-spl.imx
- @rm -f u-boot.ubl
- @rm -f u-boot.ais
- @rm -f u-boot.dtb
- @rm -f u-boot.sb
- @rm -f u-boot.spr
- @rm -f nand_spl/{u-boot.{lds,lst},System.map}
- @rm -f nand_spl/{u-boot-nand_spl.lds,u-boot-spl,u-boot-spl.map}
- @rm -f spl/{u-boot-spl,u-boot-spl.bin,u-boot-spl.map}
- @rm -f spl/u-boot-spl.lds
- @rm -f tpl/{u-boot-tpl,u-boot-tpl.bin,u-boot-tpl.map}
- @rm -f tpl/u-boot-spl.lds
- @rm -f MLO MLO.byteswap
- @rm -f SPL
- @rm -f tools/xway-swap-bytes
- @rm -fr include/asm/proc include/asm/arch include/asm
- @rm -fr include/generated
- @[ ! -d nand_spl ] || find nand_spl -name "*" -type l -print | xargs rm -f
- @rm -f dts/*.tmp
- @rm -f spl/u-boot-spl{,-pad}.ais
-
-mrproper: clobber
- @rm -f include/config.h include/config.mk \
- board/*/config.tmp board/*/*/config.tmp \
- include/autoconf.mk include/autoconf.mk.dep \
- include/spl-autoconf.mk \
- include/tpl-autoconf.mk
+ $(call cmd,rmdirs)
+ $(call cmd,rmfiles)
+ @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
+ \( -name '*.srec' \
+ -o -name '*.bin' \) -type f -print | xargs rm -f
+
+# mrproper - Delete all generated files, including .config
+#
+mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
+mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
+mrproper-dirs := $(addprefix _mrproper_,scripts)
+
+PHONY += $(mrproper-dirs) mrproper archmrproper
+$(mrproper-dirs):
+ $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
+
+mrproper: clobber $(mrproper-dirs)
+ $(call cmd,rmdirs)
+ $(call cmd,rmfiles)
+ @rm -f arch/*/include/asm/arch arch/*/include/asm/proc
+
+# distclean
+#
+PHONY += distclean
distclean: mrproper
-ifneq ($(OBJTREE),$(SRCTREE))
- rm -rf *
-endif
+ @find $(srctree) $(RCS_FIND_IGNORE) \
+ \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
+ -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
+ -o -name '.*.rej' \
+ -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
+ -type f -print | xargs rm -f
backup:
F=`basename $(TOPDIR)` ; cd .. ; \
@@ -1169,6 +1184,17 @@ backup:
endif #ifeq ($(config-targets),1)
endif #ifeq ($(mixed-targets),1)
+quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
+ cmd_rmdirs = rm -rf $(rm-dirs)
+
+quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
+ cmd_rmfiles = rm -f $(rm-files)
+
+# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
+# Usage:
+# $(Q)$(MAKE) $(clean)=dir
+clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
+
endif # skip-makefile
PHONY += FORCE
diff --git a/arch/blackfin/cpu/Makefile b/arch/blackfin/cpu/Makefile
index dd4d2d1..426292f 100644
--- a/arch/blackfin/cpu/Makefile
+++ b/arch/blackfin/cpu/Makefile
@@ -22,6 +22,7 @@ obj-y += reset.o
obj-y += traps.o
extra-y += check_initcode
+clean-files := init.lds
# make sure our initcode (which goes into LDR) does not
# have relocs or external references
diff --git a/board/cray/L1/Makefile b/board/cray/L1/Makefile
index 6aae9fa..63f43da 100644
--- a/board/cray/L1/Makefile
+++ b/board/cray/L1/Makefile
@@ -14,3 +14,5 @@ $(obj)/bootscript.c: $(obj)/bootscript.image
$(obj)/bootscript.image: $(src)/bootscript.hush
-$(OBJTREE)/tools/mkimage -A ppc -O linux -T script -C none -a 0 -e 0 -n bootscript -d $< $@
+
+clean-files := bootscript.c bootscript.image
\ No newline at end of file
diff --git a/dts/Makefile b/dts/Makefile
index cc6ecf6..1e7609a 100644
--- a/dts/Makefile
+++ b/dts/Makefile
@@ -7,12 +7,6 @@
# This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is
# enabled. See doc/README.fdt-control for more details.
-ifeq ($(DEVICE_TREE),)
-$(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
-$(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
-DEVICE_TREE = $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%)
-endif
-
DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts
DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts
DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts
@@ -28,9 +22,15 @@ DTC_FLAGS := -R 4 -p 0x1000 \
# the filename.
DT_BIN := $(obj)/dt.dtb
+DEVICE_TREE ?= $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%)
+ifeq ($(DEVICE_TREE),)
+$(DT_BIN): FORCE
+ echo >&2 "Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file"
+else
$(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
$(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp
$(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp
+endif
process_lds = \
$(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
diff --git a/scripts/Makefile b/scripts/Makefile
new file mode 100644
index 0000000..ebbadc9
--- /dev/null
+++ b/scripts/Makefile
@@ -0,0 +1,2 @@
+# Let clean descend into subdirs
+subdir- += basic
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 686cb0d..5cd0f51 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -37,6 +37,10 @@ subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
+# Temporal work-around for U-Boot
+
+subdir-ymn := $(foreach f, $(subdir-ymn), $(if $(wildcard $f/Makefile),$f))
+
# build a list of files to remove, usually relative to the current
# directory
--
1.8.3.2
More information about the U-Boot
mailing list