Clarify xzdec package description and NEWS entry
[xz/debian.git] / m4 / tuklib_cpucores.m4
blobd48f2e5e368179fef306884cc31de9c3281f29da
2 # SYNOPSIS
4 #   TUKLIB_CPUCORES
6 # DESCRIPTION
8 #   Check how to find out the number of available CPU cores in the system.
9 #   This information is used by tuklib_cpucores.c.
11 #   Currently this supports sysctl() (BSDs, OS/2) and sysconf() (GNU/Linux,
12 #   Solaris, IRIX, Cygwin).
14 # COPYING
16 #   Author: Lasse Collin
18 #   This file has been put into the public domain.
19 #   You can do whatever you want with this file.
22 AC_DEFUN_ONCE([TUKLIB_CPUCORES], [
23 AC_REQUIRE([TUKLIB_COMMON])
25 # sys/param.h might be needed by sys/sysctl.h.
26 AC_CHECK_HEADERS([sys/param.h])
28 AC_CACHE_CHECK([how to detect the number of available CPU cores],
29         [tuklib_cv_cpucores_method], [
31 # Look for sysctl() solution first, because on OS/2, both sysconf()
32 # and sysctl() pass the tests in this file, but only sysctl()
33 # actually works.
34 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
35 #include <sys/types.h>
36 #ifdef HAVE_SYS_PARAM_H
37 #       include <sys/param.h>
38 #endif
39 #include <sys/sysctl.h>
40 int
41 main(void)
43         int name[2] = { CTL_HW, HW_NCPU };
44         int cpus;
45         size_t cpus_size = sizeof(cpus);
46         sysctl(name, 2, &cpus, &cpus_size, NULL, 0);
47         return 0;
49 ]])], [tuklib_cv_cpucores_method=sysctl], [
51 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
52 #include <unistd.h>
53 int
54 main(void)
56         long i;
57 #ifdef _SC_NPROCESSORS_ONLN
58         /* Many systems using sysconf() */
59         i = sysconf(_SC_NPROCESSORS_ONLN);
60 #else
61         /* IRIX */
62         i = sysconf(_SC_NPROC_ONLN);
63 #endif
64         return 0;
66 ]])], [
67         tuklib_cv_cpucores_method=sysconf
68 ], [
69         tuklib_cv_cpucores_method=unknown
70 ])])])
71 case $tuklib_cv_cpucores_method in
72         sysctl)
73                 AC_DEFINE([TUKLIB_CPUCORES_SYSCTL], [1],
74                         [Define to 1 if the number of available CPU cores
75                         can be detected with sysctl().])
76                 ;;
77         sysconf)
78                 AC_DEFINE([TUKLIB_CPUCORES_SYSCONF], [1],
79                         [Define to 1 if the number of available CPU cores
80                         can be detected with sysconf(_SC_NPROCESSORS_ONLN)
81                         or sysconf(_SC_NPROC_ONLN).])
82                 ;;
83 esac
84 ])dnl