configure.ac: fix pthreads detection on Mac OS X

The configure script checks whether certain flags are required to use pthreads. But it did not consider that *none* might be needed (as is the case on Mac OS X). This lead to configure adding "-mt" to the list of flags (which does nothing on OS X except producing a warning). This in turn triggered a compiler warning on every single file. To solve this, we now first check if pthreads work without extra flags. This means the check is now order dependant, hence a comment is added explaining this, and the reasons for it. Note that it might be possible to write an order independent test, but it does not seem worth the extra effort required for implementing and testing such a solution, when this simple solution exists and works. Signed-off-by: Max Horn <max@quendi.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Max Horn committed Nov 28, 2012 at 00:28 UTC e0a52279304a67d6e13c5a5b4165dd09f6ba61aa
1 file changed +11 -1
configure.ac
+11 -1
@@ -1021,7 +1021,17 @@ if test -n "$USER_NOPTHREAD"; then
1021 # -D_REENTRANT' or some such.
1022 elif test -z "$PTHREAD_CFLAGS"; then
1023 threads_found=no
1024 - for opt in -mt -pthread -lpthread; do
1024 + # Attempt to compile and link some code using pthreads to determine
1025 + # required linker flags. The order is somewhat important here: We
1026 + # first try it without any extra flags, to catch systems where
1027 + # pthreads are part of the C library, then go on testing various other
1028 + # flags. We do so to avoid false positives. For example, on Mac OS X
1029 + # pthreads are part of the C library; moreover, the compiler allows us
1030 + # to add "-mt" to the CFLAGS (although it will do nothing except
1031 + # trigger a warning about an unused flag). Hence if we checked for
1032 + # "-mt" before "" we would end up picking it. But unfortunately this
1033 + # would then trigger compiler warnings on every single file we compile.
1034 + for opt in "" -mt -pthread -lpthread; do
1035 old_CFLAGS="$CFLAGS"
1036 CFLAGS="$opt $CFLAGS"
1037 AC_MSG_CHECKING([Checking for POSIX Threads with '$opt'])