]> icculus.org git repositories - icculus/xz.git/blob - m4/tuklib_physmem.m4
Update tuklib_cpucores.m4 and tuklib_physmem.m4 from tuklib,
[icculus/xz.git] / m4 / tuklib_physmem.m4
1 #
2 # SYNOPSIS
3 #
4 #   TUKLIB_PHYSMEM
5 #
6 # DESCRIPTION
7 #
8 #   Check how to get the amount of physical memory.
9 #   This information is used in tuklib_physmem.c.
10 #
11 #   Supported methods:
12 #
13 #     - Windows (including Cygwin), OS/2, DJGPP (DOS), and OpenVMS have
14 #       operating-system specific functions.
15 #
16 #     - sysconf() works on GNU/Linux and Solaris, and possibly on
17 #       some BSDs.
18 #
19 #     - BSDs use sysctl().
20 #
21 #     - sysinfo() works on Linux/dietlibc and probably on other Linux
22 #       systems whose libc may lack sysconf().
23 #
24 # COPYING
25 #
26 #   Author: Lasse Collin
27 #
28 #   This file has been put into the public domain.
29 #   You can do whatever you want with this file.
30 #
31
32 AC_DEFUN_ONCE([TUKLIB_PHYSMEM], [
33 AC_REQUIRE([TUKLIB_COMMON])
34
35 # sys/param.h might be needed by sys/sysctl.h.
36 AC_CHECK_HEADERS([sys/param.h])
37
38 AC_CACHE_CHECK([how to detect the amount of physical memory],
39         [tuklib_cv_physmem_method], [
40
41 # Maybe checking $host_os would be enough but this matches what
42 # tuklib_physmem.c does.
43 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
44 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__OS2__) \
45                 || defined(__DJGPP__) || defined(__VMS)
46 int main(void) { return 0; }
47 #else
48 #error
49 #endif
50 ]])], [tuklib_cv_physmem_method=special], [
51
52 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
53 #include <unistd.h>
54 int
55 main(void)
56 {
57         long i;
58         i = sysconf(_SC_PAGESIZE);
59         i = sysconf(_SC_PHYS_PAGES);
60         return 0;
61 }
62 ]])], [tuklib_cv_physmem_method=sysconf], [
63
64 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
65 #include <sys/types.h>
66 #ifdef HAVE_SYS_PARAM_H
67 #       include <sys/param.h>
68 #endif
69 #include <sys/sysctl.h>
70 int
71 main(void)
72 {
73         int name[2] = { CTL_HW, HW_PHYSMEM };
74         unsigned long mem;
75         size_t mem_ptr_size = sizeof(mem);
76         sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0);
77         return 0;
78 }
79 ]])], [tuklib_cv_physmem_method=sysctl], [
80
81 # This version of sysinfo() is Linux-specific. Some non-Linux systems have
82 # different sysinfo() so we must check $host_os.
83 case $host_os in
84         linux*)
85                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
86 #include <sys/sysinfo.h>
87 int
88 main(void)
89 {
90         struct sysinfo si;
91         sysinfo(&si);
92         return 0;
93 }
94                 ]])], [
95                         tuklib_cv_physmem_method=sysinfo
96                 ], [
97                         tuklib_cv_physmem_method=unknown
98                 ])
99                 ;;
100         *)
101                 tuklib_cv_physmem_method=unknown
102                 ;;
103 esac
104 ])])])])
105 case $tuklib_cv_physmem_method in
106         sysconf)
107                 AC_DEFINE([TUKLIB_PHYSMEM_SYSCONF], [1],
108                         [Define to 1 if the amount of physical memory can
109                         be detected with sysconf(_SC_PAGESIZE) and
110                         sysconf(_SC_PHYS_PAGES).])
111                 ;;
112         sysctl)
113                 AC_DEFINE([TUKLIB_PHYSMEM_SYSCTL], [1],
114                         [Define to 1 if the amount of physical memory can
115                         be detected with sysctl().])
116                 ;;
117         sysinfo)
118                 AC_DEFINE([TUKLIB_PHYSMEM_SYSINFO], [1],
119                         [Define to 1 if the amount of physical memory
120                         can be detected with Linux sysinfo().])
121                 ;;
122 esac
123 ])dnl