We are trying to test for -pthread availability and set the flag in both CXXFLAGS and LDFLAGS. We don't want to use ax_pthread because it uses the wrong compiler and sets the wrong flags for a C++ project. And according to Significance of -pthread flag when compiling, -pthread is most portable, so we want to use it for both CXXFLAGS and LDFLAGS.
The scripting we added to configure.ac is:
AC_ARG_ENABLE(tls,
AS_HELP_STRING([--enable-tls], [enable thread storage (default is yes)]),
ac_enable_tls=$enableval,
ac_enable_tls=yes)
AM_CONDITIONAL(HAS_PTHREADS, test $ac_enable_tls = yes)
if test "$ac_enable_tls" = "yes"; then
SAVED_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="-pthread"
AC_MSG_CHECKING([for pthread support])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([-pthread]) && AC_SUBST([AM_CXXFLAGS], ["-pthread"]) && AC_SUBST([AM_LDFLAGS], ["-pthread"])],
[AC_MSG_FAILURE(["--enable-tls=yes but pthreads are not available"])]
)
CXXFLAGS="$SAVED_CXXFLAGS"
fi
It results in:
./configure: line 16173: syntax error near unexpected token `&&'
./configure: line 16173: ` && AM_LDFLAGS="-pthread"'
autoreconf --warnings=all produces no warnings related to the test.
I'm guessing the trouble is trying to do three things in AC_COMPILE_IFELSE and [action-if-true]. The Autoconf AC_COMPILE_IFELSE docs don't tell us how to handle the situation and does not provide examples.
We want to perform three actions in [action-if-true]:
- Print the message
pthread AM_CXXFLAGS += -pthreadAM_LDFLAGS += -pthread
How do I perform multiple actions in [action-if-true]?