Greetings,

This started as a simple and obvious one-liner, but somehow the code morphed into something that seems a bit more clear (to me, at least). Sanity-checked on FreeBSD and Ubuntu. Contributed under LGPL3+/MPL.

Thanks,
Mike Eberdt

>From bca781bca606d7bab5908d6eb2f39d4439984846 Mon Sep 17 00:00:00 2001
From: Mike Eberdt <libr...@comcast.net>
Date: Thu, 14 Jul 2011 19:35:30 -0700
Subject: [PATCH] Properly determine number of CPUs on FreeBSD

---
 configure.in |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/configure.in b/configure.in
index c61685c..88f3d82 100755
--- a/configure.in
+++ b/configure.in
@@ -8699,16 +8699,22 @@ dnl 
===================================================================
 dnl Number of CPUs to use during the build
 dnl ===================================================================
 AC_MSG_CHECKING([for number of processors to use])
-if test "z`uname -s`" = "zDarwin" -o "z`uname -s`" = "zNetBSD" -o "z`uname 
-s`" = "zOpenBSD"; then
-    BUILD_NCPUS=`sysctl -n hw.ncpu`
-else
-    BUILD_NCPUS=`grep $'^processor\t*:' /proc/cpuinfo | wc -l`
-fi
-if test "z$with_num_cpus" != "z"; then
+if test -n "$with_num_cpus"; then
     BUILD_NCPUS=$with_num_cpus
-fi
-if echo "$BUILD_NCPUS" | $EGREP -q '^[[[:space:]]]*0[[[:space:]]]*$' ; then
-    BUILD_NCPUS=1
+else
+    case `uname -s` in
+      Darwin|FreeBSD|NetBSD|OpenBSD) \
+         BUILD_NCPUS=`sysctl -n hw.ncpu`
+         ;;
+      *) BUILD_NCPUS=`grep $'^processor\t*:' /proc/cpuinfo | wc -l`
+         ;;
+    esac
+
+    # If we hit the catch-all case, but /proc/cpuinfo doesn't exist or has an
+    # unexpected format, 'wc -l' will have returned 0.
+    if test "$BUILD_NCPUS" -eq 0; then
+        BUILD_NCPUS=1
+    fi
 fi
 AC_MSG_RESULT([$BUILD_NCPUS])
 AC_SUBST(BUILD_NCPUS)
-- 
1.7.6


_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to