When run, ninja normally runs a maximum number of processes in parallel. By default this is the number of cores on the system plus two. In some cases this can overheat a CPU or run a system out of memory. If run from the command line, passing a -jN parameter will limit the number of parallel processes, but some packages embed the execution of ninja and do not pass a -j parameter.
Using this optional procedure allows us to limit the number of parallel processes via an environment variable, NINJAJOBS.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- lfs/ninja | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/lfs/ninja b/lfs/ninja index c968345f4..ed9f8b778 100644 --- a/lfs/ninja +++ b/lfs/ninja @@ -71,6 +71,14 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) @$(PREBUILD) @rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar zxf $(DIR_DL)/$(DL_FILE)
+ # Allow to limit the paralell build processes ninja will do. + cd $(DIR_APP) && sed -i '/int Guess/a \ + int j = 0;\ + char* jobs = getenv( "NINJAJOBS" );\ + if ( jobs != NULL ) j = atoi( jobs );\ + if ( j > 0 ) return j;\ + ' src/ninja.cc + # Configure and bootstrap the build environment cd $(DIR_APP) && python3 configure.py --bootstrap --verbose
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- make.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/make.sh b/make.sh index 5b1e949c4..8dfc8897d 100755 --- a/make.sh +++ b/make.sh @@ -220,6 +220,9 @@ configure_build() { # Use this as default PARALLELISM DEFAULT_PARALLELISM="${parallelism}"
+ # Limit lauched ninja build jobs to computed parallel value. + NINJAJOBS="${parallelism}" + # Compression parameters # We use mode 8 for reasonable memory usage when decompressing # but with overall good compression @@ -465,7 +468,7 @@ prepareenv() { # Setup environment set +h LC_ALL=POSIX - export LFS LC_ALL CFLAGS CXXFLAGS DEFAULT_PARALLELISM RUSTFLAGS + export LFS LC_ALL CFLAGS CXXFLAGS DEFAULT_PARALLELISM RUSTFLAGS NINJAJOBS unset CC CXX CPP LD_LIBRARY_PATH LD_PRELOAD
# Make some extra directories