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), OpenVMS, AROS, 14# and QNX have 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 40AC_DEFUN_ONCE([TUKLIB_PHYSMEM], [ 41AC_REQUIRE([TUKLIB_COMMON]) 42 43# sys/param.h might be needed by sys/sysctl.h. 44AC_CHECK_HEADERS([sys/param.h]) 45 46AC_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. 54AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 55#if defined(_WIN32) || defined(__CYGWIN__) || defined(__OS2__) \ 56 || defined(__DJGPP__) || defined(__VMS) \ 57 || defined(AMIGA) || defined(__AROS__) || defined(__QNX__) 58int main(void) { return 0; } 59#else 60compile error 61#endif 62]])], [tuklib_cv_physmem_method=special], [ 63 64# Look for AIX-specific solution before sysconf(), because the test 65# for sysconf() will pass on AIX but won't actually work 66# (sysconf(_SC_PHYS_PAGES) compiles but always returns -1 on AIX). 67AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 68#include <sys/systemcfg.h> 69 70int 71main(void) 72{ 73 (void)_system_configuration.physmem; 74 return 0; 75} 76]])], [tuklib_cv_physmem_method=aix], [ 77 78AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 79#include <unistd.h> 80int 81main(void) 82{ 83 long i; 84 i = sysconf(_SC_PAGESIZE); 85 i = sysconf(_SC_PHYS_PAGES); 86 return 0; 87} 88]])], [tuklib_cv_physmem_method=sysconf], [ 89 90AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 91#include <sys/types.h> 92#ifdef HAVE_SYS_PARAM_H 93# include <sys/param.h> 94#endif 95#include <sys/sysctl.h> 96int 97main(void) 98{ 99 int name[2] = { CTL_HW, HW_PHYSMEM }; 100 unsigned long mem; 101 size_t mem_ptr_size = sizeof(mem); 102 sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0); 103 return 0; 104} 105]])], [tuklib_cv_physmem_method=sysctl], [ 106 107AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 108#include <sys/sysinfo.h> 109#include <machine/hal_sysinfo.h> 110 111int 112main(void) 113{ 114 int memkb; 115 int start = 0; 116 getsysinfo(GSI_PHYSMEM, (caddr_t)&memkb, sizeof(memkb), &start); 117 return 0; 118} 119]])], [tuklib_cv_physmem_method=getsysinfo],[ 120 121AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 122#include <sys/param.h> 123#include <sys/pstat.h> 124 125int 126main(void) 127{ 128 struct pst_static pst; 129 pstat_getstatic(&pst, sizeof(pst), 1, 0); 130 (void)pst.physical_memory; 131 (void)pst.page_size; 132 return 0; 133} 134]])], [tuklib_cv_physmem_method=pstat_getstatic],[ 135 136AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 137#include <invent.h> 138int 139main(void) 140{ 141 inv_state_t *st = NULL; 142 setinvent_r(&st); 143 getinvent_r(st); 144 endinvent_r(st); 145 return 0; 146} 147]])], [tuklib_cv_physmem_method=getinvent_r], [ 148 149# This version of sysinfo() is Linux-specific. Some non-Linux systems have 150# different sysinfo() so we must check $host_os. 151case $host_os in 152 linux*) 153 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 154#include <sys/sysinfo.h> 155int 156main(void) 157{ 158 struct sysinfo si; 159 sysinfo(&si); 160 return 0; 161} 162 ]])], [ 163 tuklib_cv_physmem_method=sysinfo 164 ], [ 165 tuklib_cv_physmem_method=unknown 166 ]) 167 ;; 168 *) 169 tuklib_cv_physmem_method=unknown 170 ;; 171esac 172])])])])])])])]) 173 174case $tuklib_cv_physmem_method in 175 aix) 176 AC_DEFINE([TUKLIB_PHYSMEM_AIX], [1], 177 [Define to 1 if the amount of physical memory 178 can be detected with _system_configuration.physmem.]) 179 ;; 180 sysconf) 181 AC_DEFINE([TUKLIB_PHYSMEM_SYSCONF], [1], 182 [Define to 1 if the amount of physical memory can 183 be detected with sysconf(_SC_PAGESIZE) and 184 sysconf(_SC_PHYS_PAGES).]) 185 ;; 186 sysctl) 187 AC_DEFINE([TUKLIB_PHYSMEM_SYSCTL], [1], 188 [Define to 1 if the amount of physical memory can 189 be detected with sysctl().]) 190 ;; 191 getsysinfo) 192 AC_DEFINE([TUKLIB_PHYSMEM_GETSYSINFO], [1], 193 [Define to 1 if the amount of physical memory can 194 be detected with getsysinfo().]) 195 ;; 196 pstat_getstatic) 197 AC_DEFINE([TUKLIB_PHYSMEM_PSTAT_GETSTATIC], [1], 198 [Define to 1 if the amount of physical memory can 199 be detected with pstat_getstatic().]) 200 ;; 201 getinvent_r) 202 AC_DEFINE([TUKLIB_PHYSMEM_GETINVENT_R], [1], 203 [Define to 1 if the amount of physical memory 204 can be detected with getinvent_r().]) 205 ;; 206 sysinfo) 207 AC_DEFINE([TUKLIB_PHYSMEM_SYSINFO], [1], 208 [Define to 1 if the amount of physical memory 209 can be detected with Linux sysinfo().]) 210 ;; 211esac 212])dnl 213