]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
ninja: Allow to limit the parallel build processes.
authorStefan Schantl <stefan.schantl@ipfire.org>
Sat, 26 Dec 2020 17:09:23 +0000 (18:09 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 27 Dec 2020 10:30:41 +0000 (10:30 +0000)
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>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
lfs/ninja

index c968345f4f0e4fc5c716b0a460eeab332f33c5cd..ed9f8b77806895ee79faa4a83622ee0aef971164 100644 (file)
--- 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