Enable multiple jobs for when build from source

Peter Dave Hello 2015-12-05 15:06:01 +08:00
parent f851716601
commit a8e6fee001
1 changed files with 36 additions and 2 deletions

38
nvm.sh
View File

@ -1231,6 +1231,30 @@ nvm_install_node_source() {
make='gmake' make='gmake'
MAKE_CXX="CXX=c++" MAKE_CXX="CXX=c++"
fi fi
if [ "_$NVM_OS" = "_linux" ]; then
CPU_THREADS="$(grep -c 'core id' /proc/cpuinfo)"
elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then
CPU_THREADS="$(sysctl -n hw.ncpu)"
elif [ "_$NVM_OS" = "_sunos" ]; then
CPU_THREADS="$(psrinfo | wc -l)"
fi
local CPU_THREAD_VALID
CPU_THREAD_VALID=$(nvm_is_natural_num $CPU_THREADS)
if [ -z "$CPU_THREADS" ] || [ "$CPU_THREAD_VALID" != "true" ] ; then
echo "Can not determine how many thread(s) we can use, set to only 1 now." 1>&2
echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" 1>&2
MAKE_JOBS="1"
else
echo "Detected that you have $CPU_THREADS CPU thread(s)"
if [ $CPU_THREADS -gt 2 ]; then
MAKE_JOBS=$(($CPU_THREADS - 1))
echo "Set the number of jobs to $CPU_THREADS - 1 = $MAKE_JOBS jobs to speed up the build"
else
MAKE_JOBS=1
echo "Number of CPU thread(s) less or equal to 2 will have only one job a time for 'make'"
fi
fi
local tmpdir local tmpdir
tmpdir="$NVM_DIR/src" tmpdir="$NVM_DIR/src"
local tmptarball local tmptarball
@ -1252,9 +1276,9 @@ nvm_install_node_source() {
command tar -xzf "$tmptarball" -C "$tmpdir" && \ command tar -xzf "$tmptarball" -C "$tmpdir" && \
cd "$tmpdir/node-$VERSION" && \ cd "$tmpdir/node-$VERSION" && \
./configure --prefix="$VERSION_PATH" $ADDITIONAL_PARAMETERS && \ ./configure --prefix="$VERSION_PATH" $ADDITIONAL_PARAMETERS && \
$make $MAKE_CXX && \ $make -j $MAKE_JOBS $MAKE_CXX && \
command rm -f "$VERSION_PATH" 2>/dev/null && \ command rm -f "$VERSION_PATH" 2>/dev/null && \
$make $MAKE_CXX install $make -j $MAKE_JOBS $MAKE_CXX install
) )
then then
if ! nvm_has "npm" ; then if ! nvm_has "npm" ; then
@ -1430,6 +1454,16 @@ nvm_sanitize_path() {
echo "$SANITIZED_PATH" | command sed "s#$HOME#\$HOME#g" echo "$SANITIZED_PATH" | command sed "s#$HOME#\$HOME#g"
} }
nvm_is_natural_num() {
echo $1 | command egrep -q '^[0-9]{1,}$' &> /dev/null
local IS_NATURAL_NUM=$?
if [ "$IS_NATURAL_NUM" = "0" ]; then
echo true
else
echo false
fi
}
nvm() { nvm() {
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
nvm help nvm help