Skip to content

Commit

Permalink
Makefile: -lpthread may still be necessary when libc has only pthread…
Browse files Browse the repository at this point in the history
… stubs

Without this patch, systems that provide stubs for pthread functions
in libc, but which still require libpthread for full the pthread
implementation are not detected correctly.

Also, some systems require -pthread in CFLAGS for each compilation
unit for a successful link of an mt binary, which is also addressed by
this patch.

Signed-off-by: Gary V. Vaughan <gary@thewrittenword.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Gary V. Vaughan authored and gitster committed May 31, 2010
1 parent 66dbfd5 commit 48793cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ RPMBUILD = rpmbuild
TCL_PATH = tclsh
TCLTK_PATH = wish
PTHREAD_LIBS = -lpthread
PTHREAD_CFLAGS =

export TCL_PATH TCLTK_PATH

Expand Down Expand Up @@ -898,6 +899,8 @@ ifeq ($(uname_S),AIX)
BASIC_CFLAGS += -D_LARGE_FILES
ifeq ($(shell expr "$(uname_V)" : '[1234]'),1)
NO_PTHREADS = YesPlease
else
PTHREAD_LIBS = -lpthread
endif
endif
ifeq ($(uname_S),GNU)
Expand Down Expand Up @@ -1349,6 +1352,7 @@ endif
ifdef NO_PTHREADS
BASIC_CFLAGS += -DNO_PTHREADS
else
BASIC_CFLAGS += $(PTHREAD_CFLAGS)
EXTLIBS += $(PTHREAD_LIBS)
LIB_OBJS += thread-utils.o
endif
Expand Down
1 change: 1 addition & 0 deletions config.mak.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ NO_DEFLATE_BOUND=@NO_DEFLATE_BOUND@
FREAD_READS_DIRECTORIES=@FREAD_READS_DIRECTORIES@
SNPRINTF_RETURNS_BOGUS=@SNPRINTF_RETURNS_BOGUS@
NO_PTHREADS=@NO_PTHREADS@
PTHREAD_CFLAGS=@PTHREAD_CFLAGS@
PTHREAD_LIBS=@PTHREAD_LIBS@
17 changes: 15 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,11 @@ AC_DEFUN([PTHREADTEST_SRC], [
int main(void)
{
pthread_mutex_t test_mutex;
return (0);
int retcode = 0;
retcode |= pthread_mutex_init(&test_mutex,(void *)0);
retcode |= pthread_mutex_lock(&test_mutex);
retcode |= pthread_mutex_unlock(&test_mutex);
return retcode;
}
])

Expand All @@ -819,19 +823,27 @@ if test -n "$USER_NOPTHREAD"; then
# handle these separately since PTHREAD_CFLAGS could be '-lpthreads
# -D_REENTRANT' or some such.
elif test -z "$PTHREAD_CFLAGS"; then
for opt in -pthread -lpthread; do
threads_found=no
for opt in -mt -pthread -lpthread; do
old_CFLAGS="$CFLAGS"
CFLAGS="$opt $CFLAGS"
AC_MSG_CHECKING([Checking for POSIX Threads with '$opt'])
AC_LINK_IFELSE(PTHREADTEST_SRC,
[AC_MSG_RESULT([yes])
NO_PTHREADS=
PTHREAD_LIBS="$opt"
PTHREAD_CFLAGS="$opt"
threads_found=yes
break
],
[AC_MSG_RESULT([no])])
CFLAGS="$old_CFLAGS"
done
if test $threads_found != yes; then
AC_CHECK_LIB([pthread], [pthread_create],
[PTHREAD_LIBS="-lpthread"],
[NO_PTHREADS=UnfortunatelyYes])
fi
else
old_CFLAGS="$CFLAGS"
CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
Expand All @@ -848,6 +860,7 @@ fi

CFLAGS="$old_CFLAGS"

AC_SUBST(PTHREAD_CFLAGS)
AC_SUBST(PTHREAD_LIBS)
AC_SUBST(NO_PTHREADS)

Expand Down

0 comments on commit 48793cf

Please sign in to comment.