$NetBSD: patch-aj,v 1.12 2002/07/15 23:04:20 kristerw Exp $
--- configure.in.orig	Thu Nov  8 08:28:00 2001
+++ configure.in	Mon Jul 15 23:28:12 2002
@@ -374,10 +374,7 @@
                   , enable_nas=yes)
     if test x$enable_audio = xyes -a x$enable_nas = xyes; then
         AC_MSG_CHECKING(for NAS audio support)
-        have_nas=no
-        if test -r /usr/X11R6/include/audio/audiolib.h; then
             have_nas=yes
-        fi
         AC_MSG_RESULT($have_nas)
         if test x$have_nas = xyes; then
             CFLAGS="$CFLAGS -DNAS_SUPPORT"
@@ -429,7 +426,7 @@
                   NASMFLAGS="-f win32"
                   ;;
               *)
-                  NASMFLAGS="-f elf"
+                  test -n "$NASMFLAGS" || NASMFLAGS="-f elf"
                   ;;
             esac
             AC_SUBST(NASMFLAGS)
@@ -999,8 +996,8 @@
             pthread_lib="-pthread"
             ;;
         *-*-netbsd*)
-            pthread_cflags="-I/usr/pkg/include -D_REENTRANT"
-            pthread_lib="-L/usr/pkg/lib -lpthread -lsem"
+            pthread_cflags="-D_REENTRANT"
+            pthread_lib="-lpthread"
             ;;
         *-*-openbsd*)
             pthread_cflags="-D_REENTRANT"
@@ -1281,6 +1278,126 @@
     VIDEO_DRIVERS="$VIDEO_DRIVERS quartz/libvideo_quartz.la"
 }
 
+dnl Check for the usbhid(3) library on *BSD
+CheckUSBHID()
+{
+    if test x$enable_joystick = xyes; then
+        have_libusbhid=no
+        have_libusb=no
+        AC_CHECK_LIB(usbhid, hid_init, have_libusbhid=yes)
+        if test x$have_libusbhid = xyes; then
+            SYSTEM_LIBS="$SYSTEM_LIBS -lusbhid"
+
+            AC_CHECK_HEADER(usbhid.h, have_usbhid_h=yes)
+            AC_CHECK_HEADER(libusbhid.h, have_libusbhid_h=yes)
+            if test x$have_usbhid_h = xyes; then
+                CFLAGS="$CFLAGS -DHAVE_USBHID_H"
+            fi
+            if test x$have_libusbhid_h = xyes; then
+                CFLAGS="$CFLAGS -DHAVE_LIBUSBHID_H"
+            fi
+	else
+            AC_CHECK_LIB(usb, hid_init, have_libusb=yes)
+            if test x$have_libusb = xyes; then
+                SYSTEM_LIBS="$SYSTEM_LIBS -lusb"
+
+                AC_CHECK_HEADER(usb.h, have_usb_h=yes)
+                AC_CHECK_HEADER(libusb.h, have_libusb_h=yes)
+                if test x$have_usb_h = xyes; then
+                    CFLAGS="$CFLAGS -DHAVE_USB_H"
+                fi
+                if test x$have_libusb_h = xyes; then
+                    CFLAGS="$CFLAGS -DHAVE_LIBUSB_H"
+                fi
+            fi
+        fi
+
+        AC_MSG_CHECKING(for usbhid)
+        have_usbhid=no
+        AC_TRY_COMPILE([
+          #include <sys/types.h>
+          #if defined(HAVE_USB_H)
+          #include <usb.h>
+          #endif
+          #include <dev/usb/usb.h>
+          #include <dev/usb/usbhid.h>
+          #if defined(HAVE_USBHID_H)
+          #include <usbhid.h>
+          #elif defined(HAVE_LIBUSB_H)
+          #include <libusb.h>
+          #elif defined(HAVE_LIBUSBHID_H)
+          #include <libusbhid.h>
+          #endif
+        ],[
+          struct report_desc *repdesc;
+          struct usb_ctl_report *repbuf;
+          hid_kind_t hidkind;
+        ],[
+        have_usbhid=yes
+        ])
+        AC_MSG_RESULT($have_usbhid)
+
+        if test x$have_usbhid = xyes; then
+            AC_MSG_CHECKING(for ucr_data member of usb_ctl_report)
+            have_usbhid_ucr_data=no
+            AC_TRY_COMPILE([
+              #include <sys/types.h>
+              #if defined(HAVE_USB_H)
+              #include <usb.h>
+              #endif
+              #include <dev/usb/usb.h>
+              #include <dev/usb/usbhid.h>
+              #if defined(HAVE_USBHID_H)
+              #include <usbhid.h>
+              #elif defined(HAVE_LIBUSB_H)
+              #include <libusb.h>
+              #elif defined(HAVE_LIBUSBHID_H)
+              #include <libusbhid.h>
+              #endif
+            ],[
+              struct usb_ctl_report buf;
+              if (buf.ucr_data) { }
+            ],[
+            have_usbhid_ucr_data=yes
+            ])
+            if test x$have_usbhid_ucr_data = xyes; then
+                CFLAGS="$CFLAGS -DUSBHID_UCR_DATA"
+            fi
+            AC_MSG_RESULT($have_usbhid_ucr_data)
+            
+	    AC_MSG_CHECKING(for new usbhid API)
+            have_usbhid_new=no
+            AC_TRY_COMPILE([
+              #include <sys/types.h>
+              #if defined(HAVE_USB_H)
+              #include <usb.h>
+              #endif
+              #include <dev/usb/usb.h>
+              #include <dev/usb/usbhid.h>
+              #if defined(HAVE_USBHID_H)
+              #include <usbhid.h>
+              #elif defined(HAVE_LIBUSB_H)
+              #include <libusb.h>
+              #elif defined(HAVE_LIBUSBHID_H)
+              #include <libusbhid.h>
+              #endif
+            ],[
+              report_desc_t d;
+	      hid_start_parse(d, 1, 1);
+            ],[
+            have_usbhid_new=yes
+            ])
+            if test x$have_usbhid_new = xyes; then
+                CFLAGS="$CFLAGS -DUSBHID_NEW"
+            fi
+            AC_MSG_RESULT($have_usbhid_new)
+
+            JOYSTICK_SUBDIRS="$JOYSTICK_SUBDIRS bsd"
+            JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS bsd/libjoystick_bsd.la"
+        fi
+    fi
+}
+
 case "$target" in
     *-*-linux*)
         ARCH=linux
@@ -1465,14 +1582,17 @@
         CheckDummyVideo
         CheckDiskAudio
         CheckNASM
+        CheckOPENBSDAUDIO
         CheckOSS
         CheckARTSC
         CheckESD
         CheckNAS
         CheckX11
+        CheckDGA
         CheckAAlib
         CheckOpenGL
         CheckPTHREAD
+        CheckUSBHID
         # Set up files for the main() stub
         COPY_ARCH_SRC(src/main, linux, SDL_main.c)
         # Set up files for the audio library
@@ -1481,12 +1601,6 @@
             AUDIO_SUBDIRS="$AUDIO_SUBDIRS sun"
             AUDIO_DRIVERS="$AUDIO_DRIVERS sun/libaudio_sun.la"
         fi
-        # Set up files for the joystick library
-        # (No joystick support yet)
-        if test x$enable_joystick = xyes; then
-            JOYSTICK_SUBDIRS="$JOYSTICK_SUBDIRS dummy"
-            JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS dummy/libjoystick_dummy.la"
-        fi
         # Set up files for the cdrom library
         if test x$enable_cdrom = xyes; then
             CDROM_SUBDIRS="$CDROM_SUBDIRS openbsd"
@@ -1770,7 +1884,11 @@
             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$enable_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)
@@ -2159,6 +2277,10 @@
   SDL_RLD_FLAGS="-R\${exec_prefix}/lib"
 fi
 
+if test $ARCH = netbsd; then
+  SDL_RLD_FLAGS="-Wl,-rpath,\${exec_prefix}/lib -Wl,-rpath,${X11BASE}/lib"
+fi
+
 if test $ARCH = openbsd; then
   SDL_RLD_FLAGS="-Wl,-rpath,\${exec_prefix}/lib $SYSTEM_LIBS"
 fi
@@ -2277,6 +2399,7 @@
 src/joystick/Makefile
 src/joystick/amigaos/Makefile
 src/joystick/beos/Makefile
+src/joystick/bsd/Makefile
 src/joystick/darwin/Makefile
 src/joystick/dummy/Makefile
 src/joystick/linux/Makefile
