Building the source code of big projects can take a lot of time. By default, the
make command builds one target at a time. Since most of our computers have multiple cores, this process can be sped up by building multiple targets in parallel. This can be done easily by using the
make -jwill try to build all targets in parallel whose dependencies are available. This will swamp your machine with build tasks.
make -j 6will try to build a maximum of 6 (or any non-zero positive integer you specify) targets in parallel. The actual number of builds done in parallel might be less depending on how many targets have their dependencies ready.
- If you use parallel make frequently, then it is a good idea to turn it into an alias in your shell.
-joption can be set in the
MAKEFLAGSenvironment variable, if you want parallel make to be used whenever
makeis invoked. This is better than an alias since parallel make is used even if
makeis called inside programs which are not using (or not aware of) your alias.
- You may want to use the same alias or
MAKEFLAGSvariable across machines with varying number of CPU cores. One way to solve this problem is to use the output of the
nproc --allcommand to set the number of parallel jobs.