Mac OS X >= 10.7 support
[runtime.git] / srt.m4
1 #
2 #  srt.m4
3 #
4 #  Author: Pekka Riikonen <priikone@silcnet.org>
5 #
6 #  Copyright (C) 2007 - 2008 Pekka Riikonen
7 #
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.
11 #
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.
16 #
17
18 # Function to check if system has SMP kernel.
19 #
20 # Usage: SILC_SYSTEM_IS_SMP([ACTION-IF-FOUND] [, ACTION-IF-NOT-FOUND]
21 #                           [, ACTION-IF-NOT-DETECTED])
22 #
23 # The ACTION-IF-NOT-DETECTED is called if we could not detect whether or
24 # not the system is SMP.
25 #
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
28 # code.
29 #
30 AC_DEFUN([SILC_SYSTEM_IS_SMP],
31 [
32   AC_MSG_CHECKING(whether system has SMP kernel)
33   x_is_smp=false
34
35   case "$target" in
36     *-*-linux*)
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])
42           AC_MSG_RESULT(yes)
43           x_is_smp=true
44           ifelse([$1], , :, [$1])
45         else
46           AC_MSG_RESULT(no)
47           ifelse([$2], , :, [$2])
48         fi
49       else
50         AC_MSG_RESULT(no)
51         ifelse([$2], , :, [$2])
52       fi
53       ;;
54
55     *-*-*bsd*)
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])
62         AC_MSG_RESULT(yes)
63          x_is_smp=true
64         ifelse([$1], , :, [$1])
65       else
66         AC_MSG_RESULT(no)
67         ifelse([$2], , :, [$2])
68       fi
69       ;;
70
71     *)
72       AC_MSG_RESULT(cannot detect on this system)
73       ifelse([$3], , :, [$3])
74       ;;
75   esac
76 ])
77
78 # Function to check for CPU feature flags.
79 #
80 # Usage: SILC_CPU_FLAG(flag, enable, [, ACTION-IF-FOUND]
81 #                      [, ACTION-IF-NOT-FOUND])
82 #
83 # x_have_cpu_<flag> variable is set to true or false value as a result for
84 # calling this function for the <flag>.  Caller may use the variable to
85 # check the result in the code.  If <enable> is true this will add
86 # AC_ARG_ENABLE option for the <flag>.
87 #
88 AC_DEFUN([SILC_CPU_FLAG],
89 [
90   AC_MSG_CHECKING(whether CPU supports $1)
91   x_have_cpu_$1=false
92
93   if test x$2 = xtrue; then
94     AC_ARG_ENABLE($1,
95       [  --enable-$1 ],
96       [
97         AC_MSG_RESULT(yes - enabled by --enable-$1)
98         x_have_cpu_$1=true
99       ])
100   fi
101
102   if test x$x_have_cpu_$1 = xfalse; then
103     case "$target" in
104       *-*-linux*)
105         # Take data from Linux /proc
106         if test -f /proc/cpuinfo; then
107           cpuflags=`grep "^flags.*$1 " /proc/cpuinfo 2> /dev/null`
108           if test $? != 0; then
109             AC_MSG_RESULT(no)
110             x_have_cpu_$1=false
111             ifelse([$4], , :, [$4])
112           else
113             AC_MSG_RESULT(yes)
114             x_have_cpu_$1=true
115             ifelse([$3], , :, [$3])
116           fi
117         else
118           AC_MSG_RESULT(no)
119           x_have_cpu_$1=false
120           ifelse([$4], , :, [$4])
121         fi
122         ;;
123
124       *-*-*bsd*)
125         # BSDs have some flags in sysctl 'machdep' variable
126         cpuflags=`/sbin/sysctl machdep 2> /dev/null | grep "\.$1.*.1"`
127         if test $? != 0; then
128           AC_MSG_RESULT(no)
129            x_have_cpu_$1=false
130           ifelse([$4], , :, [$4])
131         else
132           AC_MSG_RESULT(yes)
133           x_have_cpu_$1=true
134           ifelse([$3], , :, [$3])
135         fi
136         ;;
137
138       *)
139         AC_MSG_RESULT(no - cannot detect on this system)
140         x_have_cpu_$1=false
141         ifelse([$4], , :, [$4])
142         ;;
143     esac
144   fi
145 ])
146
147 # Function to check if compiler option works with the compiler.  If you
148 # want the option added to some other than CFLAGS variable use the
149 # SILC_ADD_CC_FLAGS which supports to specifiable destination variable.
150 #
151 # Usage: SILC_ADD_CFLAGS(FLAGS, [ACTION-IF-FAILED])
152 #
153 AC_DEFUN([SILC_ADD_CFLAGS],
154 [ tmp_CFLAGS="$CFLAGS"
155   CFLAGS="$CFLAGS $1"
156   AC_MSG_CHECKING(whether $CC accepts $1 flag)
157   AC_TRY_LINK([], [], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
158                                        CFLAGS="$tmp_CFLAGS"
159                                        $2])
160   unset tmp_CFLAGS
161 ])
162
163 # Function to check if compiler option works with the compiler,
164 # destination variable specifiable
165 #
166 # Usage: SILC_ADD_CC_FLAGS(VAR, FLAGS, [ACTION-IF-FAILED])
167 #
168 AC_DEFUN([SILC_ADD_CC_FLAGS],
169 [ tmp_CFLAGS="$1_CFLAGS"
170   $1_CFLAGS="${$1_CFLAGS} $2"
171   AC_MSG_CHECKING(whether $CC accepts $2 flag)
172   AC_TRY_LINK([], [], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
173                                        $1_CFLAGS="$tmp_CFLAGS"
174                                        $3])
175   unset tmp_CFLAGS
176 ])