4 # Author: Pekka Riikonen <priikone@silcnet.org>
6 # Copyright (C) 2007 Pekka Riikonen
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; version 2 of the License.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
18 # Function to check if system has SMP kernel.
20 # Usage: SILC_SYSTEM_IS_SMP([ACTION-IF-FOUND] [, ACTION-IF-NOT-FOUND]
21 # [, ACTION-IF-NOT-DETECTED])
23 # The ACTION-IF-NOT-DETECTED is called if we could not detect whether or
24 # not the system is SMP.
26 # x_is_smp variable is set to true or false as a result for calling this
27 # function. Caller may use the variable to check for the result in the
30 AC_DEFUN([SILC_SYSTEM_IS_SMP],
32 AC_MSG_CHECKING(whether system has SMP kernel)
37 # Take data from Linux /proc
38 if test -f /proc/stat; then
39 cpucount=`grep "^cpu" /proc/stat -c 2> /dev/null`
40 if test $cpucount -gt 1; then
41 AC_DEFINE([SILC_SMP], [], [SILC_SMP])
44 ifelse([$1], , :, [$1])
47 ifelse([$2], , :, [$2])
51 ifelse([$2], , :, [$2])
56 # BSDs can have SMP info in sysctl 'kern.smp.cpus' variable
57 sysctl="sysctl -n kern.smp.cpus"
58 cpucount=`(/sbin/$sysctl 2> /dev/null || \
59 /usr/sbin/$sysctl 2> /dev/null || echo -n 0)`
60 if test $cpucount -gt 1; then
61 AC_DEFINE([SILC_SMP], [], [SILC_SMP])
64 ifelse([$1], , :, [$1])
67 ifelse([$2], , :, [$2])
72 AC_MSG_RESULT(cannot detect on this system)
73 ifelse([$3], , :, [$3])
78 # Function to check for CPU feature flags.
80 # Usage: SILC_CPU_FLAG(flag [, ACTION-IF-FOUND] [, ACTION-IF-NOT-FOUND])
82 # x_have_cpu_<flag> variable is set to true or false value as a result for
83 # calling this function for the <flag>. Caller may use the variable to
84 # check the result in the code.
86 AC_DEFUN([SILC_CPU_FLAG],
88 AC_MSG_CHECKING(whether CPU supports $1)
93 # Take data from Linux /proc
94 if test -f /proc/cpuinfo; then
95 cpuflags=`grep "^flags.*$1 " /proc/cpuinfo 2> /dev/null`
98 ifelse([$3], , :, [$3])
102 ifelse([$2], , :, [$2])
106 ifelse([$3], , :, [$3])
111 # BSDs have some flags in sysctl 'machdep' variable
112 cpuflags=`/sbin/sysctl machdep 2> /dev/null | grep "\.$1.*.1"`
113 if test $? != 0; then
115 ifelse([$3], , :, [$3])
119 ifelse([$2], , :, [$2])
124 AC_MSG_RESULT(no, cannot detect on this system)
125 ifelse([$3], , :, [$3])
130 # Function to check if compiler option works with the compiler. If you
131 # want the option added to some other than CFLAGS variable use the
132 # SILC_ADD_CC_FLAGS which supports to specifiable destination variable.
134 # Usage: SILC_ADD_CFLAGS(FLAGS, [ACTION-IF-FAILED])
136 AC_DEFUN([SILC_ADD_CFLAGS],
137 [ tmp_CFLAGS="$CFLAGS"
139 AC_MSG_CHECKING(whether $CC accepts $1 flag)
140 AC_TRY_LINK([], [], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
146 # Function to check if compiler option works with the compiler,
147 # destination variable specifiable
149 # Usage: SILC_ADD_CC_FLAGS(VAR, FLAGS, [ACTION-IF-FAILED])
151 AC_DEFUN([SILC_ADD_CC_FLAGS],
152 [ tmp_CFLAGS="$1_CFLAGS"
153 $1_CFLAGS="${$1_CFLAGS} $2"
154 AC_MSG_CHECKING(whether $CC accepts $2 flag)
155 AC_TRY_LINK([], [], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
156 $1_CFLAGS="$tmp_CFLAGS"