]> git.ipfire.org Git - thirdparty/squid.git/blob - acinclude/squid-util.m4
Merged from trunk
[thirdparty/squid.git] / acinclude / squid-util.m4
1 dnl
2 dnl AUTHOR: Francesco Chemolli
3 dnl
4 dnl SQUID Web Proxy Cache http://www.squid-cache.org/
5 dnl ----------------------------------------------------------
6 dnl Squid is the result of efforts by numerous individuals from
7 dnl the Internet community; see the CONTRIBUTORS file for full
8 dnl details. Many organizations have provided support for Squid's
9 dnl development; see the SPONSORS file for full details. Squid is
10 dnl Copyrighted (C) 2001 by the Regents of the University of
11 dnl California; see the COPYRIGHT file for full details. Squid
12 dnl incorporates software developed and/or copyrighted by other
13 dnl sources; see the CREDITS file for full details.
14 dnl
15 dnl This program is free software; you can redistribute it and/or modify
16 dnl it under the terms of the GNU General Public License as published by
17 dnl the Free Software Foundation; either version 2 of the License, or
18 dnl (at your option) any later version.
19 dnl
20 dnl This program is distributed in the hope that it will be useful,
21 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
22 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 dnl GNU General Public License for more details.
24 dnl
25 dnl You should have received a copy of the GNU General Public License
26 dnl along with this program; if not, write to the Free Software
27 dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28
29 dnl save main environment variables to variables to the namespace defined by the
30 dnl first argument (prefix)
31 dnl e.g. SQUID_SAVEFLAGS([foo]) will save CFLAGS to foo_CFLAGS etc.
32 dnl Saved variables are:
33 dnl CFLAGS, CXXFLAGS, LDFLAGS, LIBS plus any variables specified as
34 dnl second argument
35 AC_DEFUN([SQUID_STATE_SAVE],[
36 $1_CFLAGS="${CFLAGS}"
37 $1_CXXFLAGS="${CXXFLAGS}"
38 $1_LDFLAGS="${LDFLAGS}"
39 $1_LIBS="${LIBS}"
40 $1_CC="${CC}"
41 $1_CXX="${CXX}"
42 $1_squid_saved_vars="$2"
43 for squid_util_var_tosave in $2
44 do
45 squid_util_var_tosave2="$1_${squid_util_var_tosave}"
46 eval "${squid_util_var_tosave2}=\"${squid_util_var_tosave}\""
47 done
48 ])
49
50 dnl commit the state changes: deleting the temporary state defined in SQUID_STATE_SAVE
51 dnl with the same prefix. It's not necessary to specify the extra variables passed
52 dnl to SQUID_STATE_SAVE again, they will be automatically reclaimed.
53 AC_DEFUN([SQUID_STATE_COMMIT],[
54 unset $1_CFLAGS
55 unset $1_CXXFLAGS
56 unset $1_LDFLAGS
57 unset $1_LIBS
58 unset $1_CC
59 unset $1_CXX
60 for squid_util_var_tosave in $$1_squid_saved_vars
61 do
62 unset ${squid_util_var_tosave2}
63 done
64 ])
65
66 dnl rollback state to the call of SQUID_STATE_SAVE with the same namespace argument.
67 dnl all temporary state will be cleared, including the custom variables specified
68 dnl at call time. It's not necessary to explicitly name them, they will be automatically
69 dnl cleared.
70 AC_DEFUN([SQUID_STATE_ROLLBACK],[
71 CFLAGS="${$1_CFLAGS}"
72 CXXFLAGS="${$1_CXXFLAGS}"
73 LDFLAGS="${$1_LDFLAGS}"
74 LIBS="${$1_LIBS}"
75 CC="${$1_CC}"
76 CXX="${$1_CXX}"
77 for squid_util_var_tosave in $$1_squid_saved_vars
78 do
79 squid_util_var_tosave2="$1_${squid_util_var_tosave}"
80 eval "${squid_util_var_tosave}=\$${squid_util_var_tosave2}"
81 done
82 SQUID_STATE_COMMIT($1)
83 ])
84
85
86 dnl look for modules in the base-directory supplied as argument.
87 dnl fill-in the variable pointed-to by the second argument with the
88 dnl space-separated list of modules
89 AC_DEFUN([SQUID_LOOK_FOR_MODULES],[
90 $2=""
91 for dir in $1/*; do
92 module="`basename $dir`"
93 if test -d "$dir" && test "$module" != CVS; then
94 $2="$$2 $module"
95 fi
96 done
97 ])
98
99 dnl remove duplicates out of a list.
100 dnl dnl argument is the name of a variable to be checked and cleaned up
101 AC_DEFUN([SQUID_CLEANUP_MODULES_LIST],[
102 squid_cleanup_tmp_outlist=""
103 for squid_cleanup_tmp in $$1
104 do
105 squid_cleanup_tmp_dupe=0
106 for squid_cleanup_tmp2 in $squid_cleanup_tmp_outlist
107 do
108 if test "$squid_cleanup_tmp" = "$squid_cleanup_tmp2"; then
109 squid_cleanup_tmp_dupe=1
110 break
111 fi
112 done
113 if test $squid_cleanup_tmp_dupe -eq 0; then
114 squid_cleanup_tmp_outlist="${squid_cleanup_tmp_outlist} $squid_cleanup_tmp"
115 fi
116 done
117 $1=$squid_cleanup_tmp_outlist
118 unset squid_cleanup_tmp_outlist
119 unset squid_cleanup_tmp_dupe
120 unset squid_cleanup_tmp2
121 unset squid_cleanup_tmp
122 ])
123
124 dnl check that all the modules supplied as a whitespace-separated list (second
125 dnl argument) exist as members of the basedir passed as first argument
126 dnl call AC_MESG_ERROR if any module does not exist. Also sets individual variables
127 dnl named $2_modulename to value "yes"
128 dnl e.g. SQUID_CHECK_EXISTING_MODULES([$srcdir/src/fs],[foo_module_candidates])
129 dnl where $foo_module_candidates is "foo bar gazonk"
130 dnl checks whether $srcdir/src/fs/{foo,bar,gazonk} exist and are all dirs
131 dnl AND sets $foo_module_candidates_foo, $foo_module_candidates_bar
132 dnl and $foo_module_candidates_gazonk to "yes"
133 AC_DEFUN([SQUID_CHECK_EXISTING_MODULES],[
134 for squid_module_check_exist_tmp in $$2
135 do
136 if test -d $1/$squid_module_check_exist_tmp
137 then
138 eval "$2_$squid_module_check_exist_tmp='yes'"
139 #echo "defining $2_$squid_module_check_exist_tmp"
140 else
141 AC_MSG_ERROR([$squid_module_check_exist_tmp not found in $1])
142 fi
143 done
144 ])
145
146 dnl lowercases the contents of the variable whose name is passed by argument
147 AC_DEFUN([SQUID_TOLOWER_VAR_CONTENTS],[
148 $1=`echo $$1|tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
149 ])
150
151 dnl uppercases the contents of the variable whose name is passed by argument
152 AC_DEFUN([SQUID_TOUPPER_VAR_CONTENTS],[
153 $1=`echo $$1|tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
154 ])
155
156 dnl like AC_DEFINE, but it defines the value to 0 or 1 using well-known textual
157 dnl conventions:
158 dnl 1: "yes", "true", 1
159 dnl 0: "no" , "false", 0, ""
160 dnl aborts with an error for unknown values
161 AC_DEFUN([SQUID_DEFINE_BOOL],[
162 squid_tmp_define=""
163 case "$2" in
164 yes|true|1) squid_tmp_define="1" ;;
165 no|false|0|"") squid_tmp_define="0" ;;
166 *) AC_MSG_ERROR([SQUID_DEFINE[]_BOOL: unrecognized value for $1: '$2']) ;;
167 esac
168 ifelse([$#],3,
169 [AC_DEFINE_UNQUOTED([$1], [$squid_tmp_define],[$3])],
170 [AC_DEFINE_UNQUOTED([$1], [$squid_tmp_define])]
171 )
172 unset squid_tmp_define
173 ])
174
175 dnl aborts with an error specified as the second argument if the first argument doesn't
176 dnl contain either "yes" or "no"
177 AC_DEFUN([SQUID_YESNO],[
178 if test "$1" != "yes" -a "$1" != "no" ; then
179 AC_MSG_ERROR([$2])
180 fi
181 ])