Skip to content

Commit 8a145cf

Browse files
macOS: Properly detect number of CPU cores on macOS
Linux and macOS have different ways of detecting number of CPU cores. Signed-off-by: Anton Kolesov <[email protected]>
1 parent 92c2b3c commit 8a145cf

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

build-all.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,11 @@ esac
448448

449449
if [ x`uname -s` = "xDarwin" ]
450450
then
451+
IS_MAC_OS=yes
451452
#You can install gsed with 'brew install gnu-sed'
452453
SED=gsed
454+
else
455+
IS_MAC_OS=no
453456
fi
454457

455458
# Parse options
@@ -835,9 +838,13 @@ then
835838
fi
836839
fi
837840

838-
# Default parallellism
839-
make_load="`(echo processor; cat /proc/cpuinfo 2>/dev/null echo processor) \
840-
| grep -c processor`"
841+
# Default parallellism (number of cores + 1).
842+
if [ "$IS_MAC_OS" != yes ]; then
843+
make_load="$( (echo processor; cat /proc/cpuinfo 2>/dev/null) \
844+
| grep -c processor )"
845+
else
846+
make_load="$(( $(sysctl -n hw.ncpu) + 1))"
847+
fi
841848

842849
if [ "x${jobs}" = "x" ]
843850
then
@@ -958,6 +965,7 @@ export BUILD_OPTSIZE_NEWLIB
958965
export BUILD_OPTSIZE_LIBSTDCXX
959966
export DO_STRIP_TARGET_LIBRARIES
960967
export IS_CROSS_COMPILING
968+
export IS_MAC_OS
961969
export IS_NATIVE
962970
export UCLIBC_IN_SRC_TREE
963971

0 commit comments

Comments
 (0)