3 AT_BANNER([Autoconf base layer.])
5 # Copyright (C) 2000-2001, 2003, 2005-2017, 2020-2024 Free Software
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 <https://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])
60 AT_CHECK_AUTOCONF([], [0], [],
61 [[trailer.m4: warning: AC_INIT was never used
62 trailer.m4: warning: AC_OUTPUT was never used
69 ## --------------------------- ##
70 ## AC_REQUIRE: error message. ##
71 ## --------------------------- ##
73 # Check that the message mentions AC_DEFUN, not m4_defun.
75 AT_SETUP([AC_REQUIRE: error message])
76 AT_KEYWORDS([m4@&t@_require])
77 AT_DATA([configure.ac],
78 [[AC_REQUIRE([AC_PROG_CC])
81 AT_CHECK_AUTOCONF([], [1], [],
82 [[configure.ac:1: error: AC_REQUIRE(AC_PROG_CC): cannot be used outside of an AC_DEFUN'd macro
83 configure.ac:1: the top level
84 autom4te: error: m4 failed with exit status: 1
89 ## ----------------------------------------------- ##
90 ## AC_REQUIRE and AC_DEFUN_ONCE: Require, expand. ##
91 ## ----------------------------------------------- ##
93 AT_SETUP([AC_REQUIRE & AC_DEFUN_ONCE: [Require, expand]])
94 AT_KEYWORDS([m4@&t@_require m4@&t@_require_once])
96 AT_DATA([configure.ac],
98 [AC_REQUIRE([MULTI_TEST])
99 AC_REQUIRE([SINGLE_TEST])])
101 AC_DEFUN([MULTI_TEST],
102 [multi_test=".$multi_test"])
104 AC_DEFUN_ONCE([SINGLE_TEST],
105 [single_test=".$single_test"])
116 case $multi_test:$single_test in
118 ...:* ) AC_MSG_ERROR([DEFUN_ONCE is broken]);;
119 *:. ) AC_MSG_ERROR([DEFUN is broken (Wow, congrats!)]);;
123 AT_CHECK_AUTOCONF([], 0, [],
124 [[trailer.m4: warning: AC_INIT was never used
125 trailer.m4: warning: AC_OUTPUT was never used
134 ## ----------------------------------------------- ##
135 ## AC_REQUIRE and AC_DEFUN_ONCE: Expand, require. ##
136 ## ----------------------------------------------- ##
138 AT_SETUP([AC_REQUIRE & AC_DEFUN_ONCE: [Expand, require]])
139 AT_KEYWORDS([m4@&t@_require m4@&t@_require_once])
141 AT_DATA([configure.ac],
143 [AC_REQUIRE([MULTI_TEST])
144 AC_REQUIRE([SINGLE_TEST])])
146 AC_DEFUN([MULTI_TEST],
147 [multi_test=".$multi_test"])
149 AC_DEFUN_ONCE([SINGLE_TEST],
150 [single_test=".$single_test"])
161 case $multi_test:$single_test in
163 ..:* ) AC_MSG_ERROR([DEFUN_ONCE is broken]);;
164 *:. ) AC_MSG_ERROR([DEFUN is broken (Wow, congrats!)]);;
165 * ) AC_MSG_ERROR([received '$multi_test:$single_test']);;
169 AT_CHECK_AUTOCONF([], 0, [],
170 [[trailer.m4: warning: AC_INIT was never used
171 trailer.m4: warning: AC_OUTPUT was never used
179 ## ------------------------- ##
180 ## AC_REQUIRE & AC_PROVIDE. ##
181 ## ------------------------- ##
183 AT_SETUP([AC_REQUIRE & AC_PROVIDE])
184 AT_KEYWORDS([m4@&t@_require])
186 AT_DATA([configure.ac],
188 [AC_REQUIRE([INNER_TEST])])
190 AC_DEFUN([INNER_TEST],
191 [inner_test=".$inner_test"])
195 AC_PROVIDE([INNER_TEST])
200 * ) AC_MSG_ERROR([received '$inner_test']);;
204 AT_CHECK_AUTOCONF([], 0, [],
205 [[trailer.m4: warning: AC_INIT was never used
206 trailer.m4: warning: AC_OUTPUT was never used
217 # Make sure AC_INIT sets PACKAGE_TARNAME properly.
221 AT_DATA([configure.ac],
222 [[AC_INIT([GNU fu], [1.0], [bug-fu@gnu.org])
227 AT_CHECK_CONFIGURE([-q])
229 # Ensure we get the expected definition:
230 AT_CHECK([grep "^PACKAGE_TARNAME='fu'\$" configure], [], [ignore])
234 ## ------------------------------- ##
235 ## AC_INIT (obsolete invocation). ##
236 ## ------------------------------- ##
238 # When AC_INIT is called with only one argument, it is equivalent to
239 # passing that argument to AC_CONFIG_SRCDIR and then calling AC_INIT
240 # with _no_ arguments. In particular, PACKAGE should _not_ be set
241 # to whatever the first argument is.
243 AT_SETUP([AC_INIT (obsolete invocation)])
245 AT_DATA([configure.ac],
246 [[AC_INIT([program.c])
252 # Ensure we get the expected definition:
253 AT_CHECK([grep "^PACKAGE_NAME=''\$" configure], [], [ignore])
255 # Running autoconf right now should fail because program.c doesn't exist.
256 AT_CHECK_CONFIGURE([], [1], [],
257 [[configure: error: cannot find sources (program.c) in . or ..
260 # Create program.c and then it should be fine.
267 ## ------------------------------------- ##
268 ## AC_INIT with unusual version strings. ##
269 ## ------------------------------------- ##
271 AT_SETUP([AC_INIT with unusual version strings])
273 if echo 'ab*c' | grep -F 'ab*c' >/dev/null 2>&1; then
279 # In both of the arguments that might contain URLs, make sure we test
280 # all of the unusual ASCII characters that commonly appear in URLs.
282 # The RFC 3986 "unreserved" characters are ASCII letters and digits, plus
284 # The RFC 3986 "gen-delims" and "sub-delims" are
285 # / : ? # [ ] @ ! $ & ' ( ) * + , ; =
286 # The URL escape character is
289 # Any argument that contains characters significant to M4,
291 # may need to be double-quoted depending on exactly how they are used
292 # (as would an argument that contains a macro name, but we don't test
295 # Characters that are still significant for Bourne shell within a
296 # single-quoted string, double-quoted string, quoted here-doc, or
297 # unquoted here-doc are explicitly not allowed:
300 # We don't test unbalanced parentheses or brackets here.
302 AT_DATA([configure.ac],
303 [[AC_INIT([GNU String++ with spaces
305 [2.48++ (2010-07-03)],
306 [[https://example/~bug/cdfijknoqrvw/-._:@!()[]*+,;/?y=z#1234567890]],
308 [[HTTPS://EXAMPLE/~PKG/BCDFIJNOQRUVW/-._:@!()[]*+,;/?y=z#1234567890]])
312 AT_CHECK_AUTOCONF([-Werror])
313 AT_CHECK_CONFIGURE([-q])
315 AT_CHECK_CONFIGURE([--help], [], [stdout])
317 'https://example/~bug/cdfijknoqrvw/-._:@!()[]*+,;/?y=z#1234567890' \
318 stdout]], [], [ignore])
320 'HTTPS://EXAMPLE/~PKG/BCDFIJNOQRUVW/-._:@!()[]*+,;/?y=z#1234567890' \
321 stdout]], [], [ignore])
323 AT_CHECK_CONFIGURE([--version], [], [stdout])
324 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
325 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
327 AT_CHECK([./config.status --help], [], [stdout])
329 'https://example/~bug/cdfijknoqrvw/-._:@!()[]*+,;/?y=z#1234567890' \
330 stdout]], [], [ignore])
332 'HTTPS://EXAMPLE/~PKG/BCDFIJNOQRUVW/-._:@!()[]*+,;/?y=z#1234567890' \
333 stdout]], [], [ignore])
335 AT_CHECK([./config.status --version], [], [stdout])
336 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
337 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
339 # Repeat the above test using all the unusual characters that might appear
340 # in a list of email addresses in both BUG-REPORT and URL. (URL isn't
341 # supposed to contain email addresses, but there's no good reason to
342 # restrict its syntax.)
343 # The RFC 5822 "atext" characters are ASCII letters and digits, plus
344 # ! # $ % & ' * + - / = ? ^ _ ` { | } ~
345 # The RFC 5822 "special" characters, all of which might appear somewhere
346 # in an address list, are
347 # ( ) < > [ ] : ; @ \ , . "
348 # As above, characters that are significant for Bourne shell within
349 # strings and heredocs are explicitly not allowed:
351 # As above, any argument that contains characters significant to M4,
353 # may need to be double-quoted depending on exactly how they are used
354 # (as would an argument that contains a macro name, but we don't test
357 AT_DATA([configure.ac],
358 [[AC_INIT([GNU String++ with spaces
360 [2.48++ (2010-07-03)],
361 [[bugs: fred <A=B?C^D_E@F>,
363 M%N&O@[156.247.38.49],
365 {jon|chyp~}@kqtvxz.VWXYZ;]],
367 [[contact: jem <A=B?C^D_E@bd>,
369 K%L&M@[156.247.38.49],
371 {qik|~prys}@wxz.VWXYZ;]])
375 AT_CHECK_AUTOCONF([-Werror])
376 AT_CHECK_CONFIGURE([-q])
378 AT_CHECK_CONFIGURE([--help], [], [stdout])
380 'bugs: fred <A=B?C^D_E@F>, G!H!I#J@K.L (wilma), M%N&O@[156.247.38.49], P*Q+R-S/T@U, {jon|chyp~}@kqtvxz.VWXYZ;' \
381 stdout]], [], [ignore])
383 'contact: jem <A=B?C^D_E@bd>, F!G!H#I@fv.J (lugh), K%L&M@[156.247.38.49], N*O+P-Q/R@STU, {qik|~prys}@wxz.VWXYZ;' \
384 stdout]], [], [ignore])
386 AT_CHECK_CONFIGURE([--version], [], [stdout])
387 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
388 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
390 AT_CHECK([./config.status --help], [], [stdout])
392 'bugs: fred <A=B?C^D_E@F>, G!H!I#J@K.L (wilma), M%N&O@[156.247.38.49], P*Q+R-S/T@U, {jon|chyp~}@kqtvxz.VWXYZ;' \
393 stdout]], [], [ignore])
395 'contact: jem <A=B?C^D_E@bd>, F!G!H#I@fv.J (lugh), K%L&M@[156.247.38.49], N*O+P-Q/R@STU, {qik|~prys}@wxz.VWXYZ;' \
396 stdout]], [], [ignore])
398 AT_CHECK([./config.status --version], [], [stdout])
399 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
400 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
402 # Check for invalid characters in each argument.
403 AT_DATA([configure.ac],
404 [[AC_INIT([GNU "String++"],
405 [2.48], [https://example.com/], [string++])
409 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
410 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
412 AT_DATA([configure.ac],
413 [[AC_INIT([GNU String++],
414 ['codename' 2.48], [https://example.com/], [string++])
418 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
419 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
421 AT_DATA([configure.ac],
423 String++], [2.48], [https://example.com/], [string++])
427 AT_CHECK_AUTOCONF([-Werror])
429 AT_DATA([configure.ac],
430 [[AC_INIT([GNU String++], ['2.48'], [https://example.com], [string++])
434 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
435 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
437 AT_DATA([configure.ac],
438 [[AC_INIT([GNU String++], [2.48], ['https://example.com'], [string++])
442 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
443 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
445 AT_DATA([configure.ac],
446 [[AC_INIT([GNU String++], [2.48], [https://example.com], [string++],
447 ['https://example.com'])
451 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
452 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
455 # The TARNAME argument is used to construct filenames, so it's even
458 AT_DATA([configure.ac],
459 [[AC_INIT([GNU String++], [2.48], [https://example.com], ['string++'])
463 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
464 AT_CHECK([grep 'AC_INIT: unsafe as a filename: ' stderr], [], [ignore])
466 AT_DATA([configure.ac],
467 [[AC_INIT([GNU String++], [2.48], [https://example.com], [string ++])
471 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
472 AT_CHECK([grep 'AC_INIT: unsafe as a filename: ' stderr], [], [ignore])
474 AT_DATA([configure.ac],
475 [[AC_INIT([GNU String++], [2.48], [https://example.com], [string*])
479 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
480 AT_CHECK([grep 'AC_INIT: unsafe as a filename: ' stderr], [], [ignore])
482 # Commas and unbalanced close parentheses are especially troublesome for M4.
483 # They are only expected to work when double-quoted, but even then they can
484 # cause malfunctions if not handled carefully within Autoconf.
486 AT_DATA([configure.ac],
487 [[AC_INIT([[GNU, String]], [2.48], [bugs@gstring.example],
488 [string], [https://gstring.example/])
493 AT_DATA([configure.ac],
494 [[AC_INIT([[GNU String)]], [2.48], [bugs@gstring.example],
495 [string], [https://gstring.example/])
500 AT_DATA([configure.ac],
501 [[AC_INIT([GNU String], [[2,48]], [bugs@gstring.example],
502 [string], [https://gstring.example/])
507 AT_DATA([configure.ac],
508 [[AC_INIT([GNU String], [[2.48)]], [bugs@gstring.example],
509 [string], [https://gstring.example/])
514 AT_DATA([configure.ac],
515 [[AC_INIT([GNU String], [2.48], [[bugs@gstring.example,
516 gstring-bugs@example.com]],
517 [string], [https://gstring.example/])
522 AT_DATA([configure.ac],
523 [[AC_INIT([GNU String], [2.48], [[bugs)@gstring.example]],
524 [string], [https://gstring.example/])
529 AT_DATA([configure.ac],
530 [[AC_INIT([GNU String], [2.48], [bugs@gstring.example],
531 [[string,]], [https://gstring.example/])
536 AT_DATA([configure.ac],
537 [[AC_INIT([GNU String], [2.48], [bugs@gstring.example],
538 [[string)]], [https://gstring.example/])
541 AT_CHECK_AUTOCONF([], [0], [ignore], [stderr])
542 AT_CHECK([grep 'AC_INIT: unsafe as a filename: ' stderr], [], [ignore])
544 AT_DATA([configure.ac],
545 [[AC_INIT([GNU String], [2.48], [bugs@gstring.example],
546 [string], [[https://gstring.example/docs,html]])
551 AT_DATA([configure.ac],
552 [[AC_INIT([GNU String], [2.48], [bugs@gstring.example],
553 [string], [[https://gstring.example/weird)/path]])
565 # Ensure the FSF notice as well as the user-provided one are present
566 # in the head of the testsuite as well as the --version output.
568 AT_SETUP([AC@&t@_COPYRIGHT])
570 AT_DATA([configure.ac],
571 [[AC_INIT([GNU fu], [1.0])
572 AC_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid
573 words that may be matched by scanners for legal things,
574 causing extra work for distributors.
575 Multi-line values should be supported.
581 AT_CHECK_CONFIGURE([--version], [], [stdout])
582 AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore])
583 AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore])
584 AT_CHECK([sed -ne 50q -e '/Copyright/{' -e N -e N -e N -e N -e 's/#//g' ]dnl
585 [ -e 's/\n//g' -e p -e '}' configure ]dnl
586 [ | grep 'Copyright.*Free Software Foundation'],
588 AT_CHECK([sed 50q configure | grep 'This is just a test notice'], [], [ignore])
593 ## ---------------- ##
594 ## AC_CACHE_CHECK. ##
595 ## ---------------- ##
597 # Make sure AC_CACHE_CHECK is silent with -q.
598 # Also make sure we warn about cache id's not named with '_cv_'.
600 AT_SETUP([AC_CACHE_CHECK])
601 AT_KEYWORDS([CONFIG_SITE])
603 AT_DATA([configure.ac],
605 # m4_define([ac_nothing], [ac_cv_absolutely_nothing])
606 AC_CACHE_CHECK([for nothing],
610 AC_MSG_CHECKING([for some other variable])
611 commands_to_set_it_was_run=false
612 AC_CACHE_VAL([my_cv_variable], [
614 commands_to_set_it_was_run=true
617 AC_MSG_RESULT([$my_cv_variable])
619 # Ensure that the result is available at this point.
620 if ${my_cv_variable+false} :; then
621 AC_MSG_ERROR([AC@&@&t@t@_CACHE_VAL did not ensure that the cache variable was set])
627 AT_CHECK_AUTOCONF([], [], [], [stderr])
628 AT_CHECK([grep 'must contain _cv_ to be cached' stderr], [], [ignore])
630 # Do not warn about defines:
631 sed 's/^# m4_define/m4_define/' configure.ac > t
634 AT_CHECK_CONFIGURE([-q])
636 sed '/m4_define/d; s/ac_nothing/ac_cv_nothing/' configure.ac > t
639 AT_CHECK_CONFIGURE([-q])
641 # Print a message saying that the result was cached, iff it was cached.
642 AT_CHECK_CONFIGURE([], [], [stdout])
643 AT_CHECK([grep 'cached' stdout], [1])
644 AT_CHECK_CONFIGURE([my_cv_variable='yes it is set'], [], [stdout])
645 AT_CHECK([grep 'cached.*yes it is set' stdout], [], [ignore])
647 # --cache-file is honored and has caching semantics.
648 AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
649 AT_CHECK([grep 'cached' stdout], [1])
650 AT_CHECK([test ! -f config.cache])
651 AT_CHECK([grep 'my_cv_variable.*true' foobar.cache], [], [ignore])
652 AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
653 AT_CHECK([grep 'some other variable.*cached.*true' stdout], [], [ignore])
655 # A setting on the command line overrides the cache.
656 AT_CHECK_CONFIGURE([--cache-file=foobar.cache my_cv_variable='override'], [], [stdout])
657 AT_CHECK([grep 'cached.*override' stdout], [], [ignore])
658 AT_CHECK([grep 'my_cv_variable.*override' foobar.cache], [], [ignore])
660 # Values containing braces need special internal treatment.
661 AT_CHECK_CONFIGURE([-C ac_cv_nothing='{' my_cv_variable='contains } brace'],
663 AT_CHECK([grep 'ac_cv_nothing.*{' config.cache], [], [ignore])
664 AT_CHECK([grep 'my_cv_variable.*contains } brace' config.cache], [], [ignore])
665 AT_CHECK_CONFIGURE([-C], [], [stdout])
666 AT_CHECK([grep 'nothing.*{' stdout], [], [ignore])
667 AT_CHECK([grep 'some other variable.*contains } brace' stdout], [], [ignore])
670 # Diagnose common side-effects that are errors in COMMANDS-TO-SET-IT:
671 sed 's/^# FOO/AC_DEFINE([some-define], [1], [oooh.])/' configure.ac > t
673 AT_CHECK_AUTOCONF([], [], [], [stderr])
674 AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
676 sed 's/^AC_DEFINE.*/AC_SUBST([some_substitution], [oooh.])/' configure.ac > t
678 AT_CHECK_AUTOCONF([], [], [], [stderr])
679 AT_CHECK([grep 'suspicious.*AC_SUBST' stderr], [], [ignore])
681 # Ensure the examples from the manual work as intended.
682 # Taken from autoconf.texi:Caching Results
683 AT_DATA([configure.ac],
685 AC_DEFUN([AC_SHELL_TRUE],
686 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
687 [my_cv_shell_true_works=no
688 (true) 2>/dev/null && my_cv_shell_true_works=yes
689 if test "x$my_cv_shell_true_works" = xyes; then
690 AC_DEFINE([TRUE_WORKS], [1],
691 [Define if 'true(1)' works properly.])
696 AT_CHECK_AUTOCONF([-Werror], [1], [], [stderr])
697 AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
699 # Taken from autoconf.texi:Caching Results
700 AT_DATA([configure.ac],
702 AC_DEFUN([AC_SHELL_TRUE],
703 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
704 [my_cv_shell_true_works=no
705 (true) 2>/dev/null && my_cv_shell_true_works=yes])
706 if test "x$my_cv_shell_true_works" = xyes; then
707 AC_DEFINE([TRUE_WORKS], [1],
708 [Define if 'true(1)' works properly.])
714 AT_CHECK_AUTOCONF([-Werror])
715 AT_CHECK_CONFIGURE([-C], [], [stdout])
716 AT_CHECK([grep my_cv_shell_true_works config.cache], [], [ignore])
717 AT_CHECK([grep 'true.*works.*yes' stdout], [], [ignore])
719 AT_CHECK_CONFIGURE([--config-cache], [], [stdout])
720 AT_CHECK([grep 'true.*works.*cached.*yes' stdout], [], [ignore])
722 # config.status only pays attention to the cache file with --recheck.
723 AT_CHECK([./config.status], [], [stdout])
724 AT_CHECK([grep cache stdout], [1])
725 AT_CHECK([./config.status --recheck], [], [stdout])
726 AT_CHECK([grep cache stdout], [0], [ignore])
728 # By default, configure uses no cache file, neither loading nor updating it.
730 AT_CHECK_CONFIGURE([], [], [stdout])
731 AT_CHECK([grep cache stdout], [1])
732 AT_CHECK([LC_ALL=C ls -t config.cache a-stamp-file | sed 1q | grep config.cache], [1])
734 # Using a symlinked cache file works.
737 AS_LN_S([cache], [config.cache])
738 AT_CHECK_CONFIGURE([-C])
739 # Either the system does not support symlinks, or the symlinked-to file
741 AT_CHECK([test -s cache || test ! -h config.cache])
743 # config.site can specify a site-wide cache, accumulating information.
744 # Also test that we don't run afoul of sourcing a file with leading -.
745 AT_DATA([-config.site],
746 [[cache_file=sitecache
749 [[my_cv_some_preset_cache_var=yes
751 CONFIG_SITE=-config.site
754 AT_CHECK([grep my_cv_some_preset_cache_var sitecache], [], [ignore])
755 AT_CHECK([grep my_cv_shell_true_works sitecache], [], [ignore])
756 AT_CHECK_CONFIGURE([], [], [stdout])
757 AT_CHECK([grep 'whether true.*works.*cached' stdout], [], [ignore])
759 dnl Until we can find a way to avoid catastrophic failure,
760 dnl skip the rest of this test on such shells.
762 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
763 0|"") exit 77;; esac'], [0], [ignore], [ignore])
765 # Check that config cache scripts must be well-formed.
769 CONFIG_SITE=$PWD/bad.site
770 AT_CHECK_CONFIGURE([ || exit 1], [1], [stdout], [stderr])
771 AT_CHECK([grep 'failed to load site script' stderr], [], [ignore], [ignore],
772 [AT_CHECK([grep 'whether true' stdout], [1])])
774 # However, a missing file is ignored.
775 CONFIG_SITE=./no-such-file
778 # Check that multiple files are loaded
779 AT_DATA([first.site],
780 [[my_cv_shell_true_works=no
782 AT_DATA([second.site],
783 [[my_cv_shell_true_works=maybe
785 CONFIG_SITE="$PWD/first.site $PWD/second.site"
786 AT_CHECK_CONFIGURE([], [], [stdout])
787 AT_CHECK([grep 'whether true.*works.*cached.*maybe' stdout], [], [ignore])
792 ## --------------- ##
794 ## --------------- ##
796 # Test AC_CACHE_LOAD.
798 AT_SETUP([AC_CACHE_LOAD])
800 AT_DATA([configure.ac],
804 AC_MSG_NOTICE([some_cv_variable is $some_cv_variable])
808 AS_UNSET([some_test_code])
810 [[some_cv_variable=value-from-new-cache
812 AT_CHECK_CONFIGURE([some_test_code='eval cache_file=new-cache'], [], [stdout])
813 AT_CHECK([grep 'some_cv_variable.*value-from-new-cache' stdout], [], [ignore])
818 ## ---------------- ##
819 ## AC_COMPUTE_INT. ##
820 ## ---------------- ##
822 # Make sure AC_COMPUTE_INT fails properly.
824 AT_SETUP([AC_COMPUTE_INT])
826 AT_DATA([configure.ac],
828 AC_COMPUTE_INT([invalid_expression],
831 [invalid_expression=failed])
832 test "$invalid_expression" = failed ||
833 AC_MSG_ERROR([**0** evaluated to $invalid_expression instead of failing])
843 ## ---------------- ##
844 ## AC_TRY_COMMAND. ##
845 ## ---------------- ##
847 AT_SETUP([AC_TRY_COMMAND])
849 AT_DATA([configure.ac],
852 if AC_TRY_COMMAND([(echo "The Cat in the Hat";
853 echo "The Hat in the Cat" >&2) |
854 grep \^The\ Cat\ in\ the\ Hat\$ >/dev/null]); then
857 AC_MSG_ERROR([didn't see the Cat in the Hat])
860 if AC_TRY_COMMAND([(echo "The Cat in the Hat";
861 echo "The Hat in the Cat" >&2) |
862 grep \^The\ Hat\ in\ the\ Cat\$ >/dev/null]); then
863 AC_MSG_ERROR([saw the Hat in the Cat])
870 AT_CHECK_CONFIGURE([-q])
879 AT_SETUP([Input/Output])
881 AT_DATA([configure.ac],
883 cat <&AS@&t@_ORIGINAL_STDIN_FD >&AS@&t@_MESSAGE_FD
887 AT_CHECK([echo Hello |
888 ./configure $configure_options |
889 grep -v '^configure: '],,
892 AT_CHECK([echo Hello | ./configure $configure_options --silent])
897 ## ------------------- ##
898 ## configure arguments ##
899 ## ------------------- ##
901 AT_SETUP([configure arguments])
903 AT_DATA([configure.ac],
910 AT_CHECK_CONFIGURE([FOO=bar --enable-baz --without-zork --silent], [0], [stdout], [ignore])
911 AT_CHECK([grep 'FOO=bar --enable-baz --without-zork --silent' stdout], [0], [ignore], [ignore])
913 dnl check that syntax error is detected
914 AT_CHECK_CONFIGURE([=], [1], [], [ignore], [ignore])
915 AT_CHECK_CONFIGURE([1=2], [1], [], [ignore], [ignore])
920 ## ------------------------------ ##
921 ## AC_ARG_ENABLE and AC_ARG_WITH. ##
922 ## ------------------------------ ##
924 AT_SETUP([AC_ARG_ENABLE and AC_ARG_WITH])
926 AT_DATA_M4SH([configure.ac],
928 # Taken from autoconf.texi:Pretty Help Strings.
930 [AS_HELP_STRING([--with-foo],
931 [use foo (default is no)])],
935 [AS_HELP_STRING([--with-c++],
937 [choice_with=$withval])
939 [AS_HELP_STRING([--enable-c++],
941 [choice_enable=$enableval])
942 echo "use_foo: $use_foo"
943 echo "with_c++: $with_c__, $choice_with"
944 echo "enable_c++: $enable_c__, $choice_enable"
949 AT_CHECK_CONFIGURE([--help | grep foo], [0],
950 [[ --with-foo use foo (default is no)
952 AT_CHECK_CONFIGURE([--with-foo=yes --with-c++ --disable-c++],
953 [], [stdout], [ignore])
954 AT_CHECK([grep 'use_foo: yes' stdout], [], [ignore])
955 AT_CHECK([grep 'with_c++: yes, yes' stdout], [], [ignore])
956 AT_CHECK([grep 'enable_c++: no, no' stdout], [], [ignore])
957 AT_CHECK([grep 'unrecognized option' stdout], [1])
958 AT_CHECK_CONFIGURE([--without-foo --with-c++=no --enable-c++=maybe],
959 [], [stdout], [ignore])
960 AT_CHECK([grep 'use_foo: no' stdout], [], [ignore])
961 AT_CHECK([grep 'with_c++: no, no' stdout], [], [ignore])
962 AT_CHECK([grep 'enable_c++: maybe, maybe' stdout], [], [ignore])
963 AT_CHECK([grep 'unrecognized option' stdout], [1])
964 AT_CHECK_CONFIGURE([], [], [stdout], [ignore])
965 AT_CHECK([grep 'use_foo: no' stdout], [], [ignore])
966 AT_CHECK([grep 'with_c++: , $' stdout], [], [ignore])
967 AT_CHECK([grep 'enable_c++: , $' stdout], [], [ignore])
968 AT_CHECK([grep 'unrecognized option' stdout], [1])
973 ## --------------------- ##
974 ## configure directories ##
975 ## --------------------- ##
977 AT_SETUP([configure directories])
981 exec_prefix=@exec_prefix@
985 AT_DATA([configure.ac],
987 AC_CONFIG_FILES([foo])
992 dnl check that relative paths are rejected
993 AT_CHECK_CONFIGURE([--libdir=.], [1], [ignore], [stderr])
994 AT_CHECK([grep 'expected an absolute directory name for --libdir: \.' stderr],
997 dnl check that extra slashes are stripped, and that defaults are not expanded
998 AT_CHECK_CONFIGURE([--prefix=/usr//])
999 AT_CHECK([cat foo], [0], [[prefix=/usr
1000 exec_prefix=${prefix}
1001 libdir=${exec_prefix}/lib
1010 AT_SETUP([AC_SUBST])
1011 AT_KEYWORDS([AS@&t@_IDENTIFIER_IF])
1013 # Check that a valid variable name is used.
1014 AT_DATA([configure.ac],
1015 [[AC_INIT([test], [1])
1016 AC_SUBST([1], [bar])
1019 AT_CHECK_AUTOCONF([], [1], [], [stderr])
1020 AT_CHECK([grep 'not a valid shell variable' stderr], [], [ignore])
1022 AT_DATA([configure.ac],
1023 [[AC_INIT([test], [1])
1027 AT_CHECK_AUTOCONF([], [1], [], [stderr])
1028 AT_CHECK([grep 'not a valid shell variable' stderr], [], [ignore])
1030 AT_DATA([configure.ac],
1031 [[AC_INIT([test], [1])
1032 AC_SUBST([*], [bar])
1035 AT_CHECK_AUTOCONF([], [1], [], [stderr])
1036 AT_CHECK([grep 'not a valid shell variable' stderr], [], [ignore])
1038 # Make sure AC_SUBST handles variables as expected.
1044 AT_DATA([configure.ac],
1045 [[AC_INIT([test], [0])
1046 m4_define([FOO], [baz])
1047 AC_SUBST([FOO], [bar])
1051 AC_CONFIG_FILES([file])
1055 AT_CHECK_AUTOCONF([], [], [], [stderr])
1057 AT_CHECK([cat file], [],
1065 ## ----------------------------------- ##
1066 ## configure with closed standard fds ##
1067 ## ----------------------------------- ##
1069 AT_SETUP([configure with closed standard fds])
1070 AT_KEYWORDS([AS@&t@_INIT])
1072 # Create a configure script that runs a relatively complicated but
1073 # self-contained test. Run it.
1074 AT_CONFIGURE_AC([[AC_PROG_CC]])
1077 AT_CHECK_CONFIGURE([], [], [stdout], [stderr])
1080 mv stdout stdout-expected
1081 mv stderr stderr-expected
1082 mv state-env.after state-env-expected
1083 mv config.status config-status-expected
1084 mv config.h config-h-expected
1086 # Run it again with stdin (fd 0) closed.
1087 # There should be no change to the stdout or stderr output and the
1088 # result of configuration should be the same.
1090 AT_CHECK_CONFIGURE([ 0<&- ], [], [stdout], [stderr])
1092 AT_CMP([stdout-expected], [stdout])
1093 AT_CMP([stderr-expected], [stderr])
1094 AT_CONFIG_CMP([state-env-expected], [state-env.after])
1096 mv stdout stdout-closed-0
1097 mv stderr stderr-closed-0
1098 mv state-env.after state-env-closed-0
1099 mv config.status config-status-closed-0
1100 mv config.h config-h-closed-0
1102 # Run it again with stdout (fd 1) closed.
1103 # There should be no change to the stderr output and the
1104 # result of configuration should be the same. (Any output
1105 # that would have gone to stdout, of course, is lost.)
1107 AT_CHECK_CONFIGURE([ 1>&- ], [], [stdout], [stderr])
1109 AT_CHECK([test -f stdout && test ! -s stdout])
1110 AT_CMP([stderr-expected], [stderr])
1111 AT_CONFIG_CMP([state-env-expected], [state-env.after])
1113 mv stdout stdout-closed-1
1114 mv stderr stderr-closed-1
1115 mv state-env.after state-env-closed-1
1116 mv config.status config-status-closed-1
1117 mv config.h config-h-closed-1
1119 # Run it again with stderr (fd 2) closed.
1120 # There should be no change to the stdout output and the
1121 # result of configuration should be the same. (Any output
1122 # that would have gone to stderr, of course, is lost.)
1124 AT_CHECK_CONFIGURE([ 2>&- ], [], [stdout], [stderr])
1126 AT_CMP([stdout-expected], [stdout])
1127 AT_CHECK([test -f stderr && test ! -s stderr])
1128 AT_CONFIG_CMP([state-env-expected], [state-env.after])
1130 mv stdout stdout-closed-2
1131 mv stderr stderr-closed-2
1132 mv state-env.after state-env-closed-2
1133 mv config.status config-status-closed-2
1134 mv config.h config-h-closed-2