]> git.ipfire.org Git - thirdparty/squid.git/blob - acinclude/squid-util.m4
Merge from trunk rev.13866
[thirdparty/squid.git] / acinclude / squid-util.m4
1 ## Copyright (C) 1996-2015 The Squid Software Foundation and contributors
2 ##
3 ## Squid software is distributed under GPLv2+ license and includes
4 ## contributions from numerous individuals and organizations.
5 ## Please see the COPYING and CONTRIBUTORS files for details.
6 ##
7
8 dnl save main environment variables to variables to the namespace defined by the
9 dnl first argument (prefix)
10 dnl e.g. SQUID_SAVEFLAGS([foo]) will save CFLAGS to foo_CFLAGS etc.
11 dnl Saved variables are:
12 dnl CFLAGS, CXXFLAGS, LDFLAGS, LIBS plus any variables specified as
13 dnl second argument
14 AC_DEFUN([SQUID_STATE_SAVE],[
15 # save state, key is $1
16 $1_CFLAGS="${CFLAGS}"
17 $1_CXXFLAGS="${CXXFLAGS}"
18 $1_LDFLAGS="${LDFLAGS}"
19 $1_LIBS="${LIBS}"
20 $1_CC="${CC}"
21 $1_CXX="${CXX}"
22 $1_squid_saved_vars="$2"
23 for squid_util_var_tosave in $$1_squid_saved_vars
24 do
25 squid_util_var_tosave2="$1_${squid_util_var_tosave}"
26 eval "${squid_util_var_tosave2}=\"${squid_util_var_tosave}\""
27 done
28 ])
29
30 dnl commit the state changes: deleting the temporary state defined in SQUID_STATE_SAVE
31 dnl with the same prefix. It's not necessary to specify the extra variables passed
32 dnl to SQUID_STATE_SAVE again, they will be automatically reclaimed.
33 AC_DEFUN([SQUID_STATE_COMMIT],[
34 # commit state, key is $1
35 unset $1_CFLAGS
36 unset $1_CXXFLAGS
37 unset $1_LDFLAGS
38 unset $1_LIBS
39 unset $1_CC
40 unset $1_CXX
41 for squid_util_var_tosave in $$1_squid_saved_vars
42 do
43 unset ${squid_util_var_tosave}
44 done
45 ])
46
47 dnl rollback state to the call of SQUID_STATE_SAVE with the same namespace argument.
48 dnl all temporary state will be cleared, including the custom variables specified
49 dnl at call time. It's not necessary to explicitly name them, they will be automatically
50 dnl cleared.
51 AC_DEFUN([SQUID_STATE_ROLLBACK],[
52 # rollback state, key is $1
53 CFLAGS="${$1_CFLAGS}"
54 CXXFLAGS="${$1_CXXFLAGS}"
55 LDFLAGS="${$1_LDFLAGS}"
56 LIBS="${$1_LIBS}"
57 CC="${$1_CC}"
58 CXX="${$1_CXX}"
59 for squid_util_var_tosave in $$1_squid_saved_vars
60 do
61 squid_util_var_tosave2="\$$1_${squid_util_var_tosave}"
62 eval "$squid_util_var_tosave=\"${squid_util_var_tosave2}\""
63 done
64 SQUID_STATE_COMMIT($1)
65 ])
66
67
68 dnl look for modules in the base-directory supplied as argument.
69 dnl fill-in the variable pointed-to by the second argument with the
70 dnl space-separated list of modules
71 AC_DEFUN([SQUID_LOOK_FOR_MODULES],[
72 $2=""
73 for dir in $1/*; do
74 module="`basename $dir`"
75 if test -d "$dir" && test "$module" != CVS; then
76 $2="$$2 $module"
77 fi
78 done
79 ])
80
81 dnl remove duplicates out of a list.
82 dnl dnl argument is the name of a variable to be checked and cleaned up
83 AC_DEFUN([SQUID_CLEANUP_MODULES_LIST],[
84 squid_cleanup_tmp_outlist=""
85 for squid_cleanup_tmp in $$1
86 do
87 squid_cleanup_tmp_dupe=0
88 for squid_cleanup_tmp2 in $squid_cleanup_tmp_outlist
89 do
90 if test "$squid_cleanup_tmp" = "$squid_cleanup_tmp2"; then
91 squid_cleanup_tmp_dupe=1
92 break
93 fi
94 done
95 if test $squid_cleanup_tmp_dupe -eq 0; then
96 squid_cleanup_tmp_outlist="${squid_cleanup_tmp_outlist} $squid_cleanup_tmp"
97 fi
98 done
99 $1=$squid_cleanup_tmp_outlist
100 unset squid_cleanup_tmp_outlist
101 unset squid_cleanup_tmp_dupe
102 unset squid_cleanup_tmp2
103 unset squid_cleanup_tmp
104 ])
105
106 dnl check that all the modules supplied as a whitespace-separated list (second
107 dnl argument) exist as members of the basedir passed as first argument
108 dnl call AC_MESG_ERROR if any module does not exist. Also sets individual variables
109 dnl named $2_modulename to value "yes"
110 dnl e.g. SQUID_CHECK_EXISTING_MODULES([$srcdir/src/fs],[foo_module_candidates])
111 dnl where $foo_module_candidates is "foo bar gazonk"
112 dnl checks whether $srcdir/src/fs/{foo,bar,gazonk} exist and are all dirs
113 dnl AND sets $foo_module_candidates_foo, $foo_module_candidates_bar
114 dnl and $foo_module_candidates_gazonk to "yes"
115 AC_DEFUN([SQUID_CHECK_EXISTING_MODULES],[
116 for squid_module_check_exist_tmp in $$2
117 do
118 if test -d $1/$squid_module_check_exist_tmp
119 then
120 eval "$2_$squid_module_check_exist_tmp='yes'"
121 #echo "defining $2_$squid_module_check_exist_tmp"
122 else
123 AC_MSG_ERROR([$squid_module_check_exist_tmp not found in $1])
124 fi
125 done
126 ])
127
128 dnl lowercases the contents of the variable whose name is passed by argument
129 AC_DEFUN([SQUID_TOLOWER_VAR_CONTENTS],[
130 $1=`echo $$1|tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
131 ])
132
133 dnl uppercases the contents of the variable whose name is passed by argument
134 AC_DEFUN([SQUID_TOUPPER_VAR_CONTENTS],[
135 $1=`echo $$1|tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
136 ])
137
138 dnl like AC_DEFINE, but it defines the value to 0 or 1 using well-known textual
139 dnl conventions:
140 dnl 1: "yes", "true", 1
141 dnl 0: "no" , "false", 0, ""
142 dnl aborts with an error for unknown values
143 AC_DEFUN([SQUID_DEFINE_BOOL],[
144 squid_tmp_define=""
145 case "$2" in
146 yes|true|1) squid_tmp_define="1" ;;
147 no|false|0|"") squid_tmp_define="0" ;;
148 *) AC_MSG_ERROR([SQUID_DEFINE[]_BOOL: unrecognized value for $1: '$2']) ;;
149 esac
150 ifelse([$#],3,
151 [AC_DEFINE_UNQUOTED([$1], [$squid_tmp_define],[$3])],
152 [AC_DEFINE_UNQUOTED([$1], [$squid_tmp_define])]
153 )
154 unset squid_tmp_define
155 ])
156
157 dnl aborts with an error specified as the second argument if the first argument doesn't
158 dnl contain either "yes" or "no"
159 AC_DEFUN([SQUID_YESNO],[
160 if test "$1" != "yes" -a "$1" != "no" ; then
161 AC_MSG_ERROR([$2])
162 fi
163 ])
164
165 AC_DEFUN([SQUID_EMBED_BUILD_INFO],[
166 AC_ARG_ENABLE([build-info],
167 AS_HELP_STRING([--enable-build-info="build info string"],
168 [Add an additional string in the output of "squid -v".
169 Default is not to add anything. If the string is not specified,
170 tries to determine nick and revision number of the current
171 bazaar branch]),[
172 case "$enableval" in
173 no) ${TRUE}
174 ;;
175 yes)
176 if test -d "${srcdir}/.bzr"; then
177 AC_PATH_PROG(BZR,bzr,$FALSE)
178 squid_bzr_branch_nick=`cd ${srcdir} && ${BZR} nick 2>/dev/null`
179 if test $? -eq 0 -a "x$squid_bzr_branch_nick" != "x"; then
180 squid_bzr_branch_revno=`cd ${srcdir} && ${BZR} revno 2>/dev/null | sed 's/\"//g'`
181 fi
182 if test $? -eq 0 -a "x$squid_bzr_branch_revno" != "x"; then
183 sh -c "cd ${srcdir} && ${BZR} diff 2>&1 >/dev/null"
184 if test $? -eq 1; then
185 squid_bzr_branch_revno="$squid_bzr_branch_revno+changes"
186 fi
187 fi
188 if test "x$squid_bzr_branch_revno" != "x"; then
189 squid_build_info="Built branch: ${squid_bzr_branch_nick}-r${squid_bzr_branch_revno}"
190 fi
191 fi
192 ;;
193 *)
194 squid_build_info=$enableval
195 ;;
196 esac
197 ])
198 AC_DEFINE_UNQUOTED([SQUID_BUILD_INFO],["$squid_build_info"],
199 [Squid extended build info field for "squid -v" output])
200 ])
201
202 dnl like AC_SEARCH_LIBS, with an extra argument which is
203 dnl a prefix to the test program
204 AC_DEFUN([SQUID_SEARCH_LIBS],
205 [AS_VAR_PUSHDEF([ac_Search], [ac_cv_search_$1])dnl
206 AC_CACHE_CHECK([for library containing $1], [ac_Search],
207 [ac_func_search_save_LIBS=$LIBS
208 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$6], [$1()])])
209 for ac_lib in '' $2; do
210 if test -z "$ac_lib"; then
211 ac_res="none required"
212 else
213 ac_res=-l$ac_lib
214 LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
215 fi
216 AC_LINK_IFELSE([], [AS_VAR_SET([ac_Search], [$ac_res])])
217 AS_VAR_SET_IF([ac_Search], [break])
218 done
219 AS_VAR_SET_IF([ac_Search], , [AS_VAR_SET([ac_Search], [no])])
220 rm conftest.$ac_ext
221 LIBS=$ac_func_search_save_LIBS])
222 ac_res=AS_VAR_GET([ac_Search])
223 AS_IF([test "$ac_res" != no],
224 [test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
225 $3],
226 [$4])
227 AS_VAR_POPDEF([ac_Search])dnl
228 ])
229
230 dnl Check for Cyrus SASL
231 AC_DEFUN([SQUID_CHECK_SASL],[
232 squid_cv_check_sasl="auto"
233 AC_CHECK_HEADERS([sasl/sasl.h sasl.h])
234 AC_CHECK_LIB(sasl2,sasl_errstring,[LIBSASL="-lsasl2"],[
235 AC_CHECK_LIB(sasl,sasl_errstring,[LIBSASL="-lsasl"], [
236 squid_cv_check_sasl="no"
237 ])
238 ])
239 case "$squid_host_os" in
240 Darwin)
241 if test "$ac_cv_lib_sasl2_sasl_errstring" = "yes" ; then
242 AC_DEFINE(HAVE_SASL_DARWIN,1,[Define to 1 if Mac Darwin without sasl.h])
243 echo "checking for MAC Darwin without sasl.h ... yes"
244 squid_cv_check_sasl="yes"
245 else
246 echo "checking for MAC Darwin without sasl.h ... no"
247 squid_cv_check_sasl="no"
248 fi
249 ;;
250 esac
251 if test "x$squid_cv_check_sasl" = "xno"; then
252 AC_MSG_WARN([Neither SASL nor SASL2 found])
253 else
254 squid_cv_check_sasl="yes"
255 fi
256 AC_SUBST(LIBSASL)
257 ])