Skip to content

Commit

Permalink
configure: Detect number of logical CPUs
Browse files Browse the repository at this point in the history
#5477

Signed-off-by: Albert Veli <[email protected]>
  • Loading branch information
AlbertVeli authored and solardiz committed May 16, 2024
1 parent b6bca75 commit 2ccc0f1
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 2 deletions.
113 changes: 112 additions & 1 deletion src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -18048,6 +18048,117 @@ Fuzzing test ....................................... ${fuzz}
EOF
fi

if test -z "$NPROC"
then :
if test -n "$ac_tool_prefix"; then
# Extract the first word of "${ac_tool_prefix}nproc", so it can be a program name with args.
set dummy ${ac_tool_prefix}nproc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_NPROC+y}
then :
printf %s "(cached) " >&6
else $as_nop
if test -n "$NPROC"; then
ac_cv_prog_NPROC="$NPROC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
case $as_dir in #(((
'') as_dir=./ ;;
*/) ;;
*) as_dir=$as_dir/ ;;
esac
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
ac_cv_prog_NPROC="${ac_tool_prefix}nproc"
printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS

fi
fi
NPROC=$ac_cv_prog_NPROC
if test -n "$NPROC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $NPROC" >&5
printf "%s\n" "$NPROC" >&6; }
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_NPROC"; then
ac_ct_NPROC=$NPROC
# Extract the first word of "nproc", so it can be a program name with args.
set dummy nproc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_NPROC+y}
then :
printf %s "(cached) " >&6
else $as_nop
if test -n "$ac_ct_NPROC"; then
ac_cv_prog_ac_ct_NPROC="$ac_ct_NPROC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
case $as_dir in #(((
'') as_dir=./ ;;
*/) ;;
*) as_dir=$as_dir/ ;;
esac
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_NPROC="nproc"
printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS

fi
fi
ac_ct_NPROC=$ac_cv_prog_ac_ct_NPROC
if test -n "$ac_ct_NPROC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NPROC" >&5
printf "%s\n" "$ac_ct_NPROC" >&6; }
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

if test "x$ac_ct_NPROC" = x; then
NPROC=""""
else
case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
NPROC=$ac_ct_NPROC
fi
else
NPROC="$ac_cv_prog_NPROC"
fi

fi
if test -z "$NPROC"; then
NUM_CORES=4
else
NUM_CORES=$(${NPROC})
fi

echo "Install missing libraries to get any needed features that were omitted."
echo ""
echo "Configure finished. Now \"${use_make} -s clean && ${use_make} -sj4\" to compile."
echo "Configure finished. Now \"${use_make} -s clean && ${use_make} -sj${NUM_CORES}\" to compile."
11 changes: 10 additions & 1 deletion src/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,16 @@ Fuzzing test ....................................... ${fuzz}
EOF
fi

dnl Try to figure out number of cpu cores for make -j suggestion
AS_IF([test -z "$NPROC"], [AC_CHECK_TOOL([NPROC], [nproc], [""])])
if test -z "$NPROC"; then
dnl default to 4
NUM_CORES=4
else
NUM_CORES=$(${NPROC})
fi

echo "Install missing libraries to get any needed features that were omitted."
echo ""
echo "Configure finished. Now \"${use_make} -s clean && ${use_make} -sj4\" to compile."
echo "Configure finished. Now \"${use_make} -s clean && ${use_make} -sj${NUM_CORES}\" to compile."
dnl ======================================================================

0 comments on commit 2ccc0f1

Please sign in to comment.