]>
Commit | Line | Data |
---|---|---|
b8ae064d | 1 | ## Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
5d2e6f19 AJ |
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 | ## | |
fa522425 FC |
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],[ | |
820c5a3c | 15 | # save state, key is $1 |
fa522425 FC |
16 | $1_CFLAGS="${CFLAGS}" |
17 | $1_CXXFLAGS="${CXXFLAGS}" | |
18 | $1_LDFLAGS="${LDFLAGS}" | |
19 | $1_LIBS="${LIBS}" | |
bee906c3 FC |
20 | $1_CC="${CC}" |
21 | $1_CXX="${CXX}" | |
7c760558 | 22 | $1_CPPFLAGS="${CPPFLAGS}" |
fa522425 | 23 | $1_squid_saved_vars="$2" |
4f0128b6 | 24 | for squid_util_var_tosave in $$1_squid_saved_vars |
fa522425 FC |
25 | do |
26 | squid_util_var_tosave2="$1_${squid_util_var_tosave}" | |
27 | eval "${squid_util_var_tosave2}=\"${squid_util_var_tosave}\"" | |
28 | done | |
29 | ]) | |
30 | ||
31 | dnl commit the state changes: deleting the temporary state defined in SQUID_STATE_SAVE | |
32 | dnl with the same prefix. It's not necessary to specify the extra variables passed | |
33 | dnl to SQUID_STATE_SAVE again, they will be automatically reclaimed. | |
34 | AC_DEFUN([SQUID_STATE_COMMIT],[ | |
820c5a3c | 35 | # commit state, key is $1 |
fa522425 | 36 | unset $1_CFLAGS |
018a3298 | 37 | unset $1_CXXFLAGS |
fa522425 FC |
38 | unset $1_LDFLAGS |
39 | unset $1_LIBS | |
50fbcbd6 FC |
40 | unset $1_CC |
41 | unset $1_CXX | |
7c760558 | 42 | unset $1_CPPFLAGS |
fa522425 FC |
43 | for squid_util_var_tosave in $$1_squid_saved_vars |
44 | do | |
820c5a3c | 45 | unset ${squid_util_var_tosave} |
fa522425 FC |
46 | done |
47 | ]) | |
48 | ||
49 | dnl rollback state to the call of SQUID_STATE_SAVE with the same namespace argument. | |
50 | dnl all temporary state will be cleared, including the custom variables specified | |
51 | dnl at call time. It's not necessary to explicitly name them, they will be automatically | |
52 | dnl cleared. | |
53 | AC_DEFUN([SQUID_STATE_ROLLBACK],[ | |
820c5a3c | 54 | # rollback state, key is $1 |
fa522425 FC |
55 | CFLAGS="${$1_CFLAGS}" |
56 | CXXFLAGS="${$1_CXXFLAGS}" | |
57 | LDFLAGS="${$1_LDFLAGS}" | |
58 | LIBS="${$1_LIBS}" | |
50fbcbd6 FC |
59 | CC="${$1_CC}" |
60 | CXX="${$1_CXX}" | |
7c760558 | 61 | CPPFLAGS="${$1_CPPFLAGS}" |
fa522425 FC |
62 | for squid_util_var_tosave in $$1_squid_saved_vars |
63 | do | |
820c5a3c FC |
64 | squid_util_var_tosave2="\$$1_${squid_util_var_tosave}" |
65 | eval "$squid_util_var_tosave=\"${squid_util_var_tosave2}\"" | |
fa522425 FC |
66 | done |
67 | SQUID_STATE_COMMIT($1) | |
68 | ]) | |
69 | ||
50fbcbd6 FC |
70 | |
71 | dnl look for modules in the base-directory supplied as argument. | |
9d6186b1 | 72 | dnl fill-in the variable pointed-to by the second argument with the |
9603207d | 73 | dnl space-separated list of modules |
50fbcbd6 | 74 | AC_DEFUN([SQUID_LOOK_FOR_MODULES],[ |
26ffc057 | 75 | $2="" |
50fbcbd6 FC |
76 | for dir in $1/*; do |
77 | module="`basename $dir`" | |
a1c22363 | 78 | AS_IF([test -d "$dir" -a "$module" != "CVS"], $2="$$2 $module") |
50fbcbd6 FC |
79 | done |
80 | ]) | |
d235bc84 | 81 | |
a1c22363 | 82 | dnl remove commas, extra whitespace, and duplicates out of a list. |
61beade2 | 83 | dnl argument is the name of a variable to be checked and cleaned up |
d235bc84 FC |
84 | AC_DEFUN([SQUID_CLEANUP_MODULES_LIST],[ |
85 | squid_cleanup_tmp_outlist="" | |
a1c22363 | 86 | for squid_cleanup_tmp in `echo "$$1" | sed -e 's/,/ /g;s/ */ /g'` |
d235bc84 FC |
87 | do |
88 | squid_cleanup_tmp_dupe=0 | |
89 | for squid_cleanup_tmp2 in $squid_cleanup_tmp_outlist | |
90 | do | |
a1c22363 | 91 | AS_IF([test "$squid_cleanup_tmp" = "$squid_cleanup_tmp2"],[ |
d235bc84 FC |
92 | squid_cleanup_tmp_dupe=1 |
93 | break | |
a1c22363 | 94 | ]) |
d235bc84 | 95 | done |
a1c22363 | 96 | AS_IF([test $squid_cleanup_tmp_dupe -eq 0],[ |
d235bc84 | 97 | squid_cleanup_tmp_outlist="${squid_cleanup_tmp_outlist} $squid_cleanup_tmp" |
a1c22363 | 98 | ]) |
d235bc84 | 99 | done |
a1c22363 | 100 | $1=`echo "$squid_cleanup_tmp_outlist" | sed -e 's/^ *//'` |
d235bc84 FC |
101 | unset squid_cleanup_tmp_outlist |
102 | unset squid_cleanup_tmp_dupe | |
103 | unset squid_cleanup_tmp2 | |
104 | unset squid_cleanup_tmp | |
105 | ]) | |
106 | ||
107 | dnl check that all the modules supplied as a whitespace-separated list (second | |
108 | dnl argument) exist as members of the basedir passed as first argument | |
dc299f29 FC |
109 | dnl call AC_MESG_ERROR if any module does not exist. Also sets individual variables |
110 | dnl named $2_modulename to value "yes" | |
111 | dnl e.g. SQUID_CHECK_EXISTING_MODULES([$srcdir/src/fs],[foo_module_candidates]) | |
112 | dnl where $foo_module_candidates is "foo bar gazonk" | |
113 | dnl checks whether $srcdir/src/fs/{foo,bar,gazonk} exist and are all dirs | |
9603207d | 114 | dnl AND sets $foo_module_candidates_foo, $foo_module_candidates_bar |
dc299f29 | 115 | dnl and $foo_module_candidates_gazonk to "yes" |
d235bc84 | 116 | AC_DEFUN([SQUID_CHECK_EXISTING_MODULES],[ |
dc299f29 | 117 | for squid_module_check_exist_tmp in $$2 |
d235bc84 | 118 | do |
a1c22363 | 119 | AS_IF([test -d "$1/$squid_module_check_exist_tmp"],[ |
dc299f29 FC |
120 | eval "$2_$squid_module_check_exist_tmp='yes'" |
121 | #echo "defining $2_$squid_module_check_exist_tmp" | |
a1c22363 | 122 | ],[ |
d235bc84 | 123 | AC_MSG_ERROR([$squid_module_check_exist_tmp not found in $1]) |
a1c22363 | 124 | ]) |
d235bc84 FC |
125 | done |
126 | ]) | |
6d1c1ab1 | 127 | |
a1c22363 AJ |
128 | dnl Check the requirements for a helper to be built. |
129 | dnl Requirements can be provided as an M4/autoconf script (required.m4) | |
130 | dnl which sets a variable BUILD_HELPER to the name of the helper | |
131 | dnl directory if the helper is to be added to the built SUBDIRS list. | |
132 | dnl Or, a shell script (config.test) which returns 0 exit status if | |
133 | dnl the helper is to be built. | |
134 | AC_DEFUN([SQUID_CHECK_HELPER],[ | |
135 | AS_IF([test "x$helper" = "x$1"],[ | |
e85b7894 | 136 | AS_IF([test -d "$srcdir/src/$2/$1"],[ |
a1c22363 AJ |
137 | dnl find helpers providing autoconf M4 requirement checks |
138 | m4_include(m4_echo([src/$2/$1/required.m4])) | |
139 | dnl find helpers not yet converted to autoconf (or third party drop-in's) | |
e85b7894 | 140 | AS_IF([test -f "$srcdir/src/$2/$1/config.test" && sh "$srcdir/src/$2/$1/config.test" "$squid_host_os"],[ |
a1c22363 AJ |
141 | BUILD_HELPER="$1" |
142 | ]) | |
143 | AS_IF( | |
144 | [test "x$BUILD_HELPER" = "x$1"], | |
145 | squid_cv_BUILD_HELPERS="$squid_cv_BUILD_HELPERS $BUILD_HELPER", | |
146 | [test "x$auto_helpers" = "xyes"], | |
147 | AC_MSG_NOTICE([helper $2/$1 ... found but cannot be built]), | |
148 | [AC_MSG_ERROR([required helper $2/$1 ... found but cannot be built])] | |
149 | ) | |
150 | ],[ | |
151 | AC_MSG_ERROR([helper $2/$1 ... not found]) | |
152 | ]) | |
153 | unset BUILD_HELPER | |
154 | ]) | |
155 | ]) | |
156 | ||
157 | dnl macro to simplify and deduplicate logic in all helpers.m4 files | |
158 | dnl Usage: | |
159 | dnl SQUID_HELPER_FEATURE_CHECK(var_name, default, path, checks) | |
160 | dnl | |
161 | AC_DEFUN([SQUID_HELPER_FEATURE_CHECK],[ | |
162 | auto_helpers=no | |
163 | squid_cv_BUILD_HELPERS="" | |
164 | AS_IF([test "x$enable_$1" = "x"],[enable_$1=$2], | |
165 | [test "x$enable_$1" = "xnone"],[enable_$1=""]) | |
166 | AS_IF([test "x$enable_$1" = "xyes"],[ | |
e85b7894 | 167 | SQUID_LOOK_FOR_MODULES([$srcdir/src/$3], enable_$1) |
a1c22363 AJ |
168 | auto_helpers=yes |
169 | ]) | |
170 | SQUID_CLEANUP_MODULES_LIST([enable_$1]) | |
171 | AC_MSG_NOTICE([checking $3 helpers: $enable_$1]) | |
172 | AS_IF([test "x$enable_$1" != "xno" -a "x$enable_$1" != "x"],[ | |
e85b7894 | 173 | SQUID_CHECK_EXISTING_MODULES([$srcdir/src/$3],[enable_$1]) |
a1c22363 AJ |
174 | for helper in $enable_$1 ; do |
175 | $4 | |
176 | done | |
177 | ]) | |
178 | AC_MSG_NOTICE([$3 helpers to be built: $squid_cv_BUILD_HELPERS]) | |
179 | unset auto_helpers | |
180 | ]) | |
181 | ||
6d1c1ab1 | 182 | dnl lowercases the contents of the variable whose name is passed by argument |
40503c27 | 183 | AC_DEFUN([SQUID_TOLOWER_VAR_CONTENTS],[ |
6d1c1ab1 FC |
184 | $1=`echo $$1|tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` |
185 | ]) | |
186 | ||
187 | dnl uppercases the contents of the variable whose name is passed by argument | |
188 | AC_DEFUN([SQUID_TOUPPER_VAR_CONTENTS],[ | |
189 | $1=`echo $$1|tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` | |
190 | ]) | |
8075a4da | 191 | |
0067eb06 | 192 | dnl like AC_DEFINE, but it defines the value to 0 or 1 using well-known textual |
8075a4da FC |
193 | dnl conventions: |
194 | dnl 1: "yes", "true", 1 | |
195 | dnl 0: "no" , "false", 0, "" | |
196 | dnl aborts with an error for unknown values | |
0067eb06 | 197 | AC_DEFUN([SQUID_DEFINE_BOOL],[ |
8075a4da | 198 | squid_tmp_define="" |
a1c22363 AJ |
199 | AS_CASE(["$2"], |
200 | [yes|true|1],[squid_tmp_define="1"], | |
201 | [no|false|0|""],[squid_tmp_define="0"], | |
202 | [AC_MSG_ERROR([SQUID_DEFINE[]_BOOL: unrecognized value for $1: '$2'])] | |
203 | ) | |
9603207d | 204 | ifelse([$#],3, |
8075a4da FC |
205 | [AC_DEFINE_UNQUOTED([$1], [$squid_tmp_define],[$3])], |
206 | [AC_DEFINE_UNQUOTED([$1], [$squid_tmp_define])] | |
207 | ) | |
208 | unset squid_tmp_define | |
209 | ]) | |
1d87b6b3 FC |
210 | |
211 | dnl aborts with an error specified as the second argument if the first argument doesn't | |
212 | dnl contain either "yes" or "no" | |
213 | AC_DEFUN([SQUID_YESNO],[ | |
ec308e40 | 214 | AS_IF([test "$1" != "yes" -a "$1" != "no"],[AC_MSG_ERROR([Bad argument for $2: "$1". Expecting "yes", "no", or no argument.])]) |
1d87b6b3 | 215 | ]) |
4fe75473 | 216 | |
a3bc98c3 AJ |
217 | dnl Check that a library is actually available, useable, |
218 | dnl and where its pieces are (eg headers and hack macros) | |
219 | dnl Parameters for this macro are: | |
220 | dnl 1) library name (without 'lib' prefix) | |
221 | dnl 2) necessary library checks (to be executed by this macro unless the use of the library is disabled) | |
222 | dnl These checks should set LIBFOO_LIBS automake variable (on success) | |
223 | dnl and ensure that it is empty or unset (on failures). | |
224 | AC_DEFUN([SQUID_CHECK_LIB_WORKS],[ | |
bf2e100a | 225 | AH_TEMPLATE(m4_toupper(m4_translit([HAVE_LIB$1], [-+.], [___])),[Define as 1 to enable '$1' library support.]) |
a3bc98c3 AJ |
226 | AS_IF([m4_translit([test "x$with_$1" != "xno"], [-+.], [___])],[ |
227 | $2 | |
228 | AS_IF([! test -z m4_toupper(m4_translit(["$LIB$1_LIBS"], [-+.], [___]))],[ | |
229 | m4_toupper(m4_translit([CPPFLAGS="$LIB$1_CFLAGS $CPPFLAGS"], [-+.], [___])) | |
230 | m4_toupper(m4_translit([LIB$1_LIBS="$LIB$1_PATH $LIB$1_LIBS"], [-+.], [___])) | |
231 | AC_MSG_NOTICE([Library '$1' support: m4_translit([${with_$1:=yes (auto)} m4_toupper($LIB$1_LIBS)], [-+.], [___])]) | |
232 | m4_translit([with_$1], [-+.], [___])=yes | |
bf2e100a | 233 | AC_DEFINE(m4_toupper(m4_translit([HAVE_LIB$1], [-+.], [___])),1,[Define as 1 to enable '$1' library support.]) |
a3bc98c3 AJ |
234 | ],[m4_translit([test "x$with_$1" = "xyes"], [-+.], [___])],[ |
235 | AC_MSG_ERROR([Required library '$1' not found]) | |
236 | ],[ | |
237 | m4_translit([with_$1], [-+.], [___])=no | |
238 | AC_MSG_NOTICE([Library '$1' support: no (auto)]) | |
239 | ]) | |
240 | ]) | |
bf2e100a | 241 | AM_CONDITIONAL(m4_toupper(m4_translit([ENABLE_LIB$1],[-+.],[___])),m4_translit([test "x$with_$1" != "xno"],[-+.],[___])) |
a3bc98c3 AJ |
242 | AC_SUBST(m4_toupper(m4_translit([LIB$1_LIBS], [-+.], [___]))) |
243 | ]) | |
244 | ||
24531401 AJ |
245 | dnl check the build parameters for a library to auto-enable |
246 | dnl Parameters for this macro are: | |
247 | dnl 1) binary library name (without 'lib' prefix) | |
248 | dnl 2) name of the library for human reading | |
249 | dnl 3) prefix used for pkg-check macros | |
250 | AC_DEFUN([SQUID_AUTO_LIB],[ | |
24531401 AJ |
251 | AC_ARG_WITH([$1],AS_HELP_STRING([--without-$1],[Compile without the $2 library.]),[ |
252 | AS_CASE(["$withval"],[yes|no],,[ | |
253 | AS_IF([test ! -d "$withval"],AC_MSG_ERROR([--with-$1 path does not point to a directory])) | |
8780c450 AJ |
254 | m4_translit([with_$1], [-+.], [___])=yes |
255 | AS_IF([test -d "$withval/lib64"],[$3_PATH+="-L$withval/lib64"]) | |
256 | AS_IF([test -d "$withval/lib"],[$3_PATH+="-L$withval/lib"]) | |
257 | AS_IF([test -d "$withval/include"],[$3_CFLAGS+="-I$withval/include"]) | |
24531401 AJ |
258 | ]) |
259 | ]) | |
24531401 AJ |
260 | ]) |
261 | dnl same as SQUID_AUTO_LIB but for default-disabled libraries | |
262 | AC_DEFUN([SQUID_OPTIONAL_LIB],[ | |
24531401 | 263 | AC_ARG_WITH([$1],AS_HELP_STRING([--with-$1],[Compile with the $2 library.]),[ |
8780c450 AJ |
264 | AS_CASE(["$withval"],[yes|no],,[ |
265 | AS_IF([test ! -d "$withval"],AC_MSG_ERROR([--with-$1 path does not point to a directory])) | |
266 | m4_translit([with_$1], [-+.], [___])=yes | |
267 | AS_IF([test -d "$withval/lib64"],[$3_PATH+="-L$withval/lib64"]) | |
268 | AS_IF([test -d "$withval/lib"],[$3_PATH+="-L$withval/lib"]) | |
269 | AS_IF([test -d "$withval/include"],[$3_CFLAGS+="-I$withval/include"]) | |
24531401 AJ |
270 | ]) |
271 | ]) | |
8780c450 | 272 | AS_IF([test "x$withval" = "x"],[m4_translit([with_$1], [-+.], [___])=no]) |
24531401 AJ |
273 | ]) |
274 | ||
4fe75473 FC |
275 | AC_DEFUN([SQUID_EMBED_BUILD_INFO],[ |
276 | AC_ARG_ENABLE([build-info], | |
277 | AS_HELP_STRING([--enable-build-info="build info string"], | |
b9c250bf | 278 | [Add an additional string in the output of "squid -v". |
4fe75473 | 279 | Default is not to add anything. If the string is not specified, |
9603207d | 280 | tries to determine nick and revision number of the current |
4fe75473 | 281 | bazaar branch]),[ |
a1c22363 AJ |
282 | AS_CASE(["$enableval"], |
283 | [no],[:], | |
284 | [yes],[ | |
285 | AS_IF([test -d "${srcdir}/.bzr"],[ | |
286 | AC_PATH_PROG(BZR,bzr,$FALSE) | |
287 | squid_bzr_branch_nick=`cd ${srcdir} && ${BZR} nick 2>/dev/null` | |
288 | AS_IF([test $? -eq 0 -a "x$squid_bzr_branch_nick" != "x"],[ | |
289 | squid_bzr_branch_revno=`cd ${srcdir} && ${BZR} revno 2>/dev/null | sed 's/\"//g'` | |
290 | ]) | |
291 | AS_IF([test $? -eq 0 -a "x$squid_bzr_branch_revno" != "x"],[ | |
292 | sh -c "cd ${srcdir} && ${BZR} diff 2>&1 >/dev/null" | |
293 | AS_IF([test $? -eq 1],[ | |
4fe75473 | 294 | squid_bzr_branch_revno="$squid_bzr_branch_revno+changes" |
a1c22363 AJ |
295 | ]) |
296 | ]) | |
297 | AS_IF([test "x$squid_bzr_branch_revno" != "x"],[ | |
298 | squid_build_info="Built branch: ${squid_bzr_branch_nick}-r${squid_bzr_branch_revno}" | |
299 | ]) | |
300 | ]) | |
301 | ], | |
302 | [squid_build_info=$enableval] | |
303 | ) | |
4fe75473 | 304 | ]) |
90cf433e FC |
305 | AC_DEFINE_UNQUOTED([SQUID_BUILD_INFO],["$squid_build_info"], |
306 | [Squid extended build info field for "squid -v" output]) | |
4fe75473 | 307 | ]) |
391f0bac FC |
308 | |
309 | dnl like AC_SEARCH_LIBS, with an extra argument which is | |
310 | dnl a prefix to the test program | |
311 | AC_DEFUN([SQUID_SEARCH_LIBS], | |
312 | [AS_VAR_PUSHDEF([ac_Search], [ac_cv_search_$1])dnl | |
313 | AC_CACHE_CHECK([for library containing $1], [ac_Search], | |
314 | [ac_func_search_save_LIBS=$LIBS | |
315 | AC_LANG_CONFTEST([AC_LANG_PROGRAM([$6], [$1()])]) | |
316 | for ac_lib in '' $2; do | |
a1c22363 | 317 | AS_IF([test -z "$ac_lib"],[ |
391f0bac | 318 | ac_res="none required" |
a1c22363 | 319 | ],[ |
391f0bac FC |
320 | ac_res=-l$ac_lib |
321 | LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS" | |
a1c22363 | 322 | ]) |
3aa7893f | 323 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], [AS_VAR_SET([ac_Search], [$ac_res])]) |
391f0bac FC |
324 | AS_VAR_SET_IF([ac_Search], [break]) |
325 | done | |
326 | AS_VAR_SET_IF([ac_Search], , [AS_VAR_SET([ac_Search], [no])]) | |
327 | rm conftest.$ac_ext | |
328 | LIBS=$ac_func_search_save_LIBS]) | |
329 | ac_res=AS_VAR_GET([ac_Search]) | |
a1c22363 AJ |
330 | AS_IF([test "$ac_res" != no],[ |
331 | AS_IF([test "$ac_res" != "none required"],[LIBS="$ac_res $LIBS"]) | |
332 | $3],[$4]) | |
391f0bac FC |
333 | AS_VAR_POPDEF([ac_Search])dnl |
334 | ]) |