diff -cr tmp/DirectFB-1.6.3/lib/direct/build.h DirectFB-1.6.3/lib/direct/build.h
*** tmp/DirectFB-1.6.3/lib/direct/build.h	2013-01-18 23:58:01.000000000 +0900
--- DirectFB-1.6.3/lib/direct/build.h	2013-08-13 18:49:41.125476858 +0900
***************
*** 44,50 ****
  #define DIRECT_BUILD_GETTID    (1)
  #define DIRECT_BUILD_NETWORK   (1)
  #define DIRECT_BUILD_STDBOOL   (1)
! #define DIRECT_BUILD_DYNLOAD   (1)
  #define DIRECT_BUILD_MULTICORE (1)
  #define DIRECT_BUILD_OSTYPE    (DIRECT_OS_LINUX_GNU_LIBC)
  
--- 44,50 ----
  #define DIRECT_BUILD_GETTID    (1)
  #define DIRECT_BUILD_NETWORK   (1)
  #define DIRECT_BUILD_STDBOOL   (1)
! #define DIRECT_BUILD_DYNLOAD   (0)
  #define DIRECT_BUILD_MULTICORE (1)
  #define DIRECT_BUILD_OSTYPE    (DIRECT_OS_LINUX_GNU_LIBC)
  
diff -cr tmp/DirectFB-1.6.3/lib/direct/fifo.c DirectFB-1.6.3/lib/direct/fifo.c
*** tmp/DirectFB-1.6.3/lib/direct/fifo.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/fifo.c	2013-08-01 10:19:22.722346055 +0900
***************
*** 7,13 ****
     Written by Denis Oliver Kropp <dok@directfb.org>,
                Andreas Hundt <andi@fischlustig.de>,
                Sven Neumann <neo@directfb.org>,
!               Ville Syrjälä <syrjala@sci.fi> and
                Claudio Ciccani <klan@users.sf.net>.
  
     This library is free software; you can redistribute it and/or
--- 7,13 ----
     Written by Denis Oliver Kropp <dok@directfb.org>,
                Andreas Hundt <andi@fischlustig.de>,
                Sven Neumann <neo@directfb.org>,
!               Ville Syrj??l?? <syrjala@sci.fi> and
                Claudio Ciccani <klan@users.sf.net>.
  
     This library is free software; you can redistribute it and/or
***************
*** 37,42 ****
--- 37,43 ----
  
  D_LOG_DOMAIN( Direct_Fifo, "Direct/Fifo", "Direct FIFO" );
  
+ #if !defined(__NetBSD__)
  /**********************************************************************************************************************/
  
  void
***************
*** 100,118 ****
  
  
       if (index == 0) {
- #if 0
-           if (fifo->up) {
-                DirectFifo *down = D_SYNC_FETCH_AND_CLEAR( &fifo->down );
-                
-                if (down) {
-                     D_MAGIC_ASSERT( down, DirectFifo );
-                     D_ASSERT( down == fifo->up );
-      
-                     direct_fifo_push( down, &fifo->item );
-                }
-           }
-           else
- #endif
            if (fifo->waiting && fifo->in /* && fifo->count*/) {
                 direct_futex_wake( &fifo->waiting, 1 );
  
--- 101,106 ----
***************
*** 295,297 ****
--- 283,552 ----
       return direct_futex_wake( &fifo->waiting, 1 );
  }
  
+ #else /* __NetBSD__ */
+ /**********************************************************************************************************************/
+ 
+ void
+ direct_fifo_init( DirectFifo *fifo )
+ {
+      D_DEBUG_AT( Direct_Fifo, "%s( %p )\n", __FUNCTION__, fifo );
+ 
+      memset( fifo, 0, sizeof(DirectFifo) );
+ 
+      pthread_mutex_init(&fifo->mutex, NULL);
+      pthread_cond_init(&fifo->cond, NULL);
+ 
+      D_MAGIC_SET( fifo, DirectFifo );
+ }
+ 
+ void
+ direct_fifo_destroy( DirectFifo *fifo )
+ {
+      D_DEBUG_AT( Direct_Fifo, "%s( %p )\n", __FUNCTION__, fifo );
+ 
+      pthread_mutex_destroy(&fifo->mutex);
+      pthread_cond_destroy(&fifo->cond);
+ 
+      D_MAGIC_ASSERT( fifo, DirectFifo );
+ 
+      D_MAGIC_CLEAR( fifo );
+ }
+ 
+ /**********************************************************************************************************************/
+ 
+ int
+ direct_fifo_push( DirectFifo *fifo, DirectFifoItem *item )
+ {
+      D_DEBUG_AT( Direct_Fifo, "%s( %p, %p )\n", __FUNCTION__, fifo, item );
+ 
+      D_MAGIC_ASSERT( fifo, DirectFifo );
+ 
+      pthread_mutex_lock(&fifo->mutex);
+ 
+      D_MAGIC_SET( item, DirectFifoItem );
+ 
+      //d_sync_push( &fifo->in, item );
+      {
+ 	DirectFifoItem *tmp = fifo->in;
+ 	fifo->in = item;
+ 	item->next = tmp;
+      }
+ 
+      D_DEBUG_AT( Direct_Fifo, "  * * * [%d] <--= %p\n", fifo, item );
+ 
+      if ( fifo->in ) {
+          pthread_cond_signal(&fifo->cond);
+      }
+      pthread_mutex_unlock(&fifo->mutex);
+ 
+      return 0;
+ }
+ 
+ void *
+ direct_fifo_pull( DirectFifo *fifo )
+ {
+      DirectFifoItem *tmp, *out;
+ 
+      D_DEBUG_AT( Direct_Fifo, "%s( %p )\n", __FUNCTION__, fifo );
+ 
+      D_MAGIC_ASSERT( fifo, DirectFifo );
+ 
+      pthread_mutex_lock(&fifo->mutex);
+ 
+      tmp = fifo->out;
+      if (tmp) {
+           D_MAGIC_ASSERT( tmp, DirectFifoItem );
+ 
+           fifo->out = tmp->next;
+      }
+      else {
+           /* tmp = d_sync_fetch_and_clear( (void**) &fifo->in ); */
+           tmp = fifo->in; fifo->in = NULL;
+           if (!tmp) {
+                pthread_mutex_unlock(&fifo->mutex);
+                return NULL;
+           } 
+           D_MAGIC_ASSERT( tmp, DirectFifoItem );
+ 
+           out = NULL;
+ 
+           while (tmp->next) {
+                DirectFifoItem *next;
+ 
+                next = tmp->next;
+ 
+                D_MAGIC_ASSERT( next, DirectFifoItem );
+ 
+                tmp->next = out;
+ 
+                out = tmp;
+ 
+                tmp = next;
+           }
+ 
+           fifo->out = out;
+      }
+ 
+      D_MAGIC_CLEAR( tmp );
+ 
+ 
+      D_DEBUG_AT( Direct_Fifo, "  : : : [%d] =--> %p\n", fifo, tmp );
+ 
+      pthread_mutex_unlock(&fifo->mutex);
+ 
+      return tmp;
+ }
+ 
+ void *
+ direct_fifo_pop( DirectFifo *fifo )
+ {
+      DirectFifoItem        *item;
+ 
+      D_DEBUG_AT( Direct_Fifo, "%s( %p )\n", __FUNCTION__, fifo );
+ 
+      D_MAGIC_ASSERT( fifo, DirectFifo );
+ 
+      pthread_mutex_lock(&fifo->mutex);
+ 
+      if (!fifo->in) {
+           D_DEBUG_AT( Direct_Fifo, "  -> fifo->in = NULL\n" );
+ 	  pthread_mutex_unlock(&fifo->mutex);
+           return NULL;
+      }
+ 
+      //item = D_SYNC_POP( &fifo->in );
+      {
+ 	  item = fifo->in;
+ 	  if(item) {
+ 	      fifo->in = item->next;
+ 	  }
+      }
+      if (!item) {
+           D_DEBUG_AT( Direct_Fifo, "  -> item NULL\n" );
+ 	  pthread_mutex_unlock(&fifo->mutex);
+           return NULL;
+      }
+ 
+      D_DEBUG_AT( Direct_Fifo, "  -> item %p\n", item );
+ 
+      D_MAGIC_ASSERT( item, DirectFifoItem );
+ 
+      item->next = NULL;
+ 
+      D_MAGIC_CLEAR( item );
+ 
+      D_DEBUG_AT( Direct_Fifo, "  # # # %p [%d] =--> %p\n", fifo, index, item );
+ 
+      pthread_mutex_unlock(&fifo->mutex);
+ 
+      return item;
+ }
+ 
+ /**********************************************************************************************************************/
+ 
+ DirectResult
+ direct_fifo_wait( DirectFifo *fifo )
+ {
+      DirectResult    ret = DR_OK;
+ 
+      D_MAGIC_ASSERT( fifo, DirectFifo );
+      pthread_mutex_lock(&fifo->mutex);
+ 
+      D_DEBUG_AT( Direct_Fifo, "%s( %p ) ## ## %p # %p\n", __FUNCTION__, fifo, fifo->in, fifo->out );
+ 
+      while (!fifo->in) {
+           if (fifo->wake) {
+                D_DEBUG_AT( Direct_Fifo, "    ### ### WAKE UP ### ###\n" );
+                fifo->wake = false;
+                break;
+           }
+ 
+           ret = pthread_cond_wait(&fifo->cond, &fifo->mutex);
+           if (ret)
+                break;
+      }
+ 
+      pthread_mutex_unlock(&fifo->mutex);
+ 
+      return ret;
+ }
+ 
+ static __inline clockid_t
+ pthread_cond_getclock(const pthread_cond_t *cond)
+ {   /* from pthread_cond.c in libpthread */
+     return cond->ptc_private ?
+ 	*(clockid_t *)cond->ptc_private : CLOCK_REALTIME;
+ }
+ 
+ static __inline void timespec_ms_add( struct timespec *r, struct timespec *t, int ms )
+ {
+     r->tv_sec  = t->tv_sec + (ms / 1000);
+     r->tv_nsec = t->tv_nsec + ((ms % 1000) * 1000000L);
+     while(r->tv_nsec >= 1000000000L) {
+ 	r->tv_sec ++;
+ 	r->tv_nsec -= 1000000000L;
+     }
+     while(r->tv_nsec < 0) {
+ 	r->tv_sec --;
+ 	r->tv_nsec += 1000000000L;
+     }
+ }
+ 
+ static int
+ pthread_cond_wait_rt( pthread_cond_t *cond, pthread_mutex_t *mutex, int ms)
+ {
+     struct timespec tm;
+     if( clock_gettime( pthread_cond_getclock(cond), &tm ) == -1 )
+ 	return errno;
+     timespec_ms_add(&tm, &tm, ms);
+     return pthread_cond_timedwait(cond, mutex, &tm);
+ }
+ 
+ DirectResult
+ direct_fifo_wait_timed( DirectFifo *fifo, int timeout_ms )
+ {
+      DirectResult ret = DR_OK;
+ 
+      D_MAGIC_ASSERT( fifo, DirectFifo );
+      pthread_mutex_lock(&fifo->mutex);
+ 
+      D_DEBUG_AT( Direct_Fifo, "%s( %p ) ## ## %p # %p\n", __FUNCTION__, fifo, fifo->in, fifo->out );
+ 
+      while (!fifo->in) {
+           if (fifo->wake) {
+                D_DEBUG_AT( Direct_Fifo, "    ### ### WAKE UP ### ###\n" );
+                fifo->wake = false;
+                break;
+           }
+           ret = pthread_cond_wait_rt(&fifo->cond, &fifo->mutex, timeout_ms);
+           if (ret)
+                break;
+      }
+ 
+      pthread_mutex_unlock(&fifo->mutex);
+ 
+      return ret;
+ }
+ 
+ DirectResult
+ direct_fifo_wakeup( DirectFifo *fifo )
+ {
+      int ret;
+ 
+      D_DEBUG_AT( Direct_Fifo, "    # # # # WAKE UP # # # #\n" );
+ 
+      D_MAGIC_ASSERT( fifo, DirectFifo );
+ 
+      ret = pthread_mutex_lock(&fifo->mutex);
+ 
+      fifo->wake = true;
+ 
+      ret = pthread_cond_signal(&fifo->cond);
+ 
+      ret = pthread_mutex_unlock(&fifo->mutex);
+ 
+      return ret;
+ }
+ 
+ #endif
+ 
diff -cr tmp/DirectFB-1.6.3/lib/direct/fifo.h DirectFB-1.6.3/lib/direct/fifo.h
*** tmp/DirectFB-1.6.3/lib/direct/fifo.h	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/fifo.h	2013-08-01 10:19:22.717345557 +0900
***************
*** 29,34 ****
--- 29,37 ----
  #ifndef __DIRECT__FIFO_H__
  #define __DIRECT__FIFO_H__
  
+ #if defined(__NetBSD__)
+ #include <pthread.h>
+ #endif
  #include <direct/debug.h>
  #include <direct/types.h>
  
***************
*** 40,59 ****
  };
  
  struct __D_DirectFifo {
- //     DirectFifoItem      item;
- 
       int                 magic;
  
- //     int                 count;
       int                 waiting;
  
       DirectFifoItem     *in;
       DirectFifoItem     *out;
  
- //     DirectFifo         *up;
- //     DirectFifo         *down;
- 
       bool                wake;
  };
  
  /**********************************************************************************************************************/
--- 43,60 ----
  };
  
  struct __D_DirectFifo {
       int                 magic;
  
       int                 waiting;
  
       DirectFifoItem     *in;
       DirectFifoItem     *out;
  
       bool                wake;
+ #if defined(__NetBSD__)
+      pthread_mutex_t	mutex;
+      pthread_cond_t     cond;
+ #endif
  };
  
  /**********************************************************************************************************************/
diff -cr tmp/DirectFB-1.6.3/lib/direct/modules.c DirectFB-1.6.3/lib/direct/modules.c
*** tmp/DirectFB-1.6.3/lib/direct/modules.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/modules.c	2013-08-02 12:30:01.477471094 +0900
***************
*** 39,45 ****
--- 39,49 ----
  #include <direct/modules.h>
  
  #if DIRECT_BUILD_DYNLOAD
+ #if defined(__NetBSD__)
+ #include <stdlib.h>
+ #else
  #include <alloca.h>
+ #endif
  #include <dirent.h>
  #include <dlfcn.h>
  #endif
***************
*** 439,453 ****
            if (!pathfront)
                 pathfront = MODULEDIR;
       }
! 
       buf = alloca( strlen( pathfront ) + 1 + strlen( path ) + 1 + strlen( module->file ) + 1 );
       sprintf( buf, "%s/%s/%s", pathfront, path, module->file );
  
!      D_DEBUG_AT( Direct_Modules, "Loading '%s'...\n", buf );
  
       handle = dlopen( buf, RTLD_NOW );
       if (!handle)
!           D_DLERROR( "Direct/Modules: Unable to dlopen `%s'!\n", buf );
  
       D_MAGIC_ASSERT( module, DirectModuleEntry );
  
--- 443,465 ----
            if (!pathfront)
                 pathfront = MODULEDIR;
       }
! //#ifdef __NetBSD__
!      if(strcmp(module->file, "libdirectfb_sdl.so")==0) {
! 	 fprintf(stderr,"libSDL loading...\n");
! 	 handle = dlopen( "/usr/local/lib/libSDL.so", RTLD_NOW );
! 	 if (!handle)
! 	      D_DLERROR( "Direct/Modules: Unable to dlopen `%s'!\n", "libSDL.so" );
! 	 handle = dlsym(handle, "SDL_FreeSurface");
!      }
! //#endif
       buf = alloca( strlen( pathfront ) + 1 + strlen( path ) + 1 + strlen( module->file ) + 1 );
       sprintf( buf, "%s/%s/%s", pathfront, path, module->file );
  
!      D_DEBUG_AT( Direct_Modules, "Loading '%s(%s)'...\n", buf, module->file );
  
       handle = dlopen( buf, RTLD_NOW );
       if (!handle)
!           D_DLERROR( "Direct/Modules: Unable to dlopen %s `%s'!\n", module->file, buf );
  
       D_MAGIC_ASSERT( module, DirectModuleEntry );
  
diff -cr tmp/DirectFB-1.6.3/lib/direct/os/filesystem.h DirectFB-1.6.3/lib/direct/os/filesystem.h
*** tmp/DirectFB-1.6.3/lib/direct/os/filesystem.h	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/os/filesystem.h	2013-08-01 10:19:22.403345595 +0900
***************
*** 96,106 ****
  
  DirectResult DIRECT_API  direct_access( const char *name, int flags );
  
! 
  #define	R_OK	4
  #define	W_OK	2
  #define	X_OK	1
  #define	F_OK	0
  
  #endif
  
--- 96,107 ----
  
  DirectResult DIRECT_API  direct_access( const char *name, int flags );
  
! #if !defined(F_OK)
  #define	R_OK	4
  #define	W_OK	2
  #define	X_OK	1
  #define	F_OK	0
+ #endif
  
  #endif
  
diff -cr tmp/DirectFB-1.6.3/lib/direct/os/linux/glibc/clock.c DirectFB-1.6.3/lib/direct/os/linux/glibc/clock.c
*** tmp/DirectFB-1.6.3/lib/direct/os/linux/glibc/clock.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/os/linux/glibc/clock.c	2013-08-01 10:19:22.518346184 +0900
***************
*** 58,72 ****
            case DIRECT_CLOCK_MONOTONIC:
                 clock_id = CLOCK_MONOTONIC;
                 break;
! 
            case DIRECT_CLOCK_PROCESS_CPUTIME_ID:
                 clock_id = CLOCK_PROCESS_CPUTIME_ID;
                 break;
! 
            case DIRECT_CLOCK_THREAD_CPUTIME_ID:
                 clock_id = CLOCK_THREAD_CPUTIME_ID;
                 break;
! 
            default:
                 D_BUG( "invalid clock type %d", type );
                 return DR_INVARG;
--- 58,73 ----
            case DIRECT_CLOCK_MONOTONIC:
                 clock_id = CLOCK_MONOTONIC;
                 break;
! #if defined(DIRECT_CLOCK_PROCESS_CPUTIME_ID)
            case DIRECT_CLOCK_PROCESS_CPUTIME_ID:
                 clock_id = CLOCK_PROCESS_CPUTIME_ID;
                 break;
! #endif
! #if defined(DIRECT_CLOCK_THREAD_CPUTIME_ID)
            case DIRECT_CLOCK_THREAD_CPUTIME_ID:
                 clock_id = CLOCK_THREAD_CPUTIME_ID;
                 break;
! #endif
            default:
                 D_BUG( "invalid clock type %d", type );
                 return DR_INVARG;
***************
*** 110,124 ****
            case DIRECT_CLOCK_MONOTONIC:
                 clock_id = CLOCK_MONOTONIC;
                 break;
! 
            case DIRECT_CLOCK_PROCESS_CPUTIME_ID:
                 clock_id = CLOCK_PROCESS_CPUTIME_ID;
                 break;
! 
            case DIRECT_CLOCK_THREAD_CPUTIME_ID:
                 clock_id = CLOCK_THREAD_CPUTIME_ID;
                 break;
! 
            default:
                 D_BUG( "invalid clock type %d", type );
                 return DR_INVARG;
--- 111,126 ----
            case DIRECT_CLOCK_MONOTONIC:
                 clock_id = CLOCK_MONOTONIC;
                 break;
! #if defined(DIRECT_CLOCK_PROCESS_CPUTIME_ID)
            case DIRECT_CLOCK_PROCESS_CPUTIME_ID:
                 clock_id = CLOCK_PROCESS_CPUTIME_ID;
                 break;
! #endif
! #if defined(DIRECT_CLOCK_THREAD_CPUTIME_ID)
            case DIRECT_CLOCK_THREAD_CPUTIME_ID:
                 clock_id = CLOCK_THREAD_CPUTIME_ID;
                 break;
! #endif
            default:
                 D_BUG( "invalid clock type %d", type );
                 return DR_INVARG;
***************
*** 151,164 ****
                 clock_id = CLOCK_MONOTONIC;
                 break;
  
            case DIRECT_CLOCK_PROCESS_CPUTIME_ID:
                 clock_id = CLOCK_PROCESS_CPUTIME_ID;
                 break;
! 
            case DIRECT_CLOCK_THREAD_CPUTIME_ID:
                 clock_id = CLOCK_THREAD_CPUTIME_ID;
                 break;
! 
            default:
                 D_BUG( "invalid clock type %d", type );
                 return DR_INVARG;
--- 153,168 ----
                 clock_id = CLOCK_MONOTONIC;
                 break;
  
+ #if defined(DIRECT_CLOCK_PROCESS_CPUTIME_ID)
            case DIRECT_CLOCK_PROCESS_CPUTIME_ID:
                 clock_id = CLOCK_PROCESS_CPUTIME_ID;
                 break;
! #endif
! #if defined(DIRECT_CLOCK_THREAD_CPUTIME_ID)
            case DIRECT_CLOCK_THREAD_CPUTIME_ID:
                 clock_id = CLOCK_THREAD_CPUTIME_ID;
                 break;
! #endif
            default:
                 D_BUG( "invalid clock type %d", type );
                 return DR_INVARG;
diff -cr tmp/DirectFB-1.6.3/lib/direct/os/linux/glibc/system.c DirectFB-1.6.3/lib/direct/os/linux/glibc/system.c
*** tmp/DirectFB-1.6.3/lib/direct/os/linux/glibc/system.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/os/linux/glibc/system.c	2013-08-01 10:19:22.431854880 +0900
***************
*** 34,40 ****
  #include <signal.h>
  #include <unistd.h>
  
! #include <linux/unistd.h>
  
  #include <direct/atomic.h>
  #include <direct/debug.h>
--- 34,40 ----
  #include <signal.h>
  #include <unistd.h>
  
! //#include <linux/unistd.h>
  
  #include <direct/atomic.h>
  #include <direct/debug.h>
***************
*** 185,191 ****
  }
  
  /**********************************************************************************************************************/
! 
  DirectResult
  direct_futex( int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3 )
  {
--- 185,191 ----
  }
  
  /**********************************************************************************************************************/
! #if !defined(__NetBSD__)
  DirectResult
  direct_futex( int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3 )
  {
***************
*** 215,218 ****
  
       return DR_OK;
  }
! 
--- 215,218 ----
  
       return DR_OK;
  }
! #endif
diff -cr tmp/DirectFB-1.6.3/lib/direct/serial.c DirectFB-1.6.3/lib/direct/serial.c
*** tmp/DirectFB-1.6.3/lib/direct/serial.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/serial.c	2013-08-01 10:19:22.373355861 +0900
***************
*** 41,47 ****
  D_LOG_DOMAIN( Direct_Serial_Wait,   "Direct/Serial/Wait",   "Direct Serial Wait" );
  
  /**********************************************************************************************************************/
! 
  DirectResult
  direct_serial_wait( DirectSerial       *serial,
                      const DirectSerial *source )
--- 41,47 ----
  D_LOG_DOMAIN( Direct_Serial_Wait,   "Direct/Serial/Wait",   "Direct Serial Wait" );
  
  /**********************************************************************************************************************/
! #if !defined(__NetBSD__)
  DirectResult
  direct_serial_wait( DirectSerial       *serial,
                      const DirectSerial *source )
***************
*** 110,113 ****
  
       return DR_OK;
  }
! 
--- 110,113 ----
  
       return DR_OK;
  }
! #endif
diff -cr tmp/DirectFB-1.6.3/lib/direct/signals.c DirectFB-1.6.3/lib/direct/signals.c
*** tmp/DirectFB-1.6.3/lib/direct/signals.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/signals.c	2013-08-01 10:19:22.726346641 +0900
***************
*** 77,83 ****
  static DirectLink  *handlers = NULL;
  static DirectMutex  handlers_lock;
  
! static pthread_t sighandler_thread = -1;
  
  /**************************************************************************************************/
  #ifndef ANDROID_NDK
--- 77,83 ----
  static DirectLink  *handlers = NULL;
  static DirectMutex  handlers_lock;
  
! static pthread_t sighandler_thread = (pthread_t) -1;
  
  /**************************************************************************************************/
  #ifndef ANDROID_NDK
***************
*** 130,136 ****
  #else
       if (direct_config->sighandler) {
            pthread_kill( sighandler_thread, SIG_CLOSE_SIGHANDLER );
!           sighandler_thread = -1;
       }
  #endif
       direct_mutex_deinit( &handlers_lock );
--- 130,136 ----
  #else
       if (direct_config->sighandler) {
            pthread_kill( sighandler_thread, SIG_CLOSE_SIGHANDLER );
!           sighandler_thread = (pthread_t) -1;
       }
  #endif
       direct_mutex_deinit( &handlers_lock );
***************
*** 335,342 ****
--- 335,347 ----
  #endif
  #ifdef SI_QUEUE
            case SI_QUEUE:
+ #if defined(__NetBSD__)
+                D_LOG( Direct_Signals, FATAL, "    --> Caught signal %d (queued by pid %d, uid %d, val %d, uctx %p) <--\n",
+                       info->si_signo, info->si_pid, info->si_uid, info->si_value.sival_int, uctx );
+ #else
                 D_LOG( Direct_Signals, FATAL, "    --> Caught signal %d (queued by pid %d, uid %d, val %d, uctx %p) <--\n",
                        info->si_signo, info->si_pid, info->si_uid, info->si_int, uctx );
+ #endif
                 return true;
  #endif
  #ifdef SI_KERNEL
diff -cr tmp/DirectFB-1.6.3/lib/direct/stream.c DirectFB-1.6.3/lib/direct/stream.c
*** tmp/DirectFB-1.6.3/lib/direct/stream.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/stream.c	2013-08-01 10:19:22.004744016 +0900
***************
*** 41,46 ****
--- 41,50 ----
  
  #include <direct/stream.h>
  
+ #if defined(__NetBSD__)
+ #  define SOL_IP IPPROTO_IP
+ #endif
+ 
  
  D_LOG_DOMAIN( Direct_Stream, "Direct/Stream", "Stream wrapper" );
  
diff -cr tmp/DirectFB-1.6.3/lib/direct/system.c DirectFB-1.6.3/lib/direct/system.c
*** tmp/DirectFB-1.6.3/lib/direct/system.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/lib/direct/system.c	2013-08-01 10:19:21.942718210 +0900
***************
*** 39,45 ****
  D_LOG_DOMAIN( Direct_Futex, "Direct/Futex", "Direct Futex" );
  
  /**********************************************************************************************************************/
! 
  DirectResult
  direct_futex_wait( int *uaddr,
                     int  val )
--- 39,45 ----
  D_LOG_DOMAIN( Direct_Futex, "Direct/Futex", "Direct Futex" );
  
  /**********************************************************************************************************************/
! #if !defined(__NetBSD__)
  DirectResult
  direct_futex_wait( int *uaddr,
                     int  val )
***************
*** 153,156 ****
  
  unsigned int __Direct_Futex_Wait_Count = 0;
  unsigned int __Direct_Futex_Wake_Count = 0;
! 
--- 153,156 ----
  
  unsigned int __Direct_Futex_Wait_Count = 0;
  unsigned int __Direct_Futex_Wake_Count = 0;
! #endif
diff -cr tmp/DirectFB-1.6.3/src/display/idirectfbsurface.c DirectFB-1.6.3/src/display/idirectfbsurface.c
*** tmp/DirectFB-1.6.3/src/display/idirectfbsurface.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/src/display/idirectfbsurface.c	2013-08-01 10:19:30.715345407 +0900
***************
*** 32,38 ****
--- 32,42 ----
  #include <stdlib.h>
  #include <unistd.h>
  #include <string.h>
+ #if defined(__NetBSD__)
+ #include <stdlib.h>
+ #else
  #include <alloca.h>
+ #endif
  
  #include <math.h>
  
diff -cr tmp/DirectFB-1.6.3/systems/egl/egl_system.c DirectFB-1.6.3/systems/egl/egl_system.c
*** tmp/DirectFB-1.6.3/systems/egl/egl_system.c	2013-01-18 23:57:11.000000000 +0900
--- DirectFB-1.6.3/systems/egl/egl_system.c	2013-08-01 10:19:28.177409068 +0900
***************
*** 49,55 ****
  
  #include <core/core_system.h>
  
! #define RASPBERRY_PI
  
  DFB_CORE_SYSTEM( egl )
  
--- 49,55 ----
  
  #include <core/core_system.h>
  
! /* #define RASPBERRY_PI */
  
  DFB_CORE_SYSTEM( egl )
  
***************
*** 76,82 ****
       VC_RECT_T src_rect;
  
       bcm_host_init();
- 
  #endif     
       egl->eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  
--- 76,81 ----
***************
*** 142,150 ****
       nativewindow.height  = egl->DisplayHeight;
       vc_dispmanx_update_submit_sync( dispman_update );
  
  #endif
  
-      egl->eglSurface = eglCreateWindowSurface( egl->eglDisplay, egl->eglConfig, &nativewindow, NULL );
       if (!TestEGLError("eglCreateWindowSurface"))
            return DFB_INIT;
  
--- 141,151 ----
       nativewindow.height  = egl->DisplayHeight;
       vc_dispmanx_update_submit_sync( dispman_update );
  
+      egl->eglSurface = eglCreateWindowSurface( egl->eglDisplay, egl->eglConfig, &nativewindow, NULL );
+ #else
+      egl->eglSurface = eglCreateWindowSurface( egl->eglDisplay, egl->eglConfig, EGL_DEFAULT_DISPLAY, NULL );
  #endif
  
       if (!TestEGLError("eglCreateWindowSurface"))
            return DFB_INIT;
  
