Is it possible to perform a make clean from the parent directory which also recursively cleans all sub-directories without having to include a makefile in each sub-directory?
For example, currently in my Makefile, I have something like:
SUBDIRS = src, src1
.PHONY: clean subdirs $(SUBDIRS)
clean: $(SUBDIRS)
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c
$(SUBDIRS):
$(MAKE) -C $(SUBDIRS) clean
However, this requires me to have a Makefile in both src and src1. Otherwise, I would get the error
No rule to make target clean
Since I only want to run the command "rm -rf *.o ~ core .depend ..cmd *.ko *.mod.c" in each subdirectory anyways, it seems redundant to have to include a Makefile in every subdirectory with the exact same line for clean. Is there no way to simply have the same clean command run in each of the subdirectories?
I agree that you could just have the rm command operate on subdirs. But something like the following allows recursive make using only a single makefile:
SUBDIRS = . src src1
SUBDIRSCLEAN=$(addsuffix clean,$(SUBDIRS))
clean: $(SUBDIRSCLEAN)
clean_curdir:
rm -rfv *.o *~ core .depend .*.cmd *.ko *.mod.c
%clean: %
$(MAKE) -C $< -f $(PWD)/Makefile clean_curdir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With