configure: rework pthread handling to allow for user defined flags
The tests for POSIX threads can now be controlled by the user with the --enable-pthreads=FLAGS option. If this is set (to some value other than yes or no), the value is passed to the compiler. Thread support is based solely on the outcome of this test. The user may specify not to use threading at all or to use the default tests (first -pthread then -lpthread) by not specifying FLAGS when passing --enable-pthreads. Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ben Walton committed
Mar 12, 2009 at 15:20 UTC
1973b0d790155b5d8a32a6f7401116fad2205721
1 file changed
+74
-15
configure.ac
+74
-15
@@ -127,6 +127,27 @@ if test -z "$lib"; then
127
lib=lib
128
fi
129
130
+AC_ARG_ENABLE([pthreads],
131
+ [AS_HELP_STRING([--enable-pthreads=FLAGS],
132
+ [FLAGS is the value to pass to the compiler to enable POSIX Threads.]
133
+ [The default if FLAGS is not specified is to try first -pthread]
134
+ [and then -lpthread.]
135
+ [--without-pthreads will disable threading.])],
136
+[
137
+if test "x$enableval" = "xyes"; then
138
+ AC_MSG_NOTICE([Will try -pthread then -lpthread to enable POSIX Threads])
139
+elif test "x$enableval" != "xno"; then
140
+ PTHREAD_CFLAGS=$enableval
141
+ AC_MSG_NOTICE([Setting '$PTHREAD_CFLAGS' as the FLAGS to enable POSIX Threads])
142
+else
143
+ AC_MSG_NOTICE([POSIX Threads will be disabled.])
144
+ NO_PTHREADS=YesPlease
145
+ USER_NOPTHREAD=1
146
+fi],
147
+[
148
+ AC_MSG_NOTICE([Will try -pthread then -lpthread to enable POSIX Threads.])
149
+])
150
+
151
## Site configuration (override autodetection)
152
## --with-PACKAGE[=ARG] and --without-PACKAGE
153
AC_MSG_NOTICE([CHECKS for site configuration])
@@ -672,23 +693,61 @@ AC_SUBST(NO_MKDTEMP)
693
#
694
# Define PTHREAD_LIBS to the linker flag used for Pthread support and define
695
# THREADED_DELTA_SEARCH if Pthreads are available.
675
-AC_LANG_CONFTEST([AC_LANG_PROGRAM(
676
- [[#include <pthread.h>]],
677
- [[pthread_mutex_t test_mutex;]]
678
-)])
679
-${CC} -pthread conftest.c -o conftest.o > /dev/null 2>&1
680
-if test $? -eq 0;then
681
- PTHREAD_LIBS="-pthread"
682
- THREADED_DELTA_SEARCH=YesPlease
696
+AC_DEFUN([PTHREADTEST_SRC], [
697
+#include <pthread.h>
698
+
699
+int main(void)
700
+{
701
+ pthread_mutex_t test_mutex;
702
+ return (0);
703
+}
704
+])
705
+
706
+dnl AC_LANG_CONFTEST([AC_LANG_PROGRAM(
707
+dnl [[#include <pthread.h>]],
708
+dnl [[pthread_mutex_t test_mutex;]]
709
+dnl )])
710
+
711
+NO_PTHREADS=UnfortunatelyYes
712
+THREADED_DELTA_SEARCH=
713
+PTHREAD_LIBS=
714
+
715
+if test -n "$USER_NOPTHREAD"; then
716
+ AC_MSG_NOTICE([Skipping POSIX Threads at user request.])
717
+# handle these separately since PTHREAD_CFLAGS could be '-lpthreads
718
+# -D_REENTRANT' or some such.
719
+elif test -z "$PTHREAD_CFLAGS"; then
720
+ for opt in -pthread -lpthread; do
721
+ old_CFLAGS="$CFLAGS"
722
+ CFLAGS="$opt $CFLAGS"
723
+ AC_MSG_CHECKING([Checking for POSIX Threads with '$opt'])
724
+ AC_LINK_IFELSE(PTHREADTEST_SRC,
725
+ [AC_MSG_RESULT([yes])
726
+ NO_PTHREADS=
727
+ PTHREAD_LIBS="$opt"
728
+ THREADED_DELTA_SEARCH=YesPlease
729
+ break
730
+ ],
731
+ [AC_MSG_RESULT([no])])
732
+ CFLAGS="$old_CFLAGS"
733
+ done
734
else
684
- ${CC} -lpthread conftest.c -o conftest.o > /dev/null 2>&1
685
- if test $? -eq 0;then
686
- PTHREAD_LIBS="-lpthread"
687
- THREADED_DELTA_SEARCH=YesPlease
688
- else
689
- NO_PTHREADS=UnfortunatelyYes
690
- fi
735
+ old_CFLAGS="$CFLAGS"
736
+ CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
737
+ AC_MSG_CHECKING([Checking for POSIX Threads with '$PTHREAD_CFLAGS'])
738
+ AC_LINK_IFELSE(PTHREADTEST_SRC,
739
+ [AC_MSG_RESULT([yes])
740
+ NO_PTHREADS=
741
+ PTHREAD_LIBS="$PTHREAD_CFLAGS"
742
+ THREADED_DELTA_SEARCH=YesPlease
743
+ ],
744
+ [AC_MSG_RESULT([no])])
745
+
746
+ CFLAGS="$old_CFLAGS"
747
fi
748
+
749
+CFLAGS="$old_CFLAGS"
750
+
751
AC_SUBST(PTHREAD_LIBS)
752
AC_SUBST(NO_PTHREADS)
753
AC_SUBST(THREADED_DELTA_SEARCH)