tuklib_physmem.m4 revision 1.1 1 1.1 joerg #
2 1.1 joerg # SYNOPSIS
3 1.1 joerg #
4 1.1 joerg # TUKLIB_PHYSMEM
5 1.1 joerg #
6 1.1 joerg # DESCRIPTION
7 1.1 joerg #
8 1.1 joerg # Check how to get the amount of physical memory.
9 1.1 joerg # This information is used in tuklib_physmem.c.
10 1.1 joerg #
11 1.1 joerg # Supported methods:
12 1.1 joerg #
13 1.1 joerg # - Windows (including Cygwin), OS/2, DJGPP (DOS), and OpenVMS have
14 1.1 joerg # operating-system specific functions.
15 1.1 joerg #
16 1.1 joerg # - AIX has _system_configuration.physmem.
17 1.1 joerg #
18 1.1 joerg # - sysconf() works on GNU/Linux and Solaris, and possibly on
19 1.1 joerg # some BSDs.
20 1.1 joerg #
21 1.1 joerg # - BSDs use sysctl().
22 1.1 joerg #
23 1.1 joerg # - Tru64 uses getsysinfo().
24 1.1 joerg #
25 1.1 joerg # - HP-UX uses pstat_getstatic().
26 1.1 joerg #
27 1.1 joerg # - IRIX has setinvent_r(), getinvent_r(), and endinvent_r().
28 1.1 joerg #
29 1.1 joerg # - sysinfo() works on Linux/dietlibc and probably on other Linux
30 1.1 joerg # systems whose libc may lack sysconf().
31 1.1 joerg #
32 1.1 joerg # COPYING
33 1.1 joerg #
34 1.1 joerg # Author: Lasse Collin
35 1.1 joerg #
36 1.1 joerg # This file has been put into the public domain.
37 1.1 joerg # You can do whatever you want with this file.
38 1.1 joerg #
39 1.1 joerg
40 1.1 joerg AC_DEFUN_ONCE([TUKLIB_PHYSMEM], [
41 1.1 joerg AC_REQUIRE([TUKLIB_COMMON])
42 1.1 joerg
43 1.1 joerg # sys/param.h might be needed by sys/sysctl.h.
44 1.1 joerg AC_CHECK_HEADERS([sys/param.h])
45 1.1 joerg
46 1.1 joerg AC_CACHE_CHECK([how to detect the amount of physical memory],
47 1.1 joerg [tuklib_cv_physmem_method], [
48 1.1 joerg
49 1.1 joerg # Maybe checking $host_os would be enough but this matches what
50 1.1 joerg # tuklib_physmem.c does.
51 1.1 joerg #
52 1.1 joerg # NOTE: IRIX has a compiler that doesn't error out with #error, so use
53 1.1 joerg # a non-compilable text instead of #error to generate an error.
54 1.1 joerg AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
55 1.1 joerg #if defined(_WIN32) || defined(__CYGWIN__) || defined(__OS2__) \
56 1.1 joerg || defined(__DJGPP__) || defined(__VMS)
57 1.1 joerg int main(void) { return 0; }
58 1.1 joerg #else
59 1.1 joerg compile error
60 1.1 joerg #endif
61 1.1 joerg ]])], [tuklib_cv_physmem_method=special], [
62 1.1 joerg
63 1.1 joerg # Look for AIX-specific solution before sysconf(), because the test
64 1.1 joerg # for sysconf() will pass on AIX but won't actually work
65 1.1 joerg # (sysconf(_SC_PHYS_PAGES) compiles but always returns -1 on AIX).
66 1.1 joerg AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
67 1.1 joerg #include <sys/systemcfg.h>
68 1.1 joerg
69 1.1 joerg int
70 1.1 joerg main(void)
71 1.1 joerg {
72 1.1 joerg (void)_system_configuration.physmem;
73 1.1 joerg return 0;
74 1.1 joerg }
75 1.1 joerg ]])], [tuklib_cv_physmem_method=aix], [
76 1.1 joerg
77 1.1 joerg AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
78 1.1 joerg #include <unistd.h>
79 1.1 joerg int
80 1.1 joerg main(void)
81 1.1 joerg {
82 1.1 joerg long i;
83 1.1 joerg i = sysconf(_SC_PAGESIZE);
84 1.1 joerg i = sysconf(_SC_PHYS_PAGES);
85 1.1 joerg return 0;
86 1.1 joerg }
87 1.1 joerg ]])], [tuklib_cv_physmem_method=sysconf], [
88 1.1 joerg
89 1.1 joerg AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
90 1.1 joerg #include <sys/types.h>
91 1.1 joerg #ifdef HAVE_SYS_PARAM_H
92 1.1 joerg # include <sys/param.h>
93 1.1 joerg #endif
94 1.1 joerg #include <sys/sysctl.h>
95 1.1 joerg int
96 1.1 joerg main(void)
97 1.1 joerg {
98 1.1 joerg int name[2] = { CTL_HW, HW_PHYSMEM };
99 1.1 joerg unsigned long mem;
100 1.1 joerg size_t mem_ptr_size = sizeof(mem);
101 1.1 joerg sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0);
102 1.1 joerg return 0;
103 1.1 joerg }
104 1.1 joerg ]])], [tuklib_cv_physmem_method=sysctl], [
105 1.1 joerg
106 1.1 joerg AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
107 1.1 joerg #include <sys/sysinfo.h>
108 1.1 joerg #include <machine/hal_sysinfo.h>
109 1.1 joerg
110 1.1 joerg int
111 1.1 joerg main(void)
112 1.1 joerg {
113 1.1 joerg int memkb;
114 1.1 joerg int start = 0;
115 1.1 joerg getsysinfo(GSI_PHYSMEM, (caddr_t)&memkb, sizeof(memkb), &start);
116 1.1 joerg return 0;
117 1.1 joerg }
118 1.1 joerg ]])], [tuklib_cv_physmem_method=getsysinfo],[
119 1.1 joerg
120 1.1 joerg AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
121 1.1 joerg #include <sys/param.h>
122 1.1 joerg #include <sys/pstat.h>
123 1.1 joerg
124 1.1 joerg int
125 1.1 joerg main(void)
126 1.1 joerg {
127 1.1 joerg struct pst_static pst;
128 1.1 joerg pstat_getstatic(&pst, sizeof(pst), 1, 0);
129 1.1 joerg (void)pst.physical_memory;
130 1.1 joerg (void)pst.page_size;
131 1.1 joerg return 0;
132 1.1 joerg }
133 1.1 joerg ]])], [tuklib_cv_physmem_method=pstat_getstatic],[
134 1.1 joerg
135 1.1 joerg AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
136 1.1 joerg #include <invent.h>
137 1.1 joerg int
138 1.1 joerg main(void)
139 1.1 joerg {
140 1.1 joerg inv_state_t *st = NULL;
141 1.1 joerg setinvent_r(&st);
142 1.1 joerg getinvent_r(st);
143 1.1 joerg endinvent_r(st);
144 1.1 joerg return 0;
145 1.1 joerg }
146 1.1 joerg ]])], [tuklib_cv_physmem_method=getinvent_r], [
147 1.1 joerg
148 1.1 joerg # This version of sysinfo() is Linux-specific. Some non-Linux systems have
149 1.1 joerg # different sysinfo() so we must check $host_os.
150 1.1 joerg case $host_os in
151 1.1 joerg linux*)
152 1.1 joerg AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
153 1.1 joerg #include <sys/sysinfo.h>
154 1.1 joerg int
155 1.1 joerg main(void)
156 1.1 joerg {
157 1.1 joerg struct sysinfo si;
158 1.1 joerg sysinfo(&si);
159 1.1 joerg return 0;
160 1.1 joerg }
161 1.1 joerg ]])], [
162 1.1 joerg tuklib_cv_physmem_method=sysinfo
163 1.1 joerg ], [
164 1.1 joerg tuklib_cv_physmem_method=unknown
165 1.1 joerg ])
166 1.1 joerg ;;
167 1.1 joerg *)
168 1.1 joerg tuklib_cv_physmem_method=unknown
169 1.1 joerg ;;
170 1.1 joerg esac
171 1.1 joerg ])])])])])])])])
172 1.1 joerg
173 1.1 joerg case $tuklib_cv_physmem_method in
174 1.1 joerg aix)
175 1.1 joerg AC_DEFINE([TUKLIB_PHYSMEM_AIX], [1],
176 1.1 joerg [Define to 1 if the amount of physical memory
177 1.1 joerg can be detected with _system_configuration.physmem.])
178 1.1 joerg ;;
179 1.1 joerg sysconf)
180 1.1 joerg AC_DEFINE([TUKLIB_PHYSMEM_SYSCONF], [1],
181 1.1 joerg [Define to 1 if the amount of physical memory can
182 1.1 joerg be detected with sysconf(_SC_PAGESIZE) and
183 1.1 joerg sysconf(_SC_PHYS_PAGES).])
184 1.1 joerg ;;
185 1.1 joerg sysctl)
186 1.1 joerg AC_DEFINE([TUKLIB_PHYSMEM_SYSCTL], [1],
187 1.1 joerg [Define to 1 if the amount of physical memory can
188 1.1 joerg be detected with sysctl().])
189 1.1 joerg ;;
190 1.1 joerg getsysinfo)
191 1.1 joerg AC_DEFINE([TUKLIB_PHYSMEM_GETSYSINFO], [1],
192 1.1 joerg [Define to 1 if the amount of physical memory can
193 1.1 joerg be detected with getsysinfo().])
194 1.1 joerg ;;
195 1.1 joerg pstat_getstatic)
196 1.1 joerg AC_DEFINE([TUKLIB_PHYSMEM_PSTAT_GETSTATIC], [1],
197 1.1 joerg [Define to 1 if the amount of physical memory can
198 1.1 joerg be detected with pstat_getstatic().])
199 1.1 joerg ;;
200 1.1 joerg getinvent_r)
201 1.1 joerg AC_DEFINE([TUKLIB_PHYSMEM_GETINVENT_R], [1],
202 1.1 joerg [Define to 1 if the amount of physical memory
203 1.1 joerg can be detected with getinvent_r().])
204 1.1 joerg ;;
205 1.1 joerg sysinfo)
206 1.1 joerg AC_DEFINE([TUKLIB_PHYSMEM_SYSINFO], [1],
207 1.1 joerg [Define to 1 if the amount of physical memory
208 1.1 joerg can be detected with Linux sysinfo().])
209 1.1 joerg ;;
210 1.1 joerg esac
211 1.1 joerg ])dnl
212