Makefile: Make the clean target independent of the build configuration
PATCH 1/1 Makefile: Make the clean target independent of the build configuration
'make clean' only removes the objects and dependency files of the configuration it's run with ($(ARCH) and the optional libraries the Makefile detects), so after a cross build a plain 'make clean' doesn't remove the objects and dependency files specific to the target architecture.
Remove every object and dependency file in the directories the Makefile builds in, along with guest/init and guest/pre_init, which depend on the configuration in the same way. List the directories by name so that objects elsewhere in the tree, such as those of a dtc clone used for LIBFDT_DIR, aren't removed.
--- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
@@ -557,12 +557,12 @@ clean: $(E) " CLEAN" $(Q) rm -f x86/bios/*.bin $(Q) rm -f x86/bios/*.elf - $(Q) rm -f x86/bios/*.o $(Q) rm -f x86/bios/bios-rom.h $(Q) rm -f tests/boot/boot_test.iso $(Q) rm -rf tests/boot/rootfs/ $(Q) rm -f $(DEPS) $(STATIC_DEPS) $(OBJS) $(OTHEROBJS) $(OBJS_DYNOPT) $(STATIC_OBJS) $(PROGRAM) $(PROGRAM_ALIAS) $(PROGRAM)-static $(GUEST_INIT) $(GUEST_PRE_INIT) $(GUEST_OBJS) - $(Q) rm -f guest/guest_init.c guest/guest_pre_init.c + $(Q) rm -f $(foreach d,. arm64 disk guest hw mips net/uip powerpc riscv ui util vfio virtio x86 x86/bios,$(d)/*.o $(d)/.*.d) + $(Q) rm -f guest/guest_init.c guest/guest_pre_init.c guest/init guest/pre_init $(Q) rm -f cscope.* $(Q) rm -f tags $(Q) rm -f TAGS
base-commit: 2f3abe56dcd2658dc6dae3eeeb4996dc4b518bcf
Signature · 1 line
2.47.3
Hi Fuad,
Quoted 11 lines · Fuad Tabba
'make clean' only removes the objects and dependency files of the configuration it's run with ($(ARCH) and the optional libraries the
Makefiledetects), so after a cross build a plain 'make clean' doesn't remove the objects and dependency files specific to the target architecture.Remove every object and dependency file in the directories the
Makefilebuilds in, along with guest/init and guest/pre_init, which depend on the configuration in the same way. List the directories by name so that objects elsewhere in the tree, such as those of a dtc clone used forLIBFDT_DIR, aren't removed.
Thanks for this, make clean not cleaning all the compilation artifacts was very annoying.
I tested this on my x86 machine:
make
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- clean
# I keep precompiled versions of libfdt in libfdt-<arch> directories find . -type f \( -name '*\.o' -o -name '*.d' \)|grep -v 'libfdt-*'|wc -l # Output: 0
ls -a guest
# Output: .gitignore and init.c
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
make clean
find . -type f \( -name '*\.o' -o -name '*.d' \)|grep -v 'libfdt-*'|wc -l # Output: 0
ls -a guest
# Output: .gitignore and init.c
And again with static linking.
Same on my arm64 machine, with CROSS_COMPILE and ARCH set for x86_64.
Also checked with git status that no files tracked by git were deleted:
Thanks a lot!
Alex
Quoted 30 lines
Signed-off-by Fuad Tabba <[email protected]>--- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Makefile +2
-2@@ -557,12 +557,12 @@ clean: $(E) " CLEAN" $(Q) rm -f x86/bios/*.bin $(Q) rm -f x86/bios/*.elf - $(Q) rm -f x86/bios/*.o $(Q) rm -f x86/bios/bios-rom.h $(Q) rm -f tests/boot/boot_test.iso $(Q) rm -rf tests/boot/rootfs/ $(Q) rm -f $(DEPS) $(STATIC_DEPS) $(OBJS) $(OTHEROBJS) $(OBJS_DYNOPT) $(STATIC_OBJS) $(PROGRAM) $(PROGRAM_ALIAS) $(PROGRAM)-static $(GUEST_INIT) $(GUEST_PRE_INIT) $(GUEST_OBJS) - $(Q) rm -f guest/guest_init.c guest/guest_pre_init.c + $(Q) rm -f $(foreach d,. arm64 disk guest hw mips net/uip powerpc riscv ui util vfio virtio x86 x86/bios,$(d)/*.o $(d)/.*.d) + $(Q) rm -f guest/guest_init.c guest/guest_pre_init.c guest/init guest/pre_init $(Q) rm -f cscope.* $(Q) rm -f tags $(Q) rm -f TAGSbase-commit:
2f3abe56dcd2658dc6dae3eeeb4996dc4b518bcfSignature · 1 line
2.47.3