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

前端 未结 7 1624
悲&欢浪女
悲&欢浪女 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:21

    If I read the question correctly, the goal is to parallelize the build process as much as possible. The make man page states the following

    If the -j option is given without an argument, make will not limit the number of jobs that can run simultaneously.

    Isn't this basically the solution that you want? If your Makefile has enough parallel targets you will use all your CPUs and if the targets are not parallel, that -j option won't help anywas.

提交回复
热议问题