Parallelization of recursive jobs in GNU make

后端 未结 4 1108
长情又很酷
长情又很酷 2021-02-02 16:08

I am looking for an elegant way for the parallelization of jobs in GNU make. Here is a sample of what I did so far. Make processes the directories dir-1, dir-2 and dir-3 in a se

4条回答
  •  礼貌的吻别
    2021-02-02 16:32

    Are dir-1, dir-2 and dir-3 interdependent or independent?

    I have a similar structure but dependence between the subdirectories so with that I preferred to just use parallel builds within each of the subdirectories. You'd get that via

    ## default to four parallel runs
    MAKEFLAGS += -j 4  
    
    all:
      @for dir in $(SUBDIRS); do (cd $$dir; $(MAKE) ); done
    

    But another trick is to read up on SUBDIRS in the make manual -- you do not need the for loop as make can unroll this for you. Try something like

    ## default to four parallel runs
    MAKEFLAGS += -j 4  
    
    SUBDIRS =    dir-1 dir-2 dir-3
    
    $(SUBDIRS):  #whatever your depends here
                 $(MAKE) -C $@
    

提交回复
热议问题