3 AT_BANNER([Autoconf base layer.])
5 # Copyright (C) 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010
6 # Free Software Foundation, Inc.
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, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ## ------------------------------- ##
23 ## AC_REQUIRE: topological sort.. ##
24 ## ------------------------------- ##
26 # Check that dependencies are always properly honored.
28 AT_SETUP([AC_REQUIRE: topological sort])
29 AT_KEYWORDS([m4@&t@_require])
31 AT_DATA([configure.ac],
32 [[define([REQUIRE_AND_CHECK],
34 test -z "$m4@&t@_translit([$1], [A-Z], [a-z])" && AS_EXIT(1)])
37 [REQUIRE_AND_CHECK([TEST2a])
38 REQUIRE_AND_CHECK([TEST2b])
45 [REQUIRE_AND_CHECK([TEST3])
49 [REQUIRE_AND_CHECK([TEST2a])
56 AC_MSG_ERROR([\$test1 is empty])
66 ## --------------------------- ##
67 ## AC_REQUIRE: error message. ##
68 ## --------------------------- ##
70 # Check that the message mentions AC_DEFUN, not m4_defun.
72 AT_SETUP([AC_REQUIRE: error message])
73 AT_KEYWORDS([m4@&t@_require])
74 AT_DATA([configure.ac],
75 [[AC_REQUIRE([AC_PROG_CC])
78 AT_CHECK_AUTOCONF([], [1], [],
79 [[configure.ac:1: error: AC_REQUIRE(AC_PROG_CC): cannot be used outside of an AC_DEFUN'd macro
80 configure.ac:1: the top level
81 autom4te: m4 failed with exit status: 1
86 ## ----------------------------------------------- ##
87 ## AC_REQUIRE and AC_DEFUN_ONCE: Require, expand. ##
88 ## ----------------------------------------------- ##
90 AT_SETUP([AC_REQUIRE & AC_DEFUN_ONCE: [Require, expand]])
91 AT_KEYWORDS([m4@&t@_require m4@&t@_require_once])
93 AT_DATA([configure.ac],
95 [AC_REQUIRE([MULTI_TEST])
96 AC_REQUIRE([SINGLE_TEST])])
98 AC_DEFUN([MULTI_TEST],
99 [multi_test=".$multi_test"])
101 AC_DEFUN_ONCE([SINGLE_TEST],
102 [single_test=".$single_test"])
113 case $multi_test:$single_test in
115 ...:* ) AC_MSG_ERROR([DEFUN_ONCE is broken]);;
116 *:. ) AC_MSG_ERROR([DEFUN is broken (Wow, congrats!)]);;
120 AT_CHECK_AUTOCONF([], 0, [])
128 ## ----------------------------------------------- ##
129 ## AC_REQUIRE and AC_DEFUN_ONCE: Expand, require. ##
130 ## ----------------------------------------------- ##
132 AT_SETUP([AC_REQUIRE & AC_DEFUN_ONCE: [Expand, require]])
133 AT_KEYWORDS([m4@&t@_require m4@&t@_require_once])
135 AT_DATA([configure.ac],
137 [AC_REQUIRE([MULTI_TEST])
138 AC_REQUIRE([SINGLE_TEST])])
140 AC_DEFUN([MULTI_TEST],
141 [multi_test=".$multi_test"])
143 AC_DEFUN_ONCE([SINGLE_TEST],
144 [single_test=".$single_test"])
155 case $multi_test:$single_test in
157 ..:* ) AC_MSG_ERROR([DEFUN_ONCE is broken]);;
158 *:. ) AC_MSG_ERROR([DEFUN is broken (Wow, congrats!)]);;
159 * ) AC_MSG_ERROR([received `$multi_test:$single_test']);;
163 AT_CHECK_AUTOCONF([], 0, [])
170 ## ------------------------- ##
171 ## AC_REQUIRE & AC_PROVIDE. ##
172 ## ------------------------- ##
174 AT_SETUP([AC_REQUIRE & AC_PROVIDE])
175 AT_KEYWORDS([m4@&t@_require])
177 AT_DATA([configure.ac],
179 [AC_REQUIRE([INNER_TEST])])
181 AC_DEFUN([INNER_TEST],
182 [inner_test=".$inner_test"])
186 AC_PROVIDE([INNER_TEST])
191 * ) AC_MSG_ERROR([received `$inner_test']);;
205 # Make sure AC_INIT sets PACKAGE_TARNAME properly.
209 AT_DATA([configure.ac],
210 [[AC_INIT([GNU fu], [1.0], [bug-fu@gnu.org])
214 AT_CHECK_CONFIGURE([-q])
216 # Ensure we get the expected definition:
217 AT_CHECK([grep "^PACKAGE_TARNAME='fu'\$" configure], [], [ignore])
222 ## ------------------------------------- ##
223 ## AC_INIT with unusual version strings. ##
224 ## ------------------------------------- ##
226 AT_SETUP([AC_INIT with unusual version strings])
228 AT_DATA([configure.ac],
229 [[AC_INIT([GNU String++ with spaces (foo)],
230 [2.48++ (2010-07-03)], [http://clisp.cons.org/], [clisp])
234 AT_CHECK_AUTOCONF([-Werror])
235 AT_CHECK_CONFIGURE([-q])
236 AT_CHECK_CONFIGURE([--help])
237 AT_CHECK_CONFIGURE([--version])
238 AT_CHECK([./config.status --version], [], [ignore])
247 # Ensure the FSF notice as well as the user-provided one are present
248 # in the head of the testsuite as well as the --version output.
250 AT_SETUP([AC@&t@_COPYRIGHT])
252 AT_DATA([configure.ac],
253 [[AC_INIT([GNU fu], [1.0])
254 AC_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid
255 words that may be matched by scanners for legal things,
256 causing extra work for distributors.
257 Multi-line values should be supported.
262 AT_CHECK_CONFIGURE([--version], [], [stdout])
263 AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore])
264 AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore])
265 AT_CHECK([sed -ne 50q -e '/Copyright/{' -e N -e N -e N -e N -e 's/#//g' ]dnl
266 [ -e 's/\n//g' -e p -e '}' configure ]dnl
267 [ | grep 'Copyright.*Free Software Foundation'],
269 AT_CHECK([sed 50q configure | grep 'This is just a test notice'], [], [ignore])
274 ## ---------------- ##
275 ## AC_CACHE_CHECK. ##
276 ## ---------------- ##
278 # Make sure AC_CACHE_CHECK is silent with -q.
279 # Also make sure we warn about cache id's not named with `_cv_'.
281 AT_SETUP([AC_CACHE_CHECK])
282 AT_KEYWORDS([CONFIG_SITE])
284 # Don't let a config.site file affect this test.
285 AS_UNSET([CONFIG_SITE])
287 AT_DATA([configure.ac],
289 # m4_define([ac_nothing], [ac_cv_absolutely_nothing])
290 AC_CACHE_CHECK([for nothing],
294 AC_MSG_CHECKING([for some other variable])
295 commands_to_set_it_was_run=false
296 AC_CACHE_VAL([my_cv_variable], [
298 commands_to_set_it_was_run=true
301 AC_MSG_RESULT([$my_cv_variable])
303 # Ensure that the result is available at this point.
304 if test ${my_cv_variable+set} != set; then
305 AC_MSG_ERROR([AC@&@&t@t@_CACHE_VAL did not ensure that the cache variable was set])
308 # AC_CACHE_SAVE should be enough here, no need for AC_OUTPUT.
312 AT_CHECK_AUTOCONF([], [], [], [stderr])
313 AT_CHECK([grep 'must contain _cv_ to be cached' stderr], [], [ignore])
315 # Do not warn about defines:
316 sed 's/^# m4_define/m4_define/' configure.ac > t
319 AT_CHECK_CONFIGURE([-q])
321 sed '/m4_define/d; s/ac_nothing/ac_cv_nothing/' configure.ac > t
324 AT_CHECK_CONFIGURE([-q])
326 # Print a message saying that the result was cached, iff it was cached.
327 AT_CHECK_CONFIGURE([], [], [stdout])
328 AT_CHECK([grep 'cached' stdout], [1])
329 AT_CHECK_CONFIGURE([my_cv_variable='yes it is set'], [], [stdout])
330 AT_CHECK([grep 'cached.*yes it is set' stdout], [], [ignore])
332 # --cache-file is honored and has caching semantics.
333 AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
334 AT_CHECK([grep 'cached' stdout], [1])
335 AT_CHECK([test ! -f config.cache])
336 AT_CHECK([grep 'my_cv_variable.*true' foobar.cache], [], [ignore])
337 AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
338 AT_CHECK([grep 'some other variable.*cached.*true' stdout], [], [ignore])
340 # A setting on the command line overrides the cache.
341 AT_CHECK_CONFIGURE([--cache-file=foobar.cache my_cv_variable='override'], [], [stdout])
342 AT_CHECK([grep 'cached.*override' stdout], [], [ignore])
343 AT_CHECK([grep 'my_cv_variable.*override' foobar.cache], [], [ignore])
345 # Values containing braces need special internal treatment.
346 AT_CHECK_CONFIGURE([-C ac_cv_nothing='{' my_cv_variable='contains } brace'],
348 AT_CHECK([grep 'ac_cv_nothing.*{' config.cache], [], [ignore])
349 AT_CHECK([grep 'my_cv_variable.*contains } brace' config.cache], [], [ignore])
350 AT_CHECK_CONFIGURE([-C], [], [stdout])
351 AT_CHECK([grep 'nothing.*{' stdout], [], [ignore])
352 AT_CHECK([grep 'some other variable.*contains } brace' stdout], [], [ignore])
355 # Diagnose common side-effects that are errors in COMMANDS-TO-SET-IT:
356 sed 's/^# FOO/AC_DEFINE([some-define], [1], [oooh.])/' configure.ac > t
358 AT_CHECK_AUTOCONF([], [], [], [stderr])
359 AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
361 sed 's/^AC_DEFINE.*/AC_SUBST([some_substitution], [oooh.])/' configure.ac > t
363 AT_CHECK_AUTOCONF([], [], [], [stderr])
364 AT_CHECK([grep 'suspicious.*AC_SUBST' stderr], [], [ignore])
366 # Ensure the examples from the manual work as intended.
367 # Taken from autoconf.texi:Caching Results
368 AT_DATA([configure.ac],
370 AC_DEFUN([AC_SHELL_TRUE],
371 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
372 [my_cv_shell_true_works=no
373 (true) 2>/dev/null && my_cv_shell_true_works=yes
374 if test "x$my_cv_shell_true_works" = xyes; then
375 AC_DEFINE([TRUE_WORKS], [1],
376 [Define if `true(1)' works properly.])
381 AT_CHECK_AUTOCONF([-Werror], [1], [], [stderr])
382 AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
384 # Taken from autoconf.texi:Caching Results
385 AT_DATA([configure.ac],
387 AC_DEFUN([AC_SHELL_TRUE],
388 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
389 [my_cv_shell_true_works=no
390 (true) 2>/dev/null && my_cv_shell_true_works=yes])
391 if test "x$my_cv_shell_true_works" = xyes; then
392 AC_DEFINE([TRUE_WORKS], [1],
393 [Define if `true(1)' works properly.])
399 AT_CHECK_AUTOCONF([-Werror])
400 AT_CHECK_CONFIGURE([-C], [], [stdout])
401 AT_CHECK([grep my_cv_shell_true_works config.cache], [], [ignore])
402 AT_CHECK([grep 'true.*works.*yes' stdout], [], [ignore])
404 AT_CHECK_CONFIGURE([--config-cache], [], [stdout])
405 AT_CHECK([grep 'true.*works.*cached.*yes' stdout], [], [ignore])
407 # config.status only pays attention to the cache file with --recheck.
408 AT_CHECK([./config.status], [], [stdout])
409 AT_CHECK([grep cache stdout], [1])
410 AT_CHECK([./config.status --recheck], [], [stdout])
411 AT_CHECK([grep cache stdout], [0], [ignore])
413 # By default, configure uses no cache file, neither loading nor updating it.
415 AT_CHECK_CONFIGURE([], [], [stdout])
416 AT_CHECK([grep cache stdout], [1])
417 AT_CHECK([LC_ALL=C ls -t config.cache a-stamp-file | sed 1q | grep config.cache], [1])
419 # config.site can specify a site-wide cache, accumulating information.
420 # Also test that we don't run afoul of sourcing a file with leading -.
421 AT_DATA([-config.site],
422 [[cache_file=sitecache
425 [[my_cv_some_preset_cache_var=yes
427 CONFIG_SITE=-config.site
430 AT_CHECK([grep my_cv_some_preset_cache_var sitecache], [], [ignore])
431 AT_CHECK([grep my_cv_shell_true_works sitecache], [], [ignore])
432 AT_CHECK_CONFIGURE([], [], [stdout])
433 AT_CHECK([grep 'whether true.*works.*cached' stdout], [], [ignore])
435 # Check that config cache scripts must be well-formed.
439 CONFIG_SITE=$PWD/bad.site
440 AT_CHECK_CONFIGURE([], [1], [ignore], [stderr])
441 AT_CHECK([grep 'failed to load site script' stderr], [], [ignore])
443 # However, a missing file is ignored.
444 CONFIG_SITE=./no-such-file
450 ## --------------- ##
452 ## --------------- ##
454 # Test AC_CACHE_LOAD.
456 AT_SETUP([AC_CACHE_LOAD])
458 AT_DATA([configure.ac],
462 AC_MSG_NOTICE([some_cv_variable is $some_cv_variable])
466 AS_UNSET([some_test_code])
468 [[some_cv_variable=value-from-new-cache
470 AT_CHECK_CONFIGURE([some_test_code='eval cache_file=new-cache'], [], [stdout])
471 AT_CHECK([grep 'some_cv_variable.*value-from-new-cache' stdout], [], [ignore])
476 ## ---------------- ##
477 ## AC_COMPUTE_INT. ##
478 ## ---------------- ##
480 # Make sure AC_COMPUTE_INT fails properly.
482 AT_SETUP([AC_COMPUTE_INT])
484 AT_DATA([configure.ac],
486 AC_COMPUTE_INT([invalid_expression],
489 [invalid_expression=failed])
490 test "$invalid_expression" = failed ||
491 AC_MSG_ERROR([**0** evaluated to $invalid_expression instead of failing])
500 ## ---------------- ##
501 ## AC_TRY_COMMAND. ##
502 ## ---------------- ##
504 AT_SETUP([AC_TRY_COMMAND])
506 AT_DATA([configure.ac],
509 if AC_TRY_COMMAND([(echo "The Cat in the Hat";
510 echo "The Hat in the Cat" >&2) |
511 grep \^The\ Cat\ in\ the\ Hat\$ >/dev/null]); then
514 AC_MSG_ERROR([didn't see the Cat in the Hat])
517 if AC_TRY_COMMAND([(echo "The Cat in the Hat";
518 echo "The Hat in the Cat" >&2) |
519 grep \^The\ Hat\ in\ the\ Cat\$ >/dev/null]); then
520 AC_MSG_ERROR([saw the Hat in the Cat])
525 AT_CHECK_CONFIGURE([-q])
534 AT_SETUP([Input/Output])
536 AT_DATA([configure.ac],
538 cat <&AS@&t@_ORIGINAL_STDIN_FD >&AS@&t@_MESSAGE_FD
541 AT_CHECK([echo Hello | CONFIG_SITE=/dev/null ./configure $configure_options | grep -v 'configure: loading site script '],, [Hello
543 AT_CHECK([echo Hello | CONFIG_SITE=/dev/null ./configure $configure_options --silent])
548 ## ------------------- ##
549 ## configure arguments ##
550 ## ------------------- ##
552 AT_SETUP([configure arguments])
554 AT_DATA([configure.ac],
560 AT_CHECK_CONFIGURE([FOO=bar --enable-baz --without-zork --silent], [0], [stdout], [ignore])
561 AT_CHECK([grep 'FOO=bar --enable-baz --without-zork --silent' stdout], [0], [ignore], [ignore])
563 dnl check that syntax error is detected
564 AT_CHECK_CONFIGURE([=], [1], [], [ignore], [ignore])
565 AT_CHECK_CONFIGURE([1=2], [1], [], [ignore], [ignore])
570 ## ------------------------------ ##
571 ## AC_ARG_ENABLE and AC_ARG_WITH. ##
572 ## ------------------------------ ##
574 AT_SETUP([AC_ARG_ENABLE and AC_ARG_WITH])
576 AT_DATA_M4SH([configure.ac],
578 # Taken from autoconf.texi:Pretty Help Strings.
580 [AS_HELP_STRING([--with-foo],
581 [use foo (default is no)])],
585 [AS_HELP_STRING([--with-c++],
587 [choice_with=$withval])
589 [AS_HELP_STRING([--enable-c++],
591 [choice_enable=$enableval])
592 echo "use_foo: $use_foo"
593 echo "with_c++: $with_c__, $choice_with"
594 echo "enable_c++: $enable_c__, $choice_enable"
598 AT_CHECK_CONFIGURE([--help | grep foo], [0],
599 [[ --with-foo use foo (default is no)
601 AT_CHECK_CONFIGURE([--with-foo=yes --with-c++ --disable-c++],
602 [], [stdout], [ignore])
603 AT_CHECK([grep 'use_foo: yes' stdout], [], [ignore])
604 AT_CHECK([grep 'with_c++: yes, yes' stdout], [], [ignore])
605 AT_CHECK([grep 'enable_c++: no, no' stdout], [], [ignore])
606 AT_CHECK([grep 'unrecognized option' stdout], [1])
607 AT_CHECK_CONFIGURE([--without-foo --with-c++=no --enable-c++=maybe],
608 [], [stdout], [ignore])
609 AT_CHECK([grep 'use_foo: no' stdout], [], [ignore])
610 AT_CHECK([grep 'with_c++: no, no' stdout], [], [ignore])
611 AT_CHECK([grep 'enable_c++: maybe, maybe' stdout], [], [ignore])
612 AT_CHECK([grep 'unrecognized option' stdout], [1])
613 AT_CHECK_CONFIGURE([], [], [stdout], [ignore])
614 AT_CHECK([grep 'use_foo: no' stdout], [], [ignore])
615 AT_CHECK([grep 'with_c++: , $' stdout], [], [ignore])
616 AT_CHECK([grep 'enable_c++: , $' stdout], [], [ignore])
617 AT_CHECK([grep 'unrecognized option' stdout], [1])
622 ## --------------------- ##
623 ## configure directories ##
624 ## --------------------- ##
626 AT_SETUP([configure directories])
630 exec_prefix=@exec_prefix@
634 AT_DATA([configure.ac],
636 AC_CONFIG_FILES([foo])
641 dnl check that relative paths are rejected
642 AT_CHECK_CONFIGURE([--libdir=.], [1], [ignore], [stderr])
643 AT_CHECK([grep 'expected an absolute directory name for --libdir: \.' stderr],
646 dnl check that extra slashes are stripped, and that defaults are not expanded
647 AT_CHECK_CONFIGURE([--prefix=/usr//])
648 AT_CHECK([cat foo], [0], [[prefix=/usr
649 exec_prefix=${prefix}
650 libdir=${exec_prefix}/lib