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