Recursive make in subdirectories

前端 未结 4 702
清歌不尽
清歌不尽 2021-02-04 01:37

How can I order make command in the Makefile to execute recursively in all subdirectories make commands (defined in the Makefile in the subdirectories)

4条回答
  •  孤城傲影
    2021-02-04 01:52

    The above answers work well when all of the subdirectories have Makefiles. It is not that difficult to only run make on the directories that contain Makefile, nor is it difficult to restrict the number of levels to recurse. In my sample code, I restrict the search for makefiles to the subdirectories immediately below the parent directory. The filter-out statement (line 2) prevents this Makefile from being included in the recursive makes.

    MAKEFILES = $(shell find . -maxdepth 2 -type f -name Makefile)
    SUBDIRS   = $(filter-out ./,$(dir $(MAKEFILES)))
    
    all:
        for dir in $(SUBDIRS); do \
            make -C $$dir all; \
        done
    

提交回复
热议问题