]> icculus.org git repositories - icculus/xz.git/blob - m4/tuklib_physmem.m4
Various changes.
[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_MSG_CHECKING([how to detect the amount of physical memory])
39
40 # Maybe checking $host_os would be enough but this matches what
41 # tuklib_physmem.c does.
42 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
43 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__OS2__) \
44                 || defined(__DJGPP__) || defined(__VMS)
45 int main(void) { return 0; }
46 #else
47 #error
48 #endif
49 ]])], [
50         AC_MSG_RESULT([special])
51 ], [
52
53 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
54 #include <unistd.h>
55 int
56 main(void)
57 {
58         long i;
59         i = sysconf(_SC_PAGESIZE);
60         i = sysconf(_SC_PHYS_PAGES);
61         return 0;
62 }
63 ]])], [
64         AC_DEFINE([TUKLIB_PHYSMEM_SYSCONF], [1],
65                 [Define to 1 if the amount of physical memory can be detected
66                 with sysconf(_SC_PAGESIZE) and sysconf(_SC_PHYS_PAGES).])
67         AC_MSG_RESULT([sysconf])
68 ], [
69
70 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
71 #include <sys/types.h>
72 #ifdef HAVE_SYS_PARAM_H
73 #       include <sys/param.h>
74 #endif
75 #include <sys/sysctl.h>
76 int
77 main(void)
78 {
79         int name[2] = { CTL_HW, HW_PHYSMEM };
80         unsigned long mem;
81         size_t mem_ptr_size = sizeof(mem);
82         sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0);
83         return 0;
84 }
85 ]])], [
86         AC_DEFINE([TUKLIB_PHYSMEM_SYSCTL], [1],
87                 [Define to 1 if the amount of physical memory can be detected
88                 with sysctl().])
89         AC_MSG_RESULT([sysctl])
90 ], [
91
92 # This version of sysinfo() is Linux-specific. Some non-Linux systems have
93 # different sysinfo() so we must check $host_os.
94 case $host_os in
95         linux*)
96                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
97 #include <sys/sysinfo.h>
98 int
99 main(void)
100 {
101         struct sysinfo si;
102         sysinfo(&si);
103         return 0;
104 }
105                 ]])], [
106                         AC_DEFINE([TUKLIB_PHYSMEM_SYSINFO], [1],
107                                 [Define to 1 if the amount of physical memory
108                                 can be detected with Linux sysinfo().])
109                         AC_MSG_RESULT([sysinfo])
110                 ], [
111                         AC_MSG_RESULT([unknown])
112                 ])
113                 ;;
114         *)
115                 AC_MSG_RESULT([unknown])
116                 ;;
117 esac
118 ])])])
119 ])dnl