The shell command make -j
runs a Makefile's commands in parallel, which is useful on modern multicore CPUs. Can such parallelism be invoked from within a Makefile?
From the manual for Gnu make, my best guess is using the main Makefile as only a wrapper, which passes -j
to a sub-make that does the real work. But maybe there's some environment variable or dot file or internal variable or other ungooglable snoopy-swearing way to do this.
It's ok to limit the number of jobs, e.g,. -j $$(nproc)
.
Probably Linux, but not necessarily.
(Adding something like alias make='make -j'
to ~/.bashrc is too dangerous; the decision about whether to parallelize should be per Makefile, not per user.)
You can append to MAKEFLAGS from within the makefile itself, for example:
MAKEFLAGS += --jobs=$(CPUS)
Where CPUS is defined in the makefile.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments