about summary refs log tree commit diff
path: root/pkgs/development/libraries/libdrm
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2011-08-29 18:55:37 +0000
committerShea Levy <shea@shealevy.com>2011-08-29 18:55:37 +0000
commite309c50e7e0027ca642b2c8dadfd42f462fd8d2e (patch)
treeebada08409b581481e360401ad52681c3c4f3b95 /pkgs/development/libraries/libdrm
parent41f39c4a2276fa77ffa7d8b9288d0e52ee17fadf (diff)
downloadnixlib-e309c50e7e0027ca642b2c8dadfd42f462fd8d2e.tar
nixlib-e309c50e7e0027ca642b2c8dadfd42f462fd8d2e.tar.gz
nixlib-e309c50e7e0027ca642b2c8dadfd42f462fd8d2e.tar.bz2
nixlib-e309c50e7e0027ca642b2c8dadfd42f462fd8d2e.tar.lz
nixlib-e309c50e7e0027ca642b2c8dadfd42f462fd8d2e.tar.xz
nixlib-e309c50e7e0027ca642b2c8dadfd42f462fd8d2e.tar.zst
nixlib-e309c50e7e0027ca642b2c8dadfd42f462fd8d2e.zip
Get libdrm to compile on darwin
The added patch uses mach_absolute_time() to get a nanosecond-resolution monotonic clock on darwin systems (See http://developer.apple.com/library/mac/#qa/qa1398/_index.html for an understanding of the added code). In addition, the patch changes one use of clock_gettime to gettimeofday since only resolution of a second is needed at that point. This code compiles on darwin, but the resulting library is not yet tested.

svn path=/nixpkgs/trunk/; revision=28879
Diffstat (limited to 'pkgs/development/libraries/libdrm')
-rw-r--r--pkgs/development/libraries/libdrm/default.nix9
-rw-r--r--pkgs/development/libraries/libdrm/libdrm-apple.patch88
2 files changed, 94 insertions, 3 deletions
diff --git a/pkgs/development/libraries/libdrm/default.nix b/pkgs/development/libraries/libdrm/default.nix
index ad6f45366041..d37b7dd0b7fb 100644
--- a/pkgs/development/libraries/libdrm/default.nix
+++ b/pkgs/development/libraries/libdrm/default.nix
@@ -1,6 +1,6 @@
 {stdenv, fetchurl, pkgconfig, libpthreadstubs}:
 
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (rec {
   name = "libdrm-2.4.24";
   
   src = fetchurl {
@@ -10,16 +10,19 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ pkgconfig libpthreadstubs ];
 
+  patches = [ ./libdrm-apple.patch ];
+
   preConfigure = ''
     # General case: non intel.
     if test -n "$crossConfig"; then
       configureFlags="$configureFlags --disable-intel";
     fi
-  '';
+  '' + stdenv.lib.optionalString stdenv.isDarwin
+  "echo : \\\${ac_cv_func_clock_gettime=\'yes\'} > config.cache";
 
   meta = {
     homepage = http://dri.freedesktop.org/libdrm/;
     description = "Library for accessing the kernel's Direct Rendering Manager";
     license = "bsd";
   };
-}
+} // (stdenv.lib.optionalAttrs stdenv.isDarwin { configureFlags = [ "-C" ]; }))
diff --git a/pkgs/development/libraries/libdrm/libdrm-apple.patch b/pkgs/development/libraries/libdrm/libdrm-apple.patch
new file mode 100644
index 000000000000..e9fd63c5faec
--- /dev/null
+++ b/pkgs/development/libraries/libdrm/libdrm-apple.patch
@@ -0,0 +1,88 @@
+diff -Naur libdrm-2.4.26-orig/intel/intel_bufmgr_gem.c libdrm-2.4.26/intel/intel_bufmgr_gem.c
+--- libdrm-2.4.26-orig/intel/intel_bufmgr_gem.c	2011-04-01 10:30:51.000000000 -0400
++++ libdrm-2.4.26/intel/intel_bufmgr_gem.c	2011-08-29 02:17:20.000000000 -0400
+@@ -51,6 +51,7 @@
+ #include <sys/mman.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
++#include <sys/time.h>
+ 
+ #include "errno.h"
+ #include "libdrm_lists.h"
+@@ -987,9 +988,9 @@
+ 	if (atomic_dec_and_test(&bo_gem->refcount)) {
+ 		drm_intel_bufmgr_gem *bufmgr_gem =
+ 		    (drm_intel_bufmgr_gem *) bo->bufmgr;
+-		struct timespec time;
++		struct timeval time;
+ 
+-		clock_gettime(CLOCK_MONOTONIC, &time);
++		gettimeofday(&time, NULL);
+ 
+ 		pthread_mutex_lock(&bufmgr_gem->lock);
+ 		drm_intel_gem_bo_unreference_final(bo, time.tv_sec);
+diff -Naur libdrm-2.4.26-orig/xf86drm.c libdrm-2.4.26/xf86drm.c
+--- libdrm-2.4.26-orig/xf86drm.c	2011-03-21 09:39:24.000000000 -0400
++++ libdrm-2.4.26/xf86drm.c	2011-08-29 02:17:49.000000000 -0400
+@@ -51,6 +51,9 @@
+ #include <sys/mman.h>
+ #include <sys/time.h>
+ #include <stdarg.h>
++#if defined(__APPLE__) && defined(__MACH__)
++#include <mach/mach_time.h>
++#endif
+ 
+ /* Not all systems have MAP_FAILED defined */
+ #ifndef MAP_FAILED
+@@ -1941,20 +1944,43 @@
+  */
+ int drmWaitVBlank(int fd, drmVBlankPtr vbl)
+ {
++#if defined(__APPLE__) && defined(__MACH__)
++    uint64_t start, end, elapsed, elapsedNano;
++    static const uint64_t maxElapsed = 2000000000;
++    static mach_timebase_info_data_t timebaseInfo;
++    if ( timebaseInfo.denom == 0 ) {
++	(void) mach_timebase_info(&timebaseInfo);
++    }
++#else
+     struct timespec timeout, cur;
++#endif
+     int ret;
+ 
++#if defined(__APPLE__) && defined(__MACH__)
++    start = mach_absolute_time();
++#else
+     ret = clock_gettime(CLOCK_MONOTONIC, &timeout);
+     if (ret < 0) {
+ 	fprintf(stderr, "clock_gettime failed: %s\n", strerror(ret));
+ 	goto out;
+     }
+     timeout.tv_sec++;
++#endif
+ 
+     do {
+        ret = ioctl(fd, DRM_IOCTL_WAIT_VBLANK, vbl);
+        vbl->request.type &= ~DRM_VBLANK_RELATIVE;
+        if (ret && errno == EINTR) {
++#if defined(__APPLE__) && defined(__MACH__)
++	       end = mach_absolute_time();
++	       elapsed = end - start;
++	       elapsedNano = elapsed * timebaseInfo.numer / timebaseInfo.denom;
++	       if (elapsedNano > maxElapsed) {
++		   errno = EBUSY;
++		   ret = -1;
++		   break;
++	       }
++#else
+ 	       clock_gettime(CLOCK_MONOTONIC, &cur);
+ 	       /* Timeout after 1s */
+ 	       if (cur.tv_sec > timeout.tv_sec + 1 ||
+@@ -1964,6 +1990,7 @@
+ 		       ret = -1;
+ 		       break;
+ 	       }
++#endif
+        }
+     } while (ret && errno == EINTR);
+