diff configure.in @ 399:cfcf6bf1640c

Unified the thread detection code for UNIX platforms
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jun 2002 21:39:49 +0000
parents d219b0e02f5f
children 3dde0301f5f9
line wrap: on
line diff
--- a/configure.in	Mon Jun 10 20:42:53 2002 +0000
+++ b/configure.in	Mon Jun 10 21:39:49 2002 +0000
@@ -1099,6 +1099,34 @@
     fi
 }
 
+dnl See if we can use GNU pth library for threads
+CheckPTH()
+{
+    dnl Check for pth support
+    AC_ARG_ENABLE(pth,
+[  --enable-pth            use GNU pth library for multi-threading [default=yes]],
+                  , enable_pth=yes)
+    if test x$enable_threads = xyes -a x$enable_pth = xyes; then
+        AC_PATH_PROG(PTH_CONFIG, pth-config, no)
+        if test "$PTH_CONFIG" = "no"; then
+            use_pth=no
+        else
+            PTH_CFLAGS=`$PTH_CONFIG --cflags`
+            PTH_LIBS=`$PTH_CONFIG --libs --all`
+            SDL_CFLAGS="$SDL_CFLAGS $PTH_CFLAGS"
+            SDL_LIBS="$SDL_LIBS $PTH_LIBS"
+            CFLAGS="$CFLAGS -DENABLE_PTH"
+            use_pth=yes
+        fi
+        AC_MSG_CHECKING(pth)
+        if test "x$use_pth" = xyes; then
+            AC_MSG_RESULT(yes)
+        else
+            AC_MSG_RESULT(no)
+        fi
+    fi
+}
+
 dnl See what type of thread model to use on Linux and Solaris
 CheckPTHREAD()
 {
@@ -1193,6 +1221,9 @@
             ])
             # Some systems have broken recursive mutex implementations
             case "$target" in
+                *-*-darwin*)
+                    has_recursive_mutexes=no
+                    ;;
                 *-*-solaris*)
                     has_recursive_mutexes=no
                     ;;
@@ -1253,45 +1284,80 @@
         CFLAGS="$CFLAGS -DHAVE_SEMUN"
     fi
 
-    # See if we can use clone() on Linux directly
-    use_clone=no
+    # See if we can use GNU Pth or clone() on Linux directly
     if test x$enable_threads = xyes -a x$use_pthreads != xyes; then
-        case "$target" in
-            *-*-linux*)
-                use_clone=yes
-                ;;
-            *)
-                CFLAGS="$CFLAGS -DFORK_HACK"
-                ;;
-        esac
+        CheckPTH
+        if test x$use_pth != xyes; then
+            case "$target" in
+                *-*-linux*)
+                    use_clone=yes
+                    ;;
+            esac
+        fi
     fi
 }
 
-dnl See if we can use GNU pth library for threads
-CheckPTH()
+# Note that we need to have either semaphores or to have mutexes and
+# condition variables to implement all thread synchronization primitives
+CopyUnixThreadSource()
 {
-    dnl Check for pth support
-    AC_ARG_ENABLE(pth,
-[  --enable-pth            use GNU pth library for multi-threading [default=yes]],
-                  , enable_pth=yes)
-    if test x$enable_threads = xyes -a x$enable_pth = xyes; then
-        AC_PATH_PROG(PTH_CONFIG, pth-config, no)
-        if test "$PTH_CONFIG" = "no"; then
-            use_pth=no
+    if test x$use_pthreads = xyes -o x$use_clone = xyes; then
+        # Basic thread creation functions
+        COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
+        if test x$use_pthreads != xyes; then
+            COPY_ARCH_SRC(src/thread, linux, clone.S)
+        fi
+        COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
+
+        # Semaphores
+        # We can fake these with mutexes and condition variables if necessary
+        if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then
+            COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
         else
-            PTH_CFLAGS=`$PTH_CONFIG --cflags`
-            PTH_LIBS=`$PTH_CONFIG --libs --all`
-            SDL_CFLAGS="$SDL_CFLAGS $PTH_CFLAGS"
-            SDL_LIBS="$SDL_LIBS $PTH_LIBS"
-            CFLAGS="$CFLAGS -DENABLE_PTH"
-            use_pth=yes
+            COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
         fi
-        AC_MSG_CHECKING(pth)
-        if test "x$use_pth" = xyes; then
-            AC_MSG_RESULT(yes)
+        COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
+
+        # Mutexes
+        # We can fake these with semaphores if necessary
+        case "$target" in
+            *-*-bsdi*)
+                COPY_ARCH_SRC(src/thread, bsdi, SDL_syssem.c)
+                COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
+                ;;
+            *)
+                if test x$glibc20_pthreads = xyes; then
+                    COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex.c)
+                    COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex_c.h)
+                else
+                    COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
+                    COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
+                fi
+                ;;
+        esac
+
+        # Condition variables
+        # We can fake these with semaphores and mutexes if necessary
+        if test x$glibc20_pthreads = xyes -o x$has_recursive_mutexes != xyes; then
+            COPY_ARCH_SRC(src/thread, generic, SDL_syscond.c)
         else
-            AC_MSG_RESULT(no)
+            COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
         fi
+        COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+
+    elif text x$use_pth = xyes; then
+        COPY_ARCH_SRC(src/thread, pth, SDL_systhread.c)
+        COPY_ARCH_SRC(src/thread, pth, SDL_systhread_c.h)
+        COPY_ARCH_SRC(src/thread, pth, SDL_sysmutex.c)
+        COPY_ARCH_SRC(src/thread, pth, SDL_sysmutex_c.h)
+        COPY_ARCH_SRC(src/thread, pth, SDL_syscond.c)
+        COPY_ARCH_SRC(src/thread, pth, SDL_syscond_c.h)
+        COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
+        COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
+    else
+       AC_MSG_ERROR([
+*** No thread support detected
+       ])
     fi
 }
 
@@ -1593,32 +1659,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            if test x$use_pthreads != xyes; then
-                COPY_ARCH_SRC(src/thread, linux, clone.S)
-            fi
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then
-                COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
-            else
-                COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-            fi
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            if test x$glibc20_pthreads = xyes; then
-                COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex.c)
-                COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex_c.h)
-                COPY_ARCH_SRC(src/thread, generic, SDL_syscond.c)
-                COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
-            else
-                COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-                COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-                if test x$has_recursive_mutexes != xyes; then
-                    COPY_ARCH_SRC(src/thread, generic, SDL_syscond.c)
-                else
-                    COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-                fi
-                COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
-            fi
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -1663,14 +1704,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            COPY_ARCH_SRC(src/thread, bsdi, SDL_syssem.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -1711,18 +1745,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then
-                COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
-            else
-                COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-            fi
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -1759,18 +1782,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then
-                COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
-            else
-                COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-            fi
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -1813,18 +1825,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then
-                COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
-            else
-                COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-            fi
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -1868,14 +1869,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, generic, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex_c.h)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -1918,14 +1912,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -1966,19 +1953,8 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            if test x$use_pthreads = xyes; then
-                COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-                COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-                COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-                COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-                if test x$have_pthread_sem != xyes; then
-                    COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
-                else
-                    COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-                fi
-                COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-                COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-                COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            if test x$use_pthreads = xyes -o x$use_pth = xyes; then
+                CopyUnixThreadSource
             else
                 COPY_ARCH_SRC(src/thread, irix, SDL_systhread.c)
                 COPY_ARCH_SRC(src/thread, irix, SDL_systhread_c.h)
@@ -2029,14 +2005,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -2075,14 +2044,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -2122,14 +2084,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -2168,14 +2123,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -2369,18 +2317,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
-            COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
-            if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then
-                COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
-            else
-                COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
-            fi
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then
@@ -2422,23 +2359,7 @@
         fi
         # Set up files for the thread library
         if test x$enable_threads = xyes; then
-            if test x$enable_pth = xyes; then
-                COPY_ARCH_SRC(src/thread, pth, SDL_systhread.c)
-                COPY_ARCH_SRC(src/thread, pth, SDL_systhread_c.h)
-                COPY_ARCH_SRC(src/thread, pth, SDL_sysmutex.c)
-                COPY_ARCH_SRC(src/thread, pth, SDL_sysmutex_c.h)
-                COPY_ARCH_SRC(src/thread, pth, SDL_syscond.c)
-                COPY_ARCH_SRC(src/thread, pth, SDL_syscond_c.h)
-            else
-                COPY_ARCH_SRC(src/thread, generic, SDL_systhread.c)
-                COPY_ARCH_SRC(src/thread, generic, SDL_systhread_c.h)
-                COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex.c)
-                COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex_c.h)
-                COPY_ARCH_SRC(src/thread, generic, SDL_syscond.c)
-                COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
-            fi
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c)
-            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
+            CopyUnixThreadSource
         fi
         # Set up files for the timer library
         if test x$enable_timers = xyes; then