build.sh: read job_count when possible

This commit is contained in:
Thomas Debesse 2020-12-12 06:28:46 +01:00 committed by mborgerson
parent aab63105fc
commit 03beb4e96b

View File

@ -88,9 +88,44 @@ package_linux() {
postbuild=''
debug_opts=''
build_cflags='-O3'
job_count='12'
default_job_count='12'
sys_ldflags=''
get_job_count () {
if command -v 'nproc' >/dev/null
then
nproc
else
case "$(uname -s)" in
'Linux')
egrep "^processor" /proc/cpuinfo | wc -l
;;
'FreeBSD')
sysctl -n hw.ncpu
;;
'Darwin')
sysctl -n hw.logicalcpu 2>/dev/null \
|| 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:-${default_job_count}}"
fi
;;
*)
echo "${default_job_count}"
;;
esac
fi
}
job_count="$(get_job_count)" 2>/dev/null
job_count="${job_count:-${default_job_count}}"
while [ ! -z "${1}" ]
do
case "${1}" in