default to number of CPUs for parallel make jobs

The previous default behaviour was to always run 'make -j8', which
can cause C++ build failures on machines which are low on memory.
"Low" being a relative measure; I've seen failures with 4GB of RAM.

Rather than assuming a beefy 8-core box, try to detect the number
of available CPU cores with nproc(1) from GNU coreutils and set
the number of parallel make jobs to the number of CPU cores.

If this command is not available, default to a safe choice: -j1
Note that installing ccache will speed up repeated builds a lot
more than -jX ever will, so falling back to -j1 isn't very bad.

Change-Id: I61c3ea1b3cb5b64eecb08ad6c390594f70cdf785
This commit is contained in:
Stefan Sperling 2018-06-25 15:19:17 +02:00
parent dadde17425
commit b0ad3d8490
1 changed files with 5 additions and 1 deletions

View File

@ -1,6 +1,10 @@
SUBDIRS=bsc bsc-nat bts ggsn_tests hlr lapdm mgw msc pcu selftest sgsn sip sysinfo
PARALLEL_MAKE ?= -j8
NPROC=$(shell nproc 2>/dev/null)
ifeq ($(NPROC),)
NPROC=1
endif
PARALLEL_MAKE ?= -j$(NPROC)
# This master makefile allows you to do things like
# make clean (remove all generated binary, c++ and symlinks)