]> icculus.org git repositories - icculus/xz.git/blob - m4/lc_physmem.m4
Major documentation update.
[icculus/xz.git] / m4 / lc_physmem.m4
1 dnl ###########################################################################
2 dnl
3 dnl lc_PHYSMEM - Check how to find out the amount of physical memory
4 dnl
5 dnl - sysconf() gives all the needed info on GNU+Linux and Solaris.
6 dnl - BSDs use sysctl().
7 dnl - sysinfo() works on Linux/dietlibc and probably on other Linux systems
8 dnl   whose libc may lack sysconf().
9 dnl
10 dnl ###########################################################################
11 dnl
12 dnl Author: Lasse Collin
13 dnl
14 dnl This file has been put into the public domain.
15 dnl You can do whatever you want with this file.
16 dnl
17 dnl ###########################################################################
18 AC_DEFUN([lc_PHYSMEM], [
19 AC_MSG_CHECKING([how to detect the amount of physical memory])
20 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
21 #include <unistd.h>
22 int
23 main(void)
24 {
25         long i;
26         i = sysconf(_SC_PAGESIZE);
27         i = sysconf(_SC_PHYS_PAGES);
28         return 0;
29 }
30 ]])], [
31         AC_DEFINE([HAVE_PHYSMEM_SYSCONF], [1],
32                 [Define to 1 if the amount of physical memory can be detected
33                 with sysconf(_SC_PAGESIZE) and sysconf(_SC_PHYS_PAGES).])
34         AC_MSG_RESULT([sysconf])
35 ], [
36 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_PARAM_H
39 #       include <sys/param.h>
40 #endif
41 #include <sys/sysctl.h>
42 int
43 main(void)
44 {
45         int name[2] = { CTL_HW, HW_PHYSMEM };
46         unsigned long mem;
47         size_t mem_ptr_size = sizeof(mem);
48         sysctl(name, 2, &mem, &mem_ptr_size, NULL, NULL);
49         return 0;
50 }
51 ]])], [
52         AC_DEFINE([HAVE_PHYSMEM_SYSCTL], [1],
53                 [Define to 1 if the amount of physical memory can be detected
54                 with sysctl().])
55         AC_MSG_RESULT([sysctl])
56 ], [
57 dnl sysinfo() is Linux-specific. Some non-Linux systems have
58 dnl incompatible sysinfo() so we must check $host_os.
59 case $host_os in
60         linux*)
61                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
62 #include <sys/sysinfo.h>
63 int
64 main(void)
65 {
66         struct sysinfo si;
67         sysinfo(&si);
68         return 0;
69 }
70                 ]])], [
71                         AC_DEFINE([HAVE_PHYSMEM_SYSINFO], [1],
72                                 [Define to 1 if the amount of physical memory
73                                 can be detected with Linux sysinfo().])
74                         AC_MSG_RESULT([sysinfo])
75                 ], [
76                         AC_MSG_RESULT([unknown])
77                 ])
78                 ;;
79         *)
80                 AC_MSG_RESULT([unknown])
81                 ;;
82 esac
83 ])])
84 ])dnl lc_PHYSMEM