Do not needlessly install and run doxygen on buildds
[xz/debian.git] / m4 / tuklib_physmem.m4
bloba8c869f3fda48ef40c6a0b1cf25331f2c8862015
2 # SYNOPSIS
4 #   TUKLIB_PHYSMEM
6 # DESCRIPTION
8 #   Check how to get the amount of physical memory.
9 #   This information is used in tuklib_physmem.c.
11 #   Supported methods:
13 #     - Windows (including Cygwin), OS/2, DJGPP (DOS), and OpenVMS have
14 #       operating-system specific functions.
16 #     - sysconf() works on GNU/Linux and Solaris, and possibly on
17 #       some BSDs.
19 #     - BSDs use sysctl().
21 #     - IRIX has setinvent_r(), getinvent_r(), and endinvent_r().
23 #     - sysinfo() works on Linux/dietlibc and probably on other Linux
24 #       systems whose libc may lack sysconf().
26 # COPYING
28 #   Author: Lasse Collin
30 #   This file has been put into the public domain.
31 #   You can do whatever you want with this file.
34 AC_DEFUN_ONCE([TUKLIB_PHYSMEM], [
35 AC_REQUIRE([TUKLIB_COMMON])
37 # sys/param.h might be needed by sys/sysctl.h.
38 AC_CHECK_HEADERS([sys/param.h])
40 AC_CACHE_CHECK([how to detect the amount of physical memory],
41         [tuklib_cv_physmem_method], [
43 # Maybe checking $host_os would be enough but this matches what
44 # tuklib_physmem.c does.
45 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
46 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__OS2__) \
47                 || defined(__DJGPP__) || defined(__VMS)
48 int main(void) { return 0; }
49 #else
50 #error
51 #endif
52 ]])], [tuklib_cv_physmem_method=special], [
54 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
55 #include <unistd.h>
56 int
57 main(void)
59         long i;
60         i = sysconf(_SC_PAGESIZE);
61         i = sysconf(_SC_PHYS_PAGES);
62         return 0;
64 ]])], [tuklib_cv_physmem_method=sysconf], [
66 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
67 #include <sys/types.h>
68 #ifdef HAVE_SYS_PARAM_H
69 #       include <sys/param.h>
70 #endif
71 #include <sys/sysctl.h>
72 int
73 main(void)
75         int name[2] = { CTL_HW, HW_PHYSMEM };
76         unsigned long mem;
77         size_t mem_ptr_size = sizeof(mem);
78         sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0);
79         return 0;
81 ]])], [tuklib_cv_physmem_method=sysctl], [
83 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
84 #include <invent.h>
85 int
86 main(void)
88         inv_state_t *st = NULL;
89         setinvent_r(&st);
90         getinvent_r(st);
91         endinvent_r(st);
92         return 0;
94 ]])], [tuklib_cv_physmem_method=getinvent_r], [
96 # This version of sysinfo() is Linux-specific. Some non-Linux systems have
97 # different sysinfo() so we must check $host_os.
98 case $host_os in
99         linux*)
100                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
101 #include <sys/sysinfo.h>
103 main(void)
105         struct sysinfo si;
106         sysinfo(&si);
107         return 0;
109                 ]])], [
110                         tuklib_cv_physmem_method=sysinfo
111                 ], [
112                         tuklib_cv_physmem_method=unknown
113                 ])
114                 ;;
115         *)
116                 tuklib_cv_physmem_method=unknown
117                 ;;
118 esac
119 ])])])])])
120 case $tuklib_cv_physmem_method in
121         sysconf)
122                 AC_DEFINE([TUKLIB_PHYSMEM_SYSCONF], [1],
123                         [Define to 1 if the amount of physical memory can
124                         be detected with sysconf(_SC_PAGESIZE) and
125                         sysconf(_SC_PHYS_PAGES).])
126                 ;;
127         sysctl)
128                 AC_DEFINE([TUKLIB_PHYSMEM_SYSCTL], [1],
129                         [Define to 1 if the amount of physical memory can
130                         be detected with sysctl().])
131                 ;;
132         getinvent_r)
133                 AC_DEFINE([TUKLIB_PHYSMEM_GETINVENT_R], [1],
134                         [Define to 1 if the amount of physical memory
135                         can be detected with getinvent_r().])
136                 ;;
137         sysinfo)
138                 AC_DEFINE([TUKLIB_PHYSMEM_SYSINFO], [1],
139                         [Define to 1 if the amount of physical memory
140                         can be detected with Linux sysinfo().])
141                 ;;
142 esac
143 ])dnl