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