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 # - sysinfo() works on Linux/dietlibc and probably on other Linux
22 # systems whose libc may lack sysconf().
26 # Author: Lasse Collin
28 # This file has been put into the public domain.
29 # You can do whatever you want with this file.
32 AC_DEFUN_ONCE([TUKLIB_PHYSMEM], [
33 AC_REQUIRE([TUKLIB_COMMON])
35 # sys/param.h might be needed by sys/sysctl.h.
36 AC_CHECK_HEADERS([sys/param.h])
38 AC_MSG_CHECKING([how to detect the amount of physical memory])
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; }
50 AC_MSG_RESULT([special])
53 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
59 i = sysconf(_SC_PAGESIZE);
60 i = sysconf(_SC_PHYS_PAGES);
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])
70 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
71 #include <sys/types.h>
72 #ifdef HAVE_SYS_PARAM_H
73 # include <sys/param.h>
75 #include <sys/sysctl.h>
79 int name[2] = { CTL_HW, HW_PHYSMEM };
81 size_t mem_ptr_size = sizeof(mem);
82 sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0);
86 AC_DEFINE([TUKLIB_PHYSMEM_SYSCTL], [1],
87 [Define to 1 if the amount of physical memory can be detected
89 AC_MSG_RESULT([sysctl])
92 # This version of sysinfo() is Linux-specific. Some non-Linux systems have
93 # different sysinfo() so we must check $host_os.
96 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
97 #include <sys/sysinfo.h>
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])
111 AC_MSG_RESULT([unknown])
115 AC_MSG_RESULT([unknown])