@matheusbsbs / matheus-bagliano / commits / 48793cf46a
Fork 0

Makefile: -lpthread may still be necessary when libc has only pthread 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>

Gary V. Vaughan committed May 14, 2010 at 09:31 UTC 48793cf46a286a21df420fdd7fc4b0c91c60a0c8
3 files changed +20 -2
Makefile
+4
@@ -294,6 +294,7 @@ RPMBUILD = rpmbuild
294 TCL_PATH = tclsh
295 TCLTK_PATH = wish
296 PTHREAD_LIBS = -lpthread
297 +PTHREAD_CFLAGS =
298
299 export TCL_PATH TCLTK_PATH
300
@@ -898,6 +899,8 @@ ifeq ($(uname_S),AIX)
899 BASIC_CFLAGS += -D_LARGE_FILES
900 ifeq ($(shell expr "$(uname_V)" : '[1234]'),1)
901 NO_PTHREADS = YesPlease
902 + else
903 + PTHREAD_LIBS = -lpthread
904 endif
905 endif
906 ifeq ($(uname_S),GNU)
@@ -1349,6 +1352,7 @@ endif
1352 ifdef NO_PTHREADS
1353 BASIC_CFLAGS += -DNO_PTHREADS
1354 else
1355 + BASIC_CFLAGS += $(PTHREAD_CFLAGS)
1356 EXTLIBS += $(PTHREAD_LIBS)
1357 LIB_OBJS += thread-utils.o
1358 endif
config.mak.in
+1
@@ -57,4 +57,5 @@ NO_DEFLATE_BOUND=@NO_DEFLATE_BOUND@
57 FREAD_READS_DIRECTORIES=@FREAD_READS_DIRECTORIES@
58 SNPRINTF_RETURNS_BOGUS=@SNPRINTF_RETURNS_BOGUS@
59 NO_PTHREADS=@NO_PTHREADS@
60 +PTHREAD_CFLAGS=@PTHREAD_CFLAGS@
61 PTHREAD_LIBS=@PTHREAD_LIBS@
configure.ac
+15 -2
@@ -802,7 +802,11 @@ AC_DEFUN([PTHREADTEST_SRC], [
802 int main(void)
803 {
804 pthread_mutex_t test_mutex;
805 - return (0);
805 + int retcode = 0;
806 + retcode |= pthread_mutex_init(&test_mutex,(void *)0);
807 + retcode |= pthread_mutex_lock(&test_mutex);
808 + retcode |= pthread_mutex_unlock(&test_mutex);
809 + return retcode;
810 }
811 ])
812
@@ -819,7 +823,8 @@ if test -n "$USER_NOPTHREAD"; then
823 # handle these separately since PTHREAD_CFLAGS could be '-lpthreads
824 # -D_REENTRANT' or some such.
825 elif test -z "$PTHREAD_CFLAGS"; then
822 - for opt in -pthread -lpthread; do
826 + threads_found=no
827 + for opt in -mt -pthread -lpthread; do
828 old_CFLAGS="$CFLAGS"
829 CFLAGS="$opt $CFLAGS"
830 AC_MSG_CHECKING([Checking for POSIX Threads with '$opt'])
@@ -827,11 +832,18 @@ elif test -z "$PTHREAD_CFLAGS"; then
832 [AC_MSG_RESULT([yes])
833 NO_PTHREADS=
834 PTHREAD_LIBS="$opt"
835 + PTHREAD_CFLAGS="$opt"
836 + threads_found=yes
837 break
838 ],
839 [AC_MSG_RESULT([no])])
840 CFLAGS="$old_CFLAGS"
841 done
842 + if test $threads_found != yes; then
843 + AC_CHECK_LIB([pthread], [pthread_create],
844 + [PTHREAD_LIBS="-lpthread"],
845 + [NO_PTHREADS=UnfortunatelyYes])
846 + fi
847 else
848 old_CFLAGS="$CFLAGS"
849 CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
@@ -848,6 +860,7 @@ fi
860
861 CFLAGS="$old_CFLAGS"
862
863 +AC_SUBST(PTHREAD_CFLAGS)
864 AC_SUBST(PTHREAD_LIBS)
865 AC_SUBST(NO_PTHREADS)
866