diff --git a/Pmodules/libpbuild.bash b/Pmodules/libpbuild.bash index 6fcecb9..32d6a3d 100644 --- a/Pmodules/libpbuild.bash +++ b/Pmodules/libpbuild.bash @@ -41,7 +41,32 @@ trap "error_handler" ERR declare configure_with='undef' #.............................................................................. -# global variables +# +# The following variables are available in build-blocks and set read-only +# :FIXME: do we have to export them? + +# install prefix of module. +declare -x PREFIX='' + +declare -r OS=$(uname -s) + +pbuild::get_num_cores() { + case "${OS}" in + Linux ) + echo $(grep -c ^processor /proc/cpuinfo) + ;; + Darwin ) + echo $(sysctl -n hw.ncpu) + ;; + * ) + std::die 1 "OS ${OS} is not supported\n" + ;; + esac +} + +#.............................................................................. +# global variables which can be set/overwritten by command line args + declare force_rebuild='' pbuild.force_rebuild() { force_rebuild="$1" @@ -73,9 +98,13 @@ pbuild.update_modulefiles() { } # number of parallel make jobs -declare -i JOBS=3 +declare -i JOBS=$(pbuild::get_num_cores) pbuild.jobs() { - JOBS="$1" + if (( $1 == 0 )); then + JOBS=$(pbuild::get_num_cores) + else + JOBS="$1" + fi } declare system='' @@ -114,18 +143,6 @@ declare -x module_release='' # abs. path is "${PREFIX}/${_docdir}/${module_name}" declare -r _DOCDIR='share/doc' -#.............................................................................. -# -# The following variables are available in build-blocks and set read-only -# :FIXME: do we have to export them? -# - -# install prefix of module. -declare -x PREFIX='' - -declare -r OS=$(uname -s) - - ############################################################################## # # Set flag to build module in source tree. diff --git a/Pmodules/modbuild.in b/Pmodules/modbuild.in index 7ba6feb..e43f41a 100755 --- a/Pmodules/modbuild.in +++ b/Pmodules/modbuild.in @@ -140,7 +140,7 @@ declare opt_dry_run='no' declare opt_enable_cleanup_build='yes' declare opt_enable_cleanup_src='yes' declare opt_force_rebuild='no' -declare -i opt_jobs=3 +declare -i opt_jobs=0 declare opt_update_modulefiles='no' declare opt_system='' declare opt_temp_dir="${PMODULES_TMPDIR:-/var/tmp/${USER}}"