[PATCH] xvid-1.2.2 compilation patch for Darwin

Fabian Groffen <[email protected]>
Newsgroups gmane.comp.video.xvid.devel
Organization Gentoo Foundation, Inc.
Message-ID <[email protected]>
Compilation fails this way:

>>> Compiling source in /Library/Gentoo/var/tmp/portage/media-libs/xvid-1.2.2-r1/work/xvidcore/build/generic ...
make -j2
  D: =build
  C: ./decoder.c
  C: ./encoder.c
  C: ./xvid.c
../../src/xvid.c: In function ‘xvid_gbl_info’:
../../src/xvid.c:682: error: ‘_SC_NPROCESSORS_CONF’ undeclared (first use in this function)
../../src/xvid.c:682: error: (Each undeclared identifier is reported only once 
../../src/xvid.c:682: error: for each function it appears in.)
make: *** [xvid.o] Error 1
make: *** Waiting for unfinished jobs....
 * ERROR: media-libs/xvid-1.2.2-r1 failed:
 *   emake failed

The attached patch fixes the issue for Darwin to retrieve the number of
CPUs via sysctl.  This should also work for BSD, but I couldn't try
that.  Additionally, the patch avoids failing during compilation by
assuming a single CPU in case there is no known way to retrieve the
number of CPUs.

Patch tested on OSX 10.4/ppc and 10.5/x86.


-- 
Fabian Groffen
Gentoo on a different level

_______________________________________________
Xvid-devel mailing list
[email protected]
http://list.xvid.org/mailman/listinfo/xvid-devel
xvid-1.2.1-ncpu.patch (text/plain, 1 KB)
http://archives.gentoo.org/gentoo-alt/msg_a2a7a3392b8ebca0207ca06ca755a38f.xml

--- src/xvid.c.orig	2009-02-28 00:13:41 -0600
+++ src/xvid.c	2009-02-28 00:13:45 -0600
@@ -32,6 +32,17 @@
   #include <unistd.h>
 #endif
 
+#if defined(__APPLE__) && defined(__MACH__)
+#  include <sys/types.h>
+#  include <sys/sysctl.h>
+#  ifdef MAX
+#    undef MAX
+#  endif
+#  ifdef MIN
+#    undef MIN
+#  endif
+#endif
+
 #include "xvid.h"
 #include "decoder.h"
 #include "encoder.h"
@@ -677,10 +682,29 @@
 	info->num_threads = siSysInfo.dwNumberOfProcessors; /* number of _logical_ cores */
   }
 
-#else
+#elif defined(__APPLE__) && defined(__MACH__)
+
+  {
+    size_t len;
+    int    mib[2], ncpu;
+
+    mib[0] = CTL_HW;
+    mib[1] = HW_NCPU;
+    len    = sizeof(ncpu);
+    if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == 0)
+      info -> num_threads = ncpu;
+    else
+      info -> num_threads = 1;
+  }
+
+#elif defined(_SC_NPROCESSORS_CONF)
 
   info->num_threads = sysconf(_SC_NPROCESSORS_CONF);	
 
+#else
+
+  info->num_threads = 1;
+
 #endif
 
 	return 0;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.