Skip to content
Snippets Groups Projects
Commit 765c4307 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: only count processors if required

- POSIX specifies '-c' for counting the number of matching lines,
  so we can just use that instead of 'wc' in wmake
parent 4d29c32e
Branches
Tags
No related merge requests found
......@@ -100,25 +100,18 @@ USAGE
exit 1
}
# Default make is the "make" in the path
make="make"
#------------------------------------------------------------------------------
# Set WM_NCOMPPROCS to number of cores on local machine
#------------------------------------------------------------------------------
useAllCores()
# Set nCores to the number of cores on the local machine
nCores=0
allCores()
{
if [ -r /proc/cpuinfo ]
then
WM_NCOMPPROCS=$(egrep "^processor" /proc/cpuinfo | wc -l)
else
WM_NCOMPPROCS=1
fi
export WM_NCOMPPROCS
nCores=$(egrep -c "^processor" /proc/cpuinfo 2>/dev/null) || nCores=1
: ${nCores:=1}
}
......@@ -145,11 +138,17 @@ do
-q | -queue | queue)
all=queue
;;
# Parallel compilation on all cores of local machine
# Parallel compilation on all cores (or specified number of cores)
-j)
useAllCores
nCores=0
test $# -ge 2 && expr $2 + 1 > /dev/null 2>&1 \
&& shift && export WM_NCOMPPROCS=$1
&& shift && nCores=$1
if [ "$nCores" = 0 ]
then
allCores
fi
export WM_NCOMPPROCS=$nCores
echo "Compiling enabled on $WM_NCOMPPROCS cores"
;;
# Parallel compilation on specified number of cores
......@@ -214,8 +213,7 @@ checkEnv
# Set WM_NCOMPPROCS automatically when both WM_HOSTS and WM_SCHEDULER are set
if [ -z "$WM_NCOMPPROCS" -a -n "$WM_HOSTS" -a -n "$WM_SCHEDULER" ]
then
WM_NCOMPPROCS=$(wmakeScheduler -count)
[ $? -eq 0 ] || unset WM_NCOMPPROCS
WM_NCOMPPROCS=$(wmakeScheduler -count) || unset WM_NCOMPPROCS
fi
if [ -n "$WM_NCOMPPROCS" ]
......@@ -348,8 +346,8 @@ then
export WM_COLLECT_DIR=$WM_PROJECT_DIR/build/${WM_OPTIONS}/${PWD////_}
export WM_SCHEDULER=wmakeCollect
trap '$WM_SCHEDULER -kill' TERM INT
$WM_SCHEDULER -clean \
&& wmake -all objects \
$WM_SCHEDULER -clean \
&& wmake -all objects \
&& $WM_SCHEDULER
) && wmake -all
exit $?
......
......@@ -78,6 +78,11 @@ do
nCores=${WM_NCOMPPROCS:-0}
test $# -ge 2 && expr $2 + 1 > /dev/null 2>&1 \
&& shift && nCores=$1
if [ "$nCores" = 0 ]
then
nCores=1
fi
;;
# Parallel compilation on specified number of cores
-j[1-9]*)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment