1 ## Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
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
14 AC_DEFUN([SQUID_STATE_SAVE],[
15 # save state, key is $1
17 $1_CXXFLAGS="${CXXFLAGS}"
18 $1_LDFLAGS="${LDFLAGS}"
22 $1_squid_saved_vars="$2"
23 for squid_util_var_tosave in $$1_squid_saved_vars
25 squid_util_var_tosave2="$1_${squid_util_var_tosave}"
26 eval "${squid_util_var_tosave2}=\"${squid_util_var_tosave}\""
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
41 for squid_util_var_tosave in $$1_squid_saved_vars
43 unset ${squid_util_var_tosave}
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
51 AC_DEFUN([SQUID_STATE_ROLLBACK],[
52 # rollback state, key is $1
54 CXXFLAGS="${$1_CXXFLAGS}"
55 LDFLAGS="${$1_LDFLAGS}"
59 for squid_util_var_tosave in $$1_squid_saved_vars
61 squid_util_var_tosave2="\$$1_${squid_util_var_tosave}"
62 eval "$squid_util_var_tosave=\"${squid_util_var_tosave2}\""
64 SQUID_STATE_COMMIT($1)
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],[
74 module="`basename $dir`"
75 if test -d "$dir" && test "$module" != CVS; then
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
87 squid_cleanup_tmp_dupe=0
88 for squid_cleanup_tmp2 in $squid_cleanup_tmp_outlist
90 if test "$squid_cleanup_tmp" = "$squid_cleanup_tmp2"; then
91 squid_cleanup_tmp_dupe=1
95 if test $squid_cleanup_tmp_dupe -eq 0; then
96 squid_cleanup_tmp_outlist="${squid_cleanup_tmp_outlist} $squid_cleanup_tmp"
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
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
118 if test -d $1/$squid_module_check_exist_tmp
120 eval "$2_$squid_module_check_exist_tmp='yes'"
121 #echo "defining $2_$squid_module_check_exist_tmp"
123 AC_MSG_ERROR([$squid_module_check_exist_tmp not found in $1])
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`
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`
138 dnl like AC_DEFINE, but it defines the value to 0 or 1 using well-known textual
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],[
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']) ;;
151 [AC_DEFINE_UNQUOTED([$1], [$squid_tmp_define],[$3])],
152 [AC_DEFINE_UNQUOTED([$1], [$squid_tmp_define])]
154 unset squid_tmp_define
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
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
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'`
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"
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}"
194 squid_build_info=$enableval
198 AC_DEFINE_UNQUOTED([SQUID_BUILD_INFO],["$squid_build_info"],
199 [Squid extended build info field for "squid -v" output])
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"
214 LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
216 AC_LINK_IFELSE([], [AS_VAR_SET([ac_Search], [$ac_res])])
217 AS_VAR_SET_IF([ac_Search], [break])
219 AS_VAR_SET_IF([ac_Search], , [AS_VAR_SET([ac_Search], [no])])
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"
227 AS_VAR_POPDEF([ac_Search])dnl
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"
239 case "$squid_host_os" in
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"
246 echo "checking for MAC Darwin without sasl.h ... no"
247 squid_cv_check_sasl="no"
251 if test "x$squid_cv_check_sasl" = "xno"; then
252 AC_MSG_WARN([Neither SASL nor SASL2 found])
254 squid_cv_check_sasl="yes"