+AC_PATH_PROG([GETOPT], [getopt], [getopt])
+AC_ARG_VAR([GETOPT], [location of gnu-getopt, see --with-gnu-getopt; e.g. /usr/local/opt/gnu-getopt/bin/getopt])
+AC_ARG_WITH([gnu-getopt], [AS_HELP_STRING([--with-gnu-getopt=path], [
+ Location of the enhanced GNU getopt program])], [
+], [
+ with_gnu_getopt=$GETOPT
+])
+
+AC_MSG_CHECKING([for GNU getopt])
+$with_gnu_getopt --test >/dev/null
+AS_IF([test $? -ne 4], [
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([$with_gnu_getopt looks like the BSD version, please provide the path to the GNU version --with-gnu-getopt])
+], [
+ AC_MSG_RESULT([yes, $with_gnu_getopt])
+ AC_SUBST([GETOPT], [$with_gnu_getopt])
+])
+
+AC_PROG_AWK
+AC_PATH_PROG([AWK_PATH], [$AWK], [/bin/$AWK])
+
+AC_CHECK_PROGS([SETSID], [setsid], [nothing])
+AC_ARG_VAR([SETSID], [location of a setsid program; a simple replacement will be built if none found or provided])
+AS_IF([test "$SETSID" = nothing], [
+ SETSID="\$BTR_BINDIR/btr-setsid"
+ AC_PROG_CC
+ AC_CONFIG_FILES([bin/Makefile])
+], [:]);
+
+AC_CHECK_PROGS([NPROC], [nproc sysctl], [nothing])
+AC_MSG_CHECKING([for number of cores])
+AS_CASE([$NPROC],
+ [nproc], [
+ BTR_CPUS=$(nproc)
+ ],
+ [sysctl], [
+ BTR_CPUS=$(sysctl -n hw.ncpu 2>/dev/null || echo 1)
+ ],
+ [
+ BTR_CPUS=1
+ ]
+)
+AC_MSG_RESULT([$BTR_CPUS])
+AC_SUBST([BTR_CPUS], [$BTR_CPUS])
+