8 # Check how to get the amount of physical memory.
9 # This information is used in tuklib_physmem.c.
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
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().
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; }
52 ]])], [tuklib_cv_physmem_method=special], [
54 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
60 i = sysconf(_SC_PAGESIZE);
61 i = sysconf(_SC_PHYS_PAGES);
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>
71 #include <sys/sysctl.h>
75 int name[2] = { CTL_HW, HW_PHYSMEM };
77 size_t mem_ptr_size = sizeof(mem);
78 sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0);
81 ]])], [tuklib_cv_physmem_method=sysctl], [
83 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
88 inv_state_t *st = NULL;
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.
100 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
101 #include <sys/sysinfo.h>
110 tuklib_cv_physmem_method=sysinfo
112 tuklib_cv_physmem_method=unknown
116 tuklib_cv_physmem_method=unknown
120 case $tuklib_cv_physmem_method in
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).])
128 AC_DEFINE([TUKLIB_PHYSMEM_SYSCTL], [1],
129 [Define to 1 if the amount of physical memory can
130 be detected with sysctl().])
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().])
138 AC_DEFINE([TUKLIB_PHYSMEM_SYSINFO], [1],
139 [Define to 1 if the amount of physical memory
140 can be detected with Linux sysinfo().])