- if [ -f "$(ls '/usr/local/bin/g++-'* | sort | tail -n1)" ]
- then
- gcc_version="$(ls '/usr/local/bin/g++-'* | sort | tail -n1 | sed -e 's/.*[^0-9]\([0-9][0-9]*\)$/\1/')"
- cmake_opts[${#cmake_opts[@]}]="-DCMAKE_C_COMPILER=/usr/local/bin/gcc-${gcc_version}"
- cmake_opts[${#cmake_opts[@]}]="-DCMAKE_CXX_COMPILER=/usr/local/bin/g++-${gcc_version}"
- else
- printf "WARNING: GCC is recommended: if build fails, install GCC and retry\n" >&2
- fi
- ;;
- 'MSYS_NT-'*)
- nproc='echo "${NUMBER_OF_PROCESSORS}"'
- ;;
- 'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
- nproc='echo "${NUMBER_OF_PROCESSORS}"'
- printf "WARNING: system is not tested: if build fails, use MSYS2 instead\n" >&2
- ;;
- *)
- nproc='true'
- printf "WARNING: system is not tested\n" >&2
- ;;
-esac
-
-if command -v 'nproc' >/dev/null
-then
- job_count="$(nproc)"
-else
- job_count="$(sh -c "${nproc}")"
-fi
+_nproc () {
+ if command -v 'nproc' >/dev/null
+ then
+ nproc
+ else
+ case "$(uname -s)" in
+ 'Linux')
+ egrep "^processor" /proc/cpuinfo | wc -l
+ ;;
+ 'FreeBSD'|'Darwin')
+ sysctl -n hw.ncpu
+ ;;
+ 'MSYS_NT-'*|'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
+ if command -v 'wmic' >/dev/null
+ then
+ wmic cpu get NumberOfLogicalProcessors/Format:List \
+ | grep -m1 '=' | cut -f2 -d'='
+ else
+ echo "${NUMBER_OF_PROCESSORS:-${_job_count}}"
+ fi
+ ;;
+ *)
+ echo "${_job_count}"
+ ;;
+ esac
+ fi
+}