Parallel make: set -j8 as the default option

☆樱花仙子☆ 提交于 2021-02-06 06:34:49

问题


I can set number of threads for the build process using -j argument. For example, I have 4 cores +4 virtual. When I write: make -j8 the speed increases 4 times.

Is it possible to set that value as default? (For example, in Linux Gentoo, in config file, it's possible to set this default value).

p.s. I have Arch Linux


回答1:


Your question is not about threads, but processes (jobs) executed by make.

The simple, way to set this, when make is used from the console is adding:

alias make="/usr/bin/make -j 8"

to your .profile file.

You can also use setenv MAKEFLAGS '-j 8', but MAKEFLAGS can ignore this parameter in some scenarios, because keeping desired number of processes requires communicating with recursive make calls. Happily this method works with current versions of GNU Make.




回答2:


setenv MAKEFLAGS '-j8'

Hope this helps!




回答3:


Here's how I've done it:

CORES ?= $(shell sysctl -n hw.ncpu || echo 1)

all:; @$(MAKE) _all -j$(CORES)
_all: install lint test
.PHONY: all _all
…

I've basically "aliased" my default target all to a "private" _all. The command to figure out the number of cores is OSX specific, AFAIK, so you could just improve it to be more cross platform if you will. And because of the ?= assignment, we can just override it with and env variable if/when needed.

EDIT:

You can also append to your MAKEFLAGS from within the makefile itself, like so:

CPUS ?= $(shell sysctl -n hw.ncpu || echo 1)
MAKEFLAGS += --jobs=$(CPUS)
…


来源:https://stackoverflow.com/questions/10567890/parallel-make-set-j8-as-the-default-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!