Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kbuild: add a script to remove stale generated files

We maintain .gitignore and Makefiles so build artifacts are properly
ignored by Git, and cleaned up by 'make clean'. However, the code is
always changing; generated files are often moved to another directory,
or removed when they become unnecessary. Such garbage files tend to be
left over in the source tree because people usually git-pull without
cleaning the tree.

This is not only the noise for 'git status', but also a build issue
in some cases.

One solution is to remove a stale file like commit 223c24a7dba9 ("kbuild:
Automatically remove stale <linux/version.h> file") did. Such workaround
should be removed after a while, but we forget about that if we scatter
the workaround code in random places.

So, this commit adds a new script to collect cleanings of stale files.

As a start point, move the code in arch/arm/boot/compressed/Makefile
into this script.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+36 -8
+5 -1
Makefile
··· 1225 1225 1226 1226 archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ 1227 1227 asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h \ 1228 - include/generated/autoconf.h 1228 + include/generated/autoconf.h remove-stale-files 1229 1229 1230 1230 prepare0: archprepare 1231 1231 $(Q)$(MAKE) $(build)=scripts/mod ··· 1233 1233 1234 1234 # All the preparing.. 1235 1235 prepare: prepare0 prepare-objtool prepare-resolve_btfids 1236 + 1237 + PHONY += remove-stale-files 1238 + remove-stale-files: 1239 + $(Q)$(srctree)/scripts/remove-stale-files 1236 1240 1237 1241 # Support for using generic headers in asm-generic 1238 1242 asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
-7
arch/arm/boot/compressed/Makefile
··· 96 96 $(foreach o, $(libfdt_objs) atags_to_fdt.o fdt_check_mem_start.o, \ 97 97 $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector)) 98 98 99 - # These were previously generated C files. When you are building the kernel 100 - # with O=, make sure to remove the stale files in the output tree. Otherwise, 101 - # the build system wrongly compiles the stale ones. 102 - ifdef building_out_of_srctree 103 - $(shell rm -f $(addprefix $(obj)/, fdt_rw.c fdt_ro.c fdt_wip.c fdt.c)) 104 - endif 105 - 106 99 targets := vmlinux vmlinux.lds piggy_data piggy.o \ 107 100 lib1funcs.o ashldi3.o bswapsdi2.o \ 108 101 head.o $(OBJS)
+31
scripts/remove-stale-files
··· 1 + #!/bin/sh 2 + 3 + set -e 4 + 5 + # When you move, remove or rename generated files, you probably also update 6 + # .gitignore and cleaning rules in the Makefile. This is the right thing 7 + # to do. However, people usually do 'git pull', 'git bisect', etc. without 8 + # running 'make clean'. Then, the stale generated files are left over, often 9 + # causing build issues. 10 + # 11 + # Also, 'git status' shows such stale build artifacts as untracked files. 12 + # What is worse, some people send a wrong patch to get them back to .gitignore 13 + # without checking the commit history. 14 + # 15 + # So, when you (re)move generated files, please move the cleaning rules from 16 + # the Makefile to this script. This is run before Kbuild starts building 17 + # anything, so people will not be annoyed by such garbage files. 18 + # 19 + # This script is not intended to grow endlessly. Rather, it is a temporary scrap 20 + # yard. Stale files stay in this file for a while (for some release cycles?), 21 + # then will be really dead and removed from the code base entirely. 22 + 23 + # These were previously generated source files. When you are building the kernel 24 + # with O=, make sure to remove the stale files in the output tree. Otherwise, 25 + # the build system wrongly compiles the stale ones. 26 + if [ -n "${building_out_of_srctree}" ]; then 27 + for f in fdt_rw.c fdt_ro.c fdt_wip.c fdt.c 28 + do 29 + rm -f arch/arm/boot/compressed/${f} 30 + done 31 + fi