make: Fix parallel building with some container platforms (VPP-880) 49/7149/4
authorChris Luke <chrisy@flirble.org>
Wed, 14 Jun 2017 15:24:41 +0000 (11:24 -0400)
committerDamjan Marion <dmarion.lists@gmail.com>
Sat, 24 Jun 2017 14:02:37 +0000 (14:02 +0000)
With some Linux container platforms /proc/cpuinfo reads as an empty
file. (Aside: stat on /proc/cpuinfo always indicates a length of
zero bytes, regardless of its content).

This has the effect that the make '-j' parameter being passed the
unhelpful value of '0' both in build-root/Makefile and dpdk/Makefile.
Make complains with the error:

  make: the '-j' option requires a positive integer argument

This patch checks for '0' and replaces it with '2' as a reasonable
number of jobs to run in parallel when the CPU count isn't known
(and assumed to be one). It also makes the value determination
consistent between VPP and DPDK (2*ncpu).

Change-Id: I78b89420114a825fab4d339e4f9291d486b7b9c8
Signed-off-by: Chris Luke <chrisy@flirble.org>
build-root/Makefile
dpdk/Makefile

index f2f7780..0fed520 100644 (file)
@@ -653,16 +653,13 @@ configure_check_timestamp =                                               \
 # Package build
 ######################################################################
 
-linux_n_cpus = `grep '^processor' /proc/cpuinfo | wc -l`
-
-MAKE_PARALLEL_JOBS =                           \
-  -j $(shell                                   \
-    if [ -f /proc/cpuinfo ] ; then             \
-      expr 2 '*' $(linux_n_cpus) ;             \
-    else                                       \
-      echo 1 ;                                 \
-    fi)
-
+# /proc/cpuinfo does not exist on platforms without a /proc and on some
+# platforms, notably inside containers, it has no content. In those cases
+# we assume there's 1 processor; we use 2*ncpu for the -j option.
+# NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
+# for file presence and content; for now this will have to do.
+MAKE_PARALLEL_JOBS = -j $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo), \
+       $(shell expr 2 '*' $$(grep -c ^processor /proc/cpuinfo)), 2)
 MAKE_PARALLEL_FLAGS = $(if $($(PACKAGE)_make_parallel_fails),,$(MAKE_PARALLEL_JOBS))
 
 # Make command shorthand for packages & tools.
index d781ed5..06ba127 100644 (file)
@@ -77,7 +77,13 @@ else
 $(error unknown platform)
 endif
 
-JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
+# /proc/cpuinfo does not exist on platforms without a /proc and on some
+# platforms, notably inside containers, it has no content. In those cases
+# we assume there's 1 processor; we use 2*ncpu for the -j option.
+# NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
+# for file presence and content; for now this will have to do.
+JOBS := $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo),\
+       $(shell expr 2 '*' $$(grep -c ^processor /proc/cpuinfo)), 2)
 
 # compiler/linker custom arguments
 DPDK_CPU_CFLAGS := -pie -fPIC