Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


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 <libreme@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



Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.