Makefile issue: smart way to scan directory tree for .c files

后端 未结 4 982
再見小時候
再見小時候 2020-12-07 16:45

I am doing a project which is growing pretty fast and keeping the object files up date is no option. The problem beyond wildcard command lies somewhere between \"I do not wa

4条回答
  •  粉色の甜心
    2020-12-07 17:00

    Recursive wildcards can be done purely in Make, without calling the shell or the find command. Doing the search using only Make means that this solution works on Windows as well, not just *nix.

    # Make does not offer a recursive wildcard function, so here's one:
    rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
    
    # How to recursively find all files with the same name in a given folder
    ALL_INDEX_HTMLS := $(call rwildcard,foo/,index.html)
    
    # How to recursively find all files that match a pattern
    ALL_HTMLS := $(call rwildcard,foo/,*.html)
    

    The trailing slash in the folder name is required. This rwildcard function does not support multiple wildcards the way that Make's built-in wildcard function does, but adding that support would be straightforward with a couple more uses of foreach.

提交回复
热议问题