diff -uNr src/joystick.orig/Makefile.am src/joystick/Makefile.am
--- src/joystick.orig/Makefile.am	Tue Sep 11 16:00:18 2001
+++ src/joystick/Makefile.am	Wed Jan 23 06:52:10 2002
@@ -5,7 +5,7 @@
 
 # Define which subdirectories need to be built
 SUBDIRS = @JOYSTICK_SUBDIRS@
-DIST_SUBDIRS = dummy amigaos beos darwin linux macos win32
+DIST_SUBDIRS = dummy amigaos beos bsd darwin linux macos win32
 
 DRIVERS = @JOYSTICK_DRIVERS@
 
diff -uNr src/joystick.orig/Makefile.in src/joystick/Makefile.in
--- src/joystick.orig/Makefile.in	Thu Nov  8 03:28:06 2001
+++ src/joystick/Makefile.in	Wed Jan 23 07:12:26 2002
@@ -1,6 +1,6 @@
-# Makefile.in generated automatically by automake 1.4 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
 
-# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -113,7 +113,7 @@
 
 # Define which subdirectories need to be built
 SUBDIRS = @JOYSTICK_SUBDIRS@
-DIST_SUBDIRS = dummy amigaos beos darwin linux macos win32
+DIST_SUBDIRS = dummy amigaos beos bsd darwin linux macos win32
 
 DRIVERS = @JOYSTICK_DRIVERS@
 
@@ -149,8 +149,9 @@
 
 DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
 
-TAR = gtar
+TAR = tar
 GZIP_ENV = --best
+DEP_FILES =  .deps/SDL_joystick.P
 SOURCES = $(libjoystick_la_SOURCES)
 OBJECTS = $(libjoystick_la_OBJECTS)
 
@@ -158,9 +159,9 @@
 .SUFFIXES:
 .SUFFIXES: .S .c .lo .o .s
 $(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
-	cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps src/joystick/Makefile
+	cd $(top_srcdir) && $(AUTOMAKE) --gnu src/joystick/Makefile
 
-Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
+Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status $(BUILT_SOURCES)
 	cd $(top_builddir) \
 	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
 
@@ -174,9 +175,6 @@
 
 maintainer-clean-noinstLTLIBRARIES:
 
-.c.o:
-	$(COMPILE) -c $<
-
 .s.o:
 	$(COMPILE) -c $<
 
@@ -193,9 +191,6 @@
 
 maintainer-clean-compile:
 
-.c.lo:
-	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
-
 .s.lo:
 	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
 
@@ -251,7 +246,8 @@
 	dot_seen=no; \
 	rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \
 	  rev="$$subdir $$rev"; \
-	  test "$$subdir" = "." && dot_seen=yes; \
+	  test "$$subdir" != "." || dot_seen=yes; \
+	  true; \
 	done; \
 	test "$$dot_seen" = "no" && rev=". $$rev"; \
 	target=`echo $@ | sed s/-recursive//`; \
@@ -309,10 +305,15 @@
 subdir = src/joystick
 
 distdir: $(DISTFILES)
+	here=`cd $(top_builddir) && pwd`; \
+	top_distdir=`cd $(top_distdir) && pwd`; \
+	distdir=`cd $(distdir) && pwd`; \
+	cd $(top_srcdir) \
+	  && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu src/joystick/Makefile
 	@for file in $(DISTFILES); do \
 	  d=$(srcdir); \
 	  if test -d $$d/$$file; then \
-	    cp -pr $$/$$file $(distdir)/$$file; \
+	    cp -pr $$d/$$file $(distdir)/$$file; \
 	  else \
 	    test -f $(distdir)/$$file \
 	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
@@ -329,6 +330,38 @@
 	      || exit 1; \
 	  fi; \
 	done
+
+DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
+
+-include $(DEP_FILES)
+
+mostlyclean-depend:
+
+clean-depend:
+
+distclean-depend:
+	-rm -rf .deps
+
+maintainer-clean-depend:
+
+%.o: %.c
+	@echo '$(COMPILE) -c $<'; \
+	$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
+	@-cp .deps/$(*F).pp .deps/$(*F).P; \
+	tr ' ' '\012' < .deps/$(*F).pp \
+	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
+	    >> .deps/$(*F).P; \
+	rm .deps/$(*F).pp
+
+%.lo: %.c
+	@echo '$(LTCOMPILE) -c $<'; \
+	$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
+	@-sed -e 's/^\([^:]*\)\.o[ 	]*:/\1.lo \1.o :/' \
+	  < .deps/$(*F).pp > .deps/$(*F).P; \
+	tr ' ' '\012' < .deps/$(*F).pp \
+	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
+	    >> .deps/$(*F).P; \
+	rm -f .deps/$(*F).pp
 info-am:
 info: info-recursive
 dvi-am:
@@ -366,27 +399,27 @@
 
 maintainer-clean-generic:
 mostlyclean-am:  mostlyclean-noinstLTLIBRARIES mostlyclean-compile \
-		mostlyclean-libtool mostlyclean-tags \
+		mostlyclean-libtool mostlyclean-tags mostlyclean-depend \
 		mostlyclean-generic
 
 mostlyclean: mostlyclean-recursive
 
 clean-am:  clean-noinstLTLIBRARIES clean-compile clean-libtool \
-		clean-tags clean-generic mostlyclean-am
+		clean-tags clean-depend clean-generic mostlyclean-am
 
 clean: clean-recursive
 
 distclean-am:  distclean-noinstLTLIBRARIES distclean-compile \
-		distclean-libtool distclean-tags distclean-generic \
-		clean-am
+		distclean-libtool distclean-tags distclean-depend \
+		distclean-generic clean-am
 	-rm -f libtool
 
 distclean: distclean-recursive
 
 maintainer-clean-am:  maintainer-clean-noinstLTLIBRARIES \
 		maintainer-clean-compile maintainer-clean-libtool \
-		maintainer-clean-tags maintainer-clean-generic \
-		distclean-am
+		maintainer-clean-tags maintainer-clean-depend \
+		maintainer-clean-generic distclean-am
 	@echo "This command is intended for maintainers to use;"
 	@echo "it deletes files that may require special tools to rebuild."
 
@@ -402,12 +435,14 @@
 all-recursive check-recursive installcheck-recursive info-recursive \
 dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \
 maintainer-clean-recursive tags tags-recursive mostlyclean-tags \
-distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
-dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
-install-exec install-data-am install-data install-am install \
-uninstall-am uninstall all-redirect all-am all installdirs-am \
-installdirs mostlyclean-generic distclean-generic clean-generic \
-maintainer-clean-generic clean mostlyclean distclean maintainer-clean
+distclean-tags clean-tags maintainer-clean-tags distdir \
+mostlyclean-depend distclean-depend clean-depend \
+maintainer-clean-depend info-am info dvi-am dvi check check-am \
+installcheck-am installcheck install-exec-am install-exec \
+install-data-am install-data install-am install uninstall-am uninstall \
+all-redirect all-am all installdirs-am installdirs mostlyclean-generic \
+distclean-generic clean-generic maintainer-clean-generic clean \
+mostlyclean distclean maintainer-clean
 
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
Binary files src/joystick.orig/bsd/.SDL_sysjoystick.c.swo and src/joystick/bsd/.SDL_sysjoystick.c.swo differ
Binary files src/joystick.orig/bsd/.SDL_sysjoystick.c.swp and src/joystick/bsd/.SDL_sysjoystick.c.swp differ
diff -uNr src/joystick.orig/bsd/Makefile.am src/joystick/bsd/Makefile.am
--- src/joystick.orig/bsd/Makefile.am	Wed Dec 31 20:00:00 1969
+++ src/joystick/bsd/Makefile.am	Wed Jan 23 06:52:10 2002
@@ -0,0 +1,8 @@
+
+## Makefile.am for the BSD joystick driver for SDL
+
+noinst_LTLIBRARIES = libjoystick_bsd.la
+libjoystick_bsd_la_SOURCES = $(SRCS)
+
+# The SDL joystick driver sources
+SRCS =  SDL_sysjoystick.c
diff -uNr src/joystick.orig/bsd/Makefile.in src/joystick/bsd/Makefile.in
--- src/joystick.orig/bsd/Makefile.in	Wed Dec 31 20:00:00 1969
+++ src/joystick/bsd/Makefile.in	Wed Jan 23 07:12:26 2002
@@ -0,0 +1,364 @@
+# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+
+# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+
+DESTDIR =
+
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+
+top_builddir = ../../..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+transform = @program_transform_name@
+
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+host_alias = @host_alias@
+host_triplet = @host@
+ARCH = @ARCH@
+ARTSCCONFIG = @ARTSCCONFIG@
+AS = @AS@
+AUDIO_DRIVERS = @AUDIO_DRIVERS@
+AUDIO_SUBDIRS = @AUDIO_SUBDIRS@
+CC = @CC@
+CDROM_DRIVERS = @CDROM_DRIVERS@
+CDROM_SUBDIRS = @CDROM_SUBDIRS@
+CXX = @CXX@
+DIRECTFB_CFLAGS = @DIRECTFB_CFLAGS@
+DIRECTFB_LIBS = @DIRECTFB_LIBS@
+DLLTOOL = @DLLTOOL@
+ESD_CFLAGS = @ESD_CFLAGS@
+ESD_CONFIG = @ESD_CONFIG@
+ESD_LIBS = @ESD_LIBS@
+JOYSTICK_DRIVERS = @JOYSTICK_DRIVERS@
+JOYSTICK_SUBDIRS = @JOYSTICK_SUBDIRS@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_RELEASE = @LT_RELEASE@
+LT_REVISION = @LT_REVISION@
+MAKEINFO = @MAKEINFO@
+NASM = @NASM@
+NASMFLAGS = @NASMFLAGS@
+OBJC = @OBJC@
+OBJCDEPMODE = @OBJCDEPMODE@
+OBJCFLAGS = @OBJCFLAGS@
+OBJDUMP = @OBJDUMP@
+PACKAGE = @PACKAGE@
+PKG_CONFIG = @PKG_CONFIG@
+PTH_CONFIG = @PTH_CONFIG@
+RANLIB = @RANLIB@
+SDL_BINARY_AGE = @SDL_BINARY_AGE@
+SDL_CFLAGS = @SDL_CFLAGS@
+SDL_EXTRADIRS = @SDL_EXTRADIRS@
+SDL_EXTRALIBS = @SDL_EXTRALIBS@
+SDL_INTERFACE_AGE = @SDL_INTERFACE_AGE@
+SDL_LIBS = @SDL_LIBS@
+SDL_MAJOR_VERSION = @SDL_MAJOR_VERSION@
+SDL_MICRO_VERSION = @SDL_MICRO_VERSION@
+SDL_MINOR_VERSION = @SDL_MINOR_VERSION@
+SDL_RLD_FLAGS = @SDL_RLD_FLAGS@
+SDL_VERSION = @SDL_VERSION@
+SYSTEM_LIBS = @SYSTEM_LIBS@
+VERSION = @VERSION@
+VIDEO_DRIVERS = @VIDEO_DRIVERS@
+VIDEO_SUBDIRS = @VIDEO_SUBDIRS@
+
+noinst_LTLIBRARIES = libjoystick_bsd.la
+libjoystick_bsd_la_SOURCES = $(SRCS)
+
+# The SDL joystick driver sources
+SRCS = SDL_sysjoystick.c
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_CLEAN_FILES = 
+LTLIBRARIES =  $(noinst_LTLIBRARIES)
+
+
+DEFS = @DEFS@ -I. -I$(srcdir) 
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+X_CFLAGS = @X_CFLAGS@
+X_LIBS = @X_LIBS@
+X_EXTRA_LIBS = @X_EXTRA_LIBS@
+X_PRE_LIBS = @X_PRE_LIBS@
+libjoystick_bsd_la_LDFLAGS = 
+libjoystick_bsd_la_LIBADD = 
+libjoystick_bsd_la_OBJECTS =  SDL_sysjoystick.lo
+CFLAGS = @CFLAGS@
+COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
+DIST_COMMON =  Makefile.am Makefile.in
+
+
+DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
+
+TAR = tar
+GZIP_ENV = --best
+DEP_FILES =  .deps/SDL_sysjoystick.P
+SOURCES = $(libjoystick_bsd_la_SOURCES)
+OBJECTS = $(libjoystick_bsd_la_OBJECTS)
+
+all: all-redirect
+.SUFFIXES:
+.SUFFIXES: .S .c .lo .o .s
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
+	cd $(top_srcdir) && $(AUTOMAKE) --gnu src/joystick/bsd/Makefile
+
+Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status $(BUILT_SOURCES)
+	cd $(top_builddir) \
+	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+
+mostlyclean-noinstLTLIBRARIES:
+
+clean-noinstLTLIBRARIES:
+	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+
+distclean-noinstLTLIBRARIES:
+
+maintainer-clean-noinstLTLIBRARIES:
+
+.s.o:
+	$(COMPILE) -c $<
+
+.S.o:
+	$(COMPILE) -c $<
+
+mostlyclean-compile:
+	-rm -f *.o core *.core
+
+clean-compile:
+
+distclean-compile:
+	-rm -f *.tab.c
+
+maintainer-clean-compile:
+
+.s.lo:
+	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
+
+.S.lo:
+	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+distclean-libtool:
+
+maintainer-clean-libtool:
+
+libjoystick_bsd.la: $(libjoystick_bsd_la_OBJECTS) $(libjoystick_bsd_la_DEPENDENCIES)
+	$(LINK)  $(libjoystick_bsd_la_LDFLAGS) $(libjoystick_bsd_la_OBJECTS) $(libjoystick_bsd_la_LIBADD) $(LIBS)
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP)
+	list='$(SOURCES) $(HEADERS)'; \
+	unique=`for i in $$list; do echo $$i; done | \
+	  awk '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	here=`pwd` && cd $(srcdir) \
+	  && mkid -f$$here/ID $$unique $(LISP)
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) $(LISP)
+	tags=; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)'; \
+	unique=`for i in $$list; do echo $$i; done | \
+	  awk '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
+	  || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags  $$unique $(LISP) -o $$here/TAGS)
+
+mostlyclean-tags:
+
+clean-tags:
+
+distclean-tags:
+	-rm -f TAGS ID
+
+maintainer-clean-tags:
+
+distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+
+subdir = src/joystick/bsd
+
+distdir: $(DISTFILES)
+	here=`cd $(top_builddir) && pwd`; \
+	top_distdir=`cd $(top_distdir) && pwd`; \
+	distdir=`cd $(distdir) && pwd`; \
+	cd $(top_srcdir) \
+	  && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu src/joystick/bsd/Makefile
+	@for file in $(DISTFILES); do \
+	  d=$(srcdir); \
+	  if test -d $$d/$$file; then \
+	    cp -pr $$d/$$file $(distdir)/$$file; \
+	  else \
+	    test -f $(distdir)/$$file \
+	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+	    || cp -p $$d/$$file $(distdir)/$$file || :; \
+	  fi; \
+	done
+
+DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
+
+-include $(DEP_FILES)
+
+mostlyclean-depend:
+
+clean-depend:
+
+distclean-depend:
+	-rm -rf .deps
+
+maintainer-clean-depend:
+
+%.o: %.c
+	@echo '$(COMPILE) -c $<'; \
+	$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
+	@-cp .deps/$(*F).pp .deps/$(*F).P; \
+	tr ' ' '\012' < .deps/$(*F).pp \
+	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
+	    >> .deps/$(*F).P; \
+	rm .deps/$(*F).pp
+
+%.lo: %.c
+	@echo '$(LTCOMPILE) -c $<'; \
+	$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
+	@-sed -e 's/^\([^:]*\)\.o[ 	]*:/\1.lo \1.o :/' \
+	  < .deps/$(*F).pp > .deps/$(*F).P; \
+	tr ' ' '\012' < .deps/$(*F).pp \
+	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
+	    >> .deps/$(*F).P; \
+	rm -f .deps/$(*F).pp
+info-am:
+info: info-am
+dvi-am:
+dvi: dvi-am
+check-am: all-am
+check: check-am
+installcheck-am:
+installcheck: installcheck-am
+install-exec-am:
+install-exec: install-exec-am
+
+install-data-am:
+install-data: install-data-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+install: install-am
+uninstall-am:
+uninstall: uninstall-am
+all-am: Makefile $(LTLIBRARIES)
+all-redirect: all-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
+installdirs:
+
+
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-rm -f Makefile $(CONFIG_CLEAN_FILES)
+	-rm -f config.cache config.log stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+mostlyclean-am:  mostlyclean-noinstLTLIBRARIES mostlyclean-compile \
+		mostlyclean-libtool mostlyclean-tags mostlyclean-depend \
+		mostlyclean-generic
+
+mostlyclean: mostlyclean-am
+
+clean-am:  clean-noinstLTLIBRARIES clean-compile clean-libtool \
+		clean-tags clean-depend clean-generic mostlyclean-am
+
+clean: clean-am
+
+distclean-am:  distclean-noinstLTLIBRARIES distclean-compile \
+		distclean-libtool distclean-tags distclean-depend \
+		distclean-generic clean-am
+	-rm -f libtool
+
+distclean: distclean-am
+
+maintainer-clean-am:  maintainer-clean-noinstLTLIBRARIES \
+		maintainer-clean-compile maintainer-clean-libtool \
+		maintainer-clean-tags maintainer-clean-depend \
+		maintainer-clean-generic distclean-am
+	@echo "This command is intended for maintainers to use;"
+	@echo "it deletes files that may require special tools to rebuild."
+
+maintainer-clean: maintainer-clean-am
+
+.PHONY: mostlyclean-noinstLTLIBRARIES distclean-noinstLTLIBRARIES \
+clean-noinstLTLIBRARIES maintainer-clean-noinstLTLIBRARIES \
+mostlyclean-compile distclean-compile clean-compile \
+maintainer-clean-compile mostlyclean-libtool distclean-libtool \
+clean-libtool maintainer-clean-libtool tags mostlyclean-tags \
+distclean-tags clean-tags maintainer-clean-tags distdir \
+mostlyclean-depend distclean-depend clean-depend \
+maintainer-clean-depend info-am info dvi-am dvi check check-am \
+installcheck-am installcheck install-exec-am install-exec \
+install-data-am install-data install-am install uninstall-am uninstall \
+all-redirect all-am all installdirs mostlyclean-generic \
+distclean-generic clean-generic maintainer-clean-generic clean \
+mostlyclean distclean maintainer-clean
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff -uNr src/joystick.orig/bsd/SDL_sysjoystick.c src/joystick/bsd/SDL_sysjoystick.c
--- src/joystick.orig/bsd/SDL_sysjoystick.c	Wed Dec 31 20:00:00 1969
+++ src/joystick/bsd/SDL_sysjoystick.c	Wed Jan 23 17:05:30 2002
@@ -0,0 +1,388 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Sam Lantinga
+    slouken@devolution.com
+*/
+
+/*
+ * Joystick driver for the uhid(4) interface found in OpenBSD,
+ * NetBSD and FreeBSD.
+ *
+ * Maintainer: <vedge at csoft.org>
+ */
+
+#ifdef SAVE_RCSID
+static char rcsid =
+ "@(#) $Id $";
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+#include <usbhid.h>
+
+#include "SDL_error.h"
+#include "SDL_joystick.h"
+#include "SDL_sysjoystick.h"
+#include "SDL_joystick_c.h"
+
+#define MAX_UHID_JOYS	4
+#define MAX_JOY_JOYS	2
+#define MAX_JOYS	(MAX_UHID_JOYS + MAX_JOY_JOYS)
+
+#define SDLAXIS_UINT8(v)		\
+	((v == 127) ? 0 :		\
+	 (v == 255) ? 32767 :		\
+	 -32767)
+
+struct report {
+	struct	usb_ctl_report *buf;	/* Buffer */
+	size_t	size;			/* Buffer size */
+	int	rid;			/* Report ID */
+	enum {
+		SREPORT_UNINIT,
+		SREPORT_CLEAN,
+		SREPORT_DIRTY
+	} status;
+};
+
+static struct {
+	int	uhid_report;
+	enum	hid_kind kind;
+	const	char *name;
+} const repinfo[] = {
+	{ UHID_INPUT_REPORT,	hid_input,	"input" },
+	{ UHID_OUTPUT_REPORT,	hid_output,	"output" },
+	{ UHID_FEATURE_REPORT,	hid_feature,	"feature" }
+};
+#define REPORT_INPUT	0
+#define REPORT_OUTPUT	1
+#define REPORT_FEATURE	2
+
+struct joystick_hwdata {
+	int	fd;
+	char	*path;
+	enum {
+		BSDJOY_UHID,	/* uhid(4) */
+		BSDJOY_JOY	/* joy(4) */
+	} type;
+	struct	report_desc *repdesc;
+	struct	report inreport;
+	int	axismin[3];
+	int	axismax[3];
+};
+
+static char *joynames[MAX_JOYS];
+static char *joydevnames[MAX_JOYS];
+
+static int	report_alloc(struct report *, struct report_desc *, int);
+static void	report_free(struct report *);
+
+int
+SDL_SYS_JoystickInit(void)
+{
+	char s[10];
+	int i, fd;
+
+	SDL_numjoysticks = 0;
+
+	memset(joynames, NULL, sizeof(joynames));
+	memset(joydevnames, NULL, sizeof(joydevnames));
+
+	for (i = 0; i < MAX_UHID_JOYS; i++) {
+		sprintf(s, "/dev/uhid%d", i);
+		fd = open(s, O_RDWR);
+		if (fd > 0) {
+			joynames[SDL_numjoysticks++] = strdup(s);
+			close(fd);
+		}
+	}
+	for (i = 0; i < MAX_JOY_JOYS; i++) {
+		sprintf(s, "/dev/joy%d", i);
+		fd = open(s, O_RDWR);
+		if (fd > 0) {
+			joynames[SDL_numjoysticks++] = strdup(s);
+			close(fd);
+		}
+	}
+
+	/* Read the default USB HID usage table. */
+	hid_init(NULL);
+
+	return (SDL_numjoysticks);
+}
+
+const char *
+SDL_SYS_JoystickName(int index)
+{
+	if (joydevnames[index] != NULL) {
+		return (joydevnames[index]);
+	}
+	return (joynames[index]);
+}
+
+int
+SDL_SYS_JoystickOpen(SDL_Joystick *joy)
+{
+	char *path = joynames[joy->index];
+	struct joystick_hwdata *hw;
+	struct hid_item hitem;
+	struct hid_data *hdata;
+	struct report *rep;
+	int fd;
+
+	fd = open(path, O_RDWR);
+	if (fd < 0) {
+		SDL_SetError("%s: %s", path, strerror(errno));
+		return (-1);
+	}
+
+	hw = (struct joystick_hwdata *)malloc(sizeof(struct joystick_hwdata));
+	if (hw == NULL) {
+		SDL_OutOfMemory();
+		close(fd);
+		return (-1);
+	}
+	joy->hwdata = hw;
+	hw->fd = fd;
+	hw->path = strdup(path);
+	hw->type = BSDJOY_UHID;
+	hw->repdesc = hid_get_report_desc(fd);
+	if (hw->repdesc == NULL) {
+		SDL_SetError("%s: USB_GET_REPORT_DESC: %s", hw->path,
+		    strerror(errno));
+		goto usberr;
+	}
+
+	rep = &hw->inreport;
+	if (report_alloc(rep, hw->repdesc, REPORT_INPUT) < 0) {
+		goto usberr;
+	}
+	if (rep->size <= 0) {
+		SDL_SetError("Input report descriptor has invalid length");
+		goto usberr;
+	}
+
+	hdata = hid_start_parse(hw->repdesc, 1 << hid_input);
+	if (hdata == NULL) {
+		SDL_SetError("%s: Cannot start HID parser", hw->path);
+		goto usberr;
+	}
+	joy->naxes = 0;
+	joy->nbuttons = 0;
+	joy->nhats = 0;
+	joy->nballs = 0;
+
+	while (hid_get_item(hdata, &hitem) > 0) {
+		char *s, *sp;
+
+		switch (hitem.kind) {
+		case hid_collection:
+			switch (HID_PAGE(hitem.usage)) {
+			case HUP_GENERIC_DESKTOP:
+				switch (HID_USAGE(hitem.usage)) {
+				case HUG_JOYSTICK:
+				case HUG_GAME_PAD:
+					s = hid_usage_in_page(hitem.usage);
+					sp = malloc(strlen(s) + 5);
+					sprintf(sp, "%s (%d)", s,
+					    joy->index);
+					joydevnames[joy->index] = sp;
+				}
+			}
+			break;
+		case hid_input:
+			switch (HID_PAGE(hitem.usage)) {
+			case HUP_UNDEFINED:
+				break;
+			case HUP_GENERIC_DESKTOP:
+				switch (HID_USAGE(hitem.usage)) {
+				case HUG_X:
+				case HUG_Y:
+				case HUG_Z:
+					hw->axismin[joy->naxes] =
+					    hitem.logical_minimum;
+					hw->axismax[joy->naxes] =
+					    hitem.logical_maximum;
+					joy->naxes++;
+					break;
+				}
+				break;
+			case HUP_BUTTON:
+				joy->nbuttons++;
+				break;
+			}
+			break;
+		default:
+			break;
+		}
+	}
+	hid_end_parse(hdata);
+
+	/* The poll blocks the event thread. */
+	fcntl(fd, F_SETFL, O_NONBLOCK);
+
+	return (0);
+usberr:
+	close(hw->fd);
+	free(hw->path);
+	free(hw);
+	return (-1);
+}
+
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick *joy)
+{
+	static struct hid_item hitem;
+	static struct hid_data *hdata;
+	static int nbutton, naxe, v, max, min;
+	static struct report *rep;
+	
+	rep = &joy->hwdata->inreport;
+	if (read(joy->hwdata->fd, rep->buf->data, rep->size) != rep->size) {
+		return;
+	}
+	hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input);
+	if (hdata == NULL) {
+		fprintf(stderr, "%s: Cannot start HID parser\n",
+		    joy->hwdata->path);
+		return;
+	}
+
+	for (nbutton = 0, naxe = 0; hid_get_item(hdata, &hitem) > 0;) {
+		switch (hitem.kind) {
+		case hid_input:
+			switch (HID_PAGE(hitem.usage)) {
+			case HUP_UNDEFINED:
+				continue;
+			case HUP_GENERIC_DESKTOP:
+				switch (HID_USAGE(hitem.usage)) {
+				case HUG_X:
+				case HUG_Y:
+				case HUG_Z:
+					v = hid_get_data(rep->buf->data,
+					    &hitem);
+
+					/*
+					 * XXX revisit later. need to test
+					 * with more devices.
+					 */
+					if (joy->hwdata->axismin[naxe] == 0 &&
+					    joy->hwdata->axismax[naxe] == 255) {
+						v = SDLAXIS_UINT8(v);
+					}
+
+					if (v != joy->axes[naxe]) {
+						SDL_PrivateJoystickAxis(joy,
+						    naxe, (Sint32)v);
+					}
+					naxe++;
+					break;
+				}
+				break;
+			case HUP_BUTTON:
+				/* XXX assume a 0..1 range */
+				v = hid_get_data(rep->buf->data, &hitem);
+				if (joy->buttons[nbutton] != v) {
+					SDL_PrivateJoystickButton(joy,
+					    nbutton, v);
+				}
+				nbutton++;
+				break;
+			}
+			break;
+		default:
+			break;
+		}
+	}
+	hid_end_parse(hdata);
+
+	return;
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick *joy)
+{
+	report_free(&joy->hwdata->inreport);
+	hid_dispose_report_desc(joy->hwdata->repdesc);
+	close(joy->hwdata->fd);
+	free(joy->hwdata->path);
+	free(joy->hwdata);
+
+	return;
+}
+
+void
+SDL_SYS_JoystickQuit(void)
+{
+	int i;
+
+	for (i = 0; i < MAX_JOYS; i++) {
+		if (joynames[i] != NULL)
+			free(joynames[i]);
+		if (joydevnames[i] != NULL)
+			free(joydevnames[i]);
+	}
+
+	return;
+}
+
+static int
+report_alloc(struct report *r, struct report_desc *rd, int repind)
+{
+	int len;
+
+	len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
+	if (len < 0) {
+		SDL_SetError("Negative HID report size");
+		return (-1);
+	}
+	r->size = len;
+
+	if (r->size > 0) {
+		r->buf = malloc(sizeof(*r->buf) - sizeof(r->buf->data) +
+		    r->size);
+		if (r->buf == NULL) {
+			SDL_OutOfMemory();
+			return (-1);
+		}
+	} else {
+		r->buf = NULL;
+	}
+
+	r->status = SREPORT_CLEAN;
+	return (0);
+}
+
+static void
+report_free(struct report *r)
+{
+	if (r->buf != NULL) {
+		free(r->buf);
+	}
+	r->status = SREPORT_UNINIT;
+}
+
