fix build on non-Linux glibc systems
authorPino Toscano <pino@debian.org>
Sat, 29 Dec 2012 22:32:27 +0000 (14:32 -0800)
committerEvan Martin <martine@danga.com>
Sat, 29 Dec 2012 22:32:27 +0000 (14:32 -0800)
ninja-build does not build on non-Linux archs, such as
GNU/kFreeBSD and GNU/Hurd.

The problem is that the GetProcessorCount() implementation for these
architectures is the sysconf() one, but <unistd.h> has not been
included, causing sysconf() and _SC_NPROCESSORS_ONLN to not be
declared. Another solution (which is the one I chose) is to make use
of the "linux" implementation which uses get_nprocs(), which is a GNU
extension and thus available for anything using GNU libc.

src/util.cc

index 4b2900f..50e3842 100644 (file)
@@ -39,7 +39,7 @@
 #elif defined(__SVR4) && defined(__sun)
 #include <unistd.h>
 #include <sys/loadavg.h>
-#elif defined(linux)
+#elif defined(linux) || defined(__GLIBC__)
 #include <sys/sysinfo.h>
 #endif
 
@@ -295,7 +295,7 @@ string StripAnsiEscapeCodes(const string& in) {
   return stripped;
 }
 
-#if defined(linux)
+#if defined(linux) || defined(__GLIBC__)
 int GetProcessorCount() {
   return get_nprocs();
 }