Commit efcf861931f987d82b11caed75b8c2ad9d709274

Authored by Masahiro Yamada
Committed by Tom Rini
1 parent 2887c47338

kbuild: use scripts/Makefile.clean

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@jp.panasonic.com>

Showing 6 changed files with 111 additions and 88 deletions Side-by-side Diff

... ... @@ -1110,93 +1110,96 @@
1110 1110 cat COPYING | gzip -9 -c | ./tools/bin2header license_gzip > include/license.h
1111 1111 #########################################################################
1112 1112  
  1113 +###
  1114 +# Cleaning is done on three levels.
  1115 +# make clean Delete most generated files
  1116 +# Leave enough to build external modules
  1117 +# make mrproper Delete the current configuration, and all generated files
  1118 +# make distclean Remove editor backup files, patch leftover files and the like
1113 1119  
1114   -#########################################################################
  1120 +# Directories & files removed with 'make clean'
  1121 +CLEAN_DIRS += $(MODVERDIR)
  1122 +CLEAN_FILES += u-boot.lds include/bmp_logo.h include/bmp_logo_data.h \
  1123 + board/*/config.tmp board/*/*/config.tmp dts/*.tmp \
  1124 + include/autoconf.mk* include/spl-autoconf.mk \
  1125 + include/tpl-autoconf.mk
1115 1126  
1116   -clean:
1117   - @rm -f examples/standalone/atmel_df_pow2 \
1118   - examples/standalone/hello_world \
1119   - examples/standalone/interrupt \
1120   - examples/standalone/mem_to_mem_idma2intr \
1121   - examples/standalone/sched \
1122   - $(addprefix examples/standalone/, smc91111_eeprom smc911x_eeprom) \
1123   - examples/standalone/test_burst \
1124   - examples/standalone/timer
1125   - @rm -f $(addprefix examples/api/, demo demo.bin)
1126   - @rm -f tools/bmp_logo tools/easylogo/easylogo \
1127   - tools/env/fw_printenv \
1128   - tools/envcrc \
1129   - $(addprefix tools/gdb/, gdbcont gdbsend) \
1130   - tools/gen_eth_addr tools/img2srec \
1131   - tools/dumpimage \
1132   - $(addprefix tools/, mkenvimage mkimage) \
1133   - tools/mpc86x_clk \
1134   - $(addprefix tools/, mk$(BOARD)spl mkexynosspl) \
1135   - tools/mxsboot \
1136   - tools/ncb tools/ubsha1 \
1137   - tools/kernel-doc/docproc \
1138   - tools/proftool
1139   - @rm -f $(addprefix board/cray/L1/, bootscript.c bootscript.image) \
1140   - board/matrix_vision/*/bootscript.img \
1141   - spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl \
1142   - u-boot.lds \
1143   - $(addprefix arch/blackfin/cpu/, init.lds init.elf)
1144   - @rm -f include/bmp_logo.h
1145   - @rm -f include/bmp_logo_data.h
1146   - @rm -f lib/asm-offsets.s
1147   - @rm -f include/generated/asm-offsets.h
1148   - @rm -f $(CPUDIR)/$(SOC)/asm-offsets.s
1149   - @rm -f $(TIMESTAMP_FILE) $(VERSION_FILE)
1150   - @$(MAKE) -f $(srctree)/doc/DocBook/Makefile cleandocs
1151   - @find $(OBJTREE) -type f \
1152   - \( -name 'core' -o -name '*.bak' -o -name '*~' -o -name '*.su' \
1153   - -o -name '*.o' -o -name '*.a' -o -name '*.exe' -o -name '*.cmd' \
1154   - -o -name '*.cfgtmp' \) -print \
1155   - | xargs rm -f
  1127 +# Directories & files removed with 'make clobber'
  1128 +CLOBBER_DIRS += $(patsubst %,spl/%, $(filter-out Makefile, \
  1129 + $(shell ls -1 spl 2>/dev/null))) \
  1130 + tpl
  1131 +CLOBBER_FILES += u-boot* MLO MLO* SPL System.map nand_spl/u-boot*
1156 1132  
  1133 +# Directories & files removed with 'make mrproper'
  1134 +MRPROPER_DIRS += include/config include/generated
  1135 +MRPROPER_FILES += .config .config.old \
  1136 + tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
  1137 + include/config.h include/config.mk
  1138 +
  1139 +# clean - Delete most, but leave enough to build external modules
  1140 +#
  1141 +clean: rm-dirs := $(CLEAN_DIRS)
  1142 +clean: rm-files := $(CLEAN_FILES)
  1143 +
  1144 +clean-dirs := $(foreach f,$(u-boot-alldirs),$(if $(wildcard $f/Makefile),$f))
  1145 +
  1146 +clean-dirs := $(addprefix _clean_, $(clean-dirs) doc/DocBook)
  1147 +
  1148 +PHONY += $(clean-dirs) clean archclean
  1149 +$(clean-dirs):
  1150 + $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
  1151 +
  1152 +# TODO: Do not use *.cfgtmp
  1153 +clean: $(clean-dirs)
  1154 + $(call cmd,rmdirs)
  1155 + $(call cmd,rmfiles)
  1156 + @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
  1157 + \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
  1158 + -o -name '*.ko.*' -o -name '*.su' -o -name '*.cfgtmp' \
  1159 + -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
  1160 + -o -name '*.symtypes' -o -name 'modules.order' \
  1161 + -o -name modules.builtin -o -name '.tmp_*.o.*' \
  1162 + -o -name '*.gcno' \) -type f -print | xargs rm -f
  1163 + @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
  1164 + -path './nand_spl/*' -type l -print | xargs rm -f
  1165 +
  1166 +# clobber
  1167 +#
  1168 +clobber: rm-dirs := $(CLOBBER_DIRS)
  1169 +clobber: rm-files := $(CLOBBER_FILES)
  1170 +
  1171 +PHONY += clobber
  1172 +
1157 1173 clobber: clean
1158   - @find $(OBJTREE) -type f \( -name '*.srec' \
1159   - -o -name '*.bin' -o -name u-boot.img \) \
1160   - -print0 | xargs -0 rm -f
1161   - @rm -f *.bak ctags etags TAGS \
1162   - cscope.* *.*~
1163   - @rm -f u-boot u-boot.map u-boot.hex $(ALL-y)
1164   - @rm -f u-boot.kwb
1165   - @rm -f u-boot.pbl
1166   - @rm -f u-boot.imx
1167   - @rm -f u-boot-with-spl.imx
1168   - @rm -f u-boot-with-nand-spl.imx
1169   - @rm -f u-boot.ubl
1170   - @rm -f u-boot.ais
1171   - @rm -f u-boot.dtb
1172   - @rm -f u-boot.sb
1173   - @rm -f u-boot.spr
1174   - @rm -f $(addprefix nand_spl/, u-boot.lds u-boot.lst System.map)
1175   - @rm -f $(addprefix nand_spl/, u-boot-nand_spl.lds u-boot-spl u-boot-spl.map)
1176   - @rm -f $(addprefix spl/, u-boot-spl u-boot-spl.bin u-boot-spl.map)
1177   - @rm -f spl/u-boot-spl.lds
1178   - @rm -f $(addprefix tpl/, u-boot-tpl u-boot-tpl.bin u-boot-tpl.map)
1179   - @rm -f tpl/u-boot-spl.lds
1180   - @rm -f MLO MLO.byteswap
1181   - @rm -f SPL
1182   - @rm -f tools/xway-swap-bytes
1183   - @rm -fr include/asm/proc include/asm/arch include/asm
1184   - @rm -fr include/generated
1185   - @[ ! -d nand_spl ] || find nand_spl -name "*" -type l -print | xargs rm -f
1186   - @rm -f dts/*.tmp
1187   - @rm -f $(addprefix spl/, u-boot-spl.ais, u-boot-spl-pad.ais)
  1174 + $(call cmd,rmdirs)
  1175 + $(call cmd,rmfiles)
1188 1176  
1189   -mrproper: clobber
1190   - @rm -f include/config.h include/config.mk \
1191   - board/*/config.tmp board/*/*/config.tmp \
1192   - include/autoconf.mk include/autoconf.mk.dep \
1193   - include/spl-autoconf.mk \
1194   - include/tpl-autoconf.mk
  1177 +# mrproper - Delete all generated files, including .config
  1178 +#
  1179 +mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
  1180 +mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
  1181 +mrproper-dirs := $(addprefix _mrproper_,scripts)
1195 1182  
  1183 +PHONY += $(mrproper-dirs) mrproper archmrproper
  1184 +$(mrproper-dirs):
  1185 + $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
  1186 +
  1187 +mrproper: clobber $(mrproper-dirs)
  1188 + $(call cmd,rmdirs)
  1189 + $(call cmd,rmfiles)
  1190 + @rm -f arch/*/include/asm/arch arch/*/include/asm/proc
  1191 +
  1192 +# distclean
  1193 +#
  1194 +PHONY += distclean
  1195 +
1196 1196 distclean: mrproper
1197   -ifneq ($(OBJTREE),$(SRCTREE))
1198   - rm -rf *
1199   -endif
  1197 + @find $(srctree) $(RCS_FIND_IGNORE) \
  1198 + \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
  1199 + -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
  1200 + -o -name '.*.rej' \
  1201 + -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
  1202 + -type f -print | xargs rm -f
1200 1203  
1201 1204 backup:
1202 1205 F=`basename $(TOPDIR)` ; cd .. ; \
... ... @@ -1206,6 +1209,17 @@
1206 1209  
1207 1210 endif #ifeq ($(config-targets),1)
1208 1211 endif #ifeq ($(mixed-targets),1)
  1212 +
  1213 +quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
  1214 + cmd_rmdirs = rm -rf $(rm-dirs)
  1215 +
  1216 +quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
  1217 + cmd_rmfiles = rm -f $(rm-files)
  1218 +
  1219 +# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
  1220 +# Usage:
  1221 +# $(Q)$(MAKE) $(clean)=dir
  1222 +clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
1209 1223  
1210 1224 endif # skip-makefile
1211 1225  
arch/blackfin/cpu/Makefile
... ... @@ -22,6 +22,7 @@
22 22 obj-y += traps.o
23 23  
24 24 extra-y += check_initcode
  25 +clean-files := init.lds
25 26  
26 27 # make sure our initcode (which goes into LDR) does not
27 28 # have relocs or external references
board/cray/L1/Makefile
... ... @@ -14,4 +14,6 @@
14 14  
15 15 $(obj)/bootscript.image: $(src)/bootscript.hush
16 16 -$(OBJTREE)/tools/mkimage -A ppc -O linux -T script -C none -a 0 -e 0 -n bootscript -d $< $@
  17 +
  18 +clean-files := bootscript.c bootscript.image
... ... @@ -7,12 +7,6 @@
7 7 # This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is
8 8 # enabled. See doc/README.fdt-control for more details.
9 9  
10   -ifeq ($(DEVICE_TREE),)
11   -$(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
12   -$(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
13   -DEVICE_TREE = $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%)
14   -endif
15   -
16 10 DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts
17 11 DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts
18 12 DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts
19 13  
... ... @@ -28,9 +22,15 @@
28 22 # the filename.
29 23 DT_BIN := $(obj)/dt.dtb
30 24  
  25 +DEVICE_TREE ?= $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%)
  26 +ifeq ($(DEVICE_TREE),)
  27 +$(DT_BIN): FORCE
  28 + echo >&2 "Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file"
  29 +else
31 30 $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
32 31 $(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp
33 32 $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp
  33 +endif
34 34  
35 35 process_lds = \
36 36 $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
  1 +# Let clean descend into subdirs
  2 +subdir- += basic
scripts/Makefile.clean
... ... @@ -37,6 +37,10 @@
37 37  
38 38 subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
39 39  
  40 +# Temporal work-around for U-Boot
  41 +
  42 +subdir-ymn := $(foreach f, $(subdir-ymn), $(if $(wildcard $f/Makefile),$f))
  43 +
40 44 # build a list of files to remove, usually relative to the current
41 45 # directory
42 46