Support parameter -j to set jobs for make
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Peter Dave Hello · committed by Peter Dave Hello · parent a8e6fee · Browse files · 1 file·+37 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+37 added−20 removed
- other:+37 added−20 removed
Provenance
- Commit
6320719- Tree
9389745- Author
Peter Dave Hello <hsu@peterdavehello.org>- Committer
Peter Dave Hello <hsu@peterdavehello.org>- Parent
a8e6fee
1 file changed+37 added−20 removed
modified:nvm.sh+37 added-20 removed
1230 unmodified lines1231 make='gmake'1232 MAKE_CXX="CXX=c++"1233 fi1234 1235- if [ "_$NVM_OS" = "_linux" ]; then1236- CPU_THREADS="$(grep -c 'core id' /proc/cpuinfo)"1237- elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then1238- CPU_THREADS="$(sysctl -n hw.ncpu)"1239- elif [ "_$NVM_OS" = "_sunos" ]; then1240- CPU_THREADS="$(psrinfo | wc -l)"1241- fi1242- local CPU_THREAD_VALID1243- CPU_THREAD_VALID=$(nvm_is_natural_num $CPU_THREADS)1244- if [ -z "$CPU_THREADS" ] || [ "$CPU_THREAD_VALID" != "true" ] ; then1245- echo "Can not determine how many thread(s) we can use, set to only 1 now." 1>&21246- echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" 1>&21247- MAKE_JOBS="1"1248- else1249- echo "Detected that you have $CPU_THREADS CPU thread(s)"1250- if [ $CPU_THREADS -gt 2 ]; then1251- MAKE_JOBS=$(($CPU_THREADS - 1))1252- echo "Set the number of jobs to $CPU_THREADS - 1 = $MAKE_JOBS jobs to speed up the build"1235+ if [ -z "$MAKE_JOBS" ]; then1236+ if [ "_$NVM_OS" = "_linux" ]; then1237+ CPU_THREADS="$(grep -c 'core id' /proc/cpuinfo)"1238+ elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then1239+ CPU_THREADS="$(sysctl -n hw.ncpu)"1240+ elif [ "_$NVM_OS" = "_sunos" ]; then1241+ CPU_THREADS="$(psrinfo | wc -l)"1242+ fi1243+ local CPU_THREAD_VALID1244+ CPU_THREAD_VALID=$(nvm_is_natural_num $CPU_THREADS)1245+ if [ -z "$CPU_THREADS" ] || [ "$CPU_THREAD_VALID" != "true" ] ; then1246+ echo "Can not determine how many thread(s) we can use, set to only 1 now." 1>&21247+ echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" 1>&21248+ MAKE_JOBS="1"1249 else1250+ echo "Detected that you have $CPU_THREADS CPU thread(s)"1251+ if [ $CPU_THREADS -gt 2 ]; then1252+ MAKE_JOBS=$(($CPU_THREADS - 1))1253+ echo "Set the number of jobs to $CPU_THREADS - 1 = $MAKE_JOBS jobs to speed up the build"1254+ else1254- MAKE_JOBS=11255- echo "Number of CPU thread(s) less or equal to 2 will have only one job a time for 'make'"1255+ MAKE_JOBS=11256+ echo "Number of CPU thread(s) less or equal to 2 will have only one job a time for 'make'"1257+ fi1258 fi1259 fi1260 local tmpdir1261 tmpdir="$NVM_DIR/src"318 unmodified lines1580 nobinary=01581 if [ "_$1" = "_-s" ]; then1582 nobinary=11583 shift1584+ if [ "_$1" = "_-j" ]; then1585+ shift1586+ local CPU_THREAD_VALID1587+ CPU_THREAD_VALID=$(nvm_is_natural_num $1)1588+ if [ "$CPU_THREAD_VALID" = "true" ]; then1589+ MAKE_JOBS=$11590+ echo "Set number of jobs to $MAKE_JOBS for 'make' utility"1591+ else1592+ unset MAKE_JOBS1593+ echo >&2 "$1 is invalid for CPU threads, should be a natural number"1594+ fi1595+ shift1596+ else1597+ unset MAKE_JOBS1598+ fi1599 fi1600 1601 provided_version="$1"1602 731 unmodified lines