]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
make.sh: Calculate MAKETUNING depending on available memory
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 7 Nov 2017 14:43:14 +0000 (15:43 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 7 Nov 2017 14:43:14 +0000 (15:43 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
make.sh
tools/make-functions

diff --git a/make.sh b/make.sh
index 175db5191e4e9f602409e46048ee4ff5f4031a3a..f4d474d364c2c19a8f5fe87ded8561f01251bd6a 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -62,16 +62,17 @@ export BASEDIR LOGFILE
 DIR_CHK=$BASEDIR/cache/check
 mkdir $BASEDIR/log/ 2>/dev/null
 
+# Load configuration file
+if [ -f .config ]; then
+       . .config
+fi
+
 # Include funtions
 . tools/make-functions
 
 # Get the amount of memory in this build system
 HOST_MEM=$(system_memory)
 
-if [ -f .config ]; then
-       . .config
-fi
-
 if [ -n "${BUILD_ARCH}" ]; then
        configure_build "${BUILD_ARCH}"
 elif [ -n "${TARGET_ARCH}" ]; then
@@ -176,11 +177,6 @@ prepareenv() {
     # Setup environment
     set +h
     LC_ALL=POSIX
-    if [ -z $MAKETUNING ]; then
-       CPU_COUNT="$(system_processors)"
-
-       MAKETUNING="-j$(( ${CPU_COUNT} * 2 + 1 ))"
-    fi
     export LFS LC_ALL CFLAGS CXXFLAGS MAKETUNING
     unset CC CXX CPP LD_LIBRARY_PATH LD_PRELOAD
 
index 676b9710120c9bd94fb8972b187cbea3407f3c86..9cf2fcfb472f0f10da31c293e06fa1e99539924a 100644 (file)
@@ -150,6 +150,26 @@ configure_build() {
        fi
 
        CXXFLAGS="${CFLAGS}"
+
+       # Determine parallelism
+       if [ -z "${MAKETUNING}" ]; then
+               # We assume that each process consumes about
+               # 192MB of memory. Therefore we find out how
+               # many processes fit into memory.
+               local mem_max=$(( ${HOST_MEM} / 192 ))
+
+               local processors="$(system_processors)"
+               local cpu_max=$(( ${processors} * 2 ))
+
+               local parallelism
+               if [ ${mem_max} -lt ${cpu_max} ]; then
+                       parallelism=${mem_max}
+               else
+                       parallelism=${cpu_max}
+               fi
+
+               MAKETUNING="-j${parallelism}"
+       fi
 }
 
 configure_build_guess() {