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
This commit is contained in:
parent
41f39c4a22
commit
e309c50e7e
@ -1,6 +1,6 @@
|
|||||||
{stdenv, fetchurl, pkgconfig, libpthreadstubs}:
|
{stdenv, fetchurl, pkgconfig, libpthreadstubs}:
|
||||||
|
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation (rec {
|
||||||
name = "libdrm-2.4.24";
|
name = "libdrm-2.4.24";
|
||||||
|
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
@ -10,16 +10,19 @@ stdenv.mkDerivation rec {
|
|||||||
|
|
||||||
buildInputs = [ pkgconfig libpthreadstubs ];
|
buildInputs = [ pkgconfig libpthreadstubs ];
|
||||||
|
|
||||||
|
patches = [ ./libdrm-apple.patch ];
|
||||||
|
|
||||||
preConfigure = ''
|
preConfigure = ''
|
||||||
# General case: non intel.
|
# General case: non intel.
|
||||||
if test -n "$crossConfig"; then
|
if test -n "$crossConfig"; then
|
||||||
configureFlags="$configureFlags --disable-intel";
|
configureFlags="$configureFlags --disable-intel";
|
||||||
fi
|
fi
|
||||||
'';
|
'' + stdenv.lib.optionalString stdenv.isDarwin
|
||||||
|
"echo : \\\${ac_cv_func_clock_gettime=\'yes\'} > config.cache";
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
homepage = http://dri.freedesktop.org/libdrm/;
|
homepage = http://dri.freedesktop.org/libdrm/;
|
||||||
description = "Library for accessing the kernel's Direct Rendering Manager";
|
description = "Library for accessing the kernel's Direct Rendering Manager";
|
||||||
license = "bsd";
|
license = "bsd";
|
||||||
};
|
};
|
||||||
}
|
} // (stdenv.lib.optionalAttrs stdenv.isDarwin { configureFlags = [ "-C" ]; }))
|
||||||
|
88
pkgs/development/libraries/libdrm/libdrm-apple.patch
Normal file
88
pkgs/development/libraries/libdrm/libdrm-apple.patch
Normal file
@ -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);
|
||||||
|
|
@ -3724,10 +3724,10 @@ let
|
|||||||
|
|
||||||
libdmtx = callPackage ../development/libraries/libdmtx { };
|
libdmtx = callPackage ../development/libraries/libdmtx { };
|
||||||
|
|
||||||
libdrm = if stdenv.isDarwin then null else (callPackage ../development/libraries/libdrm {
|
libdrm = callPackage ../development/libraries/libdrm {
|
||||||
inherit fetchurl stdenv pkgconfig;
|
inherit fetchurl stdenv pkgconfig;
|
||||||
inherit (xorg) libpthreadstubs;
|
inherit (xorg) libpthreadstubs;
|
||||||
});
|
};
|
||||||
|
|
||||||
libdv = callPackage ../development/libraries/libdv { };
|
libdv = callPackage ../development/libraries/libdv { };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user