summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'media-libs/freeglut')
-rw-r--r--media-libs/freeglut/files/freeglut-3.0.0-bsd-usb-joystick.patch753
-rw-r--r--media-libs/freeglut/freeglut-3.0.0.ebuild1
2 files changed, 754 insertions, 0 deletions
diff --git a/media-libs/freeglut/files/freeglut-3.0.0-bsd-usb-joystick.patch b/media-libs/freeglut/files/freeglut-3.0.0-bsd-usb-joystick.patch
new file mode 100644
index 000000000000..505b3467ec46
--- /dev/null
+++ b/media-libs/freeglut/files/freeglut-3.0.0-bsd-usb-joystick.patch
@@ -0,0 +1,753 @@
+From 5908c36a4a3964cdc8db5c7bfdfd4381ec0996df Mon Sep 17 00:00:00 2001
+From: dcnieho <dcnieho@7f0cb862-5218-0410-a997-914c9d46530a>
+Date: Wed, 12 Jul 2017 20:44:35 +0000
+Subject: [PATCH] Fix build on NetBSD.
+
+(cherry picked from commit 06e1d815cf9abda49b845754ff420734446eb95b)
+
+(cherry picked from commit c4294ad59093c27159ea6028d33e3c9581df5354)
+
+git-svn-id: http://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1829 7f0cb862-5218-0410-a997-914c9d46530a
+---
+ src/fg_joystick.c | 5 ++---
+ src/x11/fg_joystick_x11.c | 10 +++++-----
+ 2 files changed, 7 insertions(+), 8 deletions(-)
+
+diff --git a/src/fg_joystick.c b/src/fg_joystick.c
+index 6f6771c..b73d7e7 100644
+--- a/src/fg_joystick.c
++++ b/src/fg_joystick.c
+@@ -46,21 +46,20 @@
+
+ # ifdef HAVE_USB_JS
+ # if defined(__NetBSD__)
+-/* XXX The below hack is done until freeglut's autoconf is updated. */
+-# define HAVE_USBHID_H 1
+ # ifdef HAVE_USBHID_H
+ # include <usbhid.h>
+ # else
+ # include <usb.h>
+ # endif
++# include <dev/usb/usb.h>
+ # elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ # ifdef HAVE_USBHID_H
+ # include <usbhid.h>
+ # else
+ # include <libusbhid.h>
+ # endif
++# include <legacy/dev/usb/usb.h>
+ # endif
+-# include <legacy/dev/usb/usb.h>
+ # include <dev/usb/usbhid.h>
+
+ /* Compatibility with older usb.h revisions */
+diff --git a/src/x11/fg_joystick_x11.c b/src/x11/fg_joystick_x11.c
+index a37388b..04bc373 100644
+--- a/src/x11/fg_joystick_x11.c
++++ b/src/x11/fg_joystick_x11.c
+@@ -50,7 +50,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
+ {
+ int status;
+
+-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ int len;
+
+ if ( joy->pJoystick.os->is_analog )
+@@ -215,7 +215,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
+
+ void fgPlatformJoystickOpen( SFG_Joystick* joy )
+ {
+-#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )
++#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__)
+ int i = 0;
+ char *cp;
+ #endif
+@@ -229,7 +229,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
+ # endif
+ #endif
+
+-#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )
++#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__)
+ for( i = 0; i < _JS_MAX_AXES; i++ )
+ joy->pJoystick.os->cache_axes[ i ] = 0.0f;
+
+@@ -409,7 +409,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
+
+ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
+ {
+-#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )
++#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__)
+ fgJoystick[ ident ]->id = ident;
+ fgJoystick[ ident ]->error = GL_FALSE;
+
+@@ -436,7 +436,7 @@ void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )
+
+ void fgPlatformJoystickClose ( int ident )
+ {
+-#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )
++#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__)
+ if( fgJoystick[ident]->pJoystick.os )
+ {
+ if( ! fgJoystick[ ident ]->error )
+--
+2.19.2
+
+From c0f0f1e0903a5dd848825db0fe1f01d5db37c4e1 Mon Sep 17 00:00:00 2001
+From: dcnieho <dcnieho@7f0cb862-5218-0410-a997-914c9d46530a>
+Date: Wed, 12 Jul 2017 20:44:47 +0000
+Subject: [PATCH] some whitespace cleanup
+
+(cherry picked from commit 2dd5aa4aa1b5c19392f9abd00e0f6893907df205)
+
+git-svn-id: http://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1830 7f0cb862-5218-0410-a997-914c9d46530a
+---
+ src/fg_init.c | 32 ++--
+ src/fg_joystick.c | 8 +-
+ src/fg_main.c | 14 +-
+ src/freeglutdll.def.in | 312 +++++++++++++++++-----------------
+ src/mswin/fg_joystick_mswin.c | 2 +-
+ src/mswin/fg_main_mswin.c | 160 ++++++++---------
+ 6 files changed, 264 insertions(+), 264 deletions(-)
+
+diff --git a/src/fg_joystick.c b/src/fg_joystick.c
+index b73d7e7..2f4f6ed 100644
+--- a/src/fg_joystick.c
++++ b/src/fg_joystick.c
+@@ -581,7 +581,7 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
+
+ void fgPlatformJoystickOpen( SFG_Joystick* joy )
+ {
+- int i = 0;
++ int i = 0;
+ OSStatus err;
+
+ /* XXX FIXME: get joystick name in Mac */
+@@ -856,7 +856,7 @@ static void fghJoystickOpen( SFG_Joystick* joy )
+ joy->num_axes = joy->num_buttons = 0;
+ joy->name[ 0 ] = '\0';
+
+- fgPlatformJoystickOpen ( joy );
++ fgPlatformJoystickOpen ( joy );
+
+ }
+
+@@ -878,7 +878,7 @@ static void fghJoystickInit( int ident )
+ fgJoystick[ ident ]->num_axes = fgJoystick[ ident ]->num_buttons = 0;
+ fgJoystick[ ident ]->error = GL_TRUE;
+
+- fgPlatformJoystickInit( fgJoystick, ident );
++ fgPlatformJoystickInit( fgJoystick, ident );
+
+ fghJoystickOpen( fgJoystick[ ident ] );
+ }
+@@ -906,7 +906,7 @@ void fgJoystickClose( void )
+ {
+ if( fgJoystick[ ident ] )
+ {
+- fgPlatformJoystickClose ( ident );
++ fgPlatformJoystickClose ( ident );
+
+ free( fgJoystick[ ident ] );
+ fgJoystick[ ident ] = NULL;
+--
+2.19.2
+
+From 6096caf2468ad4557968b9156ea9fcab2efb3fd1 Mon Sep 17 00:00:00 2001
+From: dcnieho <dcnieho@7f0cb862-5218-0410-a997-914c9d46530a>
+Date: Wed, 12 Jul 2017 20:45:07 +0000
+Subject: [PATCH] moved static variables and functions that should not have
+ stuck behind in fg_joystick.c, but should have been in fg_joystick_x11.c
+
+(cherry picked from commit 0d98472817921dc95d070f13bba59b72d792a7b2)
+
+git-svn-id: http://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1832 7f0cb862-5218-0410-a997-914c9d46530a
+---
+ src/fg_joystick.c | 173 ----------------------------------
+ src/x11/fg_joystick_x11.c | 190 +++++++++++++++++++++++++++++++++++++-
+ 2 files changed, 185 insertions(+), 178 deletions(-)
+
+diff --git a/src/fg_joystick.c b/src/fg_joystick.c
+index 2f4f6ed..e548c04 100644
+--- a/src/fg_joystick.c
++++ b/src/fg_joystick.c
+@@ -68,8 +68,6 @@
+ # endif
+ # endif
+
+-static int hatmap_x[9] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 };
+-static int hatmap_y[9] = { 0, 1, 1, 0, -1, -1, -1, 0, 1 };
+ struct os_specific_s {
+ char fname [128 ];
+ int fd;
+@@ -98,178 +96,7 @@ struct os_specific_s {
+ # define UHIDDEV "/dev/uhid"
+ # define AJSDEV "/dev/joy"
+
+-# ifdef HAVE_USB_JS
+-/*
+- * fghJoystickFindUSBdev (and its helper, fghJoystickWalkUSBdev) try to locate
+- * the full name of a USB device. If /dev/usbN isn't readable, we punt and
+- * return the uhidN device name. We warn the user of this situation once.
+- */
+-static char *fghJoystickWalkUSBdev(int f, char *dev, char *out, int outlen)
+-{
+- struct usb_device_info di;
+- int i, a;
+- char *cp;
+-
+- for (a = 1; a < USB_MAX_DEVICES; a++) {
+- di.udi_addr = a;
+- if (ioctl(f, USB_DEVICEINFO, &di) != 0)
+- return NULL;
+- for (i = 0; i < USB_MAX_DEVNAMES; i++)
+- if (di.udi_devnames[i][0] &&
+- strcmp(di.udi_devnames[i], dev) == 0) {
+- cp = calloc( 1, strlen(di.udi_vendor) + strlen(di.udi_product) + 2);
+- strcpy(cp, di.udi_vendor);
+- strcat(cp, " ");
+- strcat(cp, di.udi_product);
+- strncpy(out, cp, outlen - 1);
+- out[outlen - 1] = 0;
+- free( cp );
+- return out;
+- }
+- }
+- return NULL;
+-}
+-
+-static int fghJoystickFindUSBdev(char *name, char *out, int outlen)
+-{
+- int i, f;
+- char buf[50];
+- char *cp;
+- static int protection_warned = 0;
+-
+- for (i = 0; i < 16; i++) {
+- snprintf(buf, sizeof(buf), "%s%d", USBDEV, i);
+- f = open(buf, O_RDONLY);
+- if (f >= 0) {
+- cp = fghJoystickWalkUSBdev(f, name, out, outlen);
+- close(f);
+- if (cp)
+- return 1;
+- }
+- else if (errno == EACCES) {
+- if (!protection_warned) {
+- fgWarning ( "Can't open %s for read!", buf );
+- protection_warned = 1;
+- }
+- }
+- }
+- return 0;
+-}
+
+-static int fghJoystickInitializeHID(struct os_specific_s *os,
+- int *num_axes, int *num_buttons)
+-{
+- int size, is_joystick;
+-# ifdef HAVE_USBHID_H
+- int report_id = 0;
+-# endif
+- struct hid_data *d;
+- struct hid_item h;
+- report_desc_t rd;
+-
+- if ( ( rd = hid_get_report_desc( os->fd ) ) == 0 )
+- {
+- fgWarning ( "error: %s: %s", os->fname, strerror( errno ) );
+- return FALSE;
+- }
+-
+- os->hids = NULL;
+-
+-# ifdef HAVE_USBHID_H
+- if( ioctl( os->fd, USB_GET_REPORT_ID, &report_id ) < 0)
+- {
+- /*** XXX {report_id} may not be the right variable? ***/
+- fgWarning ( "error: %s%d: %s", UHIDDEV, report_id, strerror( errno ) );
+- return FALSE;
+- }
+-
+- size = hid_report_size( rd, hid_input, report_id );
+-# else
+- size = hid_report_size( rd, 0, hid_input );
+-# endif
+- os->hid_data_buf = calloc( 1, size );
+- os->hid_dlen = size;
+-
+- is_joystick = 0;
+-# ifdef HAVE_USBHID_H
+- d = hid_start_parse( rd, 1 << hid_input, report_id );
+-# else
+- d = hid_start_parse( rd, 1 << hid_input );
+-# endif
+- while( hid_get_item( d, &h ) )
+- {
+- int usage, page, interesting_hid;
+-
+- page = HID_PAGE( h.usage );
+- usage = HID_USAGE( h.usage );
+-
+- /* This test is somewhat too simplistic, but this is how MicroSoft
+- * does, so I guess it works for all joysticks/game pads. */
+- is_joystick = is_joystick ||
+- ( h.kind == hid_collection &&
+- page == HUP_GENERIC_DESKTOP &&
+- ( usage == HUG_JOYSTICK || usage == HUG_GAME_PAD ) );
+-
+- if( h.kind != hid_input )
+- continue;
+-
+- if( !is_joystick )
+- continue;
+-
+- interesting_hid = TRUE;
+- if( page == HUP_GENERIC_DESKTOP )
+- {
+- switch( usage )
+- {
+- case HUG_X:
+- case HUG_RX:
+- case HUG_Y:
+- case HUG_RY:
+- case HUG_Z:
+- case HUG_RZ:
+- case HUG_SLIDER:
+- if( *num_axes < _JS_MAX_AXES )
+- {
+- os->axes_usage[ *num_axes ] = usage;
+- ( *num_axes )++;
+- }
+- break;
+- case HUG_HAT_SWITCH:
+- /* Allocate two axes for a hat */
+- if( *num_axes + 1 < _JS_MAX_AXES )
+- {
+- os->axes_usage[ *num_axes ] = usage;
+- (*num_axes)++;
+- os->axes_usage[ *num_axes ] = usage;
+- (*num_axes)++;
+- }
+- break;
+- default:
+- interesting_hid = FALSE;
+- break;
+- }
+- }
+- else if( page == HUP_BUTTON )
+- {
+- interesting_hid = ( usage > 0 ) &&
+- ( usage <= _JS_MAX_BUTTONS );
+-
+- if( interesting_hid && usage - 1 > *num_buttons )
+- *num_buttons = usage - 1;
+- }
+-
+- if( interesting_hid )
+- {
+- h.next = os->hids;
+- os->hids = calloc( 1, sizeof ( struct hid_item ) );
+- *os->hids = h;
+- }
+- }
+- hid_end_parse( d );
+-
+- return os->hids != NULL;
+-}
+-# endif
+ #endif
+
+ /*
+diff --git a/src/x11/fg_joystick_x11.c b/src/x11/fg_joystick_x11.c
+index 04bc373..30ad4b5 100644
+--- a/src/x11/fg_joystick_x11.c
++++ b/src/x11/fg_joystick_x11.c
+@@ -42,8 +42,188 @@
+ #include <fcntl.h>
+
+
++#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
++
++static int hatmap_x[9] = {0, 0, 1, 1, 1, 0, -1, -1, -1};
++static int hatmap_y[9] = {0, 1, 1, 0, -1, -1, -1, 0, 1};
++
++# ifdef HAVE_USB_JS
++/*
++* fghJoystickFindUSBdev (and its helper, fghJoystickWalkUSBdev) try to locate
++* the full name of a USB device. If /dev/usbN isn't readable, we punt and
++* return the uhidN device name. We warn the user of this situation once.
++*/
++static char *fghJoystickWalkUSBdev(int f, char *dev, char *out, int outlen)
++{
++ struct usb_device_info di;
++ int i, a;
++ char *cp;
++
++ for (a = 1; a < USB_MAX_DEVICES; a++) {
++ di.udi_addr = a;
++ if (ioctl(f, USB_DEVICEINFO, &di) != 0)
++ return NULL;
++ for (i = 0; i < USB_MAX_DEVNAMES; i++)
++ if (di.udi_devnames[i][0] &&
++ strcmp(di.udi_devnames[i], dev) == 0) {
++ cp = calloc(1, strlen(di.udi_vendor) + strlen(di.udi_product) + 2);
++ strcpy(cp, di.udi_vendor);
++ strcat(cp, " ");
++ strcat(cp, di.udi_product);
++ strncpy(out, cp, outlen - 1);
++ out[outlen - 1] = 0;
++ free(cp);
++ return out;
++ }
++ }
++ return NULL;
++}
++
++static int fghJoystickFindUSBdev(char *name, char *out, int outlen)
++{
++ int i, f;
++ char buf[50];
++ char *cp;
++ static int protection_warned = 0;
++
++ for (i = 0; i < 16; i++) {
++ snprintf(buf, sizeof(buf), "%s%d", USBDEV, i);
++ f = open(buf, O_RDONLY);
++ if (f >= 0) {
++ cp = fghJoystickWalkUSBdev(f, name, out, outlen);
++ close(f);
++ if (cp)
++ return 1;
++ }
++ else if (errno == EACCES) {
++ if (!protection_warned) {
++ fgWarning("Can't open %s for read!", buf);
++ protection_warned = 1;
++ }
++ }
++ }
++ return 0;
++}
++
++static int fghJoystickInitializeHID(struct os_specific_s *os,
++ int *num_axes, int *num_buttons)
++{
++ int size, is_joystick;
++# ifdef HAVE_USBHID_H
++ int report_id = 0;
++# endif
++ struct hid_data *d;
++ struct hid_item h;
++ report_desc_t rd;
++
++ if ((rd = hid_get_report_desc(os->fd)) == 0)
++ {
++ fgWarning("error: %s: %s", os->fname, strerror(errno));
++ return FALSE;
++ }
++
++ os->hids = NULL;
++
++# ifdef HAVE_USBHID_H
++ if (ioctl(os->fd, USB_GET_REPORT_ID, &report_id) < 0)
++ {
++ /*** XXX {report_id} may not be the right variable? ***/
++ fgWarning("error: %s%d: %s", UHIDDEV, report_id, strerror(errno));
++ return FALSE;
++ }
++
++ size = hid_report_size(rd, hid_input, report_id);
++# else
++ size = hid_report_size(rd, 0, hid_input);
++# endif
++ os->hid_data_buf = calloc(1, size);
++ os->hid_dlen = size;
++
++ is_joystick = 0;
++# ifdef HAVE_USBHID_H
++ d = hid_start_parse(rd, 1 << hid_input, report_id);
++# else
++ d = hid_start_parse(rd, 1 << hid_input);
++# endif
++ while (hid_get_item(d, &h))
++ {
++ int usage, page, interesting_hid;
++
++ page = HID_PAGE(h.usage);
++ usage = HID_USAGE(h.usage);
++
++ /* This test is somewhat too simplistic, but this is how MicroSoft
++ * does, so I guess it works for all joysticks/game pads. */
++ is_joystick = is_joystick ||
++ (h.kind == hid_collection &&
++ page == HUP_GENERIC_DESKTOP &&
++ (usage == HUG_JOYSTICK || usage == HUG_GAME_PAD));
++
++ if (h.kind != hid_input)
++ continue;
++
++ if (!is_joystick)
++ continue;
++
++ interesting_hid = TRUE;
++ if (page == HUP_GENERIC_DESKTOP)
++ {
++ switch (usage)
++ {
++ case HUG_X:
++ case HUG_RX:
++ case HUG_Y:
++ case HUG_RY:
++ case HUG_Z:
++ case HUG_RZ:
++ case HUG_SLIDER:
++ if (*num_axes < _JS_MAX_AXES)
++ {
++ os->axes_usage[*num_axes] = usage;
++ (*num_axes)++;
++ }
++ break;
++ case HUG_HAT_SWITCH:
++ /* Allocate two axes for a hat */
++ if (*num_axes + 1 < _JS_MAX_AXES)
++ {
++ os->axes_usage[*num_axes] = usage;
++ (*num_axes)++;
++ os->axes_usage[*num_axes] = usage;
++ (*num_axes)++;
++ }
++ break;
++ default:
++ interesting_hid = FALSE;
++ break;
++ }
++ }
++ else if (page == HUP_BUTTON)
++ {
++ interesting_hid = (usage > 0) &&
++ (usage <= _JS_MAX_BUTTONS);
++
++ if (interesting_hid && usage - 1 > *num_buttons)
++ *num_buttons = usage - 1;
++ }
++
++ if (interesting_hid)
++ {
++ h.next = os->hids;
++ os->hids = calloc(1, sizeof(struct hid_item));
++ *os->hids = h;
++ }
++ }
++ hid_end_parse(d);
++
++ return os->hids != NULL;
++}
++# endif
++#endif
++
++
+ /*this should be defined in a header file */
+-#define MAX_NUM_JOYSTICKS 2
++#define MAX_NUM_JOYSTICKS 2
+ extern SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ];
+
+ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
+@@ -216,15 +396,15 @@ void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
+ void fgPlatformJoystickOpen( SFG_Joystick* joy )
+ {
+ #if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__)
+- int i = 0;
++ int i = 0;
+ char *cp;
+ #endif
+ #ifdef JS_NEW
+ unsigned char u;
+- int i=0;
++ int i=0;
+ #else
+ # if defined( __linux__ ) || TARGET_HOST_SOLARIS
+- int i = 0;
++ int i = 0;
+ int counter = 0;
+ # endif
+ #endif
+@@ -448,7 +628,7 @@ void fgPlatformJoystickClose ( int ident )
+ free( fgJoystick[ ident ]->pJoystick.os->hid_data_buf );
+ #endif
+ free( fgJoystick[ident]->pJoystick.os );
+- }
++ }
+ #endif
+
+ if( ! fgJoystick[ident]->error )
+--
+2.19.2
+
+From f310b56bb6f93e255cf880c8970c794e0f2efc8d Mon Sep 17 00:00:00 2001
+From: dcnieho <dcnieho@7f0cb862-5218-0410-a997-914c9d46530a>
+Date: Mon, 31 Jul 2017 20:49:26 +0000
+Subject: [PATCH] Fix build on NetBSD.
+
+(cherry picked from commit 1236c7644508227b616e97e29e123b34257e36d1)
+
+git-svn-id: http://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1835 7f0cb862-5218-0410-a997-914c9d46530a
+---
+ src/fg_joystick.c | 59 -------------------------------------
+ src/x11/fg_joystick_x11.c | 61 +++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 61 insertions(+), 59 deletions(-)
+
+diff --git a/src/fg_joystick.c b/src/fg_joystick.c
+index e548c04..b24476a 100644
+--- a/src/fg_joystick.c
++++ b/src/fg_joystick.c
+@@ -40,65 +40,6 @@
+ #define JS_TRUE 1
+ #define JS_FALSE 0
+
+-/* BSD defines from "jsBSD.cxx" around lines 42-270 */
+-
+-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+-
+-# ifdef HAVE_USB_JS
+-# if defined(__NetBSD__)
+-# ifdef HAVE_USBHID_H
+-# include <usbhid.h>
+-# else
+-# include <usb.h>
+-# endif
+-# include <dev/usb/usb.h>
+-# elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+-# ifdef HAVE_USBHID_H
+-# include <usbhid.h>
+-# else
+-# include <libusbhid.h>
+-# endif
+-# include <legacy/dev/usb/usb.h>
+-# endif
+-# include <dev/usb/usbhid.h>
+-
+-/* Compatibility with older usb.h revisions */
+-# if !defined(USB_MAX_DEVNAMES) && defined(MAXDEVNAMES)
+-# define USB_MAX_DEVNAMES MAXDEVNAMES
+-# endif
+-# endif
+-
+-struct os_specific_s {
+- char fname [128 ];
+- int fd;
+- int is_analog;
+- /* The following structure members are specific to analog joysticks */
+- struct joystick ajs;
+-# ifdef HAVE_USB_JS
+- /* The following structure members are specific to USB joysticks */
+- struct hid_item *hids;
+- int hid_dlen;
+- int hid_offset;
+- char *hid_data_buf;
+- int axes_usage [ _JS_MAX_AXES ];
+-# endif
+- /* We keep button and axes state ourselves, as they might not be updated
+- * on every read of a USB device
+- */
+- int cache_buttons;
+- float cache_axes [ _JS_MAX_AXES ];
+-};
+-
+-/* Idents lower than USB_IDENT_OFFSET are for analog joysticks. */
+-# define USB_IDENT_OFFSET 2
+-
+-# define USBDEV "/dev/usb"
+-# define UHIDDEV "/dev/uhid"
+-# define AJSDEV "/dev/joy"
+-
+-
+-#endif
+-
+ /*
+ * Functions associated with the "jsJoystick" class in PLIB
+ */
+diff --git a/src/x11/fg_joystick_x11.c b/src/x11/fg_joystick_x11.c
+index 30ad4b5..8c75bbe 100644
+--- a/src/x11/fg_joystick_x11.c
++++ b/src/x11/fg_joystick_x11.c
+@@ -42,8 +42,68 @@
+ #include <fcntl.h>
+
+
++/* BSD defines from "jsBSD.cxx" around lines 42-270 */
++
++#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
++
++# ifdef HAVE_USB_JS
++# if defined(__NetBSD__)
++# ifdef HAVE_USBHID_H
++# include <usbhid.h>
++# else
++# include <usb.h>
++# endif
++# include <dev/usb/usb.h>
++# elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
++# ifdef HAVE_USBHID_H
++# include <usbhid.h>
++# else
++# include <libusbhid.h>
++# endif
++# include <legacy/dev/usb/usb.h>
++# endif
++# include <dev/usb/usbhid.h>
++
++/* Compatibility with older usb.h revisions */
++# if !defined(USB_MAX_DEVNAMES) && defined(MAXDEVNAMES)
++# define USB_MAX_DEVNAMES MAXDEVNAMES
++# endif
++# endif
++
++struct os_specific_s {
++ char fname [128 ];
++ int fd;
++ int is_analog;
++ /* The following structure members are specific to analog joysticks */
++ struct joystick ajs;
++# ifdef HAVE_USB_JS
++ /* The following structure members are specific to USB joysticks */
++ struct hid_item *hids;
++ int hid_dlen;
++ int hid_offset;
++ char *hid_data_buf;
++ int axes_usage [ _JS_MAX_AXES ];
++# endif
++ /* We keep button and axes state ourselves, as they might not be updated
++ * on every read of a USB device
++ */
++ int cache_buttons;
++ float cache_axes [ _JS_MAX_AXES ];
++};
++
++/* Idents lower than USB_IDENT_OFFSET are for analog joysticks. */
++# define USB_IDENT_OFFSET 2
++
++# define USBDEV "/dev/usb"
++# define UHIDDEV "/dev/uhid"
++# define AJSDEV "/dev/joy"
++
++
++#endif
++
+ #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ static int hatmap_x[9] = {0, 0, 1, 1, 1, 0, -1, -1, -1};
+ static int hatmap_y[9] = {0, 1, 1, 0, -1, -1, -1, 0, 1};
+
+@@ -104,6 +164,7 @@ static int fghJoystickFindUSBdev(char *name, char *out, int outlen)
+ }
+ return 0;
+ }
++#endif
+
+ static int fghJoystickInitializeHID(struct os_specific_s *os,
+ int *num_axes, int *num_buttons)
+--
+2.19.2
+
diff --git a/media-libs/freeglut/freeglut-3.0.0.ebuild b/media-libs/freeglut/freeglut-3.0.0.ebuild
index 95ec4c4bca87..3fcb972cf759 100644
--- a/media-libs/freeglut/freeglut-3.0.0.ebuild
+++ b/media-libs/freeglut/freeglut-3.0.0.ebuild
@@ -31,6 +31,7 @@ HTML_DOCS=( doc/. )
PATCHES=(
"${FILESDIR}"/${P}-drop-unnecessary-x11-libs.patch
+ "${FILESDIR}"/${P}-bsd-usb-joystick.patch
)
src_configure() {