summaryrefslogtreecommitdiff
path: root/mk/detect-cpu-count.sh
diff options
context:
space:
mode:
Diffstat (limited to 'mk/detect-cpu-count.sh')
-rwxr-xr-xmk/detect-cpu-count.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/mk/detect-cpu-count.sh b/mk/detect-cpu-count.sh
new file mode 100755
index 0000000000..abc47387d1
--- /dev/null
+++ b/mk/detect-cpu-count.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+detect_cpu_count () {
+ if [ "$CPUS" = "" ]; then
+ # Windows standard environment variable
+ CPUS="$NUMBER_OF_PROCESSORS"
+ fi
+
+ if [ "$CPUS" = "" ]; then
+ # Linux
+ CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
+ fi
+
+ if [ "$CPUS" = "" ]; then
+ # FreeBSD
+ CPUS=`getconf NPROCESSORS_ONLN 2>/dev/null`
+ fi
+
+ if [ "$CPUS" = "" ]; then
+ # nothing helped
+ CPUS="1"
+ fi
+}
+
+detect_cpu_count
+echo "$CPUS"