Using Makefile to clean subdirectories

后端 未结 5 1144
孤独总比滥情好
孤独总比滥情好 2021-02-08 16:09

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?

5条回答
  •  借酒劲吻你
    2021-02-08 16:50

    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
    

提交回复
热议问题