How can I write a makefile to auto-detect and parallelize the build with GNU Make?

前端 未结 7 1569
悲&欢浪女
悲&欢浪女 2021-02-01 03:37

Not sure if this is possible in one Makefile alone, but I was hoping to write a Makefile in a way such that trying to build any target in the file auto-magically detects the num

7条回答
  •  长发绾君心
    2021-02-01 04:04

    I just added this to the top of my Makefile. It lets make create any number of jobs, but tries to keep the load average below the number of cpu cores.

    MAKEFLAGS+="-j -l $(shell grep -c ^processor /proc/cpuinfo) "
    

    Note this is Linux specific.

提交回复
热议问题