Skip to content

Commit b98d878

Browse files
committed
COMMON: More portable num_cpus
From FreeBSD, with extra care for macOS 10.4 returning "undefined".
1 parent 93c3288 commit b98d878

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

toolchains/common/functions.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ __do_cmake () {
108108

109109
__do_make () {
110110
local num_cpus
111-
num_cpus=$(nproc || grep -c ^processor /proc/cpuinfo || echo 1)
111+
num_cpus=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1)
112+
case "$num_cpus" in
113+
''|*[!0-9]*)
114+
# Older systems may return "undefined"
115+
num_cpus=1
116+
;;
117+
esac
118+
112119
make -j${NUM_CPUS:-$num_cpus} "$@"
113120
}
114121

0 commit comments

Comments
 (0)