Using Makefile to clean subdirectories

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

    Instead of using recursion, you could shell out to find to get a list of directories and do a single iteration to generate the wildcards:

    SUBDIR_ROOTS := foo bar
    DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
    GARBAGE_PATTERNS := *.o *~ core .depend .*.cmd *.ko *.mod.c
    GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS)))
    
    clean:
        rm -rf $(GARBAGE)
    

提交回复
热议问题