3 AT_BANNER([Autoconf base layer.])
5 # Copyright (C) 2000-2001, 2003, 2005-2013 Free Software Foundation,
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://example.com/?a=b&c=d#e]], [clisp])
234 if echo 'ab*c' | grep -F 'ab*c' >/dev/null 2>&1; then
240 AT_CHECK_AUTOCONF([-Werror])
241 AT_CHECK_CONFIGURE([-q])
242 AT_CHECK_CONFIGURE([--help], [], [stdout])
243 AT_CHECK([[$FGREP 'com/?a=b&c=d#e' stdout]], [], [ignore])
244 AT_CHECK_CONFIGURE([--version], [], [stdout])
245 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
246 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
248 AT_CHECK([./config.status --help], [], [stdout])
249 AT_CHECK([[$FGREP 'com/?a=b&c=d#e' stdout]], [], [ignore])
250 AT_CHECK([./config.status --version], [], [stdout])
251 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
252 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
254 AT_DATA([configure.ac],
255 [[AC_INIT([GNU "String++"],
256 [2.48], [http://example.com/], [clisp])
260 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
261 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
263 AT_DATA([configure.ac],
264 [[AC_INIT([GNU String++],
265 ['codename' 2.48], [http://example.com/], [clisp])
269 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
270 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
272 AT_DATA([configure.ac],
274 String++], [2.48], [http://example.com/], [clisp])
278 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
279 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
288 # Ensure the FSF notice as well as the user-provided one are present
289 # in the head of the testsuite as well as the --version output.
291 AT_SETUP([AC@&t@_COPYRIGHT])
293 AT_DATA([configure.ac],
294 [[AC_INIT([GNU fu], [1.0])
295 AC_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid
296 words that may be matched by scanners for legal things,
297 causing extra work for distributors.
298 Multi-line values should be supported.
303 AT_CHECK_CONFIGURE([--version], [], [stdout])
304 AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore])
305 AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore])
306 AT_CHECK([sed -ne 50q -e '/Copyright/{' -e N -e N -e N -e N -e 's/#//g' ]dnl
307 [ -e 's/\n//g' -e p -e '}' configure ]dnl
308 [ | grep 'Copyright.*Free Software Foundation'],
310 AT_CHECK([sed 50q configure | grep 'This is just a test notice'], [], [ignore])
315 ## ---------------- ##
316 ## AC_CACHE_CHECK. ##
317 ## ---------------- ##
319 # Make sure AC_CACHE_CHECK is silent with -q.
320 # Also make sure we warn about cache id's not named with `_cv_'.
322 AT_SETUP([AC_CACHE_CHECK])
323 AT_KEYWORDS([CONFIG_SITE])
325 # Don't let a config.site file affect this test.
326 AS_UNSET([CONFIG_SITE])
328 AT_DATA([configure.ac],
330 # m4_define([ac_nothing], [ac_cv_absolutely_nothing])
331 AC_CACHE_CHECK([for nothing],
335 AC_MSG_CHECKING([for some other variable])
336 commands_to_set_it_was_run=false
337 AC_CACHE_VAL([my_cv_variable], [
339 commands_to_set_it_was_run=true
342 AC_MSG_RESULT([$my_cv_variable])
344 # Ensure that the result is available at this point.
345 if test ${my_cv_variable+set} != set; then
346 AC_MSG_ERROR([AC@&@&t@t@_CACHE_VAL did not ensure that the cache variable was set])
349 # AC_CACHE_SAVE should be enough here, no need for AC_OUTPUT.
353 AT_CHECK_AUTOCONF([], [], [], [stderr])
354 AT_CHECK([grep 'must contain _cv_ to be cached' stderr], [], [ignore])
356 # Do not warn about defines:
357 sed 's/^# m4_define/m4_define/' configure.ac > t
360 AT_CHECK_CONFIGURE([-q])
362 sed '/m4_define/d; s/ac_nothing/ac_cv_nothing/' configure.ac > t
365 AT_CHECK_CONFIGURE([-q])
367 # Print a message saying that the result was cached, iff it was cached.
368 AT_CHECK_CONFIGURE([], [], [stdout])
369 AT_CHECK([grep 'cached' stdout], [1])
370 AT_CHECK_CONFIGURE([my_cv_variable='yes it is set'], [], [stdout])
371 AT_CHECK([grep 'cached.*yes it is set' stdout], [], [ignore])
373 # --cache-file is honored and has caching semantics.
374 AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
375 AT_CHECK([grep 'cached' stdout], [1])
376 AT_CHECK([test ! -f config.cache])
377 AT_CHECK([grep 'my_cv_variable.*true' foobar.cache], [], [ignore])
378 AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
379 AT_CHECK([grep 'some other variable.*cached.*true' stdout], [], [ignore])
381 # A setting on the command line overrides the cache.
382 AT_CHECK_CONFIGURE([--cache-file=foobar.cache my_cv_variable='override'], [], [stdout])
383 AT_CHECK([grep 'cached.*override' stdout], [], [ignore])
384 AT_CHECK([grep 'my_cv_variable.*override' foobar.cache], [], [ignore])
386 # Values containing braces need special internal treatment.
387 AT_CHECK_CONFIGURE([-C ac_cv_nothing='{' my_cv_variable='contains } brace'],
389 AT_CHECK([grep 'ac_cv_nothing.*{' config.cache], [], [ignore])
390 AT_CHECK([grep 'my_cv_variable.*contains } brace' config.cache], [], [ignore])
391 AT_CHECK_CONFIGURE([-C], [], [stdout])
392 AT_CHECK([grep 'nothing.*{' stdout], [], [ignore])
393 AT_CHECK([grep 'some other variable.*contains } brace' stdout], [], [ignore])
396 # Diagnose common side-effects that are errors in COMMANDS-TO-SET-IT:
397 sed 's/^# FOO/AC_DEFINE([some-define], [1], [oooh.])/' configure.ac > t
399 AT_CHECK_AUTOCONF([], [], [], [stderr])
400 AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
402 sed 's/^AC_DEFINE.*/AC_SUBST([some_substitution], [oooh.])/' configure.ac > t
404 AT_CHECK_AUTOCONF([], [], [], [stderr])
405 AT_CHECK([grep 'suspicious.*AC_SUBST' stderr], [], [ignore])
407 # Ensure the examples from the manual work as intended.
408 # Taken from autoconf.texi:Caching Results
409 AT_DATA([configure.ac],
411 AC_DEFUN([AC_SHELL_TRUE],
412 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
413 [my_cv_shell_true_works=no
414 (true) 2>/dev/null && my_cv_shell_true_works=yes
415 if test "x$my_cv_shell_true_works" = xyes; then
416 AC_DEFINE([TRUE_WORKS], [1],
417 [Define if `true(1)' works properly.])
422 AT_CHECK_AUTOCONF([-Werror], [1], [], [stderr])
423 AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
425 # Taken from autoconf.texi:Caching Results
426 AT_DATA([configure.ac],
428 AC_DEFUN([AC_SHELL_TRUE],
429 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
430 [my_cv_shell_true_works=no
431 (true) 2>/dev/null && my_cv_shell_true_works=yes])
432 if test "x$my_cv_shell_true_works" = xyes; then
433 AC_DEFINE([TRUE_WORKS], [1],
434 [Define if `true(1)' works properly.])
440 AT_CHECK_AUTOCONF([-Werror])
441 AT_CHECK_CONFIGURE([-C], [], [stdout])
442 AT_CHECK([grep my_cv_shell_true_works config.cache], [], [ignore])
443 AT_CHECK([grep 'true.*works.*yes' stdout], [], [ignore])
445 AT_CHECK_CONFIGURE([--config-cache], [], [stdout])
446 AT_CHECK([grep 'true.*works.*cached.*yes' stdout], [], [ignore])
448 # config.status only pays attention to the cache file with --recheck.
449 AT_CHECK([./config.status], [], [stdout])
450 AT_CHECK([grep cache stdout], [1])
451 AT_CHECK([./config.status --recheck], [], [stdout])
452 AT_CHECK([grep cache stdout], [0], [ignore])
454 # By default, configure uses no cache file, neither loading nor updating it.
456 AT_CHECK_CONFIGURE([], [], [stdout])
457 AT_CHECK([grep cache stdout], [1])
458 AT_CHECK([LC_ALL=C ls -t config.cache a-stamp-file | sed 1q | grep config.cache], [1])
460 # Using a symlinked cache file works.
463 AS_LN_S([cache], [config.cache])
464 AT_CHECK_CONFIGURE([-C])
465 # Either the system does not support symlinks, or the symlinked-to file
467 AT_CHECK([test -s cache || test ! -h config.cache])
469 # config.site can specify a site-wide cache, accumulating information.
470 # Also test that we don't run afoul of sourcing a file with leading -.
471 AT_DATA([-config.site],
472 [[cache_file=sitecache
475 [[my_cv_some_preset_cache_var=yes
477 CONFIG_SITE=-config.site
480 AT_CHECK([grep my_cv_some_preset_cache_var sitecache], [], [ignore])
481 AT_CHECK([grep my_cv_shell_true_works sitecache], [], [ignore])
482 AT_CHECK_CONFIGURE([], [], [stdout])
483 AT_CHECK([grep 'whether true.*works.*cached' stdout], [], [ignore])
485 dnl Until we can find a way to avoid catastrophic failure,
486 dnl skip the rest of this test on such shells.
488 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
489 0|"") exit 77;; esac'], [0], [ignore], [ignore])
491 # Check that config cache scripts must be well-formed.
495 CONFIG_SITE=$PWD/bad.site
496 AT_CHECK_CONFIGURE([ || exit 1], [1], [stdout], [stderr])
497 AT_CHECK([grep 'failed to load site script' stderr], [], [ignore], [ignore],
498 [AT_CHECK([grep 'whether true' stdout], [1])])
500 # However, a missing file is ignored.
501 CONFIG_SITE=./no-such-file
507 ## --------------- ##
509 ## --------------- ##
511 # Test AC_CACHE_LOAD.
513 AT_SETUP([AC_CACHE_LOAD])
515 AT_DATA([configure.ac],
519 AC_MSG_NOTICE([some_cv_variable is $some_cv_variable])
523 AS_UNSET([some_test_code])
525 [[some_cv_variable=value-from-new-cache
527 AT_CHECK_CONFIGURE([some_test_code='eval cache_file=new-cache'], [], [stdout])
528 AT_CHECK([grep 'some_cv_variable.*value-from-new-cache' stdout], [], [ignore])
533 ## ---------------- ##
534 ## AC_COMPUTE_INT. ##
535 ## ---------------- ##
537 # Make sure AC_COMPUTE_INT fails properly.
539 AT_SETUP([AC_COMPUTE_INT])
541 AT_DATA([configure.ac],
543 AC_COMPUTE_INT([invalid_expression],
546 [invalid_expression=failed])
547 test "$invalid_expression" = failed ||
548 AC_MSG_ERROR([**0** evaluated to $invalid_expression instead of failing])
557 ## ---------------- ##
558 ## AC_TRY_COMMAND. ##
559 ## ---------------- ##
561 AT_SETUP([AC_TRY_COMMAND])
563 AT_DATA([configure.ac],
566 if AC_TRY_COMMAND([(echo "The Cat in the Hat";
567 echo "The Hat in the Cat" >&2) |
568 grep \^The\ Cat\ in\ the\ Hat\$ >/dev/null]); then
571 AC_MSG_ERROR([didn't see the Cat in the Hat])
574 if AC_TRY_COMMAND([(echo "The Cat in the Hat";
575 echo "The Hat in the Cat" >&2) |
576 grep \^The\ Hat\ in\ the\ Cat\$ >/dev/null]); then
577 AC_MSG_ERROR([saw the Hat in the Cat])
582 AT_CHECK_CONFIGURE([-q])
591 AT_SETUP([Input/Output])
593 AT_DATA([configure.ac],
595 cat <&AS@&t@_ORIGINAL_STDIN_FD >&AS@&t@_MESSAGE_FD
598 AT_CHECK([echo Hello | CONFIG_SITE=/dev/null ./configure $configure_options | grep -v 'configure: loading site script '],, [Hello
600 AT_CHECK([echo Hello | CONFIG_SITE=/dev/null ./configure $configure_options --silent])
605 ## ------------------- ##
606 ## configure arguments ##
607 ## ------------------- ##
609 AT_SETUP([configure arguments])
611 AT_DATA([configure.ac],
617 AT_CHECK_CONFIGURE([FOO=bar --enable-baz --without-zork --silent], [0], [stdout], [ignore])
618 AT_CHECK([grep 'FOO=bar --enable-baz --without-zork --silent' stdout], [0], [ignore], [ignore])
620 dnl check that syntax error is detected
621 AT_CHECK_CONFIGURE([=], [1], [], [ignore], [ignore])
622 AT_CHECK_CONFIGURE([1=2], [1], [], [ignore], [ignore])
627 ## ------------------------------ ##
628 ## AC_ARG_ENABLE and AC_ARG_WITH. ##
629 ## ------------------------------ ##
631 AT_SETUP([AC_ARG_ENABLE and AC_ARG_WITH])
633 AT_DATA_M4SH([configure.ac],
635 # Taken from autoconf.texi:Pretty Help Strings.
637 [AS_HELP_STRING([--with-foo],
638 [use foo (default is no)])],
642 [AS_HELP_STRING([--with-c++],
644 [choice_with=$withval])
646 [AS_HELP_STRING([--enable-c++],
648 [choice_enable=$enableval])
649 echo "use_foo: $use_foo"
650 echo "with_c++: $with_c__, $choice_with"
651 echo "enable_c++: $enable_c__, $choice_enable"
655 AT_CHECK_CONFIGURE([--help | grep foo], [0],
656 [[ --with-foo use foo (default is no)
658 AT_CHECK_CONFIGURE([--with-foo=yes --with-c++ --disable-c++],
659 [], [stdout], [ignore])
660 AT_CHECK([grep 'use_foo: yes' stdout], [], [ignore])
661 AT_CHECK([grep 'with_c++: yes, yes' stdout], [], [ignore])
662 AT_CHECK([grep 'enable_c++: no, no' stdout], [], [ignore])
663 AT_CHECK([grep 'unrecognized option' stdout], [1])
664 AT_CHECK_CONFIGURE([--without-foo --with-c++=no --enable-c++=maybe],
665 [], [stdout], [ignore])
666 AT_CHECK([grep 'use_foo: no' stdout], [], [ignore])
667 AT_CHECK([grep 'with_c++: no, no' stdout], [], [ignore])
668 AT_CHECK([grep 'enable_c++: maybe, maybe' stdout], [], [ignore])
669 AT_CHECK([grep 'unrecognized option' stdout], [1])
670 AT_CHECK_CONFIGURE([], [], [stdout], [ignore])
671 AT_CHECK([grep 'use_foo: no' stdout], [], [ignore])
672 AT_CHECK([grep 'with_c++: , $' stdout], [], [ignore])
673 AT_CHECK([grep 'enable_c++: , $' stdout], [], [ignore])
674 AT_CHECK([grep 'unrecognized option' stdout], [1])
679 ## --------------------- ##
680 ## configure directories ##
681 ## --------------------- ##
683 AT_SETUP([configure directories])
687 exec_prefix=@exec_prefix@
691 AT_DATA([configure.ac],
693 AC_CONFIG_FILES([foo])
698 dnl check that relative paths are rejected
699 AT_CHECK_CONFIGURE([--libdir=.], [1], [ignore], [stderr])
700 AT_CHECK([grep 'expected an absolute directory name for --libdir: \.' stderr],
703 dnl check that extra slashes are stripped, and that defaults are not expanded
704 AT_CHECK_CONFIGURE([--prefix=/usr//])
705 AT_CHECK([cat foo], [0], [[prefix=/usr
706 exec_prefix=${prefix}
707 libdir=${exec_prefix}/lib
717 AT_KEYWORDS([AS@&t@_IDENTIFIER_IF])
719 # Check that a valid variable name is used.
720 AT_DATA([configure.ac],
721 [[AC_INIT([test], [1])
725 AT_CHECK_AUTOCONF([], [1], [], [stderr])
726 AT_CHECK([grep 'not a valid shell variable' stderr], [], [ignore])
728 AT_DATA([configure.ac],
729 [[AC_INIT([test], [1])
733 AT_CHECK_AUTOCONF([], [1], [], [stderr])
734 AT_CHECK([grep 'not a valid shell variable' stderr], [], [ignore])
736 AT_DATA([configure.ac],
737 [[AC_INIT([test], [1])
741 AT_CHECK_AUTOCONF([], [1], [], [stderr])
742 AT_CHECK([grep 'not a valid shell variable' stderr], [], [ignore])
744 # Make sure AC_SUBST handles variables as expected.
750 AT_DATA([configure.ac],
751 [[AC_INIT([test], [0])
752 m4_define([FOO], [baz])
753 AC_SUBST([FOO], [bar])
757 AC_CONFIG_FILES([file])
761 AT_CHECK_AUTOCONF([], [], [], [stderr])
763 AT_CHECK([cat file], [],