Merge branch 'mh/pthreads-autoconf'
authorJunio C Hamano <gitster@pobox.com>
Thu, 3 Jan 2013 18:28:33 +0000 (10:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Jan 2013 18:28:33 +0000 (10:28 -0800)
* mh/pthreads-autoconf:
configure.ac: fix pthreads detection on Mac OS X

1  2 
configure.ac
diff --combined configure.ac
index dc6925f11a57d2e3987d94b4f280441038351219,55aae5f38928e1eea2de07fd7de14ad58152bab2..1991258ae031cd656a8b599fda16ec73695216cb
@@@ -753,14 -753,6 +753,14 @@@ AC_CHECK_MEMBER(struct dirent.d_type
  [#include <dirent.h>])
  GIT_CONF_SUBST([NO_D_TYPE_IN_DIRENT])
  #
 +# Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwd
 +# in the C library.
 +AC_CHECK_MEMBER(struct passwd.pw_gecos,
 +[NO_GECOS_IN_PWENT=],
 +[NO_GECOS_IN_PWENT=YesPlease],
 +[#include <pwd.h>])
 +GIT_CONF_SUBST([NO_GECOS_IN_PWENT])
 +#
  # Define NO_SOCKADDR_STORAGE if your platform does not have struct
  # sockaddr_storage.
  AC_CHECK_TYPE(struct sockaddr_storage,
@@@ -880,12 -872,6 +880,12 @@@ AC_CHECK_HEADER([libcharset.h]
  [HAVE_LIBCHARSET_H=YesPlease],
  [HAVE_LIBCHARSET_H=])
  GIT_CONF_SUBST([HAVE_LIBCHARSET_H])
 +#
 +# Define HAVE_STRINGS_H if you have strings.h
 +AC_CHECK_HEADER([strings.h],
 +[HAVE_STRINGS_H=YesPlease],
 +[HAVE_STRINGS_H=])
 +GIT_CONF_SUBST([HAVE_STRINGS_H])
  # Define CHARSET_LIB if libiconv does not export the locale_charset symbol
  # and libcharset does
  CHARSET_LIB=
@@@ -1035,10 -1021,20 +1035,20 @@@ if test -n "$USER_NOPTHREAD"; the
  # -D_REENTRANT' or some such.
  elif test -z "$PTHREAD_CFLAGS"; then
    threads_found=no
-   for opt in -mt -pthread -lpthread; do
+   # Attempt to compile and link some code using pthreads to determine
+   # required linker flags. The order is somewhat important here: We
+   # first try it without any extra flags, to catch systems where
+   # pthreads are part of the C library, then go on testing various other
+   # flags. We do so to avoid false positives. For example, on Mac OS X
+   # pthreads are part of the C library; moreover, the compiler allows us
+   # to add "-mt" to the CFLAGS (although it will do nothing except
+   # trigger a warning about an unused flag). Hence if we checked for
+   # "-mt" before "" we would end up picking it. But unfortunately this
+   # would then trigger compiler warnings on every single file we compile.
+   for opt in "" -mt -pthread -lpthread; do
       old_CFLAGS="$CFLAGS"
       CFLAGS="$opt $CFLAGS"
 -     AC_MSG_CHECKING([Checking for POSIX Threads with '$opt'])
 +     AC_MSG_CHECKING([for POSIX Threads with '$opt'])
       AC_LINK_IFELSE([PTHREADTEST_SRC],
        [AC_MSG_RESULT([yes])
                NO_PTHREADS=
  else
    old_CFLAGS="$CFLAGS"
    CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
 -  AC_MSG_CHECKING([Checking for POSIX Threads with '$PTHREAD_CFLAGS'])
 +  AC_MSG_CHECKING([for POSIX Threads with '$PTHREAD_CFLAGS'])
    AC_LINK_IFELSE([PTHREADTEST_SRC],
        [AC_MSG_RESULT([yes])
                NO_PTHREADS=