Using Makefile to clean subdirectories

后端 未结 5 1143
孤独总比滥情好
孤独总比滥情好 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:57

    ALL_MOD = $(shell find . -maxdepth 1 -type d )
    ALL_MOD_CLEAN = $(addsuffix .clean, $(ALL_MOD))
    
    .PHONY: $(ALL_MOD_CLEAN) $(ALL_MOD) default all clean
    
    $(ALL_MOD_CLEAN): 
        $(E) "cleaning $(basename $@)"
        if [ -e $(basename $@)/Makefile ] ; then \
                $(MAKE) -C $(basename $@) clean ;\
        fi 
    
    clean: $(ALL_MOD_CLEAN)
        $(E) "cleaning complete: " $(ALL_MOD)
    

    add '.' to the suffix and use $(basename ...) instead of original target otherwise will be re-making all files every time need just to clean the project

提交回复
热议问题