Added SILC_STR_REPLACE. Removed SILC_STR_STRING_APPEND. Fixed
[silc.git] / silc.m4
1 #
2 #  silc.m4
3 #
4 #  Author: Pekka Riikonen <priikone@silcnet.org>
5 #
6 #  Copyright (C) 2007 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 [, ACTION-IF-FOUND] [, ACTION-IF-NOT-FOUND])
81 #
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.
85 #
86 AC_DEFUN([SILC_CPU_FLAG],
87 [
88   AC_MSG_CHECKING(whether CPU supports $1)
89   x_have_cpu_$1=false
90
91   case "$target" in
92     *-*-linux*)
93       # Take data from Linux /proc
94       if test -f /proc/cpuinfo; then
95         cpuflags=`grep "^flags.*$1 " /proc/cpuinfo 2> /dev/null`
96         if test $? != 0; then
97           AC_MSG_RESULT(no)
98           ifelse([$3], , :, [$3])
99         else
100           AC_MSG_RESULT(yes)
101           x_have_cpu_$1=true
102           ifelse([$2], , :, [$2])
103         fi
104       else
105         AC_MSG_RESULT(no)
106         ifelse([$3], , :, [$3])
107       fi
108       ;;
109
110     *-*-*bsd*)
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
114         AC_MSG_RESULT(no)
115         ifelse([$3], , :, [$3])
116       else
117         AC_MSG_RESULT(yes)
118         x_have_cpu_$1=true
119         ifelse([$2], , :, [$2])
120       fi
121       ;;
122
123     *)
124       AC_MSG_RESULT(no, cannot detect on this system)
125       ifelse([$3], , :, [$3])
126       ;;
127   esac
128 ])
129
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.
133 #
134 # Usage: SILC_ADD_CFLAGS(FLAGS, [ACTION-IF-FAILED])
135 #
136 AC_DEFUN([SILC_ADD_CFLAGS],
137 [ tmp_CFLAGS="$CFLAGS"
138   CFLAGS="$CFLAGS $1"
139   AC_MSG_CHECKING(whether $CC accepts $1 flag)
140   AC_TRY_LINK([], [], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
141                                        CFLAGS="$tmp_CFLAGS"
142                                        $2])
143   unset tmp_CFLAGS
144 ])
145
146 # Function to check if compiler option works with the compiler,
147 # destination variable specifiable
148 #
149 # Usage: SILC_ADD_CC_FLAGS(VAR, FLAGS, [ACTION-IF-FAILED])
150 #
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"
157                                        $3])
158   unset tmp_CFLAGS
159 ])