+###############################################################################
+#
+# Query AX_PTHREAD, and figure out which compiler gets used.
+#
+###############################################################################
+
+AC_DEFUN([AC_PROG_CC_PTHREAD],
+ [have_pthread=no
+ with_pthread_req=unspecified
+
+ # AX_PTHREAD is from the GNU Autoconf Archive.
+ # https://savannah.gnu.org/projects/autoconf-archive/
+ m4_include(ax_pthread.m4)
+
+ # This affects CC, LIBS, and CFLAGS, instead of defining new variables.
+
+ AC_ARG_WITH([pthread],
+ [ --with-pthread Enables POSIX threads, for SMP support.],
+ [with_pthread="$withval"; with_pthread_req="$withval"],
+ [with_pthread=yes])
+
+ if test "$with_pthread" = yes; then
+ # AX_PTHREAD might want a different compiler.
+ AX_PTHREAD(
+ [if test "$CC" = "$PTHREAD_CC" -o -z "$ac_original_cc"; then
+ have_pthread=yes
+ else
+ ac_prog_cc_no_pthread=yes
+ fi
+ ])
+
+ if test "$have_pthread" = yes; then
+ AC_DEFINE([HAVE_PTHREAD])
+ CC=$PTHREAD_CC
+
+ # AX_PTHREAD documentation specifically suggests this...
+ LIBS="$PTHREAD_LIBS $LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ fi
+ fi
+])
+
+