]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/kyua/m4/memory.m4
amd64: use register macros for gdb_cpu_getreg()
[FreeBSD/FreeBSD.git] / contrib / kyua / m4 / memory.m4
1 dnl Copyright 2012 The Kyua Authors.
2 dnl All rights reserved.
3 dnl
4 dnl Redistribution and use in source and binary forms, with or without
5 dnl modification, are permitted provided that the following conditions are
6 dnl met:
7 dnl
8 dnl * Redistributions of source code must retain the above copyright
9 dnl   notice, this list of conditions and the following disclaimer.
10 dnl * Redistributions in binary form must reproduce the above copyright
11 dnl   notice, this list of conditions and the following disclaimer in the
12 dnl   documentation and/or other materials provided with the distribution.
13 dnl * Neither the name of Google Inc. nor the names of its contributors
14 dnl   may be used to endorse or promote products derived from this software
15 dnl   without specific prior written permission.
16 dnl
17 dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 dnl \file m4/memory.m4
30 dnl
31 dnl Macros to configure the utils::memory module.
32
33
34 dnl Entry point to detect all features needed by utils::memory.
35 dnl
36 dnl This looks for a mechanism to check the available physical memory in the
37 dnl system.
38 AC_DEFUN([KYUA_MEMORY], [
39     memory_query=unknown
40     memory_mib=none
41
42     _KYUA_SYSCTLBYNAME([have_sysctlbyname=yes], [have_sysctlbyname=no])
43     if test "${have_sysctlbyname}" = yes; then
44         _KYUA_SYSCTL_MIB([hw.usermem64], [hw_usermem64],
45                          [memory_mib="hw.usermem64"], [])
46         if test "${memory_mib}" = none; then
47             _KYUA_SYSCTL_MIB([hw.usermem], [hw_usermem],
48                              [memory_mib="hw.usermem"], [])
49         fi
50         if test "${memory_mib}" != none; then
51             memory_query=sysctlbyname
52         fi
53     fi
54
55     if test "${memory_query}" = unknown; then
56         AC_MSG_WARN([Don't know how to query the amount of physical memory])
57         AC_MSG_WARN([The test case's require.memory property will not work])
58     fi
59
60     AC_DEFINE_UNQUOTED([MEMORY_QUERY_TYPE], ["${memory_query}"],
61                        [Define to the memory query type])
62     AC_DEFINE_UNQUOTED([MEMORY_QUERY_SYSCTL_MIB], ["${memory_mib}"],
63                        [Define to the name of the sysctl MIB])
64 ])
65
66
67 dnl Detects the availability of the sysctlbyname(3) function.
68 dnl
69 dnl \param action_if_found Code to run if the function is found.
70 dnl \param action_if_not_found Code to run if the function is not found.
71 AC_DEFUN([_KYUA_SYSCTLBYNAME], [
72     AC_CHECK_HEADERS([sys/types.h sys/sysctl.h])  dnl Darwin 11.2
73     AC_CHECK_HEADERS([sys/param.h sys/sysctl.h])  dnl NetBSD 6.0
74
75     AC_CHECK_FUNCS([sysctlbyname], [$1], [$2])
76 ])
77
78
79 dnl Looks for a specific sysctl MIB.
80 dnl
81 dnl \pre sysctlbyname(3) must be present in the system.
82 dnl
83 dnl \param mib_name The name of the MIB to check for.
84 dnl \param flat_mib_name The name of the MIB as a shell variable, for use in
85 dnl     cache variable names.  This should be automatically computed with
86 dnl     m4_bpatsubst or similar, but my inability to make the code readable
87 dnl     made me add this parameter instead.
88 dnl \param action_if_found Code to run if the MIB is found.
89 dnl \param action_if_not_found Code to run if the MIB is not found.
90 AC_DEFUN([_KYUA_SYSCTL_MIB], [
91     AC_CACHE_CHECK(
92         [if the $1 sysctl MIB exists],
93         [kyua_cv_sysctl_$2], [
94         AC_RUN_IFELSE([AC_LANG_PROGRAM([
95 #if defined(HAVE_SYS_TYPES_H)
96 #   include <sys/types.h>
97 #endif
98 #if defined(HAVE_SYS_PARAM_H)
99 #   include <sys/param.h>
100 #endif
101 #if defined(HAVE_SYS_SYSCTL_H)
102 #   include <sys/sysctl.h>
103 #endif
104 #include <stdint.h>
105 #include <stdlib.h>
106 ], [
107     int64_t memory;
108     size_t memory_length = sizeof(memory);
109     if (sysctlbyname("$1", &memory, &memory_length, NULL, 0) == -1)
110         return EXIT_FAILURE;
111     else
112         return EXIT_SUCCESS;
113 ])],
114         [kyua_cv_sysctl_$2=yes],
115         [kyua_cv_sysctl_$2=no])
116     ])
117     if test "${kyua_cv_sysctl_$2}" = yes; then
118         m4_default([$3], [:])
119     else
120         m4_default([$4], [:])
121     fi
122 ])