Package: src:gcc-mingw-w64
Version: 26.5
Tags: patch

Hello Stephen.

The code in debian/rules regarding memory usage has
several issues. Here is a patch to fix them which I
also sent to llvm-toolchain maintainers:

- Ensure that USE_CPUS is always >= 1. In bug #1067714 I
explain why allowing USE_CPUS to be 0 is bad.

- Ensure that USE_CPUS is never > NUM_CPUS.
I think we don't want that either.

- Uses only one invocation of awk instead of two, by simply
getting "mt" on the fly while parsing /proc/meminfo and then
using it in the END block.

- Works also when awk is original-awk (that's what the parenthesis at
the end are for, which also makes the whole expression easier to understand).

Patch attached. Hope you like it.

Thanks.
diff --git a/debian/rules b/debian/rules
index 9148b74..337d94f 100755
--- a/debian/rules
+++ b/debian/rules
@@ -127,9 +127,8 @@ else
   NUM_CPUS := $(shell if echo $(USE_NJOBS) | grep -q -E '^[0-9]+$$'; \
                         then echo $(USE_NJOBS); \
                         else getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1; 
fi)
-  USE_CPUS := $(shell mt=`awk '/^MemTotal/ { print $$2 }' /proc/meminfo`; \
-                        awk -vn=$(NUM_CPUS) -vmt=$$mt -vm=$(MEM_PER_CPU) \
-                                'END { mt/=1024; n2 = int(mt/m); print n==1 ? 
1 : n2<n+1 ? n2 : n+1}' < /dev/null)
+  USE_CPUS := $(shell awk -vn=$(NUM_CPUS) -vm=$(MEM_PER_CPU) '/^MemTotal/ { mt 
= $$2 } \
+    END { n2 = int(mt/1024/m); print (n==1 || n2<=1) ? 1 : (n2<=n ? n2 : n) }' 
/proc/meminfo)
   ifneq (,$(strip $(USE_CPUS)))
     NJOBS := -j $(USE_CPUS)
   endif

Reply via email to