summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/CheckListOfTests.am68
-rw-r--r--t/README303
-rw-r--r--t/ac-output-old.tap177
-rw-r--r--t/aclocal-I-and-install.sh100
-rw-r--r--t/aclocal-I-order-1.sh49
-rw-r--r--t/aclocal-I-order-2.sh46
-rw-r--r--t/aclocal-I-order-3.sh46
-rw-r--r--t/aclocal-acdir.sh78
-rw-r--r--t/aclocal-amflags.sh68
-rw-r--r--t/aclocal-autoconf-version-check.sh50
-rw-r--r--t/aclocal-comments-respected.sh31
-rw-r--r--t/aclocal-deleted-header-aclocal-amflags.sh60
-rw-r--r--t/aclocal-deleted-header.sh57
-rw-r--r--t/aclocal-deps-subdir.sh69
-rw-r--r--t/aclocal-deps.sh75
-rw-r--r--t/aclocal-dirlist-abspath.sh42
-rw-r--r--t/aclocal-dirlist-globbing.sh55
-rw-r--r--t/aclocal-dirlist.sh56
-rw-r--r--t/aclocal-install-absdir.sh33
-rw-r--r--t/aclocal-install-fail.sh63
-rw-r--r--t/aclocal-install-mkdir.sh70
-rw-r--r--t/aclocal-m4-include-are-scanned-aclocal-amflags.sh108
-rw-r--r--t/aclocal-m4-include-are-scanned.sh108
-rw-r--r--t/aclocal-m4-sinclude.sh73
-rw-r--r--t/aclocal-macrodir.tap239
-rw-r--r--t/aclocal-macrodirs.tap445
-rw-r--r--t/aclocal-missing-macros.sh41
-rw-r--r--t/aclocal-no-extra-scan.sh37
-rw-r--r--t/aclocal-no-force.sh117
-rw-r--r--t/aclocal-no-install-no-mkdir.sh36
-rw-r--r--t/aclocal-no-symlinked-overwrite.sh41
-rw-r--r--t/aclocal-no-unused-required.sh42
-rw-r--r--t/aclocal-path-install-serial.sh86
-rw-r--r--t/aclocal-path-install.sh53
-rw-r--r--t/aclocal-path-nonexistent.sh34
-rw-r--r--t/aclocal-path-precedence.sh91
-rw-r--r--t/aclocal-path.sh56
-rw-r--r--t/aclocal-pr450.sh49
-rw-r--r--t/aclocal-print-acdir.sh31
-rw-r--r--t/aclocal-remake-misc.sh74
-rw-r--r--t/aclocal-req.sh34
-rw-r--r--t/aclocal-scan-configure-ac-pr319.sh47
-rw-r--r--t/aclocal-serial.sh137
-rw-r--r--t/aclocal-underquoted-defun.sh37
-rw-r--r--t/aclocal-verbose-install.sh52
-rw-r--r--t/aclocal.sh49
-rw-r--r--t/acsilent.sh36
-rw-r--r--t/acsubst.sh31
-rw-r--r--t/acsubst2.sh31
-rw-r--r--t/add-missing-install-sh.sh41
-rw-r--r--t/add-missing-multiple.sh47
-rw-r--r--t/add-missing.tap382
-rw-r--r--t/all.sh33
-rw-r--r--t/all2.sh32
-rw-r--r--t/alloca.sh40
-rw-r--r--t/alloca2.sh40
-rw-r--r--t/alpha.sh71
-rw-r--r--t/alpha2.sh59
-rw-r--r--t/am-config-header.sh50
-rw-r--r--t/am-default-source-ext.sh87
-rw-r--r--t/am-include-only-one-generated-fragment.sh48
-rw-r--r--t/am-macro-not-found.sh25
-rw-r--r--t/am-missing-prog.sh97
-rw-r--r--t/am-prog-cc-c-o.sh126
-rw-r--r--t/am-prog-cc-stdc.sh44
-rw-r--r--t/am-prog-mkdir-p.sh90
-rw-r--r--t/am-tests-environment.sh90
-rw-r--r--t/amassign.sh28
-rw-r--r--t/amhello-binpkg.sh51
-rw-r--r--t/amhello-cflags.sh50
-rw-r--r--t/amhello-cross-compile.sh53
-rw-r--r--t/aminit-moreargs-deprecation.sh51
-rw-r--r--t/aminit-trailing-dnl-comment-pr16841.sh44
-rw-r--r--t/amopt.sh38
-rw-r--r--t/amopts-location.sh83
-rw-r--r--t/amopts-variable-expansion.sh52
-rw-r--r--t/amsubst.sh39
-rw-r--r--t/ansi2knr-no-more.sh56
-rw-r--r--t/ar-lib.sh113
-rw-r--r--t/ar-lib2.sh38
-rw-r--r--t/ar-lib3.sh44
-rw-r--r--t/ar-lib4.sh57
-rw-r--r--t/ar-lib5a.sh71
-rw-r--r--t/ar-lib5b.sh97
-rw-r--r--t/ar-lib6a.sh37
-rw-r--r--t/ar-lib6b.sh37
-rw-r--r--t/ar-lib7.sh34
-rw-r--r--t/ar.sh44
-rw-r--r--t/ar2.sh38
-rw-r--r--t/ar3.sh41
-rw-r--r--t/ar4.sh37
-rw-r--r--t/ar5.sh40
-rw-r--r--t/asm.sh100
-rw-r--r--t/asm2.sh116
-rw-r--r--t/asm3.sh116
-rw-r--r--t/autodist-acconfig-no-subdir.sh56
-rw-r--r--t/autodist-acconfig.sh44
-rw-r--r--t/autodist-aclocal-m4.sh53
-rw-r--r--t/autodist-config-headers.sh59
-rw-r--r--t/autodist-configure-no-subdir.sh70
-rw-r--r--t/autodist-no-duplicate.sh50
-rw-r--r--t/autodist-stamp-vti.sh58
-rw-r--r--t/autodist-subdir.sh120
-rw-r--r--t/autodist.sh103
-rw-r--r--t/autohdr-subdir-pr12495.sh83
-rw-r--r--t/autohdr.sh30
-rw-r--r--t/autohdr3.sh53
-rw-r--r--t/autohdr4.sh80
-rw-r--r--t/autohdrdry.sh42
-rw-r--r--t/automake-cmdline.tap63
-rw-r--r--t/auxdir-autodetect.sh130
-rw-r--r--t/auxdir-cc-pr15981.sh57
-rw-r--r--t/auxdir-computed.tap39
-rw-r--r--t/auxdir-misplaced.sh31
-rw-r--r--t/auxdir-nonexistent.sh34
-rw-r--r--t/auxdir-pr15981.sh39
-rw-r--r--t/auxdir-pr19311.sh45
-rw-r--r--t/auxdir-unportable.tap51
-rw-r--r--t/auxdir.sh42
-rw-r--r--t/auxdir6.sh50
-rw-r--r--t/auxdir7.sh47
-rw-r--r--t/auxdir8.sh46
-rw-r--r--t/ax/am-test-lib.sh1063
-rw-r--r--t/ax/cc-no-c-o.in41
-rw-r--r--t/ax/deltree.pl34
-rw-r--r--t/ax/depcomp.sh417
-rw-r--r--t/ax/distcheck-hook-m4.am30
-rw-r--r--t/ax/extract-testsuite-summary.pl30
-rwxr-xr-xt/ax/is57
-rwxr-xr-xt/ax/is_newest42
-rw-r--r--t/ax/runtest.in130
-rw-r--r--t/ax/shell-no-trail-bslash.in85
-rw-r--r--t/ax/tap-functions.sh231
-rw-r--r--t/ax/tap-setup.sh47
-rw-r--r--t/ax/tap-summary-aux.sh357
-rw-r--r--t/ax/test-defs.in201
-rw-r--r--t/ax/test-init.sh29
-rw-r--r--t/ax/test-lib.sh317
-rw-r--r--t/ax/testsuite-summary-checks.sh102
-rw-r--r--t/ax/trivial-test-driver102
-rw-r--r--t/backcompat-acout.sh66
-rw-r--r--t/backcompat.sh64
-rw-r--r--t/backcompat2.sh73
-rw-r--r--t/backcompat3.sh147
-rw-r--r--t/backcompat6.sh105
-rw-r--r--t/backslash-before-trailing-whitespace.sh45
-rw-r--r--t/backslash-issues.sh47
-rw-r--r--t/badline.sh33
-rw-r--r--t/badopt.sh25
-rw-r--r--t/badprog.sh32
-rw-r--r--t/built-sources-check.sh67
-rw-r--r--t/built-sources-cond.sh91
-rw-r--r--t/built-sources-fork-bomb.sh67
-rw-r--r--t/built-sources-install.sh69
-rw-r--r--t/built-sources-subdir.sh62
-rw-r--r--t/built-sources.sh68
-rw-r--r--t/c-demo.sh178
-rw-r--r--t/candist.sh32
-rw-r--r--t/canon-name.sh38
-rw-r--r--t/canon.sh35
-rw-r--r--t/canon2.sh35
-rw-r--r--t/canon3.sh36
-rw-r--r--t/canon4.sh40
-rw-r--r--t/canon5.sh58
-rw-r--r--t/canon6.sh42
-rw-r--r--t/canon7.sh101
-rw-r--r--t/canon8.sh37
-rwxr-xr-xt/ccnoco-deps.sh82
-rwxr-xr-xt/ccnoco-lib.sh73
-rwxr-xr-xt/ccnoco-lt.sh76
-rw-r--r--t/ccnoco.sh72
-rw-r--r--t/ccnoco3.sh59
-rw-r--r--t/ccnoco4.sh53
-rw-r--r--t/check-concurrency-bug9245.sh57
-rw-r--r--t/check-exported-srcdir.sh64
-rw-r--r--t/check-fd-redirect.sh108
-rw-r--r--t/check-no-test-driver.sh37
-rw-r--r--t/check-subst-prog.sh82
-rw-r--r--t/check-subst.sh88
-rw-r--r--t/check-tests-in-builddir.sh91
-rw-r--r--t/check.sh41
-rw-r--r--t/check10.sh82
-rw-r--r--t/check11.sh59
-rw-r--r--t/check12.sh212
-rw-r--r--t/check2.sh68
-rw-r--r--t/check4.sh80
-rw-r--r--t/check5.sh60
-rw-r--r--t/check6.sh54
-rw-r--r--t/check7.sh67
-rw-r--r--t/check8.sh95
-rw-r--r--t/checkall.sh31
-rw-r--r--t/clean.sh26
-rw-r--r--t/colneq.sh32
-rw-r--r--t/colneq2.sh40
-rw-r--r--t/colneq3.sh44
-rw-r--r--t/colon.sh46
-rw-r--r--t/colon2.sh79
-rw-r--r--t/colon3.sh91
-rw-r--r--t/colon4.sh39
-rw-r--r--t/colon5.sh71
-rw-r--r--t/colon6.sh102
-rw-r--r--t/colon7.sh54
-rw-r--r--t/color-tests-opt.sh39
-rw-r--r--t/color-tests.sh150
-rw-r--r--t/color-tests2.sh201
-rw-r--r--t/commen10.sh32
-rw-r--r--t/commen11.sh41
-rw-r--r--t/comment-block.sh34
-rw-r--r--t/comment.sh27
-rw-r--r--t/comment2.sh34
-rw-r--r--t/comment3.sh31
-rw-r--r--t/comment4.sh41
-rw-r--r--t/comment5.sh85
-rw-r--r--t/comment6.sh68
-rw-r--r--t/comment7.sh57
-rw-r--r--t/comment8.sh48
-rw-r--r--t/comment9.sh53
-rw-r--r--t/comments-in-var-def.sh56
-rw-r--r--t/compile.sh45
-rw-r--r--t/compile2.sh84
-rw-r--r--t/compile3.sh62
-rw-r--r--t/compile4.sh82
-rw-r--r--t/compile5.sh80
-rw-r--r--t/compile6.sh115
-rw-r--r--t/compile7.sh82
-rw-r--r--t/compile_f90_c_cxx.sh43
-rw-r--r--t/compile_f_c_cxx.sh46
-rw-r--r--t/cond-basic.sh42
-rw-r--r--t/cond.sh42
-rw-r--r--t/cond10.sh47
-rw-r--r--t/cond11.sh61
-rw-r--r--t/cond13.sh58
-rw-r--r--t/cond14.sh51
-rw-r--r--t/cond15.sh61
-rw-r--r--t/cond16.sh55
-rw-r--r--t/cond17.sh42
-rw-r--r--t/cond18.sh63
-rw-r--r--t/cond19.sh69
-rw-r--r--t/cond20.sh46
-rw-r--r--t/cond21.sh76
-rw-r--r--t/cond22.sh69
-rw-r--r--t/cond23.sh37
-rw-r--r--t/cond24.sh39
-rw-r--r--t/cond25.sh39
-rw-r--r--t/cond26.sh38
-rw-r--r--t/cond27.sh38
-rw-r--r--t/cond28.sh38
-rw-r--r--t/cond3.sh79
-rw-r--r--t/cond30.sh59
-rw-r--r--t/cond31.sh56
-rw-r--r--t/cond32.sh71
-rw-r--r--t/cond33.sh79
-rw-r--r--t/cond34.sh71
-rw-r--r--t/cond35.sh100
-rw-r--r--t/cond36.sh61
-rw-r--r--t/cond37.sh53
-rw-r--r--t/cond38.sh67
-rw-r--r--t/cond39.sh105
-rw-r--r--t/cond4.sh65
-rw-r--r--t/cond40.sh83
-rw-r--r--t/cond41.sh30
-rw-r--r--t/cond42.sh60
-rw-r--r--t/cond43.sh44
-rw-r--r--t/cond44.sh38
-rw-r--r--t/cond45.sh39
-rw-r--r--t/cond46.sh112
-rw-r--r--t/cond5.sh69
-rw-r--r--t/cond6.sh69
-rw-r--r--t/cond7.sh39
-rw-r--r--t/cond8.sh77
-rw-r--r--t/cond9.sh44
-rw-r--r--t/condd.sh73
-rw-r--r--t/condhook.sh48
-rw-r--r--t/condhook2.sh47
-rw-r--r--t/condinc.sh42
-rw-r--r--t/condinc2.sh59
-rw-r--r--t/condlib.sh44
-rw-r--r--t/condman2.sh33
-rw-r--r--t/condman3.sh74
-rw-r--r--t/confdeps.sh37
-rw-r--r--t/conff.sh88
-rw-r--r--t/conff2.sh36
-rw-r--r--t/conffile-leading-dot.sh60
-rw-r--r--t/confh-subdir-clean.sh40
-rw-r--r--t/confh.sh63
-rw-r--r--t/confh4.sh47
-rw-r--r--t/confh5.sh58
-rw-r--r--t/confh6.sh45
-rw-r--r--t/confh7.sh44
-rw-r--r--t/confh8.sh66
-rw-r--r--t/configure.sh59
-rw-r--r--t/confincl.sh36
-rw-r--r--t/conflnk.sh70
-rw-r--r--t/conflnk2.sh57
-rw-r--r--t/conflnk3.sh86
-rw-r--r--t/conflnk4.sh93
-rw-r--r--t/confsub.sh57
-rw-r--r--t/confvar.sh32
-rw-r--r--t/confvar2.sh34
-rw-r--r--t/copy.sh101
-rw-r--r--t/cscope.tap170
-rw-r--r--t/cscope2.sh34
-rw-r--r--t/cscope3.sh39
-rw-r--r--t/cxx-demo.sh182
-rw-r--r--t/cxx-lt-demo.sh134
-rw-r--r--t/cxx.sh34
-rw-r--r--t/cxx2.sh30
-rw-r--r--t/cxxcpp.sh32
-rw-r--r--t/cxxlibobj.sh40
-rw-r--r--t/cxxlink.sh39
-rw-r--r--t/cxxnoc.sh37
-rw-r--r--t/cygnus-no-more.sh46
-rw-r--r--t/cygwin32.sh38
-rw-r--r--t/dash.sh29
-rw-r--r--t/defun.sh35
-rw-r--r--t/defun2.sh40
-rw-r--r--t/dejagnu-absolute-builddir.sh60
-rw-r--r--t/dejagnu-relative-srcdir.sh84
-rw-r--r--t/dejagnu-siteexp-append.sh70
-rw-r--r--t/dejagnu-siteexp-extend.sh159
-rw-r--r--t/dejagnu-siteexp-useredit.sh67
-rw-r--r--t/dejagnu.sh35
-rw-r--r--t/dejagnu2.sh46
-rw-r--r--t/dejagnu3.sh69
-rw-r--r--t/dejagnu4.sh102
-rw-r--r--t/dejagnu5.sh63
-rw-r--r--t/dejagnu6.sh58
-rw-r--r--t/dejagnu7.sh62
-rw-r--r--t/deleted-am.sh57
-rw-r--r--t/deleted-m4.sh63
-rw-r--r--t/depacl2.sh27
-rw-r--r--t/depcomp-implicit-auxdir.sh70
-rw-r--r--t/depcomp.sh48
-rw-r--r--t/depcomp2.sh53
-rw-r--r--t/depcomp8a.sh83
-rw-r--r--t/depcomp8b.sh78
-rw-r--r--t/depdist.sh74
-rw-r--r--t/depend-postproc.sh71
-rw-r--r--t/depend.sh36
-rw-r--r--t/depend3.sh46
-rw-r--r--t/depend4.sh36
-rw-r--r--t/depend5.sh77
-rw-r--r--t/depend6.sh46
-rw-r--r--t/deprecated-acinit.sh52
-rw-r--r--t/destdir.sh50
-rw-r--r--t/dir-named-obj-is-bad.sh61
-rw-r--r--t/discover.sh43
-rw-r--r--t/dist-auxdir-many-subdirs.sh137
-rw-r--r--t/dist-auxfile-2.sh60
-rw-r--r--t/dist-auxfile.sh95
-rw-r--r--t/dist-formats.tap469
-rw-r--r--t/dist-included-parent-dir.sh51
-rw-r--r--t/dist-install-sh.sh40
-rw-r--r--t/dist-lzma.sh41
-rw-r--r--t/dist-missing-am.sh65
-rw-r--r--t/dist-missing-included-m4.sh67
-rw-r--r--t/dist-missing-m4.sh69
-rw-r--r--t/dist-pr109765.sh42
-rw-r--r--t/dist-readonly.sh62
-rw-r--r--t/dist-repeated.sh102
-rw-r--r--t/dist-shar.sh47
-rw-r--r--t/dist-tarZ.sh59
-rw-r--r--t/dist-with-unreadable-makefile-fails.sh52
-rw-r--r--t/distcheck-configure-flags-am.sh67
-rw-r--r--t/distcheck-configure-flags-subpkg.sh80
-rw-r--r--t/distcheck-configure-flags.sh53
-rw-r--r--t/distcheck-hook.sh51
-rw-r--r--t/distcheck-hook2.sh79
-rw-r--r--t/distcheck-missing-m4.sh116
-rw-r--r--t/distcheck-no-prefix-or-srcdir-override.sh60
-rw-r--r--t/distcheck-outdated-m4.sh134
-rw-r--r--t/distcheck-override-infodir.sh78
-rw-r--r--t/distcheck-pr10470.sh57
-rw-r--r--t/distcheck-pr18286.sh70
-rw-r--r--t/distcheck-pr9579.sh92
-rw-r--r--t/distcheck-writable-srcdir.sh48
-rw-r--r--t/distcleancheck.sh69
-rw-r--r--t/distcom-subdir.sh76
-rw-r--r--t/distcom2.sh79
-rw-r--r--t/distcom3.sh55
-rw-r--r--t/distcom4.sh62
-rw-r--r--t/distcom5.sh72
-rw-r--r--t/distdir.sh81
-rw-r--r--t/disthook.sh86
-rw-r--r--t/distlinks.sh72
-rw-r--r--t/distlinksbrk.sh67
-rw-r--r--t/distname.sh47
-rw-r--r--t/dmalloc.sh59
-rw-r--r--t/doc-parsing-buglets-colneq-subst.sh37
-rw-r--r--t/doc-parsing-buglets-tabs.sh59
-rw-r--r--t/dollar.sh46
-rw-r--r--t/dollarvar.sh56
-rw-r--r--t/dollarvar2.sh86
-rw-r--r--t/double.sh29
-rw-r--r--t/dup2.sh29
-rw-r--r--t/else.sh38
-rw-r--r--t/empty-data-primary.sh31
-rw-r--r--t/empty-sources-primary.tap49
-rw-r--r--t/exdir.sh30
-rw-r--r--t/exdir2.sh29
-rw-r--r--t/exdir3.sh35
-rw-r--r--t/exeext.sh83
-rw-r--r--t/exeext2.sh43
-rw-r--r--t/exeext3.sh43
-rw-r--r--t/exeext4.sh70
-rw-r--r--t/ext.sh43
-rw-r--r--t/ext2.sh67
-rw-r--r--t/ext3.sh39
-rw-r--r--t/extra-data.sh33
-rw-r--r--t/extra-deps-lt.sh86
-rw-r--r--t/extra-deps.sh104
-rw-r--r--t/extra-dist-dirs-and-subdirs.sh57
-rw-r--r--t/extra-dist-vpath-dir-merge.sh66
-rw-r--r--t/extra-dist-vpath-dir.sh40
-rw-r--r--t/extra-dist-wildcards-gnu.sh93
-rw-r--r--t/extra-dist-wildcards-vpath.sh53
-rw-r--r--t/extra-dist-wildcards.sh50
-rw-r--r--t/extra-portability.sh95
-rw-r--r--t/extra-portability2.sh50
-rw-r--r--t/extra-portability3.sh60
-rw-r--r--t/extra-programs-and-libs.sh43
-rw-r--r--t/extra-programs-empty.sh53
-rw-r--r--t/extra-programs-misc.sh36
-rw-r--r--t/extra-sources-no-spurious.sh34
-rw-r--r--t/extra-sources.sh37
-rw-r--r--t/extra.sh41
-rw-r--r--t/f90only.sh34
-rw-r--r--t/flavor.sh60
-rw-r--r--t/flibs.sh54
-rw-r--r--t/fn99.sh50
-rw-r--r--t/fn99subdir.sh80
-rw-r--r--t/fnoc.sh39
-rw-r--r--t/fonly.sh34
-rw-r--r--t/forcemiss.sh34
-rw-r--r--t/forcemiss2.sh40
-rw-r--r--t/fort1.sh30
-rw-r--r--t/fort2.sh92
-rw-r--r--t/fort4.sh94
-rw-r--r--t/fort5.sh109
-rw-r--r--t/fortdep.sh39
-rw-r--r--t/gcj.sh36
-rw-r--r--t/gcj2.sh33
-rw-r--r--t/gcj3.sh36
-rw-r--r--t/gcj4.sh49
-rw-r--r--t/gcj5.sh32
-rw-r--r--t/gcj6.sh51
-rw-r--r--t/get-sysconf.sh70
-rw-r--r--t/gettext-basics.sh58
-rw-r--r--t/gettext-config-rpath.sh45
-rw-r--r--t/gettext-external-pr338.sh65
-rw-r--r--t/gettext-intl-subdir.sh49
-rw-r--r--t/gettext-macros.sh96
-rw-r--r--t/gettext-pr381.sh45
-rw-r--r--t/gnits.sh42
-rw-r--r--t/gnits2.sh115
-rw-r--r--t/gnits3.sh105
-rw-r--r--t/gnumake.sh43
-rw-r--r--t/gnuwarn.sh54
-rw-r--r--t/gnuwarn2.sh42
-rw-r--r--t/hdr-vars-defined-once.sh46
-rw-r--r--t/header.sh45
-rw-r--r--t/help-depend.sh37
-rw-r--r--t/help-depend2.sh38
-rw-r--r--t/help-dmalloc.sh32
-rw-r--r--t/help-init.sh37
-rw-r--r--t/help-lispdir.sh37
-rw-r--r--t/help-python.sh32
-rw-r--r--t/help-silent.sh38
-rw-r--r--t/help-upc.sh33
-rw-r--r--t/help.sh44
-rw-r--r--t/help2.sh52
-rw-r--r--t/help3.sh60
-rw-r--r--t/help4.sh54
-rw-r--r--t/hfs.sh33
-rw-r--r--t/implicit.sh35
-rw-r--r--t/init.sh38
-rw-r--r--t/init2.sh30
-rw-r--r--t/install-info-dir.sh190
-rw-r--r--t/install-sh-option-C.sh45
-rw-r--r--t/install-sh-unittests.sh152
-rw-r--r--t/installdir.sh64
-rw-r--r--t/instdat.sh33
-rw-r--r--t/instdat2.sh88
-rw-r--r--t/instdir-cond.sh48
-rw-r--r--t/instdir-cond2.sh51
-rw-r--r--t/instdir-java.sh51
-rw-r--r--t/instdir-lisp.sh48
-rw-r--r--t/instdir-ltlib.sh73
-rw-r--r--t/instdir-no-empty.sh122
-rw-r--r--t/instdir-prog.sh72
-rw-r--r--t/instdir-python.sh52
-rw-r--r--t/instdir-texi.sh62
-rw-r--r--t/instdir.sh61
-rw-r--r--t/instdir2.sh83
-rw-r--r--t/instexec.sh27
-rw-r--r--t/instfail-info.sh63
-rw-r--r--t/instfail-java.sh57
-rw-r--r--t/instfail-libtool.sh81
-rw-r--r--t/instfail.sh94
-rw-r--r--t/insthook.sh77
-rw-r--r--t/instman.sh36
-rw-r--r--t/instman2.sh33
-rw-r--r--t/instmany-mans.sh168
-rw-r--r--t/instmany-python.sh157
-rw-r--r--t/instmany.sh212
-rw-r--r--t/instspc.tap341
-rw-r--r--t/interp.sh38
-rw-r--r--t/interp2.sh37
-rw-r--r--t/java-check.sh64
-rw-r--r--t/java-clean.sh66
-rw-r--r--t/java-compile-install.sh97
-rw-r--r--t/java-compile-run-flat.sh241
-rw-r--r--t/java-compile-run-nested.sh250
-rw-r--r--t/java-empty-classpath.sh88
-rw-r--r--t/java-extra.sh73
-rw-r--r--t/java-mix.sh68
-rw-r--r--t/java-no-duplicate.sh45
-rw-r--r--t/java-nobase.sh65
-rw-r--r--t/java-noinst.sh55
-rw-r--r--t/java-rebuild.sh124
-rw-r--r--t/java-sources.sh65
-rw-r--r--t/java-uninstall.sh97
-rw-r--r--t/java.sh45
-rw-r--r--t/java2.sh47
-rw-r--r--t/java3.sh56
-rw-r--r--t/javadir-undefined.sh35
-rw-r--r--t/javaflags.sh56
-rw-r--r--t/javaprim.sh36
-rw-r--r--t/javasubst.sh36
-rw-r--r--t/ldadd.sh46
-rw-r--r--t/ldflags.sh50
-rw-r--r--t/lex-clean-cxx.sh126
-rw-r--r--t/lex-clean.sh114
-rw-r--r--t/lex-depend-cxx.sh97
-rw-r--r--t/lex-depend-grep.sh46
-rw-r--r--t/lex-depend.sh93
-rw-r--r--t/lex-header.sh93
-rw-r--r--t/lex-lib-external.sh79
-rw-r--r--t/lex-lib.sh72
-rw-r--r--t/lex-libobj.sh83
-rw-r--r--t/lex-line.sh135
-rw-r--r--t/lex-multiple.sh107
-rw-r--r--t/lex-nodist.sh90
-rw-r--r--t/lex-noyywrap.sh76
-rw-r--r--t/lex-pr204.sh88
-rw-r--r--t/lex-subobj-nodep.sh73
-rw-r--r--t/lex.sh40
-rw-r--r--t/lex2.sh35
-rw-r--r--t/lex3.sh91
-rw-r--r--t/lex5.sh97
-rw-r--r--t/lexcpp.sh44
-rw-r--r--t/lexvpath.sh128
-rw-r--r--t/lflags-cxx.sh70
-rw-r--r--t/lflags.sh71
-rw-r--r--t/libexec.sh35
-rw-r--r--t/libobj-basic.sh112
-rw-r--r--t/libobj-no-dependency-tracking.sh56
-rw-r--r--t/libobj10.sh56
-rw-r--r--t/libobj12.sh77
-rw-r--r--t/libobj13.sh51
-rw-r--r--t/libobj14.sh44
-rw-r--r--t/libobj15a.sh40
-rw-r--r--t/libobj15b.sh43
-rw-r--r--t/libobj15c.sh50
-rw-r--r--t/libobj16a.sh139
-rw-r--r--t/libobj16b.sh140
-rw-r--r--t/libobj17.sh72
-rw-r--r--t/libobj18.sh45
-rw-r--r--t/libobj19.sh94
-rw-r--r--t/libobj2.sh68
-rw-r--r--t/libobj20a.sh45
-rw-r--r--t/libobj20b.sh57
-rw-r--r--t/libobj20c.sh54
-rw-r--r--t/libobj3.sh39
-rw-r--r--t/libobj4.sh34
-rw-r--r--t/libobj5.sh39
-rw-r--r--t/libobj7.sh72
-rw-r--r--t/library.sh36
-rw-r--r--t/library2.sh31
-rw-r--r--t/library3.sh54
-rw-r--r--t/libtoo10.sh62
-rw-r--r--t/libtoo11.sh38
-rw-r--r--t/libtool-macros.sh60
-rw-r--r--t/libtool.sh41
-rw-r--r--t/libtool2.sh49
-rw-r--r--t/libtool3.sh94
-rw-r--r--t/libtool4.sh37
-rw-r--r--t/libtool5.sh44
-rw-r--r--t/libtool6.sh47
-rw-r--r--t/libtool7.sh98
-rw-r--r--t/libtool8.sh53
-rw-r--r--t/libtool9.sh106
-rw-r--r--t/license.sh61
-rw-r--r--t/license2.sh39
-rw-r--r--t/link_c_cxx.sh45
-rw-r--r--t/link_cond.sh88
-rw-r--r--t/link_dist.sh47
-rw-r--r--t/link_f90_only.sh44
-rw-r--r--t/link_f_only.sh44
-rw-r--r--t/link_fc.sh46
-rw-r--r--t/link_fccxx.sh46
-rw-r--r--t/link_fcxx.sh45
-rw-r--r--t/link_override.sh44
-rw-r--r--t/lisp-flags.sh41
-rw-r--r--t/lisp-loadpath.sh67
-rw-r--r--t/lisp-pr11806.sh51
-rw-r--r--t/lisp-subdir-mix.sh96
-rw-r--r--t/lisp-subdir.sh80
-rw-r--r--t/lisp-subdir2.sh78
-rw-r--r--t/lisp2.sh75
-rw-r--r--t/lisp3.sh84
-rw-r--r--t/lisp4.sh81
-rw-r--r--t/lisp5.sh80
-rw-r--r--t/lisp6.sh105
-rw-r--r--t/lisp7.sh47
-rw-r--r--t/lisp8.sh55
-rw-r--r--t/lispdry.sh56
-rw-r--r--t/list-of-tests.mk1323
-rw-r--r--t/listval.sh46
-rw-r--r--t/local.mk268
-rw-r--r--t/location.sh97
-rw-r--r--t/longlin2.sh48
-rw-r--r--t/longline.sh32
-rw-r--r--t/ltcond.sh106
-rw-r--r--t/ltcond2.sh91
-rw-r--r--t/ltconv.sh158
-rw-r--r--t/ltdeps.sh61
-rw-r--r--t/ltinit.sh66
-rw-r--r--t/ltinstloc.sh69
-rw-r--r--t/ltlibobjs.sh43
-rw-r--r--t/ltlibsrc.sh76
-rw-r--r--t/ltorder.sh62
-rw-r--r--t/m4-inclusion.sh56
-rw-r--r--t/maintclean-vpath.sh104
-rw-r--r--t/maintclean.sh96
-rw-r--r--t/maintmode-configure-msg.sh72
-rw-r--r--t/make-dryrun.tap147
-rw-r--r--t/make-is-gnu.sh65
-rw-r--r--t/make-keepgoing.tap137
-rw-r--r--t/make.sh52
-rw-r--r--t/makefile-deps.sh29
-rw-r--r--t/makej.sh53
-rw-r--r--t/makej2.sh44
-rw-r--r--t/maken.sh62
-rw-r--r--t/maken3.sh188
-rw-r--r--t/makevars.sh33
-rw-r--r--t/man.sh33
-rw-r--r--t/man2.sh55
-rw-r--r--t/man3.sh44
-rw-r--r--t/man5.sh69
-rw-r--r--t/man6.sh101
-rw-r--r--t/man7.sh59
-rw-r--r--t/man8.sh61
-rw-r--r--t/mdate.sh37
-rw-r--r--t/mdate2.sh40
-rw-r--r--t/mdate3.sh49
-rw-r--r--t/mdate4.sh46
-rw-r--r--t/mdate5.sh45
-rw-r--r--t/mdate6.sh36
-rw-r--r--t/missing-auxfile-stops-makefiles-creation.sh65
-rw-r--r--t/missing-version-mismatch.sh50
-rw-r--r--t/missing3.sh55
-rw-r--r--t/mkdir_p.sh55
-rw-r--r--t/mkdirp-deprecation.sh48
-rw-r--r--t/mkinst2.sh40
-rw-r--r--t/mkinst3.sh68
-rw-r--r--t/mkinstall.sh31
-rw-r--r--t/mmode.sh64
-rw-r--r--t/mmodely.sh94
-rw-r--r--t/no-extra-c-stuff.sh74
-rw-r--r--t/no-extra-makefile-code.sh41
-rw-r--r--t/no-spurious-install-recursive.sh32
-rw-r--r--t/nobase-libtool.sh94
-rw-r--r--t/nobase-nodist.sh60
-rw-r--r--t/nobase-python.sh84
-rw-r--r--t/nobase.sh147
-rw-r--r--t/nodef.sh58
-rw-r--r--t/nodef2.sh54
-rw-r--r--t/nodep.sh42
-rw-r--r--t/nodep2.sh45
-rw-r--r--t/nodepcomp.sh26
-rw-r--r--t/nodist.sh40
-rw-r--r--t/nodist2.sh38
-rw-r--r--t/nodist3.sh37
-rw-r--r--t/noinst.sh32
-rw-r--r--t/noinstdir.sh70
-rw-r--r--t/nolink.sh36
-rw-r--r--t/nostdinc.sh56
-rw-r--r--t/notrans.sh135
-rw-r--r--t/number.sh36
-rw-r--r--t/objc-basic.sh38
-rw-r--r--t/objc-deps.sh72
-rw-r--r--t/objc-flags.sh62
-rw-r--r--t/objc-megademo.sh340
-rw-r--r--t/objc-minidemo.sh76
-rw-r--r--t/objcxx-basic.sh40
-rw-r--r--t/objcxx-deps.sh72
-rw-r--r--t/objcxx-flags.sh63
-rw-r--r--t/objcxx-minidemo.sh68
-rw-r--r--t/objext-pr10128.sh58
-rw-r--r--t/oldvars.sh37
-rw-r--r--t/order.sh32
-rw-r--r--t/output-order.sh53
-rw-r--r--t/output.sh35
-rw-r--r--t/output10.sh61
-rw-r--r--t/output11.sh63
-rw-r--r--t/output12.sh60
-rw-r--r--t/output13.sh50
-rw-r--r--t/output2.sh38
-rw-r--r--t/output3.sh38
-rw-r--r--t/output4.sh35
-rw-r--r--t/output5.sh31
-rw-r--r--t/output6.sh72
-rw-r--r--t/output7.sh71
-rw-r--r--t/output8.sh54
-rw-r--r--t/output9.sh52
-rw-r--r--t/override-conditional-1.sh53
-rw-r--r--t/override-conditional-2.sh39
-rw-r--r--t/override-conditional-pr13940.sh44
-rw-r--r--t/override-html.sh33
-rw-r--r--t/override-suggest-local.sh44
-rw-r--r--t/parallel-am.sh103
-rw-r--r--t/parallel-am2.sh77
-rw-r--r--t/parallel-am3.sh74
-rw-r--r--t/parallel-tests-basics.sh144
-rw-r--r--t/parallel-tests-cmdline-override.sh82
-rw-r--r--t/parallel-tests-concurrency-2.sh65
-rw-r--r--t/parallel-tests-concurrency.sh120
-rw-r--r--t/parallel-tests-console-output.sh102
-rw-r--r--t/parallel-tests-driver-install.sh53
-rw-r--r--t/parallel-tests-dry-run-1.sh92
-rw-r--r--t/parallel-tests-dry-run-2.sh110
-rw-r--r--t/parallel-tests-empty-testlogs.sh94
-rw-r--r--t/parallel-tests-empty.sh42
-rw-r--r--t/parallel-tests-exeext.sh66
-rw-r--r--t/parallel-tests-exit-status-reported.sh68
-rw-r--r--t/parallel-tests-exit-statuses.sh91
-rw-r--r--t/parallel-tests-extra-programs.sh176
-rw-r--r--t/parallel-tests-fd-redirect-exeext.sh115
-rw-r--r--t/parallel-tests-fd-redirect.sh68
-rw-r--r--t/parallel-tests-fork-bomb.sh146
-rw-r--r--t/parallel-tests-generated-and-distributed.sh74
-rw-r--r--t/parallel-tests-harderror.sh94
-rw-r--r--t/parallel-tests-interrupt.tap116
-rw-r--r--t/parallel-tests-log-compiler-1.sh125
-rw-r--r--t/parallel-tests-log-compiler-2.sh95
-rw-r--r--t/parallel-tests-log-compiler-example.sh68
-rw-r--r--t/parallel-tests-log-override-1.sh109
-rw-r--r--t/parallel-tests-log-override-2.sh82
-rw-r--r--t/parallel-tests-log-override-recheck.sh97
-rw-r--r--t/parallel-tests-no-color-in-log.sh53
-rw-r--r--t/parallel-tests-no-spurious-summary.sh65
-rw-r--r--t/parallel-tests-once.sh47
-rw-r--r--t/parallel-tests-recheck-depends-on-all.sh89
-rw-r--r--t/parallel-tests-recheck-pr11791.sh85
-rw-r--r--t/parallel-tests-recheck.sh82
-rw-r--r--t/parallel-tests-reset-term.sh62
-rw-r--r--t/parallel-tests-subdir.sh50
-rw-r--r--t/parallel-tests-suffix-prog.sh77
-rw-r--r--t/parallel-tests-suffix.sh62
-rw-r--r--t/parallel-tests-trailing-whitespace.sh46
-rw-r--r--t/parallel-tests-unreadable.sh75
-rw-r--r--t/parse.sh36
-rw-r--r--t/per-target-flags.sh92
-rw-r--r--t/percent.sh36
-rw-r--r--t/percent2.sh39
-rwxr-xr-xt/perf/cond.sh56
-rwxr-xr-xt/perf/testsuite-recheck.sh98
-rwxr-xr-xt/perf/testsuite-summary.sh75
-rw-r--r--t/phony.sh32
-rw-r--r--t/pkg-config-macros.sh95
-rw-r--r--t/pluseq.sh30
-rw-r--r--t/pluseq10.sh52
-rw-r--r--t/pluseq11.sh52
-rw-r--r--t/pluseq2.sh46
-rw-r--r--t/pluseq3.sh50
-rw-r--r--t/pluseq4.sh34
-rw-r--r--t/pluseq5.sh60
-rw-r--r--t/pluseq6.sh38
-rw-r--r--t/pluseq7.sh37
-rw-r--r--t/pluseq8.sh43
-rw-r--r--t/pluseq9.sh71
-rw-r--r--t/pm/Cond2.pl22
-rw-r--r--t/pm/Cond3.pl22
-rw-r--r--t/pm/Condition-t.pl327
-rw-r--r--t/pm/Condition.pl277
-rw-r--r--t/pm/DisjCon2.pl24
-rw-r--r--t/pm/DisjCon3.pl23
-rw-r--r--t/pm/DisjConditions-t.pl461
-rw-r--r--t/pm/DisjConditions.pl404
-rw-r--r--t/pm/Version.pl129
-rw-r--r--t/pm/Version2.pl20
-rw-r--r--t/pm/Version3.pl20
-rw-r--r--t/pm/Wrap.pl112
-rw-r--r--t/posixsubst-data.sh74
-rw-r--r--t/posixsubst-extradist.sh54
-rw-r--r--t/posixsubst-ldadd.sh78
-rw-r--r--t/posixsubst-libraries.sh65
-rw-r--r--t/posixsubst-ltlibraries.sh66
-rw-r--r--t/posixsubst-programs.sh63
-rw-r--r--t/posixsubst-scripts.sh99
-rw-r--r--t/posixsubst-sources.sh81
-rw-r--r--t/posixsubst-tests.sh68
-rw-r--r--t/ppf77.sh34
-rw-r--r--t/pr2.sh48
-rw-r--r--t/pr211.sh51
-rw-r--r--t/pr220.sh58
-rw-r--r--t/pr224.sh63
-rw-r--r--t/pr229.sh35
-rw-r--r--t/pr243.sh57
-rw-r--r--t/pr266.sh46
-rw-r--r--t/pr279-2.sh51
-rw-r--r--t/pr279.sh50
-rw-r--r--t/pr287.sh47
-rw-r--r--t/pr300-lib.sh76
-rw-r--r--t/pr300-ltlib.sh82
-rw-r--r--t/pr300-prog.sh72
-rw-r--r--t/pr307.sh93
-rw-r--r--t/pr401.sh187
-rw-r--r--t/pr401b.sh187
-rw-r--r--t/pr401c.sh189
-rw-r--r--t/pr72.sh44
-rw-r--r--t/pr87.sh75
-rw-r--r--t/pr9.sh58
-rw-r--r--t/precious.sh32
-rw-r--r--t/prefix.sh33
-rw-r--r--t/preproc-basics.sh106
-rw-r--r--t/preproc-c-compile.sh118
-rw-r--r--t/preproc-demo.sh230
-rw-r--r--t/preproc-errmsg.sh78
-rw-r--r--t/primary-prefix-couples-documented-valid.sh87
-rw-r--r--t/primary-prefix-couples-force-valid.sh92
-rw-r--r--t/primary-prefix-invalid-couples.tap193
-rw-r--r--t/primary-prefix-valid-couples.sh87
-rw-r--r--t/primary.sh30
-rw-r--r--t/primary2.sh32
-rw-r--r--t/primary3.sh43
-rw-r--r--t/print-libdir.sh46
-rw-r--r--t/proginst.sh29
-rw-r--r--t/programs-primary-rewritten.sh61
-rw-r--r--t/py-compile-basedir.sh54
-rw-r--r--t/py-compile-basic.sh70
-rw-r--r--t/py-compile-destdir.sh47
-rw-r--r--t/py-compile-env.sh59
-rw-r--r--t/py-compile-option-terminate.sh43
-rw-r--r--t/py-compile-usage.sh75
-rw-r--r--t/python-am-path-iftrue.sh55
-rw-r--r--t/python-dist.sh78
-rw-r--r--t/python-missing.sh82
-rw-r--r--t/python-pr10995.sh56
-rw-r--r--t/python-too-old.sh61
-rw-r--r--t/python-vars.sh105
-rw-r--r--t/python-virtualenv.sh201
-rw-r--r--t/python.sh60
-rw-r--r--t/python10.sh87
-rw-r--r--t/python11.sh58
-rw-r--r--t/python12.sh54
-rw-r--r--t/python2.sh106
-rw-r--r--t/python3.sh47
-rw-r--r--t/recurs-user-deeply-nested.sh97
-rw-r--r--t/recurs-user-indir.sh99
-rw-r--r--t/recurs-user-keep-going.sh95
-rw-r--r--t/recurs-user-many.sh73
-rw-r--r--t/recurs-user-no-subdirs.sh52
-rw-r--r--t/recurs-user-no-top-level.sh50
-rw-r--r--t/recurs-user-override.sh68
-rw-r--r--t/recurs-user-phony.sh64
-rw-r--r--t/recurs-user-wrap.sh59
-rw-r--r--t/recurs-user.sh81
-rw-r--r--t/recurs-user2.sh103
-rw-r--r--t/relativize.tap96
-rw-r--r--t/remake-aclocal-version-mismatch.sh45
-rw-r--r--t/remake-after-acinclude-m4.sh112
-rw-r--r--t/remake-after-aclocal-m4.sh112
-rw-r--r--t/remake-after-configure-ac.sh109
-rw-r--r--t/remake-after-makefile-am.sh111
-rw-r--r--t/remake-all-1.sh67
-rw-r--r--t/remake-all-2.sh75
-rw-r--r--t/remake-am-pr10111.sh62
-rw-r--r--t/remake-config-status-dependencies.sh70
-rw-r--r--t/remake-configure-dependencies.sh83
-rw-r--r--t/remake-deeply-nested.sh83
-rw-r--r--t/remake-deleted-am-2.sh75
-rw-r--r--t/remake-deleted-am-subdir.sh77
-rw-r--r--t/remake-deleted-am.sh67
-rw-r--r--t/remake-deleted-m4-file.sh74
-rw-r--r--t/remake-fail.sh69
-rw-r--r--t/remake-gnulib-add-acsubst.sh133
-rw-r--r--t/remake-gnulib-add-header.sh109
-rw-r--r--t/remake-gnulib-remove-header.sh136
-rw-r--r--t/remake-include-aclocal.sh115
-rw-r--r--t/remake-include-configure.sh112
-rw-r--r--t/remake-include-makefile.sh112
-rw-r--r--t/remake-m4-pr10111.sh60
-rw-r--r--t/remake-macrodir.sh83
-rw-r--r--t/remake-maintainer-mode.sh80
-rw-r--r--t/remake-makefile-intree.sh190
-rw-r--r--t/remake-makefile-vpath.sh192
-rw-r--r--t/remake-mild-stress.sh146
-rw-r--r--t/remake-moved-m4-file.sh76
-rw-r--r--t/remake-not-after-make-dist.sh56
-rw-r--r--t/remake-recurs-user.sh89
-rw-r--r--t/remake-renamed-am.sh58
-rw-r--r--t/remake-renamed-m4-file.sh83
-rw-r--r--t/remake-renamed-m4-macro-and-file.sh86
-rw-r--r--t/remake-renamed-m4-macro.sh72
-rw-r--r--t/remake-subdir-from-subdir.sh56
-rw-r--r--t/remake-subdir-gnu.sh80
-rw-r--r--t/remake-subdir-grepping.sh39
-rw-r--r--t/remake-subdir-long-time.sh114
-rw-r--r--t/remake-subdir-no-makefile.sh72
-rw-r--r--t/remake-subdir-only.sh55
-rw-r--r--t/remake-subdir.sh81
-rw-r--r--t/remake-subdir2.sh82
-rw-r--r--t/remake-subdir3.sh62
-rw-r--r--t/remake-timing-bug-pr8365.sh106
-rw-r--r--t/repeated-options.sh81
-rw-r--r--t/reqd2.sh57
-rw-r--r--t/rm-f-probe.sh74
-rw-r--r--t/rulepat.sh30
-rw-r--r--t/sanity.sh43
-rw-r--r--t/seenc.sh43
-rw-r--r--t/self-check-cc-no-c-o.sh35
-rw-r--r--t/self-check-configure-help.sh274
-rw-r--r--t/self-check-dir.tap71
-rw-r--r--t/self-check-exit.tap82
-rw-r--r--t/self-check-explicit-skips.sh54
-rw-r--r--t/self-check-is-blocked-signal.tap29
-rw-r--r--t/self-check-is_newest.tap90
-rw-r--r--t/self-check-me.tap67
-rw-r--r--t/self-check-report.sh54
-rw-r--r--t/self-check-seq.tap75
-rw-r--r--t/self-check-shell-no-trail-bslash.sh81
-rw-r--r--t/self-check-unindent.tap255
-rw-r--r--t/serial-tests.sh84
-rw-r--r--t/silent-c.sh88
-rw-r--r--t/silent-configsite.sh86
-rw-r--r--t/silent-custom.sh110
-rw-r--r--t/silent-cxx.sh107
-rw-r--r--t/silent-f77.sh89
-rw-r--r--t/silent-f90.sh89
-rw-r--r--t/silent-gen.sh82
-rw-r--r--t/silent-lex.sh133
-rw-r--r--t/silent-lt.sh93
-rw-r--r--t/silent-many-languages.sh253
-rw-r--r--t/silent-nested-vars.sh144
-rw-r--r--t/silent-texi.sh82
-rw-r--r--t/silent-yacc-headers.sh164
-rw-r--r--t/silent-yacc.sh130
-rw-r--r--t/sourcefile-in-subdir.sh36
-rw-r--r--t/space.sh29
-rw-r--r--t/specflg-dummy.sh246
-rw-r--r--t/specflg6.sh53
-rw-r--r--t/specflg7.sh64
-rw-r--r--t/specflg8.sh63
-rw-r--r--t/specflg9.sh45
-rw-r--r--t/spell.sh29
-rw-r--r--t/spell2.sh31
-rw-r--r--t/spell3.sh31
-rw-r--r--t/spelling.sh30
-rw-r--r--t/spy-double-colon.sh106
-rw-r--r--t/spy-rm.tap48
-rw-r--r--t/src-acsubst.sh44
-rw-r--r--t/stamph2.sh68
-rw-r--r--t/stdinc.sh62
-rw-r--r--t/stdlib.sh51
-rw-r--r--t/stdlib2.sh94
-rw-r--r--t/strictness-override.sh123
-rw-r--r--t/strictness-precedence.sh77
-rw-r--r--t/strip.sh50
-rw-r--r--t/strip2.sh46
-rw-r--r--t/strip3.sh48
-rw-r--r--t/subdir-ac-subst.sh94
-rw-r--r--t/subdir-add-pr46.sh96
-rw-r--r--t/subdir-add2-pr46.sh97
-rw-r--r--t/subdir-am-cond.sh93
-rw-r--r--t/subdir-cond-err.sh40
-rw-r--r--t/subdir-cond-gettext.sh44
-rw-r--r--t/subdir-distclean.sh103
-rw-r--r--t/subdir-env-interference.sh37
-rw-r--r--t/subdir-keep-going-pr12554.sh70
-rw-r--r--t/subdir-order.sh159
-rw-r--r--t/subdir-subsub.sh59
-rw-r--r--t/subdir-with-slash.sh55
-rw-r--r--t/subdir.sh40
-rw-r--r--t/subobj-clean-lt-pr10697.sh168
-rw-r--r--t/subobj-clean-pr10697.sh163
-rw-r--r--t/subobj-indir-pr13928.sh51
-rw-r--r--t/subobj-objname-clash.sh104
-rw-r--r--t/subobj-pr13928-more-langs.sh138
-rw-r--r--t/subobj-vpath-pr13928.sh127
-rw-r--r--t/subobj.sh91
-rw-r--r--t/subobj10.sh55
-rw-r--r--t/subobj11a.sh80
-rw-r--r--t/subobj11b.sh82
-rw-r--r--t/subobj11c.sh48
-rw-r--r--t/subobj2.sh38
-rw-r--r--t/subobj4.sh50
-rw-r--r--t/subobj5.sh69
-rw-r--r--t/subobj6.sh85
-rw-r--r--t/subobj7.sh38
-rw-r--r--t/subobj8.sh46
-rw-r--r--t/subobj9.sh87
-rw-r--r--t/subobjname.sh72
-rw-r--r--t/subpkg-macrodir.sh85
-rw-r--r--t/subpkg-yacc.sh129
-rw-r--r--t/subpkg.sh111
-rw-r--r--t/subpkg2.sh70
-rw-r--r--t/subpkg3.sh55
-rw-r--r--t/subpkg4.sh71
-rw-r--r--t/subst-no-trailing-empty-line.sh93
-rw-r--r--t/subst.sh39
-rw-r--r--t/subst3.sh178
-rw-r--r--t/subst4.sh44
-rw-r--r--t/subst5.sh40
-rw-r--r--t/substre2.sh50
-rw-r--r--t/substref.sh54
-rw-r--r--t/substtarg.sh51
-rw-r--r--t/suffix-chain.tap64
-rw-r--r--t/suffix-custom-pr14441.sh56
-rw-r--r--t/suffix-custom-subobj-and-specflg.sh62
-rw-r--r--t/suffix-custom-subobj.sh59
-rw-r--r--t/suffix-extra-c-stuff-pr14560.sh37
-rw-r--r--t/suffix.sh59
-rw-r--r--t/suffix10.tap82
-rw-r--r--t/suffix11.tap82
-rw-r--r--t/suffix2.sh54
-rw-r--r--t/suffix3.tap82
-rw-r--r--t/suffix4.sh39
-rw-r--r--t/suffix5.sh66
-rw-r--r--t/suffix6.sh63
-rw-r--r--t/suffix6b.sh75
-rw-r--r--t/suffix6c.sh92
-rw-r--r--t/suffix7.sh37
-rw-r--r--t/suffix8.tap105
-rw-r--r--t/suffix9.sh64
-rw-r--r--t/symlink.sh40
-rw-r--r--t/symlink2.sh32
-rw-r--r--t/syntax.sh31
-rw-r--r--t/tags-pr12372.sh85
-rw-r--r--t/tags.sh29
-rw-r--r--t/tags2.sh42
-rw-r--r--t/tagsub.sh48
-rw-r--r--t/tap-ambiguous-directive.sh53
-rw-r--r--t/tap-autonumber.sh73
-rw-r--r--t/tap-bad-prog.tap85
-rw-r--r--t/tap-bailout-and-logging.sh48
-rw-r--r--t/tap-bailout-leading-space.sh63
-rw-r--r--t/tap-bailout-suppress-badexit.sh63
-rw-r--r--t/tap-bailout-suppress-later-diagnostic.sh40
-rw-r--r--t/tap-bailout-suppress-later-errors.sh70
-rw-r--r--t/tap-bailout.sh134
-rw-r--r--t/tap-basic.sh168
-rw-r--r--t/tap-color.sh163
-rw-r--r--t/tap-common-setup.sh42
-rw-r--r--t/tap-deps.sh84
-rw-r--r--t/tap-diagnostic-custom.sh91
-rw-r--r--t/tap-diagnostic.sh117
-rw-r--r--t/tap-doc.sh96
-rw-r--r--t/tap-doc2.sh138
-rw-r--r--t/tap-driver-stderr.sh49
-rw-r--r--t/tap-empty-diagnostic.sh39
-rw-r--r--t/tap-empty.sh53
-rw-r--r--t/tap-escape-directive-2.sh52
-rw-r--r--t/tap-escape-directive.sh36
-rw-r--r--t/tap-exit.sh51
-rw-r--r--t/tap-fancy.sh127
-rw-r--r--t/tap-fancy2.sh136
-rw-r--r--t/tap-global-log.sh122
-rw-r--r--t/tap-global-result.sh185
-rw-r--r--t/tap-log.sh162
-rw-r--r--t/tap-merge-stdout-stderr.sh63
-rw-r--r--t/tap-missing-plan-and-bad-exit.sh41
-rw-r--r--t/tap-more.sh159
-rw-r--r--t/tap-more2.sh89
-rw-r--r--t/tap-msg0-bailout.sh35
-rw-r--r--t/tap-msg0-directive.sh38
-rw-r--r--t/tap-msg0-misc.sh79
-rw-r--r--t/tap-msg0-planskip.sh34
-rw-r--r--t/tap-msg0-result.sh60
-rw-r--r--t/tap-negative-numbers.sh55
-rw-r--r--t/tap-no-disable-hard-error.sh47
-rw-r--r--t/tap-no-merge-stdout-stderr.sh51
-rw-r--r--t/tap-no-spurious-numbers.sh98
-rw-r--r--t/tap-no-spurious-summary.sh44
-rw-r--r--t/tap-no-spurious.sh111
-rw-r--r--t/tap-not-ok-skip.sh36
-rw-r--r--t/tap-number-wordboundary.sh105
-rw-r--r--t/tap-numbers-leading-zero.sh107
-rw-r--r--t/tap-numeric-description.sh66
-rw-r--r--t/tap-out-of-order.sh77
-rw-r--r--t/tap-passthrough-exit.sh58
-rw-r--r--t/tap-passthrough.sh165
-rw-r--r--t/tap-plan-corner.sh189
-rw-r--r--t/tap-plan-errors.sh112
-rw-r--r--t/tap-plan-leading-zero.sh53
-rw-r--r--t/tap-plan-malformed.sh57
-rw-r--r--t/tap-plan-middle.sh80
-rw-r--r--t/tap-plan-whitespace.sh38
-rw-r--r--t/tap-plan.sh51
-rw-r--r--t/tap-planskip-and-logging.sh70
-rw-r--r--t/tap-planskip-badexit.sh50
-rw-r--r--t/tap-planskip-bailout.sh34
-rw-r--r--t/tap-planskip-case-insensitive.sh42
-rw-r--r--t/tap-planskip-late.sh42
-rw-r--r--t/tap-planskip-later-errors.sh37
-rw-r--r--t/tap-planskip-unplanned-corner.sh45
-rw-r--r--t/tap-planskip-unplanned.sh68
-rw-r--r--t/tap-planskip-whitespace.sh44
-rw-r--r--t/tap-planskip.sh75
-rw-r--r--t/tap-recheck-logs.sh113
-rw-r--r--t/tap-recheck.sh220
-rw-r--r--t/tap-result-comment.sh51
-rw-r--r--t/tap-signal.tap133
-rw-r--r--t/tap-summary-color.sh23
-rw-r--r--t/tap-summary.sh23
-rw-r--r--t/tap-test-number-0.sh58
-rw-r--r--t/tap-todo-skip-together.sh37
-rw-r--r--t/tap-todo-skip-whitespace.sh99
-rw-r--r--t/tap-todo-skip.sh86
-rw-r--r--t/tap-unplanned.sh153
-rw-r--r--t/tap-whitespace-normalization.sh163
-rw-r--r--t/tap-with-and-without-number.sh48
-rw-r--r--t/tap-xfail-tests.sh63
-rw-r--r--t/tar-opts-errors.sh52
-rw-r--r--t/tar-override.sh68
-rw-r--r--t/tar-pax.sh43
-rw-r--r--t/tar-ustar-id-too-high.sh88
-rw-r--r--t/tar-ustar.sh43
-rw-r--r--t/target-cflags.sh75
-rw-r--r--t/targetclash.sh33
-rw-r--r--t/test-driver-acsubst.sh86
-rw-r--r--t/test-driver-cond.sh116
-rw-r--r--t/test-driver-create-log-dir.sh82
-rw-r--r--t/test-driver-custom-multitest-recheck.sh220
-rw-r--r--t/test-driver-custom-multitest-recheck2.sh176
-rw-r--r--t/test-driver-custom-multitest.sh168
-rw-r--r--t/test-driver-custom-no-extra-driver.sh63
-rw-r--r--t/test-driver-custom-xfail-tests.sh163
-rw-r--r--t/test-driver-custom.sh143
-rw-r--r--t/test-driver-fail.sh64
-rw-r--r--t/test-driver-is-distributed.sh83
-rw-r--r--t/test-driver-strip-vpath.sh97
-rw-r--r--t/test-driver-trs-suffix-registered.sh57
-rw-r--r--t/test-extensions-cond.sh69
-rw-r--r--t/test-extensions.sh71
-rw-r--r--t/test-harness-vpath-rewrite.sh57
-rw-r--r--t/test-log.sh176
-rw-r--r--t/test-logs-repeated.sh44
-rw-r--r--t/test-metadata-global-log.sh146
-rw-r--r--t/test-metadata-global-result.sh195
-rw-r--r--t/test-metadata-recheck.sh164
-rw-r--r--t/test-metadata-results.sh177
-rw-r--r--t/test-missing.sh65
-rw-r--r--t/test-missing2.sh52
-rw-r--r--t/test-trs-basic.sh157
-rw-r--r--t/test-trs-recover.sh161
-rw-r--r--t/test-trs-recover2.sh118
-rw-r--r--t/tests-environment-and-log-compiler.sh74
-rw-r--r--t/tests-environment-backcompat.sh59
-rw-r--r--t/tests-environment-fd-redirect.sh92
-rw-r--r--t/tests-environment.sh46
-rw-r--r--t/testsuite-summary-color.sh197
-rw-r--r--t/testsuite-summary-count-many.sh102
-rw-r--r--t/testsuite-summary-count.sh159
-rw-r--r--t/testsuite-summary-reference-log.sh82
-rw-r--r--t/transform.sh68
-rw-r--r--t/transform2.sh99
-rw-r--r--t/transform3.sh92
-rw-r--r--t/txinfo-absolute-srcdir-pr408.sh70
-rw-r--r--t/txinfo-add-missing-and-dist.sh62
-rw-r--r--t/txinfo-bsd-make-recurs.sh40
-rw-r--r--t/txinfo-builddir.sh131
-rw-r--r--t/txinfo-clean.sh126
-rw-r--r--t/txinfo-dvi-recurs.sh39
-rw-r--r--t/txinfo-include.sh164
-rw-r--r--t/txinfo-info-in-srcdir.sh91
-rw-r--r--t/txinfo-makeinfo-error-no-clobber.sh78
-rw-r--r--t/txinfo-many-output-formats-vpath.sh206
-rw-r--r--t/txinfo-many-output-formats.sh206
-rw-r--r--t/txinfo-no-clutter.sh146
-rw-r--r--t/txinfo-no-extra-dist.sh59
-rw-r--r--t/txinfo-no-installinfo.sh48
-rw-r--r--t/txinfo-no-repeated-targets.sh41
-rw-r--r--t/txinfo-no-split.sh101
-rw-r--r--t/txinfo-nodist-info.sh66
-rw-r--r--t/txinfo-other-suffixes.sh41
-rw-r--r--t/txinfo-override-infodeps.sh62
-rw-r--r--t/txinfo-override-texinfo-tex.sh68
-rw-r--r--t/txinfo-setfilename-repeated.sh41
-rw-r--r--t/txinfo-setfilename-suffix-strip.sh33
-rw-r--r--t/txinfo-subdir-pr343.sh60
-rw-r--r--t/txinfo-tex-dist.sh47
-rw-r--r--t/txinfo-unrecognized-extension.sh38
-rw-r--r--t/txinfo-unrecognized-info-suffix.sh32
-rw-r--r--t/txinfo-vtexi.sh62
-rw-r--r--t/txinfo-vtexi2.sh42
-rw-r--r--t/txinfo-vtexi3.sh124
-rw-r--r--t/txinfo-vtexi4.sh106
-rw-r--r--t/txinfo-without-info-suffix.sh57
-rw-r--r--t/txinfo19.sh72
-rw-r--r--t/txinfo23.sh69
-rw-r--r--t/txinfo24.sh83
-rw-r--r--t/txinfo25.sh116
-rw-r--r--t/txinfo28.sh89
-rw-r--r--t/uninstall-fail.sh101
-rw-r--r--t/uninstall-pr9578.sh67
-rw-r--r--t/unused.sh35
-rw-r--r--t/upc.sh50
-rw-r--r--t/upc2.sh31
-rw-r--r--t/upc3.sh65
-rw-r--r--t/vala-configure.sh118
-rw-r--r--t/vala-grepping.sh86
-rw-r--r--t/vala-headers.sh85
-rw-r--r--t/vala-libs.sh100
-rw-r--r--t/vala-mix.sh125
-rw-r--r--t/vala-mix2.sh122
-rw-r--r--t/vala-non-recursive-setup.sh94
-rw-r--r--t/vala-parallel.sh76
-rw-r--r--t/vala-per-target-flags.sh100
-rw-r--r--t/vala-recursive-setup.sh107
-rw-r--r--t/vala-vapi.sh95
-rw-r--r--t/vala-vpath.sh93
-rw-r--r--t/var-recurs.sh34
-rw-r--r--t/var-recurs2.sh31
-rw-r--r--t/vars.sh36
-rw-r--r--t/vars3.sh72
-rw-r--r--t/vartar.sh39
-rw-r--r--t/vartypo2.sh69
-rw-r--r--t/vartypos.sh89
-rw-r--r--t/version3.sh27
-rw-r--r--t/version4.sh26
-rw-r--r--t/version6.sh36
-rw-r--r--t/version7.sh67
-rw-r--r--t/version8.sh24
-rw-r--r--t/vpath.sh33
-rw-r--r--t/warning-groups-win-over-strictness.sh64
-rw-r--r--t/warnings-obsolete-default.sh39
-rw-r--r--t/warnings-override.sh111
-rw-r--r--t/warnings-precedence.sh77
-rw-r--r--t/warnings-strictness-interactions.sh59
-rw-r--r--t/warnings-unknown.sh44
-rw-r--r--t/warnings-win-over-strictness.sh90
-rw-r--r--t/warnopts.sh75
-rw-r--r--t/werror.sh26
-rw-r--r--t/werror2.sh48
-rw-r--r--t/werror3.sh48
-rw-r--r--t/werror4.sh66
-rw-r--r--t/whoami.sh27
-rw-r--r--t/xsource.sh38
-rw-r--r--t/yacc-auxdir.sh56
-rw-r--r--t/yacc-basic.sh108
-rw-r--r--t/yacc-bison-skeleton-cxx.sh102
-rw-r--r--t/yacc-bison-skeleton.sh77
-rw-r--r--t/yacc-clean-cxx.sh161
-rw-r--r--t/yacc-clean.sh147
-rw-r--r--t/yacc-cxx-grepping.sh81
-rw-r--r--t/yacc-cxx.sh140
-rw-r--r--t/yacc-d-basic.sh163
-rw-r--r--t/yacc-d-cxx.sh232
-rw-r--r--t/yacc-d-vpath.sh108
-rw-r--r--t/yacc-deleted-headers.sh163
-rw-r--r--t/yacc-depend.sh82
-rw-r--r--t/yacc-depend2.sh81
-rw-r--r--t/yacc-dist-nobuild-subdir.sh92
-rw-r--r--t/yacc-dist-nobuild.sh89
-rw-r--r--t/yacc-dry.sh58
-rw-r--r--t/yacc-grepping.sh80
-rw-r--r--t/yacc-grepping2.sh81
-rw-r--r--t/yacc-headers-and-dist-pr47.sh89
-rw-r--r--t/yacc-line.sh126
-rw-r--r--t/yacc-misc.sh86
-rw-r--r--t/yacc-mix-c-cxx.sh206
-rw-r--r--t/yacc-nodist.sh101
-rw-r--r--t/yacc-pr204.sh83
-rw-r--r--t/yacc-subdir.sh106
-rw-r--r--t/yacc-vpath.sh97
-rw-r--r--t/yacc-weirdnames.sh54
-rw-r--r--t/yflags-cmdline-override.sh87
-rw-r--r--t/yflags-conditional.sh143
-rw-r--r--t/yflags-cxx.sh68
-rw-r--r--t/yflags-d-false-positives.sh41
-rw-r--r--t/yflags-force-conditional.sh85
-rw-r--r--t/yflags-force-override.sh62
-rw-r--r--t/yflags-var-expand.sh61
-rw-r--r--t/yflags.sh68
1286 files changed, 97642 insertions, 0 deletions
diff --git a/t/CheckListOfTests.am b/t/CheckListOfTests.am
new file mode 100644
index 000000000..b741a2176
--- /dev/null
+++ b/t/CheckListOfTests.am
@@ -0,0 +1,68 @@
+## -*- Automake -*-
+##
+## Copyright (C) 2011-2017 Free Software Foundation, Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see <https://www.gnu.org/licenses/>.
+##
+
+## Temporary files used in the 'check-list-of-tests' recipe.
+am__tmk = tests-in-makefile-list.tmp
+am__tfs = tests-on-filesystem-list.tmp
+am__tdf = diff-in-tests-lists.tmp
+
+## Check that the list of tests given in the Makefile is equal to the
+## list of all test scripts in the Automake testsuite.
+.PHONY: maintainer-check-list-of-tests
+maintainer-check-list-of-tests:
+## Prefer unified diffs over plain diffs, for readability.
+ @if diff -u /dev/null /dev/null >/dev/null 2>&1; then \
+ diff='diff -u'; \
+ else \
+ diff='diff'; \
+ fi; \
+## List of tests in Makefile.
+ lst='$(expected_list_of_tests)'; \
+ test -n "$$lst" || lst='$(TESTS)'; \
+ for t in $$lst; do \
+ echo "$$t"; \
+ done | sort >$(am__tmk); \
+## List of subdirs where to look for tests.
+ dirs='$(test_subdirs)'; \
+ test -n "$$dirs" || dirs=.; \
+## List of tests on filesystem. Be careful to cater for VPATH builds too.
+ test_extensions='$(TEST_EXTENSIONS)'; \
+ for ext in $$test_extensions; do \
+ for dir in $$dirs; do \
+ ls $$dir/*$$ext 2>/dev/null; \
+ if test $(srcdir) != $(builddir); then \
+ ($(am__cd) $(srcdir) && ls $$dir/*$$ext 2>/dev/null); \
+ fi; \
+ done; \
+ done | sed 's,^\./,,' | sort | uniq >$(am__tfs); \
+## Compare the two lists, complain if they differ.
+ if $$diff $(am__tmk) $(am__tfs) >$(am__tdf); then \
+ result=0; \
+ else \
+ echo '$@: list of tests in Makefile an on filesystem differ' >&2; \
+ echo "+ $$diff in-makefile on-filesystem" >&2; \
+ cat $(am__tdf) >&2; \
+ result=1; \
+ fi; \
+ rm -f $(am__tmk) $(am__tfs) $(am__tdf); \
+ exit $$result;
+
+.PHONY: clean-maintcheck-testslist-tmp
+clean-local: clean-maintcheck-testslist-tmp
+clean-maintcheck-testslist-tmp:
+ rm -f $(am__tmk) $(am__tfs) $(am__tdf)
diff --git a/t/README b/t/README
new file mode 100644
index 000000000..23dd943f5
--- /dev/null
+++ b/t/README
@@ -0,0 +1,303 @@
+ The Automake test suite
+
+
+User interface
+==============
+
+
+Running the tests
+-----------------
+
+ To run all tests:
+
+ make -k check
+
+ By default, verbose output of a test 't/foo.sh' or 't/foo.tap' is retained
+ in the log file 't/foo.log'. Also, a summary log is created in the file
+ 'test-suite.log' (in the top-level directory).
+
+ You can use '-jN' for faster completion (it even helps on a uniprocessor
+ system, due to unavoidable sleep delays, as noted below):
+
+ make -k -j4
+
+ To rerun only failed tests:
+
+ make -k recheck
+
+ To run only tests that are newer than their last results:
+
+ make -k check RECHECK_LOGS=
+
+ To run only selected tests:
+
+ make -k check TESTS="t/foo.sh t/bar.tap" (GNU make)
+ env TESTS="t/foo.sh t/bar.tap" make -e -k check (non-GNU make)
+
+ To run the tests in cross-compilation mode, you should first configure
+ the automake source tree to a cross-compilation setup. For example, to
+ run with a Linux-to-MinGW cross compiler, you will need something like
+ this:
+
+ ./configure --host i586-mingw32msvc --build i686-pc-linux-gnu
+
+ To avoid possible spurious error, you really have to *explicitly* specify
+ '--build' in addition to '--host'; the 'lib/config.guess' script can help
+ determine the correct value to pass to '--build'.
+ Then you can just run the testsuite in the usual way, and the test cases
+ using a compiler should automatically use a cross-compilation setup.
+
+
+Interpretation
+--------------
+
+ Successes:
+ PASS - success
+ XFAIL - expected failure
+
+ Failures:
+ FAIL - failure
+ XPASS - unexpected success
+
+ Other:
+ SKIP - skipped tests (third party tools not available)
+ ERROR - some unexpected error condition
+
+
+About the tests
+---------------
+
+ There are two kinds of tests in the Automake testsuite (both implemented
+ as shell scripts). The scripts with the '.sh' suffix are "simple"
+ tests, their outcome completely determined by their exit status. Those
+ with the '.tap' suffix use the TAP protocol.
+
+ If you want to run a test by hand, you should be able to do so using the
+ 'runtest' script provided in the Automake distribution:
+
+ ./runtest t/nogzip.sh
+ ./runtest t/add-missing.tap
+
+ This will run the test using the correct shell, and should also work in
+ VPATH builds. Note that, to run the TAP tests this way, you'll need to
+ have the prove(1) utility available in $PATH.
+
+
+Supported shells
+----------------
+
+ By default, the tests are run by a proper shell detected at configure
+ time. Here is how you can run the tests with a different shell, say
+ '/bin/my-sh':
+
+ # Running through the makefile test driver.
+ make check AM_TEST_RUNNER_SHELL=/bin/my-sh (GNU make)
+ AM_TEST_RUNNER_SHELL=/bin/my-sh make -e check (non-GNU make)
+
+ # Run a test directly from the command line.
+ AM_TEST_RUNNER_SHELL=/bin/my-sh ./runtest t/foo.sh
+
+ The test scripts are written with portability in mind, and should run
+ with any decent POSIX shell. However, it is worth nothing that older
+ versions of Zsh (pre-4.3) exhibited several bugs and incompatibilities
+ with our uses, and are thus not supported for running Automake's test
+ scripts.
+
+
+Reporting failures
+------------------
+
+ Send verbose output, i.e., the contents of test-suite.log, of failing
+ tests to <bug-automake@gnu.org>, along with the usual version numbers
+ (which Automake, which Autoconf, which operating system, which make
+ version, which shell, etc.)
+
+
+
+Writing test cases
+==================
+
+* If you plan to fix a bug, write the test case first. This way you'll
+ make sure the test catches the bug, and that it succeeds once you have
+ fixed the bug.
+
+* Add a copyright/license paragraph.
+
+* Explain what the test does, i.e., which features it checks, which
+ invariants it verifies, or what bugs/issues it guard against.
+
+* Cite the PR number (if any), and the original reporter (if any), so
+ we can find or ask for information if needed.
+
+* If a test checks examples or idioms given in the documentation, make
+ sure the documentation reference them appropriately in comments, as
+ with:
+
+ @c Keep in sync with autodist-config-headers.sh
+ @example
+ ...
+ @end example
+
+* Use "required=..." for required tools. Do not explicitly require
+ tools which can be taken for granted because they're listed in the
+ GNU Coding Standards (for example, 'gzip').
+
+* Include 'test-init.sh' in every test script (see existing tests for
+ examples of how to do this).
+
+* Use the 'skip_' function to skip tests, with a meaningful message if
+ possible. Where convenient, use the 'warn_' function to print generic
+ warnings, the 'fail_' function for test failures, and the 'fatal_'
+ function for hard errors. In case a hard error is due to a failed
+ set-up of a test scenario, you can use the 'framework_fail_' function
+ instead.
+
+* For those tests checking the Automake-provided test harnesses that
+ are expected to work also when the 'serial-tests' Automake option
+ is used (thus causing the serial testsuite harness to be used in the
+ generated Makefile), place a line containing "try-with-serial-tests"
+ somewhere in the file (usually in a comment).
+ That will ensure that the 'gen-testsuite-part' script generates a
+ sibling of that test which uses the serial harness instead of the
+ parallel one. For those tests that are *not* meant to work with the
+ parallel testsuite harness at all (these should be very very few),
+ set the shell variable 'am_serial_tests' to "yes" before including
+ test-init.sh.
+
+* Some tests in the Automake testsuite are auto-generated; those tests
+ might have custom extensions, but their basename (that is, with such
+ extension stripped) is expected to end with "-w" string, optionally
+ followed by decimal digits. For example, the name of a valid
+ auto-generated test can be 'color-w.sh' or 'tap-signal-w09.tap'.
+ Please don't name hand-written tests in a way that could cause them
+ to be confused with auto-generated tests; for example, 'u-v-w.sh'
+ or 'option-w0.tap' are *not* valid name for hand-written tests.
+
+* test-init.sh brings in some commonly required files, and sets a skeleton
+ configure.ac. If possible, append to this file. In some cases you'll
+ have to overwrite it, but this should be the exception. Note that
+ configure.ac registers Makefile.in but do not output anything by
+ default. If you need ./configure to create Makefile, append AC_OUTPUT
+ to configure.ac. In case you don't want your test directory to be
+ pre-populate by test-init.sh (this should be a rare occurrence), set
+ the 'am_create_testdir' shell variable to "empty" before sourcing
+ test-init.sh.
+
+* By default, the testcases are run with the errexit shell flag on,
+ to make it easier to catch failures you might not have thought of.
+ If this is undesirable in some testcase, you can use "set +e" to
+ disable the errexit flag (but please do so only if you have a very
+ good reason).
+
+* End the test script with a ':' command. Otherwise, when somebody
+ changes the test by adding a failing command after the last command,
+ the test will spuriously fail because '$?' is nonzero at the end.
+ Note that this is relevant even if the errexit shell flag is on, in
+ case the test contains commands like "grep ... Makefile.in && exit 1"
+ (and there are indeed a lot of such tests).
+
+* Use $ACLOCAL, $AUTOMAKE, $AUTOCONF, $AUTOUPDATE, $AUTOHEADER,
+ $PERL, $MAKE, $EGREP, and $FGREP, instead of the corresponding
+ commands.
+
+* When you want to redirect the output from a make invocation, use the
+ 'run_make' function rather than calling $MAKE directly. Not only is
+ this more idiomatic, but it also avoid possible spurious racy failures
+ when the make invocations in the testsuite are run in parallel mode
+ (as with "make check AM_TESTSUITE_MAKE='make -j4"').
+
+* Do not override Makefile variables using make arguments, as in e.g.:
+
+ $MAKE prefix=/opt install # BAD
+
+ This is not portable for recursive targets (with non-GNU make,
+ targets that call a sub-make may not pass "prefix=/opt" along).
+ Instead, use the 'run_make' function, which automatically uses
+ the AM_MAKEFLAGS to propagate the variable definitions along to
+ sub-make:
+
+ run_make prefix=/opt install # GOOD
+
+* Use '$sleep' when you have to make sure that some file is newer
+ than another.
+
+* Use cat or grep or similar commands to display (part of) files that
+ may be interesting for debugging, so that when a user send a verbose
+ output we don't have to ask him for more details. Display stderr
+ output on the stderr file descriptor. If some redirected command is
+ likely to fail, display its output even in the failure case, before
+ exiting.
+
+* Use '$PATH_SEPARATOR', not hard-coded ':', as the separator of
+ PATH's entries.
+
+* It's more important to make sure that a feature works, than make
+ sure that Automake's output looks correct. It might look correct
+ and still fail to work. In other words, prefer running 'make' over
+ grepping Makefile.in (or do both).
+
+* If you run $ACLOCAL, $AUTOMAKE or $AUTOCONF several times in the
+ same test and change configure.ac by the meantime, do
+
+ rm -rf autom4te*.cache
+
+ before the following runs. On fast machines the new configure.ac
+ could otherwise have the same timestamp as the old autom4te.cache.
+
+* Use filenames with two consecutive spaces when testing that some
+ code preserves filenames with spaces. This will catch errors like
+ `echo $filename | ...`.
+
+* Make sure your test script can be used to faithfully check an
+ installed version of automake (as with "make installcheck"). For
+ example, if you need to copy or grep an automake-provided script,
+ do not assume that they can be found in the '$top_srcdir/lib'
+ directory, but use '$am_scriptdir' instead. The complete list of
+ such "$am_...dir" variables can be found in the 't/ax/test-defs.in'
+ file.
+
+* When writing input for lex, include the following in the definitions
+ section:
+
+ %{
+ #define YY_NO_UNISTD_H 1
+ %}
+
+ to accommodate non-ANSI systems, since GNU flex generates code that
+ includes unistd.h otherwise. Also add:
+
+ int isatty (int fd) { return 0; }
+
+ to the definitions section if the generated code is to be compiled
+ by a C++ compiler, for similar reasons (i.e., the isatty(3) function
+ from that same unistd.h header would be required otherwise).
+
+* Add any new test to handwritten_TESTS in 't/list-of-tests.mk', and
+ to XFAIL_TESTS in addition if needed (that is, if the test is expected
+ to fail).
+
+* In test scripts, prefer using POSIX constructs over their old
+ Bourne-only equivalents:
+
+ - use $(...), not `...`, for command substitution;
+ - use $((...)), not `expr ...`, for arithmetic processing;
+ - liberally use '!' to invert the exit status of a command, e.g.,
+ in idioms like "if ! CMD; then ...", instead of relying on clumsy
+ paraphrases like "if CMD; then :; else ...".
+ - prefer use of ${param%pattern} and ${param#pattern} parameter
+ expansions over processing by 'sed' or 'expr'.
+
+* Note however that, when writing Makefile recipes or shell code in a
+ configure.ac, you should still use `...` instead, because the Autoconf
+ generated configure scripts do not ensure they will find a truly POSIX
+ shell (even though they will prefer and use it *if* it's found).
+
+* Do not test an Automake error with "$AUTOMAKE && exit 1", or in three
+ years we'll discover that this test failed for some other bogus reason.
+ This happened many times. Better use something like
+
+ AUTOMAKE_fails
+ grep 'expected diagnostic' stderr
+
+ Note this doesn't prevent the test from failing for another reason,
+ but at least it makes sure the original error is still here.
diff --git a/t/ac-output-old.tap b/t/ac-output-old.tap
new file mode 100644
index 000000000..2022681b5
--- /dev/null
+++ b/t/ac-output-old.tap
@@ -0,0 +1,177 @@
+#!/bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for various older bugs related to quoting, escaping and
+# line breaking in the use of AC_OUTPUT. Synthesised by a bunch
+# of older tests (referenced below).
+
+. test-init.sh
+
+plan_ 22
+
+rm -f configure.ac depcomp # Not required.
+
+# -----------------------------------------------------------------------
+
+# Test for bug reported by François Pinard.
+# If \ is in AC_OUTPUT, automake barfs.
+# This was the old test 'acoutbs.test'.
+
+# Also test for bug reported by David A. Swierczek.
+# Another bug with \ in AC_OUTPUT (this time with whitespace).
+# This was the old test 'acoutbs2.test'.
+
+acoutbs_check ()
+{
+ dir=acoutbs$1
+ mkdir $dir
+ cd $dir
+ cat > configure.ac
+ touch Makefile.am zot.in
+ command_ok_ "aclocal groks '\\' in AC_OUTPUT ($dir)" $ACLOCAL
+ command_ok_ "automake groks '\\' in AC_OUTPUT ($dir)" $AUTOMAKE
+ command_ok_ "autoconf groks '\\' in AC_OUTPUT ($dir)" $AUTOCONF
+ command_ok_ "can ./configure in $dir" ./configure
+ command_ok_ "zot created in $dir" test -f zot
+ ls -a > lst || bailout_ "cannot get file listing in $dir"
+ command_ok_ "'\\' not leaked in filenames in $dir" not grep '\\' lst
+ cd ..
+}
+
+acoutbs_check 1 << 'END'
+AC_INIT([acoutbs1], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT(Makefile \
+zot)
+END
+
+acoutbs_check 2 << 'END'
+AC_INIT([acoutbs2], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT(\
+ Makefile \
+ zot
+)
+END
+
+# -----------------------------------------------------------------------
+
+# Test for bug reported by Jerome Santini.
+# If I put this line in my configure.ac:
+# AC_OUTPUT(Makefile src/Makefile tests/Makefile, echo timestamp > stamp-h)dnl
+# automake is not happy:
+# [ ... ]
+# This was the old test 'acoutnoq.test'.
+
+mkdir acoutnoq
+cd acoutnoq
+
+cat > configure.ac << 'END'
+AC_INIT([acoutnoq], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT(Makefile, [true])
+END
+
+: > Makefile.am
+
+command_ok_ "aclocal and quoted AC_OUTPUT second argument" $ACLOCAL
+command_ok_ "automake and quoted AC_OUTPUT second argument" $AUTOMAKE
+
+cd ..
+
+# -----------------------------------------------------------------------
+
+# Test for bug when AC_OUTPUT has 2 args on the same line, eg:
+# AC_OUTPUT([Makefile automake tests/Makefile],[chmod +x automake])
+# This was the old test 'acoutpt.test'.
+
+mkdir acoutpt
+cd acoutpt
+
+cat > configure.ac << 'END'
+AC_INIT([acoutpt], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT([Makefile], [true])
+END
+
+: > Makefile.am
+
+command_ok_ "aclocal and two AC_OUTPUT arguments on same line" $ACLOCAL
+command_ok_ "automake and two AC_OUTPUT arguments on same line" $AUTOMAKE
+
+cd ..
+
+# -----------------------------------------------------------------------
+
+# Test for bug reported by Eric Magnien.
+# This was the old test 'acoutpt2.test'.
+
+mkdir acoutpt2
+cd acoutpt2
+
+# Name of the current "subtest".
+cur=acoutput2
+
+cat > configure.ac <<END
+AC_INIT([$cur], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT([subdir/Makefile subdir/foo Makefile foo], [true])
+END
+
+mkdir subdir
+
+: > Makefile.am
+: > subdir/Makefile.am
+: > foo.in
+: > subdir/foo.in
+
+command_ok_ "aclocal and AC_OUTPUT ($cur)" $ACLOCAL
+command_ok_ "automake and AC_OUTPUT ($cur)" $AUTOMAKE
+command_ok_ "foo.in mentioned two times in Makefile.in ($cur)" \
+ test $($FGREP -c 'foo.in' Makefile.in) -eq 2
+
+# This ought to work as well.
+command_ok_ "'automake -a -f' and AC_OUTPUT ($cur)" \
+ $AUTOMAKE --add-missing --force-missing
+
+cd ..
+
+# -----------------------------------------------------------------------
+
+# Test for bug reported by François Pinard.
+# This was the old test 'acoutqnl.test'.
+
+mkdir acoutqnl
+cd acoutqnl
+
+cat > configure.ac << 'END'
+AC_INIT([acoutqnl], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT([Makefile],
+[echo zardoz has spoken])
+END
+
+: > Makefile.am
+
+command_ok_ "aclocal and two AC_OUTPUT arguments on two lines" $ACLOCAL
+command_ok_ "automake and two AC_OUTPUT arguments on two lines" $AUTOMAKE
+
+cd ..
+
+# -----------------------------------------------------------------------
+
+# And we're done.
+exit 0
diff --git a/t/aclocal-I-and-install.sh b/t/aclocal-I-and-install.sh
new file mode 100644
index 000000000..33f7bb15b
--- /dev/null
+++ b/t/aclocal-I-and-install.sh
@@ -0,0 +1,100 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal define macros in the same order as -I's.
+# This is the similar to aclocal-I-order-1.sh, with the macro calls
+# reversed (it did make a difference).
+#
+# Also check for --install.
+
+# TODO: write a sister test that doesn't use a 'dirlist' file, but
+# TODO: puts third-party macros directly into 'acdir'.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+MACRO2
+MACRO1
+MACRO3
+END
+
+ACLOCAL="$ACLOCAL --system-acdir acdir"
+
+mkdir m4_1 m4_2 acdir acdir2
+echo ./acdir2 > acdir/dirlist
+
+cat >m4_1/somedefs.m4 <<EOF
+AC_DEFUN([MACRO1], [:macro11:])
+AC_DEFUN([MACRO2], [:macro21:])
+EOF
+
+cat >m4_2/somedefs.m4 <<EOF
+AC_DEFUN([MACRO1], [:macro12:])
+EOF
+
+cat >acdir2/macro.m4 <<EOF
+AC_DEFUN([MACRO3], [:macro33:])
+EOF
+
+$ACLOCAL -I m4_1 -I m4_2
+$AUTOCONF
+$FGREP ':macro11:' configure
+$FGREP ':macro21:' configure
+$FGREP ':macro33:' configure
+grep MACRO3 aclocal.m4
+test ! -e m4_1/macro.m4
+test ! -e m4_2/macro.m4
+
+$sleep
+
+$ACLOCAL -I m4_2 -I m4_1
+$AUTOCONF
+$FGREP ':macro12:' configure
+$FGREP ':macro21:' configure
+$FGREP ':macro33:' configure
+grep MACRO3 aclocal.m4
+test ! -e m4_1/macro.m4
+test ! -e m4_2/macro.m4
+
+$sleep
+
+$ACLOCAL -I m4_1 -I m4_2 --install
+$AUTOCONF
+$FGREP ':macro11:' configure
+$FGREP ':macro21:' configure
+$FGREP ':macro33:' configure
+grep MACRO3 aclocal.m4 && exit 1
+test -f m4_1/macro.m4
+test ! -e m4_2/macro.m4
+cp aclocal.m4 copy.m4
+
+$sleep
+
+echo '#GREPME' >>acdir2/macro.m4
+$ACLOCAL -I m4_1 -I m4_2 --install
+$AUTOCONF
+$FGREP ':macro11:' configure
+$FGREP ':macro21:' configure
+$FGREP ':macro33:' configure
+grep MACRO3 aclocal.m4 && exit 1
+grep GREPME m4_1/macro.m4 && exit 1
+test -f m4_1/macro.m4
+test ! -e m4_2/macro.m4
+diff aclocal.m4 copy.m4
+
+:
diff --git a/t/aclocal-I-order-1.sh b/t/aclocal-I-order-1.sh
new file mode 100644
index 000000000..c844079c4
--- /dev/null
+++ b/t/aclocal-I-order-1.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal define macros in the same order as -I's.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+MACRO1
+MACRO2
+END
+
+mkdir m4_1 m4_2
+
+cat >m4_1/somedefs.m4 <<EOF
+AC_DEFUN([MACRO1], [:macro11:])
+AC_DEFUN([MACRO2], [:macro21:])
+EOF
+
+cat >m4_2/somedefs.m4 <<EOF
+AC_DEFUN([MACRO1], [:macro12:])
+EOF
+
+$ACLOCAL -I m4_1 -I m4_2
+$AUTOCONF
+$FGREP ':macro11:' configure
+$FGREP ':macro21:' configure
+
+$ACLOCAL --force -I m4_2 -I m4_1
+$AUTOCONF --force
+$FGREP ':macro12:' configure
+$FGREP ':macro21:' configure
+
+:
diff --git a/t/aclocal-I-order-2.sh b/t/aclocal-I-order-2.sh
new file mode 100644
index 000000000..096b4fdb6
--- /dev/null
+++ b/t/aclocal-I-order-2.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that when two files define the same macro in the same
+# directory, the macro from the lexically greatest file is used.
+# See also sister test 'aclocal-I-order-3.sh'.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+MACRO2
+MACRO1
+END
+
+mkdir m4
+
+cat >m4/version1.m4 <<EOF
+AC_DEFUN([MACRO1], [:macro11:])
+AC_DEFUN([MACRO2], [:macro21:])
+EOF
+
+cat >m4/version2.m4 <<EOF
+AC_DEFUN([MACRO1], [:macro12:])
+EOF
+
+$ACLOCAL -I m4
+$AUTOCONF
+$FGREP ':macro12:' configure
+$FGREP ':macro21:' configure
+
+:
diff --git a/t/aclocal-I-order-3.sh b/t/aclocal-I-order-3.sh
new file mode 100644
index 000000000..c0a5f6d7d
--- /dev/null
+++ b/t/aclocal-I-order-3.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that when two files define the same macro in the same
+# directory, the macro from the lexically greatest file is used.
+# Same as aclocal-I-order-2.sh, but without calling MACRO2.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+MACRO1
+END
+
+mkdir m4
+
+cat >m4/version1.m4 <<EOF
+AC_DEFUN([MACRO1], [:macro11:])
+AC_DEFUN([MACRO2], [:macro21:])
+EOF
+
+cat >m4/version2.m4 <<EOF
+AC_DEFUN([MACRO1], [:macro12:])
+EOF
+
+$ACLOCAL --verbose -I m4
+$AUTOCONF
+$FGREP ':macro11:' configure && exit 1
+$FGREP ':macro21:' configure && exit 1
+$FGREP ':macro12:' configure
+
+:
diff --git a/t/aclocal-acdir.sh b/t/aclocal-acdir.sh
new file mode 100644
index 000000000..07c624430
--- /dev/null
+++ b/t/aclocal-acdir.sh
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test aclocal's '--automake-acdir' and '--system-acdir' options. Also
+# check that stuff in the automake acdir takes precedence over stuff in
+# the system acdir.
+
+. test-init.sh
+
+mkdir am sys
+# FIXME: remove in Automake 2.0
+mkdir am/internal
+: > am/internal/ac-config-macro-dirs.m4
+
+cat >> configure.ac <<'END'
+MY_MACRO
+END
+
+cat > am/foo.m4 <<'END'
+AC_DEFUN([AM_INIT_AUTOMAKE], [fake--init--automake])
+END
+
+cat > sys/foo.m4 <<'END'
+AC_DEFUN([MY_MACRO], [my--macro])
+END
+
+$ACLOCAL --automake-acdir am
+$AUTOCONF --force
+$FGREP 'fake--init--automake' configure
+$FGREP 'MY_MACRO' configure
+
+rm -rf autom4te*.cache
+
+$ACLOCAL --system-acdir sys
+$AUTOCONF --force
+$FGREP 'am__api_version' configure
+$FGREP 'my--macro' configure
+
+rm -rf autom4te*.cache
+
+$ACLOCAL --automake-acdir am --system-acdir sys
+$AUTOCONF --force
+$FGREP 'fake--init--automake' configure
+$FGREP 'my--macro' configure
+
+rm -rf autom4te*.cache
+
+$ACLOCAL --system-acdir sys --automake-acdir am
+$AUTOCONF --force
+$FGREP 'fake--init--automake' configure
+$FGREP 'my--macro' configure
+
+rm -rf autom4te*.cache
+
+# Stuff in automake acdir takes precedence over stuff in system acdir.
+cat > am/bar.m4 <<'END'
+AC_DEFUN([MY_MACRO], [am--macro])
+END
+$ACLOCAL --automake-acdir am --system-acdir sys
+$AUTOCONF --force
+$FGREP 'fake--init--automake' configure
+$FGREP 'am--macro' configure
+$FGREP 'my--macro' configure && exit 1 # Just to be sure.
+
+:
diff --git a/t/aclocal-amflags.sh b/t/aclocal-amflags.sh
new file mode 100644
index 000000000..ca89b21a6
--- /dev/null
+++ b/t/aclocal-amflags.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the obsolescent idiom of setting $(ACLOCAL_AMFLAGS) in
+# Makefile.am still works. Remove this test once support for this
+# obsolescent idiom is removed.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+MACRO_FOO || AS_EXIT([1])
+AC_OUTPUT
+END
+
+mkdir m4_1 m4_2
+cat > m4_1/foo.m4 <<'END'
+AC_DEFUN([MACRO_FOO], [: > foo])
+END
+cat > m4_2/bar.m4 <<'END'
+AC_DEFUN([MACRO_BAR], [: > bar])
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I m4_2 --verbose
+check-local:
+ test ! -r foo
+ test -f bar
+DISTCLEANFILES = bar
+END
+
+$ACLOCAL -I m4_1 >output 2>&1 || { cat output; exit 1; }
+cat output
+grep 'found macro' output && exit 1 # Sanity check.
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f foo
+rm -f foo
+
+# ACLOCAL_AMFLAGS is used in rebuild rules, so trigger them.
+$sleep
+
+sed 's/MACRO_FOO/MACRO_BAR/' configure.ac > t
+mv -f t configure.ac
+
+run_make -M Makefile
+grep "^aclocal.*:.*found macro.*MACRO_BAR.*m4_2/bar\.m4" output
+grep "macro.*MACRO_FOO" output && exit 1
+test ! -r foo
+test -f bar
+
+$MAKE distcheck
+
+:
diff --git a/t/aclocal-autoconf-version-check.sh b/t/aclocal-autoconf-version-check.sh
new file mode 100644
index 000000000..00f68b02b
--- /dev/null
+++ b/t/aclocal-autoconf-version-check.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure autoconf version checks in aclocal.m4 are robust.
+
+am_create_testdirs=empty
+. test-init.sh
+
+cat > configure.ac <<END
+m4_define([AC_AUTOCONF_VERSION], [9999a])
+dnl!! m4_define([a], [oops])
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'You have another version of autoconf' stderr
+grep 'aclocal.m4:.*this file was generated for' stderr
+$AUTOMAKE -a
+./configure
+$MAKE
+
+sed 's/^dnl!! //' < configure.ac > configure.tmp
+cmp configure.ac configure.tmp && fatal_ 'failed to edit configure.ac'
+mv -f configure.tmp configure.ac
+
+run_make -E
+grep 'You have another version of autoconf' stderr
+grep 'aclocal.m4:.*this file was generated for autoconf 9999a' stderr
+
+:
diff --git a/t/aclocal-comments-respected.sh b/t/aclocal-comments-respected.sh
new file mode 100644
index 000000000..364bb82ca
--- /dev/null
+++ b/t/aclocal-comments-respected.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal ignores include() commands in comments.
+# Report from Mike Frysinger.
+# Also make sure aclocal does not think 'include' is
+# an Autoconf macro.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat >>configure.ac <<EOF
+dnl m4_include(__some_really_bogus_nonexistent_file__.m4)
+ # m4_include(__some_really_bogus_nonexistent_file__.m4)
+## m4_include(__some_really_bogus_nonexistent_file__.m4)
+echo 'include(foobar)' is OK
+EOF
+$ACLOCAL
diff --git a/t/aclocal-deleted-header-aclocal-amflags.sh b/t/aclocal-deleted-header-aclocal-amflags.sh
new file mode 100644
index 000000000..098c9558b
--- /dev/null
+++ b/t/aclocal-deleted-header-aclocal-amflags.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the "deleted header file" issue is fixed wrt. aclocal.m4
+# dependencies.
+# NOTE: this test works by using the obsolete 'ACLOCAL_AMFLAGS' make
+# variable; see sister test 'aclocal-deleted-header.sh' for a modern
+# equivalent.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+FOO
+AC_OUTPUT
+EOF
+
+cat >foo.m4 <<EOF
+AC_DEFUN([FOO], [AC_SUBST([GREPFOO])])
+EOF
+
+cat >bar.m4 <<EOF
+AC_DEFUN([BAR], [AC_SUBST([GREPBAR])])
+EOF
+
+cat >Makefile.am <<EOF
+ACLOCAL_AMFLAGS = -I .
+EOF
+
+$ACLOCAL -I .
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+
+$MAKE
+grep GREPFOO Makefile
+grep GREPBAR Makefile && exit 1
+
+sed 's/FOO/BAR/' < configure.ac > t
+mv -f t configure.ac
+rm -f foo.m4
+
+$MAKE
+grep GREPFOO Makefile && exit 1
+grep GREPBAR Makefile
+
+:
diff --git a/t/aclocal-deleted-header.sh b/t/aclocal-deleted-header.sh
new file mode 100644
index 000000000..c33f461b5
--- /dev/null
+++ b/t/aclocal-deleted-header.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the "deleted header file" issue is fixed w.r.t. aclocal.m4
+# dependencies. See also related the tests 'remake-deleted-m4-file.sh'
+# and 'remake-renamed-m4-macro-and-file.sh'.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_CONFIG_MACRO_DIR([.])
+FOO
+AC_OUTPUT
+EOF
+
+cat >foo.m4 <<EOF
+AC_DEFUN([FOO], [AC_SUBST([GREPFOO])])
+EOF
+
+cat >bar.m4 <<EOF
+AC_DEFUN([BAR], [AC_SUBST([GREPBAR])])
+EOF
+
+: >Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+
+$MAKE
+grep GREPFOO Makefile
+grep GREPBAR Makefile && exit 1
+
+sed 's/FOO/BAR/' < configure.ac > t
+mv -f t configure.ac
+rm -f foo.m4
+
+$MAKE
+grep GREPFOO Makefile && exit 1
+grep GREPBAR Makefile
+
+:
diff --git a/t/aclocal-deps-subdir.sh b/t/aclocal-deps-subdir.sh
new file mode 100644
index 000000000..77ec5a460
--- /dev/null
+++ b/t/aclocal-deps-subdir.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that aclocal.m4's dependencies are honored in
+# sub-directories. See also related tests 'remake-subdir*.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_MACRO_DIR([m4])
+FOO_TEST([GREPME])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+END
+
+mkdir sub
+: > sub/Makefile.am
+
+mkdir m4
+echo 'AC_DEFUN([FOO_TEST], [echo $@])' > m4/moredefs.m4
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+./configure
+$MAKE
+
+# Update an aclocal.m4 dependency, then make sure all Makefiles are
+# updated, even from a sub-directory. Check that AU_ALIAS is
+# recognized. Change the definition of FOO_TEST to check that its new
+# definition is used.
+$sleep # Modified configure dependencies must be newer than config.status.
+echo 'AU_ALIAS([FOO_TEST], [AC_SUBST])' > m4/moredefs.m4
+cd sub
+$MAKE
+cd ..
+grep GREPME Makefile
+grep GREPME sub/Makefile
+
+# Make sure configure dependencies are distributed.
+$MAKE distdir
+test -f $me-1.0/m4/moredefs.m4
+
+# Change the definition of FOO_TEST to check that its new definition is
+# used. Check that AC_DEFUN_ONCE is caught.
+$sleep # Modified configure dependencies must be newer than config.status.
+echo 'AC_DEFUN_ONCE([FOO_TEST], [AC_SUBST(__$1__)])' > m4/moredefs.m4
+$MAKE
+grep 'm4/moredefs\.m4' aclocal.m4
+grep '__GREPME__' configure
+
+:
diff --git a/t/aclocal-deps.sh b/t/aclocal-deps.sh
new file mode 100644
index 000000000..18adc213c
--- /dev/null
+++ b/t/aclocal-deps.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure dependencies on aclocal.m4 are set correctly.
+# Report from Jim Meyering.
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_CONFIG_MACRO_DIR([m4])
+AC_PROG_RANLIB
+AM_PROG_AR
+AC_PROG_CC
+MY_MACRO
+AC_CONFIG_FILES([lib/Makefile])
+AC_OUTPUT
+EOF
+
+mkdir m4
+cat >m4/mymacro.m4 <<EOF
+AC_DEFUN([MY_MACRO], [])
+EOF
+
+mkdir lib
+: > lib/foo.c
+: > lib/bar.c
+cat >lib/Makefile.am <<'EOF'
+noinst_LIBRARIES = liberi.a
+liberi_a_SOURCES = bar.c
+liberi_a_LIBADD = $(LIBOBJS)
+EOF
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = lib
+EXTRA_DIST = m4/mymacro.m4
+check-foo: distdir
+ test -f $(distdir)/lib/foo.c
+ test -f $(distdir)/lib/bar.c
+
+check-not-foo: distdir
+ test ! -f $(distdir)/lib/foo.c
+ test -f $(distdir)/lib/bar.c
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE check-not-foo
+
+# Update one of the macros. This should cause ./configure, Makefile.in,
+# Makefile, lib/Makefile.in, and lib/Makefile to be updated.
+
+cat >m4/mymacro.m4 <<'EOF'
+AC_DEFUN([MY_MACRO], [AC_LIBOBJ([foo])])
+EOF
+
+using_gmake || $MAKE
+$MAKE check-foo
+
+:
diff --git a/t/aclocal-dirlist-abspath.sh b/t/aclocal-dirlist-abspath.sh
new file mode 100644
index 000000000..ec65299c5
--- /dev/null
+++ b/t/aclocal-dirlist-abspath.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check use of absolute paths in dirlist.
+
+am_create_testdir=empty
+. test-init.sh
+
+mkdir acdir-more sub sub/acdir
+echo "$(pwd)/acdir-more" > sub/acdir/dirlist
+
+echo 'AC_DEFUN([AM_FOO], [foo-foo--foo])' > acdir-more/foo.m4
+
+cd sub
+
+cat > configure.ac <<EOF
+AC_INIT([$me], [1.0])
+AM_FOO
+EOF
+
+$ACLOCAL --system-acdir acdir
+$AUTOCONF
+
+# Only -I directories are subject to file inclusion.
+grep m4_include aclocal.m4 && exit 1
+
+grep 'foo-foo--foo' configure
+
+:
diff --git a/t/aclocal-dirlist-globbing.sh b/t/aclocal-dirlist-globbing.sh
new file mode 100644
index 000000000..9479ea55f
--- /dev/null
+++ b/t/aclocal-dirlist-globbing.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check dirlist globbing support.
+
+. test-init.sh
+
+cat > configure.ac <<EOF
+AC_INIT([$me], [1.0])
+AM_INIT_GUILE_MODULE
+AM_FOO_BAR
+EOF
+
+mkdir dirlist21-test dirlist22-test
+
+cat >dirlist21-test/dirlist21-check.m4 <<'END'
+AC_DEFUN([AM_INIT_GUILE_MODULE],[. $srcdir/../GUILE-VERSION])
+END
+
+cat >dirlist22-test/dirlist22-check.m4 <<'END'
+AC_DEFUN([AM_FOO_BAR],[
+: foo bar baz
+])
+END
+
+mkdir my-acdir
+cat > my-acdir/dirlist <<'END'
+dirlist2*-test
+END
+
+$ACLOCAL --system-acdir my-acdir
+$AUTOCONF
+
+# There should be no m4_include in aclocal.m4, even though m4/dirlist
+# contains './dirlist-test' as a relative directory. Only -I directories
+# are subject to file inclusion.
+grep m4_include aclocal.m4 && exit 1
+
+grep 'GUILE-VERSION' configure
+grep 'foo bar baz' configure
+
+:
diff --git a/t/aclocal-dirlist.sh b/t/aclocal-dirlist.sh
new file mode 100644
index 000000000..7cea8f9fa
--- /dev/null
+++ b/t/aclocal-dirlist.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check dirlist support.
+
+. test-init.sh
+
+cat > configure.ac <<EOF
+AC_INIT([$me], [1.0])
+AM_INIT_GUILE_MODULE
+EOF
+
+mkdir acdir dirlist-test
+echo ./dirlist-test > acdir/dirlist
+
+cat >dirlist-test/dirlist-check.m4 <<'END'
+AC_DEFUN([AM_INIT_GUILE_MODULE],[
+. $srcdir/../GUILE-VERSION
+AM_INIT_AUTOMAKE(foreign)
+AC_CONFIG_AUX_DIR(..)
+module=[$1]
+AC_SUBST(module)])
+END
+
+cat >dirlist-test/init.m4 <<EOF
+AC_DEFUN([AM_INIT_AUTOMAKE], [I should not be included])
+EOF
+
+$ACLOCAL --system-acdir acdir
+$AUTOCONF
+
+# There should be no m4_include in aclocal.m4, even though m4/dirlist
+# contains './dirlist-test' as a relative directory. Only -I directories
+# are subject to file inclusion.
+grep m4_include aclocal.m4 && exit 1
+
+grep 'GUILE-VERSION' configure
+
+# This bug can occur only when we do a VPATH build of Automake
+# but it's OK because VPATH builds are done by 'make distcheck'.
+grep 'I should not be included' configure && exit 1
+
+:
diff --git a/t/aclocal-install-absdir.sh b/t/aclocal-install-absdir.sh
new file mode 100644
index 000000000..c71935f41
--- /dev/null
+++ b/t/aclocal-install-absdir.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure "aclocal --install" install files also in directories
+# passed to '-I' as absolute paths. Now that we support the
+# ACLOCAL_PATH variable, it is clear that this is the right thing
+# to do. See also automake bug#8407.
+
+. test-init.sh
+
+mkdir loc sys
+
+echo 'AM_DUMMY_MACRO' >> configure.ac
+echo 'AC_DEFUN([AM_DUMMY_MACRO], [:])' >> sys/foo.m4
+
+cwd=$(pwd) || fatal_ "cannot get current working directory"
+env ACLOCAL_PATH="$cwd/sys" $ACLOCAL --verbose --install -I "$cwd/loc"
+diff sys/foo.m4 loc/foo.m4
+
+:
diff --git a/t/aclocal-install-fail.sh b/t/aclocal-install-fail.sh
new file mode 100644
index 000000000..ac6810681
--- /dev/null
+++ b/t/aclocal-install-fail.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that "aclocal --install" fails when it should.
+# FIXME: this is a good candidate for a conversion to TAP.
+
+am_create_testdir=empty
+required=ro-dir
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+MY_MACRO
+END
+
+mkdir sys-acdir
+cat > sys-acdir/my-defs.m4 <<END
+AC_DEFUN([MY_MACRO], [:])
+END
+
+ACLOCAL="$ACLOCAL -Wnone --system-acdir=sys-acdir"
+
+: > a-regular-file
+mkdir unwritable-dir
+chmod a-w unwritable-dir
+
+$ACLOCAL -I a-regular-file --install 2>stderr \
+ && { cat stderr >&2; exit 1; }
+cat stderr >&2
+$EGREP '(mkdir:|directory ).*a-regular-file' stderr
+test ! -e aclocal.m4
+
+$ACLOCAL --install -I unwritable-dir/sub 2>stderr \
+ && { cat stderr >&2; exit 1; }
+cat stderr >&2
+$EGREP '(mkdir:|directory ).*unwritable-dir/sub' stderr
+test ! -e aclocal.m4
+
+$ACLOCAL -I unwritable-dir --install 2>stderr \
+ && { cat stderr >&2; exit 1; }
+cat stderr >&2
+$EGREP '(cp:|copy ).*unwritable-dir' stderr
+test ! -e aclocal.m4
+
+# Sanity check.
+mkdir m4
+$ACLOCAL -I m4 --install && test -f aclocal.m4 \
+ || fatal_ "aclocal failed also when expected to succeed"
+
+:
diff --git a/t/aclocal-install-mkdir.sh b/t/aclocal-install-mkdir.sh
new file mode 100644
index 000000000..24f1da71c
--- /dev/null
+++ b/t/aclocal-install-mkdir.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that "aclocal --install" creates the local m4 directory if
+# necessary.
+# FIXME: this is a good candidate for a conversion to TAP.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+MY_MACRO
+END
+
+mkdir sys-acdir
+cat > sys-acdir/my-defs.m4 <<END
+AC_DEFUN([MY_MACRO], [:])
+END
+
+ACLOCAL="$ACLOCAL --system-acdir=sys-acdir"
+
+$ACLOCAL -I foo --install
+test -f foo/my-defs.m4
+
+$ACLOCAL --install -I "$(pwd)/bar"
+test -f bar/my-defs.m4
+
+$ACLOCAL --install -I baz/sub/sub2
+test -f baz/sub/sub2/my-defs.m4
+
+# What should happen:
+# * zardoz1 should be created, and required m4 files copied into there.
+# * zardoz2 shouldn't be preferred to quux, even if the former exists
+# while the latter does not.
+mkdir zardoz2
+$ACLOCAL --install -I zardoz1 -I zardoz2
+test -d zardoz1
+grep MY_MACRO zardoz1/my-defs.m4
+ls zardoz2 | grep . && exit 1
+
+# Directories in ACLOCAL_PATH should never be created if they don't
+# exist.
+ACLOCAL_PATH="$(pwd)/none:$(pwd)/none2" $ACLOCAL --install && exit 1
+test ! -e none
+test ! -e none2
+ACLOCAL_PATH="$(pwd)/none:$(pwd)/none2" $ACLOCAL --install -I x
+test -f x/my-defs.m4
+test ! -e none
+test ! -e none2
+
+# It's better if aclocal doesn't create the first include dir on failure.
+$ACLOCAL --install -I none -I none2 && exit 1
+test ! -e none
+test ! -e none2
+
+:
diff --git a/t/aclocal-m4-include-are-scanned-aclocal-amflags.sh b/t/aclocal-m4-include-are-scanned-aclocal-amflags.sh
new file mode 100644
index 000000000..333d5d1ce
--- /dev/null
+++ b/t/aclocal-m4-include-are-scanned-aclocal-amflags.sh
@@ -0,0 +1,108 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure m4_included files are also scanned for definitions.
+# Report from Phil Edwards.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+echo 'm4_include([a.m4])' > acinclude.m4
+echo 'm4_include([b.m4])' > a.m4
+
+cat >b.m4 <<EOF
+m4_include([c.m4])
+AC_DEFUN([AM_PROG_LIBTOOL],
+[AC_REQUIRE([SOMETHING])dnl
+AC_REQUIRE([SOMETHING_ELSE])dnl
+])
+
+AC_DEFUN([SOMETHING])
+EOF
+
+echo 'm4_include([d.m4])' > c.m4
+echo 'AC_DEFUN([SOMETHING_ELSE])' >d.m4
+
+mkdir defs
+echo 'AC_DEFUN([SOMETHING_ELSE])' >defs/e.m4
+echo 'AC_DEFUN([ANOTHER_MACRO])' >defs/f.m4
+
+cat >>Makefile.am<<\EOF
+ACLOCAL_AMFLAGS = -I defs
+testdist1: distdir
+ test -f $(distdir)/acinclude.m4
+ test -f $(distdir)/a.m4
+ test -f $(distdir)/b.m4
+ test -f $(distdir)/c.m4
+ test -f $(distdir)/d.m4
+ test ! -d $(distdir)/defs
+testdist2: distdir
+ test -f $(distdir)/acinclude.m4
+ test -f $(distdir)/a.m4
+ test -f $(distdir)/b.m4
+ test -f $(distdir)/c.m4
+ test -f $(distdir)/d.m4
+ test ! -f $(distdir)/defs/e.m4
+ test -f $(distdir)/defs/f.m4
+EOF
+
+$ACLOCAL -I defs
+
+$FGREP acinclude.m4 aclocal.m4
+# None of the following macro should be included. acinclude.m4
+# includes the first four, and the last two are not needed at all.
+$FGREP a.m4 aclocal.m4 && exit 1
+$FGREP b.m4 aclocal.m4 && exit 1
+$FGREP c.m4 aclocal.m4 && exit 1
+$FGREP d.m4 aclocal.m4 && exit 1
+$FGREP defs/e.m4 aclocal.m4 && exit 1
+$FGREP defs/f.m4 aclocal.m4 && exit 1
+
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE testdist1
+
+cp aclocal.m4 aclocal.old
+$sleep
+echo 'AC_DEFUN([FOO], [ANOTHER_MACRO])' >> c.m4
+$MAKE
+# Because c.m4 has changed, aclocal.m4 must have been rebuilt.
+is_newest aclocal.m4 aclocal.old
+# However, since FOO is not used, f.m4 should not be included
+# and the contents of aclocal.m4 should remain the same
+diff aclocal.m4 aclocal.old
+
+# If FOO where to be used, that would be another story, of course:
+# f.m4 should be included
+$sleep
+echo FOO >> configure.ac
+$MAKE
+$FGREP defs/f.m4 aclocal.m4
+$MAKE testdist2
+
+# Make sure aclocal diagnose missing included files with correct 'file:line:'.
+rm -f b.m4
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'a\.m4:1: .*b\.m4.*does not exist' stderr
+
+:
diff --git a/t/aclocal-m4-include-are-scanned.sh b/t/aclocal-m4-include-are-scanned.sh
new file mode 100644
index 000000000..0d340f6b8
--- /dev/null
+++ b/t/aclocal-m4-include-are-scanned.sh
@@ -0,0 +1,108 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure m4_included files are also scanned for definitions.
+# Report from Phil Edwards.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_MACRO_DIR([defs])
+AM_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+echo 'm4_include([a.m4])' > acinclude.m4
+echo 'm4_include([b.m4])' > a.m4
+
+cat >b.m4 <<EOF
+m4_include([c.m4])
+AC_DEFUN([AM_PROG_LIBTOOL],
+[AC_REQUIRE([SOMETHING])dnl
+AC_REQUIRE([SOMETHING_ELSE])dnl
+])
+
+AC_DEFUN([SOMETHING])
+EOF
+
+echo 'm4_include([d.m4])' > c.m4
+echo 'AC_DEFUN([SOMETHING_ELSE])' >d.m4
+
+mkdir defs
+echo 'AC_DEFUN([SOMETHING_ELSE])' >defs/e.m4
+echo 'AC_DEFUN([ANOTHER_MACRO])' >defs/f.m4
+
+cat >>Makefile.am<<\EOF
+testdist1: distdir
+ test -f $(distdir)/acinclude.m4
+ test -f $(distdir)/a.m4
+ test -f $(distdir)/b.m4
+ test -f $(distdir)/c.m4
+ test -f $(distdir)/d.m4
+ test ! -d $(distdir)/defs
+testdist2: distdir
+ test -f $(distdir)/acinclude.m4
+ test -f $(distdir)/a.m4
+ test -f $(distdir)/b.m4
+ test -f $(distdir)/c.m4
+ test -f $(distdir)/d.m4
+ test ! -f $(distdir)/defs/e.m4
+ test -f $(distdir)/defs/f.m4
+EOF
+
+$ACLOCAL -I defs
+
+$FGREP acinclude.m4 aclocal.m4
+# None of the following macro should be included. acinclude.m4
+# includes the first four, and the last two are not needed at all.
+$FGREP a.m4 aclocal.m4 && exit 1
+$FGREP b.m4 aclocal.m4 && exit 1
+$FGREP c.m4 aclocal.m4 && exit 1
+$FGREP d.m4 aclocal.m4 && exit 1
+$FGREP defs/e.m4 aclocal.m4 && exit 1
+$FGREP defs/f.m4 aclocal.m4 && exit 1
+
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE testdist1
+
+cp aclocal.m4 aclocal.old
+$sleep
+echo 'AC_DEFUN([FOO], [ANOTHER_MACRO])' >> c.m4
+$MAKE
+# Because c.m4 has changed, aclocal.m4 must have been rebuilt.
+is_newest aclocal.m4 aclocal.old
+# However, since FOO is not used, f.m4 should not be included
+# and the contents of aclocal.m4 should remain the same
+diff aclocal.m4 aclocal.old
+
+# If FOO where to be used, that would be another story, of course:
+# f.m4 should be included
+$sleep
+echo FOO >> configure.ac
+$MAKE
+$FGREP defs/f.m4 aclocal.m4
+$MAKE testdist2
+
+# Make sure aclocal diagnose missing included files with correct 'file:line:'.
+rm -f b.m4
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'a\.m4:1: .*b\.m4.*does not exist' stderr
+
+:
diff --git a/t/aclocal-m4-sinclude.sh b/t/aclocal-m4-sinclude.sh
new file mode 100644
index 000000000..f4c850e67
--- /dev/null
+++ b/t/aclocal-m4-sinclude.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure changes to m4_included files also cause aclocal.m4 to change.
+
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([m4sinclude], [1.0])
+AM_INIT_AUTOMAKE
+m4_include([somefile.m4])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'EOF'
+check-local:
+ test -f "$(srcdir)/somefile.m4"
+ test -f "$(srcdir)/m4/version1.m4"
+ test -f "$(srcdir)/m4/otherfile.m4"
+EOF
+
+mkdir m4
+
+echo MACRO1 >somefile.m4
+echo 'AC_PREREQ([2.58])' >m4/otherfile.m4
+
+cat >m4/version1.m4 <<EOF
+AC_DEFUN([MACRO1])
+AC_DEFUN([MACRO2])
+m4_sinclude(m4/otherfile.m4)
+EOF
+
+cat >m4/version2.m4 <<EOF
+AC_DEFUN([MACRO1])
+EOF
+
+$ACLOCAL -I m4
+grep version2 aclocal.m4
+grep version1 aclocal.m4 && exit 1
+
+$sleep
+echo MACRO2 >somefile.m4
+
+$ACLOCAL -I m4
+grep version2 aclocal.m4 && exit 1
+grep version1 aclocal.m4
+
+$sleep
+# aclocal.m4 should change if we touch otherfile.m4
+touch m4/otherfile.m4
+$ACLOCAL -I m4
+is_newest aclocal.m4 m4/otherfile.m4
+
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
+
+:
diff --git a/t/aclocal-macrodir.tap b/t/aclocal-macrodir.tap
new file mode 100644
index 000000000..823268423
--- /dev/null
+++ b/t/aclocal-macrodir.tap
@@ -0,0 +1,239 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIR with
+# aclocal. See also related test 'aclocal-macrodir.tap'.
+
+am_create_testdir=empty
+. test-init.sh
+
+plan_ 7
+
+ocwd=$(pwd) || fatal_ "getting current working directory"
+unset ACLOCAL_PATH
+
+#
+# General utility functions and variables.
+#
+# TODO: These should maybe be refactored, generalized and
+# moved into 't/ax/tap-functions.sh' ...
+#
+
+tcount=0
+r=invalid
+description=''
+directive=''
+
+test_begin ()
+{
+ if test -n "$description"; then
+ fatal_ "'test_begin' called, but another test seems active already"
+ else
+ r=ok
+ description=$1
+ directive=${2-}
+ echo "$description" > README.txt
+ shift
+ fi
+ tcount=$(($tcount + 1)) && test $tcount -gt 0 \
+ || fatal_ "failed to bump the test count"
+ mkdir $tcount.d
+ cd $tcount.d
+}
+
+test_end ()
+{
+ if test -z "$description"; then
+ fatal_ "'test_end' called, but no test seems active"
+ else
+ cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
+ result_ "$r" -D "$directive" -- "$description"
+ # Don't leave directories for successful subtests hanging around.
+ if test -z "$directive" && test "$r" = ok; then
+ rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
+ fi
+ r=invalid directive= description=
+ fi
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR is honored"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [10.0])
+AC_CONFIG_MACRO_DIR([macro-dir])
+MY_FOO
+END
+
+mkdir macro-dir
+echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4
+
+$ACLOCAL \
+ && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $FGREP 'MY_FOO' configure \
+ && $FGREP '::my::foo::' configure \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR([foo]) interaction with --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst], [1.0])
+AC_CONFIG_MACRO_DIR([the-dir])
+THE_MACRO
+END
+
+mkdir sys-dir the-dir
+echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
+
+test ! -r the-dir/my.m4 \
+ && $ACLOCAL --install --system-acdir ./sys-dir \
+ && diff sys-dir/my.m4 the-dir/my.m4 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "'-I' option wins over AC_CONFIG_MACRO_DIR"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [4.6])
+AC_CONFIG_MACRO_DIR([dir1])
+MY_FOO
+END
+
+mkdir dir1 dir2
+echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
+echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
+
+$ACLOCAL -I dir2 \
+ && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
+ && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $FGREP '::ko::ko::' configure \
+ && $FGREP '::ok::ok::' configure \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR([foo]) can create directory 'foo'"
+
+cat > configure.ac << 'END'
+AC_INIT([x], [1.0])
+AC_CONFIG_MACRO_DIR([foo])
+MY_MACRO
+END
+
+mkdir acdir
+echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
+
+test ! -d foo \
+ && $ACLOCAL --install --system-acdir ./acdir \
+ && diff acdir/bar.m4 foo/bar.m4 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR([non-existent]) warns with -Wunsupported"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIR([non-existent])
+AM_INIT_AUTOMAKE
+END
+
+$ACLOCAL -Wno-error 2>stderr \
+ && cat stderr >&2 \
+ && grep "couldn't open directory 'non-existent'" stderr \
+ && test -f aclocal.m4 \
+ || r='not ok'
+
+rm -rf aclocal.m4 autom4te*.cache
+
+$ACLOCAL -Werror -Wno-unsupported \
+ && test -f aclocal.m4 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR([not-exist]) and ACLOCAL_AMFLAGS = -I not-exist"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIR([not-exist])
+END
+
+cat > Makefile.am << 'END'
+ACLOCAL_AMFLAGS = -I not-exist
+END
+
+$ACLOCAL -Wno-error 2>stderr \
+ && cat stderr >&2 \
+ && test $(grep -c "couldn't open directory 'not-exist'" stderr) -eq 1 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+# Avoid spurious failures with pre-2.70 autoconf.
+# FIXME: remove this in automake 2.0, once we require Autoconf 2.70.
+if echo 'AC_INIT AC_CONFIG_MACRO_DIRS' | $AUTOCONF -o/dev/null -; then
+
+ test_begin "AC_CONFIG_MACRO_DIR interaction with AC_REQUIRE"
+
+ unindent > configure.ac <<'END'
+ AC_INIT([req], [1.0])
+ AC_CONFIG_MACRO_DIR([macro-dir])
+ AC_DEFUN([MY_FOO], [AC_REQUIRE([MY_BAR])])
+ MY_FOO
+END
+
+ mkdir macro-dir
+ echo 'AC_DEFUN([MY_BAR], [//my//bar//])' > macro-dir/x.m4
+
+ st=0; $ACLOCAL 2>stderr || st=$?
+ cat stderr >&2
+
+ test $st -eq 0 \
+ && test ! -s stderr \
+ && $FGREP 'm4_include([macro-dir/x.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $EGREP 'MY_(FOO|BAR)' configure \
+ && $FGREP '//my//bar//' configure \
+ || r='not ok'
+
+ test_end
+
+else
+
+ skip_ -r "autoconf is too old (AC_CONFIG_MACRO_DIRS not defined)"
+
+fi
+
+:
diff --git a/t/aclocal-macrodirs.tap b/t/aclocal-macrodirs.tap
new file mode 100644
index 000000000..b6bb946bd
--- /dev/null
+++ b/t/aclocal-macrodirs.tap
@@ -0,0 +1,445 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIRS with
+# aclocal. See also related test 'aclocal-macrodir.tap'.
+
+am_create_testdir=empty
+. test-init.sh
+
+plan_ 15
+
+ocwd=$(pwd) || fatal_ "getting current working directory"
+unset ACLOCAL_PATH
+
+#
+# General utility functions and variables.
+#
+# TODO: These should maybe be refactored, generalized and
+# moved into 't/ax/tap-functions.sh' ...
+#
+
+tcount=0
+r=invalid
+description=''
+directive=''
+
+test_begin ()
+{
+ if test -n "$description"; then
+ fatal_ "'test_begin' called, but another test seems active already"
+ else
+ r=ok
+ description=$1
+ directive=${2-}
+ echo "$description" > README.txt
+ shift
+ fi
+ tcount=$(($tcount + 1)) && test $tcount -gt 0 \
+ || fatal_ "failed to bump the test count"
+ mkdir $tcount.d
+ cd $tcount.d
+}
+
+test_end ()
+{
+ if test -z "$description"; then
+ fatal_ "'test_end' called, but no test seems active"
+ else
+ cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
+ result_ "$r" -D "$directive" -- "$description"
+ # Don't leave directories for successful subtests hanging around.
+ if test -z "$directive" && test "$r" = ok; then
+ rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
+ fi
+ r=invalid directive= description=
+ fi
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS is honored"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [10.0])
+AC_CONFIG_MACRO_DIRS([macro-dir])
+MY_FOO
+END
+
+mkdir macro-dir
+echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4
+
+$ACLOCAL \
+ && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $FGREP 'MY_FOO' configure \
+ && $FGREP '::my::foo::' configure \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+three_dirs_check ()
+{
+ mkdir dir1 dir2 dir3
+ echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > dir1/foo.m4
+ echo 'AC_DEFUN([MY_BAR], [!!my!!bar!!])' > dir2/zap.m4
+ echo 'AC_DEFUN([MY_BAZ], [==my==baz==])' > dir3/0.m4
+ $ACLOCAL \
+ && $FGREP 'm4_include([dir1/foo.m4])' aclocal.m4 \
+ && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
+ && $FGREP 'm4_include([dir3/0.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
+ && $FGREP '::my::foo::' configure \
+ && $FGREP '!!my!!bar!!' configure \
+ && $FGREP '==my==baz==' configure \
+ || r='not ok'
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS several arguments"
+
+cat > configure.ac <<'END'
+AC_INIT([more-args], [0.2])
+AC_CONFIG_MACRO_DIRS([dir1 dir2 dir3])
+MY_FOO
+MY_BAR
+MY_BAZ
+END
+
+three_dirs_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS several calls"
+
+cat > configure.ac <<'END'
+AC_INIT([more-calls], [2.0])
+AC_CONFIG_MACRO_DIRS([dir1])
+AC_CONFIG_MACRO_DIRS([dir2 dir3])
+MY_FOO
+MY_BAR
+MY_BAZ
+END
+
+three_dirs_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS extra whitespace"
+
+bslash=\\
+
+cat > configure.ac <<END
+AC_INIT([more-args], [0.2])
+AC_CONFIG_MACRO_DIRS([ dir1${bslash}
+${tab} dir2 ${tab}${tab}dir3
+${bslash}
+
+])
+MY_FOO
+MY_BAR
+MY_BAZ
+END
+
+three_dirs_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS precedence"
+
+cat > configure.ac <<'END'
+AC_INIT([more-calls], [2.0])
+AC_CONFIG_MACRO_DIRS([dir1])
+AC_CONFIG_MACRO_DIRS([dir2 dir3])
+MY_FOO
+MY_BAR
+MY_BAZ
+END
+
+mkdir dir1 dir2 dir3
+echo 'AC_DEFUN([MY_FOO], [OK-Foo])' > dir1/b.m4
+echo 'AC_DEFUN([MY_FOO], [KO-Foo])' > dir2/a.m4
+echo 'AC_DEFUN([MY_BAR], [OK-Bar])' > dir2/1.m4
+echo 'AC_DEFUN([MY_BAR], [KO-Bar])' > dir3/0.m4
+echo 'AC_DEFUN([MY_BAZ], [OK-Baz])' > dir3/x.m4
+
+$ACLOCAL \
+ && $FGREP 'm4_include([dir1/b.m4])' aclocal.m4 \
+ && $FGREP 'm4_include([dir2/1.m4])' aclocal.m4 \
+ && $FGREP 'm4_include([dir3/x.m4])' aclocal.m4 \
+ && test $($FGREP -c 'm4_include([dir1' aclocal.m4) -eq 1 \
+ && test $($FGREP -c 'm4_include([dir2' aclocal.m4) -eq 1 \
+ && test $($FGREP -c 'm4_include([dir3' aclocal.m4) -eq 1 \
+ && $AUTOCONF \
+ && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
+ && $FGREP 'OK-Foo' configure \
+ && $FGREP 'OK-Bar' configure \
+ && $FGREP 'OK-Baz' configure \
+ && not $FGREP 'KO-' configure \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS interaction with --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst], [1.0])
+AC_CONFIG_MACRO_DIRS([the-dir])
+THE_MACRO
+END
+
+mkdir sys-dir the-dir
+echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
+
+test ! -r the-dir/my.m4 \
+ && $ACLOCAL --install --system-acdir ./sys-dir \
+ && diff sys-dir/my.m4 the-dir/my.m4 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+two_dirs_install_check ()
+{
+ mkdir sys-dir dir1 dir2
+ echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
+ echo 'AC_DEFUN([AX_FOO], [:])' > dir2/zap.m4
+ test ! -r dir1/my.m4 \
+ && $ACLOCAL --install --system-acdir ./sys-dir \
+ && diff sys-dir/my.m4 dir1/my.m4 \
+ && test ! -e dir2/my.m4 \
+ && $FGREP 'm4_include([dir1/my.m4])' aclocal.m4 \
+ && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
+ || r='not ok'
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "several AC_CONFIG_MACRO_DIRS arguments and --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst2a], [1.0])
+AC_CONFIG_MACRO_DIRS([dir1 dir2])
+THE_MACRO
+AX_FOO
+END
+
+two_dirs_install_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+
+test_begin "several AC_CONFIG_MACRO_DIRS calls and --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst2b], [1.0])
+AC_CONFIG_MACRO_DIRS([dir1])
+AC_CONFIG_MACRO_DIRS([dir2])
+THE_MACRO
+AX_FOO
+END
+
+two_dirs_install_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "'-I' option wins over AC_CONFIG_MACRO_DIRS"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [4.6])
+AC_CONFIG_MACRO_DIRS([dir1])
+MY_FOO
+END
+
+mkdir dir1 dir2
+echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
+echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
+
+$ACLOCAL -I dir2 \
+ && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
+ && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $FGREP '::ko::ko::' configure \
+ && $FGREP '::ok::ok::' configure \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([foo]) can create directory 'foo'"
+
+cat > configure.ac << 'END'
+AC_INIT([x], [1.0])
+AC_CONFIG_MACRO_DIRS([foo])
+MY_MACRO
+END
+
+mkdir acdir
+echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
+
+test ! -d foo \
+ && $ACLOCAL --install --system-acdir ./acdir \
+ && diff acdir/bar.m4 foo/bar.m4 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) warns (1)"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([non-existent])
+AM_INIT_AUTOMAKE
+END
+
+$ACLOCAL -Wno-error 2>stderr \
+ && cat stderr >&2 \
+ && grep "couldn't open directory 'non-existent'" stderr \
+ && test -f aclocal.m4 \
+ || r='not ok'
+
+rm -rf aclocal.m4 autom4te*.cache
+
+$ACLOCAL -Werror -Wno-unsupported \
+ && test -f aclocal.m4 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) warns (2)"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([dir-ok])
+AC_CONFIG_MACRO_DIRS([dir-ko])
+END
+
+mkdir dir-ok
+not $ACLOCAL 2>stderr \
+ && cat stderr >&2 \
+ && grep "couldn't open directory 'dir-ko'" stderr \
+ && not grep "dir-ok" stderr \
+ && test ! -e aclocal.m4 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([existent non-existent]) errors out"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([dir-ok])
+AC_CONFIG_MACRO_DIRS([dir-ko])
+END
+
+mkdir dir-ok
+
+not $ACLOCAL -Wnone --install 2>stderr \
+ && cat stderr >&2 \
+ && grep "couldn't open directory 'dir-ko'" stderr \
+ && test ! -e dir-ko \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([not-exist]) and ACLOCAL_AMFLAGS = -I not-exist"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([not-exist])
+END
+
+cat > Makefile.am << 'END'
+ACLOCAL_AMFLAGS = -I not-exist
+END
+
+$ACLOCAL -Wno-error 2>stderr \
+ && cat stderr >&2 \
+ && test $(grep -c "couldn't open directory 'not-exist'" stderr) -eq 1 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+# Avoid spurious failures with pre-2.70 autoconf.
+# FIXME: remove this in automake 2.0, once we require Autoconf 2.70.
+if echo 'AC_INIT AC_CONFIG_MACRO_DIRS' | $AUTOCONF -o/dev/null -; then
+
+ test_begin "AC_CONFIG_MACRO_DIRS interaction with AC_REQUIRE"
+
+ unindent > configure.ac <<'END'
+ AC_INIT([req], [1.0])
+ AC_CONFIG_MACRO_DIRS([m1 m2])
+ AC_DEFUN([MY_FOO], [
+ AC_REQUIRE([MY_BAR])
+ AC_REQUIRE([MY_BAZ])
+ ])
+ MY_FOO
+END
+
+ mkdir m1 m2
+ echo 'AC_DEFUN([MY_BAR], [^^my^^bar^^])' > m1/x.m4
+ echo 'AC_DEFUN([MY_BAZ], [~~my~~baz~~])' > m2/x.m4
+
+ st=0; $ACLOCAL 2>stderr || st=$?
+ cat stderr >&2
+
+ test $st -eq 0 \
+ && test ! -s stderr \
+ && $FGREP 'm4_include([m1/x.m4])' aclocal.m4 \
+ && $FGREP 'm4_include([m2/x.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
+ && $FGREP '^^my^^bar^^' configure \
+ && $FGREP '~~my~~baz~~' configure \
+ || r='not ok'
+
+ test_end
+
+else
+
+ skip_ -r "autoconf is too old (AC_CONFIG_MACRO_DIRS not defined)"
+
+fi
+
+:
diff --git a/t/aclocal-missing-macros.sh b/t/aclocal-missing-macros.sh
new file mode 100644
index 000000000..4bc00986a
--- /dev/null
+++ b/t/aclocal-missing-macros.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure include of include detects missing macros
+
+am_create_testdir=empty
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_INIT([$me], [1.0])
+GNOME_X_CHECKS
+END
+
+mkdir macros
+
+cat > macros/gnome.m4 << 'END'
+AC_DEFUN([GNOME_X_CHECKS], [
+# Use a macro that cannot be installed in a third-party system-wide m4
+# file; otherwise, this test might fail under "make installcheck".
+ AM__PATH__GTK(0.99.5,,AC_MSG_ERROR(GTK not installed, or gtk-config not in path))
+])
+END
+
+$ACLOCAL -I macros 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr
+grep '^macros/gnome\.m4:4:.*AM__PATH__GTK.*not found' stderr
+
+:
diff --git a/t/aclocal-no-extra-scan.sh b/t/aclocal-no-extra-scan.sh
new file mode 100644
index 000000000..91f93aed0
--- /dev/null
+++ b/t/aclocal-no-extra-scan.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal does not include definitions that are not actually
+# evaluated.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([x], [0])
+AC_SUBST([POM])
+END
+
+mkdir m4
+cat >m4/some.m4 <<'EOF'
+AC_DEFUN([AM_SOME_MACRO],
+[AC_DEFUN([AC_SUBST], [GREPME])])
+EOF
+
+$ACLOCAL -I m4
+$EGREP 'some.m4|GREPME' aclocal.m4 && exit 1
+
+:
diff --git a/t/aclocal-no-force.sh b/t/aclocal-no-force.sh
new file mode 100644
index 000000000..e0d558221
--- /dev/null
+++ b/t/aclocal-no-force.sh
@@ -0,0 +1,117 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal does not overwrite aclocal.m4 needlessly.
+# Also make sure automake --no-force does not overwrite Makefile.in needlessly.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+SOME_DEFS
+AC_CONFIG_FILES([sub/Makefile])
+END
+
+mkdir sub
+: > sub/Makefile.am
+
+cat >> Makefile.am << 'END'
+SUBDIRS = sub
+include fragment.inc
+END
+
+: > fragment.inc
+
+mkdir m4
+echo 'AC_DEFUN([SOME_DEFS], [])' > m4/somedefs.m4
+
+# Automake will take aclocal.m4 to be newer if it has the same timestamp
+# as Makefile.in. Avoid the confusing by sleeping.
+AUTOMAKE_after_aclocal ()
+{
+ $sleep
+ $AUTOMAKE --no-force
+}
+
+# aclocal will rewrite aclocal.m4 unless the input files are all older than the
+# existing aclocal.m4 -- sleep to ensure somedefs.m4 has an older timestamp
+# than the aclocal.m4 that the next aclocal call will generate.
+$sleep
+
+$ACLOCAL -I m4
+AUTOMAKE_after_aclocal
+
+touch foo
+$sleep
+$ACLOCAL -I m4
+AUTOMAKE_after_aclocal
+# aclocal.m4 and Makefile.in should not have been updated, so 'foo'
+# should be younger
+is_newest foo aclocal.m4 Makefile.in sub/Makefile.in
+
+$sleep
+$ACLOCAL -I m4 --force
+is_newest aclocal.m4 foo
+# We still use --no-force for automake, but since aclocal.m4 has
+# changed all Makefile.ins should be updated.
+AUTOMAKE_after_aclocal
+is_newest Makefile.in aclocal.m4 foo
+is_newest sub/Makefile.in aclocal.m4 foo
+
+$sleep
+touch m4/somedefs.m4
+$sleep
+$ACLOCAL -I m4
+AUTOMAKE_after_aclocal
+# aclocal.m4 should have been updated, although its contents haven't
+# changed.
+is_newest aclocal.m4 m4/somedefs.m4
+is_newest Makefile.in m4/somedefs.m4
+is_newest sub/Makefile.in m4/somedefs.m4
+
+$sleep
+touch fragment.inc
+$sleep
+$ACLOCAL -I m4
+AUTOMAKE_after_aclocal
+# Only ./Makefile.in should change.
+is_newest Makefile.in fragment.inc
+is_newest fragment.inc aclocal.m4
+is_newest fragment.inc sub/Makefile.in
+
+grep README Makefile.in && exit 1
+
+$sleep
+: > README
+$sleep
+$AUTOMAKE --no-force
+# Even if no dependency change, the content changed.
+is_newest Makefile.in README
+is_newest README sub/Makefile.in
+
+grep README Makefile.in
+
+: > sub/Makefile.in
+$sleep
+touch foo
+$sleep
+$ACLOCAL -I m4
+$AUTOMAKE --no-force
+# Only sub/Makefile.in should change.
+is_newest foo aclocal.m4
+is_newest foo Makefile.in
+is_newest sub/Makefile.in foo
+
+:
diff --git a/t/aclocal-no-install-no-mkdir.sh b/t/aclocal-no-install-no-mkdir.sh
new file mode 100644
index 000000000..51c99305c
--- /dev/null
+++ b/t/aclocal-no-install-no-mkdir.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that aclocal does not create a non-existent local m4 directory
+# if the '--install' option is not given.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+MY_MACRO
+END
+
+mkdir sys-acdir
+cat > sys-acdir/my-defs.m4 <<END
+AC_DEFUN([MY_MACRO], [:])
+END
+
+$ACLOCAL -I foo --system-acdir=sys-acdir && exit 1
+test ! -e foo
+
+:
diff --git a/t/aclocal-no-symlinked-overwrite.sh b/t/aclocal-no-symlinked-overwrite.sh
new file mode 100644
index 000000000..d0450aa57
--- /dev/null
+++ b/t/aclocal-no-symlinked-overwrite.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal does not write into symlinked aclocal.m4.
+
+am_create_testdir=empty
+. test-init.sh
+
+echo 'm4_define([FOO], [wrong foo])' > foo.m4
+echo 'm4_define([FOO], [right foo])' > acinclude.m4
+echo 'AC_INIT FOO' > configure.ac
+
+chmod a-w foo.m4
+
+# Setup.
+ln -s foo.m4 aclocal.m4 && test -h aclocal.m4 \
+ || skip_ "cannot create symlinks to files"
+
+# Sanity check.
+grep 'wrong foo' aclocal.m4 \
+ || fatal_ "weird error symlinking aclocal.m4 -> foo.m4"
+
+$ACLOCAL
+$AUTOCONF
+grep 'right foo' configure
+grep 'wrong foo' foo.m4
+
+:
diff --git a/t/aclocal-no-unused-required.sh b/t/aclocal-no-unused-required.sh
new file mode 100644
index 000000000..cdac63d2e
--- /dev/null
+++ b/t/aclocal-no-unused-required.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal does not require unused macros.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+SOME_DEFS
+END
+
+mkdir m4
+cat >m4/somedefs.m4 <<EOF
+AC_DEFUN([SOME_DEFS], [
+ m4_if([a], [a], [MACRO1], [MACRO2])
+])
+EOF
+
+echo 'AC_DEFUN([MACRO1],)' >m4/macro1.m4
+echo 'AC_DEFUN([MACRO2], [AC_REQUIRE([AM_UNUSED_MACRO])])' >m4/macro2.m4
+
+$ACLOCAL -I m4 >output 2>&1 || { cat output; exit 1; }
+test 0 -eq $(wc -l <output)
+grep macro1.m4 aclocal.m4
+grep macro2.m4 aclocal.m4 && exit 1
+
+:
diff --git a/t/aclocal-path-install-serial.sh b/t/aclocal-path-install-serial.sh
new file mode 100644
index 000000000..5ebcb1b58
--- /dev/null
+++ b/t/aclocal-path-install-serial.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# ACLOCAL_PATH, acdir and '--install' interactions when serial number
+# are involved.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+AM_FOO
+END
+
+set_serial ()
+{
+ serial=$1 file=$2
+ sed '/^# serial/d' $file > t
+ case $serial in
+ none) mv -f t $file;;
+ *) (echo "# serial $serial" && cat t) > $file; rm -f t;;
+ esac
+ cat $file # For debugging.
+}
+
+win ()
+{
+ case $1 in
+ sdir) ok=sdir ko=pdir;;
+ pdir) ok=pdir ko=sdir;;
+ *) fatal_ "win(): invalid argument '$1'";;
+ esac
+ # This is required on fast machine, to avoid caching and timestamp
+ # issues with the autotools (already happened in practice).
+ rm -rf configure aclocal.m4 autom4te*.cache m4/*
+ $ACLOCAL -I m4 --install
+ test -f m4/foo.m4 # Sanity check.
+ $AUTOCONF
+ $FGREP "::$ok:" m4/foo.m4
+ $FGREP "::$ok::" configure
+ $FGREP "::$ko::" m4/foo.m4 configure && exit 1
+ :
+}
+
+mkdir sdir pdir m4
+
+ACLOCAL="$ACLOCAL --system-acdir=$(pwd)/sdir"
+ACLOCAL_PATH=./pdir; export ACLOCAL_PATH
+
+cat > sdir/foo.m4 << 'END'
+AC_DEFUN([AM_FOO], [::sdir::])
+END
+cat > pdir/foo.m4 << 'END'
+AC_DEFUN([AM_FOO], [::pdir::])
+END
+
+set_serial 2 sdir/foo.m4
+set_serial 1 pdir/foo.m4
+win sdir
+
+set_serial 3.3 sdir/foo.m4
+set_serial 5.7 pdir/foo.m4
+win pdir
+
+set_serial 0 sdir/foo.m4
+set_serial none pdir/foo.m4
+win sdir
+
+set_serial none sdir/foo.m4
+set_serial 1.2.3 pdir/foo.m4
+win pdir
+
+:
diff --git a/t/aclocal-path-install.sh b/t/aclocal-path-install.sh
new file mode 100644
index 000000000..3ff7d4196
--- /dev/null
+++ b/t/aclocal-path-install.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# ACLOCAL_PATH and '--install' interactions.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+AM_FOO
+END
+
+mkdir acdir pdir ldir
+
+ACLOCAL="$ACLOCAL --system-acdir=$(pwd)/acdir"
+ACLOCAL_PATH=./pdir; export ACLOCAL_PATH
+
+cat > acdir/foo.m4 << 'END'
+AC_DEFUN([AM_FOO], [:])
+END
+
+cat > pdir/bar.m4 << 'END'
+AC_DEFUN([AM_BAR], [:])
+END
+
+# The '--install' option should never cause anything to be installed
+# in a directory specified in ACLOCAL_PATH.
+$ACLOCAL --install 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'impossible without -I .* nor AC_CONFIG_MACRO_DIR' stderr
+test ! -e pdir/foo.m4
+
+# The '--install' option should cause a required macro found in a
+# directory specified in ACLOCAL_PATH to be installed locally.
+echo AM_BAR >> configure.ac
+$ACLOCAL --install -I ldir
+diff pdir/bar.m4 ldir/bar.m4
+
+:
diff --git a/t/aclocal-path-nonexistent.sh b/t/aclocal-path-nonexistent.sh
new file mode 100644
index 000000000..caf365873
--- /dev/null
+++ b/t/aclocal-path-nonexistent.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Non-existent directories in ACLOCAL_PATH are ok.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+AM_FOO
+END
+
+mkdir mdir
+echo 'AC_DEFUN([AM_FOO], [am--foo])' > mdir/foo.m4
+
+ACLOCAL_PATH=./nonesuch:./mdir:$(pwd)/nonesuch2:nonesuch3 $ACLOCAL
+$AUTOCONF
+$FGREP 'am--foo' configure
+
+:
diff --git a/t/aclocal-path-precedence.sh b/t/aclocal-path-precedence.sh
new file mode 100644
index 000000000..cefdad87c
--- /dev/null
+++ b/t/aclocal-path-precedence.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check precedence rules for ACLOCAL_PATH.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([foo], [1.0])
+AM_INIT_AUTOMAKE
+FOO_MACRO
+BAR_MACRO
+AC_PROG_LIBTOOL
+AM_GNU_GETTEXT
+END
+
+mkdir mdir1 mdir2 mdir3 sysdir extradir
+
+cat > mdir1/foo1.m4 << 'END'
+AC_DEFUN([FOO_MACRO], [::pass-foo::])
+END
+
+cat > mdir2/foo2.m4 << 'END'
+AC_DEFUN([FOO_MACRO], [::fail-foo::])
+END
+
+cat > mdir1/baz.m4 << 'END'
+AC_DEFUN([BAR_MACRO], [::fail-bar::])
+END
+
+cat > mdir3/bar.m4 << 'END'
+AC_DEFUN([BAR_MACRO], [::pass-bar::])
+END
+
+cat > mdir2/quux.m4 << 'END'
+AC_DEFUN([AM_INIT_AUTOMAKE], [::fail-init::])
+AC_DEFUN([AC_PROG_LIBTOOL], [::pass-libtool::])
+AC_DEFUN([AM_GNU_GETTEXT], [::pass-gettext::])
+END
+
+cat > sysdir/libtool.m4 << 'END'
+AC_DEFUN([AC_PROG_LIBTOOL], [::fail-libtool::])
+END
+
+cat > extradir/gettext.m4 << 'END'
+AC_DEFUN([AM_GNU_GETTEXT], [::fail-gettext::])
+END
+
+echo ./extradir > sysdir/dirlist
+
+ACLOCAL_PATH=mdir1:mdir2 $ACLOCAL -I mdir3 --system-acdir sysdir
+$AUTOCONF
+
+$FGREP '::' configure # For debugging.
+
+# Directories coming first in ACLOCAL_PATH should take precedence
+# over those coming later.
+$FGREP '::pass-foo::' configure
+
+# Directories from '-I' options should take precedence over directories
+# in ACLOCAL_PATH.
+$FGREP '::pass-bar::' configure
+
+# Directories in ACLOCAL_PATH should take precedence over system acdir
+# (typically '${prefix}/share/aclocal'), and any directory added through
+# the 'dirlist' special file.
+$FGREP '::pass-gettext::' configure
+$FGREP '::pass-libtool::' configure
+
+# Directories in ACLOCAL_PATH shouldn't take precedence over the internal
+# automake acdir (typically '${prefix}/share/aclocal-${APIVERSION}').
+$FGREP 'am__api_version' configure
+
+# A final sanity check.
+$FGREP '::fail' configure && exit 1
+
+:
diff --git a/t/aclocal-path.sh b/t/aclocal-path.sh
new file mode 100644
index 000000000..cbaa4ac3c
--- /dev/null
+++ b/t/aclocal-path.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check basic ACLOCAL_PATH support.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+AM_FOO_MACRO
+AM_BAR_MACRO
+AM_BAZ_MACRO
+END
+
+mkdir mdir1 mdir2 mdir3
+
+cat > mdir1/foo.m4 << 'END'
+AC_DEFUN([AM_FOO_MACRO], [am--foo])
+END
+
+cat > mdir2/bar.m4 << 'END'
+AC_DEFUN([AM_BAR_MACRO], [am--bar])
+END
+
+cat > mdir3/baz.m4 << 'END'
+AC_DEFUN([AM_BAZ_MACRO], [am--baz])
+END
+
+ACLOCAL_PATH=mdir1:./mdir2:$(pwd)/mdir3 $ACLOCAL
+$AUTOCONF
+
+# there should be no m4_include in aclocal.m4, even though ACLOCAL_PATH
+# contains 'mdir1' and './mdir2' as relative directories. Only -I
+# directories should be subject to file inclusion.
+$FGREP m4_include aclocal.m4 && exit 1
+
+$EGREP 'AM_(FOO|BAR|BAZ)_MACRO' configure && exit 1
+$FGREP 'am--foo' configure
+$FGREP 'am--bar' configure
+$FGREP 'am--baz' configure
+
+:
diff --git a/t/aclocal-pr450.sh b/t/aclocal-pr450.sh
new file mode 100644
index 000000000..4c9d22f43
--- /dev/null
+++ b/t/aclocal-pr450.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal does not fail on configure.ac inclusions that do
+# more than just variable definitions.
+# Report from Peter Breitenlohner (PR/450).
+
+. test-init.sh
+
+cat >configure.ac <<END
+AC_INIT([$me], [1.0])
+m4_include([aconfig.ac])
+FOO
+AC_OUTPUT
+END
+
+cat >aconfig.ac <<'END'
+AM_INIT_AUTOMAKE
+AC_DEFUN([FOO], [echo GREPME])
+sinclude([bconfig.ac])
+END
+
+cat >bconfig.ac <<'END'
+AC_ARG_WITH([grepme], [string])
+END
+
+$ACLOCAL
+$AUTOCONF
+./configure >stdout || { cat stdout; exit 1; }
+cat stdout
+grep GREPME stdout
+grep 'aconfig\.ac' aclocal.m4 && exit 1
+grep 'bconfig\.ac' aclocal.m4 && exit 1
+grep with-grepme configure
+
+:
diff --git a/t/aclocal-print-acdir.sh b/t/aclocal-print-acdir.sh
new file mode 100644
index 000000000..abaee0afc
--- /dev/null
+++ b/t/aclocal-print-acdir.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test on aclocal's '--print-ac-dir' option.
+
+am_create_testdir=empty
+. test-init.sh
+
+$ACLOCAL --print-ac-dir
+test "$($ACLOCAL --print-ac-dir)" = "$am_system_acdir"
+
+$ACLOCAL --system-acdir /bar --print-ac-dir
+test "$($ACLOCAL --system-acdir /bar --print-ac-dir)" = /bar
+
+$ACLOCAL --automake-acdir /bar --print-ac-dir
+test "$($ACLOCAL --automake-acdir /bar --print-ac-dir)" = "$am_system_acdir"
+
+:
diff --git a/t/aclocal-remake-misc.sh b/t/aclocal-remake-misc.sh
new file mode 100644
index 000000000..fe7385f8d
--- /dev/null
+++ b/t/aclocal-remake-misc.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal.m4 is rebuilt whenever a configure
+# dependency changes. Test for acinclude.m4 and VPATH too.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+SOME_DEFS
+AC_CONFIG_FILES([sub/Makefile])
+AC_CONFIG_MACRO_DIR([m4])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+END
+
+mkdir sub
+: > sub/Makefile.am
+
+mkdir m4
+echo 'AC_DEFUN([SOME_DEFS], [])' > m4/somedefs.m4
+echo 'AC_DEFUN([MORE_DEFS], [AC_SUBST([GREPME])])' > m4/moredefs.m4
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+mkdir build
+cd build
+
+../configure
+$MAKE
+
+# Modified configure dependencies must be newer than config.status.
+$sleep
+# Update an aclocal.m4 dependency, then make sure all Makefiles
+# are updated, even from a sub-directory.
+echo 'AC_DEFUN([SOME_DEFS], [MORE_DEFS])' > ../m4/somedefs.m4
+# Because aclocal will run again, it should also pick up acinclude.m4.
+echo 'AC_SUBST([METOO])' > ../acinclude.m4
+
+cd sub
+$MAKE
+cd ..
+grep GREPME Makefile
+grep GREPME sub/Makefile
+grep GREPME sub/Makefile
+grep METOO Makefile
+grep METOO sub/Makefile
+grep METOO sub/Makefile
+
+# Make sure configure dependencies are distributed.
+$MAKE distdir
+test -f $me-1.0/m4/moredefs.m4
+test -f $me-1.0/m4/somedefs.m4
+test -f $me-1.0/acinclude.m4
+
+:
diff --git a/t/aclocal-req.sh b/t/aclocal-req.sh
new file mode 100644
index 000000000..dd46a85a6
--- /dev/null
+++ b/t/aclocal-req.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure macro used in m4 file is included.
+
+. test-init.sh
+
+cat > configure.ac <<EOF
+AC_INIT([$me], [1.0])
+AM_INIT_GUILE_MODULE
+EOF
+
+cat > acinclude.m4 << 'END'
+AC_DEFUN([AM_INIT_GUILE_MODULE], [AM_INIT_AUTOMAKE([whocares])])
+END
+
+$ACLOCAL
+
+grep 'DEFUN.*INIT_AUTOMAKE' aclocal.m4
+
+:
diff --git a/t/aclocal-scan-configure-ac-pr319.sh b/t/aclocal-scan-configure-ac-pr319.sh
new file mode 100644
index 000000000..2e7e10080
--- /dev/null
+++ b/t/aclocal-scan-configure-ac-pr319.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal scans configure.ac for macro definitions.
+# PR/319.
+
+am_create_testdir=empty
+. test-init.sh
+
+# Start macros with AM_ because that causes aclocal to complain if it
+# cannot find them.
+
+cat > configure.ac << 'END'
+AC_INIT
+m4_include([somedef.m4])
+AC_DEFUN([AM_SOME_MACRO])
+AC_DEFUN([AM_SOME_OTHER_MACRO])
+AM_SOME_MACRO
+AM_SOME_OTHER_MACRO
+AM_MORE_MACRO
+END
+
+mkdir m4
+echo 'AC_DEFUN([AM_SOME_MACRO])' > m4/some.m4
+echo 'AC_DEFUN([AM_SOME_DEF])' > somedef.m4
+echo 'AC_DEFUN([AM_MORE_MACRO], [AC_REQUIRE([AM_SOME_DEF])])' > m4/more.m4
+
+$ACLOCAL -I m4
+$FGREP AM_SOME_MACRO aclocal.m4 && exit 1
+$FGREP AM_MORE_MACRO aclocal.m4 && exit 1
+$FGREP 'm4_include([m4/more.m4])' aclocal.m4
+test 1 = $(grep m4_include aclocal.m4 | wc -l)
+
+:
diff --git a/t/aclocal-serial.sh b/t/aclocal-serial.sh
new file mode 100644
index 000000000..17ed7d359
--- /dev/null
+++ b/t/aclocal-serial.sh
@@ -0,0 +1,137 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for --install with #serial numbers.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+AM_MACRO1
+AM_MACRO2
+END
+
+mkdir 1 2 3 4 5 6
+
+cat >1/m1.m4 <<EOF
+#serial 1.8.1230.9
+AC_DEFUN([AM_MACRO1], [:macro11:])
+AC_DEFUN([AM_MACRO2], [:macro21:])
+EOF
+
+cat >2/m1.m4 <<EOF
+#serial 1.8.1231.9
+AC_DEFUN([AM_MACRO1], [:macro12:])
+EOF
+
+cat >3/m2.m4 <<EOF
+#serial 13
+AC_DEFUN([AM_MACRO2], [:macro23:])
+EOF
+
+cat >3/m1.m4 <<EOF
+#serial 1.8.1230.1
+AC_DEFUN([AM_MACRO1], [:macro13:])
+EOF
+
+cat >4/mumble.m4 <<EOF
+#serial 0
+AC_DEFUN([AM_MACRO1], [:macro14:])
+EOF
+
+cat >5/ill-formed.m4 <<EOF
+#serial bla
+#serial .2
+#serial
+AC_DEFUN([AM_MACRO1], [:macro15:])
+EOF
+
+cat >6/after-def.m4 <<EOF
+AC_DEFUN([AM_MACRO1], [:macro16:])
+#serial 1
+EOF
+
+clean_stale ()
+{
+ rm -rf aclocal.m4 configure autom4te*.cache
+}
+
+$ACLOCAL -I 1 -I 2 -I 3 -I 4
+$AUTOCONF
+$FGREP ':macro11:' configure
+$FGREP ':macro21:' configure
+
+clean_stale
+$ACLOCAL -I 1 -I 2 -I 3 -I 4 --install
+$AUTOCONF
+$FGREP ':macro12:' configure
+$FGREP ':macro23:' configure
+
+cp -f aclocal.m4 aclocal-m4.sav
+clean_stale
+mv -f aclocal-m4.sav aclocal.m4
+$ACLOCAL -I 4 -I 1 -I 2 -I 3 --install --dry-run
+$AUTOCONF
+$FGREP ':macro12:' configure
+$FGREP ':macro23:' configure
+
+clean_stale
+$ACLOCAL -I 4 -I 1 -I 2 -I 3 --install
+$AUTOCONF
+$FGREP ':macro14:' configure
+$FGREP ':macro23:' configure
+
+clean_stale
+$ACLOCAL -I 4 -I 1 -I 2 --install 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'macro.*AM_MACRO2.*not found' stderr
+
+clean_stale
+$ACLOCAL -I 4 -I 1 --install
+$AUTOCONF
+$FGREP ':macro14:' configure
+$FGREP ':macro21:' configure
+
+mkdir acdir
+ACLOCAL="$ACLOCAL --system-acdir acdir"
+
+cat >acdir/m1.m4 <<EOF
+#serial 456
+AC_DEFUN([AM_MACRO1], [:macro1d:])
+AC_DEFUN([AM_MACRO2], [:macro2d:])
+EOF
+clean_stale
+$ACLOCAL -I 4 -I 1 --diff=diff >stdout 2>stderr || {
+ cat stderr >&2
+ cat stdout
+ exit 1
+}
+cat stderr >&2
+cat stdout
+grep '#serial 456' stdout
+test ! -e 4/m1.m4
+grep 'installing.*4/m1\.m4' stderr
+
+$ACLOCAL -I 5 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+test $(grep -c 'ill-formed serial' stderr) -eq 3
+
+$ACLOCAL -I 6 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'serial.*before any macro definition' stderr
+
+:
diff --git a/t/aclocal-underquoted-defun.sh b/t/aclocal-underquoted-defun.sh
new file mode 100644
index 000000000..2770011c5
--- /dev/null
+++ b/t/aclocal-underquoted-defun.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure we diagnose underquoted AC_DEFUN's.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT
+FOO
+END
+
+mkdir m4
+cat >m4/foo.m4 <<EOF
+AC_DEFUN(FOO, [echo foo])
+EOF
+
+$ACLOCAL -I m4 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'underquoted definition.*FOO' stderr
+grep 'warning.*warning' stderr && exit 1
+
+:
diff --git a/t/aclocal-verbose-install.sh b/t/aclocal-verbose-install.sh
new file mode 100644
index 000000000..bcbbcfa6b
--- /dev/null
+++ b/t/aclocal-verbose-install.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check verbose messages by 'aclocal --install'.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+MY_MACRO_BAR
+MY_MACRO_QUUX
+END
+
+mkdir sys-acdir
+cat > sys-acdir/bar.m4 <<END
+AC_DEFUN([MY_MACRO_BAR], [:])
+END
+cat > sys-acdir/quux.m4 <<END
+AC_DEFUN([MY_MACRO_QUUX], [:])
+END
+
+mkdir foodir
+: > foodir/bar.m4
+
+$ACLOCAL --system-acdir=sys-acdir --install --verbose -I foodir 2>stderr \
+ || { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep ' installing .*sys-acdir/bar\.m4.* to .*foodir/bar\.m4' stderr
+grep ' installing .*sys-acdir/quux\.m4.* to .*foodir/quux\.m4' stderr
+grep ' overwriting .*foodir/bar\.m4.* with .*sys-acdir/bar\.m4' stderr
+grep ' installing .*foodir/quux\.m4.* from .*sys-acdir/quux\.m4' stderr
+
+# Sanity checks.
+ls -l foodir
+grep MY_MACRO_BAR foodir/bar.m4
+grep MY_MACRO_QUUX foodir/quux.m4
+
+:
diff --git a/t/aclocal.sh b/t/aclocal.sh
new file mode 100644
index 000000000..171a179e3
--- /dev/null
+++ b/t/aclocal.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test on some aclocal options. Report from Alexandre Oliva.
+
+am_create_testdir=empty
+. test-init.sh
+
+echo "AC_INIT([$me], [0]) AM_INIT_AUTOMAKE" > configure.ac
+
+$ACLOCAL --output=fred
+test -f fred
+
+$ACLOCAL --output 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'option.*--output.*requires an argument' stderr
+grep '[Tt]ry.*--help.*for more information' stderr
+
+$ACLOCAL --unknown-option 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'unrecognized option.*--unknown-option' stderr
+grep '[Tt]ry.*--help.*for more information' stderr
+
+$ACLOCAL foobar 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'non-option argument.*foobar' stderr
+grep '[Tt]ry.*--help.*for more information' stderr
+
+$ACLOCAL --ver 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'unrecognized option.*--ver' stderr
+grep '[Tt]ry.*--help.*for more information' stderr
+
+$ACLOCAL --versi
+
+:
diff --git a/t/acsilent.sh b/t/acsilent.sh
new file mode 100644
index 000000000..cae24ba59
--- /dev/null
+++ b/t/acsilent.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure there are no spurious acinclude warnings.
+
+. test-init.sh
+
+cat >configure.ac <<EOF
+AC_INIT([$me], [1.0])
+AM_INIT_GUILE_MODULE
+EOF
+
+cat > acinclude.m4 << 'END'
+AC_DEFUN([AM_INIT_GUILE_MODULE], [
+AM_INIT_AUTOMAKE([dist-xz])
+AC_CONFIG_AUX_DIR(..)
+module=[$1]
+AC_SUBST(module)])
+END
+
+$ACLOCAL >output 2>&1 || { cat output; exit 1; }
+cat output
+test ! -s output
diff --git a/t/acsubst.sh b/t/acsubst.sh
new file mode 100644
index 000000000..3ebc5ed5f
--- /dev/null
+++ b/t/acsubst.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_SUBST([FOOBAR_LDFLAGS],[blablabla])
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = mumble
+mumble_SOURCES = a.c b.c d.h
+mumble_LDFLAGS = $(FOOBAR_LDFLAGS)
+END
+
+$ACLOCAL
+$AUTOMAKE -a
diff --git a/t/acsubst2.sh b/t/acsubst2.sh
new file mode 100644
index 000000000..fd5d62841
--- /dev/null
+++ b/t/acsubst2.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_SUBST([FOOBAR_CFLAGS],[blablabla])
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = mumble
+mumble_SOURCES = a.c b.c d.h
+mumble_CFLAGS = $(FOOBAR_CFLAGS)
+END
+
+$ACLOCAL
+$AUTOMAKE -a
diff --git a/t/add-missing-install-sh.sh b/t/add-missing-install-sh.sh
new file mode 100644
index 000000000..12ba626e6
--- /dev/null
+++ b/t/add-missing-install-sh.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for this bug:
+# automake: Makefile.am: required file "../../install-sh" not found; installing
+# This also makes sure that install-sh is created in the correct directory.
+
+. test-init.sh
+
+: > Makefile.am
+rm -f install-sh
+
+# Since the default path includes '../..', we must run this test in
+# yet another subdir.
+mkdir frob
+mv Makefile.am configure.ac frob/
+cd frob
+
+$ACLOCAL
+$AUTOMAKE --add-missing >output 2>&1 || { cat output; exit 1; }
+cat output
+
+# Only one '/' should appear in the output.
+grep '/.*/' output && exit 1
+
+test -f install-sh
+
+:
diff --git a/t/add-missing-multiple.sh b/t/add-missing-multiple.sh
new file mode 100644
index 000000000..7d8e7b9b6
--- /dev/null
+++ b/t/add-missing-multiple.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake will install several copies of required files if needed.
+# Reported by Marius Vollmer.
+
+. test-init.sh
+
+cat >> configure.ac <<EOF
+AC_CONFIG_FILES([one/Makefile two/Makefile])
+AC_OUTPUT
+EOF
+
+mkdir one
+mkdir two
+
+echo 'SUBDIRS = one two' > Makefile.am
+echo 'info_TEXINFOS = mumble.texi' > one/Makefile.am
+cat >one/mumble.texi <<'END'
+@setfilename mumble.info
+@include version.texi
+END
+
+cp one/Makefile.am one/mumble.texi two
+
+$ACLOCAL
+$AUTOMAKE --add-missing --copy
+
+test -f one/mdate-sh
+test -f one/texinfo.tex
+test -f two/mdate-sh
+test -f two/texinfo.tex
+
+:
diff --git a/t/add-missing.tap b/t/add-missing.tap
new file mode 100644
index 000000000..4276f3fb1
--- /dev/null
+++ b/t/add-missing.tap
@@ -0,0 +1,382 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that automake complains when required auxiliary files are not
+# found, and that 'automake --add-missing' installs the files (and only
+# the files) it's supposed to, and that these files are symlinked by
+# default, but copied if the '--copy' option is used.
+
+am_create_testdir=empty
+. test-init.sh
+
+plan_ "later"
+
+build_aux=build-aux
+ocwd=$(pwd) || fatal_ "cannot get current working directory"
+
+# Try to improve readability of displayed diffs.
+if diff -u /dev/null /dev/null; then
+ am_diff='diff -u'
+elif diff -c /dev/null /dev/null; then
+ am_diff='diff -c'
+else
+ am_diff=diff
+fi
+
+# MinGW/MSYS lacks real symlinks, so we'll have to skip some checks
+# on that system. More details below.
+echo dummy > foo
+if ln -s foo bar && test -h bar; then
+ have_true_symlinks=yes
+else
+ have_true_symlinks=no
+fi
+rm -f foo bar
+
+cat > configure.stub << END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([$build_aux])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+# Pre-compute aclocal.m4, in order to save several aclocal invocations.
+cat configure.stub - > configure.ac <<'END'
+AC_PROG_CC
+AC_CANONICAL_BUILD
+AC_CANONICAL_HOST
+AC_CANONICAL_TARGET
+AC_CANONICAL_SYSTEM
+AM_PATH_LISPDIR
+AM_PATH_PYTHON
+AC_OUTPUT
+END
+$ACLOCAL || framework_failure_ "cannot pre-compute aclocal.m4"
+
+rm -rf configure.ac autom4te*.cache
+mv aclocal.m4 aclocal.stub
+
+# For debugging.
+cat configure.stub
+cat aclocal.stub
+
+check_count=0
+
+# This is hacky and ugly and complex, but allow us to organize our tests
+# below in a more "declarative fashion". All in all, a good trade-off.
+check_ ()
+{
+ set +x # Temporary disable shell traces to remove noise from log files.
+ check_count=$(($check_count + 1))
+ echo check count: $check_count
+ override=no
+ run_aclocal=no
+ fetch_file=
+ while test $# -gt 0; do
+ case $1 in
+ --override) override=yes;;
+ --run-aclocal) run_aclocal=yes;;
+ --fetch-file) fetch_file=$2; shift;;
+ *) framework_failure_ "check_: invalid argument '$1'";;
+ esac
+ shift
+ done
+ mkdir testdir-$check_count
+ cd testdir-$check_count
+ # Directory for common data files (specific to the current test, but
+ # shared by its "subtests").
+ mkdir generic
+ cd generic
+ : > Makefile.am
+ if test $override = yes; then
+ : > configure.ac
+ else
+ cp "$ocwd"/configure.stub configure.ac
+ fi
+ test -z "$fetch_file" || cp "$ocwd/$fetch_file" .
+ # Read description of "test scenario" from standard input.
+ what= line= name= files=
+ while read line; do
+ case $line in
+ '== Name ==') what=NAME;;
+ '== Makefile.am ==') what=Makefile.am;;
+ '== configure.ac ==') what=configure.ac;;
+ '== Files ==') what=LIST;;
+ '==*') framework_failure_ "invalid input line: $line";;
+ ''|'#%'*) : Empty line or ad-hoc comment, ignore. ;;
+ *)
+ if test $what = LIST; then
+ files="$files $line"
+ elif test $what = NAME; then
+ name=$line
+ else
+ printf '%s\n' "$line" >> "$what"
+ fi
+ ;;
+ esac
+ done
+ test -n "$name" || fatal_ "name of a test case not specified"
+ if test $run_aclocal = yes; then
+ if $ACLOCAL; then
+ ok_ "[$name] aclocal.m4 rebuilt"
+ echo == aclocal.m4 ==
+ cat aclocal.m4
+ else
+ not_ok_ "[$name] aclocal failure, aclocal.m4 not rebuilt"
+ fi
+ else
+ cp "$ocwd"/aclocal.stub aclocal.m4
+ fi
+ echo == Makefile.am ==
+ cat Makefile.am
+ echo == configure.ac ==
+ cat configure.ac
+ echo Expected files: $files
+ mkdir "$build_aux"
+ cd ..
+ # End of "test scenario" setup.
+ set -x # Re-enable shell traces.
+ pwd
+ ls -l generic
+ # Test once with '--copy', once without.
+ for action in link copy; do
+ case $action in
+ link) opts='--add-missing';;
+ copy) opts='-a --copy';;
+ *) fatal_ "invalid value '$action' for \$action";;
+ esac
+ pfx="[$action $name]"
+ cp -R generic $action
+ cd $action
+ # If the required auxiliary files are missing, and automake is
+ # not told to install them, it should complain and error out,
+ # and also give a useful suggestion.
+ AUTOMAKE_fails -d "$pfx missing files, automake fails"
+ for f in $files; do
+ command_ok_ \
+ "$pfx warn about missing file $f" \
+ $FGREP "required file '$build_aux/$f' not found" stderr
+ # Suggest the user to use '--add-missing'.
+ command_ok_ \
+ "$pfx suggest --add-missing for $f" \
+ grep ".*--add-missing.* install .*'$f'" stderr
+ done
+ # No files should be automatically installed by automake if it
+ # is not told to.
+ if ls "$build_aux" | grep .; then r='not ok'; else r=ok; fi
+ result_ "$r" "$pfx no extra files installed"
+ AUTOMAKE_run -d "$pfx automake run successfully" -- $opts
+ ls -l . $build_aux
+ # The expected files should get installed correctly (e.g., no
+ # broken symlinks).
+ for f in $files; do
+ command_ok_ \
+ "$pfx file $f installed" \
+ test -f $build_aux/$f
+ done
+ # Automake should inform about which files it's installing.
+ for f in $files; do
+ command_ok_ \
+ "$pfx report installation of $f" \
+ $FGREP ": installing '$build_aux/$f'" stderr
+ done
+ # Only the expected files should be installed. But automake always
+ # require 'missing' and 'install-sh', so account for them.
+ all_files="install-sh missing $files"
+ for f in $all_files; do echo $f; done | sort | uniq > files.exp
+ (cd $build_aux && ls) | sort > files.got
+ cat files.exp
+ cat files.got
+ command_ok_ \
+ "$pfx all and only expected files installed" \
+ $am_diff files.exp files.got
+ # The files should be copied by '--copy' and symlinked otherwise.
+ # But these checks make no sense on systems like MSYS/MinGW where
+ # there are no true symlinks ('ln -s' behaves like 'cp -p'), so be
+ # ready to skip the checks in that case. See automake bug#10441.
+ for f in $files; do
+ if test $have_true_symlinks = no; then
+ skip_ -r "system lacks true symlinks" "$pfx $f is a symlink or not"
+ else
+ if test -h $build_aux/$f; then
+ is_symlink=yes
+ else
+ is_symlink=no
+ fi
+ case $action,$is_symlink in
+ link,yes) ok_ "$pfx $f has been symlinked" ;;
+ link,no) not_ok_ "$pfx $f has not been symlinked" ;;
+ copy,yes) not_ok_ "$pfx $f has been symlinked" ;;
+ copy,no) ok_ "$pfx $f has not been symlinked" ;;
+ *) fatal_ "invalid condition in case" ;;
+ esac
+ fi
+ done
+ # Now that the required auxiliary files have been installed, automake
+ # should not complain anymore even if the '--add-missing' option is
+ # not used.
+ AUTOMAKE_run -d "$pfx automake finds all added files"
+ cd ..
+ done # for action in link copy
+ cd "$ocwd" || fatal_ "cannot chdir back to top-level test directory"
+}
+
+# Automake should always and unconditionally require the 'missing'
+# and 'install-sh' scripts.
+check_ <<'END'
+== Name ==
+minimal
+== Files ==
+install-sh missing
+END
+
+check_ <<'END'
+== Name ==
+depcomp/C
+== Files ==
+depcomp
+compile
+== configure.ac ==
+AC_PROG_CC
+== Makefile.am ==
+bin_PROGRAMS = foo
+END
+
+check_ <<'END'
+== Name ==
+depcomp/C++
+== Files ==
+depcomp
+== configure.ac ==
+AC_PROG_CXX
+== Makefile.am ==
+bin_PROGRAMS = foo
+foo_SOURCES = foo.cc
+END
+
+check_ --run-aclocal <<'END'
+== Name ==
+compile
+== Files ==
+compile
+== configure.ac ==
+# Using AC_PROG_CC in configure.ac should be enough.
+# No need to also define, say, xxx_PROGRAMS in Makefile.am.
+AC_PROG_CC
+END
+
+# For config.guess and config.sub.
+for mach in build host target system; do
+ MACH=$(echo "$mach" | LC_ALL=C tr '[a-z]' '[A-Z]')
+ check_ <<END
+== Name ==
+cfg-$mach
+== Files ==
+config.sub
+config.guess
+== configure.ac ==
+AC_CANONICAL_$MACH
+END
+done
+
+check_ <<'END'
+== Name ==
+ylwrap/Lex
+== Files ==
+ylwrap
+compile
+== configure.ac ==
+AC_PROG_CC
+AC_PROG_LEX
+== Makefile.am ==
+AUTOMAKE_OPTIONS = no-dependencies
+bin_PROGRAMS = foo
+foo_SOURCES = foo.l
+END
+
+check_ <<'END'
+== Name ==
+ylwrap/Yacc
+== Files ==
+ylwrap
+compile
+== configure.ac ==
+AC_PROG_CC
+AC_PROG_YACC
+== Makefile.am ==
+AUTOMAKE_OPTIONS = no-dependencies
+bin_PROGRAMS = foo
+foo_SOURCES = foo.y
+END
+
+echo '@setfilename foo.info' > foo.texi
+check_ --fetch-file foo.texi <<'END'
+== Name ==
+Texinfo
+== Files ==
+texinfo.tex
+== Makefile.am ==
+info_TEXINFOS = foo.texi
+END
+
+echo '@include version.texi' >> foo.texi
+check_ --fetch-file foo.texi <<'END'
+== Name ==
+Texinfo/mdate-sh
+== Files ==
+mdate-sh
+texinfo.tex
+== Makefile.am ==
+info_TEXINFOS = foo.texi
+END
+
+rm -f foo.texi
+
+check_ <<'END'
+== Name ==
+py-compile
+== Files ==
+py-compile
+== configure.ac ==
+AM_PATH_PYTHON
+== Makefile.am ==
+python_PYTHON = foo.py
+END
+
+# Try few unrelated auxiliary scripts together.
+check_ <<'END'
+== Name ==
+misc
+== Files ==
+py-compile
+depcomp
+ylwrap
+config.sub
+config.guess
+== configure.ac ==
+AC_CANONICAL_BUILD
+AC_CANONICAL_HOST
+AC_PROG_CXX
+== Makefile.am ==
+PYTHON = python
+pythondir = $(prefix)/py
+YACC = bison -y
+bin_PROGRAMS = foo
+foo_SOURCES = bar.yxx baz.c++
+python_PYTHON = zardoz.py
+END
+
+:
diff --git a/t/all.sh b/t/all.sh
new file mode 100644
index 000000000..bb908940f
--- /dev/null
+++ b/t/all.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure several *-local's in a single rule work.
+
+. test-init.sh
+
+targets='all install-exec install-data uninstall'
+echo "$targets:" | sed -e 's/[ :]/-local&/g' > Makefile.am
+cat Makefile.am # For debugging.
+
+$ACLOCAL
+$AUTOMAKE
+
+for target in $targets; do
+ grep "${target}-local" Makefile.in # For debugging.
+ grep "${target}-am:.*${target}-local" Makefile.in
+done
+
+:
diff --git a/t/all2.sh b/t/all2.sh
new file mode 100644
index 000000000..a24e16cdc
--- /dev/null
+++ b/t/all2.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure all-local and other -local targets work correctly.
+
+. test-init.sh
+
+$ACLOCAL
+
+targets='all install-exec install-data uninstall'
+for target in $targets; do
+ : Doing $target
+ echo "${target}-local:" > Makefile.am
+ $AUTOMAKE
+ grep "${target}-local ${target}-local" Makefile.in && exit 1
+ grep "${target}-am:.*${target}-local" Makefile.in
+done
+
+:
diff --git a/t/alloca.sh b/t/alloca.sh
new file mode 100644
index 000000000..f5d654bdc
--- /dev/null
+++ b/t/alloca.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we complain if @ALLOCA@ is used without being set in configure.ac
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AM_PROG_AR
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = @ALLOCA@
+END
+
+: > alloca.c
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile\.am:1:.*define .*RANLIB.* add .*AC_PROG_RANLIB' stderr
+grep '^Makefile\.am:3:.*define .*ALLOCA.* add .*AC_FUNC_ALLOCA' stderr
+
+:
diff --git a/t/alloca2.sh b/t/alloca2.sh
new file mode 100644
index 000000000..cf05f9632
--- /dev/null
+++ b/t/alloca2.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we complain if @LTALLOCA@ is used without being set in configure.ac
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+END
+
+cat > Makefile.am << 'END'
+noinst_LTLIBRARIES = libtu.la
+libtu_la_SOURCES =
+libtu_la_LIBADD = @LTALLOCA@
+END
+
+: > alloca.c
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile\.am:1:.*define.*LIBTOOL.* add .*LT_INIT' stderr
+grep '^Makefile\.am:3:.*LTALLOCA' stderr
+
+:
diff --git a/t/alpha.sh b/t/alpha.sh
new file mode 100644
index 000000000..9fb704b59
--- /dev/null
+++ b/t/alpha.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure README-alpha is distributed when appropriate. Report from
+# Jim Meyering.
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([alpha], [1.0a])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = gnits
+SUBDIRS = sub
+check-local: distdir
+ test -f $(distdir)/README-alpha
+ test -f $(distdir)/sub/README
+ test ! -f $(distdir)/sub/README-alpha
+ : > works
+END
+
+mkdir sub
+cat > sub/Makefile.am << 'END'
+AUTOMAKE_OPTIONS = gnits
+END
+
+: > README-alpha
+: > sub/README-alpha
+: > sub/README
+
+# Gnits stuff.
+: > INSTALL
+: > NEWS
+: > README
+: > COPYING
+: > AUTHORS
+: > ChangeLog
+: > THANKS
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+# "make distdir" should fail because NEWS does not mention 1.0a
+run_make -E -e FAIL check
+grep 'NEWS not updated' stderr
+test ! -e works
+
+echo 'alpha 1.0a released' > NEWS
+$MAKE check
+test -f works
+
+:
diff --git a/t/alpha2.sh b/t/alpha2.sh
new file mode 100644
index 000000000..ca7d0177a
--- /dev/null
+++ b/t/alpha2.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another check for README-alpha support. This time it is requested
+# from configure.ac. Report from Akim Demaille.
+
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([alpha], [1.0b])
+AM_INIT_AUTOMAKE([readme-alpha])
+AC_CONFIG_FILES([Makefile sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+check-local: distdir
+ test -f $(distdir)/README-alpha
+ test -f $(distdir)/sub/README
+ test ! -f $(distdir)/sub/README-alpha
+ : > works
+END
+
+mkdir sub
+: > sub/Makefile.am
+
+: > README-alpha
+: > sub/README-alpha
+: > sub/README
+
+# Gnits stuff.
+: > INSTALL
+: > NEWS
+: > README
+: > COPYING
+: > AUTHORS
+: > ChangeLog
+: > THANKS
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE check
+test -f works
diff --git a/t/am-config-header.sh b/t/am-config-header.sh
new file mode 100644
index 000000000..af7d6226f
--- /dev/null
+++ b/t/am-config-header.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the obsolete macro AM_CONFIG_HEADER still works.
+
+. test-init.sh
+
+cat > Makefile.am <<'END'
+check-local:
+ test -f oldconf.h
+ test -f $(srcdir)/oldconf.in
+END
+
+cat >> configure.ac <<'END'
+AM_CONFIG_HEADER([oldconf.h:oldconf.in])
+AC_OUTPUT
+END
+
+$ACLOCAL -Wno-obsolete
+
+$AUTOCONF -Werror -Wall 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep "^configure\.ac:4:.*'AM_CONFIG_HEADER'.*obsolete" stderr
+grep "'AC_CONFIG_HEADERS'.* instead" stderr
+
+$AUTOCONF -Werror -Wall -Wno-obsolete
+
+$AUTOHEADER
+test -f oldconf.in
+
+$AUTOMAKE
+
+./configure
+$MAKE check-local
+$MAKE distcheck
+
+:
diff --git a/t/am-default-source-ext.sh b/t/am-default-source-ext.sh
new file mode 100644
index 000000000..082c7a1fb
--- /dev/null
+++ b/t/am-default-source-ext.sh
@@ -0,0 +1,87 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# AM_DEFAULT_SOURCE_EXT
+
+required='cc c++'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_CONFIG_FILES([sub/Makefile sub2/Makefile])
+AM_CONDITIONAL([COND], [:])
+AC_OUTPUT
+END
+
+mkdir sub sub2
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub sub2
+bin_PROGRAMS = foo
+END
+
+cat > sub/Makefile.am << 'END'
+bin_PROGRAMS = bar baz
+AM_DEFAULT_SOURCE_EXT = .cpp
+END
+
+cat > sub2/Makefile.am << 'END'
+bin_PROGRAMS = bla
+if COND
+AM_DEFAULT_SOURCE_EXT = .foo .quux
+endif
+SUFFIXES = .foo .c
+.foo.c:
+ cat $< >$@
+BUILT_SOURCES = bla.c
+CLEANFILES = bla.c
+END
+
+cat > foo.c << 'END'
+int main () { return 0; }
+END
+
+cp foo.c sub/bar.cpp
+cp foo.c sub/baz.cpp
+cp foo.c sub2/bla.foo
+
+$ACLOCAL
+$AUTOCONF
+
+# Conditional AM_DEFAULT_SOURCE_EXT does not work yet :-(
+# (this limitation could be lifted).
+AUTOMAKE_fails --add-missing
+grep 'defined conditionally' stderr
+
+sed '/^if/d; /^endif/d' sub2/Makefile.am > t
+mv -f t sub2/Makefile.am
+
+# AM_DEFAULT_SOURCE_EXT can only assume one value
+# (lifting this limitation is not such a good idea).
+AUTOMAKE_fails --add-missing
+grep 'at most one value' stderr
+
+sed 's/ \.quux//' sub2/Makefile.am > t
+mv -f t sub2/Makefile.am
+
+$AUTOMAKE --add-missing
+
+./configure
+$MAKE
+$MAKE distcheck
+
+:
diff --git a/t/am-include-only-one-generated-fragment.sh b/t/am-include-only-one-generated-fragment.sh
new file mode 100644
index 000000000..99c8cb85a
--- /dev/null
+++ b/t/am-include-only-one-generated-fragment.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2014-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that inclusion of only one '.am' that can be regenerated via
+# a user-defined Makefile rule does not incur in spurious automake
+# warnings about "target redefinition".
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+include foobar.am
+$(srcdir)/foobar.am: $(srcdir)/touch.sh
+ $(SHELL) $(srcdir)/touch.sh $(srcdir)/foobar.am
+EXTRA_DIST = touch.sh
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+include $(top_srcdir)/quux.am
+$(top_srcdir)/quux.am: $(top_srcdir)/touch.sh
+ $(SHELL) $(top_srcdir)/touch.sh $@
+END
+
+: > foobar.am
+: > quux.am
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/am-macro-not-found.sh b/t/am-macro-not-found.sh
new file mode 100644
index 000000000..e5480d992
--- /dev/null
+++ b/t/am-macro-not-found.sh
@@ -0,0 +1,25 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to see if aclocal correctly reports missing AM_ macro.
+
+. test-init.sh
+
+echo AM_ZARDOZ >> configure.ac
+
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr
+grep 'configure.ac:.*AM_ZARDOZ.*not found' stderr
diff --git a/t/am-missing-prog.sh b/t/am-missing-prog.sh
new file mode 100644
index 000000000..59a61b24d
--- /dev/null
+++ b/t/am-missing-prog.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test AM_MISSING_PROG.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AM_MISSING_PROG([NO_SUCH_COMMAND], [am-none-none])
+AM_MISSING_PROG([MISMATCHED_COMMAND], [am-exit-63])
+AM_MISSING_PROG([OVERRIDDEN_COMMAND], [am-none-none])
+AM_MISSING_PROG([COMMAND_FOUND], [my-command])
+AC_OUTPUT
+END
+
+mkdir bin
+cat > bin/am-exit-63 <<'END'
+#!/bin/sh
+echo "Oops, I'm too old"
+exit 63
+END
+cat > bin/am-overridden <<'END'
+#!/bin/sh
+echo "Hey, I'm OK!"
+exit 0
+END
+cat > bin/my-command <<'END'
+#!/bin/sh
+echo SNAFU
+exit 0
+END
+chmod a+x bin/*
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
+
+cat > Makefile.am <<'END'
+# Different for different targets, for the sake of parallel make.
+o = $@-stdout
+e = $@-stderr
+
+debug_info = grep . $@-stdout $@-stderr
+status_is = $(debug_info); echo $@: st=$$st; test $$st -eq
+
+w_mis = 'am-none-none' is needed, and is missing on your system
+w_old = 'am-exit-63' is needed, and is probably too old
+
+test1:
+ st=0; $(NO_SUCH_COMMAND) >$o 2>$e || st=$$?; $(status_is) 127
+ grep "^WARNING: $(w_mis)" $e
+ test ! -s $o
+test2:
+ st=0; $(MISMATCHED_COMMAND) >$o 2>$e || st=$$?; $(status_is) 63
+ grep "^WARNING: $(w_old)" $e
+ test "`cat $o`" = "Oops, I'm too old"
+test3:
+ st=0; $(OVERRIDDEN_COMMAND) >$o 2>$e || st=$$?; $(status_is) 0
+ st=0; $(OVERRIDDEN_COMMAND) >$o 2>$e || st=$$?; \
+ test ! -s $e
+ test "`cat $o`" = "Hey, I'm OK!"
+test4:
+ st=0; $(COMMAND_FOUND) >$o 2>$e || st=$$?; $(status_is) 0
+ test ! -s $e
+ test "`cat $o`" = SNAFU
+check-local: test1 test2 test2 test4
+.PHONY: test1 test2 test2 test4
+CLEANFILES = test[1234]-stdout test[1234]-stderr
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure OVERRIDDEN_COMMAND=am-overridden
+
+$FGREP COMMAND Makefile.in Makefile # For debugging.
+
+grep "^NO_SUCH_COMMAND = \${SHELL} .*/missing .*am-none-none" Makefile
+grep "^MISMATCHED_COMMAND = \${SHELL} .*/missing .*am-exit-63" Makefile
+grep "^COMMAND_FOUND = \${SHELL} .*/missing .*my-command" Makefile
+grep '^OVERRIDDEN_COMMAND = am-overridden *$' Makefile
+
+$MAKE test1 test2 test3 test4
+$MAKE distcheck DISTCHECK_CONFIGURE_FLAGS='OVERRIDDEN_COMMAND=am-overridden'
+
+:
diff --git a/t/am-prog-cc-c-o.sh b/t/am-prog-cc-c-o.sh
new file mode 100644
index 000000000..74e973214
--- /dev/null
+++ b/t/am-prog-cc-c-o.sh
@@ -0,0 +1,126 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that uses of the obsolescent AM_PROG_CC_C_O macro doesn't
+# cause spurious warnings or errors. Suggested by Eric Blake.
+
+# We need gcc for for two reasons:
+# 1. to ensure our C compiler grasps "-c -o" together.
+# 2. to be able to later fake a dumb compiler not grasping that
+# (done with 'cc-no-c-o' script below, which required gcc).
+required=gcc
+. test-init.sh
+
+echo bin_PROGRAMS = foo > Makefile.am
+echo 'int main (void) { return 0; }' > foo.c
+
+cp configure.ac configure.bak
+
+cat > acinclude.m4 <<'END'
+AC_DEFUN([AM_TWEAKED_OUTPUT], [
+# For debugging.
+printf "CC = '%s'\\n" "$CC"
+# Make sure that $CC can be used after AM_PROG_CC_C_O.
+$CC --version || exit 1
+$CC -v || exit 1
+# $CC rewrite should only take place on time.
+case " $CC " in
+ *" compile"*" compile"*) AC_MSG_ERROR([CC rewritten twice]);;
+esac
+AC_OUTPUT
+])
+END
+
+# ---
+
+cat configure.bak - > configure.ac << 'END'
+dnl It's OK to call AM_PROG_CC_C_O after AC_PROG_CC.
+AC_PROG_CC
+AM_PROG_CC_C_O
+AM_TWEAKED_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure >stdout || { cat stdout; exit 1; }
+cat stdout
+if test "$AM_TESTSUITE_SIMULATING_NO_CC_C_O" != no; then
+ $EGREP 'understands? -c and -o together.* no$' stdout
+else
+ $EGREP 'understands? -c and -o together.* yes$' stdout
+fi
+
+# No repeated checks please.
+test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
+
+$MAKE
+$MAKE maintainer-clean
+rm -rf autom4te*.cache
+
+# ---
+
+cat configure.bak - > configure.ac << 'END'
+dnl It's also OK to call AM_PROG_CC_C_O *before* AC_PROG_CC.
+AM_PROG_CC_C_O
+AC_PROG_CC
+AM_TWEAKED_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure >stdout || { cat stdout; exit 1; }
+cat stdout
+if test "$AM_TESTSUITE_SIMULATING_NO_CC_C_O" != no; then
+ $EGREP 'understands? -c and -o together.* no$' stdout
+else
+ $EGREP 'understands? -c and -o together.* yes$' stdout
+fi
+
+# Repeated checks are OK in this case, but should be cached.
+test $(grep ".*-c['\" ].*-o['\" ]" stdout \
+ | $FGREP -v ' (cached) ' | wc -l) -eq 1
+
+$MAKE
+$MAKE maintainer-clean
+rm -rf autom4te*.cache
+
+# ---
+
+cat configure.bak - > configure.ac << 'END'
+dnl It's also OK to call AM_PROG_CC_C_O *without* AC_PROG_CC.
+AM_PROG_CC_C_O
+AM_TWEAKED_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+# Make sure the compiler doesn't understand '-c -o'
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+./configure >stdout || { cat stdout; exit 1; }
+cat stdout
+$EGREP 'understands? -c and -o together.* no$' stdout
+# No repeated checks please.
+test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
+$MAKE
+
+:
diff --git a/t/am-prog-cc-stdc.sh b/t/am-prog-cc-stdc.sh
new file mode 100644
index 000000000..4f01f70ec
--- /dev/null
+++ b/t/am-prog-cc-stdc.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the obsolete macro the obsolete macro AM_PROG_CC_STDC
+# still works.
+
+required=gcc
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AM_PROG_CC_STDC
+AC_OUTPUT
+END
+
+echo bin_PROGRAMS = foo > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+$AUTOCONF -Wnone -Wobsolete -Werror 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep "^configure\.ac:4:.*'AM_PROG_CC_STDC'.*obsolete" stderr
+grep "'AC_PROG_CC'.* instead" stderr
+
+echo 'int main (void) { return 0; }' > foo.c
+
+./configure
+$MAKE
+$MAKE distcheck
+
+:
diff --git a/t/am-prog-mkdir-p.sh b/t/am-prog-mkdir-p.sh
new file mode 100644
index 000000000..a99dd5aa2
--- /dev/null
+++ b/t/am-prog-mkdir-p.sh
@@ -0,0 +1,90 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the AM_PROG_MKDIR_P macro is deprecated, but still works.
+# We should should also still define $(mkdir_p), for backward
+# compatibility.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AM_PROG_MKDIR_P
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+all-local:
+ $(MKDIR_P) . dir1/a
+ $(mkdir_p) . dir2/b
+ @MKDIR_P@ . dir3/c
+ @mkdir_p@ . dir4/d
+check-local: all
+ test -d dir1/a
+ test -d dir2/b
+ test -d dir3/c
+ test -d dir4/d
+ test -d dir5/e
+ test -d dir5/f
+ test -d dir5/g
+END
+
+mkdir sub
+cat > sub/Makefile.am << 'END'
+# Even '$(mkdir_p)' should continue to work also in subdir makefiles.
+all-local:
+ $(MKDIR_P) .. ../dir5/d
+ $(mkdir_p) .. ../dir5/e
+ @MKDIR_P@ .. ../dir5/f
+ @mkdir_p@ .. ../dir5/g
+END
+
+$ACLOCAL
+$AUTOCONF -Wnone -Wobsolete -Werror 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep "^configure\\.ac:5:.*'AM_PROG_MKDIR_P'.*deprecated" stderr
+grep "[Aa]utoconf-provided 'AC_PROG_MKDIR_P'.* instead" stderr
+grep "'\$(MKDIR_P)' instead of '\$(mkdir_p)'" stderr
+
+$AUTOCONF -Wno-obsolete
+$AUTOMAKE
+
+./configure
+$MAKE check-local
+$MAKE distcheck
+
+# Now try using AC_PROG_MKDIR_P, but keeping the occurrences of
+# $(mkdir_p) and @mkdir_p@. This is to check against a regression
+# that hit us with Gettext 0.18.2.
+$MAKE maintainer-clean
+rm -rf autom4te*.cache
+
+sed 's/AM_PROG_MKDIR/AC_PROG_MKDIR/' configure.ac > t
+diff configure.ac t && fatal_ "failed to edit configure.ac"
+mv -f t configure.ac
+
+$ACLOCAL 2>stderr \
+ && $AUTOCONF -Wall -Werror 2>>stderr \
+ && test ! -s stderr \
+ || { cat stderr >&2; exit 1; }
+
+$AUTOMAKE
+./configure
+$MAKE check-local
+$MAKE distcheck
+
+:
diff --git a/t/am-tests-environment.sh b/t/am-tests-environment.sh
new file mode 100644
index 000000000..1e900ae02
--- /dev/null
+++ b/t/am-tests-environment.sh
@@ -0,0 +1,90 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests: check AM_TESTS_ENVIRONMENT support, and its
+# interactions with TESTS_ENVIRONMENT.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_MKDIR_P
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_EXTENSIONS = .sh .test
+TESTS = foo.test bar.sh
+SH_LOG_COMPILER = sh
+AM_TESTS_ENVIRONMENT = \
+ $(MKDIR_P) quux.dir; \
+ if test -f $(srcdir)/test-env.sh; then \
+ . $(srcdir)/test-env.sh; \
+ fi; \
+ FOO=1; export FOO;
+EXTRA_DIST = $(TESTS) test-env.sh
+END
+
+cat > foo.test << 'END'
+#! /bin/sh
+ls -l && test -d quux.dir
+END
+chmod a+x foo.test
+
+cat > bar.sh << 'END'
+echo "FOO='$FOO'"
+echo "BAR='$BAR'"
+test x"$FOO" = x"$BAR"
+END
+
+debug_info ()
+{
+ cat test-suite.log
+ cat foo.log
+ cat bar.log
+}
+
+minicheck ()
+{
+ debug_info
+ test -d quux.dir
+}
+
+miniclean ()
+{
+ rmdir quux.dir
+ rm -f foo.log bar.log test-suite.log
+}
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+TESTS_ENVIRONMENT='BAR=1' $MAKE check || { debug_info; exit 1; }
+minicheck
+miniclean
+
+TESTS_ENVIRONMENT='BAR=2' $MAKE check && { debug_info; exit 1; }
+minicheck
+miniclean
+
+echo 'BAR=1 && export BAR' > test-env.sh
+$MAKE check || { debug_info; exit 1; }
+minicheck
+$MAKE distcheck
+
+:
diff --git a/t/amassign.sh b/t/amassign.sh
new file mode 100644
index 000000000..76c2c58b0
--- /dev/null
+++ b/t/amassign.sh
@@ -0,0 +1,28 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to see if AM_ name can be assigned to in configure.ac.
+# Report from Steve Robbins.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CFLAGS=foo
+AC_SUBST(AM_BAR)
+AC_SUBST([AM_ZARDOZ])
+END
+
+$ACLOCAL
diff --git a/t/amhello-binpkg.sh b/t/amhello-binpkg.sh
new file mode 100644
index 000000000..7f4ad58d7
--- /dev/null
+++ b/t/amhello-binpkg.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test an example from the manual about the 'amhello' package:
+# using DESTDIR to build simple, no-frills binary packages.
+
+am_create_testdir=empty
+. test-init.sh
+
+cp "$am_docdir"/amhello-1.0.tar.gz . \
+ || fatal_ "cannot get amhello tarball"
+
+gzip -dc amhello-1.0.tar.gz | tar xf -
+cd amhello-1.0
+
+./configure --prefix /usr
+$MAKE
+$MAKE DESTDIR="$(pwd)/inst" install
+cd inst
+find . -type f -print > ../files.lst
+tar cvf amhello-1.0-i686.tar.gz $(cat ../files.lst) > tar.got 2>&1
+
+EXEEXT=$(sed -n -e 's/^EXEEXT *= *//p' < ../Makefile)
+
+if tar --version </dev/null | grep GNU; then
+ LC_ALL=C sort tar.got > t
+ mv -f t tar.got
+ diff - tar.got <<END
+./usr/bin/hello$EXEEXT
+./usr/share/doc/amhello/README
+END
+else
+ : Be laxer with other tar implementations, to avoid spurious failures.
+ $EGREP '(^| )(\./)?usr/bin/hello'$EXEEXT'( |$)' tar.got
+ $EGREP '(^| )(\./)?usr/share/doc/amhello/README( |$)' tar.got
+fi
+
+:
diff --git a/t/amhello-cflags.sh b/t/amhello-cflags.sh
new file mode 100644
index 000000000..a5bc7dbfd
--- /dev/null
+++ b/t/amhello-cflags.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test an example from the manual about the 'amhello' package:
+# using VPATH builds to configure the same package with different
+# options.
+
+am_create_testdir=empty
+required=gcc
+. test-init.sh
+
+cp "$am_docdir"/amhello-1.0.tar.gz . \
+ || fatal_ "cannot get amhello tarball"
+
+gzip -dc amhello-1.0.tar.gz | tar xf -
+cd amhello-1.0
+
+mkdir debug optim
+cd debug
+../configure CFLAGS='-g -O0'
+$MAKE
+ls -l . src # For debugging.
+cd ../optim
+../configure CFLAGS='-O3 -fomit-frame-pointer'
+$MAKE
+ls -l . src # For debugging.
+cd ..
+
+# Check that we have really compiled the objects with two different
+# configurations.
+for exeext in '' .exe :; do
+ test -f optim/src/hello$exeext && break
+ test "$exeext" = : && fatal_ "cannot determine extension of executables"
+done
+cmp optim/src/hello$exeext debug/src/hello$exeext && exit 1
+
+:
diff --git a/t/amhello-cross-compile.sh b/t/amhello-cross-compile.sh
new file mode 100644
index 000000000..7bc91c90e
--- /dev/null
+++ b/t/amhello-cross-compile.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test an example from the manual about the 'amhello' package:
+# cross-compiling a package from Linux/Unix to MinGW.
+
+am_create_testdir=empty
+required=i586-mingw32msvc-gcc
+. test-init.sh
+
+cp "$am_docdir"/amhello-1.0.tar.gz . \
+ || fatal_ "cannot get amhello tarball"
+
+host=i586-mingw32msvc
+build=$("$am_scriptdir"/config.guess) && test -n "$build" \
+ || fatal_ "cannot guess build platform"
+case $build in *mingw*) skip_ "build system is MinGW too";; esac
+
+gzip -dc amhello-1.0.tar.gz | tar xf -
+cd amhello-1.0
+
+./configure --build "$build" --host "$host" > stdout \
+ || { cat stdout ; exit 1; }
+cat stdout
+grep '^checking for i586-mingw32msvc-strip\.\.\.' stdout
+grep '^checking for i586-mingw32msvc-gcc\.\.\.' stdout
+grep '^checking for suffix of executables\.\.\. \.exe *$' stdout
+grep '^checking for suffix of object files\.\.\. o *$' stdout
+grep '^checking whether i586-mingw32msvc-gcc accepts -g\.\.\. yes' stdout
+
+$MAKE
+
+cd src
+file hello.exe > whatis
+cat whatis
+$EGREP 'DOS|Win' whatis
+grep 'executable' whatis
+grep 'ELF' whatis && exit 1
+
+:
diff --git a/t/aminit-moreargs-deprecation.sh b/t/aminit-moreargs-deprecation.sh
new file mode 100644
index 000000000..64aa18509
--- /dev/null
+++ b/t/aminit-moreargs-deprecation.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake warns against old-style usages of AM_INIT_AUTOMAKE
+# (i.e., calls with two or three arguments).
+
+. test-init.sh
+
+warn_rx='AM_INIT_AUTOMAKE.* two-.* three-arguments form.*deprecated'
+
+cat > configure.ac <<'END'
+AC_INIT([Makefile.am])
+AM_INIT_AUTOMAKE([twoargs], [1.0])
+AC_CONFIG_FILES([Makefile])
+END
+
+$ACLOCAL
+
+do_check()
+{
+ rm -rf autom4te*.cache
+ for cmd in "$AUTOCONF" "$AUTOMAKE"; do
+ $cmd -Werror -Wnone -Wobsolete 2>stderr && { cat stderr; exit 1; }
+ cat stderr >&2
+ grep "^configure\.ac:2:.*$warn_rx" stderr
+ $cmd -Werror -Wall -Wno-obsolete || exit 1
+ done
+}
+
+: > Makefile.am
+do_check
+
+sed "/^AM_INIT_AUTOMAKE/s|)$|, [NODEFINE])|" configure.ac > t
+diff configure.ac t && fatal_ "failed to edit configure.ac"
+mv -f t configure.ac
+do_check
+
+:
diff --git a/t/aminit-trailing-dnl-comment-pr16841.sh b/t/aminit-trailing-dnl-comment-pr16841.sh
new file mode 100644
index 000000000..aa5c2e0a5
--- /dev/null
+++ b/t/aminit-trailing-dnl-comment-pr16841.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2014-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that a trailing 'dnl' m4 comment automake after the
+# AM_INIT_AUTOMAKE invocation doesn't produce a syntactically
+# invalid configure script. This used to be the case until
+# automake 1.13, but we broke that in automake 1.14. See
+# automake bug#16841.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([test-pr16841], [1.0])
+AM_INIT_AUTOMAKE([1.14 -Werror]) dnl Some comment
+echo "OK OK OK"
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure >stdout || { cat stdout; exit 1; }
+cat stdout
+grep '^OK OK OK$' stdout
+
+:
diff --git a/t/amopt.sh b/t/amopt.sh
new file mode 100644
index 000000000..28042462e
--- /dev/null
+++ b/t/amopt.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make Automake diagnose a conditional AUTOMAKE_OPTIONS.
+# Report from Bas Wijnen.
+
+. test-init.sh
+
+cat >>configure.ac <<END
+AM_CONDITIONAL([COND], [true])
+END
+
+mkdir sub
+
+cat >Makefile.am <<END
+if COND
+AUTOMAKE_OPTIONS = -Wall
+endif
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile\.am:2.*AUTOMAKE_OPTIONS.*conditional' stderr
+
+:
diff --git a/t/amopts-location.sh b/t/amopts-location.sh
new file mode 100644
index 000000000..39a30c3c3
--- /dev/null
+++ b/t/amopts-location.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that errors about AUTOMAKE_OPTIONS refers to correct
+# locations.
+
+. test-init.sh
+
+cat > Makefile.am <<'END'
+# comment \
+# continued
+include Makefile0.am
+END
+
+cat > Makefile0.am <<'END'
+#1
+#2
+#3
+include Makefile1.am
+END
+
+cat > Makefile1.am <<'END'
+AUTOMAKE_OPTIONS = tar-pax
+# comment
+END
+
+cat > Makefile2.am <<'END'
+## automake comment
+bar:
+ :
+line = \
+continued
+AUTOMAKE_OPTIONS = tar-ustar
+END
+
+cat > Makefile3.am <<'END'
+quux = a
+AUTOMAKE_OPTIONS =
+quux += b
+AUTOMAKE_OPTIONS += tar-v7
+zardoz = 1
+END
+
+cat >>configure.ac <<'END'
+AC_CONFIG_FILES([Makefile2 Makefile3])
+END
+
+$ACLOCAL
+# Automake options 'tar-v7', 'tar-ustar' and 'tar-pax' can only be used
+# as argument to AM_INIT_AUTOMAKE, and not in AUTOMAKE_OPTIONS.
+AUTOMAKE_fails
+
+# Check that all the expected line numbers are correctly reported
+# in automake warning/error messages.
+grep '^Makefile1\.am:1:.*tar-pax' stderr
+grep '^Makefile2\.am:6:.*tar-ustar' stderr
+grep '^Makefile3\.am:2:.*tar-v7' stderr
+grep '^Makefile\.am:3:.*Makefile0\.am.*included from here' stderr
+grep '^Makefile0\.am:4:.*Makefile1\.am.*included from here' stderr
+
+# And also check that no botched line number is reported.
+cat stderr \
+ | grep -v '^Makefile\.am:3:' \
+ | grep -v '^Makefile0\.am:4:' \
+ | grep -v '^Makefile1\.am:1:' \
+ | grep -v '^Makefile2\.am:6:' \
+ | grep -v '^Makefile3\.am:2:' \
+ | grep . && exit 1
+
+:
diff --git a/t/amopts-variable-expansion.sh b/t/amopts-variable-expansion.sh
new file mode 100644
index 000000000..0a4a767ff
--- /dev/null
+++ b/t/amopts-variable-expansion.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that AUTOMAKE_OPTIONS support variable expansion.
+
+. test-init.sh
+
+# We want complete control over automake options.
+AUTOMAKE=$am_original_AUTOMAKE
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([-Wall -Werror gnu])
+AC_CONFIG_FILES([Makefile])
+END
+
+cat > Makefile.am <<'END'
+# The following should expand to '-Wnone -Wno-error foreign -Wportability'.
+AUTOMAKE_OPTIONS = $(foo) foreign
+AUTOMAKE_OPTIONS += ${bar}
+foo = $(foo1)
+foo1 = ${foo2}
+foo2 = -Wnone
+foo2 += $(foo3)
+foo3 = -Wno-error
+bar = -Wportability
+# This will give a warning with '-Wportability'.
+zardoz :=
+# This would give a warning with '-Woverride'.
+install:
+END
+
+$ACLOCAL
+AUTOMAKE_run
+grep '^Makefile\.am:.*:=.*not portable' stderr
+grep README stderr && exit 1
+$EGREP '(install|override)' stderr && exit 1
+
+:
diff --git a/t/amsubst.sh b/t/amsubst.sh
new file mode 100644
index 000000000..800e99b71
--- /dev/null
+++ b/t/amsubst.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for _AM_SUBST_NOTMAKE.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([backslash], "\\")
+_AM_SUBST_NOTMAKE([backslash])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+test:
+ @echo $(backslash) @backslash@$$
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+# If _AM_SUBST_NOTMAKE is not honored, the backslash
+# variable will not be empty.
+$MAKE test | grep '^[$]$'
diff --git a/t/ansi2knr-no-more.sh b/t/ansi2knr-no-more.sh
new file mode 100644
index 000000000..a3436750c
--- /dev/null
+++ b/t/ansi2knr-no-more.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that any attempt to use the obsolete de-ANSI-fication support
+# is diagnosed.
+
+. test-init.sh
+
+warn_rx='automatic de-ANSI-fication.*removed'
+
+echo AC_PROG_CC >> configure.ac
+$ACLOCAL
+mv aclocal.m4 aclocal.sav
+cp configure.ac configure.sav
+
+echo AM_C_PROTOTYPES >> configure.ac
+
+$ACLOCAL -Wnone 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep "^configure\\.ac:5:.*$warn_rx" stderr
+
+cat aclocal.sav "$am_top_srcdir"/m4/obsolete.m4 > aclocal.m4
+$AUTOCONF -Wnone 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep "^configure\\.ac:5:.*$warn_rx" stderr
+
+for opt in ansi2knr lib/ansi2knr; do
+ # ansi2knr option in Makefile.am
+ cp configure.sav configure.ac
+ echo "AUTOMAKE_OPTIONS = $opt" > Makefile.am
+ rm -rf autom4te*.cache
+ AUTOMAKE_fails -Wnone
+ grep "^Makefile\.am:1:.*$warn_rx" stderr
+ # ansi2knr option in configure.ac
+ : > Makefile.am
+ sed "s|^\\(AM_INIT_AUTOMAKE\\).*|\1([$opt])|" configure.sav >configure.ac
+ cat configure.ac # For debugging.
+ rm -rf autom4te*.cache
+ AUTOMAKE_fails -Wnone
+ grep "^configure\\.ac:2:.*$warn_rx" stderr
+done
+
+:
diff --git a/t/ar-lib.sh b/t/ar-lib.sh
new file mode 100644
index 000000000..02d059deb
--- /dev/null
+++ b/t/ar-lib.sh
@@ -0,0 +1,113 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'ar-lib' wraps the Microsoft Library Manager (lib) correctly.
+
+am_create_testdir=empty
+required=xsi-lib-shell
+. test-init.sh
+
+get_shell_script ar-lib
+
+# Use a dummy lib, since lib isn't readily available on all systems.
+cat >lib <<'END'
+#! /bin/sh
+if test x"$2" = x-LIST && test x"$3" = xfake.lib; then
+ echo fake.obj
+elif test x"$2" = x-LIST && test x"$3" = xfake2.lib; then
+ printf "%s\n" "dir\\fake2.obj"
+else
+ printf "%s\n" "lib $*"
+fi
+END
+
+chmod +x ./lib
+
+# Check if ar-lib can create an archive with "cr".
+opts=$(./ar-lib ./lib cr foo.lib foo.obj)
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.obj"
+
+# Check if ar-lib can update an existing archive with "r".
+touch foo.lib
+opts=$(./ar-lib ./lib r foo.lib foo.obj)
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.lib foo.obj"
+
+# Check if ar-lib can update an existing archive with "q".
+opts=$(./ar-lib ./lib q foo.lib foo.obj)
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.lib foo.obj"
+
+# Check if ar-lib accepts "u" as a modifier.
+# NOTE: "u" should have an effect, but currently doesn't.
+opts=$(./ar-lib ./lib ru foo.lib foo.obj)
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.lib foo.obj"
+
+# Check if ar-lib accepts "s" as a modifier.
+opts=$(./ar-lib ./lib rs foo.lib foo.obj)
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.lib foo.obj"
+
+# Check if ar-lib accepts "S" as a modifier.
+opts=$(./ar-lib ./lib rS foo.lib foo.obj)
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.lib foo.obj"
+
+# Check if ar-lib passes on @FILE with "r"
+opts=$(./ar-lib ./lib r foo.lib @list)
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.lib @list"
+
+# Check if ar-lib can delete a member from an archive with "d".
+opts=$(./ar-lib ./lib d foo.lib foo.obj)
+test x"$opts" = x"lib -NOLOGO -REMOVE:foo.obj foo.lib"
+
+# Check if ar-lib can delete members in an @FILE.
+echo foo.obj > foolist
+opts=$(./ar-lib ./lib d foo.lib @foolist)
+test x"$opts" = x"lib -NOLOGO -REMOVE:foo.obj foo.lib"
+
+# Check if ar-lib can list archive members with "t".
+opts=$(./ar-lib ./lib t foo.lib)
+test x"$opts" = x"lib -NOLOGO -LIST foo.lib"
+
+# Check if ar-lib accepts "v" as a modifier.
+# NOTE: "v" should have an effect, but currently doesn't.
+opts=$(./ar-lib ./lib tv foo.lib)
+test x"$opts" = x"lib -NOLOGO -LIST foo.lib"
+
+# Check if ar-lib can extract archive members with "x".
+touch fake.lib
+opts=$(./ar-lib ./lib x fake.lib)
+test x"$opts" = x"lib -NOLOGO -EXTRACT:fake.obj fake.lib"
+
+# Check if ar-lib can extract specified archive members with "x".
+opts=$(./ar-lib ./lib x foo.lib foo.obj)
+test x"$opts" = x"lib -NOLOGO -EXTRACT:foo.obj foo.lib"
+
+# Check if ar-lib can extract members in an @FILE.
+opts=$(./ar-lib ./lib x foo.lib @foolist)
+test x"$opts" = x"lib -NOLOGO -EXTRACT:foo.obj foo.lib"
+
+# Check if ar-lib passes -lib and -LTCG through to the wrappee.
+opts=$(./ar-lib ./lib -lib -LTCG x foo.lib foo.obj)
+test x"$opts" = x"lib -lib -LTCG -NOLOGO -EXTRACT:foo.obj foo.lib"
+
+# Check if ar-lib can extract backslashed members.
+touch fake2.lib
+opts=$(./ar-lib ./lib x fake2.lib)
+test x"$opts" = x"lib -NOLOGO -EXTRACT:dir\\fake2.obj fake2.lib"
+
+# Check if ar-lib accepts "s" as an action.
+opts=$(./ar-lib ./lib s foo.lib)
+test x"$opts" = x
+
+:
diff --git a/t/ar-lib2.sh b/t/ar-lib2.sh
new file mode 100644
index 000000000..212123a1b
--- /dev/null
+++ b/t/ar-lib2.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test if AM_PROG_AR installs ar-lib.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = wish
+wish_SOURCES = a.c
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+# Make sure ar-lib is installed, and that Automake says so.
+grep '^configure\.ac:.*install.*ar-lib' stderr
+test -f ar-lib
+
+:
diff --git a/t/ar-lib3.sh b/t/ar-lib3.sh
new file mode 100644
index 000000000..5392f734b
--- /dev/null
+++ b/t/ar-lib3.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test if lib_LIBRARIES requests AM_PROG_AR.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+END
+
+cat > Makefile.am << 'END'
+lib_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+
+grep 'requires.*AM_PROG_AR' stderr
+
+cat >> configure.ac << 'END'
+AM_PROG_AR
+END
+
+rm -rf autom4te*.cache
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+:
diff --git a/t/ar-lib4.sh b/t/ar-lib4.sh
new file mode 100644
index 000000000..b7f45fd98
--- /dev/null
+++ b/t/ar-lib4.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test if lib_LTLIBRARIES requests AM_PROG_AR.
+
+required=libtoolize
+. test-init.sh
+
+cp configure.ac X
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = foo.c
+END
+
+libtoolize
+$ACLOCAL
+AUTOMAKE_fails
+
+grep 'requires.*AM_PROG_AR' stderr
+
+rm -rf autom4te*.cache
+
+cp X configure.ac
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+:
diff --git a/t/ar-lib5a.sh b/t/ar-lib5a.sh
new file mode 100644
index 000000000..11de4b267
--- /dev/null
+++ b/t/ar-lib5a.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test if AM_PROG_AR triggers the use of the ar-lib script.
+# This test requires Microsoft lib.
+# Keep this test in sync with sister test 'ar-lib5b.sh'.
+
+required=lib
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([auxdir])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+# We want to test the content of am_cv_ar_interface in the Makefile.
+AC_SUBST([am_cv_ar_interface])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LIBRARIES = libwish.a
+libwish_a_SOURCES = wish.c
+
+check-local:
+ test x'$(am_cv_ar_interface)' = x'lib'
+ test -f ar-lib-worked
+ test -f libwish.a
+MOSTLYCLEANFILES = ar-lib-worked
+END
+
+cat > wish.c << 'END'
+int wish(void) { return 0; }
+END
+
+mkdir auxdir
+cat - "$am_scriptdir/ar-lib" > auxdir/ar-lib << 'END'
+#! /bin/sh
+:> ar-lib-worked
+END
+chmod +x auxdir/ar-lib
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+# Sanity check: test that it is ok to use 'am_cv_ar_interface' as we do.
+$FGREP 'am_cv_ar_interface=' configure
+
+./configure AR=lib RANLIB=:
+
+$MAKE check
+$MAKE distcheck DISTCHECK_CONFIGURE_FLAGS='AR=lib RANLIB=:'
+
+:
diff --git a/t/ar-lib5b.sh b/t/ar-lib5b.sh
new file mode 100644
index 000000000..d7a9dc44c
--- /dev/null
+++ b/t/ar-lib5b.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test if AM_PROG_AR triggers the use of the ar-lib script.
+# This test does not require Microsoft lib.
+# Keep this test in sync with sister test 'ar-lib5a.sh'.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([auxdir])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+# We want to test the content of am_cv_ar_interface in the Makefile.
+AC_SUBST([am_cv_ar_interface])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LIBRARIES = libwish.a
+libwish_a_SOURCES = wish.c
+
+check-local:
+ test x'$(am_cv_ar_interface)' = x'lib'
+ test -f ar-lib-worked
+MOSTLYCLEANFILES = ar-lib-worked
+END
+
+cat > wish.c << 'END'
+int wish(void) { return 0; }
+END
+
+mkdir auxdir
+cat > auxdir/ar-lib << 'END'
+#! /bin/sh
+:> ar-lib-worked
+END
+chmod +x auxdir/ar-lib
+
+# Let's fake microsoft lib.
+mkdir bin
+cat > bin/lib << 'END'
+#! /bin/sh
+echo lib command line: $* >&2 # For debugging.
+case " $* " in
+ # The '-OUT:' option is used by tests in configure. So don't create
+ # the 'ar-lib-worked' file here, as that might cause spurious passes
+ # of this test; but don't fail either, as that would confuse said
+ # configure tests.
+ *' -OUT:'*) exit 0;;
+ # This means that $* looks like a command-line for 'ar'. We have to
+ # exit with failure here, to accommodate the two following ortoghonal
+ # scenarios:
+ # 1. when 'lib' is tested by configure, this will tell that it does
+ # not use the ar(1) interface, so that the 'ar-lib' script will
+ # get involved;
+ # 2. when 'lib' is called by the Makefile, an ar-style command line
+ # passed to it would mean that the 'ar-lib' script has failed to
+ # properly munge the command line, or hasn't been invoked to do so.
+ *\ c*) exit 1;;
+ # Assume everything else is OK.
+ *) : > ar-lib-worked;;
+esac
+END
+chmod +x bin/lib
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+# Sanity check: test that it is ok to use 'am_cv_ar_interface' as we do.
+$FGREP 'am_cv_ar_interface=' configure
+
+./configure AR=lib RANLIB=:
+
+$MAKE check
+$MAKE distcheck DISTCHECK_CONFIGURE_FLAGS="AR=lib RANLIB=:"
+
+:
diff --git a/t/ar-lib6a.sh b/t/ar-lib6a.sh
new file mode 100644
index 000000000..76a4329c7
--- /dev/null
+++ b/t/ar-lib6a.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test AM_PROG_AR ordering requirements
+# Keep this test in sync with sister test 'ar-lib6b.sh'.
+
+required=libtoolize
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+m4_ifdef([LT_INIT], [LT_INIT], [AC_PROG_LIBTOOL])
+AM_PROG_AR
+END
+
+libtoolize
+$ACLOCAL
+$AUTOCONF 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+
+$EGREP '(AC_PROG_LIBTOOL|LT_INIT).*before.*AM_PROG_AR' stderr
+
+:
diff --git a/t/ar-lib6b.sh b/t/ar-lib6b.sh
new file mode 100644
index 000000000..47938561e
--- /dev/null
+++ b/t/ar-lib6b.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test AM_PROG_AR ordering requirements for older Libtools
+# Keep this test in sync with sister test 'ar-lib6a.sh'.
+
+required=libtoolize
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_PROG_LIBTOOL
+AM_PROG_AR
+END
+
+libtoolize
+$ACLOCAL
+$AUTOCONF 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+
+$EGREP 'AC_PROG_LIBTOOL.*before.*AM_PROG_AR' stderr
+
+:
diff --git a/t/ar-lib7.sh b/t/ar-lib7.sh
new file mode 100644
index 000000000..d7c21f16e
--- /dev/null
+++ b/t/ar-lib7.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test if automake warns if ar-lib is missing when AM_PROG_AR is used.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_AR
+END
+
+:> Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+
+grep '^configure\.ac:.*ar-lib.*not found' stderr
+
+$AUTOMAKE --add-missing
+
+:
diff --git a/t/ar.sh b/t/ar.sh
new file mode 100644
index 000000000..08bcb72a0
--- /dev/null
+++ b/t/ar.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that AR, ARFLAGS, and RANLIB can be substituted from configure.ac.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_AR
+AC_SUBST([AR], ['echo it works'])
+AC_SUBST([ARFLAGS], ['>'])
+AC_SUBST([RANLIB], ['echo really works >>'])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LIBRARIES = libfoo.a
+libfoo_a_SOURCES =
+END
+
+:> ar-lib
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
+grep 'it works' libfoo.a
+grep 'really works' libfoo.a
+
+:
diff --git a/t/ar2.sh b/t/ar2.sh
new file mode 100644
index 000000000..1c3f4d6d3
--- /dev/null
+++ b/t/ar2.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure AR and ARFLAGS are defined for EXTRA_LIBRARIES.
+# Report from Kevin Ryde.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+EXTRA_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+$ACLOCAL
+$AUTOMAKE -Wno-extra-portability
+grep '^ARFLAGS =' Makefile.in
+grep '^AR =' Makefile.in
+
+:
diff --git a/t/ar3.sh b/t/ar3.sh
new file mode 100644
index 000000000..fc4f9fa99
--- /dev/null
+++ b/t/ar3.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that AR, ARFLAGS, etc. works also when the macro AM_PROG_AR
+# is used.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+EXTRA_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+: > ar-lib
+
+$ACLOCAL
+$AUTOMAKE
+$EGREP '^ARFLAGS =' Makefile.in
+$EGREP '^AR =' Makefile.in
+
+:
diff --git a/t/ar4.sh b/t/ar4.sh
new file mode 100644
index 000000000..2a98fb574
--- /dev/null
+++ b/t/ar4.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test if configure bails out if $AR does not work and AM_PROG_AR is used.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_AR
+END
+
+$ACLOCAL
+$AUTOCONF
+
+st=0; ./configure AR=/bin/false >stdout 2>stderr || st=$?
+cat stdout
+cat stderr >&2
+test $st -eq 1
+
+grep '^checking.* archiver .*interface.*\.\.\. unknown' stdout
+grep '^configure: error: could not determine /bin/false interface' stderr
+ls *conftest* && exit 1
+
+:
diff --git a/t/ar5.sh b/t/ar5.sh
new file mode 100644
index 000000000..3cd7328f7
--- /dev/null
+++ b/t/ar5.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test the optional argument of AM_PROG_AR.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_AR([
+ echo spy > bad-archiver-interface-detected
+ AC_MSG_CHECKING([for something else])
+ AC_MSG_RESULT([found it])
+ echo Grep This
+])
+END
+
+$ACLOCAL
+$AUTOCONF
+
+./configure AR=/bin/false >stdout || { cat stdout; exit 1; }
+cat stdout
+grep '^checking.* archiver .*interface.*\.\.\. unknown$' stdout
+grep '^checking for something else\.\.\. found it$' stdout
+grep '^Grep This$' stdout
+test -f bad-archiver-interface-detected
+
+:
diff --git a/t/asm.sh b/t/asm.sh
new file mode 100644
index 000000000..f3e6b5759
--- /dev/null
+++ b/t/asm.sh
@@ -0,0 +1,100 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of basic assembly functionality.
+# Keep this in sync with sister tests 'asm2.sh' and 'asm3.sh'.
+
+. test-init.sh
+
+mv configure.ac configure.stub
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = maude
+maude_SOURCES = maude.s
+END
+
+echo '*** Try 1 -- should fail because we need CC and CCAS ***'
+cat configure.stub - > configure.ac << 'END'
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Aa]ssembler source.*CCAS.* undefined' stderr
+grep 'define .*CCAS.* add .*AM_PROG_AS' stderr
+
+# On fast machines the autom4te.cache created during the above run of
+# $AUTOMAKE is likely to have the same time stamp as the configure.ac
+# created below; thus causing traces for the old configure.ac to be
+# used. We could do '$sleep', but it's faster to erase the
+# directory. (Erase autom4te*.cache, not autom4te.cache, because some
+# bogus installations of Autoconf use a versioned cache.)
+rm -rf autom4te*.cache
+
+echo '*** Try 2 -- we still need CCAS ***'
+cat configure.stub - > configure.ac << 'END'
+AC_PROG_CC
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Aa]ssembler source.*CCAS.* undefined' stderr
+grep 'define .*CCAS.* add .*AM_PROG_AS' stderr
+
+rm -rf autom4te*.cache
+
+echo '*** Try 3 -- we need CCASFLAGS ***'
+cat configure.stub - > configure.ac << 'END'
+CCAS='$(CC)'
+AC_SUBST([CCAS])
+AC_PROG_CC
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Aa]ssembler source.*CCASFLAGS.* undefined' stderr
+grep 'define .*CCASFLAGS.* add .*AM_PROG_AS' stderr
+
+rm -rf autom4te*.cache
+
+echo '*** Try 4 -- we have everything needed, expect success ***'
+cat configure.stub - > configure.ac << 'END'
+CCAS='$(CC)'
+AC_SUBST([CCAS])
+AC_PROG_CC
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+rm -rf autom4te*.cache
+
+echo '*** Try 5 -- we have everything needed, expect success ***'
+cat configure.stub - > configure.ac << 'END'
+AM_PROG_AS
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/asm2.sh b/t/asm2.sh
new file mode 100644
index 000000000..6a38d25a5
--- /dev/null
+++ b/t/asm2.sh
@@ -0,0 +1,116 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of basic preprocessed assembly functionality.
+# Keep this in sync with sister tests 'asm.sh' and 'asm3.sh'.
+
+. test-init.sh
+
+mv configure.ac configure.stub
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = maude
+maude_SOURCES = maude.S
+END
+
+echo '*** Try 1 -- should fail because we need CC and CCAS ***'
+cat configure.stub - > configure.ac << 'END'
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Aa]ssembler source.*CCAS.* undefined' stderr
+grep 'define .*CCAS.* add .*AM_PROG_AS' stderr
+
+# On fast machines the autom4te.cache created during the above run of
+# $AUTOMAKE is likely to have the same time stamp as the configure.ac
+# created below; thus causing traces for the old configure.ac to be
+# used. We could do '$sleep', but it's faster to erase the
+# directory. (Erase autom4te*.cache, not autom4te.cache, because some
+# bogus installations of Autoconf use a versioned cache.)
+rm -rf autom4te*.cache
+
+echo '*** Try 2 -- we still need CCAS ***'
+cat configure.stub - > configure.ac << 'END'
+AC_PROG_CC
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Aa]ssembler source.*CCAS.* undefined' stderr
+grep 'define .*CCAS.* add .*AM_PROG_AS' stderr
+
+rm -rf autom4te*.cache
+
+echo '*** Try 3 -- we need CCASFLAGS ***'
+cat configure.stub - > configure.ac << 'END'
+CCAS='$(CC)'
+AC_SUBST([CCAS])
+AC_PROG_CC
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Aa]ssembler source.*CCASFLAGS.* undefined' stderr
+grep 'define .*CCASFLAGS.* add .*AM_PROG_AS' stderr
+
+rm -rf autom4te*.cache
+
+echo '*** Try 4 -- we need dependency tracking. ***'
+cat configure.stub - > configure.ac << 'END'
+CCAS='$(CC)'
+AC_SUBST([CCAS])
+AC_PROG_CC
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep ' add .*AM_PROG_AS' stderr
+
+rm -rf autom4te*.cache
+
+echo '*** Try 5 -- we have everything needed, expect success. ***'
+cat configure.stub - > configure.ac << 'END'
+CCAS='$(CC)'
+AC_SUBST([CCAS])
+AC_PROG_CC
+_AM_DEPENDENCIES([CCAS])
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+rm -rf autom4te*.cache
+
+echo '*** Try 6 -- we have everything needed, expect success. ***'
+cat configure.stub - > configure.ac << 'END'
+AM_PROG_AS
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/asm3.sh b/t/asm3.sh
new file mode 100644
index 000000000..925710617
--- /dev/null
+++ b/t/asm3.sh
@@ -0,0 +1,116 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of basic preprocessed assembly functionality with extension '.sx'.
+# Keep this in sync with sister tests 'asm.sh' and 'asm2.sh'.
+
+. test-init.sh
+
+mv configure.ac configure.stub
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = maude
+maude_SOURCES = maude.sx
+END
+
+echo '*** Try 1 -- should fail because we need CC and CCAS ***'
+cat configure.stub - > configure.ac << 'END'
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Aa]ssembler source.*CCAS.* undefined' stderr
+grep 'define .*CCAS.* add .*AM_PROG_AS' stderr
+
+# On fast machines the autom4te.cache created during the above run of
+# $AUTOMAKE is likely to have the same time stamp as the configure.ac
+# created below; thus causing traces for the old configure.ac to be
+# used. We could do '$sleep', but it's faster to erase the
+# directory. (Erase autom4te*.cache, not autom4te.cache, because some
+# bogus installations of Autoconf use a versioned cache.)
+rm -rf autom4te*.cache
+
+echo '*** Try 2 -- we still need CCAS ***'
+cat configure.stub - > configure.ac << 'END'
+AC_PROG_CC
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Aa]ssembler source.*CCAS.* undefined' stderr
+grep 'define .*CCAS.* add .*AM_PROG_AS' stderr
+
+rm -rf autom4te*.cache
+
+echo '*** Try 3 -- we need CCASFLAGS ***'
+cat configure.stub - > configure.ac << 'END'
+CCAS='$(CC)'
+AC_SUBST([CCAS])
+AC_PROG_CC
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Aa]ssembler source.*CCASFLAGS.* undefined' stderr
+grep 'define .*CCASFLAGS.* add .*AM_PROG_AS' stderr
+
+rm -rf autom4te*.cache
+
+echo '*** Try 4 -- we need dependency tracking. ***'
+cat configure.stub - > configure.ac << 'END'
+CCAS='$(CC)'
+AC_SUBST([CCAS])
+AC_PROG_CC
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep ' add .*AM_PROG_AS' stderr
+
+rm -rf autom4te*.cache
+
+echo '*** Try 5 -- we have everything needed, expect success. ***'
+cat configure.stub - > configure.ac << 'END'
+CCAS='$(CC)'
+AC_SUBST([CCAS])
+AC_PROG_CC
+_AM_DEPENDENCIES([CCAS])
+AC_SUBST([CCASFLAGS])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+rm -rf autom4te*.cache
+
+echo '*** Try 6 -- we have everything needed, expect success. ***'
+cat configure.stub - > configure.ac << 'END'
+AM_PROG_AS
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/autodist-acconfig-no-subdir.sh b/t/autodist-acconfig-no-subdir.sh
new file mode 100644
index 000000000..42a043c3c
--- /dev/null
+++ b/t/autodist-acconfig-no-subdir.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that 'acconfig.h' is *not* automatically distributed when
+# placed in a subdirectory.
+# Related to automake bug#7819.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+sub/acconfig.h:
+ echo target $@ should not be built >&2; exit 1
+check-local: distdir
+ ls -l $(distdir)/sub
+ test ! -f $(distdir)/sub/acconfig.h
+END
+
+mkdir sub
+
+cat > sub/Makefile.am <<'END'
+acconfig.h:
+ echo target $@ should not be built >&2; exit 1
+check-local:
+ echo $(DISTFILES) | grep 'acconfig\.h' && exit 1; :
+ echo $(DIST_COMMON) | grep 'acconfig\.h' && exit 1; :
+END
+
+: > sub/acconfig.h
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE check
+
+:
diff --git a/t/autodist-acconfig.sh b/t/autodist-acconfig.sh
new file mode 100644
index 000000000..f22a09ec5
--- /dev/null
+++ b/t/autodist-acconfig.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that 'acconfig.h' is automatically distributed if it exists
+# (at automake runtime).
+# Related to automake bug#7819.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+.PHONY: test
+test: distdir
+ ls -l $(distdir)
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]acconfig\.h '
+ test -f $(distdir)/acconfig.h
+END
+
+: > acconfig.h
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE test
+
+:
diff --git a/t/autodist-aclocal-m4.sh b/t/autodist-aclocal-m4.sh
new file mode 100644
index 000000000..a605333c3
--- /dev/null
+++ b/t/autodist-aclocal-m4.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that 'aclocal.m4' is not automatically distributed if not
+# required to build 'configure'. This is *really* a corner-case
+# check, and the behaviour it checks is not documented either, so
+# if that behaviour is deliberately changed in the future, just
+# remove this test.
+# Related to automake bug#7819.
+
+. test-init.sh
+
+{ echo 'm4_include([defs.m4])'
+ cat configure.ac
+ echo 'AC_OUTPUT'
+} > t
+mv -f t configure.ac
+
+cat > Makefile.am <<'END'
+.PHONY: test
+test: distdir
+ ls -l $(distdir)
+ test ! -f $(distdir)/aclocal.m4
+ echo $(DISTFILES) | grep 'aclocal\.m4' && exit 1; :
+ echo $(DIST_COMMON) | grep 'aclocal\.m4' && exit 1; :
+check-local: test
+END
+
+: > defs.m4
+$ACLOCAL
+mv -f aclocal.m4 defs.m4
+
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/autodist-config-headers.sh b/t/autodist-config-headers.sh
new file mode 100644
index 000000000..f3fb5e35b
--- /dev/null
+++ b/t/autodist-config-headers.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that config.h.bot and config.h.top are automatically
+# distributed if the AC_CONFIG_HADERS macro is used and they
+# exist at automake runtime.
+# Related to automake bug#7819.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_CONFIG_HEADERS([config.h sub/config.h cfg2.h:conf2.hin])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+.PHONY: test
+test: distdir
+ ls -l $(distdir) $(distdir)/sub
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]config\.h\.bot '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]config\.h\.top '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]cfg2\.h\.bot '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]cfg2\.h\.top '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]sub/config\.h\.bot '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]sub/config\.h\.top '
+ test -f $(distdir)/config.h.bot
+ test -f $(distdir)/config.h.top
+ test -f $(distdir)/cfg2.h.bot
+ test -f $(distdir)/cfg2.h.top
+ test -f $(distdir)/sub/config.h.bot
+ test -f $(distdir)/sub/config.h.top
+END
+
+mkdir sub
+touch config.h.in config.h.top config.h.bot \
+ conf2.hin cfg2.h.top cfg2.h.bot \
+ sub/config.h.in sub/config.h.top sub/config.h.bot
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE test
+
+:
diff --git a/t/autodist-configure-no-subdir.sh b/t/autodist-configure-no-subdir.sh
new file mode 100644
index 000000000..f26ad9a33
--- /dev/null
+++ b/t/autodist-configure-no-subdir.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that 'configure', 'configure.ac' and 'configure.in' are *not*
+# automatically distributed when placed in a subdirectory.
+# Related to automake bug#7819.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+dontbuild = echo target $@ should not be built >&2; exit 1
+sub/configure:
+ $(dontbuild)
+sub/configure.ac:
+ $(dontbuild)
+sub/configure.in:
+ $(dontbuild)
+check-local: distdir
+ ls -l $(distdir)/sub
+ test ! -f $(distdir)/sub/configure
+ test ! -f $(distdir)/sub/configure.in
+ test ! -f $(distdir)/sub/configure.ac
+END
+
+mkdir sub
+
+cat > sub/Makefile.am <<'END'
+dontbuild = echo target $@ should not be built >&2; exit 1
+configure:
+ $(dontbuild)
+configure.ac:
+ $(dontbuild)
+configure.in:
+ $(dontbuild)
+check-local:
+ echo $(DISTFILES) | grep 'configure' && exit 1; :
+ echo $(DIST_COMMON) | grep 'configure' && exit 1; :
+END
+
+: > sub/configure.ac
+: > sub/configure.in
+: > sub/configure
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE check
+
+:
diff --git a/t/autodist-no-duplicate.sh b/t/autodist-no-duplicate.sh
new file mode 100644
index 000000000..639cf7765
--- /dev/null
+++ b/t/autodist-no-duplicate.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that there are no duplicates in the list of files automatically
+# distributed by automake.
+
+. test-init.sh
+
+re='Files .*automatically distributed.*if found'
+
+# The automake manual states that the list of automatically-distributed
+# files should be given by 'automake --help'.
+
+list1=$($AUTOMAKE --help \
+ | sed -n "/^$re.*always/,/^ *$/p" \
+ | sed 1d)
+list1=$(echo $list1)
+
+list2=$($AUTOMAKE --help \
+ | sed -n "/^$re.*under certain conditions/,/^ *$/p" \
+ | sed 1d)
+list2=$(echo $list2)
+
+test -n "$list1"
+test -n "$list2"
+
+st=0
+for i in 1 2; do
+ eval list=\${list$i}
+ for f in $list; do echo $f; done | sort > files$i.lst
+ uniq files$i.lst > files$i.uniq
+ cat files$i.lst
+ cat files$i.uniq
+ diff files$i.lst files$i.uniq || st=1
+done
+
+exit $st
diff --git a/t/autodist-stamp-vti.sh b/t/autodist-stamp-vti.sh
new file mode 100644
index 000000000..181df6694
--- /dev/null
+++ b/t/autodist-stamp-vti.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that 'stamp-vti' is automatically distributed when info_TEXINFOS
+# and version.texi are involved.
+# Related to automake bug#7819.
+
+required=makeinfo
+. test-init.sh
+
+cat >> configure.ac << END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = foo.texi
+.PHONY: test
+test: all distdir
+ ls -l $(distdir)
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]stamp-vti '
+ test -f $(distdir)/stamp-vti
+END
+
+cat > foo.texi << 'END'
+\input texinfo
+@setfilename foo.info
+@settitle Zardoz
+@node Top
+@include version.texi
+bar baz quux
+@bye
+END
+
+# Required when using Texinfo.
+: > texinfo.tex
+cp "$am_scriptdir"/mdate-sh .
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE test
+
+:
diff --git a/t/autodist-subdir.sh b/t/autodist-subdir.sh
new file mode 100644
index 000000000..6079e8f88
--- /dev/null
+++ b/t/autodist-subdir.sh
@@ -0,0 +1,120 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake really automatically distributes all the files
+# it advertises to do, even when in subdirectories.
+#
+# This behavior might be suboptimal, but it has been in place for quite
+# a long time, and it would be risky to change it now. See also the
+# discussion of automake bug#7819:
+# <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=7819>
+#
+# Keep this test in sync with sister test 'autodist.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+
+# The automake manual states that the list of automatically-distributed
+# files should be given by 'automake --help'.
+list=$($AUTOMAKE --help \
+ | sed -n '/^Files.*automatically distributed.*if found.*always/,/^ *$/p' \
+ | sed 1d)
+# Normalize whitespace, just in case.
+list=$(echo $list)
+
+test -n "$list"
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+check-local:
+## For debugging.
+ @echo DIST_COMMON:
+ @for f in $(DIST_COMMON); do echo " $$f"; done
+ @echo DISTDIR:
+ @ls -l $(distdir) | sed 's/^/ /'
+## Now the checks.
+ @for f in $(autodist_list); do \
+ echo "file: sub/$$f"; \
+ test -f $(distdir)/sub/$$f \
+ || { echo $$f: distdir fail >&2; exit 1; }; \
+ done
+END
+
+mkdir sub
+
+cat > sub/Makefile.am <<'END'
+include distfiles.am
+check-local:
+## For debugging.
+ @echo DIST_COMMON:
+ @for f in $(DIST_COMMON); do echo " $$f"; done
+ @echo DISTDIR:
+ @ls -l $(distdir) | sed 's/^/ /'
+## Now the checks.
+ @for f in $(autodist_list); do \
+ echo "file: $$f"; \
+## Some filenames might contain dots, but this won't cause spurious
+## failures, and "spurious successes" are so unlikely that they're
+## not worth worrying about.
+ echo ' ' $(DIST_COMMON) ' ' | grep "[ /]$$f " >/dev/null \
+ || { echo $$f: distcom fail >&2; exit 1; }; \
+ done
+END
+
+: First try listing the automatically-distributed files in proper
+: targets in Makefile.am
+
+echo "MAINTAINERCLEANFILES = $list" > sub/distfiles.am
+for f in $list; do echo "$f :; touch $f"; done >> sub/distfiles.am
+
+cat sub/distfiles.am # For debugging.
+
+$AUTOMAKE -a
+
+./configure
+
+$MAKE distdir
+autodist_list="$list" $MAKE check
+
+$MAKE maintainer-clean
+test ! -e sub/README # Sanity check.
+rm -rf $me-1.0 # Remove $(distdir).
+
+: Now try creating the automatically-distributed files before
+: running automake.
+
+: > sub/distfiles.am
+for f in $list; do
+ echo dummy > sub/$f
+done
+
+ls -l # For debugging.
+
+$AUTOMAKE
+
+./configure
+
+$MAKE distdir
+autodist_list="$list" $MAKE check
+
+:
diff --git a/t/autodist.sh b/t/autodist.sh
new file mode 100644
index 000000000..0c2d2cacf
--- /dev/null
+++ b/t/autodist.sh
@@ -0,0 +1,103 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake really automatically distributes all the files
+# it advertises to do.
+# Related to automake bug#7819.
+# Keep this test in sync with sister test 'autodist-subdir.sh'.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([.])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+
+# The automake manual states that the list of automatically-distributed
+# files should be given by 'automake --help'.
+list=$($AUTOMAKE --help \
+ | sed -n '/^Files.*automatically distributed.*if found.*always/,/^ *$/p' \
+ | sed 1d)
+# Normalize whitespace, just in case.
+list=$(echo $list)
+
+test -n "$list"
+
+cat > Makefile.am <<'END'
+include distfiles.am
+check-local:
+## For debugging.
+ @echo DIST_COMMON:
+ @for f in $(DIST_COMMON); do echo " $$f"; done
+ @echo DISTDIR:
+ @ls -l $(distdir) | sed 's/^/ /'
+## Now the checks.
+ @for f in $(autodist_list); do \
+ echo "file: $$f"; \
+ test -f $(distdir)/$$f \
+ || { echo $$f: distdir fail >&2; exit 1; }; \
+## Some filenames might contain dots, but this won't cause spurious
+## failures, and "spurious successes" are so unlikely that they're
+## not worth worrying about.
+ echo ' ' $(DIST_COMMON) ' ' | grep "[ /]$$f " >/dev/null \
+ || { echo $$f: distcom fail >&2; exit 1; }; \
+ done
+END
+
+: First try listing the automatically-distributed files in proper
+: targets in Makefile.am
+
+echo "MAINTAINERCLEANFILES = $list" > distfiles.am
+for f in $list; do echo "$f :; touch $f"; done >> distfiles.am
+
+cat distfiles.am # For debugging.
+
+$AUTOMAKE -a
+
+./configure
+
+$MAKE distdir
+autodist_list="$list" $MAKE check
+
+$MAKE maintainer-clean
+test ! -e README # Sanity check.
+rm -rf $me-1.0 # Remove $(distdir).
+
+: Now try creating the automatically-distributed files before
+: running automake.
+
+: > distfiles.am
+for f in $list; do
+ echo dummy > $f
+done
+
+ls -l # For debugging.
+
+$AUTOMAKE
+
+./configure
+
+$MAKE distdir
+autodist_list="$list" $MAKE check
+
+:
diff --git a/t/autohdr-subdir-pr12495.sh b/t/autohdr-subdir-pr12495.sh
new file mode 100644
index 000000000..e392ba87d
--- /dev/null
+++ b/t/autohdr-subdir-pr12495.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Related to automake bug#12495: Automake shouldn't generate useless
+# remake rules for AC_CONFIG_HEADERS arguments after the first one,
+# not even when subdirs are involved.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_HEADERS([a.h b.h sub/c.h])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+echo SUBDIRS = sub > Makefile.am
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+# Even if an AC_CONFIG_HEADERS invocation is passed several files in
+# the first argument, only the first one is considered by autoheader
+# for automatic generation. Otherwise, the present test case would
+test -f a.h.in && test ! -f c.h.in && test ! -f sub/c.h.in \
+ || fatal_ "unexpected autoheader behavior with multiple" \
+ "AC_CONFIG_HEADERS arguments"
+# Automake should require the missing headers though.
+AUTOMAKE_fails -Wno-error -Wnone
+grep "^configure\.ac:4:.* required file 'b.h.in' not found" stderr
+grep "^configure\.ac:4:.* required file 'sub/c.h.in' not found" stderr
+: > b.h.in
+: > sub/c.h.in
+$AUTOMAKE
+
+./configure
+
+# Automake should regenerate this.
+grep '^$(srcdir)/a\.h\.in:' Makefile.in
+# But not these.
+grep '[bc]\.h\.in.*:' Makefile.in sub/Makefile.in && exit 1
+
+test -f a.h && test -f b.h && test -f sub/c.h \
+ || fatal_ "unexpected ./configure behavior with multiple" \
+ "AC_CONFIG_HEADERS arguments"
+
+rm -f a.h.in a.h
+$MAKE
+test -f a.h.in
+test -f a.h
+
+# We might need to grep the output of GNU make for error messages.
+LANG=C LANGUAGE=C LC_ALL=C
+export LANG LANGUAGE LC_ALL
+
+ocwd=$(pwd)
+for x in b c; do
+ test $x = b || cd sub
+ rm -f $x.h.in
+ run_make -E -e FAIL $x.h.in
+ test ! -f $x.h.in
+ if using_gmake; then
+ grep "No rule to make target [\`\"']$x\.h\.in[\`\"']" stderr
+ fi
+ : > $x.h.in
+ cd "$ocwd" || fatal_ "cannot chdir back"
+done
+
+:
diff --git a/t/autohdr.sh b/t/autohdr.sh
new file mode 100644
index 000000000..585ef3e0d
--- /dev/null
+++ b/t/autohdr.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that autoheaders works, despite our AC_CONFIG_HEADERS hack.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_CONFIG_HEADERS([thisfile.h])
+EOF
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOHEADER
+
+test -f thisfile.h.in
diff --git a/t/autohdr3.sh b/t/autohdr3.sh
new file mode 100644
index 000000000..36209bda3
--- /dev/null
+++ b/t/autohdr3.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check rebuild rules for autoheader.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+m4_include([foo.m4])
+AC_CONFIG_HEADERS([config.h:config.hin])
+AC_OUTPUT
+EOF
+
+: > foo.m4
+
+cat > Makefile.am <<'END'
+.PHONY: test
+check-local: test
+test: all
+ cat $(srcdir)/config.hin ;: For debugging.
+ cat config.h ;: Likewise.
+ grep '#.*GREPME' $(srcdir)/config.hin
+ grep '#.*define.*GREPME' config.h
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE
+
+./configure
+$MAKE
+
+$sleep
+echo 'AC_DEFINE([GREPME], 1, [Doc for GREPME])' > foo.m4
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/autohdr4.sh b/t/autohdr4.sh
new file mode 100644
index 000000000..ae35b7005
--- /dev/null
+++ b/t/autohdr4.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check rebuild rules for AC_CONFIG_HEADERS.
+# (This should also work without GNU Make.)
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AC_PROG_CC
+AC_SUBST([BOT], [bot])
+AC_CONFIG_HEADERS([defs.h config.h:sub1/config.top:sub2/config.${BOT}],,
+ [BOT=$BOT])
+AC_CONFIG_FILES([sub3/Makefile])
+AC_OUTPUT
+EOF
+
+mkdir sub1 sub2 sub3
+
+: > sub1/config.top
+echo '#define NAME "grepme1"' >sub2/config.bot
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub3
+.PHONY: test-prog-updated
+test-prog-updated:
+ is_newest sub3/run$(EXEEXT) sub2/config.bot
+END
+
+cat > sub3/Makefile.am <<'END'
+noinst_PROGRAMS = run
+END
+
+cat >sub3/run.c <<'EOF'
+#include <defs.h>
+#include <config.h>
+#include <stdio.h>
+
+int main (void)
+{
+ puts (NAME); /* from config.h */
+ puts (PACKAGE); /* from defs.h */
+}
+EOF
+
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE
+
+# Do not reject slow dependency extractors: we need dependency tracking.
+./configure --enable-dependency-tracking
+$MAKE
+# Sanity check.
+cross_compiling || sub3/run | grep grepme1 || exit 1
+
+$sleep
+echo '#define NAME "grepme2"' > sub2/config.bot
+$MAKE
+cross_compiling || sub3/run | grep grepme2 || exit 1
+$MAKE test-prog-updated
+
+$MAKE distcheck
+
+:
diff --git a/t/autohdrdry.sh b/t/autohdrdry.sh
new file mode 100644
index 000000000..fb53ab81a
--- /dev/null
+++ b/t/autohdrdry.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Removal recovery rules for AC_CONFIG_HEADERS should not remove files
+# with 'make -n'.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AC_CONFIG_HEADERS([config.h])
+AC_OUTPUT
+EOF
+
+: >Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE
+
+./configure
+$MAKE
+
+rm -f config.h
+$MAKE -n
+test -f stamp-h1
+test ! -e config.h
+
+:
diff --git a/t/automake-cmdline.tap b/t/automake-cmdline.tap
new file mode 100644
index 000000000..5f873cdd3
--- /dev/null
+++ b/t/automake-cmdline.tap
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test Automake's command-line options.
+
+. test-init.sh
+
+plan_ 17
+
+# Usage: bad_cmdline DESCRIPTION REGEX-FOR-STDERR [ARGS-FOR-AUTOMAKE...]
+do_check ()
+{
+ test $# -ge 3 || fatal_ "do_check: invalid usage"
+ desc=$1; shift
+ regex=$1; shift
+ AUTOMAKE_fails -d "$desc (run)" -- "$@"
+ command_ok_ "$desc (stderr)" grep "$regex" stderr
+}
+
+do_check 'invalid long option' 'unrecognized option.*--voo' --voo
+
+# Older perl has a buggy Getopt::Long which makes this fail.
+if $PERL -e 'require 5.8.2;'; then
+ do_check "list of options terminated by '--'" \
+ 'input file.*--voo' -- --voo
+else
+ skip_row_ 2 -r "older perl with buggy Getopt::Long"
+fi
+
+do_check "empty argument" \
+ 'empty argument' ''
+
+do_check "missing argument for long option" \
+ 'option.*-W.*requires an argument' -W
+
+do_check "missing argument for short option" \
+ 'option.*--warnings.*requires an argument' --warnings
+
+do_check "'--help' as option argument" \
+ 'unknown warning.*--help' --warnings --help
+
+do_check "'--help' as option argument" \
+ 'unknown warning.*--help' --warnings --help
+
+do_check "ambiguous incomplete option" \
+ 'unrecognized option.*--ver' --ver
+
+command_ok_ "unambiguous incomplete long option" $AUTOMAKE --vers
+
+:
diff --git a/t/auxdir-autodetect.sh b/t/auxdir-autodetect.sh
new file mode 100644
index 000000000..16db5f1b0
--- /dev/null
+++ b/t/auxdir-autodetect.sh
@@ -0,0 +1,130 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that, if AC_CONFIG_AUX_DIR is not specified, Automake tries
+# to use '.', '..' and '../..', in precisely that order.
+
+. test-init.sh
+
+nil=__no_such_program
+
+unset NONESUCH
+
+cat >>configure.ac << END
+AM_MISSING_PROG([NONESUCH],[$nil])
+AC_OUTPUT
+END
+
+mkdir d3
+mkdir d3/d2
+mkdir d3/d2/d1
+mkdir d3/d2/d1/d0
+
+echo 'echo %%d3%% $*' > d3/missing
+chmod +x d3/missing
+echo 'echo %%d2%% $*' > d3/d2/missing
+chmod +x d3/d2/missing
+echo 'echo %%d1%% $*' > d3/d2/d1/missing
+chmod +x d3/d2/d1/missing
+echo 'echo %%d0%% $*' > d3/d2/d1/d0/missing
+chmod +x d3/d2/d1/d0/missing
+
+mv configure.ac d3/d2/d1/d0/
+
+cd d3/d2/d1/d0
+
+cat > Makefile.am << 'EOF'
+.PHONY: test
+test:
+ $(NONESUCH) >$(out)
+EOF
+
+$ACLOCAL
+$AUTOCONF
+
+# ------------------------------------------- #
+: We must end up with AC_CONFIG_AUX_DIR = . #
+# ------------------------------------------- #
+
+: > install-sh
+$AUTOMAKE
+./configure
+out=out0 $MAKE test
+cat out0
+grep "%%d0%%.*$nil" out0
+grep '%%d[123]' out0 && exit 1
+
+rm -f missing install-sh
+
+# -------------------------------------------- #
+: We must end up with AC_CONFIG_AUX_DIR = .. #
+# -------------------------------------------- #
+
+# Automake finds 'install-sh' in '.', so it assumes that auxdir is '.';
+# but it won't find 'missing' in '.', so it will fail.
+: > install-sh
+AUTOMAKE_fails
+grep 'required file.*[^.]\./missing.*not found' stderr
+rm -f install-sh
+
+# Now things should work.
+: > ../install-sh
+$AUTOMAKE
+./configure
+out=out1 $MAKE test
+cat out1
+grep "%%d1%%.*$nil" out1
+grep '%%d[023]' out1 && exit 1
+
+rm -f ../missing ../install-sh
+
+# ----------------------------------------------- #
+: We must end up with AC_CONFIG_AUX_DIR = ../.. #
+# ----------------------------------------------- #
+
+# Automake finds 'install-sh' in '.', so it assumes that auxdir is '.';
+# but it won't find 'missing' in '.', so it will fail.
+: > install-sh
+AUTOMAKE_fails
+grep 'required file.*[^.]\./missing.*not found' stderr
+rm -f install-sh
+
+# Automake finds 'install-sh' in '..', so it assumes that auxdir is '..';
+# but it won't find 'missing' in '.', so it will fail.
+: > ../install-sh
+AUTOMAKE_fails
+grep 'required file.*[^.]\.\./missing.*not found' stderr
+rm -f ../install-sh
+
+# Now things should work.
+: > ../../install-sh
+$AUTOMAKE
+./configure
+out=out2 $MAKE test
+cat out2
+grep "%%d2%%.*$nil" out2
+grep '%%d[013]' out2 && exit 1
+
+rm -f ../../missing ../../install-sh
+
+# --------------------------------------------------------- #
+: AC_CONFIG_AUX_DIR will not be found: Automake must fail #
+# --------------------------------------------------------- #
+
+AUTOMAKE_fails
+grep 'required file.*missing.*not found' stderr
+
+:
diff --git a/t/auxdir-cc-pr15981.sh b/t/auxdir-cc-pr15981.sh
new file mode 100644
index 000000000..5285382f2
--- /dev/null
+++ b/t/auxdir-cc-pr15981.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2014-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test automake bug#15981: automake 1.14 may use $ac_aux_dir
+# before it is defined, leading to error messages such as:
+# "/bin/sh: /home/david/missing: No such file or directory"
+
+required=cc
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [0.0])
+AC_USE_SYSTEM_EXTENSIONS
+AM_INIT_AUTOMAKE([1.11 foreign])
+AC_CONFIG_FILES([Makefile])
+AC_SUBST([MISSING])
+AC_OUTPUT
+test -n "\${MISSING}"
+END
+
+echo 'int main (void) { return 0; }' > foo.c
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo
+
+# Without quotes around '--help' and with an empty $(MISSING), make might
+# strip the trailing '--', call Bash's 'help' builtin, and have this test
+# succeed spuriously. Yes, that has happened in practice :-(
+test:
+ $(MISSING) '--help'
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+$FGREP "missing" stderr && exit 1
+
+$MAKE all
+$MAKE test
+
+:
diff --git a/t/auxdir-computed.tap b/t/auxdir-computed.tap
new file mode 100644
index 000000000..0dae89c9f
--- /dev/null
+++ b/t/auxdir-computed.tap
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# It should be possible to use a computed auxdir. This might seem
+# bizarre, but it is actually used in multilib builds.
+
+. test-init.sh
+
+plan_ 3
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([\$foo])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+: > Makefile.am
+
+command_ok_ "aclocal" $ACLOCAL
+# Both these two invocations are meant.
+# They exercise both code paths concerning auxiliary files.
+command_ok_ "automake -a" -D TODO -r "long-standing limitation" $AUTOMAKE -a
+command_ok_ "automake" -D TODO -r "long-standing limitation" $AUTOMAKE
+
+:
diff --git a/t/auxdir-misplaced.sh b/t/auxdir-misplaced.sh
new file mode 100644
index 000000000..fb2cc7b01
--- /dev/null
+++ b/t/auxdir-misplaced.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure we diagnose misplaced AC_CONFIG_AUX_DIR.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_AUX_DIR([.]) dnl this will appear after AM_INIT_AUTOMAKE
+END
+
+: > Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'AC_CONFIG_AUX_DIR.*AM_INIT_AUTOMAKE' stderr
+
+:
diff --git a/t/auxdir-nonexistent.sh b/t/auxdir-nonexistent.sh
new file mode 100644
index 000000000..f7a5620f8
--- /dev/null
+++ b/t/auxdir-nonexistent.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we diagnose non-existent AC_CONFIG_AUX_DIR names.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([nonesuch])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+: > Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^configure\.ac:2:.*nonesuch.* not exist' stderr
+
+:
diff --git a/t/auxdir-pr15981.sh b/t/auxdir-pr15981.sh
new file mode 100644
index 000000000..282867159
--- /dev/null
+++ b/t/auxdir-pr15981.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2014-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# AM_AUX_DIR_EXPAND should ensure $ac_aux_dir is properly initialized.
+# Issue revealed by related automake bug#15981.
+
+. test-init.sh
+
+cat > configure.ac <<'END'
+AC_INIT([test], [0.0])
+AM_AUX_DIR_EXPAND
+printf '%s\n' "ac_aux_dir: '$ac_aux_dir'"
+printf '%s\n' "am_aux_dir: '$am_aux_dir'"
+test "$ac_aux_dir" = . || AS_EXIT([1])
+test "$am_aux_dir" = "`pwd`" || AS_EXIT([1])
+AS_EXIT([0])
+END
+
+$ACLOCAL
+$AUTOCONF
+
+test -f install-sh # sanity check
+
+./configure
+
+:
diff --git a/t/auxdir-pr19311.sh b/t/auxdir-pr19311.sh
new file mode 100644
index 000000000..61970cef7
--- /dev/null
+++ b/t/auxdir-pr19311.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2014-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automake bug#19311: AC_PROG_CC called before AC_CONFIG_AUX_DIR can
+# silently force wrong $ac_aux_dir definition.
+
+am_create_testdir=empty
+required=cc
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_PROG_CC
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE
+AC_OUTPUT([Makefile])
+END
+
+: > Makefile.am
+
+mkdir build-aux
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+test -f build-aux/compile
+test -f build-aux/install-sh
+
+./configure
+
+:
diff --git a/t/auxdir-unportable.tap b/t/auxdir-unportable.tap
new file mode 100644
index 000000000..1d21f5e07
--- /dev/null
+++ b/t/auxdir-unportable.tap
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we diagnose unportable AC_CONFIG_AUX_DIR names.
+
+. test-init.sh
+
+plan_ 4
+
+cat >configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([aux])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+: > Makefile.am
+
+am_warn_unportable_auxdir ()
+{
+ details=$1
+ AUTOMAKE_fails
+ command_ok_ \
+ "warn about $details unportable auxdir name" \
+ grep '^configure\.ac:2:.*aux.*W32' stderr
+}
+
+$ACLOCAL || fatal_ "aclocal failed"
+
+am_warn_unportable_auxdir "non-existent"
+
+if mkdir aux; then
+ am_warn_unportable_auxdir "existent"
+else
+ skip_row_ 2 -r "cannot create directory named 'aux'"
+fi
+
+:
diff --git a/t/auxdir.sh b/t/auxdir.sh
new file mode 100644
index 000000000..f3dc58571
--- /dev/null
+++ b/t/auxdir.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure AC_CONFIG_AUX_DIR works correctly.
+
+. test-init.sh
+
+# The "./." is here so we don't have to mess with subdirs.
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([./.])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+cat > Makefile.am << 'END'
+pkgdata_DATA =
+END
+
+cp "$am_scriptdir/mkinstalldirs" .
+
+# The "././" prefix confuses Automake into thinking it is doing a
+# subdir build. Yes, this is hacky.
+$ACLOCAL
+$AUTOMAKE ././Makefile
+
+grep '/\./\./mkinstalldirs' Makefile.in
+
+:
diff --git a/t/auxdir6.sh b/t/auxdir6.sh
new file mode 100644
index 000000000..964755ef4
--- /dev/null
+++ b/t/auxdir6.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure AC_CONFIG_AUX_DIR works correctly.
+# This test calls AC_CONFIG_AUX_DIR with an explicit literal argument,
+# thus explicitly making the directory named by that argument the
+# config auxdir.
+# Keep this in sync with sister tests 'auxdir7.sh' and 'auxdir8.sh'.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([auxdir])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile subdir/Makefile])
+END
+
+mkdir subdir auxdir
+
+cat > Makefile.am << 'END'
+pkgdata_DATA =
+END
+
+cp Makefile.am subdir/Makefile.am
+
+: > auxdir/mkinstalldirs
+: > auxdir/install-sh
+: > auxdir/missing
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP '$(top_srcdir)/auxdir/mkinstalldirs' Makefile.in
+$FGREP '$(top_srcdir)/auxdir/mkinstalldirs' subdir/Makefile.in
+
+:
diff --git a/t/auxdir7.sh b/t/auxdir7.sh
new file mode 100644
index 000000000..3dcf6e0bf
--- /dev/null
+++ b/t/auxdir7.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure AC_CONFIG_AUX_DIR works correctly.
+# This test calls AC_CONFIG_AUX_DIR with a '.' argument, thus explicitly
+# making the top-level directory the config auxdir.
+# Keep this in sync with sister tests 'auxdir6.sh' and 'auxdir8.sh'.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([.])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile subdir/Makefile])
+END
+
+mkdir subdir
+
+cat > Makefile.am << 'END'
+pkgdata_DATA =
+END
+
+cp Makefile.am subdir/Makefile.am
+
+: > mkinstalldirs
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP '$(top_srcdir)/mkinstalldirs' Makefile.in
+$FGREP '$(top_srcdir)/mkinstalldirs' subdir/Makefile.in
+
+:
diff --git a/t/auxdir8.sh b/t/auxdir8.sh
new file mode 100644
index 000000000..8e584604a
--- /dev/null
+++ b/t/auxdir8.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure AC_CONFIG_AUX_DIR works correctly.
+# This test tries without an explicit call to AC_CONFIG_AUX_DIR;
+# the config auxdir should be implicitly defined to '.' since
+# the install-sh, mkinstalldirs, etc., scripts are in the top-level
+# directory.
+# Keep this in sync with sister tests 'auxdir6.sh' and 'auxdir7.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([subdir/Makefile])
+END
+
+mkdir subdir
+
+cat > Makefile.am << 'END'
+pkgdata_DATA =
+END
+
+cp Makefile.am subdir/Makefile.am
+
+: > mkinstalldirs
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP '$(top_srcdir)/mkinstalldirs' Makefile.in
+$FGREP '$(top_srcdir)/mkinstalldirs' subdir/Makefile.in
+
+:
diff --git a/t/ax/am-test-lib.sh b/t/ax/am-test-lib.sh
new file mode 100644
index 000000000..3c4bf0120
--- /dev/null
+++ b/t/ax/am-test-lib.sh
@@ -0,0 +1,1063 @@
+# -*- shell-script -*-
+#
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+########################################################
+### IMPORTANT NOTE: keep this file 'set -e' clean. ###
+########################################################
+
+# Do not source several times.
+test ${am_test_lib_sourced-no} = yes && return 0
+am_test_lib_sourced=yes
+
+# A literal escape character. Used by test checking colored output.
+esc=''
+
+# This might be used in testcases checking distribution-related features.
+# Test scripts are free to override this if they need to.
+distdir=$me-1.0
+
+## ---------------------- ##
+## Environment cleanup. ##
+## ---------------------- ##
+
+# Unset some make-related variables that may cause $MAKE to act like
+# a recursively invoked sub-make. Any $MAKE invocation in a test is
+# conceptually an independent invocation, not part of the main
+# 'automake' build.
+unset MFLAGS MAKEFLAGS AM_MAKEFLAGS MAKELEVEL
+unset __MKLVL__ MAKE_JOBS_FIFO # For BSD make.
+unset DMAKE_CHILD DMAKE_DEF_PRINTED DMAKE_MAX_JOBS # For Solaris dmake.
+# Unset verbosity flag.
+unset V
+# Also unset variables that might influence "make install".
+unset DESTDIR
+unset prefix exec_prefix bindir datarootdir datadir docdir dvidir
+unset htmldir includedir infodir libdir libexecdir localedir mandir
+unset oldincludedir pdfdir psdir sbindir sharedstatedir sysconfdir
+# Unset variables that might influence "make distcheck".
+unset DISTCHECK_CONFIGURE_FLAGS AM_DISTCHECK_CONFIGURE_FLAGS
+# Used by install rules for info files.
+unset AM_UPDATE_INFO_DIR
+# We don't want to use the $srcdir value exported by the test driver.
+unset srcdir
+# Also unset variables that control our test driver. While not
+# conceptually independent, they cause some changed semantics we
+# need to control (and test for) in some of the tests to ensure
+# backward-compatible behavior.
+unset TESTS_ENVIRONMENT AM_TESTS_ENVIRONMENT
+unset DISABLE_HARD_ERRORS
+unset AM_COLOR_TESTS
+unset TESTS
+unset XFAIL_TESTS
+unset TEST_LOGS
+unset TEST_SUITE_LOG
+unset RECHECK_LOGS
+unset VERBOSE
+for pfx in TEST_ SH_ TAP_ ''; do
+ unset ${pfx}LOG_COMPILER
+ unset ${pfx}LOG_COMPILE # Not a typo!
+ unset ${pfx}LOG_FLAGS
+ unset AM_${pfx}LOG_FLAGS
+ unset ${pfx}LOG_DRIVER
+ unset ${pfx}LOG_DRIVER_FLAGS
+ unset AM_${pfx}LOG_DRIVER_FLAGS
+done
+unset pfx
+
+# cross_compiling
+# ---------------
+# Tell whether we are cross-compiling. This is especially useful to skip
+# tests (or portions of them) that requires a native compiler.
+cross_compiling ()
+{
+ # Quoting from the autoconf manual:
+ # ... [$host_alias and $build both] default to the result of running
+ # config.guess, unless you specify either --build or --host. In
+ # this case, the default becomes the system type you specified.
+ # If you specify both, *and they're different*, configure enters
+ # cross compilation mode (so it doesn't run any tests that require
+ # execution).
+ test x"$host_alias" != x && test x"$build_alias" != x"$host_alias"
+}
+
+# is_blocked_signal SIGNAL-NUMBER
+# --------------------------------
+# Return success if the given signal number is blocked in the shell,
+# return a non-zero exit status and print a proper diagnostic otherwise.
+is_blocked_signal ()
+{
+ # Use perl, since trying to do this portably in the shell can be
+ # very tricky, if not downright impossible. For reference, see:
+ # <https://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
+ if $PERL -w -e '
+ use strict;
+ use warnings FATAL => "all";
+ use POSIX;
+ my %oldsigaction = ();
+ sigaction('"$1"', 0, \%oldsigaction);
+ exit ($oldsigaction{"HANDLER"} eq "IGNORE" ? 0 : 77);
+ '; then
+ return 0
+ elif test $? -eq 77; then
+ return 1
+ else
+ fatal_ "couldn't determine whether signal $1 is blocked"
+ fi
+}
+
+# single_quote STRING
+# -------------------
+# Single-quote STRING for the shell, also dealing with embedded single
+# quotes. Place the result in the '$am_result', that is thus to be
+# considered public.
+single_quote ()
+{
+ am_result=$1
+ case $am_result in
+ *\'*) am_result=$(printf '%s\n' "$*" | sed -e "s/'/'\\\\''/g");;
+ esac
+ am_result="'$am_result'"
+}
+
+# append_single_quoted VARIABLE STRING
+# ------------------------------------
+append_single_quoted ()
+{
+ am__var=$1; shift
+ single_quote "$1" # Sets 'am_result'.
+ eval "${am__var}=\${$am__var:+\"\${$am__var} \"}\$am_result"
+ unset am__var am_result
+}
+
+# is_valid_varname STRING
+# -----------------------
+# Tell whether STRING is a valid name for a shell variable. Return 0
+# if yes, return 1 if not.
+is_valid_varname ()
+{
+ # FIXME: is the below truly portable even for LC_COLLATE != "C" ?
+ case $1 in
+ [0-9]*) return 1;;
+ *[!a-zA-Z0-9_]*) return 1;;
+ esac
+ return 0
+}
+
+# run_make [-e STATUS] [-O] [-E] [-M] [--] [VAR=VAL ...] [MAKE-ARGS...]
+# ---------------------------------------------------------------------
+#
+# Run $MAKE with the given command-line, and fail if it doesn't exit with
+# STATUS (default: 0). If STATUS is "FAIL", then any exit status > 0 is
+# acceptable. If STATUS is "IGNORE", any exit value is acceptable.
+#
+# Other options:
+#
+# -O save the standard output from make on disk, in a regular file
+# named 'stdout'.
+#
+# -E save the standard error from make on disk, in a regular file
+# named 'stderr'.
+#
+# -M save both the standard output and standard error from make on
+# disk, in a regular file named 'output'. This option supersedes
+# both the '-O' and '-E' options.
+#
+# This function also handle command-line override of variable definition
+# in a smart way, using AM_MAKEFLAGS if a non-GNU make implementation
+# is in use.
+#
+run_make ()
+{
+ am__make_redirect_stdout=no
+ am__make_redirect_stderr=no
+ am__make_redirect_stdall=no
+ am__make_flags=
+ am__make_rc_exp=0
+ # Follow-up code might want to analyse this, so mark is as
+ # publicly accessible (no double undesrscore).
+ am_make_rc=0
+ # Parse options for this function.
+ while test $# -gt 0; do
+ case $1 in
+ -e) am__make_rc_exp=$2; shift;;
+ -O) am__make_redirect_stdout=yes;;
+ -E) am__make_redirect_stderr=yes;;
+ -M) am__make_redirect_stdall=yes;;
+ --) shift; break;;
+ *) break;;
+ esac
+ shift
+ done
+
+ # Use append mode here to avoid dropping output. See automake bug#11413
+ if using_gmake; then
+ # We can trust GNU make to correctly pass macro definitions given
+ # on the command line down to sub-make invocations, and this allow
+ # us to have a vary simple implementation: delegate all the work
+ # to GNU make.
+ :
+ else
+ # We have to explicitly parse arguments passed to make. Not 100%
+ # safe w.r.t. options like '-I' that can have an argument, but
+ # should be good enough for our usages so far.
+ for am__x
+ do
+ case $am__x in
+ *=*)
+ am__maybe_var=${am__x%%=*}
+ am__maybe_val=${am__x#*=}
+ am__maybe_def="${am__maybe_var}=${am__maybe_val}"
+ # Some variables should be portably overridable from the command
+ # line, even when using non-GNU make.
+ case $am__maybe_var in
+ V|\
+ DESTDIR|\
+ SHELL|\
+ VERBOSE|\
+ DISABLE_HARD_ERRORS|\
+ DISTCHECK_CONFIGURE_FLAGS)
+ ;;
+ *)
+ if is_valid_varname "$am__maybe_var"; then
+ append_single_quoted am__make_flags "$am__maybe_def"
+ fi
+ esac
+ unset am__maybe_var am__maybe_val am__maybe_def
+ ;;
+ esac
+ done
+ unset am__x
+ fi
+
+ if test x"$am__make_flags" != x; then
+ set AM_MAKEFLAGS="$am__make_flags" ${1+"$@"}
+ unset am__make_flags
+ fi
+
+ # In redirecting make output below, use append mode, to avoid
+ # dropping output. See automake bug#11413 for details.
+ # The exit status of 253 is a more-or-less random choice, to
+ # help us catch possible errors in redirections and error out
+ # accordingly.
+ (
+ : exec $MAKE ${1+"$@"} # Display traces for future command.
+ set +x # We need to remove them now, not to pollute redirected stderr.
+ if test $am__make_redirect_stdall = yes; then
+ : > output && exec 1>>output 2>&1 || exit 253
+ else
+ if test $am__make_redirect_stdout = yes; then
+ : > stdout && exec 1>>stdout || exit 253
+ fi
+ if test $am__make_redirect_stderr = yes; then
+ : > stderr && exec 2>>stderr || exit 253
+ fi
+ fi
+ exec $MAKE ${1+"$@"}
+ ) || am_make_rc=$?
+
+ if test $am_make_rc -eq 253; then
+ fatal_ "run_make: problems in redirecting make output"
+ fi
+
+ if test $am__make_redirect_stdall = yes; then
+ cat output || fatal_ "displaying make output"
+ else
+ if test $am__make_redirect_stdout = yes; then
+ cat stdout || fatal_ "displaying make output"
+ fi
+ if test $am__make_redirect_stderr = yes; then
+ cat stderr >&2 || fatal_ "displaying make output"
+ fi
+ fi
+
+ case $am__make_rc_exp in
+ IGNORE)
+ : Ignore exit status
+ ;;
+ FAIL)
+ test $am_make_rc -gt 0 || return 1
+ ;;
+ *)
+ test $am__make_rc_exp -ge 0 && test $am__make_rc_exp -le 255 \
+ || fatal_ "invalid expected exit status: '$am__make_rc_exp'"
+ test $am_make_rc -eq $am__make_rc_exp || return 1
+ ;;
+ esac
+}
+
+# AUTOMAKE_run [-e STATUS] [-d DESCRIPTION] [--] [AUTOMAKE-ARGS...]
+# -----------------------------------------------------------------
+# Run automake with AUTOMAKE-ARGS, and fail if it doesn't exit with
+# STATUS. Should be polymorphic for TAP and "plain" tests. The
+# DESCRIPTION, when provided, is used for console reporting, only if
+# the TAP protocol is in use in the current test script.
+AUTOMAKE_run ()
+{
+ am__desc=
+ am__exp_rc=0
+ while test $# -gt 0; do
+ case $1 in
+ -d) am__desc=$2; shift;;
+ -e) am__exp_rc=$2; shift;;
+ --) shift; break;;
+ # Don't fail on unknown option: assume they (and the rest of the
+ # command line) are to be passed verbatim to automake (so stop our
+ # own option parsing).
+ *) break;;
+ esac
+ shift
+ done
+ am__got_rc=0
+ $AUTOMAKE ${1+"$@"} >stdout 2>stderr || am__got_rc=$?
+ cat stderr >&2
+ cat stdout
+ if test $am_test_protocol = none; then
+ test $am__got_rc -eq $am__exp_rc || exit 1
+ return
+ fi
+ if test -z "$am__desc"; then
+ if test $am__got_rc -eq $am__exp_rc; then
+ am__desc="automake exited $am__got_rc"
+ else
+ am__desc="automake exited $am__got_rc, expecting $am__exp_rc"
+ fi
+ fi
+ command_ok_ "$am__desc" test $am__got_rc -eq $am__exp_rc
+}
+
+# AUTOMAKE_fails [-d DESCRIPTION] [OPTIONS...]
+# --------------------------------------------
+# Run automake with OPTIONS, and fail if doesn't exit with status 1.
+# Should be polymorphic for TAP and "plain" tests. The DESCRIPTION,
+# when provided, is used for console reporting, only if the TAP
+# protocol is in use in the current test script.
+AUTOMAKE_fails ()
+{
+ AUTOMAKE_run -e 1 ${1+"$@"}
+}
+
+# extract_configure_help { --OPTION | VARIABLE-NAME } [FILES]
+# -----------------------------------------------------------
+# Use this to extract from the output of "./configure --help" (or similar)
+# the description or help message associated to the given --OPTION or
+# VARIABLE-NAME.
+extract_configure_help ()
+{
+ am__opt_re='' am__var_re=''
+ case $1 in
+ --*'=') am__opt_re="^ $1";;
+ --*'[=]') am__opt_re='^ '$(printf '%s\n' "$1" | sed 's/...$//')'\[=';;
+ --*) am__opt_re="^ $1( .*|$)";;
+ *) am__var_re="^ $1( .*|$)";;
+ esac
+ shift
+ if test x"$am__opt_re" != x; then
+ LC_ALL=C awk '
+ /'"$am__opt_re"'/ { print; do_print = 1; next; }
+ /^$/ { do_print = 0; next }
+ /^ --/ { do_print = 0; next }
+ (do_print == 1) { print }
+ ' ${1+"$@"}
+ else
+ LC_ALL=C awk '
+ /'"$am__var_re"'/ { print; do_print = 1; next; }
+ /^$/ { do_print = 0; next }
+ /^ [A-Z][A-Z0-9_]* / { do_print = 0; next }
+ /^ [A-Z][A-Z0-9_]*$/ { do_print = 0; next }
+ (do_print == 1) { print }
+ ' ${1+"$@"}
+ fi
+}
+
+# grep_configure_help { --OPTION | VARIABLE-NAME } REGEXP
+# -------------------------------------------------------
+# Grep the section of "./configure --help" output associated with either
+# --OPTION or VARIABLE-NAME for the given *extended* regular expression.
+grep_configure_help ()
+{
+ ./configure --help > am--all-help \
+ || { cat am--all-help; exit 1; }
+ cat am--all-help
+ extract_configure_help "$1" am--all-help > am--our-help \
+ || { cat am--our-help; exit 1; }
+ cat am--our-help
+ $EGREP "$2" am--our-help || exit 1
+}
+
+# using_gmake
+# -----------
+# Return success if $MAKE is GNU make, return failure otherwise.
+# Caches the result for speed reasons.
+using_gmake ()
+{
+ case $am__using_gmake in
+ yes)
+ return 0;;
+ no)
+ return 1;;
+ '')
+ # Use --version AND -v, because SGI Make doesn't fail on --version.
+ # Also grep for GNU because newer versions of FreeBSD make do
+ # not complain about --version (they seem to silently ignore it).
+ if $MAKE --version -v | grep GNU; then
+ am__using_gmake=yes
+ return 0
+ else
+ am__using_gmake=no
+ return 1
+ fi;;
+ *)
+ fatal_ "invalid value for \$am__using_gmake: '$am__using_gmake'";;
+ esac
+}
+am__using_gmake="" # Avoid interferences from the environment.
+
+# make_can_chain_suffix_rules
+# ---------------------------
+# Return 0 if $MAKE is a make implementation that can chain suffix rules
+# automatically, return 1 otherwise. Caches the result for speed reasons.
+make_can_chain_suffix_rules ()
+{
+ if test -z "$am__can_chain_suffix_rules"; then
+ if using_gmake; then
+ am__can_chain_suffix_rules=yes
+ return 0
+ else
+ mkdir am__chain.dir$$
+ cd am__chain.dir$$
+ unindent > Makefile << 'END'
+ .SUFFIXES: .u .v .w
+ .u.v: ; cp $< $@
+ .v.w: ; cp $< $@
+END
+ echo make can chain suffix rules > foo.u
+ if $MAKE foo.w && diff foo.u foo.w; then
+ am__can_chain_suffix_rules=yes
+ else
+ am__can_chain_suffix_rules=no
+ fi
+ cd ..
+ rm -rf am__chain.dir$$
+ fi
+ fi
+ case $am__can_chain_suffix_rules in
+ yes) return 0;;
+ no) return 1;;
+ *) fatal_ "make_can_chain_suffix_rules: internal error";;
+ esac
+}
+am__can_chain_suffix_rules="" # Avoid interferences from the environment.
+
+# useless_vpath_rebuild
+# ---------------------
+# Tell whether $MAKE suffers of the bug triggering automake bug#7884.
+# For example, this happens with FreeBSD make, since in a VPATH build
+# it tends to rebuilt files for which there is an explicit or even just
+# a suffix rule, even if said files are already available in the VPATH
+# directory.
+useless_vpath_rebuild ()
+{
+ if test -z "$am__useless_vpath_rebuild"; then
+ if using_gmake; then
+ am__useless_vpath_rebuild=no
+ return 1
+ fi
+ mkdir am__vpath.dir$$
+ cd am__vpath.dir$$
+ touch foo.a foo.b bar baz
+ mkdir build
+ cd build
+ unindent > Makefile << 'END'
+ .SUFFIXES: .a .b
+ VPATH = ..
+ all: foo.b baz
+ .PHONY: all
+ .a.b: ; cp $< $@
+ baz: bar ; cp ../baz bar
+END
+ if run_make all && test ! -e foo.b && test ! -e bar; then
+ am__useless_vpath_rebuild=no
+ else
+ am__useless_vpath_rebuild=yes
+ fi
+ cd ../..
+ rm -rf am__vpath.dir$$
+ fi
+ case $am__useless_vpath_rebuild in
+ yes) return 0;;
+ no) return 1;;
+ "") ;;
+ *) fatal_ "useless_vpath_rebuild: internal error";;
+ esac
+}
+am__useless_vpath_rebuild=""
+
+yl_distcheck () { useless_vpath_rebuild || run_make distcheck ${1+"$@"}; }
+
+null_install ()
+{
+ for am__v in nulldirs destdir instdir; do
+ if ! eval 'test -n "$'$am__v'"'; then
+ fatal_ "null_install() invoked with \$$am__v unset"
+ fi
+ done
+ unset am__v
+ case $#,$1 in
+ 0,)
+ am__inst='install';;
+ 1,-t|1,--texi)
+ am__inst='install install-html install-dvi install-ps install-pdf';;
+ *)
+ fatal_ "null_install(): invalid usage";;
+ esac
+ run_make $nulldirs $am__inst
+ test ! -e "$instdir"
+ run_make $nulldirs $am__inst DESTDIR="$destdir"
+ test ! -e "$instdir"
+ test ! -e "$destdir"
+ run_make -M $nulldirs uninstall
+ # Creative quoting below to please maintainer-check.
+ grep 'rm'' ' output && exit 1
+ run_make -M $nulldirs uninstall DESTDIR="$destdir"
+ # Creative quoting below to please maintainer-check.
+ grep 'rm'' ' output && exit 1
+ : # For 'set -e'.
+}
+
+# count_test_results total=N pass=N fail=N xpass=N xfail=N skip=N error=N
+# -----------------------------------------------------------------------
+# Check that a testsuite run driven by the parallel-tests harness has
+# had the specified numbers of test results (specified by kind).
+# This function assumes that the output of "make check" or "make recheck"
+# has been saved in the 'stdout' file in the current directory, and its
+# log in the 'test-suite.log' file.
+count_test_results ()
+{
+ # Use a subshell so that we won't pollute the script namespace.
+ (
+ # TODO: Do proper checks on the arguments?
+ total=ERR pass=ERR fail=ERR xpass=ERR xfail=ERR skip=ERR error=ERR
+ eval "$@"
+ # For debugging.
+ $EGREP -i '(total|x?pass|x?fail|skip|error)' stdout || :
+ rc=0
+ # Avoid spurious failures with shells with "overly sensible"
+ # errexit shell flag, such as e.g., Solaris /bin/sh.
+ set +e
+ test $(grep -c '^PASS:' stdout) -eq $pass || rc=1
+ test $(grep -c '^XFAIL:' stdout) -eq $xfail || rc=1
+ test $(grep -c '^SKIP:' stdout) -eq $skip || rc=1
+ test $(grep -c '^FAIL:' stdout) -eq $fail || rc=1
+ test $(grep -c '^XPASS:' stdout) -eq $xpass || rc=1
+ test $(grep -c '^ERROR:' stdout) -eq $error || rc=1
+ grep "^# TOTAL: *$total$" stdout || rc=1
+ grep "^# PASS: *$pass$" stdout || rc=1
+ grep "^# XFAIL: *$xfail$" stdout || rc=1
+ grep "^# SKIP: *$skip$" stdout || rc=1
+ grep "^# FAIL: *$fail$" stdout || rc=1
+ grep "^# XPASS: *$xpass$" stdout || rc=1
+ grep "^# ERROR: *$error$" stdout || rc=1
+ test $rc -eq 0
+ )
+}
+
+# get_shell_script SCRIPT-NAME
+# -----------------------------
+# Fetch an Automake-provided shell script from the 'lib/' directory into
+# the current directory, and, if the '$am_test_prefer_config_shell'
+# variable is set to "yes", modify its shebang line to use $SHELL instead
+# of /bin/sh.
+get_shell_script ()
+{
+ am_source=$1 am_target=${2-$1}
+ test ! -f "$am_target" || rm -f "$am_target" || return 99
+ if test x"$am_test_prefer_config_shell" = x"yes"; then
+ sed "1s|#!.*|#! $SHELL|" "$am_scriptdir/$am_source" > "$am_target" \
+ && chmod a+x "$am_target" \
+ || return 99
+ else
+ cp -f "$am_scriptdir/$am_source" "$am_target" || return 99
+ fi
+ sed 10q "$am_target" # For debugging.
+ unset am_target am_source
+}
+
+# fetch_tap_driver
+# ----------------
+# Fetch the Automake-provided TAP driver from the 'lib/' directory into
+# the current directory, and edit its shebang line so that it will be
+# run with the proper shell.
+fetch_tap_driver ()
+{
+ AM_TAP_AWK=$AWK; export AM_TAP_AWK
+ get_shell_script tap-driver.sh tap-driver
+}
+
+
+# require_xsi SHELL
+# -----------------
+# Skip the test if the given shell fails to support common XSI constructs.
+require_xsi ()
+{
+ test $# -eq 1 || fatal_ "require_xsi needs exactly one argument"
+ echo "$me: trying some XSI constructs with $1"
+ $1 -c "$xsi_shell_code" || skip_all_ "$1 lacks XSI features"
+}
+# Shell code supposed to work only with XSI shells. Keep this in sync
+# with libtool.m4:_LT_CHECK_SHELL_FEATURES.
+xsi_shell_code='
+ _lt_dummy="a/b/c"
+ test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
+ = c,a/b,b/c, \
+ && eval '\''test $(( 1 + 1 )) -eq 2 \
+ && test "${#_lt_dummy}" -eq 5'\'
+
+# $PYTHON and support for PEP-3147. Needed to check our python-related
+# install rules.
+python_has_pep3147 ()
+{
+ if test -z "$am_pep3147_tag"; then
+ am_pep3147_tag=$($PYTHON -c 'import imp; print(imp.get_tag())') \
+ || am_pep3147_tag=none
+ fi
+ test $am_pep3147_tag != none
+}
+am_pep3147_tag=
+
+# pyc_location [-p] [FILE]
+# ------------------------
+# Determine what the actual location of the given '.pyc' or '.pyo'
+# byte-compiled file should be, taking into account PEP-3147. Save
+# the location in the '$am_pyc_file' variable. If the '-p' option
+# is given, print the location on the standard output as well.
+pyc_location ()
+{
+ case $#,$1 in
+ 2,-p) am_pyc_print=yes; shift;;
+ 1,*) am_pyc_print=no;;
+ *) fatal_ "pyc_location: invalid usage";;
+ esac
+ if python_has_pep3147; then
+ case $1 in
+ */*) am_pyc_dir=${1%/*} am_pyc_base=${1##*/};;
+ *) am_pyc_dir=. am_pyc_base=$1;;
+ esac
+ am_pyc_ext=${am_pyc_base##*.}
+ am_pyc_base=${am_pyc_base%.py?}
+ am_pyc_file=$am_pyc_dir/__pycache__/$am_pyc_base.$am_pep3147_tag.$am_pyc_ext
+ else
+ am_pyc_file=$1
+ fi
+ test $am_pyc_print = no || printf '%s\n' "$am_pyc_file"
+}
+
+# py_installed [--not] FILE
+# --------------------------
+# Check that the given python FILE has been installed (resp. *not*
+# installed, if the '--not' option is specified). If FILE is a
+# byte-compiled '.pyc' file, the new installation layout specified
+# by PEP-3147 will be taken into account.
+py_installed ()
+{
+ case $#,$1 in
+ 1,*) am_test_py_file='test -f';;
+ 2,--not) am_test_py_file='test ! -e'; shift;;
+ *) fatal_ "pyc_installed: invalid usage";;
+ esac
+ case $1 in
+ *.py[co]) pyc_location "$1"; am_target_py_file=$am_pyc_file;;
+ *) am_target_py_file=$1;;
+ esac
+ $am_test_py_file "$am_target_py_file"
+}
+
+# Usage: require_compiler_ {cc|c++|fortran|fortran77}
+require_compiler_ ()
+{
+ case $# in
+ 0) fatal_ "require_compiler_: missing argument";;
+ 1) ;;
+ *) fatal_ "require_compiler_: too many arguments";;
+ esac
+ case $1 in
+ cc)
+ am__comp_lang="C"
+ am__comp_var=CC
+ am__comp_flag_vars='CFLAGS CPPFLAGS'
+ ;;
+ c++)
+ am__comp_lang="C++"
+ am__comp_var=CXX
+ am__comp_flag_vars='CXXFLAGS CPPFLAGS'
+ ;;
+ fortran)
+ am__comp_lang="Fortran"
+ am__comp_var=FC
+ am__comp_flag_vars='FCFLAGS'
+ ;;
+ fortran77)
+ am__comp_lang="Fortran 77"
+ am__comp_var=F77
+ am__comp_flag_vars='FFLAGS'
+ ;;
+ esac
+ shift
+ eval "am__comp_prog=\${$am__comp_var}" \
+ || fatal_ "expanding \${$am__comp_var} in require_compiler_"
+ case $am__comp_prog in
+ "")
+ fatal_ "botched configuration: \$$am__comp_var is empty";;
+ false)
+ skip_all_ "no $am__comp_lang compiler available";;
+ autodetect|autodetected)
+ # Let the ./configure commands in the test script try to determine
+ # these automatically.
+ unset $am__comp_var $am__comp_flag_vars;;
+ *)
+ # Pre-set these for the ./configure commands in the test script.
+ export $am__comp_var $am__comp_flag_vars;;
+ esac
+ # Delete private variables.
+ unset am__comp_lang am__comp_prog am__comp_var am__comp_flag_vars
+}
+
+## ----------------------------------------------------------- ##
+## Checks for required tools, and additional setups (if any) ##
+## required by them. ##
+## ----------------------------------------------------------- ##
+
+require_tool ()
+{
+ am_tool=$1
+ case $1 in
+ cc|c++|fortran|fortran77)
+ require_compiler_ $1;;
+ -c-o)
+ if test x"$AM_TESTSUITE_SIMULATING_NO_CC_C_O" = x"yes"; then
+ skip_all_ "need a C compiler that grasps -c and -o together"
+ fi
+ ;;
+ xsi-lib-shell)
+ if test x"$am_test_prefer_config_shell" = x"yes"; then
+ require_xsi "$SHELL"
+ else
+ require_xsi "/bin/sh"
+ fi
+ ;;
+ bzip2)
+ # Do not use --version, older versions bzip2 still tries to compress
+ # stdin.
+ echo "$me: running bzip2 --help"
+ bzip2 --help \
+ || skip_all_ "required program 'bzip2' not available"
+ ;;
+ cl)
+ CC=cl
+ # Don't export CFLAGS, as that could have been initialized to only
+ # work with the C compiler detected at configure time. If the user
+ # wants CFLAGS to also influence 'cl', he can still export CFLAGS
+ # in the environment "by hand" before calling the testsuite.
+ export CC CPPFLAGS
+ echo "$me: running $CC -?"
+ # The IRAF package (http://iraf.noao.edu/) contains a 'cl' program
+ # which is interactive, and which could cause the testsuite to hang
+ # if its standard input is not redirected. See automake bug#14707.
+ $CC -? </dev/null \
+ || skip_all_ "Microsoft C compiler '$CC' not available"
+ ;;
+ icl)
+ CC=icl
+ # Don't export CFLAGS, as that could have been initialized to only
+ # work with the C compiler detected at configure time. If the user
+ # wants CFLAGS to also influence 'icl', he can still export CFLAGS
+ # in the environment "by hand" before calling the testsuite.
+ export CC CPPFLAGS
+ echo "$me: running $CC -?"
+ $CC -? >/dev/null \
+ || skip_all_ "Intel C compiler '$CC' not available"
+ ;;
+ etags)
+ # Exuberant Ctags will create a TAGS file even
+ # when asked for --help or --version. (Emacs's etags
+ # does not have such problem.) Use -o /dev/null
+ # to make sure we do not pollute the build directory.
+ echo "$me: running etags --version -o /dev/null"
+ etags --version -o /dev/null \
+ || skip_all_ "required program 'etags' not available"
+ ;;
+ GNUmake)
+ for am_make in "$MAKE" gmake gnumake :; do
+ MAKE=$am_make
+ am__using_gmake= # Invalidate cache used by 'using_gmake()'.
+ test "$MAKE" = : && break
+ echo "$me: determine whether $MAKE is GNU make"
+ using_gmake && break
+ : For shells with busted 'set -e'.
+ done
+ test "$MAKE" = : && skip_all_ "this test requires GNU make"
+ export MAKE
+ unset am_make
+ ;;
+ gcj)
+ GCJ=$GNU_GCJ GCJFLAGS=$GNU_GCJFLAGS; export GCJ GCJFLAGS
+ test "$GCJ" = false && skip_all_ "GNU Java compiler unavailable"
+ : For shells with busted 'set -e'.
+ ;;
+ gcc)
+ CC=$GNU_CC CFLAGS=$GNU_CFLAGS; export CC CFLAGS CPPFLAGS
+ test "$CC" = false && skip_all_ "GNU C compiler unavailable"
+ : For shells with busted 'set -e'.
+ ;;
+ g++)
+ CXX=$GNU_CXX CXXFLAGS=$GNU_CXXFLAGS; export CXX CXXFLAGS CPPFLAGS
+ test "$CXX" = false && skip_all_ "GNU C++ compiler unavailable"
+ : For shells with busted 'set -e'.
+ ;;
+ gfortran)
+ FC=$GNU_FC FCFLAGS=$GNU_FCFLAGS; export FC FCFLAGS
+ test "$FC" = false && skip_all_ "GNU Fortran compiler unavailable"
+ case " $required " in
+ *\ g77\ *) ;;
+ *) F77=$FC FFLAGS=$FCFLAGS; export F77 FFLAGS;;
+ esac
+ ;;
+ g77)
+ F77=$GNU_F77 FFLAGS=$GNU_FFLAGS; export F77 FFLAGS
+ test "$F77" = false && skip_all_ "GNU Fortran 77 compiler unavailable"
+ case " $required " in
+ *\ gfortran\ *) ;;
+ *) FC=$F77 FCFLAGS=$FFLAGS; export FC FCFLAGS;;
+ esac
+ ;;
+ grep-nonprint)
+ # Check that grep can parse nonprinting characters correctly.
+ # BSD 'grep' works from a pipe, but not a seekable file.
+ # GNU or BSD 'grep -a' works on files, but is not portable.
+ case $(echo "$esc" | grep .)$(echo "$esc" | grep "$esc") in
+ "$esc$esc") ;;
+ *) skip_ "grep can't handle nonprinting characters correctly";;
+ esac
+ ;;
+ javac)
+ # The Java compiler from JDK 1.5 (and presumably earlier versions)
+ # cannot handle the '-version' option by itself: it bails out
+ # telling that source files are missing. Adding also the '-help'
+ # option seems to solve the problem.
+ echo "$me: running javac -version -help"
+ javac -version -help || skip_all_ "Sun Java compiler not available"
+ ;;
+ java)
+ # See the comments above about 'javac' for why we use also '-help'.
+ echo "$me: running java -version -help"
+ java -version -help || skip_all_ "Sun Java interpreter not found"
+ ;;
+ lib)
+ AR=lib; export AR
+ # Attempting to create an empty archive will actually not
+ # create the archive, but lib will output its version.
+ echo "$me: running $AR -out:defstest.lib"
+ $AR -out:defstest.lib \
+ || skip_all_ "Microsoft 'lib' utility not available"
+ ;;
+ makedepend)
+ echo "$me: running makedepend -f-"
+ makedepend -f- \
+ || skip_all_ "required program 'makedepend' not available"
+ ;;
+ mingw)
+ uname_s=$(uname -s || echo UNKNOWN)
+ echo "$me: system name: $uname_s"
+ case $uname_s in
+ MINGW*) ;;
+ *) skip_all_ "this test requires MSYS in MinGW mode" ;;
+ esac
+ unset uname_s
+ ;;
+ non-root)
+ # Skip this test case if the user is root.
+ # We try to append to a read-only file to detect this.
+ priv_check_temp=am--priv-check.$$
+ touch $priv_check_temp && chmod a-w $priv_check_temp \
+ || framework_failure_ "creating unwritable file $priv_check_temp"
+ # Not a useless use of subshell: lesser shells might bail
+ # out if a builtin fails.
+ overwrite_status=0
+ (echo foo >> $priv_check_temp) || overwrite_status=$?
+ rm -f $priv_check_temp
+ if test $overwrite_status -eq 0; then
+ skip_all_ "cannot drop file write permissions"
+ fi
+ unset priv_check_temp overwrite_status
+ ;;
+ # Extra quoting required to avoid maintainer-check spurious failures.
+ 'perl-threads')
+ if test "$WANT_NO_THREADS" = "yes"; then
+ skip_all_ "Devel::Cover cannot cope with threads"
+ fi
+ ;;
+ native)
+ # Don't use "&&" here, to avoid a bug of 'set -e' present in
+ # some (even relatively recent) versions of the BSD shell.
+ # We add the dummy "else" branch for extra safety.
+ ! cross_compiling || skip_all_ "doesn't work in cross-compile mode"
+ ;;
+ python)
+ PYTHON=${PYTHON-python}
+ # Older python versions don't support --version, they have -V.
+ echo "$me: running $PYTHON -V"
+ $PYTHON -V || skip_all_ "python interpreter not available"
+ ;;
+ ro-dir)
+ # Skip this test case if read-only directories aren't supported
+ # (e.g., under DOS.)
+ ro_dir_temp=ro_dir.$$
+ mkdir $ro_dir_temp && chmod a-w $ro_dir_temp \
+ || framework_failure_ "creating unwritable directory $ro_dir_temp"
+ # Not a useless use of subshell: lesser shells might bail
+ # out if a builtin fails.
+ create_status=0
+ (: > $ro_dir_temp/probe) || create_status=$?
+ rm -rf $ro_dir_temp
+ if test $create_status -eq 0; then
+ skip_all_ "cannot drop directory write permissions"
+ fi
+ unset ro_dir_temp create_status
+ ;;
+ runtest)
+ # DejaGnu's runtest program. We rely on being able to specify
+ # the program on the runtest command-line. This requires
+ # DejaGnu 1.4.3 or later.
+ echo "$me: running runtest SOMEPROGRAM=someprogram --version"
+ runtest SOMEPROGRAM=someprogram --version \
+ || skip_all_ "DejaGnu is not available"
+ ;;
+ tex)
+ # No all versions of Tex support '--version', so we use
+ # a configure check.
+ if test -z "$TEX"; then
+ skip_all_ "TeX is required, but it wasn't found by configure"
+ fi
+ ;;
+ lex)
+ test x"$LEX" = x"false" && skip_all_ "lex not found or disabled"
+ export LEX
+ ;;
+ yacc)
+ test x"$YACC" = x"false" && skip_all_ "yacc not found or disabled"
+ export YACC
+ ;;
+ flex)
+ LEX=flex; export LEX
+ echo "$me: running flex --version"
+ flex --version || skip_all_ "required program 'flex' not available"
+ ;;
+ bison)
+ YACC='bison -y'; export YACC
+ echo "$me: running bison --version"
+ bison --version || skip_all_ "required program 'bison' not available"
+ ;;
+ valac)
+ echo "$me: running valac --version"
+ if ! valac --version; then
+ skip_all_ "required program 'valac' not available"
+ elif cross_compiling; then
+ skip_all_ "cross-compiling valac-generated C files is brittle"
+ fi
+ # TODO: We also know we need GNU make, the C compiler, and pkg-config
+ # here, but there is no easy way to express this with the current
+ # code organization. We should improve the situation, sooner or
+ # later. At which point the tests requiring 'valac' can drop the
+ # explicit requirements for those tools.
+ ;;
+ *)
+ # Generic case: the tool must support --version.
+ echo "$me: running $1 --version"
+ # It is not likely but possible that the required tool is a special
+ # builtin, in which case the shell is allowed to exit after an error.
+ # So we need the subshell here. Also, some tools, like Sun cscope,
+ # can be interactive without redirection.
+ ($1 --version) </dev/null \
+ || skip_all_ "required program '$1' not available"
+ ;;
+ esac
+}
+
+process_requirements ()
+{
+ # Look for (and maybe set up) required tools and/or system features;
+ # skip the current test if they are not found.
+ for am_tool in $*; do
+ require_tool $am_tool
+ done
+ # We might need extra m4 macros, e.g., for Libtool or Gettext.
+ for am_tool in gettext libtool pkg-config; do
+ case " $required " in
+ # The lack of whitespace after $am_tool is intended.
+ *" $am_tool"*) . ./t/$am_tool-macros.dir/get.sh;;
+ esac
+ done
+ unset am_tool
+}
+
+## ---------------------------------------------------------------- ##
+## Create and set up of the temporary directory used by the test. ##
+## ---------------------------------------------------------------- ##
+
+am_setup_testdir ()
+{
+ # The subdirectory where the current test script will run and write its
+ # temporary/data files. This will be created shortly, and will be removed
+ # by the cleanup trap below if the test passes. If the test doesn't pass,
+ # this directory will be kept, to facilitate debugging.
+ am_test_subdir=${argv0#$am_rel_srcdir/}
+ case $am_test_subdir in
+ */*) am_test_subdir=${am_test_subdir%/*}/$me.dir;;
+ *) am_test_subdir=$me.dir;;
+ esac
+ test ! -e $am_test_subdir || rm_rf_ $am_test_subdir \
+ || framework_failure_ "removing old test subdirectory"
+ $MKDIR_P $am_test_subdir \
+ || framework_failure_ "creating test subdirectory"
+ cd $am_test_subdir \
+ || framework_failure_ "cannot chdir into test subdirectory"
+ if test x"$am_create_testdir" != x"empty"; then
+ cp "$am_scriptdir"/install-sh "$am_scriptdir"/missing \
+ "$am_scriptdir"/compile "$am_scriptdir"/depcomp . \
+ || framework_failure_ "fetching common files from $am_scriptdir"
+ # Build appropriate environment in test directory. E.g., create
+ # configure.ac, touch all necessary files, etc. Don't use AC_OUTPUT,
+ # but AC_CONFIG_FILES so that appending still produces a valid
+ # configure.ac. But then, tests running config.status really need
+ # to append AC_OUTPUT.
+ {
+ echo "AC_INIT([$me], [1.0])"
+ if test x"$am_serial_tests" = x"yes"; then
+ echo "AM_INIT_AUTOMAKE([serial-tests])"
+ else
+ echo "AM_INIT_AUTOMAKE"
+ fi
+ echo "AC_CONFIG_FILES([Makefile])"
+ } >configure.ac || framework_failure_ "creating configure.ac skeleton"
+ fi
+}
+
+am_extra_info ()
+{
+ echo "Running from installcheck: $am_running_installcheck"
+ echo "Test Protocol: $am_test_protocol"
+ echo "PATH = $PATH"
+}
diff --git a/t/ax/cc-no-c-o.in b/t/ax/cc-no-c-o.in
new file mode 100644
index 000000000..fd51482e4
--- /dev/null
+++ b/t/ax/cc-no-c-o.in
@@ -0,0 +1,41 @@
+#! @AM_TEST_RUNNER_SHELL@
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# A "C compiler" that chokes when the '-c' and '-o' options are passed
+# together to it on the command line. See also automake bug#13378.
+
+am_CC=${AM_TESTSUITE_GNU_CC-'@GNU_CC@'}
+
+seen_c=false
+seen_o=false
+
+for arg
+do
+ case $arg in
+ -c)
+ seen_c=true;;
+ # It is acceptable not to leave a space between the '-o' option
+ # and its argument, so we have to cater for that.
+ -o|-o*)
+ seen_o=true;;
+ esac
+ if $seen_c && $seen_o; then
+ echo "$0: both '-o' and '-c' seen on the command line" >&2
+ exit 2
+ fi
+done
+
+exec $am_CC "$@"
diff --git a/t/ax/deltree.pl b/t/ax/deltree.pl
new file mode 100644
index 000000000..f239057aa
--- /dev/null
+++ b/t/ax/deltree.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+# deltree: recursively removes file and directory,
+# trying to handle permissions and other complications.
+
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use strict;
+use warnings FATAL => 'all';
+use File::Path qw/rmtree/;
+
+my $exit_status = 0;
+local $SIG{__WARN__} = sub { warn "@_"; $exit_status = 1; };
+
+foreach my $path (@ARGV) {
+ local $@ = undef;
+ rmtree ($path);
+}
+
+exit $exit_status;
+
+# vim: ft=perl ts=4 sw=4 et
diff --git a/t/ax/depcomp.sh b/t/ax/depcomp.sh
new file mode 100644
index 000000000..09cf99933
--- /dev/null
+++ b/t/ax/depcomp.sh
@@ -0,0 +1,417 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check dependency tracking in various flavours.
+# Contains both libtool and non-libtool case.
+# Sourced by the various (autogenerated) 'depcomp*.tap' tests.
+# Examples of reported failures that motivated those test are
+# listed below.
+
+# -------------------------------------------------------------------------
+
+# <https://lists.gnu.org/archive/html/automake-patches/2011-04/msg00028.html>
+#
+# Here's the bug: makedepend will prefix VPATH to the object file name,
+# thus the second make will invoke depcomp with object='../../src/foo.o',
+# causing errors such as:
+#
+# touch: cannot touch '../../src/.deps/foo.TPo': No such file or directory
+# makedepend: error: cannot open "../../src/.deps/foo.TPo"
+# ../../depcomp: line 560: ../../src/.deps/foo.TPo: No such file or directory
+
+# -------------------------------------------------------------------------
+
+# <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=8473>
+# <https://lists.gnu.org/archive/html/automake-patches/2011-04/msg00079.html>
+#
+# Here's the bug: hp depmode will prefix VPATH to the object file name,
+# thus the second gmake will invoke depcomp with object='../../src/foo.o',
+# causing errors such as (broken on multiple lines for clarity):
+#
+# cpp: "", line 0: error 4066: Cannot create
+# "../../gllib/.deps/nonblocking.TPo" file for
+# "-M../../gllib/.deps/nonblocking.TPo" option.
+# (No such file or directory[errno=2])
+#
+
+# -------------------------------------------------------------------------
+
+# <https://lists.gnu.org/archive/html/automake-patches/2011-04/msg00140.html>
+# <https://lists.gnu.org/archive/html/automake-patches/2011-05/msg00019.html>
+#
+# A partial failure of an earlier version of this test; some bad
+# post-processing of the '*.Po' files led to the following broken
+# contents of 'src/sub/.deps/subfoo.Po':
+#
+# > sub/subfoo.o: ../../depmod-data.dir/src/sub/subfoo.c \
+# > ../../depmod-data.dir/src/foo.h
+# > ../../depmod-data.dir/src/sub/subfoo.c \:
+# > ../../depmod-data.dir/src/foo.h:
+#
+# which caused make to die with an error like:
+#
+# "sub/.deps/subfoo.Po:3: *** missing separator. Stop."
+
+# -------------------------------------------------------------------------
+
+# This code expects test-init.sh has already been included in advance.
+
+ocwd=$(pwd) || fatal_ "getting current working directory"
+longpath=this-is/a-path/which-has/quite-a/definitely/truly/long_long_name
+cachevar=am_cv_CC_dependencies_compiler_type
+
+srctree=depmod-1.0
+mkdir $srctree
+cd $srctree
+
+cd_top ()
+{
+ cd "$ocwd" || fatal_ "cannot chdir back to top directory"
+}
+
+delete ()
+{
+ test -f "$1" || fatal_ "$1: file does not exist"
+ rm -f "$1" || fatal_ "$1: couldn't remove"
+}
+
+edit ()
+{
+ file=$1; shift
+ sed "$@" <"$file" > t && mv -f t "$file" \
+ || fatal_ "$file: editing of file failed"
+}
+
+rewrite ()
+{
+ file=$1; shift
+ "$@" > "$file" || fatal_ "$file: couldn't rewrite"
+}
+
+setup_srcdir ()
+{
+ srcdir=$1 # This is intended to be global.
+ mkdir -p "$srcdir" \
+ || fatal_ "couldn't create source directory '$srcdir'"
+ cp -pR "$ocwd/$srctree"/* "$srcdir"/ \
+ || fatal_ "couldn't populate source directory '$srcdir'"
+}
+
+
+check_no_depfiles ()
+{
+ find . -name '*.Plo' -o -name '*.Po' | grep . && return 1
+ return 0
+}
+
+check_distclean ()
+{
+ # "make distcleancheck" can only run from a VPATH build.
+ if test $vpath = no; then
+ make_ok distclean && check_no_depfiles
+ else
+ $MAKE distcleancheck
+ fi
+}
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE([subdir-objects])
+AC_PROG_CC
+AM_PROG_AR
+$(if test $depcomp_with_libtool = yes; then
+ echo AC_PROG_LIBTOOL
+ else
+ echo AC_PROG_RANLIB
+ fi)
+AC_CONFIG_FILES([Makefile src/Makefile])
+AC_OUTPUT
+END
+
+mkdir build-aux sub src src/sub2
+
+case $depcomp_with_libtool in
+ yes)
+ po=Plo objext=lo a=la
+ normalized_target=libfoo_la
+ # On platforms requiring that no undefined symbols exist in order
+ # to build shared libraries (e.g. Windows DLLs), you have to
+ # explicitly declare that the libtool library you are building
+ # does not actually have any undefined symbols, for libtool to
+ # even try to build it as a shared library. Without that
+ # explicit declaration, libtool falls back to a static library
+ # only, regardless of any --enable-shared flags etc.
+ LIBPRIMARY=LTLIBRARIES LINKADD=LIBADD NOUNDEF=-no-undefined
+ libbaz_ldflags="libbaz_${a}_LDFLAGS = $NOUNDEF"
+ echo lib_LTLIBRARIES = libfoo.la >> Makefile.am
+ make_ok ()
+ {
+ run_make -M -- ${1+"$@"}
+ $FGREP 'unknown directive' output && return 1
+ rm -f output
+ # Checks for stray files possibly left around by less common
+ # depmodes.
+ find . -name '*.[ud]' | grep . && return 1
+ return 0
+ }
+ ;;
+ no)
+ po=Po objext='$(OBJEXT)' a=a
+ normalized_target=foo
+ LIBPRIMARY=LIBRARIES LINKADD=LDADD NOUNDEF=
+ libbaz_ldflags=
+ echo bin_PROGRAMS = foo >> Makefile.am
+ make_ok ()
+ {
+ $MAKE ${1+"$@"}
+ }
+ ;;
+ *)
+ fatal_ "invalid value '$depcomp_with_libtool' for variable" \
+ "\$depcomp_with_libtool"
+ ;;
+esac
+
+cat >> Makefile.am <<END
+SUBDIRS = src
+# We include subfoo only to be sure that the munging in depcomp
+# doesn't remove too much from the object file name.
+${normalized_target}_SOURCES = foo.c sub/subfoo.c foo.h sub/subfoo.h
+${normalized_target}_LDFLAGS = $NOUNDEF
+${normalized_target}_${LINKADD} = src/libbaz.$a
+
+.PHONY: grep-test
+grep-test:
+## For debugging.
+ cat \$(DEPDIR)/foo.$po || :
+ cat sub/\$(DEPDIR)/subfoo.$po || :
+ cat src/\$(DEPDIR)/baz.$po || :
+ cat src/sub2/\$(DEPDIR)/sub2foo.$po || :
+## Checks are done here.
+ grep '^foo.$objext.*:' \$(DEPDIR)/foo.$po
+ grep '^sub/subfoo\.$objext.*:' sub/\$(DEPDIR)/subfoo.$po
+ grep '^baz\.$objext.*:' src/\$(DEPDIR)/baz.$po
+ grep '^sub2/sub2foo\.$objext.*:' src/sub2/\$(DEPDIR)/sub2foo.$po
+END
+
+cat > src/Makefile.am <<END
+noinst_${LIBPRIMARY} = libbaz.$a
+# We include sub2foo only to be sure that the munging in depcomp
+# doesn't remove too much from the object file name.
+libbaz_${a}_SOURCES = baz.c sub2/sub2foo.c baz.h sub2/sub2foo.h
+$libbaz_ldflags
+END
+
+cat > foo.c <<'END'
+#include "foo.h"
+#include "src/baz.h"
+#include <stdlib.h>
+int main (void)
+{
+ printf ("foo bar\n");
+ exit (EXIT_SUCCESS + subfoo () + baz ());
+}
+END
+
+cat > foo.h <<'END'
+#include <stdio.h>
+#include "sub/subfoo.h"
+END
+
+cat > sub/subfoo.c <<'END'
+#include "sub/subfoo.h"
+int subfoo (void) { return 0; }
+END
+
+echo '/* empty */' > src/sub2/sub2foo.h
+
+cat > sub/subfoo.h <<'END'
+#include <stdio.h>
+extern int subfoo (void);
+END
+
+cat > src/baz.c <<'END'
+#include "baz.h"
+int baz (void) { return 0; }
+END
+
+cat > src/baz.h <<'END'
+extern int baz (void);
+END
+
+cat > src/sub2/sub2foo.c <<'END'
+#include "sub2foo.h"
+int sub2foo (void) { return 0; }
+END
+
+test $depcomp_with_libtool = no || libtoolize \
+ || fatal_ "libtoolize failed"
+$ACLOCAL && $AUTOCONF && $AUTOMAKE -a \
+ || fatal_ "autotools failed"
+test -f build-aux/depcomp \
+ || fatal_ "depcomp script not installed"
+
+# To offer extra coverage for the depmodes (like "aix" of "hp2") where the
+# name of the compiler-generated depfiles can depend on whether libtool is
+# in use *and* on which kind of libraries libtool is building (static,
+# shared, or both), we would like to run the libtool-oriented tests thrice:
+# once after having run configure with the '--disable-shared' option, once
+# after having run it with the '--enable-shared' options, and once by
+# leaving it to configure to automatically select which kind of library (or
+# libraries) to build.
+#
+# But doing such three-fold checks unconditionally for all the depmodes
+# would slow down the already too slow libtool tests unacceptably (up to a
+# 150-200% factor), with no real gain in coverage for most of the depmodes.
+# So, since the depmodes that would benefit from the extra tests are never
+# forced to configure in out tests below, but can only be automatically
+# selected by '--enable-dependency-tracking', we make this threefold check
+# only in this later case.
+
+if test $depmode,$depcomp_with_libtool = auto,yes; then
+ do_all_tests ()
+ {
+ do_test default
+ do_test noshared --disable-shared
+ do_test nostatic --disable-static
+ }
+else
+ do_all_tests () { do_test; }
+fi
+
+case $depmode in
+ auto)
+ displayed_depmode='..*' # At least one character long.
+ cfg_deptrack=--enable-dependency-tracking ;;
+ disabled)
+ displayed_depmode=none
+ cfg_deptrack=--disable-dependency-tracking ;;
+ *)
+ displayed_depmode="(cached) $depmode"
+ cfg_deptrack="$cachevar=$depmode"
+ # Sanity check: ensure the cache variable we force is truly
+ # used by configure.
+ $FGREP $cachevar configure \
+ || fatal_ "configure lacks required cache variable '$cachevar'";;
+esac
+
+cd_top
+
+do_test ()
+{
+ cd_top
+ if test $vpath = no; then
+ pfx="in-tree build"
+ else
+ pfx="$vpath VPATH"
+ fi
+ if test $# -gt 0; then
+ subdir=$1; shift
+ pfx="$pfx, $subdir"
+ test -d $subdir || mkdir $subdir || fatal_ "creating directory $subdir"
+ cd $subdir
+ fi
+ pfx="[$pfx]"
+ case $vpath in
+ simple)
+ mkdir -p vpath-simple/build
+ cd vpath-simple/build
+ setup_srcdir ..
+ ;;
+ long)
+ mkdir -p vpath-long/src vpath-long/wrk
+ cd vpath-long/wrk
+ setup_srcdir ../src/$longpath
+ ;;
+ absolute)
+ mkdir -p vpath-abs/build
+ cd vpath-abs/build
+ absdir=$(cd .. && pwd) || fatal_ "getting absolute directory"
+ setup_srcdir "$absdir/vpath-abs"
+ unset absdir
+ ;;
+ no)
+ mkdir intree
+ cd intree
+ setup_srcdir .
+ ;;
+ *)
+ fatal_ "invalid value '$vpath' for variable \$vpath"
+ ;;
+ esac
+
+ command_ok_ \
+ "$pfx configure" \
+ "$srcdir/configure" $cfg_deptrack ${1+"$@"} >stdout
+ cat stdout
+
+ command_ok_ \
+ "$pfx right depmode selected" \
+ grep "^checking dependency style .*\.\.\. $displayed_depmode$" stdout
+ rm -f stdout
+
+ command_ok_ "$pfx simple make" make_ok
+ # Some bugs in VPATH builds only kick in during a rebuild.
+ command_ok_ "$pfx clean & rebuild" eval '$MAKE clean && make_ok'
+
+ if test $depmode = disabled; then
+ command_ok_ "$pfx no dependency files generated" check_no_depfiles
+ r=ok \
+ && grep "[ $tab]depmode=none" Makefile \
+ && rewrite "$srcdir"/src/sub2/sub2foo.h echo 'choke me' \
+ && delete "$srcdir"/sub/subfoo.h \
+ && make_ok \
+ || r='not ok'
+ result_ "$r" "$pfx dependency tracking is truly disabled"
+ elif grep "[ $tab]depmode=none" Makefile; then
+ skip_row_ 2 -r "automatic dependency tracking couldn't be activated"
+ else
+ command_ok_ "$pfx generated $po files look correct" $MAKE grep-test
+ r=ok \
+ && : "Some checks in the subdir." \
+ && $sleep \
+ && : "Ensure rebuild rules really kick in." \
+ && rewrite "$srcdir"/src/sub2/sub2foo.h echo 'choke me' \
+ && cd src \
+ && not $MAKE \
+ && cd .. \
+ && : "Ensure the deleted header bug is fixed." \
+ && delete "$srcdir"/src/sub2/sub2foo.h \
+ && edit "$srcdir"/src/sub2/sub2foo.c -e 1d \
+ && cd src \
+ && make_ok \
+ && : "Now do similar checks for the parent directory." \
+ && cd .. \
+ && rewrite "$srcdir"/sub/subfoo.h echo 'choke me' \
+ && not $MAKE \
+ && delete "$srcdir"/sub/subfoo.h \
+ && edit "$srcdir"/sub/subfoo.c -e 1d \
+ && edit "$srcdir"/foo.h -e 2d \
+ && make_ok \
+ || r='not ok'
+ result_ "$r" "$pfx dependency tracking works"
+ fi
+
+ command_ok_ "$pfx make distclean" check_distclean
+ cd_top
+}
+
+for vpath in no simple long absolute; do
+ do_all_tests
+done
+
+:
diff --git a/t/ax/distcheck-hook-m4.am b/t/ax/distcheck-hook-m4.am
new file mode 100644
index 000000000..9442a9896
--- /dev/null
+++ b/t/ax/distcheck-hook-m4.am
@@ -0,0 +1,30 @@
+## Data files for some tests. Not used in the automake build system.
+##
+## Copyright (C) 2011-2017 Free Software Foundation, Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+distcheck-hook:
+ @fatal () { echo "$@: $$*" >&2; exit 1; }; \
+ $(am__cd) $(distdir) && chmod u+w . && mkdir _m4 \
+ || fatal "cannot setup distdir"; \
+ $(ACLOCAL) -I _m4 $(ACLOCAL_AMFLAGS) --install --output=_am.m4 \
+ || fatal "cannot regenerate aclocal.m4"; \
+ lst=`ls _m4 | tr '\012\015' ' '`; \
+ if test -n "$$lst"; then \
+ fatal "required m4 files not distributed or outdated: $$lst"; \
+ fi; \
+ $(AUTOCONF) -o /dev/null || fatal "can't remake configure"; \
+ rm -rf _m4 _am.m4 autom4te.cache && chmod a-w . \
+ || fatal "cannot reset distdir"
diff --git a/t/ax/extract-testsuite-summary.pl b/t/ax/extract-testsuite-summary.pl
new file mode 100644
index 000000000..284eefdcf
--- /dev/null
+++ b/t/ax/extract-testsuite-summary.pl
@@ -0,0 +1,30 @@
+#! /usr/bin/env perl
+# Extract the testsuite summary generated by the parallel testsuite
+# harness from the output of "make check".
+
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use warnings FATAL => 'all';
+use strict;
+
+my $br = '=' x 76;
+my @sections = ('');
+while (<>)
+ {
+ push @sections, $_, '' if /$br/;
+ $sections[-1] .= $_ if !/$br/;
+ }
+print @sections[1..$#sections-1];
diff --git a/t/ax/is b/t/ax/is
new file mode 100755
index 000000000..ba6ea4445
--- /dev/null
+++ b/t/ax/is
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that two whitespace-separated lists are equal.
+# Assumes the two lists are passed on the command line separated by
+# a '==' string.
+# This script is useful to test equality of lists in makefile rules,
+# in the face of variables defined through line-continuations,
+# automake rewrites and expansions of empty variables.
+
+# NOTE: keep this file Bourne-compatible, for the sake of systems with
+# non-POSIX /bin/sh (like Solaris).
+
+set -e
+set -u
+
+# Initialize before unsetting, for shells (like older bash or Solaris
+# ksh) that fail to unset variables that are already unset.
+exp= got=; unset exp got
+seen_eqeq=no
+while test $# -gt 0; do
+ if test x"$1" = x"=="; then
+ if test $seen_eqeq = no; then
+ seen_eqeq=yes
+ else
+ echo "$0: more than one '==' argument seen on command line" >&2
+ exit 2
+ fi
+ else
+ if test $seen_eqeq = no; then
+ got=${got+"$got "}$1
+ else
+ exp=${exp+"$exp "}$1
+ fi
+ fi
+ shift
+done
+
+if test $seen_eqeq = no; then
+ echo "$0: no '==' argument seen on command line" >&2
+ exit 2
+fi
+
+test x"${exp-}" = x"${got-}"
diff --git a/t/ax/is_newest b/t/ax/is_newest
new file mode 100755
index 000000000..e62c132d1
--- /dev/null
+++ b/t/ax/is_newest
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Usage: is_newest FILE FILES
+# Fail if any file in FILES is newer than FILE, and print the list of
+# such files on the standard error. Resolve ties in favor of FILE.
+
+# NOTE: keep this file Bourne-compatible, for the sake of systems with
+# non-POSIX /bin/sh (like Solaris).
+
+set -u
+
+me=is_newest
+
+if test $# -lt 2; then
+ echo "$me: too few arguments" >&2
+ exit 2
+fi
+
+file=$1; shift
+newer_files=`find "$@" -prune -newer "$file"` || exit $?
+
+if test -n "$newer_files"; then
+ echo "$me: these files are newer than '$file':" >&2
+ for f in $newer_files; do echo "* $f" >&2; done
+ exit 1
+fi
+
+exit 0
diff --git a/t/ax/runtest.in b/t/ax/runtest.in
new file mode 100644
index 000000000..80a6b1a29
--- /dev/null
+++ b/t/ax/runtest.in
@@ -0,0 +1,130 @@
+#!@AM_TEST_RUNNER_SHELL@
+# @configure_input@
+#
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Run an Automake test from the command line.
+
+set -e; set -u
+
+: ${AM_TEST_RUNNER_SHELL='@AM_TEST_RUNNER_SHELL@'}
+: ${AM_PROVE_CMD='prove'}
+: ${AM_PROVEFLAGS='--merge --verbose'}
+: ${srcdir='@srcdir@'}
+: ${abs_srcdir='@abs_srcdir@'}
+: ${abs_builddir='@abs_builddir@'}
+: ${PATH_SEPARATOR='@PATH_SEPARATOR@'}
+
+# For sourcing of extra "shell libraries" by our test scripts. As per
+# POSIX, sourcing a file with '.' will cause it to be looked up in $PATH
+# in case it is given with a relative name containing no slashes.
+if test "$srcdir" != .; then
+ PATH=$abs_srcdir/t/ax$PATH_SEPARATOR$PATH
+fi
+PATH=$abs_builddir/t/ax$PATH_SEPARATOR$PATH
+export PATH
+
+# For use by the testsuite framework. The Automake test harness
+# define this, so we better do the same.
+export srcdir
+
+# Some testsuite-influential variables should be overridable from the
+# test scripts, but not from the environment.
+# Keep this in sync with the 'Makefile.am:AM_TESTS_ENVIRONMENT'.
+for v in \
+ required \
+ am_test_protocol \
+ am_serial_tests \
+ am_test_prefer_config_shell \
+ am_original_AUTOMAKE \
+ am_original_ACLOCAL \
+ am_test_lib_sourced \
+ test_lib_sourced \
+; do
+ eval "$v= && unset $v" || exit 1
+done
+unset v
+
+xecho () { printf '%s\n' "$*"; }
+error () { echo "$0: $*" >&2; exit 255; }
+
+# Some shell flags should be passed over to the test scripts.
+shell_opts=
+while test $# -gt 0; do
+ case $1 in
+ --help)
+ xecho "Usage: $0 [--shell=PATH] [-k] [SHELL-OPTIONS]" \
+ "[VAR=VALUE ...] TEST [TEST-OPTIONS]"
+ exit $?
+ ;;
+ --shell)
+ test $# -gt 1 || error "missing argument for option '$1'"
+ AM_TEST_RUNNER_SHELL=$2
+ shift
+ ;;
+ --shell=*)
+ AM_TEST_RUNNER_SHELL=${1#--shell=}
+ ;;
+ -o)
+ test $# -gt 1 || error "missing argument for option '$1'"
+ shell_opts="$shell_opts -o $2"
+ shift
+ ;;
+ -k|--keep-testdir|--keep-testdirs)
+ keep_testdirs=yes; export keep_testdirs;;
+ -*)
+ # Assume it is an option to pass through to the shell.
+ shell_opts="$shell_opts $1";;
+ *=*)
+ var=${1%%=*} val=${1#*=}
+ xecho "$var" | LC_ALL=C grep '^[a-zA-Z_][a-zA-Z0-9_]*$' >/dev/null \
+ || error "'$var': invalid variable name"
+ eval "$var=\$val && export $var" || exit 1
+ ;;
+ *)
+ break;;
+ esac
+ shift
+done
+
+test $# -gt 0 || error "missing argument"
+
+tst=$1; shift
+
+case $tst in
+ /*) ;;
+ *) if test -f ./$tst; then
+ tst=./$tst
+ # Support for VPATH build.
+ elif test -f $srcdir/$tst; then
+ tst=$srcdir/$tst
+ else
+ error "could not find test '$tst'"
+ fi
+ ;;
+esac
+
+case $tst in
+ *.sh)
+ exec $AM_TEST_RUNNER_SHELL $shell_opts "$tst" ${1+"$@"} ;;
+ *.tap)
+ exec "$AM_PROVE_CMD" $AM_PROVEFLAGS -e \
+ "$AM_TEST_RUNNER_SHELL $shell_opts" "$tst" ${1+"$@"} ;;
+ *)
+ error "test '$tst' has an unrecognized extension" ;;
+esac
+
+error "dead code reached"
diff --git a/t/ax/shell-no-trail-bslash.in b/t/ax/shell-no-trail-bslash.in
new file mode 100644
index 000000000..fc7b54107
--- /dev/null
+++ b/t/ax/shell-no-trail-bslash.in
@@ -0,0 +1,85 @@
+#! @AM_TEST_RUNNER_SHELL@
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# A "shell" that chokes on '-c' commands and/or shell scripts having
+# a trailing '\' character (possibly followed by whitespace only).
+# This is to emulate problems seen in older bash versions (e.g., bash
+# 2.05b). See also automake bug#10436.
+
+set -u
+
+am_SHELL=${AM_TESTSUITE_SHELL-'@SHELL@'}
+
+(
+ set -e
+ shell_command=; unset shell_command
+ shell_script=; unset shell_script
+ while test $# -gt 0; do
+ case $1 in
+ # The shell might be invoked by make e.g. as "sh -ec" or "sh -ce".
+ # Be liberal (in the spirit of defensive programming) and accept
+ # both forms.
+ -*c*) shell_command=$2; shift;;
+ -?*) ;;
+ *) break;;
+ esac
+ shift
+ done
+
+ if test x${shell_command+"set"} != x"set"; then
+ if test $# -gt 0; then
+ shell_script=$1
+ shell_command=$(cat <"$shell_script")
+ else
+ # Some make implementations, like *BSD's, pass the recipes to the
+ # shell through its standard input. Trying to run our extra checks
+ # in this case would be too tricky, so we just skip them.
+ exit 0
+ fi
+ fi
+ original_shell_command=$shell_command
+
+ tab=' '
+ nl='
+'
+ case "$shell_command" in
+ *" "|*"$tab"|*"$nl")
+ shell_command=$(printf '%s\n' "$shell_command" | tr -d " $tab$nl");;
+ esac
+
+ case "$shell_command" in
+ *\\)
+ {
+ printf '%s\n' "$0: recipe/script ends with backslash character"
+ printf '%s\n' "=== BEGIN recipe/script"
+ if test x${shell_script+"set"} = x"set"; then
+ cat <"$shell_script"
+ else
+ printf '%s\n' "$original_shell_command"
+ fi
+ printf '%s\n' "=== END recipe/script"
+ } >&2
+ exit 1
+ ;;
+ esac
+)
+
+if test $? -gt 0; then
+ # Some of our scripts or makefile recipes had invalid contents.
+ exit 3
+fi
+
+exec ${AM_TESTSUITE_SHELL-'@SHELL@'} ${1+"$@"}
diff --git a/t/ax/tap-functions.sh b/t/ax/tap-functions.sh
new file mode 100644
index 000000000..efa85a42d
--- /dev/null
+++ b/t/ax/tap-functions.sh
@@ -0,0 +1,231 @@
+# -*- shell-script -*-
+#
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Helper functions used by TAP-producing tests of the Automake testsuite.
+
+#
+# IMPORTANT: All the functions defined in this file can *not* be used
+# from within a subshell, unless explicitly noted otherwise.
+#
+
+# The counts of the TAP test results seen so far: total count and
+# per-result counts.
+tap_count_=0
+tap_pass_count_=0
+tap_skip_count_=0
+tap_fail_count_=0
+tap_xfail_count_=0
+tap_xpass_count_=0
+
+# not COMMAND [ARGS...]
+# ---------------------
+# Run the given command and invert its exit status.
+not () { ! "$@"; }
+
+# plan_ [unknown|later|lazy|now|NUMBER-OF-PLANNED-TESTS]
+# ------------------------------------------------------
+# Print a TAP plan for the given number of tests. This must be called
+# before reporting any test result. If called with the special argument
+# "unknown" or "later", it will do nothing, expecting the calling script
+# to declare the plan later. If called with the special argument "lazy"
+# or "now", it will print a TAP plan that accounts for the number of tests
+# seen so far.
+plan_ ()
+{
+ if test $# -eq 0; then
+ bailout_ "plan_: missing argument"
+ elif test $# -ge 2; then
+ bailout_ "plan_: too many arguments"
+ elif test x"$planned_" != x"none" && test x"$planned_" != x"later"; then
+ bailout_ "plan_: called to many times"
+ elif test x"$1" = x"unknown" || test x"$1" = x"later"; then
+ # This means we want to get back later to declaring the TAP plan.
+ planned_=later
+ return 0
+ elif test x"$1" = x"lazy" || test x"$1" = x"now"; then
+ planned_=$tap_count_ # Number of test results seen so far.
+ elif test $1 -ge 0; then
+ planned_=$1
+ else
+ bailout_ "plan_: invalid argument '$1'"
+ fi
+ echo "1..$planned_"
+}
+planned_=none
+
+# diag_ [EXPLANATION]
+# ------------------
+# Report the given text as TAP diagnostic. Assumes the string denoting
+# TAP diagnostic lines is stored in the '$diag_string_' variable; this is
+# done to allow better interplay with TAP drivers that allow such a string
+# to be configured.
+diag_ ()
+{
+ test $# -eq 0 || echo "$diag_string_ $*"
+}
+
+# Used by the 'diag_' function above. User-overridable.
+diag_string_="#"
+
+# warn_ [EXPLANATION]
+# ------------------
+# Give a warning (using TAP diagnostic).
+warn_ ()
+{
+ case $# in
+ 0) diag_ "WARNING: (unknown warning)";;
+ *) diag_ "WARNING: $*";;
+ esac
+}
+
+# result_ RESULT [-D DIRECTIVE] [-r REASON] [--] [DESCRIPTION...]
+# ---------------------------------------------------------------
+# Report a test case with the given RESULT (valid values are "ok" and
+# "not ok") and the given DESCRIPTION (if any). If DIRECTIVE is given
+# and non-empty (valid values being "TODO" and "SKIP"), it will be
+# reported too, with the REASON (if given) appended.
+result_ ()
+{
+ set +x # Don't pollute the log files.
+ test $# -gt 0 || bailout_ "result_: missing argument"
+ tap_result_=$1; shift
+ case $tap_result_ in
+ "ok"|"not ok") ;;
+ *) bailout_ "result_: invalid result '$tap_result'" ;;
+ esac
+ tap_directive_= tap_reason_=
+ while test $# -gt 0; do
+ case $1 in
+ -D|--directive) tap_directive_=$2; shift;;
+ -r|--reason) tap_reason_=$2; shift;;
+ --) shift; break;;
+ -*) bailout_ "result_: invalid option '$1'";;
+ *) break;;
+ esac
+ shift
+ done
+ case $tap_directive_ in
+ ""|TODO|SKIP) ;;
+ *) bailout_ "result_: invalid directive '$directive_'" ;;
+ esac
+ tap_count_=$(($tap_count_ + 1))
+ case $tap_result_,$tap_directive_ in
+ ok,) # Passed.
+ tap_pass_count_=$(($tap_pass_count_ + 1)) ;;
+ not\ ok,TODO) # Expected failure.
+ tap_xfail_count_=$(($tap_xfail_count_ + 1)) ;;
+ not\ ok,*) # Failed.
+ tap_fail_count_=$(($tap_fail_count_ + 1)) ;;
+ ok,TODO) # Unexpected pass.
+ tap_xpass_count_=$(($tap_xpass_count_ + 1)) ;;
+ ok,SKIP) # Skipped.
+ tap_skip_count_=$(($tap_skip_count_ + 1)) ;;
+ *) # Can't happen.
+ bailout_ "internal error in 'result_'" ;;
+ esac
+ tap_text_="$tap_result_ $tap_count_"
+ if test x"$*" != x; then
+ tap_text_="$tap_text_ - $*"
+ fi
+ if test x"$tap_directive_" != x; then
+ tap_text_="$tap_text_ # $tap_directive_"${tap_reason_:+" $tap_reason_"}
+ fi
+ printf '%s\n' "$tap_text_"
+ set -x # Restore shell xtraces.
+}
+
+# Shorthands for common usages of 'result_'.
+ok_ () { result_ 'ok' ${1+"$@"}; }
+not_ok_ () { result_ 'not ok' ${1+"$@"}; }
+skip_ () { result_ 'ok' -D SKIP ${1+"$@"}; }
+
+# skip_row_ COUNT [-r REASON] [--] [DESCRIPTION...]
+# -------------------------------------------------
+# Report a COUNT of skipped test, with the given reason and descriptions
+# (if any). Useful to avoid cascade failures in case a fair number of
+# tests depend on an earlier one that failed.
+skip_row_ ()
+{
+ skip_count_=$1; shift
+ for i_ in $(seq_ $skip_count_); do skip_ ${1+"$@"}; done
+}
+
+# skip_all_ [REASON ...]
+# ----------------------
+# Skip all the tests in a test script. Must be used before calling 'plan_'
+# or reporting any test result. Can't be used from within a subshell.
+skip_all_ ()
+{
+ echo "1..0 # SKIP" ${1+"$@"}
+ planned_=0
+ exit 0
+}
+
+# bailout_ [REASON ...]
+# ---------------------
+# Stop the execution of the current test suite right now, due to an
+# unrecoverable error. Can be called at any point, but cannot be used
+# from within a subshell.
+bailout_ ()
+{
+ echo 'Bail out!' ${1+"$@"}
+ exit 99
+}
+
+# fatal_ [REASON ...]
+# -------------------
+# Same as 'bailout_'; for compatibility with 'plain-functions.sh'.
+fatal_ ()
+{
+ bailout_ ${1+"$@"}
+}
+
+# framework_failure_ [REASON ...]
+# -------------------------------
+# Stop the execution of the current test suite right now, due to an
+# unrecoverable error in the set-up of the test case. Can be called
+# at any point, but cannot be used from within a subshell.
+framework_failure_ ()
+{
+ bailout_ "set-up failure"${1+": $*"}
+}
+
+# command_ok_ TEST-DESCRIPTION [OPTIONS..] [--] CMD [ARGS...]
+# -----------------------------------------------------------
+# Helper subroutine for when a TAP result must be determined by the
+# outcome of a command.
+command_ok_ ()
+{
+ tap_directive_= tap_reason_=
+ test $# -gt 0 || bailout_ "command_ok_: missing argument"
+ tap_description_=$1; shift
+ while test $# -gt 0; do
+ case $1 in
+ -D|--directive) tap_directive_=$2; shift;;
+ -r|--reason) tap_reason_=$2; shift;;
+ --) shift; break;;
+ -*) bailout_ "command_ok_: invalid option '$1'";;
+ *) break;;
+ esac
+ shift
+ done
+ tap_result_="ok"; "$@" || tap_result_="not ok"
+ result_ "$tap_result_" -D "$tap_directive_" -r "$tap_reason_" \
+ -- "$tap_description_"
+}
+
+:
diff --git a/t/ax/tap-setup.sh b/t/ax/tap-setup.sh
new file mode 100644
index 000000000..64580c4cf
--- /dev/null
+++ b/t/ax/tap-setup.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Auxiliary shell script that copies the common data and files used by
+# many tests on TAP support into the current directory. It should be
+# sourced by client test scripts, and assumes the auxiliary test
+# 'tap-common-setup.test' has been run beforehand (it will error out
+# if this is not the case).
+
+# Check that we are running from a proper directory: last thing we want
+# is to overwrite some random user files.
+test -f ../../bin/automake && test -f ../../runtest && test -d ../../t \
+ || fatal_ "running from a wrong directory"
+
+test ! -f Makefile.am || mv Makefile.am Makefile.am~ \
+ || fatal_ "failed to save Makefile.am"
+
+test -d ../tap-common-setup.dir && cp -fpR ../tap-common-setup.dir/* . \
+ || fatal_ "couldn't get precomputed data files"
+
+fetch_tap_driver
+
+if test -f Makefile.am~; then
+ mv -f Makefile.am~ Makefile.am \
+ || fatal_ "failed to restore Makefile.am"
+ echo 'TEST_LOG_DRIVER = $(srcdir)/tap-driver' >> Makefile.am \
+ || fatal_ "failed to update Makefile.am"
+ $AUTOMAKE Makefile \
+ || fatal_ "failed to remake Makefile.in"
+ ./config.status Makefile \
+ || fatal_ "failed to remake Makefile"
+fi
+
+:
diff --git a/t/ax/tap-summary-aux.sh b/t/ax/tap-summary-aux.sh
new file mode 100644
index 000000000..f0c31aa63
--- /dev/null
+++ b/t/ax/tap-summary-aux.sh
@@ -0,0 +1,357 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Auxiliary script for tests on TAP support: checking testsuite summary.
+
+. test-init.sh
+
+br='============================================================================'
+
+case $use_colors in
+ yes|no) ;;
+ *) fatal_ "invalid \$use_colors value '$use_colors'"
+esac
+
+fetch_tap_driver
+
+cat > configure.ac <<END
+AC_INIT([GNU AutoTAP], [5.12], [bug-automake@gnu.org])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = $(srcdir)/tap-driver
+TEST_LOG_COMPILER = cat
+TESTS = all.test
+END
+
+# The following shell variables are influential for this function:
+# - expect_failure
+# - use_colors
+do_check ()
+{
+ case $#,$1 in
+ 1,--pass) expect_failure=no;;
+ 1,--fail) expect_failure=yes;;
+ *) fatal_ "invalid usage of 'do_check'";;
+ esac
+ shift
+ cat > summary.exp
+ cat all.test
+ if test $use_colors = yes; then
+ # Forced colorization should take place also with non-ANSI terminals;
+ # hence the "TERM=dumb" definition.
+ make_args='TERM=dumb AM_COLOR_TESTS=always'
+ else
+ make_args=
+ fi
+ run_make -O -e IGNORE $make_args check
+ if test $expect_failure = yes; then
+ test $am_make_rc -gt 0 || exit 1
+ else
+ test $am_make_rc -eq 0 || exit 1
+ fi
+ $PERL "$am_testaux_srcdir"/extract-testsuite-summary.pl stdout >summary.got \
+ || fatal_ "cannot extract testsuite summary"
+ cat summary.exp
+ cat summary.got
+ if test $use_colors = yes; then
+ # Use cmp, not diff, because the files might contain binary data.
+ compare=cmp
+ else
+ compare=diff
+ fi
+ $compare summary.exp summary.got || exit 1
+}
+
+if test $use_colors = yes; then
+ red="$esc[0;31m"
+ grn="$esc[0;32m"
+ lgn="$esc[1;32m"
+ blu="$esc[1;34m"
+ mgn="$esc[0;35m"
+ brg="$esc[1m"
+ std="$esc[m"
+else
+ red= grn= lgn= blu= mgn= brg= std=
+fi
+
+ success_header="\
+${grn}${br}${std}
+${grn}Testsuite summary for GNU AutoTAP 5.12${std}
+${grn}${br}${std}"
+
+ success_footer=${grn}${br}${std}
+
+ failure_header="\
+${red}${br}${std}
+${red}Testsuite summary for GNU AutoTAP 5.12${std}
+${red}${br}${std}"
+
+ failure_footer="\
+${red}${br}${std}
+${red}See ./test-suite.log${std}
+${red}Please report to bug-automake@gnu.org${std}
+${red}${br}${std}"
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+# 1 pass.
+{ echo 1..1 && echo ok; } > all.test
+do_check --pass <<END
+$success_header
+${brg}# TOTAL: 1${std}
+${grn}# PASS: 1${std}
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+# 1 skip.
+{ echo 1..1 && echo 'ok # SKIP'; } > all.test
+do_check --pass <<END
+$success_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+${blu}# SKIP: 1${std}
+# XFAIL: 0
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+# 1 xfail.
+{ echo 1..1 && echo 'not ok # TODO'; } > all.test
+do_check --pass <<END
+$success_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+# SKIP: 0
+${lgn}# XFAIL: 1${std}
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+# 1 fail.
+{ echo 1..1 && echo not ok; } > all.test
+do_check --fail <<END
+$failure_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+# SKIP: 0
+# XFAIL: 0
+${red}# FAIL: 1${std}
+# XPASS: 0
+# ERROR: 0
+$failure_footer
+END
+
+# 1 xpass.
+{ echo 1..1 && echo 'ok # TODO'; } > all.test
+do_check --fail <<END
+$failure_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 0
+${red}# XPASS: 1${std}
+# ERROR: 0
+$failure_footer
+END
+
+# 1 hard error.
+{ echo 1..1 && echo 'Bail out!'; } > all.test
+do_check --fail <<END
+$failure_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 0
+# XPASS: 0
+${mgn}# ERROR: 1${std}
+$failure_footer
+END
+
+# 3 non-failing results.
+cat > all.test <<END
+1..3
+ok
+not ok # TODO
+ok # SKIP
+END
+do_check --pass <<END
+$success_header
+${brg}# TOTAL: 3${std}
+${grn}# PASS: 1${std}
+${blu}# SKIP: 1${std}
+${lgn}# XFAIL: 1${std}
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+# 1 pass, 1 skip, 1 fail.
+cat > all.test <<END
+1..3
+ok
+ok # SKIP
+not ok
+END
+do_check --fail <<END
+$failure_header
+${brg}# TOTAL: 3${std}
+${grn}# PASS: 1${std}
+${blu}# SKIP: 1${std}
+# XFAIL: 0
+${red}# FAIL: 1${std}
+# XPASS: 0
+# ERROR: 0
+$failure_footer
+END
+
+# 1 pass, 1 xfail, 1 xpass.
+cat > all.test <<END
+1..3
+ok
+ok # TODO
+not ok # TODO
+END
+do_check --fail <<END
+$failure_header
+${brg}# TOTAL: 3${std}
+${grn}# PASS: 1${std}
+# SKIP: 0
+${lgn}# XFAIL: 1${std}
+# FAIL: 0
+${red}# XPASS: 1${std}
+# ERROR: 0
+$failure_footer
+END
+
+# 1 skip, 1 xfail, 1 error.
+cat > all.test <<END
+1..3
+ok # SKIP
+not ok # TODO
+Bail out!
+END
+do_check --fail <<END
+$failure_header
+${brg}# TOTAL: 3${std}
+# PASS: 0
+${blu}# SKIP: 1${std}
+${lgn}# XFAIL: 1${std}
+# FAIL: 0
+# XPASS: 0
+${mgn}# ERROR: 1${std}
+$failure_footer
+END
+
+# 1 of each kind
+cat > all.test <<END
+1..6
+ok
+not ok
+ok # TODO
+not ok # TODO
+ok # SKIP
+Bail out!
+END
+do_check --fail <<END
+$failure_header
+${brg}# TOTAL: 6${std}
+${grn}# PASS: 1${std}
+${blu}# SKIP: 1${std}
+${lgn}# XFAIL: 1${std}
+${red}# FAIL: 1${std}
+${red}# XPASS: 1${std}
+${mgn}# ERROR: 1${std}
+$failure_footer
+END
+
+# Prepare some common data for later.
+for i in 0 1 2 3 4 5 6 7 8 9; do
+ for j in 0 1 2 3 4 5 6 7 8 9; do
+ echo "ok"
+ echo "not ok # TODO"
+ echo "ok # SKIP"
+ done
+done > tap
+
+# Lots of non-failures (300 per kind).
+(cat tap && cat tap && cat tap) > all.test
+test $(wc -l <all.test) -eq 900 || exit 99 # Sanity check.
+echo 1..900 >> all.test # Test plan.
+do_check --pass <<END
+$success_header
+${brg}# TOTAL: 900${std}
+${grn}# PASS: 300${std}
+${blu}# SKIP: 300${std}
+${lgn}# XFAIL: 300${std}
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+# 1 failure and lots of non-failures means failure.
+(cat tap && echo "not ok" && cat tap) > all.test
+test $(wc -l <all.test) -eq 601 || exit 99 # Sanity check.
+echo 1..601 >> all.test # Test plan.
+do_check --fail <<END
+$failure_header
+${brg}# TOTAL: 601${std}
+${grn}# PASS: 200${std}
+${blu}# SKIP: 200${std}
+${lgn}# XFAIL: 200${std}
+${red}# FAIL: 1${std}
+# XPASS: 0
+# ERROR: 0
+$failure_footer
+END
+
+# 1 error and lots of non-failures means failure.
+(cat tap && sed 30q tap && echo 'Bail out!') > all.test
+test $(wc -l <all.test) -eq 331 || exit 99 # Sanity check.
+echo 1..331 >> all.test # Test plan.
+do_check --fail <<END
+$failure_header
+${brg}# TOTAL: 331${std}
+${grn}# PASS: 110${std}
+${blu}# SKIP: 110${std}
+${lgn}# XFAIL: 110${std}
+# FAIL: 0
+# XPASS: 0
+${mgn}# ERROR: 1${std}
+$failure_footer
+END
+
+:
diff --git a/t/ax/test-defs.in b/t/ax/test-defs.in
new file mode 100644
index 000000000..04d952133
--- /dev/null
+++ b/t/ax/test-defs.in
@@ -0,0 +1,201 @@
+# -*- shell-script -*-
+# @configure_input@
+#
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Defines and minimal setup for Automake testing environment.
+
+# IMPORTANT NOTES AND REQUIREMENTS
+# - Multiple inclusions of this file should be idempotent.
+# - This code has to be 'set -e' clean.
+
+# See whether the current test script is expected to use TAP or not.
+# Use a sensible default, while allowing the scripts to override this
+# check.
+if test -z "$am_test_protocol"; then
+ case $argv0 in
+ *.tap) am_test_protocol=tap;;
+ *) am_test_protocol=none;;
+ esac
+fi
+
+am_rel_srcdir='@srcdir@'
+am_top_srcdir='@abs_srcdir@'
+am_top_builddir='@abs_builddir@'
+
+# Where testsuite-related helper scripts, data files and shell libraries
+# are placed.
+am_testaux_srcdir=$am_top_srcdir/t/ax
+am_testaux_builddir=$am_top_builddir/t/ax
+
+# Support for the "installcheck" target.
+case ${am_running_installcheck:=no} in
+ yes)
+ am_amdir='@amdir@'
+ am_automake_acdir='@automake_acdir@'
+ am_bindir='@bindir@'
+ am_datadir='@datadir@'
+ am_docdir='@docdir@'
+ am_pkgvdatadir='@pkgvdatadir@'
+ am_scriptdir='@scriptdir@'
+ am_system_acdir='@system_acdir@'
+ ;;
+ no)
+ am_amdir=$am_top_srcdir/lib/am
+ am_automake_acdir=""
+ am_bindir=$am_top_builddir/bin
+ am_datadir=$am_top_srcdir
+ am_docdir=$am_top_srcdir/doc
+ am_pkgvdatadir=$am_top_srcdir/lib
+ am_scriptdir=$am_top_srcdir/lib
+ am_system_acdir=""
+ ;;
+ *)
+ echo "$me: variable 'am_running_installcheck' has invalid"
+ "value '$am_running_installcheck'" >&2
+ exit 99
+ ;;
+esac
+
+APIVERSION='@APIVERSION@'
+PATH_SEPARATOR='@PATH_SEPARATOR@'
+
+host_alias=${host_alias-'@host_alias@'}; export host_alias
+build_alias=${build_alias-'@build_alias@'}; export build_alias
+
+# Whether the testsuite is being run by faking the presence of a C
+# compiler that doesn't grasp the '-c' and '-o' flags together. By
+# default, of course, it isn't.
+: "${AM_TESTSUITE_SIMULATING_NO_CC_C_O:=no}"
+
+# A concurrency-safe "mkdir -p" implementation.
+MKDIR_P=${AM_TESTSUITE_MKDIR_P-'@MKDIR_P@'}
+
+# The shell we use to run our own test scripts, determined at configure
+# time. It is required in the self tests, and most importantly for the
+# automatic re-execution of test scripts.
+AM_TEST_RUNNER_SHELL=${AM_TEST_RUNNER_SHELL-'@AM_TEST_RUNNER_SHELL@'}
+
+# Make sure we override the user shell. And do not read the value of
+# $SHELL from the environment (think to the non-uncommon situation where
+# e.g., $SHELL=/bin/tcsh).
+SHELL=${AM_TESTSUITE_SHELL-'@SHELL@'}; export SHELL
+
+# User can override various tools used. Prefer overriding specific for
+# that automake testsuite, if they are available.
+AWK=${AM_TESTSUITE_AWK-${AWK-'@AWK@'}}
+PERL=${AM_TESTSUITE_PERL-${PERL-'@PERL@'}}
+MAKE=${AM_TESTSUITE_MAKE-${MAKE-'make'}}
+YACC=${AM_TESTSUITE_YACC-${YACC-'@YACC@'}}
+LEX=${AM_TESTSUITE_LEX-${LEX-'@LEX@'}}
+AUTOCONF=${AM_TESTSUITE_AUTOCONF-${AUTOCONF-'@am_AUTOCONF@'}}
+AUTOM4TE=${AM_TESTSUITE_AUTOM4TE-${AUTOM4TE-'@am_AUTOM4TE@'}}
+AUTORECONF=${AM_TESTSUITE_AUTORECONF-${AUTORECONF-'@am_AUTORECONF@'}}
+AUTOHEADER=${AM_TESTSUITE_AUTOHEADER-${AUTOHEADER-'@am_AUTOHEADER@'}}
+AUTOUPDATE=${AM_TESTSUITE_AUTOUPDATE-${AUTOUPDATE-'@am_AUTOUPDATE@'}}
+
+# Tests which want complete control over aclocal or automake command-line
+# options should use $am_original_ACLOCAL or $am_original_AUTOMAKE. The
+# "test -z" tests take care not to re-initialize them if 'test-defs.sh'
+# is re-sourced, as we want that file to remain really idempotent.
+if test -z "$am_original_AUTOMAKE"; then
+ am_original_AUTOMAKE=${AM_TESTSUITE_AUTOMAKE-${AUTOMAKE-"automake-$APIVERSION"}}
+fi
+if test -z "$am_original_ACLOCAL"; then
+ am_original_ACLOCAL=${AM_TESTSUITE_ACLOCAL-${ACLOCAL-"aclocal-$APIVERSION"}}
+fi
+
+# Use -Werror by default. Tests for which this is inappropriate should
+# use -Wno-error.
+# Tests which want complete control over aclocal command-line options
+# should use $am_original_ACLOCAL instead.
+ACLOCAL="$am_original_ACLOCAL -Werror"
+
+# See how Automake should be run. We put --foreign as the default
+# strictness to avoid having to create lots and lots of files. A test
+# can override this by specifying a different strictness. Use -Wall
+# -Werror by default. Tests for which this is inappropriate (e.g. when
+# testing that a warning is enabled by a specific switch) should use
+# -Wnone or/and -Wno-error.
+# Tests who want complete control over automake command-line options
+# should use $am_original_AUTOMAKE instead.
+AUTOMAKE="$am_original_AUTOMAKE --foreign -Werror -Wall"
+
+# POSIX no longer requires 'egrep' and 'fgrep',
+# but some hosts lack 'grep -E' and 'grep -F'.
+EGREP=${AM_TESTSUITE_EGREP-'@EGREP@'}
+FGREP=${AM_TESTSUITE_FGREP-'@FGREP@'}
+
+# Compilers and their flags. These can point to non-GNU compilers (and
+# on non-Linux and non-BSD systems, they probably will).
+if test $AM_TESTSUITE_SIMULATING_NO_CC_C_O = no; then
+ CC=${AM_TESTSUITE_CC-${CC-'@CC@'}}
+else
+ CC=$am_testaux_builddir/cc-no-c-o
+fi
+CXX=${AM_TESTSUITE_CXX-${CXX-'@CXX@'}}
+F77=${AM_TESTSUITE_F77-${F77-'@F77@'}}
+FC=${AM_TESTSUITE_FC-${FC-'@FC@'}}
+CFLAGS=${AM_TESTSUITE_CFLAGS-${CFLAGS-'@CFLAGS@'}}
+CXXFLAGS=${AM_TESTSUITE_CXXFLAGS-${CXXFLAGS-'@CXXFLAGS@'}}
+FCFLAGS=${AM_TESTSUITE_FCFLAGS-${FCFLAGS-'@FCFLAGS@'}}
+FFLAGS=${AM_TESTSUITE_FFLAGS-${FFLAGS-'@FFLAGS@'}}
+CPPFLAGS=${AM_TESTSUITE_CPPFLAGS-${CPPFLAGS-'@CPPFLAGS@'}}
+
+# GNU compilers and their flags.
+if test $AM_TESTSUITE_SIMULATING_NO_CC_C_O = no; then
+ GNU_CC=${AM_TESTSUITE_GNU_CC-${GNU_CC-'@GNU_CC@'}}
+else
+ GNU_CC=$am_testaux_builddir/cc-no-c-o
+fi
+GNU_CC=${AM_TESTSUITE_GNU_CC-${GNU_CC-'@GNU_CC@'}}
+GNU_CXX=${AM_TESTSUITE_GNU_CXX-${GNU_CXX-'@GNU_CXX@'}}
+GNU_F77=${AM_TESTSUITE_GNU_F77-${GNU_F77-'@GNU_F77@'}}
+GNU_FC=${AM_TESTSUITE_GNU_FC-${GNU_FC-'@GNU_FC@'}}
+GNU_FFLAGS=${AM_TESTSUITE_GNU_FFLAGS-${GNU_FFLAGS-'@GNU_FFLAGS@'}}
+GNU_FCFLAGS=${AM_TESTSUITE_GNU_FCFLAGS-${GNU_FCFLAGS-'@GNU_FCFLAGS@'}}
+GNU_CXXFLAGS=${AM_TESTSUITE_GNU_CXXFLAGS-${GNU_CXXFLAGS-'@GNU_CXXFLAGS@'}}
+GNU_CFLAGS=${AM_TESTSUITE_GNU_CFLAGS-${GNU_CFLAGS-'@GNU_CFLAGS@'}}
+GNU_GCJ=${AM_TESTSUITE_GNU_GCJ-${GNU_GCJ-'@GNU_GCJ@'}}
+GNU_GCJFLAGS=${AM_TESTSUITE_GNU_GCJFLAGS-${GNU_GCJFLAGS-'@GNU_GCJFLAGS@'}}
+
+# No all versions of Tex support '--version', so we use a configure
+# check to decide if tex is available. This decision is embodied in
+# this variable.
+TEX=${AM_TESTSUITE_TEX-'@TEX@'}
+
+# The amount we should wait after modifying files depends on the platform.
+# For instance, Windows '95, '98 and ME have 2-second granularity
+# and can be up to 3 seconds in the future w.r.t. the system clock.
+# The creative quoting is to avoid spuriously triggering a failure in
+# the maintainer checks,
+sleep='sleep ''@MODIFICATION_DELAY@'
+
+# An old timestamp that can be given to a file, in "touch -t" format.
+# The time stamp should be portable to all file systems of interest.
+# Just for fun, choose the exact time of the announcement of the GNU project
+# in UTC; see <https://www.gnu.org/gnu/initial-announcement.html>.
+old_timestamp=198309271735.59
+
+# Make our wrapper script (or installed scripts, if running under
+# "installcheck") accessible by default. And avoid to uselessly
+# extend $PATH multiple times if this file is sourced multiple times.
+case $PATH in
+ $am_bindir$PATH_SEPARATOR*) ;;
+ *) PATH=$am_bindir$PATH_SEPARATOR$PATH;;
+esac
+
+export PATH
diff --git a/t/ax/test-init.sh b/t/ax/test-init.sh
new file mode 100644
index 000000000..4311fb7c9
--- /dev/null
+++ b/t/ax/test-init.sh
@@ -0,0 +1,29 @@
+# -*- shell-script -*-
+#
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+set -e
+
+# The variable '$required' should no longer be modified after this
+# file gets sources.
+required=${required-}; readonly required
+
+# Source the actual code for test initialization and setup.
+. test-lib.sh
+. am-test-lib.sh
+
+# Run that setup, and return control to the test script sourcing us.
+am_test_setup
diff --git a/t/ax/test-lib.sh b/t/ax/test-lib.sh
new file mode 100644
index 000000000..5882ef052
--- /dev/null
+++ b/t/ax/test-lib.sh
@@ -0,0 +1,317 @@
+# -*- shell-script -*-
+#
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+########################################################
+### IMPORTANT NOTE: keep this file 'set -e' clean. ###
+########################################################
+
+# Do not source several times.
+test ${test_lib_sourced-no} = yes && return 0
+test_lib_sourced=yes
+
+# CDPATH is evil if used in non-interactive scripts (and even more
+# evil if exported in the environment).
+CDPATH=; unset CDPATH
+
+# Be more Bourne compatible.
+# (Snippet inspired to configure's initialization in Autoconf 2.64)
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+ emulate sh
+ NULLCMD=:
+ setopt NO_GLOB_SUBST
+ # If Zsh is not started directly in POSIX-compatibility mode, it has some
+ # incompatibilities in the handling of $0 that conflict with our usage;
+ # i.e., $0 inside a file sourced with the '.' builtin is temporarily set
+ # to the name of the sourced file. Work around that.
+ # Note that a bug in some versions of Zsh prevents us from resetting $0
+ # in a sourced script, so the use of $argv0. For more info see:
+ # <http://www.zsh.org/mla/workers/2009/msg01140.html>
+ # The apparently useless 'eval' here is needed by at least dash 0.5.2,
+ # to prevent it from bailing out with an error like:
+ # "Syntax error: Bad substitution".
+ eval 'argv0=${functrace[-1]%:*}' && test -f "$argv0" || {
+ echo "Cannot determine the path of running test script." >&2
+ echo "Your Zsh (version $ZSH_VERSION) is probably too old." >&2
+ exit 99
+ }
+else
+ argv0=$0
+ # Ignore command substitution failure, for it might cause problems
+ # with "set -e" on some shells.
+ am_shell_opts=$(set -o) || :
+ case $am_shell_opts in *posix*) set -o posix;; esac
+ unset am_shell_opts
+fi
+
+# A single whitespace character.
+sp=' '
+# A tabulation character.
+tab=' '
+# A newline character.
+nl='
+'
+
+# As autoconf-generated configure scripts do, ensure that IFS
+# is defined initially, so that saving and restoring $IFS works.
+IFS=$sp$tab$nl
+
+# The name of the current test (without the '.sh' or '.tap' suffix).
+me=${argv0##*/} # Strip all directory components.
+case $me in # Strip test suffix.
+ *.tap) me=${me%.tap};;
+ *.sh) me=${me%.sh} ;;
+ esac
+
+# Source extra package-specific configuration.
+. test-defs.sh
+# And fail hard if something went wrong.
+test $? -eq 0 || exit 99
+
+# We use a trap below for cleanup. This requires us to go through
+# hoops to get the right exit status transported through the signal.
+# Turn off errexit here so that we don't trip the bug with OSF1/Tru64
+# sh inside this function (FIXME: is this still relevant now that we
+# require a POSIX shell?).
+_am_exit ()
+{
+ set +e
+ # See comments in the exit trap for the reason we do this.
+ test 77 = $1 && am__test_skipped=yes
+ # Extra escaping to ensure we do not call our 'exit' alias.
+ (\exit $1); \exit $1
+}
+# Avoid interferences from the environment
+am__test_skipped=no
+# This alias must actually be placed before any use if 'exit' -- even
+# just inside a function definition. Weird, but real.
+alias exit=_am_exit
+
+# In some shells (e.g., Solaris 10 /bin/ksh, or NetBSD 5.1 /bin/sh),
+# "unset VAR" returns a non-zero exit status in case the VAR variable
+# is already unset. This doesn't interact well with our usage of
+# "set -e" in the testsuite. This function and the alias below help
+# to work around the issue. But be sure to use them only if actually
+# needed. The repeated unset in the check below cater to the very
+# unlikely case where the '_am_v' variable is set in the environment.
+if unset _am_v && unset _am_v; then
+ : Nothing needs to be done.
+else
+ _am_unset ()
+ {
+ for _am_v
+ do
+ # Extra escaping (here and below) to ensure we do not call our
+ # 'unset' alias.
+ eval ${_am_v}=dummy && \unset ${_am_v} || return 1
+ done
+ \unset _am_v
+ }
+ alias unset=_am_unset
+fi
+
+## ------------------------------------ ##
+## General testsuite shell functions. ##
+## ------------------------------------ ##
+
+# Print warnings (e.g., about skipped and failed tests) to this file
+# number. Override by putting, say:
+# AM_TESTS_ENVIRONMENT = stderr_fileno_=9; export stderr_fileno_;
+# AM_TESTS_FD_REDIRECT = 9>&2
+# in your Makefile.am.
+# This is useful when using automake's parallel tests mode, to print the
+# reason for skip/failure to console, rather than to the *.log files.
+: ${stderr_fileno_=2}
+
+# Helper functions used by "plain" tests of the Automake testsuite
+# (i.e., tests that don't use any test protocol).
+# TAP tests will override these functions with their TAP-enhanced
+# equivalents later (see sourcing of 'tap-functions.sh' below).
+# These are copied from Gnulib's 'tests/init.sh'.
+warn_ () { echo "$@" 1>&$stderr_fileno_; }
+fail_ () { warn_ "$me: failed test: $@"; exit 1; }
+skip_ () { warn_ "$me: skipped test: $@"; exit 77; }
+fatal_ () { warn_ "$me: hard error: $@"; exit 99; }
+framework_failure_ () { warn_ "$me: set-up failure: $@"; exit 99; }
+# For compatibility with TAP functions.
+skip_all_ () { skip_ "$@"; }
+
+if test $am_test_protocol = tap; then
+ . tap-functions.sh
+fi
+
+## ---------------------------- ##
+## Auxiliary shell functions. ##
+## ---------------------------- ##
+
+# Tell whether we should keep the test directories around, even in
+# case of success. By default, we don't.
+am_keeping_testdirs ()
+{
+ case $keep_testdirs in
+ ""|n|no|NO) return 1;;
+ *) return 0;;
+ esac
+}
+
+# seq_ - print a sequence of numbers
+# ----------------------------------
+# This function simulates GNU seq(1) portably. Valid usages:
+# - seq LAST
+# - seq FIRST LAST
+# - seq FIRST INCREMENT LAST
+seq_ ()
+{
+ case $# in
+ 0) fatal_ "seq_: missing argument";;
+ 1) seq_first=1 seq_incr=1 seq_last=$1;;
+ 2) seq_first=$1 seq_incr=1 seq_last=$2;;
+ 3) seq_first=$1 seq_incr=$2 seq_last=$3;;
+ *) fatal_ "seq_: too many arguments";;
+ esac
+ i=$seq_first
+ while test $i -le $seq_last; do
+ echo $i
+ i=$(($i + $seq_incr))
+ done
+}
+
+# rm_rf_ [FILES OR DIRECTORIES ...]
+# ---------------------------------
+# Recursively remove the given files or directory, also handling the case
+# of non-writable subdirectories.
+rm_rf_ ()
+{
+ test $# -gt 0 || return 0
+ $PERL "$am_testaux_srcdir"/deltree.pl "$@"
+}
+
+commented_sed_unindent_prog='
+ /^$/b # Nothing to do for empty lines.
+ x # Get x<indent> into pattern space.
+ /^$/{ # No prior x<indent>, go prepare it.
+ g # Copy this 1st non-blank line into pattern space.
+ s/^\(['"$tab"' ]*\).*/x\1/ # Prepare x<indent> in pattern space.
+ } # Now: x<indent> in pattern and <line> in hold.
+ G # Build x<indent>\n<line> in pattern space, and
+ h # duplicate it into hold space.
+ s/\n.*$// # Restore x<indent> in pattern space, and
+ x # exchange with the above duplicate in hold space.
+ s/^x\(.*\)\n\1// # Remove leading <indent> from <line>.
+ s/^x.*\n// # Restore <line> when there is no leading <indent>.
+'
+
+# unindent [input files...]
+# -------------------------
+# Remove the "proper" amount of leading whitespace from the given files,
+# and output the result on stdout. That amount is determined by looking
+# at the leading whitespace of the first non-blank line in the input
+# files. If no input file is specified, standard input is implied.
+unindent ()
+{
+ if test x"$sed_unindent_prog" = x; then
+ sed_unindent_prog=$(printf '%s\n' "$commented_sed_unindent_prog" \
+ | sed -e "s/ *# .*//")
+ fi
+ sed "$sed_unindent_prog" ${1+"$@"}
+}
+sed_unindent_prog="" # Avoid interferences from the environment.
+
+## ---------------------------------------------------------------- ##
+## Create and set up of the temporary directory used by the test. ##
+## Set up of the exit trap for cleanup of said directory. ##
+## ---------------------------------------------------------------- ##
+
+# Set up the exit trap.
+am_exit_trap ()
+{
+ exit_status=$1
+ set +e
+ cd "$am_top_builddir"
+ if test $am_test_protocol = tap; then
+ if test "$planned_" = later && test $exit_status -eq 0; then
+ plan_ "now"
+ fi
+ test $exit_status -eq 0 && test $tap_pass_count_ -eq $tap_count_ \
+ || keep_testdirs=yes
+ else
+ # This is to ensure that a test script does give a SKIP outcome just
+ # because a command in it happens to exit with status 77. This
+ # behaviour, while from time to time useful to developers, is not
+ # meant to be enabled by default, as it could cause spurious failures
+ # in the wild. Thus it will be enabled only when the variable
+ # 'am_explicit_skips' is set to a "true" value.
+ case $am_explicit_skips in
+ [yY]|[yY]es|1)
+ if test $exit_status -eq 77 && test $am__test_skipped != yes; then
+ echo "$me: implicit skip turned into failure"
+ exit_status=78
+ fi;;
+ esac
+ test $exit_status -eq 0 || keep_testdirs=yes
+ fi
+ am_keeping_testdirs || rm_rf_ $am_test_subdir
+ set +x
+ # Spurious escaping to ensure we do not call our "exit" alias.
+ \exit $exit_status
+}
+
+am_set_exit_traps ()
+{
+ trap 'am_exit_trap $?' 0
+ trap "fatal_ 'caught signal SIGHUP'" 1
+ trap "fatal_ 'caught signal SIGINT'" 2
+ trap "fatal_ 'caught signal SIGTERM'" 15
+ # Various shells seems to just ignore SIGQUIT under some circumstances,
+ # even if the signal is not blocked; however, if the signal is trapped,
+ # the trap gets correctly executed. So we also trap SIGQUIT.
+ # Here is a list of some shells that have been verified to exhibit the
+ # problematic behavior with SIGQUIT:
+ # - zsh 4.3.12 on Debian GNU/Linux
+ # - /bin/ksh and /usr/xpg4/bin/sh on Solaris 10
+ # - Bash 3.2.51 on Solaris 10 and bash 4.1.5 on Debian GNU/Linux
+ # - AT&T ksh on Debian Gnu/Linux (deb package ksh, version 93u-1)
+ # OTOH, at least these shells that do *not* exhibit that behaviour:
+ # - modern version of the Almquist Shell (at least 0.5.5.1), on
+ # both Solaris and GNU/Linux
+ # - public domain Korn Shell, version 5.2.14, on Debian GNU/Linux
+ trap "fatal_ 'caught signal SIGQUIT'" 3
+ # Ignore further SIGPIPE in the trap code. This is required to avoid
+ # a very weird issue with some shells, at least when the execution of
+ # the automake testsuite is driven by the 'prove' utility: if prove
+ # (or the make process that has spawned it) gets interrupted with
+ # Ctrl-C, the shell might go in a loop, continually getting a SIGPIPE,
+ # sometimes finally dumping core, other times hanging indefinitely.
+ # See also Test::Harness bug [rt.cpan.org #70855], archived at
+ # <https://rt.cpan.org/Ticket/Display.html?id=70855>
+ trap "trap '' 13; fatal_ 'caught signal SIGPIPE'" 13
+}
+
+am_test_setup ()
+{
+ process_requirements $required
+ am_set_exit_traps
+ # Create and populate the temporary directory, if required.
+ if test x"$am_create_testdir" = x"no"; then
+ am_test_subdir=
+ else
+ am_setup_testdir
+ fi
+ am_extra_info
+ set -x
+ pwd
+}
diff --git a/t/ax/testsuite-summary-checks.sh b/t/ax/testsuite-summary-checks.sh
new file mode 100644
index 000000000..0078d1ccf
--- /dev/null
+++ b/t/ax/testsuite-summary-checks.sh
@@ -0,0 +1,102 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check the testsuite summary with the parallel test harness. This
+# script is meant to be sourced by other test script, so that it can
+# be used to check different scenarios (colorized and non-colorized
+# testsuite output, packages with and without bug-report addresses,
+# testsuites in subdirectories, ...)
+
+. test-init.sh
+
+case $use_colors in
+ yes)
+ AM_COLOR_TESTS=always; export AM_COLOR_TESTS
+ # Forced colorization should take place also with non-ANSI
+ # terminals; hence this setting.
+ TERM=dumb; export TERM
+ ;;
+ no)
+ ;;
+ *)
+ fatal_ "invalid use_colors='$use_colors'";;
+esac
+
+cat > configure.ac <<END
+AC_INIT([GNU AutoFoo], [7.1], [bug-automake@gnu.org])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+TEST_EXTENSIONS = .t
+T_LOG_COMPILER = $(SHELL) $(srcdir)/log-compiler
+## Will be defined at runtime.
+TESTS =
+$(TESTS):
+END
+
+cat > log-compiler <<'END'
+#!/bin/sh
+case "$1" in
+ pass*|*/pass*|xpass*|*/xpass*) exit 0;;
+ fail*|*/fail*|xfail*|*/xfail*) exit 1;;
+ skip*|*/skip*) exit 77;;
+ error*|/error*) exit 99;;
+ copy*|*/copy*) cat "$1";;
+ *) exit 99;;
+esac
+END
+
+# Quite complexish, but allow the tests in client scripts to be written
+# in a "data-driven fashion".
+do_check ()
+{
+ cat > summary.exp
+ expect_failure=false
+ xfail_tests=''
+ tests="$*"
+ for t in $*; do
+ case $t in fail*|xpass*|error*) expect_failure=:;; esac
+ case $t in xfail*|xpass*) xfail_tests="$xfail_tests $t";; esac
+ done
+ run_make -O -e IGNORE check TESTS="$tests" XFAIL_TESTS="$xfail_tests"
+ if $expect_failure; then
+ test $am_make_rc -gt 0 || exit 1
+ else
+ test $am_make_rc -eq 0 || exit 1
+ fi
+ $PERL "$am_testaux_srcdir"/extract-testsuite-summary.pl stdout >summary.got \
+ || fatal_ "cannot extract testsuite summary"
+ cat summary.exp
+ cat summary.got
+ if test $use_colors = yes; then
+ # Use cmp, not diff, because the files might contain binary data.
+ compare=cmp
+ else
+ compare=diff
+ fi
+ $compare summary.exp summary.got || exit 1
+}
+
+br='============================================================================'
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+:
diff --git a/t/ax/trivial-test-driver b/t/ax/trivial-test-driver
new file mode 100644
index 000000000..5745fe3d9
--- /dev/null
+++ b/t/ax/trivial-test-driver
@@ -0,0 +1,102 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+#
+# Test driver for a very simple test protocol used by the Automake
+# testsuite to check support for custom test drivers allowing for more
+# test results per test script.
+#
+# The exit status of the wrapped script is ignored. Lines in its stdout
+# and stderr beginning with 'PASS', 'FAIL', 'XFAIL', 'XPASS', 'SKIP' or
+# 'ERROR' count as a test case result with the obviously-corresponding
+# outcome. Every other line is ignored for what concerns the testsuite
+# outcome.
+#
+# This script is used at least by the 'driver-custom-multitest*.test'
+# tests.
+#
+
+# Help to avoid typo-related bugs.
+set -u
+
+## Option parsing.
+
+test_name=INVALID.NAME
+log_file=BAD.LOG
+trs_file=BAD.TRS
+while test $# -gt 0; do
+ case $1 in
+ --test-name) test_name=$2; shift;;
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ # Ignored.
+ --expect-failure) shift;;
+ --color-tests) shift;;
+ --enable-hard-errors) shift;;
+ # Explicitly terminate option list.
+ --) shift; break;;
+ # Shouldn't happen
+ *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
+ esac
+ shift
+done
+
+## Log file header.
+{
+ echo "RUN: $test_name"
+ echo "RUN: $test_name" | sed 's/./=/g'
+ echo
+} > $log_file
+
+## Run the test script, get test cases results, display them on console.
+
+"$@" 2>&1 | tee -a $log_file | (
+ i=0 st=0
+ exec 5> $trs_file
+ while read line; do
+ result=
+ case $line in
+ PASS:*) result=PASS ;;
+ FAIL:*) result=FAIL ;;
+ XPASS:*) result=XPASS ;;
+ XFAIL:*) result=XFAIL ;;
+ SKIP:*) result=SKIP ;;
+ ERROR:*) result=ERROR ;;
+ esac
+ if test -n "$result"; then
+ case $result in FAIL|XPASS|ERROR) st=1;; esac
+ # Output testcase result to console.
+ echo "$result: $test_name"
+ # Register testcase outcome for the log file.
+ echo ":test-result: $line" >&5
+ echo >&5
+ fi
+ done
+ if test $st -eq 0; then
+ recheck=no
+ copy_in_global_log=no
+ else
+ recheck=yes
+ copy_in_global_log=yes
+ fi
+ echo ":recheck: $recheck" >&5
+ echo ":copy-in-global-log: $copy_in_global_log" >&5
+ exec 5>&-
+) | awk '{ print $0 ", testcase " NR }'
+
+## And we're done.
+
+exit 0
diff --git a/t/backcompat-acout.sh b/t/backcompat-acout.sh
new file mode 100644
index 000000000..262f72997
--- /dev/null
+++ b/t/backcompat-acout.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Backward-compatibility: AC_OUTPUT with arguments.
+
+. test-init.sh
+
+mkdir sub
+: > Makefile.am
+: > zardoz
+: > foo.in
+: > foo1.in
+: > foo2.in
+: > foo3.in
+: > sub/bar.in
+
+ls -l # For debugging.
+
+for args in \
+ 'foo' \
+ 'foo:foo1.in' \
+ 'foo:zardoz' \
+ 'foo:sub/bar.in' \
+ 'foo:foo1.in:foo2.in' \
+ 'foo:zardoz:zardoz' \
+ 'foo:foo1.in:foo2.in:foo3.in' \
+ 'foo:foo1.in:foo2.in:sub/bar.in:foo3.in' \
+; do
+ rm -rf autom4te*.cache aclocal.m4
+ unindent >configure.ac <<END
+ AC_INIT([$me], [1.0])
+ AM_INIT_AUTOMAKE
+ AC_CONFIG_FILES([$args])
+ AC_OUTPUT
+END
+ cat configure.ac # For debugging.
+ $ACLOCAL
+ $AUTOMAKE Makefile
+ mv -f Makefile.in Makefile.acf
+ rm -rf autom4te*.cache aclocal.m4
+ unindent >configure.ac <<END
+ AC_INIT([$me], [1.0])
+ AM_INIT_AUTOMAKE
+ AC_OUTPUT([$args])
+END
+ cat configure.ac # For debugging.
+ $ACLOCAL
+ $AUTOMAKE Makefile
+ mv -f Makefile.in Makefile.aco
+ diff Makefile.acf Makefile.aco
+done
+
+:
diff --git a/t/backcompat.sh b/t/backcompat.sh
new file mode 100644
index 000000000..83e605847
--- /dev/null
+++ b/t/backcompat.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test usage of AM_INIT_AUTOMAKE with two or three arguments, for
+# backward-compatibility.
+
+. test-init.sh
+
+cat > Makefile.am <<'END'
+.PHONY: test display
+
+## Might be useful for debugging.
+display:
+## The following should be substituted by AM_INIT_AUTOMAKE.
+ @echo PACKAGE = $(PACKAGE)
+ @echo VERSION = $(VERSION)
+## The following should not be substituted, as we used the
+## old form of AC_INIT.
+ @echo PACKAGE_NAME = $(PACKAGE_NAME)
+ @echo PACKAGE_VERSION = $(PACKAGE_VERSION)
+ @echo PACKAGE_TARNAME = $(PACKAGE_TARNAME)
+ @echo PACKAGE_STRING = $(PACKAGE_STRING)
+
+test: display
+ test x'$(PACKAGE)' = x'FooBar'
+ test x'$(VERSION)' = x'0.7.1'
+ test x'$(PACKAGE_NAME)' = x
+ test x'$(PACKAGE_VERSION)' = x
+ test x'$(PACKAGE_TARNAME)' = x
+ test x'$(PACKAGE_STRING)' = x
+END
+
+for ac_init in 'AC_INIT' 'AC_INIT([Makefile.am])'; do
+ for am_extra_args in '' ', []' ', [:]' ', [false]'; do
+ rm -rf autom4te*.cache config* Makefile.in Makefile
+ unindent > configure.ac <<END
+ $ac_init
+ AM_INIT_AUTOMAKE([FooBar], [0.7.1]$am_extra_args)
+ AC_CONFIG_FILES([Makefile])
+ AC_OUTPUT
+END
+ cat configure.ac # For debugging.
+ $ACLOCAL
+ $AUTOCONF
+ $AUTOMAKE -Wno-obsolete
+ ./configure
+ $MAKE test
+ done
+done
+
+:
diff --git a/t/backcompat2.sh b/t/backcompat2.sh
new file mode 100644
index 000000000..43a43868b
--- /dev/null
+++ b/t/backcompat2.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Backward-compatibility test: check that AM_INIT_AUTOMAKE with two or
+# three arguments does AC_DEFINE the symbols PACKAGE and VERSION iff the
+# third argument is empty or non-existent.
+
+am_create_testdir=empty
+. test-init.sh
+
+# A trick to make the test run muuuch faster, by avoiding repeated
+# runs of aclocal (one order of magnitude improvement in speed!).
+echo 'AC_INIT(x,0) AM_INIT_AUTOMAKE' > configure.ac
+$ACLOCAL
+rm -rf configure.ac autom4te.*
+
+touch install-sh missing
+
+cat > config.h.in <<'END'
+#undef PACKAGE
+#undef VERSION
+END
+
+for am_arg3 in ':' 'false' '#' ' '; do
+ unindent > configure.ac <<END
+ AC_INIT
+ AC_CONFIG_HEADERS([config.h])
+ AM_INIT_AUTOMAKE([pkgname], [pkgversion], [$am_arg3])
+ AC_OUTPUT
+END
+ cat configure.ac # For debugging.
+ $AUTOCONF
+ ./configure
+ cat config.h # For debugging.
+ # The non-empty third argument should prevent PACKAGE and VERSION
+ # from being AC_DEFINE'd.
+ $EGREP 'pkg(name|version)' config.h && exit 1
+ # This is required because even relatively-recent versions of the
+ # BSD shell wrongly exit when the 'errexit' shell flag is active if
+ # the last command of a compound statement fails, even if it should
+ # be protected by the use of "&&".
+ :
+done
+
+for am_extra_args in '' ',' ', []'; do
+ unindent > configure.ac <<END
+ AC_INIT
+ AC_CONFIG_HEADERS([config.h])
+ AM_INIT_AUTOMAKE([pkgname], [pkgversion]$am_extra_args)
+ AC_OUTPUT
+END
+ cat configure.ac # For debugging.
+ $AUTOCONF
+ ./configure
+ cat config.h # For debugging.
+ grep '^ *# *define *PACKAGE *"pkgname" *$' config.h
+ grep '^ *# *define *VERSION *"pkgversion" *$' config.h
+done
+
+:
diff --git a/t/backcompat3.sh b/t/backcompat3.sh
new file mode 100644
index 000000000..88047827d
--- /dev/null
+++ b/t/backcompat3.sh
@@ -0,0 +1,147 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Backward-compatibility test: check what happens when AC_INIT and
+# AM_INIT_AUTOMAKE are both given two or more arguments.
+
+am_create_testdir=empty
+. test-init.sh
+
+empty=''
+
+AUTOMAKE="$AUTOMAKE -Wno-obsolete"
+
+cat > Makefile.am <<'END'
+## Leading ':;' here required to work around bugs of (at least) bash 3.2
+got: Makefile
+ @:; { \
+ echo 'PACKAGE = $(PACKAGE)'; \
+ echo 'VERSION = $(VERSION)'; \
+ echo 'PACKAGE_NAME = $(PACKAGE_NAME)'; \
+ echo 'PACKAGE_VERSION = $(PACKAGE_VERSION)'; \
+ echo 'PACKAGE_STRING = $(PACKAGE_STRING)'; \
+ echo 'PACKAGE_TARNAME = $(PACKAGE_TARNAME)'; \
+ echo 'PACKAGE_BUGREPORT = $(PACKAGE_BUGREPORT)'; \
+ echo 'PACKAGE_URL = $(PACKAGE_URL)'; \
+ } >$@
+END
+
+
+### Run 1 ###
+
+cat > configure.ac <<END
+AC_INIT([ac_name], [ac_version])
+AM_INIT_AUTOMAKE([am_name], [am_version])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat configure.ac
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+cat >exp <<END
+PACKAGE = am_name
+VERSION = am_version
+PACKAGE_NAME = ac_name
+PACKAGE_VERSION = ac_version
+PACKAGE_STRING = ac_name ac_version
+PACKAGE_TARNAME = ac_name
+PACKAGE_BUGREPORT = $empty
+PACKAGE_URL = $empty
+END
+
+$MAKE got
+
+diff exp got
+
+
+### Run 2 ###
+
+cat > configure.ac <<'END'
+AC_INIT([ac_name], [ac_version], [ac_bugreport], [ac_tarname],
+ [ac_url])],
+AM_INIT_AUTOMAKE([am_name], [am_version])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat configure.ac
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+cat >exp <<END
+PACKAGE = am_name
+VERSION = am_version
+PACKAGE_NAME = ac_name
+PACKAGE_VERSION = ac_version
+PACKAGE_STRING = ac_name ac_version
+PACKAGE_TARNAME = ac_tarname
+PACKAGE_BUGREPORT = ac_bugreport
+PACKAGE_URL = ac_url
+END
+
+$MAKE got
+
+diff exp got
+
+
+### Run 3 ###
+
+cat > configure.ac <<END
+AC_INIT([ac_name], [ac_version])
+AM_INIT_AUTOMAKE([am_name], [am_version], [am_foo_quux])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat configure.ac
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+cat >exp <<END
+PACKAGE = am_name
+VERSION = am_version
+PACKAGE_NAME = ac_name
+PACKAGE_VERSION = ac_version
+PACKAGE_STRING = ac_name ac_version
+PACKAGE_TARNAME = ac_name
+PACKAGE_BUGREPORT = $empty
+PACKAGE_URL = $empty
+END
+
+$MAKE got
+
+diff exp got
+
+$FGREP am_foo_quux Makefile.in Makefile configure config.status && exit 1
+
+
+### Done ###
+
+:
diff --git a/t/backcompat6.sh b/t/backcompat6.sh
new file mode 100644
index 000000000..3c81a55f8
--- /dev/null
+++ b/t/backcompat6.sh
@@ -0,0 +1,105 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Backward-compatibility test: try to build and distribute a package
+# using obsoleted forms of AC_INIT, AM_INIT_AUTOMAKE and AC_OUTPUT,
+# and 'configure.in' as autconf input file.
+# This script can also serve as mild stress-testing for Automake.
+# See also the similar test 'backcompat5.test'.
+
+required=cc
+am_create_testdir=empty
+. test-init.sh
+
+# Anyone doing something like this in a real-life package probably
+# deserves to be killed.
+cat > configure.ac <<'END'
+dnl: Everything here is *deliberately* underquoted!
+AC_INIT(quux.c)
+PACKAGE=nonesuch-zardoz
+VERSION=nonesuch-0.1
+AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
+AC_SUBST(one,1)
+two=2
+AC_SUBST(two, $two)
+three=3
+AC_SUBST(three)
+AC_PROG_CC
+AM_CONFIG_HEADER(config.h:config.hin)
+AM_CONDITIONAL(CROSS_COMPILING, test "$cross_compiling" = yes)
+AC_OUTPUT(Makefile foo.got:foo1.in:foo2.in:foo3.in)
+END
+
+echo @one@ > foo1.in
+echo @two@ > foo2.in
+echo @three@ > foo3.in
+
+cat >config.hin <<'END'
+#undef PACKAGE
+#undef VERSION
+END
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = quux.c
+check-local:
+ test x'$(PACKAGE)' = x'nonesuch-zardoz'
+ test x'$(VERSION)' = x'nonesuch-0.1'
+if ! CROSS_COMPILING
+ ./foo
+## Do not anchor the regexps w.r.t. the end of line, because on
+## MinGW/MSYS, grep may assume LF line endings only, while our
+## 'foo' program may generate CRLF line endings.
+ ./foo | grep '^PACKAGE = nonesuch-zardoz!'
+ ./foo | echo '^VERSION = nonesuch-0\.1!'
+endif
+END
+
+cat > quux.c <<'END'
+#include <config.h>
+#include <stdio.h>
+int main (void)
+{
+ printf("PACKAGE = %s!\nVERSION = %s!\n", PACKAGE, VERSION);
+ return 0;
+}
+END
+
+$ACLOCAL -Wno-obsolete
+$AUTOMAKE -Wno-obsolete --add-missing
+$AUTOCONF
+
+./configure
+
+cat >foo.exp <<'END'
+1
+2
+3
+END
+
+diff foo.exp foo.got
+
+$MAKE
+$MAKE check
+
+distdir=nonesuch-zardoz-nonesuch-0.1
+$MAKE distdir
+test -f $distdir/quux.c
+test ! -f $distdir/foo.got
+
+$MAKE distcheck
+
+:
diff --git a/t/backslash-before-trailing-whitespace.sh b/t/backslash-before-trailing-whitespace.sh
new file mode 100644
index 000000000..843c6ef2f
--- /dev/null
+++ b/t/backslash-before-trailing-whitespace.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we diagnose and fix white spaces following backslash.
+# Report from Peter Muir.
+
+. test-init.sh
+
+echo AC_OUTPUT >>configure.ac
+
+# Note: trailing whitespace used during the test should not appear as
+# trailing whitespace in this file, or it will get stripped by any
+# reasonable editor.
+
+echo 'bin_SCRIPTS = foo \ ' >Makefile.am
+cat >>Makefile.am <<'END'
+bar
+ok:
+ :
+END
+echo 'data_DATA = baz \ ' >>Makefile.am
+echo ' fum' >>Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+AUTOMAKE_fails
+grep ':1:.*whitespace' stderr
+grep ':5:.*whitespace' stderr
+$AUTOMAKE -Wno-error
+./configure
+# Older versions of Automake used to produce invalid Makefiles such input.
+$MAKE ok
diff --git a/t/backslash-issues.sh b/t/backslash-issues.sh
new file mode 100644
index 000000000..21102346d
--- /dev/null
+++ b/t/backslash-issues.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for "\" problems.
+# TODO: might be nice to convert this to TAP...
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+$ACLOCAL
+
+# Bug report from Joerg-Martin Schwarz.
+cat > Makefile.am << 'END'
+bin_PROGRAMS = \
+ frob
+END
+$AUTOMAKE
+grep '^_SOURCE' Makefile.in && exit 1
+
+# We must skip the backslash, not complain about './\' not existing.
+# Reported by Rick Scott <rwscott@omnisig.com>
+cat > Makefile.am << 'END'
+SUBDIRS = \
+ .
+END
+$AUTOMAKE
+
+# Make sure we diagnose trailing backslash at the end of a file.
+# Report from Akim Demaile <akim@epita.fr>.
+echo 'foo = \' > Makefile.am
+AUTOMAKE_fails
+grep 'trailing backslash' stderr
+
+:
diff --git a/t/badline.sh b/t/badline.sh
new file mode 100644
index 000000000..c1dd4b0a7
--- /dev/null
+++ b/t/badline.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that line number and file name in error message
+# referring to variable is always correct.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_SUBST(TEXINFOS)
+AC_CONFIG_FILES([Makefile])
+END
+
+: > Makefile.am
+
+$ACLOCAL || exit 1
+AUTOMAKE_fails
+grep 'configure.ac:3:.*info_TEXINFOS' stderr
diff --git a/t/badopt.sh b/t/badopt.sh
new file mode 100644
index 000000000..dad8b2a2d
--- /dev/null
+++ b/t/badopt.sh
@@ -0,0 +1,25 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure bad options cause error.
+
+. test-init.sh
+
+echo 'AUTOMAKE_OPTIONS = zardoz' > Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+grep zardoz stderr
diff --git a/t/badprog.sh b/t/badprog.sh
new file mode 100644
index 000000000..5620f3830
--- /dev/null
+++ b/t/badprog.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that programs with bad names are properly
+# transformed.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = a,b
+a_b_SOURCES = ab.c
+END
+
+$ACLOCAL
+$AUTOMAKE
diff --git a/t/built-sources-check.sh b/t/built-sources-check.sh
new file mode 100644
index 000000000..7b2de2569
--- /dev/null
+++ b/t/built-sources-check.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'check:' honors $(BUILT_SOURCES).
+# PR/359.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([dir/Makefile])
+AC_OUTPUT
+END
+
+mkdir dir
+
+cat > Makefile.am << 'END'
+BUILT_SOURCES = command1.inc
+SUBDIRS = dir
+TESTS = subrun.sh
+subrun.sh:
+ (echo '#! /bin/sh'; cat command1.inc) > $@
+ chmod +x $@
+command1.inc:
+ echo 'dir/echo.sh' > $@
+CLEANFILES = subrun.sh command1.inc
+END
+
+cat > dir/Makefile.am << 'END'
+BUILT_SOURCES = command2.inc
+check_SCRIPTS = echo.sh
+echo.sh:
+## The next line ensures that command1.inc has been built before
+## recurring into the subdir.
+ test -f ../command1.inc
+ (echo '#! /bin/sh'; cat command2.inc) > $@
+ chmod +x $@
+command2.inc:
+ echo 'echo Hello' > $@
+CLEANFILES = echo.sh command2.inc
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure --prefix "$(pwd)/inst"
+
+run_make -O check
+grep '^PASS: subrun\.sh *$' stdout
+grep 'PASS.*echo\.sh' stdout && exit 1
+
+$MAKE distcheck
+
+:
diff --git a/t/built-sources-cond.sh b/t/built-sources-cond.sh
new file mode 100644
index 000000000..57b6abea4
--- /dev/null
+++ b/t/built-sources-cond.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Interaction of BUILT_SOURCES with conditionals.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AM_CONDITIONAL([COND1], [test $cond1 = yes])
+AM_CONDITIONAL([COND2], [test $cond2 = yes])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if COND1
+BUILT_SOURCES = a
+else
+BUILT_SOURCES = b
+endif
+if COND2
+BUILT_SOURCES += c
+endif
+
+a b c:
+ echo who cares > $@
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+cleanup ()
+{
+ # Files in $(BUILT_SOURCES) should be automatically removed
+ # upon maintainer-clean.
+ $MAKE maintainer-clean
+ test ! -f a
+ test ! -f b
+ test ! -f c
+}
+
+./configure cond1=yes cond2=yes
+
+$MAKE
+test -f a
+test ! -f b
+test -f c
+
+cleanup
+
+./configure cond1=no cond2=yes
+
+$MAKE
+test ! -f a
+test -f b
+test -f c
+
+cleanup
+
+./configure cond1=yes cond2=no
+
+$MAKE
+test -f a
+test ! -f b
+test ! -f c
+
+cleanup
+
+./configure cond1=no cond2=no
+
+$MAKE
+test ! -f a
+test -f b
+test ! -f c
+
+cleanup
+
+:
diff --git a/t/built-sources-fork-bomb.sh b/t/built-sources-fork-bomb.sh
new file mode 100644
index 000000000..59ded6931
--- /dev/null
+++ b/t/built-sources-fork-bomb.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Due to how the handling of $(BUILT_SOURCES) is implemented in Automake-NG,
+# a recursive make call in the recipe of any $(BUILT_SOURCES) (or of any of
+# its prerequisites) might cause an infinite recursion (complete with fork
+# bomb, yuck) if not handled correctly. Verify that this doesn't happen.
+# For more background, see:
+# <https://lists.gnu.org/archive/html/help-smalltalk/2012-08/msg00027.html>
+# <https://lists.gnu.org/archive/html/automake-patches/2012-08/msg00052.html>
+# Backported to improve coverage of mainline Automake.
+
+required=GNUmake
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+BUILT_SOURCES = foo
+.PHONY: build-foo
+build-foo:
+ echo OK > foo
+foo:
+ $(MAKE) build-foo
+
+# If the bug is still present, we want this test to fail, not to actually
+# go fork bomb and potentially crash the user machine. Take care of that.
+
+is_too_deep := $(shell test $(MAKELEVEL) -lt 10 && echo no)
+
+## Extra indentation here required to avoid confusing Automake.
+ ifeq ($(is_too_deep),no)
+ # All is ok.
+ else
+ $(error ::OOPS:: Recursion too deep, $(MAKELEVEL) levels)
+ endif
+END
+
+$ACLOCAL
+$AUTOMAKE -Wno-portability
+$AUTOCONF
+
+./configure
+
+run_make -M -- -n foo
+test ! -f foo
+# Guard against possible infinite recursion.
+$FGREP '::OOPS::' output && exit 1
+
+run_make -M -- foo
+# Guard against possible infinite recursion.
+$FGREP '::OOPS::' output && exit 1
+
+:
diff --git a/t/built-sources-install.sh b/t/built-sources-install.sh
new file mode 100644
index 000000000..8f9103d36
--- /dev/null
+++ b/t/built-sources-install.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'install:' honors $(BUILT_SOURCES).
+# PR/359.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([dir/Makefile])
+AC_OUTPUT
+END
+
+mkdir dir
+
+cat > Makefile.am << 'END'
+BUILT_SOURCES = built1
+SUBDIRS = dir
+built1:
+ echo ok > $@
+CLEANFILES = built1
+install-data-hook:
+ $(MKDIR_P) $(DESTDIR)$(prefix)/dir2
+ cp built1 $(DESTDIR)$(prefix)/built1
+ cp dir/built2 $(DESTDIR)$(prefix)/dir2/built3
+uninstall-hook:
+ rm -f $(DESTDIR)$(prefix)/built1
+ rm -f $(DESTDIR)$(prefix)/dir2/built3
+ rmdir $(DESTDIR)$(prefix)/dir2
+installcheck-local:
+ test -f $(prefix)/built1
+ test -f $(prefix)/dir2/built3
+END
+
+cat > dir/Makefile.am << 'END'
+BUILT_SOURCES = built2
+built2:
+## The next line ensures that command1.inc has been built before
+## recurring into the subdir.
+ cp ../built1 $@
+CLEANFILES = built2
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure --prefix "$(pwd)/inst"
+
+# Now make sure these two files are rebuilt during make install.
+$MAKE install
+test -f built1
+test -f dir/built2
+$MAKE installcheck
+$MAKE distcheck
+
+:
diff --git a/t/built-sources-subdir.sh b/t/built-sources-subdir.sh
new file mode 100644
index 000000000..9f892fa46
--- /dev/null
+++ b/t/built-sources-subdir.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure when using SUBDIRS that all BUILT_SOURCES are built.
+# A bug occurred where subdirs do not have all-recursive or
+# all-recursive-am which depended on BUILT_SOURCES.
+
+required=cc
+. test-init.sh
+
+mkdir lib
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([lib/Makefile])
+AC_PROG_RANLIB
+AC_PROG_CC
+AM_PROG_AR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = lib
+END
+
+cat > lib/Makefile.am << 'END'
+pkgdata_DATA =
+noinst_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+BUILT_SOURCES = foo.h
+foo.h:
+ echo \#define FOO_DEFINE 1 >$@
+CLEANFILES = $(BUILT_SOURCES)
+END
+
+cat > lib/foo.c << 'END'
+#include <foo.h>
+int foo (void) { return !FOO_DEFINE; }
+END
+
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+./configure
+$MAKE
+$MAKE distcheck
+
+:
diff --git a/t/built-sources.sh b/t/built-sources.sh
new file mode 100644
index 000000000..99d5bca03
--- /dev/null
+++ b/t/built-sources.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic test on BUILT_SOURCES.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+BUILT_SOURCES = foo.c
+noinst_PROGRAMS = bar baz
+foo.c:
+ rm -f $@ $@-t
+## Use printf, not echo, to avoid spurious interpretation of
+## the "\n" as a newline (seen on NetBSD 5.1).
+ printf '%s\n' '#include <stdio.h>' > $@-t
+ printf '%s\n' 'int main (void)' >> $@-t
+ printf '%s\n' '{ ' >> $@-t
+ printf '%s\n' ' printf ("%s\n", FOOMSG);' >> $@-t
+ printf '%s\n' ' return 0;' >> $@-t
+ printf '%s\n' '}' >> $@-t
+ mv -f $@-t $@
+CLEANFILES = foo.c
+END
+
+cat > bar.c <<'END'
+#define FOOMSG "Howdy, World"
+#include "foo.c"
+END
+
+cat > baz.c <<'END'
+#define FOOMSG "Hello, Earth"
+#include "foo.c"
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE
+if cross_compiling; then :; else
+ ./bar
+ ./bar | grep 'Howdy, World'
+ ./baz
+ ./baz | grep 'Hello, Earth'
+fi
+$MAKE distcheck
+
+:
diff --git a/t/c-demo.sh b/t/c-demo.sh
new file mode 100644
index 000000000..ff3616ca7
--- /dev/null
+++ b/t/c-demo.sh
@@ -0,0 +1,178 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Demo on C support, also testing automatic dependency tracking,
+# conditional SUBDIRS and convenience libraries.
+
+required=cc
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([GNU C Demo], [22.3.2], [bug-automake@gnu.org])
+AC_CONFIG_SRCDIR([tests/test.test])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AM_CONDITIONAL([RUN_TESTS], [test x"$run_tests" != x"no"])
+AC_CONFIG_FILES([Makefile src/Makefile lib/Makefile tests/Makefile])
+AC_OUTPUT
+END
+
+if cross_compiling; then
+ run_tests=no
+else
+ run_tests=yes
+fi
+export run_tests
+
+mkdir build-aux lib src tests
+
+cat > Makefile.am <<'END'
+SUBDIRS = lib src
+
+if RUN_TESTS
+SUBDIRS += tests
+endif
+
+.PHONY: test-objs
+check-local: test-objs
+test-objs:
+ test -f src/zardoz-main.$(OBJEXT)
+ test -f lib/foo.$(OBJEXT)
+ test -f lib/bar.$(OBJEXT)
+END
+
+cat > src/Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = main.c
+zardoz_LDADD = $(top_builddir)/lib/lib-convenience.a
+zardoz_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
+END
+
+cat > lib/Makefile.am << 'END'
+noinst_LIBRARIES = lib-convenience.a
+lib_convenience_a_SOURCES = foo.c
+lib_convenience_a_SOURCES += bar.c
+dist_lib_convenience_a_SOURCES = bar.h
+nodist_lib_convenience_a_SOURCES = foo.h
+
+# We want this to be auto-generated an removed by "make clean", to
+# ensure that cleaning rules work correctly; an older implementation
+# of automatic dependency tracking support suffered of weaknesses in
+# this situation, see the "historical comments" reported in:
+# https://lists.gnu.org/archive/html/automake-patches/2012-06/msg00033.html
+foo.h: $(srcdir)/foo.c
+ sed -n 's/.*foo *(.*/&;/p' "$(srcdir)/foo.c" >$@-t
+ test 1 -eq `wc -l <$@-t`
+ chmod a-w $@-t && mv -f $@-t $@
+BUILT_SOURCES = foo.h
+CLEANFILES = $(BUILT_SOURCES)
+
+check-local:
+ test -f ${top_srcdir}/tests/test.test
+END
+
+cat > tests/Makefile.am << 'END'
+AUTOMAKE_OPTIONS = parallel-tests
+TEST_LOG_COMPILER = $(SHELL)
+TESTS = test.test
+EXTRA_DIST = $(TESTS)
+END
+
+cat > tests/test.test << 'END'
+#!/bin/sh
+set -x; set -e;
+../src/zardoz
+test "`../src/zardoz`" = 'Foo, Bar!'
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+test -f build-aux/depcomp
+test -f build-aux/compile # We have per-target flags on C sources.
+
+# Don't reject slow dependency extractors.
+./configure --enable-dependency-tracking
+
+cat > src/main.c << 'END'
+#include "foo.h"
+#include "bar.h"
+int main (void)
+{
+ printf ("%s, %s!\n", foo (), bar ());
+ return 0;
+}
+END
+
+cat > lib/foo.c << 'END'
+#include "foo.h"
+static char s[4];
+volatile char *foo (void)
+{
+ s[0] = 'F';
+ s[1] = s[2] = 'o';
+ s[3] = '\0';
+ return s;
+}
+END
+
+cat > lib/bar.c << 'END'
+#include "bar.h"
+const char *bar (void)
+{
+ return BARBAR;
+}
+END
+
+cat > lib/bar.h << 'END'
+#define BARBAR "Bar"
+const char *bar (void);
+END
+
+$MAKE
+ls -l . src lib # For debugging.
+$MAKE test-objs
+
+VERBOSE=x $MAKE check
+if cross_compiling; then
+ test ! -e tests/test-suite.log
+ test ! -e tests/test.log
+else
+ test -f tests/test-suite.log
+ grep 'Foo, Bar!' tests/test.log
+fi
+
+$MAKE distcheck
+
+if ! cross_compiling && ! grep "[ $tab]depmode=none" Makefile; then
+ # Let's check automatic dependency tracking.
+ sed 's/^\(#define BARBAR \).*/\1 "Zap"/' lib/bar.h > t
+ mv -f t lib/bar.h
+ $MAKE
+ ./src/zardoz
+ test "$(./src/zardoz)" = 'Foo, Zap!'
+fi
+
+$MAKE clean
+test ! -e lib/foo.h
+test -f lib/bar.h
+
+:
diff --git a/t/candist.sh b/t/candist.sh
new file mode 100644
index 000000000..19615aab0
--- /dev/null
+++ b/t/candist.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure things that cannot be dist_'ed are diagnosed.
+
+. test-init.sh
+
+echo AC_OUTPUT >>configure.ac
+
+cat > Makefile.am << 'END'
+dist_bin_PROGRAMS = foo
+dist_lib_LIBRARIES = libfoo.a
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+test 2 -eq $(grep -c 'dist.*forbidden' stderr)
+
+exit 0
diff --git a/t/canon-name.sh b/t/canon-name.sh
new file mode 100644
index 000000000..c8a071fca
--- /dev/null
+++ b/t/canon-name.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# PR 511: Make sure we warn about e.g. AC_CONFIG_FILES([./gmakefile]),
+# as not all make implementations treat 'file' and './file' equally.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([./gmakefile ./sub/gmakefile])
+AC_OUTPUT
+END
+
+mkdir sub
+echo 'SUBDIRS = sub' >gmakefile.am
+: >sub/gmakefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'leading.*\./.*\./gmakefile' stderr
+grep 'leading.*\./.*\./sub/gmakefile' stderr
+
+:
diff --git a/t/canon.sh b/t/canon.sh
new file mode 100644
index 000000000..9c0915330
--- /dev/null
+++ b/t/canon.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that name canonicalization error works.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = sniff-glue
+sniff-glue_SOURCES = sg.c
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'Makefile\.am:2:.* bad .*variable.*sniff-glue_SOURCES' stderr
+grep 'Makefile\.am:2:.* use .*sniff_glue_SOURCES' stderr
+
+:
diff --git a/t/canon2.sh b/t/canon2.sh
new file mode 100644
index 000000000..d6c451001
--- /dev/null
+++ b/t/canon2.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure name canonicalization happens for texinfo.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = zar-doz.texi
+zar_doz_TEXINFOS = frob.texi
+END
+
+: > texinfo.tex
+echo '@setfilename zar-doz.info' > zar-doz.texi
+echo '@setfilename frob' > frob.texi
+
+$ACLOCAL
+$AUTOMAKE
+
+grep zar-doz_TEXINFOS Makefile.in && exit 1
+
+:
diff --git a/t/canon3.sh b/t/canon3.sh
new file mode 100644
index 000000000..20933039a
--- /dev/null
+++ b/t/canon3.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Yet another canonicalization test.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = perm-number
+END
+
+: > perm-number.c
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP 'perm_number.c' Makefile.in && exit 1
+
+:
diff --git a/t/canon4.sh b/t/canon4.sh
new file mode 100644
index 000000000..44bf47b4c
--- /dev/null
+++ b/t/canon4.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure name canonicalization happens for static libraries.
+# Keep this in sync with sister test 'canon6.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libx-y.a
+libx_y_a_SOURCES = xy.c
+END
+
+: > ar-lib
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^ *libx-y.*=' Makefile.in && exit 1
+
+:
diff --git a/t/canon5.sh b/t/canon5.sh
new file mode 100644
index 000000000..e54877cff
--- /dev/null
+++ b/t/canon5.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that we allow variable names starting in
+# non-letters. Whatever that might mean.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+$ACLOCAL
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = 123test
+123test_SOURCES = 123.c
+END
+
+$AUTOMAKE
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = _foo
+_foo_SOURCES = foo.c
+END
+
+$AUTOMAKE
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = ,foo
+,foo_SOURCES = foo.c
+END
+
+AUTOMAKE_fails
+grep 'Makefile\.am:2:.* bad .*variable.*,foo_SOURCES' stderr
+grep 'Makefile\.am:2:.* use .*_foo_SOURCES' stderr
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = ,foo
+_foo_SOURCES = foo.c
+END
+
+$AUTOMAKE -Wno-portability
+
+:
diff --git a/t/canon6.sh b/t/canon6.sh
new file mode 100644
index 000000000..ea832a080
--- /dev/null
+++ b/t/canon6.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure name canonicalization happens for libtool libraries.
+# Keep this in sync with sister test 'canon4.sh'.
+
+required='libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+END
+
+cat > Makefile.am << 'END'
+noinst_LTLIBRARIES = libx-y.la
+libx_y_la_SOURCES = xy.c
+END
+
+: > ltmain.sh
+: > ar-lib
+
+$ACLOCAL
+$AUTOMAKE -a
+
+grep '^ *libx-y.*=' Makefile.in && exit 1
+
+:
diff --git a/t/canon7.sh b/t/canon7.sh
new file mode 100644
index 000000000..37c28f2f4
--- /dev/null
+++ b/t/canon7.sh
@@ -0,0 +1,101 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Stress test on canonicalization.
+
+required='cc libtool libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB dnl: for static libraries
+AC_PROG_LIBTOOL dnl: for libtool libraries
+AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
+AC_OUTPUT
+END
+
+if touch ,foo-bar libb.az+baz lib~zardoz,,; then
+ rm -f ,foo-bar libb.az+baz lib~zardoz,,
+else
+ skip_ "cannot create regular files with \"tricky\" names"
+fi
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = dummy_static dummy_dynamic ,foo-bar
+noinst_LIBRARIES = libb.az+baz.a
+noinst_LTLIBRARIES = lib~zardoz,,.la
+
+dummy_static_SOURCES = dummy.c lib.h
+dummy_dynamic_SOURCES = $(dummy_static_SOURCES)
+
+dummy_static_LDADD = $(noinst_LIBRARIES)
+dummy_dynamic_LDADD = $(noinst_LTLIBRARIES)
+
+_foo_bar_SOURCES = foobar.c
+libb_az_baz_a_SOURCES = libs.c
+lib_zardoz___la_SOURCES = libd.c
+
+check-local:
+ ls -l
+if CROSS_COMPILING
+ test -f ./,foo-bar$(EXEEXT)
+ test -f ./dummy_static$(EXEEXT)
+ test -f ./dummy_dynamic$(EXEEXT)
+else !CROSS_COMPILING
+ ./,foo-bar
+ ./dummy_static
+ ./dummy_dynamic
+ ./,foo-bar | grep 'Hello, FooBar!'
+ ./dummy_static | grep 'Hello from Static!'
+ ./dummy_dynamic | grep 'Hello from Dynamic!'
+endif !CROSS_COMPILING
+END
+
+cat > foobar.c << 'END'
+#include <stdio.h>
+int main(void)
+{
+ printf("Hello, FooBar!\n");
+ return 0;
+}
+END
+
+cat > dummy.c << 'END'
+#include <stdio.h>
+#include "lib.h"
+int main(void)
+{
+ printf("Hello from %s!\n", dummy_func());
+ return 0;
+}
+END
+
+echo 'const char *dummy_func(void);' > lib.h
+echo 'const char *dummy_func(void) { return "Dynamic"; }' > libd.c
+echo 'const char *dummy_func(void) { return "Static"; }' > libs.c
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/canon8.sh b/t/canon8.sh
new file mode 100644
index 000000000..ae9440c4b
--- /dev/null
+++ b/t/canon8.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that canonicalization does not transliterate the '@' charactrer.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foob@rquux
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# The first grep is here mostly for debugging.
+grep foob.rquux Makefile.in
+grep foob@rquux Makefile.in
+grep 'foob[^@]rquux' Makefile.in && exit 1
+
+:
diff --git a/t/ccnoco-deps.sh b/t/ccnoco-deps.sh
new file mode 100755
index 000000000..d5264ae33
--- /dev/null
+++ b/t/ccnoco-deps.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that dependency tracking can also work with compilers that
+# doesn't understand '-c -o', even if the AM_PROG_CC_C_O macro is not
+# explicitly called.
+
+required=gcc # For 'cc-no-c-o'.
+. test-init.sh
+
+echo '#define myStr "Hello"' > foobar.h
+
+cat > foo.c << 'END'
+#include <stdio.h>
+#include "foobar.h"
+int main (void)
+{
+ printf ("%s\n", myStr);
+ return 0;
+}
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c foobar.h
+check-deps: all
+ test -n '$(DEPDIR)' && test -d '$(DEPDIR)'
+ ls -l $(DEPDIR)
+ grep 'stdio\.h' $(DEPDIR)/foo.Po
+ grep 'foobar\.h' $(DEPDIR)/foo.Po
+check-updated: all
+ is_newest foo$(EXEEXT) foobar.h
+END
+
+# We deliberately don't invoke AM_PROG_CC_C_O here.
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+# Make sure the compiler doesn't understand '-c -o'.
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+./configure >stdout || { cat stdout; exit 1; }
+cat stdout
+$EGREP 'understands? -c and -o together.* no$' stdout
+grep '^checking dependency style .*\.\.\. gcc' stdout
+
+$MAKE check-deps
+
+if ! cross_compiling; then
+ ./foo
+ test "$(./foo)" = Hello
+fi
+
+$sleep
+echo '#define myStr "Howdy"' > foobar.h
+$MAKE check-updated
+
+if ! cross_compiling; then
+ ./foo
+ test "$(./foo)" = Howdy
+fi
+
+:
diff --git a/t/ccnoco-lib.sh b/t/ccnoco-lib.sh
new file mode 100755
index 000000000..97146ba1c
--- /dev/null
+++ b/t/ccnoco-lib.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure we can compile when the compiler doesn't
+# understand '-c -o'.
+
+required=gcc # For cc-no-c-o.
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+$CC --version || exit 1
+$CC -v || exit 1
+AC_PROG_RANLIB
+AM_PROG_AR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+mylibsdir = $(libdir)/my-libs
+mylibs_LIBRARIES = libwish.a
+libwish_a_SOURCES = a.c
+# Make sure we need something strange.
+libwish_CFLAGS = -O0
+END
+
+cat > a.c << 'END'
+int wish_granted (void)
+{
+ return 0;
+}
+END
+
+# Make sure the compiler doesn't understand '-c -o'.
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+$ACLOCAL
+$AUTOCONF -Wall -Werror
+$AUTOMAKE --copy --add-missing
+
+for vpath in : false; do
+ if $vpath; then
+ srcdir=..
+ mkdir build
+ cd build
+ else
+ srcdir=.
+ fi
+ $srcdir/configure >stdout || { cat stdout; exit 1; }
+ cat stdout
+ $EGREP 'understands? -c and -o together.* no$' stdout
+ # No repeated checks please.
+ test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
+ $MAKE
+ cd $srcdir
+done
+
+$MAKE distcheck
+
+:
diff --git a/t/ccnoco-lt.sh b/t/ccnoco-lt.sh
new file mode 100755
index 000000000..3088b1a35
--- /dev/null
+++ b/t/ccnoco-lt.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure we can compile libtool libraries when the compiler
+# doesn't understand '-c -o'.
+
+required='gcc libtoolize' # For cc-no-c-o.
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+LT_INIT
+$CC --version
+$CC -v
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libwish.la
+END
+
+cat > libwish.c << 'END'
+int wish_granted (void)
+{
+ return 0;
+}
+END
+
+# Make sure the compiler doesn't understand '-c -o'.
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+libtoolize --verbose --install
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+for vpath in : false; do
+ if $vpath; then
+ srcdir=..
+ mkdir build
+ cd build
+ else
+ srcdir=.
+ fi
+ $srcdir/configure >stdout || { cat stdout; exit 1; }
+ cat stdout
+ $EGREP 'understands? -c and -o together.* no$' stdout
+ # No repeated checks please.
+ test $(grep ".*-c['\" ].*-o['\" ]" stdout \
+ | $FGREP -v ' -c -o file.o' | wc -l) -eq 1
+ # Once we have rewritten $CC to use our 'compile' wrapper script,
+ # libtool should pick it up correctly, and not mess with the
+ # redefinition.
+ grep '^checking if .*/compile .*supports -c -o file\.o\.\.\. yes' stdout
+ # And of course, we should be able to build our package.
+ $MAKE
+ cd $srcdir
+done
+
+$MAKE distcheck
+
+:
diff --git a/t/ccnoco.sh b/t/ccnoco.sh
new file mode 100644
index 000000000..48fb86a15
--- /dev/null
+++ b/t/ccnoco.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure we can compile when the compiler doesn't
+# understand '-c -o'.
+
+required=gcc # For cc-no-c-o.
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+$CC --version || exit 1
+$CC -v || exit 1
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = wish
+wish_SOURCES = a.c
+# Make sure we need something strange.
+wish_CFLAGS = -g
+END
+
+cat > a.c << 'END'
+#include <stdio.h>
+
+int main ()
+{
+ printf ("hi\n");
+}
+END
+
+# Make sure the compiler doesn't understand '-c -o'.
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+$ACLOCAL
+$AUTOCONF -Wall -Werror
+$AUTOMAKE --copy --add-missing
+
+for vpath in : false; do
+ if $vpath; then
+ srcdir=..
+ mkdir build
+ cd build
+ else
+ srcdir=.
+ fi
+ $srcdir/configure >stdout || { cat stdout; exit 1; }
+ cat stdout
+ $EGREP 'understands? -c and -o together.* no$' stdout
+ # No repeated checks please.
+ test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
+ $MAKE
+ cd $srcdir
+done
+
+$MAKE distcheck
+
+:
diff --git a/t/ccnoco3.sh b/t/ccnoco3.sh
new file mode 100644
index 000000000..4cd4443bf
--- /dev/null
+++ b/t/ccnoco3.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure 'compile' doesn't call 'mv SRC SRC'.
+
+required=gcc # For cc-no-c-o.
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+$CC --version; $CC -v; # For debugging.
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = wish
+wish_SOURCES = a.c
+END
+
+mkdir sub
+
+cat > a.c << 'END'
+#include <stdio.h>
+
+int main ()
+{
+ printf ("hi\n");
+}
+END
+
+# Make sure the compiler doesn't understand '-c -o'
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+mkdir build
+cd build
+
+../configure
+run_make -E
+grep 'mv.*the same file' stderr && exit 1
+
+:
diff --git a/t/ccnoco4.sh b/t/ccnoco4.sh
new file mode 100644
index 000000000..7b3a458a7
--- /dev/null
+++ b/t/ccnoco4.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that Automake-generated C compilation rules don't mistakenly
+# use the "-c -o" options combination unconditionally (even with losing
+# compilers) when the 'subdir-objects' is used but sources are only
+# present in the top-level directory. Reported by Nick Bowler in the
+# discussion on automake bug#13378:
+# <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=13378#35>
+# <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=13378#44>
+
+required=gcc # For cc-no-c-o.
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+$CC --version; $CC -v; # For debugging.
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = foo bar
+bar_SOURCES = foo.c
+END
+
+echo 'int main (void) { return 0; }' > foo.c
+
+# Make sure the compiler doesn't understand '-c -o'
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+./configure
+$MAKE
+$MAKE distcheck
+
+:
diff --git a/t/check-concurrency-bug9245.sh b/t/check-concurrency-bug9245.sh
new file mode 100644
index 000000000..28744ecce
--- /dev/null
+++ b/t/check-concurrency-bug9245.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Look for a bug where FreeBSD make in concurrent mode reported success
+# even when the Automake-generated parallel testsuite harness failed.
+# See automake bug#9245.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test bar.test
+END
+
+cat > foo.test <<'END'
+#!/bin/sh
+exit 1
+END
+chmod a+x foo.test
+
+cp foo.test bar.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE -j1 || skip_ "'$MAKE' doesn't support the -j option"
+
+for j in '' -j1 -j2; do
+ $MAKE $j check && exit 1
+ run_make -e FAIL -- $j TESTS=foo.test check
+ $MAKE $j recheck && exit 1
+ run_make -e FAIL -- $j TEST_LOGS=foo.log check
+ rm -f test-suite.log
+ run_make -e FAIL $j test-suite.log
+ test -f test-suite.log || exit 1
+done
+
+:
diff --git a/t/check-exported-srcdir.sh b/t/check-exported-srcdir.sh
new file mode 100644
index 000000000..5050fe032
--- /dev/null
+++ b/t/check-exported-srcdir.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the testsuite driver (either with or without the
+# serial-tests option enabled) exports the 'srcdir' value in the
+# environment of the tests. This is documented in the manual.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+show_info ()
+{
+ if test x"$am_serial_tests" != x"yes"; then
+ cat foo.log
+ cat test-suite.log
+ else
+ :
+ fi
+}
+
+mkdir SrcDir
+mv [!S]* SrcDir
+mkdir BuildDir
+cd SrcDir
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test
+END
+
+cat > foo.test <<'END'
+#!/bin/sh
+echo "foo.test: srcdir='$srcdir'"
+test x"$srcdir" = x"../SrcDir"
+END
+chmod a+x foo.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cd ../BuildDir
+../SrcDir/configure
+
+$MAKE check || { show_info; exit 1; }
+show_info
+
+:
diff --git a/t/check-fd-redirect.sh b/t/check-fd-redirect.sh
new file mode 100644
index 000000000..8be88e8ec
--- /dev/null
+++ b/t/check-fd-redirect.sh
@@ -0,0 +1,108 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Simple Tests support: redirection of file descriptors with
+# AM_TESTS_FD_REDIRECT.
+# See also related test 'parallel-tests-fd-redirect.sh'.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+TESTS = foo.test
+AM_TESTS_FD_REDIRECT = 3<three 4>four 5>>five 7<&0 8>&1 9>&2
+END
+
+echo '3333' > three
+chmod a-w three
+
+: > foo.test
+chmod a+x foo.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+
+do_check ()
+{
+ cat foo.test # For debugging.
+ echo 'this line will be removed' > four
+ echo 'this line will not be removed' > five
+ st=0; echo 'ok ok ok' | run_make -O -E -e IGNORE check || st=$?
+ cat four
+ test x"$am_serial_tests" = x"yes" || cat foo.log
+ test $st -eq 0
+ grep '[ /]foo\.test: foofoofoo$' stdout
+ grep '[ /]foo\.test: barbarbar$' stderr
+ grep 'this line' four && exit 1
+ grep '^3333$' four
+ grep '^this line will not be removed$' five
+ grep '^ok ok ok$' five
+ $EGREP '(foofoofoo|barbarbar|3333|ok ok ok|this line)' foo.log && exit 1
+ :
+}
+
+# Try using both shell script and a perl script as the test, for
+# better coverage.
+
+cat > foo.test <<'END'
+#! /bin/sh
+set -e
+
+read FOO <&3
+test 3333 -eq "$FOO"
+echo "$FOO" >&4
+
+grep '^ok ok ok$' <&7 >&5
+
+echo " " $0: foofoofoo >&8
+echo " " $0: barbarbar >&9
+END
+
+do_check
+
+echo "#! $PERL -w" > foo.test
+cat >> foo.test <<'END'
+use warnings FATAL => 'all';
+use strict;
+
+open (FD3, "<&=3") or die "opening FD3: $!";
+open (FD4, ">&=4") or die "opening FD4: $!";
+open (FD5, ">&=5") or die "opening FD5: $!";
+open (FD7, "<&=7") or die "opening FD7: $!";
+open (FD8, ">&=8") or die "opening FD8: $!";
+open (FD9, ">&=9") or die "opening FD9: $!";
+
+chomp (my $FOO = <FD3>);
+die "$FOO != 3333" if not $FOO eq "3333";
+print FD4 "$FOO\n";
+
+chomp ($_ = <FD7>);
+die "$_ != 'ok ok ok'" if not $_ eq 'ok ok ok';
+print FD5 "$_\n";
+
+print FD8 " $0: foofoofoo\n";
+print FD9 " $0: barbarbar\n";
+END
+
+do_check
+
+:
diff --git a/t/check-no-test-driver.sh b/t/check-no-test-driver.sh
new file mode 100644
index 000000000..a059616e5
--- /dev/null
+++ b/t/check-no-test-driver.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that auxiliary script 'test-driver' doesn't get needlessly
+# installed or referenced when the 'serial-tests' option is used.
+
+am_serial_tests=yes
+. test-init.sh
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = serial-tests
+TESTS = foo.test
+END
+
+$ACLOCAL
+
+for opts in '' '-a' '--add-missing --copy'; do
+ $AUTOMAKE $opts
+ $FGREP 'test-driver' Makefile.in && exit 1
+ find . | $FGREP 'test-driver' && exit 1
+ : For shells with busted 'set -e'.
+done
+
+:
diff --git a/t/check-subst-prog.sh b/t/check-subst-prog.sh
new file mode 100644
index 000000000..d4a1e4d85
--- /dev/null
+++ b/t/check-subst-prog.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check @substituted@ TESTS, some of which are also PROGRAMS.
+# See also sister test 'check-subst.sh'.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_SUBST([script_tests],
+ ['subst-pass-script.test subst-xfail-script.test'])
+AC_SUBST([prog_tests],
+ ['subst-pass-prog.test$(EXEEXT) subst-xfail-prog.test$(EXEEXT)'])
+AC_SUBST([xfail_tests],
+ ['xfail-script.test subst-xfail-script.test]dnl
+ [ xfail-prog$(EXEEXT) subst-xfail-prog.test$(EXEEXT)'])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = pass-script.test xfail-script.test @script_tests@ $(check_PROGRAMS)
+XFAIL_TESTS = @xfail_tests@
+check_PROGRAMS = pass-prog xfail-prog @prog_tests@
+EXTRA_PROGRAMS = subst-pass-prog.test subst-xfail-prog.test
+END
+
+cat > pass-script.test <<'END'
+#! /bin/sh
+exit 0
+END
+cat > xfail-script.test <<'END'
+#! /bin/sh
+exit 1
+END
+chmod a+x pass-script.test xfail-script.test
+cp pass-script.test subst-pass-script.test
+cp xfail-script.test subst-xfail-script.test
+
+cat > pass-prog.c <<'END'
+int main (void) { return 0; }
+END
+cat > xfail-prog.c <<'END'
+#include <stdlib.h>
+int main (void) { return EXIT_FAILURE; }
+END
+# The .test extension is removed for the default source file name:
+cp pass-prog.c subst-pass-prog.c
+cp xfail-prog.c subst-xfail-prog.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE all
+$MAKE check
+$MAKE distclean
+
+mkdir build
+cd build
+../configure
+$MAKE all
+$MAKE check
+$MAKE distclean
+
+:
diff --git a/t/check-subst.sh b/t/check-subst.sh
new file mode 100644
index 000000000..35a989464
--- /dev/null
+++ b/t/check-subst.sh
@@ -0,0 +1,88 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check @substituted@ TESTS.
+# Note that in this test, we rely on the .test extension for the
+# substituted names: this is necessary for the parallel harness.
+# See also sister test 'check-subst-prog.sh'.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([script_tests], ['subst-pass-script.sh subst-xfail-script.sh'])
+AC_SUBST([xfail_tests], ['xfail-script.test subst-xfail-script.sh'])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = pass-script.test xfail-script.test @script_tests@
+XFAIL_TESTS = @xfail_tests@
+END
+
+if test x"$am_serial_tests" != x"yes"; then
+ unindent >> Makefile.am <<'END'
+ TEST_EXTENSIONS = .sh .test
+ SH_LOG_COMPILER = $(SHELL)
+END
+fi
+
+cat > pass-script.test <<'END'
+#! /bin/sh
+exit 0
+END
+cat > xfail-script.test <<'END'
+#! /bin/sh
+exit 1
+END
+cp pass-script.test subst-pass-script.sh
+cp xfail-script.test subst-xfail-script.sh
+chmod a+x pass-script.test xfail-script.test
+
+if test x"$am_serial_tests" = x"yes"; then
+ chmod a+x subst-pass-script.sh subst-xfail-script.sh
+fi
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+for vpath in false : ; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+ $MAKE all
+ $MAKE check
+ if test x"$am_serial_tests" != x"yes"; then
+ ls -l
+ test -f pass-script.log
+ test -f xfail-script.log
+ test -f subst-pass-script.log
+ test -f subst-xfail-script.log
+ fi
+ $MAKE distclean
+ cd $srcdir
+
+done
+
+:
diff --git a/t/check-tests-in-builddir.sh b/t/check-tests-in-builddir.sh
new file mode 100644
index 000000000..b09c336fe
--- /dev/null
+++ b/t/check-tests-in-builddir.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the testsuite driver can find test in the srcdir as
+# well as in builddir, and that is prefers those in the builddir.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test bar.test
+EXTRA_DIST = $(TESTS)
+END
+
+cat > foo.test << 'END'
+#! /bin/sh
+exit ${FOO_EXIT_STATUS-0}
+END
+chmod a+x foo.test
+
+unset FOO_EXIT_STATUS
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkdir build
+cd build
+
+../configure
+
+cat > bar.test << 'END'
+#! /bin/sh
+exit 0
+END
+chmod a+x bar.test
+
+run_make -M check
+# The serial test driver does not strip VPATH components from
+# the name of the test, but the parallel driver should.
+if test x"$am_serial_tests" = x"yes"; then
+ grep '^PASS: .*foo\.test *$' output
+else
+ grep '\.\./foo' output && exit 1
+ grep '^PASS: foo\.test *$' output
+fi
+grep '^PASS: bar\.test *$' output
+
+rm -f test-suite.log foo.log bar.log
+
+run_make -M -e FAIL FOO_EXIT_STATUS=1 check
+# The serial test driver does not strip VPATH components from
+# the name of the test, but the parallel driver should.
+if test x"$am_serial_tests" = x"yes"; then
+ grep '^FAIL: .*foo\.test *$' output
+else
+ grep '\.\./foo' output && exit 1
+ grep '^FAIL: foo\.test *$' output
+fi
+grep '^PASS: bar\.test *$' output
+
+rm -f test-suite.log foo.log bar.log
+
+# Check that if the same test is present in srcdir and builddir,
+# the one in builddir is preferred.
+cp bar.test foo.test
+run_make -M FOO_EXIT_STATUS=1 check
+grep '^PASS: foo\.test *$' output
+grep '^PASS: bar\.test *$' output
+
+# The tests in the builddir must be preferred also by "make dist".
+FOO_EXIT_STATUS=1 $MAKE distcheck
+
+:
diff --git a/t/check.sh b/t/check.sh
new file mode 100644
index 000000000..f6aa2d62a
--- /dev/null
+++ b/t/check.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test Automake style tests.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat > Makefile.am << 'END'
+TESTS = frob.test
+END
+
+test x"$am_serial_tests" = x"yes" || : > test-driver
+
+$ACLOCAL
+$AUTOMAKE
+
+grep 'check-TESTS.*:' Makefile.in
+grep 'check-DEJAGNU' Makefile.in && exit 1
+
+# 'check-TESTS' is phony.
+sed -n '/^\.PHONY:/,/^$/p' Makefile.in | $EGREP '(^| )check-TESTS($| )'
+
+# 'check' should depend directly on 'check-am' (similar tests are
+# in check2.sh and check3.sh).
+$EGREP '^check:.* check-am( |$)' Makefile.in
+
+:
diff --git a/t/check10.sh b/t/check10.sh
new file mode 100644
index 000000000..b9e577290
--- /dev/null
+++ b/t/check10.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check singular and plural in test summaries.
+
+# This test only makes sense for the older serial testsuite driver.
+am_serial_tests=yes
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = fail pass skip xfail xpass fail2 pass2 skip2 xfail2 xpass2
+XFAIL_TESTS = xfail xpass xfail2 xpass2
+END
+
+cat > pass <<'END'
+#! /bin/sh
+exit 0
+END
+cat > fail <<'END'
+#! /bin/sh
+exit 1
+END
+cat > skip <<'END'
+#! /bin/sh
+exit 77
+END
+chmod a+x pass fail skip
+cp pass pass2
+cp pass xpass
+cp xpass xpass2
+cp fail xfail
+cp fail fail2
+cp xfail xfail2
+cp skip skip2
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+(
+ run_make -e IGNORE TESTS=pass check
+ run_make -e IGNORE TESTS=fail check
+ run_make -e IGNORE TESTS=skip check
+ run_make -e IGNORE TESTS=xfail check
+ run_make -e IGNORE TESTS=xpass check
+ run_make -e IGNORE TESTS="pass pass2" check
+ run_make -e IGNORE TESTS="fail fail2" check
+ run_make -e IGNORE TESTS="skip skip2" check
+ run_make -e IGNORE TESTS="xfail xfail2" check
+ run_make -e IGNORE TESTS="xpass xpass2" check
+ run_make -e IGNORE TESTS='pass skip xfail' check
+ run_make -e IGNORE check
+) >stdout || { cat stdout; exit 1; }
+cat stdout
+
+grep '1 [tT]ests' stdout && exit 1
+grep '[02-9] [tT]est ' stdout && exit 1
+grep '1 .* were ' stdout && exit 1
+grep '[02-9].* was .*run' stdout && exit 1
+grep 'All 1 ' stdout && exit 1
+$EGREP '1 (un)?expected (failures|passes)' stdout && exit 1
+$EGREP '[^1] (un)?expected (failure|pass)\)' stdout && exit 1
+
+:
diff --git a/t/check11.sh b/t/check11.sh
new file mode 100644
index 000000000..fe6860017
--- /dev/null
+++ b/t/check11.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check skip summary.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = skip skip2
+END
+
+cat > skip <<'END'
+#! /bin/sh
+exit 77
+END
+chmod a+x skip
+cp skip skip2
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+run_make -O TESTS=skip check
+if test x"$am_serial_tests" = x"yes"; then
+ grep '1.*passed' stdout && exit 1
+ : For shells with buggy 'set -e'.
+else
+ count_test_results total=1 pass=0 fail=0 skip=1 xfail=0 xpass=0 error=0
+fi
+
+run_make -O TESTS="skip skip2" check
+if test x"$am_serial_tests" = x"yes"; then
+ grep '2.*passed' stdout && exit 1
+ : For shells with buggy 'set -e'.
+else
+ count_test_results total=2 pass=0 fail=0 skip=2 xfail=0 xpass=0 error=0
+fi
+
+:
diff --git a/t/check12.sh b/t/check12.sh
new file mode 100644
index 000000000..4c4594a6d
--- /dev/null
+++ b/t/check12.sh
@@ -0,0 +1,212 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure dejagnu tests, automake-style tests, and check-local
+# target can coexist.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+required=runtest
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS =
+EXTRA_DIST =
+CLEANFILES =
+END
+
+## Simple tests.
+
+cat > a.test << 'END'
+#!/bin/sh
+echo a.test: exit status: ${A_EXIT_STATUS-0}
+exit ${A_EXIT_STATUS-0}
+END
+cat > b.test << 'END'
+#!/bin/sh
+echo b.test: exit status: ${B_EXIT_STATUS-0}
+exit ${B_EXIT_STATUS-0}
+END
+chmod +x a.test b.test
+
+cat >> Makefile.am << 'END'
+TESTS = a.test b.test
+EXTRA_DIST += $(TESTS)
+END
+
+A_EXIT_STATUS=0; export A_EXIT_STATUS
+B_EXIT_STATUS=0; export B_EXIT_STATUS
+
+## DejaGnu tests.
+
+cat >> Makefile.am << 'END'
+AUTOMAKE_OPTIONS += dejagnu
+DEJATOOL = hammer spanner
+AM_RUNTESTFLAGS = HAMMER=$(srcdir)/hammer SPANNER=$(srcdir)/spanner
+EXTRA_DIST += hammer.test/hammer.exp
+EXTRA_DIST += spanner.test/spanner.exp
+END
+
+cat > hammer << 'END'
+#! /bin/sh
+echo "Everything looks like a ${NAIL-nail} to me!"
+END
+
+NAIL=nail; export NAIL
+
+cat > spanner << 'END'
+#! /bin/sh
+echo "I'm a right spanner!"
+END
+chmod +x hammer spanner
+
+mkdir hammer.test spanner.test
+
+cat > hammer.test/hammer.exp << 'END'
+set test test_hammer
+spawn $HAMMER
+expect {
+ "Everything looks like a nail to me!" { pass "$test" }
+ default { fail "$test" }
+}
+END
+
+cat > spanner.test/spanner.exp << 'END'
+set test test_spanner
+spawn $SPANNER
+expect {
+ "I'm a right spanner!" { pass "$test" }
+ default { fail "$test" }
+}
+END
+
+## User-defined extra tests.
+
+cat >> Makefile.am <<'END'
+check-local:
+ case $$CHECKLOCAL_EXIT_STATUS in \
+ 0) echo 'check-local succeeded :-)';; \
+ *) echo 'check-local failed :-(';; \
+ esac >local.log
+ exit $$CHECKLOCAL_EXIT_STATUS
+CLEANFILES += local.log
+END
+CHECKLOCAL_EXIT_STATUS=0; export CHECKLOCAL_EXIT_STATUS
+
+## Go with the testcase execution.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+for vpath in : false; do
+
+ if $vpath; then
+ srcdir=..
+ mkdir build
+ cd build
+ else
+ srcdir=.
+ fi
+
+ if test -f config.status; then
+ $MAKE distclean
+ fi
+
+ $srcdir/configure
+
+ $MAKE check
+ test -f hammer.log
+ test -f hammer.sum
+ test -f spanner.log
+ test -f spanner.sum
+ if test x"$am_serial_tests" != x"yes"; then
+ test -f test-suite.log
+ test -f a.log
+ test -f b.log
+ fi
+ grep 'check-local succeeded :-)' local.log
+
+ cp -f config.status config-status.sav
+
+ $MAKE distclean
+ test ! -e hammer.log
+ test ! -e hammer.sum
+ test ! -e spanner.log
+ test ! -e spanner.sum
+ test ! -e test-suite.log
+ test ! -e a.log
+ test ! -e b.log
+ test ! -e local.log
+
+ mv -f config-status.sav config.status
+ ./config.status
+
+ NAIL=screw $MAKE check && exit 1
+ test -f hammer.log
+ test -f hammer.sum
+ test -f spanner.log
+ test -f spanner.sum
+ grep 'FAIL: test_hammer' hammer.sum
+ grep 'FAIL:' spanner.sum && exit 1
+
+ B_EXIT_STATUS=1 $MAKE check && exit 1
+ if test x"$am_serial_tests" != x"yes"; then
+ cat test-suite.log
+ cat a.log
+ cat b.log
+ grep '^a\.test: exit status: 0$' a.log
+ grep '^b\.test: exit status: 1$' b.log
+ grep '^FAIL: b$' test-suite.log
+ grep '^b\.test: exit status: 1$' test-suite.log
+ grep '^a\.test' test-suite.log && exit 1
+ : For shells with busted 'set -e'.
+ fi
+
+ CHECKLOCAL_EXIT_STATUS=1 $MAKE check && exit 1
+ grep 'check-local failed :-(' local.log
+
+ # Do not trust the exit status of 'make -k'.
+ NAIL=screw B_EXIT_STATUS=23 CHECKLOCAL_EXIT_STATUS=1 $MAKE -k check || :
+ test -f hammer.log
+ test -f hammer.sum
+ test -f spanner.log
+ test -f spanner.sum
+ grep 'FAIL: test_hammer' hammer.sum
+ grep 'FAIL:' spanner.sum && exit 1
+ if test x"$am_serial_tests" != x"yes"; then
+ cat test-suite.log
+ cat a.log
+ cat b.log
+ grep '^a\.test: exit status: 0$' a.log
+ grep '^b\.test: exit status: 23$' b.log
+ grep '^FAIL: b$' test-suite.log
+ grep '^b\.test: exit status: 23$' test-suite.log
+ grep '^a\.test' test-suite.log && exit 1
+ : For shells with busted 'set -e'.
+ fi
+ grep 'check-local failed :-(' local.log
+
+ cd $srcdir
+
+done
+
+$MAKE distcheck
+
+:
diff --git a/t/check2.sh b/t/check2.sh
new file mode 100644
index 000000000..bb6b1414f
--- /dev/null
+++ b/t/check2.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test Automake style tests.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([dir/Makefile])
+AC_OUTPUT
+END
+
+mkdir dir
+
+cat > Makefile.am << 'END'
+SUBDIRS = dir
+TESTS = \
+ subrun.sh
+subrun.sh:
+ (echo '#! /bin/sh'; echo 'dir/echo.sh') > $@
+ chmod +x $@
+CLEANFILES = subrun.sh
+END
+
+cat > dir/Makefile.am << 'END'
+check_SCRIPTS = echo.sh
+echo.sh:
+ (echo '#! /bin/sh'; echo 'echo Hello') > $@
+ chmod +x $@
+CLEANFILES = echo.sh
+END
+
+test x"$am_serial_tests" = x"yes" || cp "$am_scriptdir/test-driver" .
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+run_make -O check
+grep '^PASS: subrun\.sh *$' stdout
+grep 'PASS.*echo\.sh' stdout && exit 1
+
+# 'check' should depend directly on 'check-am' (similar tests are
+# in 'check.sh' and 'built-sources-check.sh').
+$EGREP '^check:.* check-recursive( |$)' Makefile.in
+$EGREP '^check:.* check-am( |$)' dir/Makefile.in
+
+# Make sure subrun.sh is still on its line as above. This means Automake
+# hasn't rewritten the TESTS line unnecessarily (we can tell, because all
+# Automake variables are reformatted by VAR_PRETTY).
+grep '^ subrun\.sh$' Makefile.in
+
+:
diff --git a/t/check4.sh b/t/check4.sh
new file mode 100644
index 000000000..7ec30cf28
--- /dev/null
+++ b/t/check4.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'make -k check' processes all directories.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([dir/Makefile])
+AC_OUTPUT
+END
+
+mkdir dir
+
+cat > Makefile.am <<'END'
+SUBDIRS = dir
+TESTS = ok.sh
+END
+
+echo TESTS = fail.sh >dir/Makefile.am
+
+cat >ok.sh <<'END'
+#!/bin/sh
+:
+END
+
+cat >dir/fail.sh <<'END'
+#!/bin/sh
+exit 1
+END
+
+chmod +x ok.sh dir/fail.sh
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure --prefix "$(pwd)/inst"
+
+run_make -O -e FAIL -- check
+grep '^FAIL: fail\.sh *$' stdout
+grep '^PASS: ok\.sh *$' stdout && exit 1
+
+# The exit status of 'make -k' can be anything
+# (depending on the Make implementation)
+run_make -O -e IGNORE -- -k check
+grep '^FAIL: fail\.sh *$' stdout
+grep '^PASS: ok\.sh *$' stdout
+
+# Should also works when -k is not in first position.
+run_make -O -e IGNORE -- -s -k check
+grep '^FAIL: fail\.sh *' stdout
+grep '^PASS: ok\.sh *' stdout
+
+# The rest of the test is for GNU Make.
+
+if using_gmake; then
+ # Try with a long-option that do not have a short option equivalent
+ # (here, --no-print-directory). That should cause all options to
+ # appear verbatim in MAKEFLAGS.
+ run_make -e FAIL -O -- --no-print-directory -k check
+ grep '^FAIL: fail\.sh *$' stdout
+ grep '^PASS: ok\.sh *$' stdout
+fi
+
+:
diff --git a/t/check5.sh b/t/check5.sh
new file mode 100644
index 000000000..0d45cf76c
--- /dev/null
+++ b/t/check5.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test TESTS = $(check_PROGRAMS)
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+check_PROGRAMS = one two
+TESTS = $(check_PROGRAMS)
+check-local:
+ test -f one$(EXEEXT)
+ test -f two$(EXEEXT)
+ touch ok
+expect-tests:
+ is $(TESTS) == one$(EXEEXT) two$(EXEEXT)
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cat > one.c << 'END'
+int main (void)
+{
+ return 0;
+}
+END
+cp one.c two.c
+
+./configure
+$MAKE check
+test -f ok
+run_make expect-tests
+run_make expect-tests EXEEXT=.bin
+# No am__EXEEXT_* variable is needed.
+grep '_EXEEXT_[1-9]' Makefile.in && exit 1
+$FGREP 'TESTS = $(check_PROGRAMS)' Makefile.in
+
+:
diff --git a/t/check6.sh b/t/check6.sh
new file mode 100644
index 000000000..2efeb0524
--- /dev/null
+++ b/t/check6.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 400: XFAIL_TESTS delimited by TABs.
+# Also test that Solaris make VPATH rewriting is honored
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = $(XFAIL_TESTS)
+XFAIL_TESTS = a b c
+END
+
+cat >>a <<'END'
+#! /bin/sh
+exit 1
+END
+
+cp a b
+cp a c
+
+chmod a+x a b c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE check
+$MAKE distclean
+mkdir build
+cd build
+../configure
+$MAKE check
+
+:
diff --git a/t/check7.sh b/t/check7.sh
new file mode 100644
index 000000000..ff08a049f
--- /dev/null
+++ b/t/check7.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check EXEEXT extension for XFAIL_TESTS.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = $(XFAIL_TESTS)
+XFAIL_TESTS = a b c d
+check_PROGRAMS = a c d
+check_SCRIPTS = b
+EXTRA_DIST = $(check_SCRIPTS)
+
+expect-xfail-tests:
+ is $(XFAIL_TESTS) == a$(EXEEXT) b c$(EXEEXT) d$(EXEEXT)
+END
+
+cat > b <<'END'
+#! /bin/sh
+exit 1
+END
+chmod a+x b
+
+cat > a.c <<'END'
+#include <stdlib.h>
+int main (void)
+{
+ return EXIT_FAILURE;
+}
+END
+
+cp a.c c.c
+cp a.c d.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE check
+run_make expect-xfail-tests
+run_make expect-xfail-tests EXEEXT=.bin
+
+$MAKE distcheck
+
+:
diff --git a/t/check8.sh b/t/check8.sh
new file mode 100644
index 000000000..a37ad4e38
--- /dev/null
+++ b/t/check8.sh
@@ -0,0 +1,95 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check subdir TESTS.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+TESTS = foo sub/foo $(check_PROGRAMS)
+XFAIL_TESTS = foo sub/baz
+check_PROGRAMS = bar sub/bar baz sub/baz
+END
+
+mkdir sub
+
+cat > foo <<'END'
+#! /bin/sh
+test -f "$srcdir/Makefile.am"
+END
+cat > sub/foo <<'END'
+#! /bin/sh
+test -f "$srcdir/Makefile.am"
+END
+chmod a+x foo sub/foo
+
+cat > bar.c <<'END'
+int main (void) { return 0; }
+END
+cat > sub/bar.c <<'END'
+int main (void) { return 0; }
+END
+cat > baz.c <<'END'
+#include <stdlib.h>
+int main (void) { return EXIT_FAILURE; }
+END
+cat > sub/baz.c <<'END'
+#include <stdlib.h>
+int main (void) { return EXIT_FAILURE; }
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+run_make -E -O -e FAIL check
+grep 'XPASS.* foo$' stdout
+grep '^[^X]*PASS.* sub/foo$' stdout
+grep '^[^X]*PASS.* bar' stdout
+grep '^[^X]*PASS.* sub/bar' stdout
+grep '^[^X]*FAIL.* baz' stdout
+grep 'XFAIL.* sub/baz' stdout
+# The parallel test driver should cause circular dependencies.
+# Look for known warnings from a couple of 'make' implementations.
+grep -i 'circular.*dependency' stderr && exit 1
+grep -i 'graph cycles' stderr && exit 1
+
+$MAKE distclean
+
+mkdir build
+cd build
+../configure
+run_make -O -e FAIL check
+# Note: we are not grepping for the space in the lines from the 'foo'
+# tests, due to the Solaris make VPATH rewriting (if we fix that, we
+# can still write a separate test for it).
+grep 'XPASS.*foo$' stdout
+grep '^[^X]*PASS.*sub/foo$' stdout
+grep '^[^X]*PASS.* bar' stdout
+grep '^[^X]*PASS.* sub/bar' stdout
+grep '^[^X]*FAIL.* baz' stdout
+grep 'XFAIL.* sub/baz' stdout
+
+:
diff --git a/t/checkall.sh b/t/checkall.sh
new file mode 100644
index 000000000..f8066b30d
--- /dev/null
+++ b/t/checkall.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug where check target doesn't depend on all.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+bin_SCRIPTS = derived
+check-local:
+ true
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^check-am:.*all-am' Makefile.in
+grep 'MAKE.*check-local' Makefile.in
diff --git a/t/clean.sh b/t/clean.sh
new file mode 100644
index 000000000..565ea904a
--- /dev/null
+++ b/t/clean.sh
@@ -0,0 +1,26 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure a clean target depends on previous one.
+
+. test-init.sh
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^clean-am:.*mostlyclean-am' Makefile.in
diff --git a/t/colneq.sh b/t/colneq.sh
new file mode 100644
index 000000000..8a58e63c0
--- /dev/null
+++ b/t/colneq.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that := definitions produce warnings, but otherwise work.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+ICONS := $(wildcard *.xbm)
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep ':=.*not portable' stderr
+
+$AUTOMAKE -Wno-portability
+grep '^ICONS *:= *\$(wildcard \*\.xbm) *$' Makefile.in
+
+:
diff --git a/t/colneq2.sh b/t/colneq2.sh
new file mode 100644
index 000000000..9172fca43
--- /dev/null
+++ b/t/colneq2.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that := in var substitutions works.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+t = a b c
+EXTRA_DIST = $(t:=.test)
+.PHONY: test
+test:
+ is $(EXTRA_DIST) == a.test b.test c.test
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+:
diff --git a/t/colneq3.sh b/t/colneq3.sh
new file mode 100644
index 000000000..36c05d96a
--- /dev/null
+++ b/t/colneq3.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that := definitions work as expected at make time.
+
+required=GNUmake
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+BAR := $(FOO)
+BAZ = $(FOO)
+FOO := foo
+.PHONY: test
+test:
+ test x'$(FOO)' = x'foo'
+ test x'$(BAZ)' = x'foo'
+ test x'$(BAR)' = x
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -Wno-portability
+
+./configure
+$MAKE test
+
+:
diff --git a/t/colon.sh b/t/colon.sh
new file mode 100644
index 000000000..6a72d7fe1
--- /dev/null
+++ b/t/colon.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug reported by Nyul Laszlo. When using the ":" syntax in
+# AC_OUTPUT, Automake fails to find the correct file.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([foo.h:foo.hin])
+AC_OUTPUT
+END
+
+: > foo.hin
+
+cat > Makefile.am <<'END'
+.PHONY: test
+test: distdir
+ ls -l . $(distdir)
+ test -f foo.h
+ test -f $(distdir)/foo.hin
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/colon2.sh b/t/colon2.sh
new file mode 100644
index 000000000..0453fa149
--- /dev/null
+++ b/t/colon2.sh
@@ -0,0 +1,79 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure ":" works with files automake generates.
+# See also sister test 'colon3.sh'.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile:zardoz.in])
+AC_OUTPUT
+END
+
+cat > zardoz.am <<END
+.PHONY: dummy
+dummy:
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# Automake should have created zardoz.in.
+test -f zardoz.in
+
+# The generated file should refer to zardoz.in and zardoz.am, but
+# never just "zardoz".
+$FGREP 'zardoz.am' zardoz.in
+$FGREP 'zardoz.in' zardoz.in
+sed -e 's|zardoz\.am|zrdz.am|g' \
+ -e 's|zardoz\.in|zrdz.in|g' \
+ <zardoz.in | $FGREP 'zardoz' && exit 1
+
+# The configure-generated Makefile should depend on zardoz.in, two.in and
+# three.in. The automake-generated zardoz.in should depend on zardoz.am.
+# Let's do this check the right way by running configure and make.
+
+str='%% ZaR DoZ %%'
+
+$AUTOCONF
+./configure
+test -f Makefile # Sanity check.
+
+$MAKE dummy
+# Again, make sure that the generated Makefile do not unduly
+# refer to 'zardoz' .
+$MAKE -n zardoz && exit 1
+
+$sleep
+cat >> zardoz.am <<END
+check-local: testam testin testmk
+.PHONY: testam testin testmk
+testam:
+ grep '$str' \$(srcdir)/zardoz.am
+testin:
+ grep '$str' \$(srcdir)/zardoz.in
+testmk:
+ grep '$str' Makefile
+END
+$MAKE Makefile # For non-GNU make.
+$MAKE testam testin testmk
+
+$MAKE distcheck
+
+:
diff --git a/t/colon3.sh b/t/colon3.sh
new file mode 100644
index 000000000..840fc313a
--- /dev/null
+++ b/t/colon3.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure ":" works with files automake generates.
+# This test is for multiple ":"s.
+# See also sister test 'colon2.sh'.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile:zardoz.in:two.in:three.in])
+AC_OUTPUT
+END
+
+cat > zardoz.am <<END
+.PHONY: dummy
+dummy:
+END
+
+: > two.in
+: > three.in
+
+$ACLOCAL
+$AUTOMAKE
+
+# Automake should have created zardoz.in.
+test -f zardoz.in
+
+# The generated file should refer to zardoz.in and zardoz.am, but
+# never just "zardoz".
+$FGREP 'zardoz.am' zardoz.in
+$FGREP 'zardoz.in' zardoz.in
+sed -e 's|zardoz\.am|zrdz.am|g' \
+ -e 's|zardoz\.in|zrdz.in|g' \
+ <zardoz.in | $FGREP 'zardoz' && exit 1
+
+# The configure-generated Makefile should depend on zardoz.in, two.in and
+# three.in. The automake-generated zardoz.in should depend on zardoz.am.
+# Let's do this check the right way by running configure and make.
+
+str='%% ZaR DoZ %%'
+str2='// 2_TwO_2 //'
+str3='== @thr33@ =='
+
+$AUTOCONF
+./configure
+test -f Makefile # Sanity check.
+
+$MAKE dummy
+# Again, make sure that the generated Makefile do not unduly
+# refer to 'zardoz' .
+$MAKE -n zardoz && exit 1
+
+$sleep
+cat >> zardoz.am <<END
+check-local: testam testin testmk test2 test3
+.PHONY: testam testin test2 testmk test3
+testam:
+ grep '$str' \$(srcdir)/zardoz.am
+testin:
+ grep '$str' \$(srcdir)/zardoz.in
+testmk:
+ grep '$str' Makefile
+test2:
+ grep '$str2' \$(srcdir)/two.in
+test3:
+ grep '$str3' \$(srcdir)/three.in
+END
+echo "# $str2" >> two.in
+echo "# $str3" >> three.in
+$MAKE Makefile # For non-GNU make.
+$MAKE testam testin testmk test2 test3
+
+$MAKE distcheck
+
+:
diff --git a/t/colon4.sh b/t/colon4.sh
new file mode 100644
index 000000000..6f01857fe
--- /dev/null
+++ b/t/colon4.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure multiple ":"s in AC_CONFIG_FILES do not generate broken
+# rebuild rules.
+# Test from Maciej W. Rozycki.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_CONFIG_FILES([zardoz:one:two:three])
+AC_OUTPUT
+END
+
+: > Makefile.am
+: > one
+: > two
+: > three
+
+$ACLOCAL
+$AUTOMAKE
+
+# The rule should regenerate the file "zardoz", not a meaningless
+# file "'zardoz:one:two".
+$FGREP 'zardoz:one:two' Makefile.in && exit 1
+exit 0
diff --git a/t/colon5.sh b/t/colon5.sh
new file mode 100644
index 000000000..50d014407
--- /dev/null
+++ b/t/colon5.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another multi-":" test, this time from Doug Evans.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile:Makefile.in:Makefile.dep])
+AC_OUTPUT
+END
+
+: > Makefile.dep
+
+cat > Makefile.am <<'END'
+.PHONY: test-fs-layout test-grep test-distcommon test-distdir
+check-local: test-fs-layout test-grep test-distcommon test-distdir
+test-fs-layout:
+ test x'$(srcdir)' = '.' || test ! -r Makefile.dep
+test-grep:
+## The use of $(empty) prevents spurious matches.
+ grep '=GrEp$(empty)Me_am=' $(srcdir)/Makefile.in
+ grep '=GrEp$(empty)Me_dep=' $(srcdir)/Makefile.dep
+ grep '=GrEp$(empty)Me_am=' Makefile
+ grep '=GrEp$(empty)Me_dep=' Makefile
+test-distcommon:
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]Makefile.dep '
+test-distdir: distdir
+ test -f $(distdir)/Makefile.dep
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+grep '=GrEpMe_am=' Makefile && exit 1 # Sanity check.
+grep '=GrEpMe_dep=' Makefile && exit 1 # Likewise.
+
+$MAKE test-distcommon
+$MAKE test-distdir
+
+$sleep
+
+echo '# =GrEpMe_am=' >> Makefile.am
+echo '# =GrEpMe_dep=' >> Makefile.dep
+
+$MAKE Makefile # For non-GNU make.
+$MAKE test-grep
+$MAKE test-distcommon
+$MAKE test-distdir
+
+$MAKE distcheck
+
+:
diff --git a/t/colon6.sh b/t/colon6.sh
new file mode 100644
index 000000000..f33f4fefe
--- /dev/null
+++ b/t/colon6.sh
@@ -0,0 +1,102 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Yet another multi-":" test, this time from Ken Pizzini.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+# With this, version.good should depend on version.gin, while
+# Makefile should not depend on either of them.
+AC_CONFIG_FILES([demo/Makefile demo/version.good:demo/version.gin])
+AC_OUTPUT
+END
+
+mkdir demo
+: > demo/version.gin
+: > demo/Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+# These are older "grepping checks", kept mostly for backward-compatibility.
+# They might (unlikely, but possibly) require updating when automake
+# internals are changed. Just relax or remove if they become too fragile.
+$EGREP 'Makefile:.*(demo|version)' demo/Makefile.in && exit 1
+grep 'version\.good:.*version\.gin' demo/Makefile.in
+
+$AUTOCONF
+
+for vpath in : false; do
+
+ if $vpath; then
+ srcdir=..
+ mkdir build
+ cd build
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+
+ test -f demo/version.good # Sanity check.
+ test ! -s demo/version.good # Likewise.
+
+ cd demo
+
+ $sleep
+ # HP-UX make considers targets with exact time stamps as one of their
+ # prerequisites out of date. Ensure Makefile is newer than config.status to
+ # avoid triggering the am--refresh rule in the (here-nonexistent) toplevel
+ # Makefile.
+ touch Makefile
+
+ # version.good should depend on version.gin.
+ echo "Rebuilt (srcdir=$srcdir)" > ../$srcdir/demo/version.gin
+ $MAKE version.good
+ $FGREP "Rebuilt (srcdir=$srcdir)" version.good
+
+ # Makefile should not depend on version.good.
+ rm -f version.good
+ $MAKE Makefile
+ test ! -e version.good
+
+ # version.good should be rebuilt from version.gin.
+ $MAKE version.good
+ test -f version.good
+
+ # Makefile should not depend on version.gin.
+ rm -f ../$srcdir/demo/version.gin
+ $MAKE Makefile
+ test ! -e ../$srcdir/demo/version.gin # Sanity check.
+
+ # version.good should depend on version.gin.
+ rm -f version.good
+ run_make -M -e FAIL version.good
+ # Try to verify that we errored out for the right reason.
+ $FGREP version.gin output
+
+ cd .. # Back in top builddir.
+ cd $srcdir
+
+ # Re-create it for the next pass (if any).
+ : > demo/version.gin
+
+done
+
+:
diff --git a/t/colon7.sh b/t/colon7.sh
new file mode 100644
index 000000000..a0ae9369d
--- /dev/null
+++ b/t/colon7.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another test for a failing ":" in AC_OUTPUT.
+# Report from Maciej Stachowiak.
+
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([colon7], [1.0])
+AM_INIT_AUTOMAKE
+dnl: Please do not add proper m4 quoting here.
+AC_OUTPUT(subdir/bar:subdir/foo \
+ Makefile \
+ subdir/Makefile
+)
+END
+
+mkdir subdir
+: > Makefile.am
+: > subdir/foo
+cat > subdir/Makefile.am << 'END'
+# DIST_COMMON should contain 'foo', not 'subdir/foo'.
+test:
+ case '$(DIST_COMMON)' in *subdir/foo*) exit 1;; *) exit 0;; esac
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]foo '
+.PHONY: test
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# Should nowhere refer to 'bar.in'.
+$FGREP 'bar.in' Makefile.in subdir/Makefile.in && exit 1
+
+$AUTOCONF
+./configure
+cd subdir
+$MAKE test
+
+:
diff --git a/t/color-tests-opt.sh b/t/color-tests-opt.sh
new file mode 100644
index 000000000..6f8e543d0
--- /dev/null
+++ b/t/color-tests-opt.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the 'color-tests' option, now active by default, is
+# nonetheless still silently accepted, for backward compatibility.
+
+. test-init.sh
+
+cat >configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([color-tests])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<END
+AUTOMAKE_OPTIONS = color-tests
+TESTS = foo.test
+END
+
+: > test-driver
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/color-tests.sh b/t/color-tests.sh
new file mode 100644
index 000000000..300c6bd85
--- /dev/null
+++ b/t/color-tests.sh
@@ -0,0 +1,150 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test Automake TESTS color output, by forcing it.
+# Keep this in sync with the sister test 'color-tests2.sh'.
+
+required='grep-nonprint'
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+# Escape '[' for grep, below.
+red="$esc\[0;31m"
+grn="$esc\[0;32m"
+lgn="$esc\[1;32m"
+blu="$esc\[1;34m"
+mgn="$esc\[0;35m"
+std="$esc\[m"
+
+cat >>configure.ac <<END
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+TESTS = $(check_SCRIPTS)
+check_SCRIPTS = pass fail skip xpass xfail error
+XFAIL_TESTS = xpass xfail
+END
+
+cat >pass <<END
+#! /bin/sh
+exit 0
+END
+
+cat >fail <<END
+#! /bin/sh
+exit 1
+END
+
+cat >skip <<END
+#! /bin/sh
+exit 77
+END
+
+cat >error <<END
+#! /bin/sh
+exit 99
+END
+
+cp fail xfail
+cp pass xpass
+chmod +x pass fail skip xpass xfail error
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+test_color ()
+{
+ # Not a useless use of cat; see above comments "grep-nonprinting"
+ # requirement in 'test-init.sh'.
+ cat stdout | grep "^${grn}PASS${std}: .*pass"
+ cat stdout | grep "^${red}FAIL${std}: .*fail"
+ cat stdout | grep "^${blu}SKIP${std}: .*skip"
+ cat stdout | grep "^${lgn}XFAIL${std}: .*xfail"
+ cat stdout | grep "^${red}XPASS${std}: .*xpass"
+ # The old serial testsuite driver doesn't distinguish between failures
+ # and hard errors.
+ if test x"$am_serial_tests" = x"yes"; then
+ cat stdout | grep "^${red}FAIL${std}: .*error"
+ else
+ cat stdout | grep "^${mgn}ERROR${std}: .*error"
+ fi
+ :
+}
+
+test_no_color ()
+{
+ # With make implementations that, like Solaris make, in case of errors
+ # print the whole failing recipe on standard output, we should content
+ # ourselves with a laxer check, to avoid false positives.
+ # Keep this in sync with lib/am/check.am:$(am__color_tests).
+ if $FGREP '= Xalways; then' stdout; then
+ # Extra verbose make, resort to laxer checks.
+ # Note that we also want to check that the testsuite summary is
+ # not unduly colorized.
+ (
+ set +e # In case some grepped regex below isn't matched.
+ # Not a useless use of cat; see above comments "grep-nonprinting"
+ # requirement in 'test-init.sh'.
+ cat stdout | grep "TOTAL.*:"
+ cat stdout | grep "PASS.*:"
+ cat stdout | grep "FAIL.*:"
+ cat stdout | grep "SKIP.*:"
+ cat stdout | grep "XFAIL.*:"
+ cat stdout | grep "XPASS.*:"
+ cat stdout | grep "ERROR.*:"
+ cat stdout | grep 'test.*expected'
+ cat stdout | grep 'test.*not run'
+ cat stdout | grep '===='
+ cat stdout | grep '[Ss]ee .*test-suite\.log'
+ cat stdout | grep '[Tt]estsuite summary'
+ ) | grep "$esc" && exit 1
+ : For shells with broken 'set -e'
+ else
+ cat stdout | grep "$esc" && exit 1
+ : For shells with broken 'set -e'
+ fi
+}
+
+for vpath in false :; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+
+ # Forced colorization should take place also with non-ANSI terminals;
+ # hence the "TERM=dumb" definition.
+ AM_COLOR_TESTS=always; export AM_COLOR_TESTS
+ run_make -e FAIL -O TERM=dumb check
+ test_color
+
+ unset AM_COLOR_TESTS
+ run_make -e FAIL -O TERM=ansi check
+ test_no_color
+
+ $MAKE distclean
+ cd $srcdir
+
+done
+
+:
diff --git a/t/color-tests2.sh b/t/color-tests2.sh
new file mode 100644
index 000000000..7def8fa88
--- /dev/null
+++ b/t/color-tests2.sh
@@ -0,0 +1,201 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test Automake TESTS color output, using the expect(1) program.
+# Keep this in sync with the sister test 'color-tests.sh'.
+
+required='grep-nonprint'
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+# Escape '[' for grep, below.
+red="$esc\[0;31m"
+grn="$esc\[0;32m"
+lgn="$esc\[1;32m"
+blu="$esc\[1;34m"
+mgn="$esc\[0;35m"
+std="$esc\[m"
+
+# This test requires a working a working 'expect' program.
+(set +e; expect -c 'exit 77'; test $? -eq 77) \
+ || skip_ "requires a working expect program"
+
+# Also, if the $MAKE program fails to consider the standard output as a
+# tty (this happens with e.g., BSD make and Solaris dmake when they're
+# run in parallel mode; see the autoconf manual), there is little point
+# in proceeding.
+cat > Makefile <<'END'
+all:
+## Creative quoting in the 'echo' below to avoid risk of spurious output
+## matches by 'expect', below.
+ @test -t 1 && echo "stdout" "is" "a" "tty"
+END
+
+cat > expect-check <<'END'
+eval spawn $env(MAKE)
+expect {
+ "stdout is a tty" { exit 0 }
+ default { exit 1 }
+}
+exit 1
+END
+MAKE=$MAKE expect -f expect-check \
+ || skip_ "make spawned by expect should have a tty stdout"
+rm -f expect-check Makefile
+
+# Do the tests.
+
+cat >>configure.ac << 'END'
+if $testsuite_colorized; then :; else
+ AC_SUBST([AM_COLOR_TESTS], [no])
+fi
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+TESTS = $(check_SCRIPTS)
+check_SCRIPTS = pass fail skip xpass xfail error
+XFAIL_TESTS = xpass xfail
+END
+
+cat >pass <<END
+#! /bin/sh
+exit 0
+END
+
+cat >fail <<END
+#! /bin/sh
+exit 1
+END
+
+cat >skip <<END
+#! /bin/sh
+exit 77
+END
+
+cat >error <<END
+#! /bin/sh
+exit 99
+END
+
+cp fail xfail
+cp pass xpass
+chmod +x pass fail skip xpass xfail error
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+test_color ()
+{
+ # Not a useless use of cat; see above comments "grep-nonprinting"
+ # requirement in 'test-init.sh'.
+ cat stdout | grep "^${grn}PASS${std}: .*pass"
+ cat stdout | grep "^${red}FAIL${std}: .*fail"
+ cat stdout | grep "^${blu}SKIP${std}: .*skip"
+ cat stdout | grep "^${lgn}XFAIL${std}: .*xfail"
+ cat stdout | grep "^${red}XPASS${std}: .*xpass"
+ # The old serial testsuite driver doesn't distinguish between failures
+ # and hard errors.
+ if test x"$am_serial_tests" = x"yes"; then
+ cat stdout | grep "^${red}FAIL${std}: .*error"
+ else
+ cat stdout | grep "^${mgn}ERROR${std}: .*error"
+ fi
+ :
+}
+
+test_no_color ()
+{
+ # With make implementations that, like Solaris make, in case of errors
+ # print the whole failing recipe on standard output, we should content
+ # ourselves with a laxer check, to avoid false positives.
+ # Keep this in sync with lib/am/check.am:$(am__color_tests).
+ if $FGREP '= Xalways; then' stdout; then
+ # Extra verbose make, resort to laxer checks.
+ # Note that we also want to check that the testsuite summary is
+ # not unduly colorized.
+ (
+ set +e # In case some grepped regex below isn't matched.
+ # Not a useless use of cat; see above comments "grep-nonprinting"
+ # requirement in 'test-init.sh'.
+ cat stdout | grep "TOTAL.*:"
+ cat stdout | grep "PASS.*:"
+ cat stdout | grep "FAIL.*:"
+ cat stdout | grep "SKIP.*:"
+ cat stdout | grep "XFAIL.*:"
+ cat stdout | grep "XPASS.*:"
+ cat stdout | grep "ERROR.*:"
+ cat stdout | grep 'test.*expected'
+ cat stdout | grep 'test.*not run'
+ cat stdout | grep '===='
+ cat stdout | grep '[Ss]ee .*test-suite\.log'
+ cat stdout | grep '[Tt]estsuite summary'
+ ) | grep "$esc" && exit 1
+ : For shells with broken 'set -e'
+ else
+ cat stdout | grep "$esc" && exit 1
+ : For shells with broken 'set -e'
+ fi
+}
+
+our_make ()
+{
+ set "MAKE=$MAKE" ${1+"$@"}
+ env "$@" expect -f $srcdir/expect-make >stdout || { cat stdout; exit 1; }
+ cat stdout
+}
+
+cat >expect-make <<'END'
+eval spawn $env(MAKE) -e check
+expect eof
+END
+
+for vpath in false :; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+
+ our_make TERM=ansi
+ test_color
+
+ our_make TERM=dumb
+ test_no_color
+
+ our_make AM_COLOR_TESTS=no
+ test_no_color
+
+ $srcdir/configure testsuite_colorized=false
+
+ our_make TERM=ansi
+ test_no_color
+
+ our_make TERM=ansi MAKE="env AM_COLOR_TESTS=always $MAKE"
+ test_color
+
+ $MAKE distclean
+ cd $srcdir
+
+done
+
+:
diff --git a/t/commen10.sh b/t/commen10.sh
new file mode 100644
index 000000000..a8e67ebd9
--- /dev/null
+++ b/t/commen10.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure comments following trailing backslashes are diagnosed.
+# Report from Harald Dunkel.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+SUBDIRS = foo \
+# bar
+
+END
+
+mkdir foo
+
+$ACLOCAL
+AUTOMAKE_fails
+grep backslash stderr
diff --git a/t/commen11.sh b/t/commen11.sh
new file mode 100644
index 000000000..0f9cf722d
--- /dev/null
+++ b/t/commen11.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure backslash-newline-hash combinations are diagnosed as
+# comments following a trailing backslash, even when the combination
+# follows a variable assignment that is preceded by a comment.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+# initial comment
+variable = value-before-comment \
+#
+
+# comment
+SUBDIRS = foo \
+# bar
+
+END
+
+mkdir foo
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile\.am:3:.*backslash' stderr
+grep '^Makefile\.am:7:.*backslash' stderr
+
+:
diff --git a/t/comment-block.sh b/t/comment-block.sh
new file mode 100644
index 000000000..7c3712f69
--- /dev/null
+++ b/t/comment-block.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure block comments are not double-spaced.
+# Report from François Pinard.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+#START
+#a
+#b
+#c
+#END
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+(sed -e '/^#START/,/^#END/ !d' Makefile.in | grep -v '^#') && exit 1
+exit 0
diff --git a/t/comment.sh b/t/comment.sh
new file mode 100644
index 000000000..fedf97ec0
--- /dev/null
+++ b/t/comment.sh
@@ -0,0 +1,27 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that '#' as start of word in AUTOMAKE_OPTIONS means
+# comment.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = #no such option
+END
+
+$ACLOCAL
+$AUTOMAKE
diff --git a/t/comment2.sh b/t/comment2.sh
new file mode 100644
index 000000000..e78d6e41f
--- /dev/null
+++ b/t/comment2.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure comment recognition works in PROGRAMS. Report from Mark
+# Galassi.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = sim_products receive_th receive_pos # image_proc
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^image_proc' Makefile.in && exit 1
+exit 0
diff --git a/t/comment3.sh b/t/comment3.sh
new file mode 100644
index 000000000..7a595b46f
--- /dev/null
+++ b/t/comment3.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that '#' after a tab is a failure.
+# The Tru64 Unix V5.1 system make will pass these to the
+# shell, which in turn can't find '#' as a command.
+# Sigh. Some vendors must be destroyed.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+install-data-local:
+ # Tru64 Unix must die
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'Makefile.am:2:.*#' stderr
diff --git a/t/comment4.sh b/t/comment4.sh
new file mode 100644
index 000000000..eeb012e2e
--- /dev/null
+++ b/t/comment4.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure commented variables are output near their comments.
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'EOF'
+# UnIqUe_COPYRIGHT_BOILERPLATE
+
+# UnIqUe_MUMBLE_COMMENT
+mumble = UnIqUe_MUMBLE_VALUE
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+# UnIqUe_COPYRIGHT_BOILERPLATE should appear near the top of the file.
+test $(sed -n -e '1,/UnIqUe_COPYRIGHT_BOILERPLATE/p' \
+ Makefile.in | wc -l) -le 30
+# UnIqUe_MUMBLE_COMMENT should appear right before the mumble declaration.
+test $(sed -n -e '/UnIqUe_MUMBLE_COMMENT/,/UnIqUe_MUMBLE_VALUE/p' \
+ Makefile.in | wc -l) -eq 2
+
+:
diff --git a/t/comment5.sh b/t/comment5.sh
new file mode 100644
index 000000000..ac15884f0
--- /dev/null
+++ b/t/comment5.sh
@@ -0,0 +1,85 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR/280.
+# (Automake should complain about trailing backslashes in comments.)
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'EOF'
+all-local:
+ @echo ${var}
+
+# a comment with backslash \
+
+
+var = foo
+EOF
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile.am:5: error: blank line following trailing backslash' stderr
+
+
+## Here is a second test because head comments are
+## handled differently in Automake 1.5.
+
+cat > Makefile.am << 'EOF'
+# a comment with backslash \
+
+
+all-local:
+ @echo ${var}
+
+var = foo
+EOF
+
+AUTOMAKE_fails
+grep '^Makefile.am:2: error: blank line following trailing backslash' stderr
+
+
+## Make sure we print an 'included' stack on errors.
+
+echo 'include Makefile.inc'> Makefile.am
+cat > Makefile.inc << 'EOF'
+# a comment with backslash \
+
+EOF
+
+AUTOMAKE_fails
+grep '^Makefile.inc:2: error: blank line following trailing backslash' stderr
+grep '^Makefile.am:1: .*included from here' stderr
+grep -v '^Makefile.am:1: .*error:' stderr
+
+
+## Make sure backslashes are still allowed within a comment.
+## This usually happens when commenting out a Makefile rule.
+
+cat > Makefile.am << 'EOF'
+all-local:
+ @echo ${var}
+
+# a comment with backslash \
+# but terminated by a line without backslash
+
+var = foo
+EOF
+
+$AUTOMAKE
diff --git a/t/comment6.sh b/t/comment6.sh
new file mode 100644
index 000000000..2e5455af9
--- /dev/null
+++ b/t/comment6.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR/322.
+# Automake 1.6.1 seems to have a problem parsing comments that use
+# '\' to span multiple lines.
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AC_OUTPUT
+EOF
+
+## There are two tests: one with backslashed comments at the top
+## of the file, and one with a rule first. This is because
+## Comments at the top of the file are handled specially
+## since Automake 1.5.
+
+cat > Makefile.am << 'EOF'
+# SOME_FILES = \
+ file1 \
+ file2 \
+ file3
+
+all-local:
+ @echo Good
+
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
+
+grep '# SOME_FILES' Makefile
+grep '# *file3' Makefile
+
+cat > Makefile.am << 'EOF'
+all-local:
+ @echo Good
+
+# SOME_FILES = \
+ file1 \
+ file2 \
+ file3
+EOF
+
+$AUTOMAKE
+./configure
+$MAKE
+grep '# SOME_FILES' Makefile
+grep '# *file3' Makefile
+
+:
diff --git a/t/comment7.sh b/t/comment7.sh
new file mode 100644
index 000000000..d2efdfc96
--- /dev/null
+++ b/t/comment7.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure comment for conditional variables are output near the
+# corresponding conditional definitions.
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AM_CONDITIONAL([COND], [true])
+EOF
+
+cat > Makefile.am << 'EOF'
+if COND
+# Comment for VAR in COND_TRUE.
+VAR = foo
+else
+# Comment for VAR in COND_FALSE.
+VAR = bar
+endif
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP '@COND' Makefile.in # For debugging, mostly.
+
+# The VAR definition appears once for each condition.
+test $(grep -c '@COND_TRUE@VAR' Makefile.in) = 1
+test $(grep -c '@COND_FALSE@VAR' Makefile.in) = 1
+
+# Make sure the right definition follows each comment.
+sed -n '/^#.*VAR.*COND_TRUE/ {
+ n
+ p
+ }' Makefile.in |
+ grep '@COND_TRUE@VAR = foo'
+sed -n '/^#.*VAR.*COND_FALSE/ {
+ n
+ p
+ }' Makefile.in |
+ grep '@COND_FALSE@VAR = bar'
+
+:
diff --git a/t/comment8.sh b/t/comment8.sh
new file mode 100644
index 000000000..bee420e16
--- /dev/null
+++ b/t/comment8.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure += does not append to a comment.
+# Report from Stepan Kasal.
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [true])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'EOF'
+VAR = valA# comA ## com C
+VAR += valB # comB
+if COND1
+ VAR += val1 # com1
+endif COND1
+VAR += valC
+if COND2
+ VAR += val2 # com2
+endif COND2
+
+.PHONY: test
+test:
+ is $(VAR) == valA valB val1 valC val2
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE test
diff --git a/t/comment9.sh b/t/comment9.sh
new file mode 100644
index 000000000..299a75ba2
--- /dev/null
+++ b/t/comment9.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure ##-comments are ignored in variable definitions.
+# Report from Julien Sopena.
+
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+TESTS = \
+ 1.test \
+ 2.test \
+ 3.test \
+## 4.test \
+ 5.test \
+ 6.test \
+ 7.test
+EOF
+
+: > test-driver
+
+$ACLOCAL
+$AUTOMAKE
+
+sed -n -e '/^TESTS =.*\\$/ {
+ :loop
+ p
+ n
+ t clear
+ :clear
+ s/\\$/\\/
+ t loop
+ p
+ n
+ }' -e '/^TESTS =/ p' Makefile.in > tests
+
+grep '3\.test' tests
+grep '##' tests && exit 1
+grep '4\.test' tests && exit 1
+grep '5\.test' tests
diff --git a/t/comments-in-var-def.sh b/t/comments-in-var-def.sh
new file mode 100644
index 000000000..fc991dbe2
--- /dev/null
+++ b/t/comments-in-var-def.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake ignores in-line comments when using variables,
+# but preserve them in the output.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+# Use a slash in the comment, because automake takes the dirname
+# of TEXINFO_TEX to compute $(am__TEXINFO_TEX_DIR).
+cat > Makefile.am << 'END'
+TEXINFO_TEX = tex/texinfo.tex # some comment w/ a slash
+info_TEXINFOS = main.texi
+.PHONY: test
+test:
+ test tex/texinfo.tex = $(TEXINFO_TEX)
+ test -d '$(am__TEXINFO_TEX_DIR)'
+ case '$(am__TEXINFO_TEX_DIR)' in tex|./tex) :;; *) exit 1;; esac
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+END
+
+mkdir tex
+: > tex/texinfo.tex
+
+$ACLOCAL
+$AUTOMAKE
+
+grep TEX Makefile.in # For debugging.
+grep '^TEXINFO_TEX *= *tex/texinfo\.tex *# some comment w/ a slash *$' Makefile.in
+
+$AUTOCONF
+./configure
+$MAKE test
+
+:
diff --git a/t/compile.sh b/t/compile.sh
new file mode 100644
index 000000000..086fdd963
--- /dev/null
+++ b/t/compile.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'compile' preserves spaces in its arguments.
+
+am_create_testdir=empty
+. test-init.sh
+
+get_shell_script compile
+
+# -o 'a c' should not be stripped because 'a c' is not an object
+# (it does not matter whether touch creates ./-- or not)
+./compile touch a.o -- -o 'a c' a.c
+test -f 'a c'
+test -f ./-o
+test -f a.o
+test -f a.c
+
+rm -f 'a c' ./-o a.o a.c
+
+./compile touch a.o -- -o 'a c.o' a.c
+test -f 'a c.o'
+test ! -e ./-o
+test ! -e a.o
+test -f a.c
+
+# Make sure 'compile' works for .obj too.
+./compile touch a.obj -- -o ac.obj a.c
+test ! -e a.obj
+test ac.obj
+
+:
diff --git a/t/compile2.sh b/t/compile2.sh
new file mode 100644
index 000000000..602a66a22
--- /dev/null
+++ b/t/compile2.sh
@@ -0,0 +1,84 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'compile' deals correctly with Windows-style paths.
+
+am_create_testdir=empty
+. test-init.sh
+
+get_shell_script compile
+
+cat >mycc <<'END'
+source_seen=no
+for arg
+do
+ test "X$arg" = X-o && exit 1
+ test "X$arg" = "X$amtest_source" && source_seen=yes
+done
+if test "$source_seen" != yes; then
+ echo "$0: no source file seen" >&2
+ exit 1
+fi
+if test ! -f "$amtest_source"; then
+ echo "$0: $amtest_source not readable" >&2
+ exit 1
+fi
+if test ! -d "$amtest_lock"; then
+ echo "$0: no lockdir $amtest_lock" >&2
+ exit 1
+fi
+touch "$amtest_obj"
+END
+
+chmod +x ./mycc
+
+# In case this test runs on a system with backslash directory separators:
+mkdir libltdl libltdl/libltdl
+
+# Backslashes in the input and the output name should be accepted.
+# Since this test might run on non-w32 systems, we need to be careful not
+# to use any backslash sequences which might be interpreted by 'echo'.
+amtest_source='libltdl\libltdl\slist.c'
+amtest_object='libltdl\libltdl\libltdl_libltdl_la-slist.obj'
+amtest_obj='slist.o'
+amtest_lock='slist_o.d'
+export amtest_source amtest_object amtest_obj amtest_lock
+
+: > "$amtest_source"
+./compile ./mycc -c "$amtest_source" -o "$amtest_object"
+test -f "$amtest_object"
+
+# Absolute Windows paths should be accepted.
+# Do not actually run this test on anything that could be Windows.
+if test -d 'C:\'; then
+ skip_ "this test shouldn't run on a Windows-like system"
+fi
+case $PATH_SEPARATOR in
+ ';'|':');;
+ *) skip_ "unrecognized PATH separator '$PATH_SEPARATOR'"
+esac
+
+amtest_source='C:\libltdl\libltdl\slist.c'
+amtest_object='C:\libltdl\libltdl\libltdl_libltdl_la-slist.obj'
+amtest_obj='slist.o'
+amtest_lock='slist_o.d'
+export amtest_source amtest_object amtest_obj amtest_lock
+
+: > "$amtest_source"
+./compile ./mycc -c "$amtest_source" -o "$amtest_object"
+test -f "$amtest_object"
+
+:
diff --git a/t/compile3.sh b/t/compile3.sh
new file mode 100644
index 000000000..d8b5a28d1
--- /dev/null
+++ b/t/compile3.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'compile' wraps the Microsoft C/C++ compiler (cl) correctly
+
+am_create_testdir=empty
+required=xsi-lib-shell
+. test-init.sh
+
+get_shell_script compile
+
+# Use a dummy cl, since cl isn't readily available on all systems
+cat >cl <<'END'
+#! /bin/sh
+echo "$@"
+END
+
+chmod +x ./cl
+
+# POSIX mandates that the compiler accepts a space between the -I,
+# -l and -L options and their respective arguments. Traditionally,
+# this should work also without a space. Try both usages.
+for sp in '' ' '; do
+
+ # Check if compile handles "-o foo", -I, -l, -L, -Xlinker -Wl,
+ opts=$(LIB= ./compile ./cl foo.c -o foo -l${sp}bar -L${sp}gazonk \
+ -I${sp}baz -Xlinker foobar -Wl,-foo,bar)
+ test x"$opts" = \
+ x"foo.c -Fefoo bar.lib -Ibaz -link -LIBPATH:gazonk foobar -foo bar"
+
+ # Check if compile handles "-o foo.obj"
+ opts=$(./compile ./cl -c foo.c -o foo.obj -I${sp}baz)
+ test x"$opts" = x"-c foo.c -Fofoo.obj -Ibaz"
+
+ # Check if compile handles "-o foo.o"
+ opts=$(./compile ./cl -c foo.c -o foo.o -I${sp}baz)
+ test x"$opts" = x"-c foo.c -Fofoo.o -Ibaz"
+
+ # Check if compile handles "foo.cc" as C++.
+ opts=$(./compile ./cl -c foo.cc -o foo.o -I${sp}baz)
+ test x"$opts" = x"-c -Tpfoo.cc -Fofoo.o -Ibaz"
+
+ # Check if compile clears the "eat" variable properly.
+ opts=$(eat=1 ./compile ./cl -c foo.c -o foo.obj -I${sp}baz)
+ test x"$opts" = x"-c foo.c -Fofoo.obj -Ibaz"
+
+done
+
+:
diff --git a/t/compile4.sh b/t/compile4.sh
new file mode 100644
index 000000000..630d8b681
--- /dev/null
+++ b/t/compile4.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'compile' wraps the Microsoft C/C++ compiler (cl) correctly
+# with respect to absolute paths.
+
+required='cl'
+. test-init.sh
+
+get_shell_script compile
+
+mkdir sub
+
+cat >sub/foo.c <<'EOF'
+int foo (void)
+{
+ return 0;
+}
+EOF
+
+cat >main.c <<'EOF'
+extern int foo (void);
+int main (void)
+{
+ return foo ();
+}
+EOF
+
+cwd=$(pwd) || fatal_ "cannot get current directory"
+absfoodir=$cwd/sub
+absmainc=$cwd/main.c
+absmainobj=$cwd/main.obj
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+END
+
+cat > sub/Makefile.am << 'END'
+lib_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE
+
+./compile cl $CPPFLAGS $CFLAGS -c -o "$absmainobj" "$absmainc"
+
+# POSIX mandates that the compiler accepts a space between the -I,
+# -l and -L options and their respective arguments. Traditionally,
+# this should work also without a space. Try both usages.
+for sp in '' ' '; do
+ rm -f main
+ ./compile cl $CFLAGS $LDFLAGS -L${sp}"$absfoodir" "$absmainobj" \
+ -o main -l${sp}foo
+ ./main
+done
+
+:
diff --git a/t/compile5.sh b/t/compile5.sh
new file mode 100644
index 000000000..9e96083e7
--- /dev/null
+++ b/t/compile5.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the file name translation in the 'compile' script works
+# correctly
+
+. test-init.sh
+
+get_shell_script compile
+
+# Use a dummy cl, since cl isn't readily available on all systems
+cat >cl <<'END'
+#! /bin/sh
+echo "$@"
+END
+
+chmod +x ./cl
+
+cat >>configure.ac << 'END'
+AC_CANONICAL_HOST
+AC_CONFIG_FILES([check_host], [chmod +x check_host])
+AC_OUTPUT
+END
+
+: >Makefile.am
+
+# This will be sourced, nor executed.
+cat >check_host.in << 'END'
+case '@host_os@' in
+ mingw*)
+ ;;
+ *)
+ skip_ "target OS is not MinGW"
+ ;;
+esac
+case @build_os@ in
+ mingw* | cygwin*)
+ ;;
+ *)
+ winepath -w / \
+ || skip_ "not on MinGW or Cygwin, and winepath not available"
+ ;;
+esac
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+. ./check_host
+
+cwd=$(pwd) || fatal_ "cannot get current directory"
+
+# POSIX mandates that the compiler accepts a space between the -I,
+# -l and -L options and their respective arguments. Traditionally,
+# this should work also without a space. Try both usages.
+for sp in '' ' '; do
+ # Check if "compile cl" transforms absolute file names to
+ # host format (e.g /somewhere -> c:/msys/1.0/somewhere).
+ res=$(./compile ./cl -L${sp}"$cwd" | sed -e 's/-link -LIBPATH://')
+ case $res in
+ ?:[\\/]*) ;;
+ *) exit 1 ;;
+ esac
+done
+
+:
diff --git a/t/compile6.sh b/t/compile6.sh
new file mode 100644
index 000000000..7a72eea4d
--- /dev/null
+++ b/t/compile6.sh
@@ -0,0 +1,115 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'compile' searches libraries correctly
+
+am_create_testdir=empty
+required=xsi-lib-shell
+. test-init.sh
+
+get_shell_script compile
+
+# Use a dummy cl, since cl isn't readily available on all systems
+cat >cl <<'END'
+#! /bin/sh
+echo "$@"
+END
+
+chmod +x ./cl
+
+# POSIX mandates that the compiler accepts a space between the -I,
+# -l and -L options and their respective arguments. Traditionally,
+# this should work also without a space. Try both usages.
+for sp in '' ' '; do
+
+ rm -rf lib lib2 syslib "sys lib2"
+
+ mkdir syslib
+ : > syslib/foo.lib
+
+ syslib=$(pwd)/syslib
+ LIB=$syslib
+ export LIB
+
+ mkdir lib
+ : > lib/bar.lib
+ : > lib/bar.dll.lib
+ : > lib/libbar.a
+ : > lib/libbaz.a
+
+ # Check if compile library search correctly
+ opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}bar -l${sp}foo)
+ test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib"
+
+ # Check if -static makes compile avoid bar.dll.lib
+ opts=$(./compile ./cl foo.c -o foo -L${sp}lib -static -l${sp}bar -l${sp}foo)
+ test x"$opts" = x"foo.c -Fefoo lib/bar.lib $syslib/foo.lib -link -LIBPATH:lib"
+
+ : > syslib/bar.lib
+ : > syslib/bar.dll.lib
+ : > syslib/libbar.a
+
+ # Check if compile finds bar.dll.lib in syslib
+ opts=$(./compile ./cl foo.c -o foo -l${sp}bar -l${sp}foo)
+ test x"$opts" = x"foo.c -Fefoo $syslib/bar.dll.lib $syslib/foo.lib"
+
+ # Check if compile prefers -L over $LIB
+ opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}bar -l${sp}foo)
+ test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib"
+
+ # Check if compile falls back to finding classic libname.a style libraries
+ # when name.lib or name.dll.lib isn't available.
+ opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}baz)
+ test x"$opts" = x"foo.c -Fefoo lib/libbaz.a -link -LIBPATH:lib"
+
+ mkdir lib2
+ : > lib2/bar.dll.lib
+
+ # Check if compile avoids bar.dll.lib in lib2 when -static
+ opts=$(./compile ./cl foo.c -o foo -L${sp}lib2 -static -l${sp}bar -l${sp}foo)
+ test x"$opts" = x"foo.c -Fefoo $syslib/bar.lib $syslib/foo.lib -link -LIBPATH:lib2"
+
+ # Check if compile gets two different bar libraries when -static
+ # is added in the middle
+ opts=$(./compile ./cl foo.c -o foo -L${sp}lib2 -L${sp}lib -l${sp}bar -static -l${sp}bar)
+ test x"$opts" = x"foo.c -Fefoo lib2/bar.dll.lib lib/bar.lib -link -LIBPATH:lib2 -LIBPATH:lib"
+
+ # Check if compile gets the correct bar.dll.lib
+ opts=$(./compile ./cl foo.c -o foo -L${sp}lib -L${sp}lib2 -l${sp}bar -l${sp}foo)
+ test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib -LIBPATH:lib2"
+
+ # Check if compile gets the correct bar.dll.lib
+ opts=$(./compile ./cl foo.c -o foo -L${sp}lib2 -L${sp}lib -l${sp}bar -l${sp}foo)
+ test x"$opts" = x"foo.c -Fefoo lib2/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib2 -LIBPATH:lib"
+
+ mkdir "sys lib2"
+ : > "sys lib2/foo.dll.lib"
+
+ syslib2="$(pwd)/sys lib2"
+ LIB="$syslib2;$LIB"
+
+ # Check if compile handles spaces in $LIB and that it obeys the order
+ # in a multi-component $LIB.
+ opts=$(./compile ./cl foo.c -o foo -l${sp}foo)
+ test x"$opts" = x"foo.c -Fefoo $syslib2/foo.dll.lib"
+
+ # Check if compile handles the 2nd directory in a multi-component $LIB.
+ opts=$(./compile ./cl foo.c -o foo -static -l${sp}foo)
+ test x"$opts" = x"foo.c -Fefoo $syslib/foo.lib"
+
+done
+
+:
diff --git a/t/compile7.sh b/t/compile7.sh
new file mode 100644
index 000000000..d2eb8f887
--- /dev/null
+++ b/t/compile7.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'compile' wraps the Intel C/C++ compiler (icl) correctly
+# with respect to absolute paths.
+
+required='icl'
+. test-init.sh
+
+get_shell_script compile
+
+mkdir sub
+
+cat >sub/foo.c <<'EOF'
+int foo (void)
+{
+ return 0;
+}
+EOF
+
+cat >main.c <<'EOF'
+extern int foo (void);
+int main (void)
+{
+ return foo ();
+}
+EOF
+
+cwd=$(pwd) || fatal_ "cannot get current directory"
+absfoodir=$cwd/sub
+absmainc=$cwd/main.c
+absmainobj=$cwd/main.obj
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+END
+
+cat > sub/Makefile.am << 'END'
+lib_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE
+
+./compile icl $CPPFLAGS $CFLAGS -c -o "$absmainobj" "$absmainc"
+
+# POSIX mandates that the compiler accepts a space between the -I,
+# -l and -L options and their respective arguments. Traditionally,
+# this should work also without a space. Try both usages.
+for sp in '' ' '; do
+ rm -f main
+ ./compile icl $CFLAGS $LDFLAGS -L${sp}"$absfoodir" "$absmainobj" \
+ -o main -l${sp}foo
+ ./main
+done
+
+:
diff --git a/t/compile_f90_c_cxx.sh b/t/compile_f90_c_cxx.sh
new file mode 100644
index 000000000..986683614
--- /dev/null
+++ b/t/compile_f90_c_cxx.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure rules to invoke all compilers are selected with
+# mixed source objects.
+# (copied from compile_f_c_cxx.sh) Mike Nolta <mrnolta@princeton.edu>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_FC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.f90 bar.c baz.cc
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# Look for the macros at the beginning of rules.
+tab=
+$FGREP "$tab\$(COMPILE)" Makefile.in
+$FGREP "$tab\$(CXXCOMPILE)" Makefile.in
+$FGREP "$tab\$(FCCOMPILE)" Makefile.in
+
+:
diff --git a/t/compile_f_c_cxx.sh b/t/compile_f_c_cxx.sh
new file mode 100644
index 000000000..8fa80a4b5
--- /dev/null
+++ b/t/compile_f_c_cxx.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure rules to invoke all compilers are selected with
+# mixed source objects.
+# Matthew D. Langston <langston@SLAC.Stanford.EDU>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_F77
+AC_F77_LIBRARY_LDFLAGS
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.f bar.c baz.cc
+END
+
+: > config.guess
+: > config.sub
+
+$ACLOCAL
+$AUTOMAKE
+
+# Look for the macros at the beginning of rules.
+$FGREP "$tab\$(AM_V_CC)\$(COMPILE)" Makefile.in
+$FGREP "$tab\$(AM_V_CXX)\$(CXXCOMPILE)" Makefile.in
+$FGREP "$tab\$(AM_V_F77)\$(F77COMPILE)" Makefile.in
+
+:
diff --git a/t/cond-basic.sh b/t/cond-basic.sh
new file mode 100644
index 000000000..9ddeb1c5d
--- /dev/null
+++ b/t/cond-basic.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check basic use of conditionals.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([TEST], [true])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if TEST
+target: true
+ action
+else
+target: false
+endif
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^@TEST_TRUE@target: true' Makefile.in
+grep "^@TEST_TRUE@${tab}action" Makefile.in
+grep '^@TEST_FALSE@target: false' Makefile.in
+
+:
diff --git a/t/cond.sh b/t/cond.sh
new file mode 100644
index 000000000..f4a8b487f
--- /dev/null
+++ b/t/cond.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check basic use of conditionals.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([TEST], [true])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if TEST
+VAR = true
+else
+VAR = false
+endif
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^TEST_FALSE' Makefile.in && exit 1
+grep '^TEST_TRUE' Makefile.in && exit 1
+grep '^@TEST_TRUE@VAR = true$' Makefile.in
+grep '^@TEST_FALSE@VAR = false$' Makefile.in
+
+:
diff --git a/t/cond10.sh b/t/cond10.sh
new file mode 100644
index 000000000..8a1d68f89
--- /dev/null
+++ b/t/cond10.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in conditionals. From Raja R Harinath.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([USE_A], [test x = y])
+AM_CONDITIONAL([USE_B], [test x = z])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if USE_A
+out=output_a.c
+else
+if USE_B
+out=output_b.c
+else
+out=output_c.c
+endif
+endif
+
+noinst_PROGRAMS=foo
+foo_SOURCES=foo.c $(out)
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+grep 'USE_A_FALSE.*USE_B_FALSE.*output_c\...OBJEXT.' Makefile.in
+
+:
diff --git a/t/cond11.sh b/t/cond11.sh
new file mode 100644
index 000000000..20f4af783
--- /dev/null
+++ b/t/cond11.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in conditionals. From Richard Boulton.
+# This checks that, if LDADD is set from a conditional variable
+# and an AC_SUBST, the _DEPENDENCIES variable is set correctly.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([CC], [false])
+AM_CONDITIONAL([USE_A], [test -z "$two"])
+AC_SUBST([SUBSTVAR], [bar])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if USE_A
+foolibs=faz.la
+else
+foolibs=
+endif
+
+noinst_PROGRAMS = foo
+foo_SOURCES = foo.c
+LDADD = $(SUBSTVAR) $(foolibs)
+
+.PHONY: test1 test2
+test1:
+ is faz.la == $(foo_DEPENDENCIES)
+test2:
+ is "" == $(foo_DEPENDENCIES)
+END
+
+: > config.guess
+: > config.sub
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --ignore-deps
+
+./configure
+$MAKE test1
+
+./configure two=yes
+$MAKE test2
+
+:
diff --git a/t/cond13.sh b/t/cond13.sh
new file mode 100644
index 000000000..c2e78e5a8
--- /dev/null
+++ b/t/cond13.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in conditionals.
+# Report from Lars J. Aas.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AM_PROG_AR
+AC_PROG_RANLIB
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [true])
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtest.a
+
+if COND1
+SOURCEVAR1 =
+SOURCEVAR2 = habla.cpp espanol.cpp
+else
+SOURCEVAR1 = dummy.cpp
+SOURCEVAR2 =
+endif
+
+if COND2
+TESTSOURCES = $(SOURCEVAR1)
+else
+TESTSOURCES = $(SOURCEVAR2)
+endif
+
+libtest_a_SOURCES = $(TESTSOURCES)
+END
+
+: > ar-lib
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^am_libtest_a_OBJECTS =' Makefile.in
+
+:
diff --git a/t/cond14.sh b/t/cond14.sh
new file mode 100644
index 000000000..1cfd30233
--- /dev/null
+++ b/t/cond14.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in conditionals.
+# Report from Robert Boehne.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([COND1], [true])
+END
+
+cat > Makefile.am << 'END'
+if COND1
+BUILD_helldl = helldl
+helldl_SOURCES = dlmain.c
+helldl_DEPENDENCIES = libhello.la
+else
+BUILD_helldl =
+bin_SCRIPTS = helldl
+helldl$(EXEEXT):
+ rm -f $@
+ echo '#! /bin/sh' > $@
+ echo '-dlopen is unsupported' >> $@
+ chmod +x $@
+endif
+
+bin_PROGRAMS = $(BUILD_helldl)
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP helldl Makefile.in # For debugging.
+test $($FGREP -c 'helldl$(EXEEXT):' Makefile.in) -eq 2
+
+:
diff --git a/t/cond15.sh b/t/cond15.sh
new file mode 100644
index 000000000..d11882ba4
--- /dev/null
+++ b/t/cond15.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for conditionally defined overriding of automatic rules.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [true])
+END
+
+cat > Makefile.am << 'END'
+if COND1
+if COND2
+bin_SCRIPTS = helldl
+helldl$(EXEEXT):
+ rm -f $@
+ echo '#! /bin/sh' > $@
+ echo '-dlopen is unsupported' >> $@
+ chmod +x $@
+endif
+else
+if COND2
+else
+bin_SCRIPTS = helldl
+helldl$(EXEEXT):
+ rm -f $@
+ echo '#! /bin/sh' > $@
+ echo '-dlopen is unsupported' >> $@
+ chmod +x $@
+endif
+endif
+
+bin_PROGRAMS = helldl
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP helldl Makefile.in # For debugging.
+num1=$($FGREP -c 'helldl$(EXEEXT):' Makefile.in)
+num2=$($FGREP -c '@COND1_FALSE@@COND2_TRUE@helldl$(EXEEXT):' Makefile.in)
+test $num1 -eq 4
+test $num2 -eq 1
+
+:
diff --git a/t/cond16.sh b/t/cond16.sh
new file mode 100644
index 000000000..e34b23f4b
--- /dev/null
+++ b/t/cond16.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in conditionals in SOURCES with variable substitution
+# references.
+# Report from Richard Boulton.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND1], [true])
+AC_OUTPUT
+END
+
+: > hello.c
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+CC = false
+OBJEXT = o
+
+if COND1
+var = foo.c
+else
+var = foo.c
+endif
+
+bin_PROGRAMS = hell
+hell_SOURCES = $(var:=)
+
+.PHONY: test
+test:
+ is $(hell_SOURCES) $(hell_OBJECTS) == foo.c foo.o
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE test
+
+:
diff --git a/t/cond17.sh b/t/cond17.sh
new file mode 100644
index 000000000..82405f05b
--- /dev/null
+++ b/t/cond17.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for being able to define an object to be generated in different ways
+# according to a conditional.
+# Report from Richard Boulton.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AM_CONDITIONAL([COND1], [true])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = helldl
+if COND1
+helldl_SOURCES = foo.cc
+else
+helldl_SOURCES = foo.c
+endif
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+:
diff --git a/t/cond18.sh b/t/cond18.sh
new file mode 100644
index 000000000..70e2edab4
--- /dev/null
+++ b/t/cond18.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for substitution references to conditional variables.
+# Report from Richard Boulton.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [true])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+CC = false
+OBJEXT = obj
+
+var1 = dlmain
+
+if COND1
+var2 = $(var1:=.c) foo.cc
+else
+var2 = $(var1:=.c)
+endif
+
+if COND2
+var3 = $(var2:.cc=.c)
+else
+var3 = $(var2:.cc=.c)
+endif
+
+helldl_SOURCES = $(var3)
+
+.PHONY: test
+test:
+ is $(helldl_SOURCES) $(helldl_OBJECTS) == \
+ dlmain.c foo.c dlmain.obj foo.obj
+
+bin_PROGRAMS = helldl
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE test
+
+:
diff --git a/t/cond19.sh b/t/cond19.sh
new file mode 100644
index 000000000..ecdf014e1
--- /dev/null
+++ b/t/cond19.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for substitution references to conditional variables.
+# Report from Richard Boulton.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([CC], [false])
+AC_SUBST([OBJEXT], [o])
+AM_CONDITIONAL([COND1], [test "x$CONDITION1" = "xtrue"])
+AM_CONDITIONAL([COND2], [test "x$CONDITION2" = "xtrue"])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = helldl
+
+var1 = dlmain
+
+if COND1
+var2 = $(var1:=.c)
+else
+var2 = $(var1:=.c)
+endif
+
+if COND2
+var3 = $(var2:.c=a.c)
+var4 = $(var2:.c=b.c)
+else
+var3 = $(var2:.c=b.c)
+var4 = $(var2:.c=a.c)
+endif
+
+helldl_SOURCES = $(var3:.c=1.c) $(var4:.c=2.c)
+
+.PHONY: test
+test:
+ is $(exp) == $(helldl_SOURCES) $(helldl_OBJECTS)
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a -i
+
+CONDITION1=true CONDITION2=true ./configure
+$MAKE test exp='dlmaina1.c dlmainb2.c dlmaina1.o dlmainb2.o'
+CONDITION1=true CONDITION2=false ./configure
+$MAKE test exp='dlmainb1.c dlmaina2.c dlmainb1.o dlmaina2.o'
+CONDITION1=false CONDITION2=true ./configure
+$MAKE test exp='dlmaina1.c dlmainb2.c dlmaina1.o dlmainb2.o'
+CONDITION1=false CONDITION2=false ./configure
+$MAKE test exp='dlmainb1.c dlmaina2.c dlmainb1.o dlmaina2.o'
+
+:
diff --git a/t/cond20.sh b/t/cond20.sh
new file mode 100644
index 000000000..dfbb6e3f7
--- /dev/null
+++ b/t/cond20.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for recursion handling in substitution references to
+# conditional variables.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([COND1], [true])
+END
+
+cat > Makefile.am << 'END'
+var1 = $(var2)
+
+if COND1
+var2 = $(var1:=.c) foo.c
+else
+var2 = $(var1:=.c)
+endif
+
+helldl_SOURCES = $(var2)
+
+bin_PROGRAMS = helldl
+END
+
+$ACLOCAL
+$AUTOCONF
+AUTOMAKE_fails -a
+grep "variable.*var2.*recursively defined" stderr
+
+:
diff --git a/t/cond21.sh b/t/cond21.sh
new file mode 100644
index 000000000..7aecdc24c
--- /dev/null
+++ b/t/cond21.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for use of = and += in different conditions.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [true])
+AM_CONDITIONAL([COND3], [true])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+
+FOO = foo
+if COND1
+ FOO += foo1
+else
+ FOO += foon1
+endif
+if COND2
+ FOO += foo2
+else
+ FOO += foon2
+endif
+if COND1
+ FOO += foo1b
+else
+ FOO += foon1b
+endif
+
+if COND1
+if COND2
+ BAR = bar12
+else
+ BAR = bar1n2
+endif
+else
+ BAR = barn1
+endif
+
+BAR += bar
+
+if COND3
+ BAR += bar3
+endif
+
+.PHONY: test
+test:
+ @echo BAR: $(BAR) :BAR
+ @echo FOO: $(FOO) :FOO
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE test | $FGREP 'BAR: bar12 bar bar3 :BAR'
+$MAKE test | $FGREP 'FOO: foo foo1 foo2 foo1b :FOO'
+
+:
diff --git a/t/cond22.sh b/t/cond22.sh
new file mode 100644
index 000000000..3812f08c0
--- /dev/null
+++ b/t/cond22.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for bug when sources listed in conditional.
+# Report from Richard Boulton. PR/326.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+CC=false; AC_SUBST([CC])
+OBJEXT=oo; AC_SUBST([OBJEXT])
+AM_CONDITIONAL([ONE], [true])
+AM_CONDITIONAL([TWO], [false])
+AM_CONDITIONAL([THREE], [false])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = targ
+
+if ONE
+SONE = one.c
+endif
+
+if TWO
+STWO =
+else
+STWO = two.c
+endif
+
+if THREE
+STHREE =
+else
+STHREE = three.c
+endif
+
+if THREE
+STHREE2 =
+else
+STHREE2 = three2.c
+endif
+
+targ_SOURCES = $(SONE) $(STWO) $(STHREE) $(STHREE2)
+
+.PHONY: test
+test:
+ is $(targ_OBJECTS) == one.oo two.oo three.oo three2.oo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --ignore-deps
+./configure
+$MAKE test
+
+:
diff --git a/t/cond23.sh b/t/cond23.sh
new file mode 100644
index 000000000..56518b3e0
--- /dev/null
+++ b/t/cond23.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that conditional redefinitions of AC_SUBST'ed variables are detected.
+# Report from Patrik Weiskircher.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AM_CONDITIONAL([COND], [true])
+AC_OUTPUT
+EOF
+
+cat >Makefile.am <<EOF
+if COND
+libdir = mumble
+endif
+EOF
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile\.am:2:.* libdir was already defined' stderr
+
+:
diff --git a/t/cond24.sh b/t/cond24.sh
new file mode 100644
index 000000000..3cfda5a83
--- /dev/null
+++ b/t/cond24.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that conditional redefinitions of AC_SUBST'ed variables are detected.
+# Report from Patrik Weiskircher.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_SUBST([foo], [bar])
+AM_CONDITIONAL([COND], [true])
+EOF
+
+cat >Makefile.am <<EOF
+if COND
+## A dummy comment to change line numer.
+foo = baz
+endif
+EOF
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile\.am:3:.* foo was already defined' stderr
+grep '^configure\.ac:4:.*foo.* previously defined here' stderr
+
+:
diff --git a/t/cond25.sh b/t/cond25.sh
new file mode 100644
index 000000000..e93c0ef60
--- /dev/null
+++ b/t/cond25.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that conditional primaries can use non-conditional directories.
+# From Pavel Roskin.
+
+. test-init.sh
+
+cat >>configure.ac << 'EOF'
+AM_CONDITIONAL([USE_FOO], [true])
+AC_PROG_CC
+EOF
+
+cat >Makefile.am << 'EOF'
+if USE_FOO
+foo_PROGRAMS = foo
+endif
+
+foodir = $(libdir)/foo
+foo_SOURCES = foo.c
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/cond26.sh b/t/cond26.sh
new file mode 100644
index 000000000..535a021ca
--- /dev/null
+++ b/t/cond26.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that non-conditional primaries can use conditional directories.
+# Reported by Juergen Keil.
+
+. test-init.sh
+
+cat >>configure.ac << 'EOF'
+AM_CONDITIONAL([USE_FOO], [true])
+EOF
+
+cat >Makefile.am << 'EOF'
+if USE_FOO
+mydir = /foo
+else
+mydir = /bar
+endif
+my_DATA = foo
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/cond27.sh b/t/cond27.sh
new file mode 100644
index 000000000..a47f5de58
--- /dev/null
+++ b/t/cond27.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that non-conditional primaries cannot use directories defined
+# in some conditions (but not others).
+
+. test-init.sh
+
+cat >>configure.ac << 'EOF'
+AM_CONDITIONAL([USE_FOO], [true])
+EOF
+
+cat >Makefile.am << 'EOF'
+if USE_FOO
+mydir = /foo
+endif
+my_DATA = foo
+EOF
+
+$ACLOCAL
+AUTOMAKE_fails
+grep ' USE_FOO' stderr && exit 1
+grep '!USE_FOO' stderr
+
+:
diff --git a/t/cond28.sh b/t/cond28.sh
new file mode 100644
index 000000000..6238ab767
--- /dev/null
+++ b/t/cond28.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that conditional primaries can use directories defined
+# in the same conditions (but not others).
+
+. test-init.sh
+
+cat >>configure.ac << 'EOF'
+AM_CONDITIONAL([USE_FOO], [true])
+EOF
+
+cat >Makefile.am << 'EOF'
+if USE_FOO
+mydir = /foo
+endif
+if USE_FOO
+my_DATA = foo
+endif
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/cond3.sh b/t/cond3.sh
new file mode 100644
index 000000000..421fd15ef
--- /dev/null
+++ b/t/cond3.sh
@@ -0,0 +1,79 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test sources listed in conditional.
+# Report from Rob Savoye <rob@cygnus.com>, and Lars J. Aas.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([ONE], [true])
+AM_CONDITIONAL([TWO], [false])
+AM_CONDITIONAL([THREE], [maybe])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = targ
+
+if ONE
+SONE = one.c
+else
+SONE =
+endif
+
+if TWO
+STWO = two.c
+else
+STWO =
+endif
+
+if THREE
+STHREE = three.c
+else
+STHREE =
+endif
+
+targ_SOURCES = $(SONE) $(STWO) $(STHREE)
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# 'b top' so that
+sed -n '
+/[oO][bB][jJ][eE][cC][tT].* =/ {
+ : loop
+ /\\$/ {
+ p
+ n
+ b loop
+ }
+ p
+}' Makefile.in >produced
+
+cat >expected << 'EOF'
+@ONE_TRUE@am__objects_1 = one.$(OBJEXT)
+@TWO_TRUE@am__objects_2 = two.$(OBJEXT)
+@THREE_TRUE@am__objects_3 = three.$(OBJEXT)
+am_targ_OBJECTS = $(am__objects_1) $(am__objects_2) $(am__objects_3)
+targ_OBJECTS = $(am_targ_OBJECTS)
+EOF
+
+diff expected produced
+
+:
diff --git a/t/cond30.sh b/t/cond30.sh
new file mode 100644
index 000000000..3bfcd809e
--- /dev/null
+++ b/t/cond30.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# For PR/352: make sure we support bin_PROGRAMS being defined conditionally.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_CONDITIONAL([C1], [test -z "$two"])
+AM_CONDITIONAL([C2], [test -n "$two"])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = no-dependencies
+CC = false
+EXEEXT = .foo
+
+if C1
+bin_PROGRAMS = a
+endif
+if C2
+bin_PROGRAMS = b $(undefined)
+endif
+
+.PHONY: test-a test-b
+test-a:
+ test a.foo = $(bin_PROGRAMS)
+test-b:
+ test b.foo = $(bin_PROGRAMS)
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+$FGREP 'a_SOURCES = a.c' Makefile.in
+$FGREP 'b_SOURCES = b.c' Makefile.in
+
+./configure
+$MAKE test-a
+
+./configure two=yes
+$MAKE test-b
+
+:
diff --git a/t/cond31.sh b/t/cond31.sh
new file mode 100644
index 000000000..1f4ebbdea
--- /dev/null
+++ b/t/cond31.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we define conditional _DEPENDENCIES correctly.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AC_SUBST([CC], [false])
+AC_SUBST([OBJEXT], [o])
+AM_CONDITIONAL([C1], [test -z "$two"])
+AM_CONDITIONAL([C2], [test -n "$two"])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+bin_PROGRAMS = a
+a_LDADD = c0.o -L/some/where
+if C1
+a_LDADD += c1.o -llibfoo.a
+endif
+if C2
+a_LDADD += c2.o -dlopen c3.la
+endif
+
+.PHONY: test1 test2
+test1:
+ is $(a_DEPENDENCIES) == c0.o c1.o
+test2:
+ is $(a_DEPENDENCIES) == c0.o c2.o c3.la
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --ignore-deps
+
+./configure
+$MAKE test1
+
+./configure two=yes
+$MAKE test2
+
+:
diff --git a/t/cond32.sh b/t/cond32.sh
new file mode 100644
index 000000000..879dda9dd
--- /dev/null
+++ b/t/cond32.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the user can override a conditional _DEPENDENCIES.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_CONDITIONAL([C1], [test -z "$two"])
+AM_CONDITIONAL([C2], [test -n "$two"])
+AM_CONDITIONAL([C3], [test -z "$three"])
+# We define CC in Makefile.am, but OBJEXT here.
+OBJEXT=o; AC_SUBST([OBJEXT])
+AC_SUBST([MYSUB], ["foo.$OBJEXT"])
+AC_OUTPUT
+EOF
+
+cat >>Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = no-dependencies
+CC = :
+
+bin_PROGRAMS = a
+
+if C1
+a_LDADD = $(MYSUB)
+a_DEPENDENCIES = $(MYSUB) nonsense.a
+# Note that 'nonsense.a' is there just to make sure Automake insn't
+# using some self computed a_DEPENDENCIES variable.
+endif
+
+if C2
+if C3
+BAR = bar.o
+else
+BAR = baz.o
+endif
+a_LDADD = $(BAR)
+endif
+
+test:
+ is $(exp) == $(a_DEPENDENCIES)
+.PHONY: test
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test exp='foo.o nonsense.a'
+
+./configure two=yes three=
+$MAKE test exp='bar.o'
+
+./configure two=yes three=yes
+$MAKE test exp='baz.o'
+
+:
diff --git a/t/cond33.sh b/t/cond33.sh
new file mode 100644
index 000000000..b9e24dac1
--- /dev/null
+++ b/t/cond33.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that conditionally-defined install directories are handled
+# correctly.
+# Report from Ralf Corsepius.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_CONDITIONAL([INC], [test -z "$two"])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+if INC
+include_foodir = $(includedir)/foo
+include_foo_HEADERS = foo.h
+else
+bardir = $(bindir)
+dist_bar_SCRIPTS = x.sh
+endif
+
+foo.h x.sh:
+ :>$@
+
+.PHONY: distdircheck
+distdircheck: distdir
+ test -f $(distdir)/foo.h
+ test -f $(distdir)/x.sh
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cwd=$(pwd) || fatal_ "cannot get current directory"
+mkdir nowhere
+chmod a-w nowhere
+
+./configure --prefix="$cwd"/nowhere --bindir="$cwd"/bin \
+ --includedir="$cwd"/inc
+$MAKE installdirs
+test ! -e bin
+test -d inc/foo
+test ! -e inc/foo/foo.h
+rm -rf inc
+$MAKE install
+test ! -e bin
+test -f inc/foo/foo.h
+$MAKE distdircheck
+
+rm -rf inc
+
+./configure two=two --prefix="$cwd"/nowhere --bindir="$cwd"/bin \
+ --includedir="$cwd"/inc
+$MAKE install
+test ! -e inc
+test -f bin/x.sh
+rm -rf inc
+$MAKE installdirs
+test ! -e inc
+test -d bin
+$MAKE distdircheck
+
+:
diff --git a/t/cond34.sh b/t/cond34.sh
new file mode 100644
index 000000000..0682faf7b
--- /dev/null
+++ b/t/cond34.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for _DEPENDENCIES definition with conditional _LDADD.
+# Report from Elena A. Vengerova.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_CONDITIONAL([TWO], [test -n "$two"])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+OBJEXT=z
+CC=false
+AUTOMAKE_OPTIONS=no-dependencies
+
+bin_PROGRAMS = test1 test2
+
+if TWO
+ test1_LDADD = two.$(OBJEXT)
+ test2_LDADD = two.$(OBJEXT)
+ test2_DEPENDENCIES = $(test2_LDADD) somethingelse.a
+else !TWO
+ test1_LDADD = one.$(OBJEXT)
+ test2_LDADD = three.$(OBJEXT)
+endif !TWO
+
+test1_DEPENDENCIES = $(test1_LDADD) somethingelse.a
+
+.PHONY: dep-test1 dep-test2
+dep-test1:
+ echo BEG: $(test1_DEPENDENCIES) :END
+dep-test2:
+ echo BEG: $(test2_DEPENDENCIES) :END
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+run_make -O dep-test1
+$FGREP 'BEG: one.z somethingelse.a :END' stdout
+
+run_make -O dep-test2
+$FGREP 'BEG: three.z :END' stdout
+
+./configure two=2
+
+run_make -O dep-test1
+$FGREP 'BEG: two.z somethingelse.a :END' stdout
+
+run_make -O dep-test2
+$FGREP 'BEG: two.z somethingelse.a :END' stdout
+
+:
diff --git a/t/cond35.sh b/t/cond35.sh
new file mode 100644
index 000000000..bfac89ec5
--- /dev/null
+++ b/t/cond35.sh
@@ -0,0 +1,100 @@
+#!/bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check rules output for parser defined conditionally.
+# Report from Roman Fietze.
+
+required='cc lex yacc'
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_CONDITIONAL([CASE_A], [test -z "$case_B"])
+AC_PROG_CC
+AM_PROG_LEX
+AC_PROG_YACC
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+AM_YFLAGS = -d
+
+BUILT_SOURCES = tparse.h
+
+if CASE_A
+bin_PROGRAMS = ta
+ta_SOURCES = ta.c tparse.h tscan.l tparse.y
+ta_LDADD = $(LEXLIB)
+else
+bin_PROGRAMS = tb
+tb_SOURCES = tb.c tparse.h tscan.l tparse.y
+tb_LDADD = $(LEXLIB)
+endif
+
+
+test-ta:
+ test -f ta$(EXEEXT)
+test-tb:
+ test -f tb$(EXEEXT)
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+$FGREP 'tparse.h' Makefile.in # For debugging.
+test $($FGREP -c 'tparse.h:' Makefile.in) -eq 1
+
+cat > tscan.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+%%
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+ return 1;
+}
+END
+
+cat > tparse.y << 'END'
+%{
+void yyerror (char *s) {}
+%}
+%token EOF
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' EOF {};
+END
+
+cat > ta.c << 'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+cp ta.c tb.c
+
+./configure
+$MAKE
+$MAKE test-ta
+
+./configure case_B=yes
+$MAKE
+$MAKE test-tb
+
+:
diff --git a/t/cond36.sh b/t/cond36.sh
new file mode 100644
index 000000000..09e39690d
--- /dev/null
+++ b/t/cond36.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check rules output for parser defined conditionally.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_CONDITIONAL([CASE_A], [test -z "$case_B"])
+AC_PROG_CC
+AM_PROG_LEX
+AC_PROG_YACC
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+AM_YFLAGS = -d
+
+BUILT_SOURCES = tparse.h
+
+if CASE_A
+bin_PROGRAMS = ta
+ta_SOURCES = ta.c tparse.h tscan.l tparse.y
+ta_LDADD = $(LEXLIB)
+else
+bin_PROGRAMS = tb
+tb_SOURCES = tb.c tparse.h tscan.l tparse.y
+tb_LDADD = $(LEXLIB)
+tparse.h: tparce.c
+ echo whatever
+endif
+EOF
+
+$ACLOCAL
+
+# Presently Automake doesn't fully support partially overriden rules
+# and should complain.
+AUTOMAKE_fails --add-missing
+grep 'tparse\.h.*already defined' stderr
+$AUTOMAKE -Wno-error
+
+# Still and all, it should generate two rules.
+$FGREP 'tparse.h' Makefile.in # For debugging.
+test $($FGREP -c 'tparse.h:' Makefile.in) -eq 2
+$FGREP '@CASE_A_TRUE@tparse.h:' Makefile.in
+$FGREP '@CASE_A_FALSE@tparse.h:' Makefile.in
+
+:
diff --git a/t/cond37.sh b/t/cond37.sh
new file mode 100644
index 000000000..96587aa01
--- /dev/null
+++ b/t/cond37.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check conditional local rules.
+# Report from Simon Josefsson.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_CONDITIONAL([CASE_A], [test -n "$case_A"])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+if CASE_A
+check-local:
+ @echo GrepMe1
+else
+install-data-local:
+ @echo GrepMe2
+endif
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+run_make -O check
+grep GrepMe1 stdout && exit 1
+run_make -O install
+grep GrepMe2 stdout
+
+./configure case_A=1
+run_make -O check
+grep GrepMe1 stdout
+run_make -O install
+grep GrepMe2 stdout && exit 1
+
+:
diff --git a/t/cond38.sh b/t/cond38.sh
new file mode 100644
index 000000000..2e212ff62
--- /dev/null
+++ b/t/cond38.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check conditional variable ordering.
+# Report from Ed Hartnett.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_CONDITIONAL([CASE_A], :)
+AM_CONDITIONAL([CASE_B], :)
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+SUBDIRS = a
+if CASE_A
+SUBDIRS += b
+endif
+SUBDIRS += c
+if CASE_A
+SUBDIRS += d
+if CASE_B
+SUBDIRS += e
+endif
+SUBDIRS += f
+endif
+SUBDIRS += g
+if CASE_B
+SUBDIRS += h
+endif
+if CASE_B
+SUBDIRS += iXYZ
+SUBDIRS += jZYX
+endif
+
+.PHONY: test
+test:
+ is $(SUBDIRS) == a b c d e f g h iXYZ jZYX
+EOF
+
+mkdir a b c d e f g h iXYZ jZYX
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+# Make sure no extra variable was created for the last 3 items.
+grep 'append.*=.* h iXYZ jZYX' Makefile
+# Check good ordering.
+$MAKE test
+
+:
diff --git a/t/cond39.sh b/t/cond39.sh
new file mode 100644
index 000000000..57523bbc6
--- /dev/null
+++ b/t/cond39.sh
@@ -0,0 +1,105 @@
+#!/bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Build either as CONFIG_FILE or as PROGRAM.
+
+required=cc
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AM_CONDITIONAL([COND], [test "$COND" = true])
+AM_COND_IF([COND], [],
+ [AC_CONFIG_FILES([prog1], [chmod 755 prog1])
+ AC_CONFIG_FILES([sub/prog2], [chmod 755 sub/prog2])])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+SUBDIRS = sub
+if COND
+bin_PROGRAMS = prog1
+prog1_SOURCES = prog.c
+else
+bin_SCRIPTS = prog1
+CLEANFILES = prog1
+endif
+
+sure-exist:
+ test -f prog1 || test -f prog1$(EXEEXT)
+ test -f sub/prog2 || test -f sub/prog2$(EXEEXT)
+
+sure-not-exist:
+ test ! -f prog1 && test ! -f prog1$(EXEEXT)
+ test ! -f sub/prog2 && test ! -f sub/prog2$(EXEEXT)
+END
+
+cat >sub/Makefile.am <<'END'
+if COND
+bin_PROGRAMS = prog2
+prog2_SOURCES = prog.c
+else
+bin_SCRIPTS = prog2
+CLEANFILES = prog2
+endif
+END
+
+cat >prog.c <<'END'
+int main () { return 42; }
+END
+
+cat >prog1.in <<'END'
+#! /bin/sh
+bindir='@bindir@'
+echo "hi, this is $0, and bindir is $bindir"
+END
+
+cp prog.c sub
+cp prog1.in sub/prog2.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure COND=true
+run_make -E
+grep 'overriding commands' stderr && exit 1
+$MAKE sure-exist
+./prog1 && exit 1
+./sub/prog2 && exit 1
+$MAKE clean
+$MAKE sure-not-exist
+$MAKE
+$MAKE sure-exist
+./prog1 && exit 1
+./sub/prog2 && exit 1
+$MAKE distclean
+
+./configure COND=false
+run_make -E
+grep 'overriding commands' stderr && exit 1
+./prog1
+./sub/prog2
+$MAKE clean
+$MAKE sure-not-exist
+$MAKE
+./prog1
+./sub/prog2
+
+:
diff --git a/t/cond4.sh b/t/cond4.sh
new file mode 100644
index 000000000..b37377249
--- /dev/null
+++ b/t/cond4.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another sources-in-conditional test. Report from Tim Goodwin.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([CC], [false])
+AC_SUBST([OBJEXT], [o])
+AM_CONDITIONAL([ONE], [test "x$CONDITION1" = "xtrue"])
+AM_CONDITIONAL([TWO], [test "x$CONDITION2" = "xtrue"])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = targ
+
+if ONE
+OPT1 = one.c
+endif
+
+if TWO
+OPT2 = two.c
+endif
+
+targ_SOURCES = main.c $(OPT1) $(OPT2)
+
+.PHONY: test
+test:
+ is $(exp) == $(targ_OBJECTS)
+END
+
+$ACLOCAL
+$AUTOMAKE -i
+
+# We should not output useless definitions.
+grep '^@ONE_FALSE@' Makefile.in && exit 1
+grep '^@TWO_FALSE@' Makefile.in && exit 1
+
+$AUTOCONF
+
+CONDITION1=true CONDITION2=true ./configure
+$MAKE test exp='main.o one.o two.o'
+CONDITION1=true CONDITION2=false ./configure
+$MAKE test exp='main.o one.o'
+CONDITION1=false CONDITION2=true ./configure
+$MAKE test exp='main.o two.o'
+CONDITION1=false CONDITION2=false ./configure
+$MAKE test exp='main.o'
+
+:
diff --git a/t/cond40.sh b/t/cond40.sh
new file mode 100644
index 000000000..dd737c513
--- /dev/null
+++ b/t/cond40.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test AM_COND_IF.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_DEFUN([FOO],
+ [AC_CONFIG_FILES([$1])])
+
+AM_CONDITIONAL([COND], [test "$cond" = yes])
+# Next lines should not cause a shell syntax error.
+AM_COND_IF([COND])
+AM_COND_IF([COND],
+ [AC_SUBST([BAR])])
+AM_COND_IF([COND],
+ [AC_CONFIG_FILES([file1])])
+
+# Things should work even at a time when the shell expressions
+# for the conditional are not valid any more.
+ok=$cond1
+AM_CONDITIONAL([COND1], [test "$ok" = yes])
+ok=$cond2
+AM_CONDITIONAL([COND2], [test "$ok" = yes])
+ok=$cond3
+AM_CONDITIONAL([COND3], [test "$ok" = yes])
+
+AM_COND_IF([COND1],
+ [AM_COND_IF([COND2], [FOO([file2])],
+ [AM_COND_IF([COND3],
+ [FOO([file3])])])])
+
+AC_OUTPUT
+END
+
+: >Makefile.am
+: >file1.in
+: >file2.in
+: >file3.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure cond=yes cond1=yes cond2=no cond3=yes
+test -f file1
+test ! -e file2
+test -f file3
+rm -f file1 file3
+$MAKE file1 file3
+$MAKE file2 && exit 1
+test -f file1
+test ! -e file2
+test -f file3
+$MAKE distclean
+
+./configure cond=no cond1=yes cond2=yes
+test ! -e file1
+test -f file2
+test ! -e file3
+rm -f file2
+$MAKE file1 && exit 1
+$MAKE file2
+$MAKE file3 && exit 1
+test ! -e file1
+test -f file2
+test ! -e file3
+
+:
diff --git a/t/cond41.sh b/t/cond41.sh
new file mode 100644
index 000000000..00a605eb1
--- /dev/null
+++ b/t/cond41.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# AM_COND_IF with an undefined condition should fail.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_COND_IF([BAD_COND], [AC_CONFIG_FILES([file1])])
+AC_OUTPUT
+END
+
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep '^configure\.ac:4:.*AM_COND_IF.* no such condition.*BAD_COND' stderr
+
+:
diff --git a/t/cond42.sh b/t/cond42.sh
new file mode 100644
index 000000000..0ac8e57f3
--- /dev/null
+++ b/t/cond42.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+nfig
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure an error with inconsistent state of conditionals in configure.ac.
+# This shouldn't happen with user input, as _AM_COND_* are not documented,
+# but better to be safe.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_CONDITIONAL([COND], [:])
+# The next line is needed so that cond-if.m4 is pulled in.
+AM_COND_IF([COND])
+_AM_COND_IF([COND])
+AC_OUTPUT
+END
+
+edit_configure_ac ()
+{
+ sed "$@" < configure.ac >configure.tmp
+ mv -f configure.tmp configure.ac
+ rm -rf autom4te*.cache
+}
+
+: >Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^configure\.ac:8:.* condition stack' stderr
+
+edit_configure_ac 's/_AM_COND_IF/_AM_COND_ELSE/'
+AUTOMAKE_fails
+grep '^configure\.ac:7:.* else without if' stderr
+
+edit_configure_ac 's/_AM_COND_ELSE/_AM_COND_ENDIF/'
+AUTOMAKE_fails
+grep '^configure\.ac:7:.* endif without if' stderr
+
+edit_configure_ac 's/\(_AM_COND_ENDIF\).*/_AM_COND_IF\
+_AM_COND_ENDIF/'
+AUTOMAKE_fails
+grep '^configure\.ac:7:.* not enough arguments.* _AM_COND_IF' stderr
+grep '^configure\.ac:8:.* not enough arguments.* _AM_COND_ENDIF' stderr
+test 2 -eq $($FGREP -c 'not enough arguments' stderr)
+
+:
diff --git a/t/cond43.sh b/t/cond43.sh
new file mode 100644
index 000000000..0eb188d90
--- /dev/null
+++ b/t/cond43.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure an error with underquoted usage of AM_COND_IF in configure.ac.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_CONDITIONAL([COND1], [:])
+AM_CONDITIONAL([COND2], [:])
+AM_COND_IF([COND1],
+ AM_COND_IF([COND2], [:])
+)
+AC_OUTPUT
+END
+
+: >Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+$EGREP '^configure\.ac:7:.* missing m4 quoting.*macro depth 2( |$)' stderr
+
+sed '/.AM_COND_IF/{
+ s/^/[/
+ s/$/]/
+ }' < configure.ac > configure.tmp
+mv -f configure.tmp configure.ac
+rm -rf autom4te*.cache
+$AUTOMAKE
+
+:
diff --git a/t/cond44.sh b/t/cond44.sh
new file mode 100644
index 000000000..2cea626dd
--- /dev/null
+++ b/t/cond44.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that redefinitions of AC_SUBST'ed AM_SUBST_NOTMAKE'd variables
+# are not diagnosed. See 'cond23.sh'.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AM_CONDITIONAL([COND], [true])
+AM_SUBST_NOTMAKE([libdir])
+AC_OUTPUT
+EOF
+
+cat >Makefile.am <<EOF
+if COND
+libdir = mumble
+endif
+EOF
+
+$ACLOCAL
+AUTOMAKE_run
+grep 'libdir was already defined' stderr && exit 1
+grep '^libdir = ' Makefile.in && exit 1
+exit 0
diff --git a/t/cond45.sh b/t/cond45.sh
new file mode 100644
index 000000000..e51d346a1
--- /dev/null
+++ b/t/cond45.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that redefinitions of AC_SUBST'ed AM_SUBST_NOTMAKE'd variables
+# are not diagnosed. See 'cond24.sh'.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_SUBST([foo], [bar])
+AM_SUBST_NOTMAKE([foo])
+AM_CONDITIONAL([COND], [true])
+AC_OUTPUT
+EOF
+
+cat >Makefile.am <<EOF
+if COND
+foo = baz
+endif
+EOF
+
+$ACLOCAL
+AUTOMAKE_run
+grep 'foo was already defined' stderr && exit 1
+grep '^foo =' Makefile.in && exit 1
+exit 0
diff --git a/t/cond46.sh b/t/cond46.sh
new file mode 100644
index 000000000..de54c969e
--- /dev/null
+++ b/t/cond46.sh
@@ -0,0 +1,112 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure the right condition is listed after 'else' and 'endif'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([USE_A], [test x = y])
+AM_CONDITIONAL([USE_B], [test x = z])
+AC_OUTPUT
+END
+
+notcompat="incompatible with current conditional"
+
+$ACLOCAL
+
+cat > Makefile.am << 'END'
+if USE_A
+endif !USE_A
+END
+
+AUTOMAKE_fails
+grep "^Makefile\\.am:2:.*endif.*!USE_A.*$notcompat.*[^!]USE_A" stderr
+
+cat > Makefile.am << 'END'
+if USE_A
+endif USE_B
+END
+
+AUTOMAKE_fails
+grep "^Makefile\\.am:2:.*endif.*[^!]USE_B.*$notcompat.*[^!]USE_A" stderr
+
+cat > Makefile.am << 'END'
+if USE_A
+else
+endif USE_A
+END
+
+AUTOMAKE_fails
+grep "^Makefile\\.am:3:.*endif.*[^!]USE_A.*$notcompat.*USE_A" stderr
+
+cat > Makefile.am << 'END'
+if USE_A
+else
+endif !USE_A
+END
+
+$AUTOMAKE
+
+cat > Makefile.am << 'END'
+if USE_A
+if USE_B
+else
+endif !USE_A
+endif
+END
+
+AUTOMAKE_fails
+grep "^Makefile\\.am:4:.*endif.*!USE_A.*$notcompat.*USE_B" stderr
+
+cat > Makefile.am << 'END'
+if USE_A
+else USE_A
+endif
+END
+
+AUTOMAKE_fails
+grep "^Makefile\\.am:2:.*else.*[^!]USE_A.*$notcompat.*[^!]USE_A" stderr
+
+cat > Makefile.am << 'END'
+if USE_A
+else !USE_A
+endif
+END
+
+$AUTOMAKE
+
+cat > Makefile.am << 'END'
+if USE_A
+else USE_B
+endif
+END
+
+AUTOMAKE_fails
+grep "^Makefile\\.am:2:.*else.*[^!]USE_B.*$notcompat.*[^!]USE_A" stderr
+
+cat > Makefile.am << 'END'
+if USE_A
+if USE_B
+else USE_A
+endif
+endif
+END
+
+AUTOMAKE_fails
+grep "^Makefile\\.am:3:.*else.*[^!]USE_A.*$notcompat.*[^!]USE_B" stderr
+
+:
diff --git a/t/cond5.sh b/t/cond5.sh
new file mode 100644
index 000000000..73cd39ebf
--- /dev/null
+++ b/t/cond5.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Yet another sources-in-conditional test. Report from Tim Goodwin.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([ONE], [true])
+AM_CONDITIONAL([TWO], [false])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = targ
+
+if ONE
+OPT_SRC = one.c
+endif
+
+if TWO
+OPT_SRC = $(OPT_SRC) two.c
+endif
+
+targ_SOURCES = main.c $(OPT_SRC)
+END
+
+# The bug is that automake hangs. So we give it an appropriate grace
+# time, then kill it if necessary.
+$ACLOCAL
+$AUTOMAKE 2>stderr &
+pid=$!
+
+# MSYS bash seems to have a bug in kill, so don't try to kill too soon.
+# The extra quoting avoids a maintainer-check failure.
+sleep '2'
+
+# Make at most 30 tries, one every 10 seconds (= 300 seconds = 5 min).
+try=1
+while test $try -le 30; do
+ if kill -0 $pid; then
+ : process $pid is still alive, wait and retry
+ sleep '10'
+ try=$(($try + 1))
+ else
+ cat stderr >&2
+ # Automake must fail with a proper error message.
+ grep 'variable.*OPT_SRC.*recursively defined' stderr
+ exit 0
+ fi
+done
+# The automake process probably hung. Kill it, and exit with failure.
+echo "$me: Automake process $pid hung"
+kill $pid
+exit 1
diff --git a/t/cond6.sh b/t/cond6.sh
new file mode 100644
index 000000000..834aa32fd
--- /dev/null
+++ b/t/cond6.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for an odd conditional bug. Report from Matt Leach.
+
+. test-init.sh
+
+echo 'AM_CONDITIONAL([FOO], [true])' >> configure.ac
+
+cat > Makefile.am << 'END'
+if FOO
+
+helpdir = $(prefix)/Help
+# The continuation line below must start with a Tab to see the bug.
+help_DATA = a b c d e \
+ f g h
+
+else
+
+helpdir = $(prefix)/help
+help_DATA = foo
+
+endif
+
+a b c d e f g h:
+ touch $@
+
+.PHONY: test
+test:
+ is $(help_DATA) == a b c d e f g h
+END
+
+
+# Older versions of this test checked that automake could process the above
+# Makefile.am even with no AC_OUTPUT in configure. So continue to do this
+# check, for completeness.
+$ACLOCAL
+$AUTOMAKE
+
+rm -rf autom4te*.cache
+
+echo AC_OUTPUT >> configure.ac
+touch aclocal.m4 # Avoid unnecessary firing the remake rules.
+$AUTOCONF
+$AUTOMAKE Makefile
+
+./configure --prefix="$(pwd)/_inst"
+
+$MAKE test
+
+$MAKE install
+for x in a b c d e f g h; do
+ test -f _inst/Help/$x
+done
+
+:
diff --git a/t/cond7.sh b/t/cond7.sh
new file mode 100644
index 000000000..4accccd68
--- /dev/null
+++ b/t/cond7.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for an odd conditional bug. Report from Pavel Roskin.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+compat=yes
+AM_CONDITIONAL([Compatible], [test x$compat = xyes])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if Compatible
+abdir = none
+ab_HEADERS = \
+ minus.h
+endif
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^[^#].*002' Makefile.in && exit 1
+exit 0
diff --git a/t/cond8.sh b/t/cond8.sh
new file mode 100644
index 000000000..76353f785
--- /dev/null
+++ b/t/cond8.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure _PROGRAMS conditionals can be written in a useful
+# way.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([X], [test "$x" = yes])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if X
+bin_PROGRAMS = x y
+else
+noinst_PROGRAMS = x y
+endif
+
+.PHONY: get-built get-install not-install
+get-built:
+ test -f x.$(OBJEXT)
+ test -f y.$(OBJEXT)
+ test -f x$(EXEEXT)
+ test -f y$(EXEEXT)
+get-installed:
+ test -f $(bindir)/x$(EXEEXT)
+ test -f $(bindir)/y$(EXEEXT)
+not-installed:
+ if find $(prefix) -type f | grep .; then exit 1; else :; fi
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+cat > x.c <<'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+cp x.c y.c
+
+instdir=$(pwd)/_inst || fatal_ "cannot get current directory"
+
+# Skip the rest of the test in case of e.g. missing C compiler.
+./configure --prefix="$instdir" x=yes || exit $?
+$MAKE install
+$MAKE get-built
+$MAKE get-installed
+
+$MAKE distclean
+rm -rf _inst
+
+./configure --prefix="$instdir" x=no
+$MAKE install
+$MAKE get-built
+$MAKE not-installed
+
+:
diff --git a/t/cond9.sh b/t/cond9.sh
new file mode 100644
index 000000000..1c5fa2a5c
--- /dev/null
+++ b/t/cond9.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in conditionals. From Raja R Harinath.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([WRONG], [test x = y])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if WRONG
+this=
+else
+this=is_something_interesting
+endif
+
+.PHONY: test-this
+test-this:
+ test '$(this)' = is_something_interesting
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE test-this
+
+:
diff --git a/t/condd.sh b/t/condd.sh
new file mode 100644
index 000000000..64e874632
--- /dev/null
+++ b/t/condd.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in conditionals.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+dnl Define a macro with the same name as the conditional to exhibit
+dnl any underquoted bug.
+AC_DEFUN([COND1], ["some'meaningless;characters`])
+AM_CONDITIONAL([COND1], [false])
+AC_CONFIG_FILES([foo/Makefile])
+AC_CONFIG_FILES([bar/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+CC = false
+
+SUBDIRS = foo
+if COND1
+SUBDIRS += bar
+endif
+
+# Small example from the manual.
+bin_PROGRAMS = hello
+hello_SOURCES = hello-common.c
+if COND1
+hello_SOURCES += hello-cond1.c
+else
+hello_SOURCES += hello-generic.c
+endif
+
+.PHONY: test
+test: distdir
+ test -f $(distdir)/foo/Makefile.am
+ test -f $(distdir)/bar/Makefile.am
+ test -f $(distdir)/hello-common.c
+ test -f $(distdir)/hello-cond1.c
+ test -f $(distdir)/hello-generic.c
+END
+
+mkdir foo bar
+
+: > foo/Makefile.am
+: > bar/Makefile.am
+: > hello-common.c
+: > hello-cond1.c
+: > hello-generic.c
+
+$ACLOCAL
+$AUTOCONF
+grep "meaningless;characters" configure && exit 1
+$AUTOMAKE
+./configure
+$MAKE test
+
+:
diff --git a/t/condhook.sh b/t/condhook.sh
new file mode 100644
index 000000000..2e817c8eb
--- /dev/null
+++ b/t/condhook.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test install when a conditional install-*-hook is not defined.
+# Keep this in sync with sister test 'condhook2.sh'.
+# Report by Nik A. Melchior (PR/428).
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([TEST], [false])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+sysconf_DATA = mumble
+if TEST
+install-data-hook:
+ : > $(top_srcdir)/bad
+endif
+END
+
+: > mumble
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure --prefix "$(pwd)/inst"
+
+$MAKE install
+test -f inst/etc/mumble
+test ! -e bad
+
+:
diff --git a/t/condhook2.sh b/t/condhook2.sh
new file mode 100644
index 000000000..4901897c4
--- /dev/null
+++ b/t/condhook2.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test install when a conditional install-*-hook is defined.
+# Keep this in sync with sister test 'condhook.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([TEST], [true])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+sysconf_DATA = mumble
+if TEST
+install-data-hook:
+ : > $(top_srcdir)/good
+endif
+END
+
+: > mumble
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure --prefix "$(pwd)/inst"
+
+$MAKE install
+test -f inst/etc/mumble
+test -f good
+
+:
diff --git a/t/condinc.sh b/t/condinc.sh
new file mode 100644
index 000000000..ba2d8636e
--- /dev/null
+++ b/t/condinc.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure a conditional include statement is handled properly.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([TOBE], [false])
+END
+
+cat > Makefile.am << 'END'
+if TOBE
+include adjunct
+endif
+END
+
+cat > adjunct << 'END'
+target: dependency
+ rule
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^target:' Makefile.in && exit 1
+grep '^@TOBE_TRUE@target:' Makefile.in
+
+:
diff --git a/t/condinc2.sh b/t/condinc2.sh
new file mode 100644
index 000000000..5983d262d
--- /dev/null
+++ b/t/condinc2.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another test of conditional include statements.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([TOBE], [false])
+END
+
+cat > Makefile.am << 'END'
+if TOBE
+include adjunct
+endif
+END
+
+cat > adjunct << 'END'
+target: dependency
+ rule
+endif
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'adjunct:3: error: too many conditionals closed' stderr
+
+cat > adjunct << 'END'
+if TOBE
+target: dependency
+ rule
+END
+
+AUTOMAKE_fails
+grep 'unterminated conditionals' stderr
+
+cat > adjunct << 'END'
+if TOBE
+target: dependency
+ rule
+endif
+END
+
+$AUTOMAKE
+
+:
diff --git a/t/condlib.sh b/t/condlib.sh
new file mode 100644
index 000000000..1a6966757
--- /dev/null
+++ b/t/condlib.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug with conditional library.
+# From Harlan Stenn.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_RANLIB
+AM_MAINTAINER_MODE
+AM_PROG_AR
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = @LIBRSAREF@
+EXTRA_LIBRARIES = librsaref.a
+
+nodist_librsaref_a_SOURCES = desc.c digit.c
+
+BUILT_SOURCES = $(nodist_librsaref_a_SOURCES)
+END
+
+: > ar-lib
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP librsaref.a.c Makefile.in && exit 1
+exit 0
diff --git a/t/condman2.sh b/t/condman2.sh
new file mode 100644
index 000000000..7229b588d
--- /dev/null
+++ b/t/condman2.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure appropriate man install targets generated in all cases.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+man_MANS = foo.1 foo.2
+man5_MANS = foo.5
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^install-man1:' Makefile.in
+grep '^install-man2:' Makefile.in
+grep '^install-man5:' Makefile.in
+
+:
diff --git a/t/condman3.sh b/t/condman3.sh
new file mode 100644
index 000000000..59d33266e
--- /dev/null
+++ b/t/condman3.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure conditionals work with man pages.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND], [test x"$FOO" = x"true"])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if COND
+man_MANS = foo.1
+man4_MANS = 6.man
+else
+man_MANS = bar.2 baz.1
+man5_MANS = zap.5
+endif
+
+.PHONY: test1 test2
+test1:
+ find $(mandir) ;: For debugging.
+ test -f $(mandir)/man1/foo.1
+ test -f $(mandir)/man4/6.4
+ test ! -f $(mandir)/man2/bar.2
+ test ! -f $(mandir)/man1/baz.1
+ test ! -f $(mandir)/man5/zap.5
+test2:
+ find $(mandir) ;: For debugging.
+ test -f $(mandir)/man2/bar.2
+ test -f $(mandir)/man1/baz.1
+ test -f $(mandir)/man5/zap.5
+ test ! -f $(mandir)/man1/foo.1
+ test ! -f $(mandir)/man4/6.4
+ test ! -f $(mandir)/man4/6.man
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+$EGREP 'MANS|\.([123456789]|man)' Makefile.in # For debugging.
+
+mkdir build
+cd build
+../configure FOO=true --prefix="$(pwd)/_inst"
+$EGREP 'MANS|\.([123456789]|man)' Makefile # For debugging.
+touch foo.1 6.man
+$MAKE install
+$MAKE test1
+
+cd ..
+./configure FOO=false --prefix="$(pwd)/_inst"
+$EGREP 'MANS|\.([123456789]|man)' Makefile # For debugging.
+touch bar.2 baz.1 zap.5
+$MAKE install
+$MAKE test2
+
+:
diff --git a/t/confdeps.sh b/t/confdeps.sh
new file mode 100644
index 000000000..dde90b41e
--- /dev/null
+++ b/t/confdeps.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that config* files are properly regenerated.
+
+. test-init.sh
+
+echo "FOO = foo" > Makefile.am
+
+$ACLOCAL
+
+echo "$me: Generated by aclocal ..."
+$AUTOMAKE
+grep '^\$(ACLOCAL_M4):' Makefile.in
+
+echo "$me: Not generated by aclocal ..."
+# Pretend it is not from aclocal (remove the signature),
+# but keep it correct, i.e., with AM_INIT_AUTOMAKE etc.
+sed -n '3,$p' aclocal.m4 >aclocal.m4t
+mv -f aclocal.m4t aclocal.m4
+$AUTOMAKE
+grep '^\$(ACLOCAL_M4):' Makefile.in && exit 1
+
+:
diff --git a/t/conff.sh b/t/conff.sh
new file mode 100644
index 000000000..3512a9025
--- /dev/null
+++ b/t/conff.sh
@@ -0,0 +1,88 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure rebuild rules work even when AC_CONFIG_FILES uses colons.
+# Report from Alexander Turbov.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([bar/Makefile:bar/Makefile.in:Makefile.bot])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = bar
+EXTRA_DIST = Makefile.bot
+END
+
+mkdir bar
+cat > bar/Makefile.am << 'END'
+top-rule:
+ @echo 'top rule'
+END
+
+cat > Makefile.bot << 'END'
+bot-rule:
+ @echo 'bot rule'
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
+
+cd bar
+run_make -O top-rule
+grep 'top rule' stdout
+run_make -O bot-rule
+grep 'bot rule' stdout
+cd ..
+
+$sleep
+
+cat > bar/Makefile.am << 'END'
+top-rule:
+ @echo 'top2 rule'
+END
+$MAKE
+
+cd bar
+run_make -O top-rule
+grep 'top2 rule' stdout
+run_make -O bot-rule
+grep 'bot rule' stdout
+cd ..
+
+$sleep
+
+cat > Makefile.bot << 'END'
+bot-rule:
+ @echo 'bot2 rule'
+END
+$MAKE
+
+cd bar
+run_make -O top-rule
+grep 'top2 rule' stdout
+run_make -O bot-rule
+grep 'bot2 rule' stdout
+cd ..
+
+$MAKE distcheck
+
+:
diff --git a/t/conff2.sh b/t/conff2.sh
new file mode 100644
index 000000000..6aff1eb38
--- /dev/null
+++ b/t/conff2.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure empty calls to AC_CONFIG_FILES or AC_CONFIG_HEADERS are diagnosed.
+
+. test-init.sh
+
+# We avoid using configure.ac stub initialized by our testsuite setup, as
+# we need to keep track of line numbers (to grep for error messages).
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES ([oops])
+AC_CONFIG_HEADERS
+AC_OUTPUT
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'configure\.ac:3:.* arguments .*AC_CONFIG_FILES' stderr
+grep 'configure\.ac:4:.* arguments .*AC_CONFIG_HEADERS' stderr
+
+:
diff --git a/t/conffile-leading-dot.sh b/t/conffile-leading-dot.sh
new file mode 100644
index 000000000..e6eadbe01
--- /dev/null
+++ b/t/conffile-leading-dot.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automake must complain if AC_CONFIG_FILES is passed something starting
+# with a dot (like "./Makefile"), since the remake rules might be subtly
+# broken in that case.
+
+required=GNUmake
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([./Makefile])
+AC_CONFIG_FILES([./foo:a.in:b.in:c.in])
+AC_OUTPUT
+END
+
+touch a.in b.in c.in Makefile.am
+
+$ACLOCAL
+
+AUTOMAKE_fails -Wnone -Wunsupported
+grep "^configure\.ac:3:.*'\\./Makefile'" stderr
+grep "^configure\.ac:3:.* omit leading '\\./'" stderr
+grep "^configure\.ac:3:.*remake rules might be subtly broken" stderr
+grep "^configure\.ac:4:.*'\\./foo'" stderr
+grep "^configure\.ac:4:.* omit leading '\\./'" stderr
+grep "^configure\.ac:4:.*remake rules might be subtly broken" stderr
+
+# Check that our warning was actually justified.
+sed 's/^AM_INIT_AUTOMAKE/&([-Wall -Wno-unsupported])/' <configure.ac >t
+mv -f t configure.ac
+rm -rf autom4te*.cache
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -Wall -Wno-unsupported
+./configure
+$MAKE
+$sleep
+touch Makefile.am
+# Check that remake rules do truly break -- otherwise automake is
+# giving a bogus warning.
+run_make -e FAIL -E
+grep "config\\.status:.*invalid argument.*Makefile" stderr
+
+:
diff --git a/t/confh-subdir-clean.sh b/t/confh-subdir-clean.sh
new file mode 100644
index 000000000..81e1b85bb
--- /dev/null
+++ b/t/confh-subdir-clean.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure config headers in subdirectories are cleaned.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_HEADERS([sub/config.h:sub/config.hin])
+AC_OUTPUT
+END
+
+touch Makefile.am
+mkdir sub
+
+$ACLOCAL
+$AUTOCONF
+touch sub/config.hin
+$AUTOMAKE
+./configure
+test -f sub/stamp-h1
+$MAKE clean
+test -f sub/stamp-h1
+$MAKE distclean
+test -f sub/stamp-h1 && exit 1
+
+:
diff --git a/t/confh.sh b/t/confh.sh
new file mode 100644
index 000000000..8400c2120
--- /dev/null
+++ b/t/confh.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure config.h works in a subdir.
+# Report from Alexandre Oliva.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_HEADERS([include/config.h])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+.PHONY: test1 test2
+test1:
+ @echo DIST_COMMON = $(DIST_COMMON)
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]acconfig\.h '
+test2: distdir
+ ls -l $(distdir)/*
+ test -f $(distdir)/acconfig.h
+check-local: test1 test2
+END
+
+mkdir include
+: > include/config.h.in
+: > acconfig.h
+
+# The test used to fail if 'include/Makefile.am' was created (!)
+: > include/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE
+
+./configure
+
+$MAKE test1
+$MAKE test2
+$MAKE distcheck
+
+# Make sure re-running automake in a different way generates same
+# Makefile.in.
+mv Makefile.in Makefile.sav
+$ACLOCAL
+$AUTOMAKE Makefile
+diff Makefile.sav Makefile.in
+
+:
diff --git a/t/confh4.sh b/t/confh4.sh
new file mode 100644
index 000000000..2a2f4c626
--- /dev/null
+++ b/t/confh4.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 34.
+# > Description:
+# Automake fails to add -I option to include configuration
+# header indicated like AM_CONFIG_HEADER(magick/config.h)
+# > How-To-Repeat:
+# Use AM_CONFIG_HEADER(subdir/config.h) to place configuration
+# header in subdirectory and observe that it is not included.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([include/Makefile])
+AC_CONFIG_HEADERS([include/config.h])
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c
+END
+
+mkdir include
+: > include/Makefile.am
+: > include/config.h.in
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^ *DEFAULT_INCLUDES *=.* -I\$(top_builddir)/include' Makefile.in
+
+:
diff --git a/t/confh5.sh b/t/confh5.sh
new file mode 100644
index 000000000..74e2207b5
--- /dev/null
+++ b/t/confh5.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we do not distribute header sources when they are built.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([FOO], [NameToBeGrepped])
+AC_CONFIG_FILES([include/config.h.in])
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_HEADERS([include/config.h])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+.PHONY: test
+test: distdir
+ test -f $(distdir)/config.h.in
+ test -f $(distdir)/include/config.h.in.in
+ test ! -f $(distdir)/include/config.h.in
+ test ! -r $(distdir)/include/config.h.in
+END
+
+mkdir include
+: > include/config.h.in.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE
+
+./configure
+$MAKE
+
+$sleep
+echo '#undef @FOO@' > include/config.h.in.in
+$MAKE include/config.h
+# Don't try to be too strict in this grepping, since the substitution
+# is done by config.status, and we don't have too much control on it.
+grep '/\*.*#undef.*NameToBeGrepped' include/config.h
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/confh6.sh b/t/confh6.sh
new file mode 100644
index 000000000..4cf2b296c
--- /dev/null
+++ b/t/confh6.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure config.h rule made even if it is in a subdir. The
+# idea is that if config.h is in a subdir, and there is no Makefile in
+# that subdir, then we want to build config.h as the top level.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_HEADERS([subdir/config.h])
+AC_OUTPUT
+END
+
+: > Makefile.am
+mkdir subdir
+: > subdir/config.h.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
+
+$sleep
+echo '#define gRePmE' > subdir/config.h.in
+$MAKE subdir/config.h
+$FGREP gRePmE subdir/config.h
+
+$MAKE distcheck
+
+:
diff --git a/t/confh7.sh b/t/confh7.sh
new file mode 100644
index 000000000..3a5a9a03a
--- /dev/null
+++ b/t/confh7.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure several config headers are allowed.
+# See also sister "semantic" test 'confh8.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_HEADERS([config.h two.h])
+END
+
+: > Makefile.am
+
+: > config.h.in
+: > two.h.in
+
+$ACLOCAL
+$AUTOMAKE
+
+# Try again with more macros.
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+$ACLOCAL --force
+$AUTOMAKE
+
+:
diff --git a/t/confh8.sh b/t/confh8.sh
new file mode 100644
index 000000000..9891bc97d
--- /dev/null
+++ b/t/confh8.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure several config headers are allowed.
+# See also sister "minimalistic" test 'confh7.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_HEADERS([one.h two.h])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+.PHONY: test0 test1 test2
+test0:
+ @echo DIST_COMMON = $(DIST_COMMON)
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]one\.h\.in '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]two\.h\.in '
+ : Processed header files should not be distributed.
+ if echo ' ' $(DIST_COMMON) ' ' | grep '\.h '; then \
+ exit 1; \
+ else \
+ exit 0; \
+ fi
+test1: all
+ test -f one.h
+ test -f two.h
+test2: distdir
+ ls -l $(distdir)/*
+ test -f $(distdir)/one.h.in
+ test -f $(distdir)/two.h.in
+ : Processed header files should not be distributed.
+ test ! -r $(distdir)/one.h
+ test ! -r $(distdir)/two.h
+check-local: test0 test1 test2
+END
+
+: > one.h.in
+: > two.h.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test0
+$MAKE test1
+$MAKE test2
+$MAKE distcheck
+
+:
diff --git a/t/configure.sh b/t/configure.sh
new file mode 100644
index 000000000..5f5924322
--- /dev/null
+++ b/t/configure.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Diagnose if the autoconf input is named configure.in.
+# Diagnose if both configure.in and configure.ac are present, prefer
+# configure.ac.
+
+. test-init.sh
+
+cat >configure.ac <<EOF
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+EOF
+
+cat >configure.in <<EOF
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([an-invalid-automake-option])
+AC_CONFIG_FILES([Makefile])
+EOF
+
+: >Makefile.am
+
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'configure\.ac.*configure\.in.*both present' stderr
+
+$ACLOCAL -Wno-error 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'configure\.ac.*configure\.in.*both present' stderr
+grep 'proceeding.*configure\.ac' stderr
+
+# Ensure we really proceed with configure.ac.
+AUTOMAKE_fails -Werror
+grep 'configure\.ac.*configure\.in.*both present' stderr
+grep 'proceeding.*configure\.ac' stderr
+
+AUTOMAKE_run -Wno-error
+grep 'configure\.ac.*configure\.in.*both present' stderr
+grep 'proceeding.*configure\.ac' stderr
+
+mv -f configure.ac configure.in
+AUTOMAKE_fails
+grep "autoconf input.*'configure.ac', not 'configure.in'" stderr
+
+:
diff --git a/t/confincl.sh b/t/confincl.sh
new file mode 100644
index 000000000..40cd93f94
--- /dev/null
+++ b/t/confincl.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# This tests for a bug reported by Gord Matzigkeit.
+# If config.h is not used, @CONFIG_INCLUDE_SPEC@ should not appear
+# in Makefile.in.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = fred
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP '@CONFIG_INCLUDE_SPEC@' Makefile.in && exit 1
+
+:
diff --git a/t/conflnk.sh b/t/conflnk.sh
new file mode 100644
index 000000000..3ec22addc
--- /dev/null
+++ b/t/conflnk.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure links created by AC_CONFIG_LINKS get removed with
+# 'make distclean'
+
+. test-init.sh
+
+echo 'SUBDIRS = sdir' > Makefile.am
+: > src
+mkdir sdir
+: > sdir/Makefile.am
+: > sdir/src2
+mkdir sdir-no-make
+
+cat >>configure.ac << 'EOF'
+AC_CONFIG_FILES([sdir/Makefile])
+AC_CONFIG_LINKS([dest:src])
+AC_CONFIG_LINKS([dest2:src])
+AC_CONFIG_LINKS([sdir/dest3:src])
+AC_CONFIG_LINKS([dest4:sdir/src2])
+AC_CONFIG_LINKS([sdir/dest5:sdir/src2 sdir-no-make/dest6:src])
+AC_OUTPUT
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure
+
+# Make sure nothing is deleted by 'make clean'
+$MAKE clean
+
+test -r dest
+test -r dest2
+test -r sdir/dest3
+test -r dest4
+test -r sdir/dest5
+test -r sdir-no-make/dest6
+test -f src
+test -f sdir/src2
+
+# Make sure the links are deleted by 'make distclean' and the original files
+# are not.
+$MAKE distclean
+
+test -f src
+test -f sdir/src2
+
+test -r dest && exit 1
+test -r dest2 && exit 1
+test -r sdir/dest3 && exit 1
+test -r dest4 && exit 1
+test -r sdir/dest5 && exit 1
+test -r sdir-no-make/dest6 && exit 1
+
+:
diff --git a/t/conflnk2.sh b/t/conflnk2.sh
new file mode 100644
index 000000000..0a7d43f38
--- /dev/null
+++ b/t/conflnk2.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that sources for links created by AC_CONFIG_LINKS
+# are distributed.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+SUBDIRS = sdir
+.PHONY: test
+test: distdir
+ test -f $(distdir)/src
+ test -f $(distdir)/src2
+ test -f $(distdir)/sdir/src3
+ test -f $(distdir)/sdir-no-make/src4
+ test 2 -gt `find $(distdir)/sdir -type d | wc -l`
+ test 2 -gt `find $(distdir)/sdir-no-make -type d | wc -l`
+ test 4 -gt `find $(distdir) -type d | wc -l`
+END
+
+: > src
+: > src2
+mkdir sdir
+: > sdir/Makefile.am
+: > sdir/src3
+mkdir sdir-no-make
+: > sdir-no-make/src4
+
+cat >>configure.ac << 'EOF'
+AC_CONFIG_FILES([sdir/Makefile])
+AC_CONFIG_LINKS([dest:src])
+AC_CONFIG_LINKS([sdir/dest2:src2 sdir-no-make/dest3:sdir/src3])
+AC_CONFIG_LINKS([sdir/dest4:sdir-no-make/src4])
+AC_OUTPUT
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure
+$MAKE test
+
+:
diff --git a/t/conflnk3.sh b/t/conflnk3.sh
new file mode 100644
index 000000000..9a5e230d5
--- /dev/null
+++ b/t/conflnk3.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that AC_CONFIG_LINKS using a variable source
+# is not broken.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+SUBDIRS = sdir
+.PHONY: test
+test: distdir
+ test ! -r $(distdir)/sdir/dest3
+ test ! -r $(distdir)/sdir/dest2
+ test ! -r $(distdir)/dest3
+ test ! -r $(distdir)/dest2
+ test -f $(distdir)/src2
+## src3 cannot be distributed, Automake knows nothing about it.
+ test ! -r $(distdir)/sdir/src3
+ test ! -r $(distdir)/src3
+END
+
+: > src
+: > src2
+mkdir sdir
+: > sdir/Makefile.am
+: > sdir/src3
+
+cat >>configure.ac << 'EOF'
+AC_CONFIG_FILES([sdir/Makefile])
+my_src_dir=sdir
+my_dest=dest
+AC_CONFIG_LINKS([sdir/dest2:src2 sdir/dest3:$my_src_dir/src3])
+AC_CONFIG_LINKS([$my_dest:src])
+# The following is a link whose source is itself a link.
+AC_CONFIG_LINKS([dest4:sdir/dest2])
+# Some package prefer to compute links.
+cmplink='dest5:src';
+AC_CONFIG_LINKS([$cmplink])
+AC_OUTPUT
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+# $my_src_dir and $my_dest are variables local to configure, they should
+# not appear in Makefile.
+grep my_src_dir Makefile.in && exit 1
+grep my_dest Makefile.in && exit 1
+
+./configure
+test -r sdir/dest2
+test -r sdir/dest3
+test -r dest
+test -r dest4
+test -r dest5
+$MAKE test
+
+$MAKE distclean
+test ! -e sdir/dest2
+test ! -e sdir/dest3
+test -r dest # Should still exist, Automake knows nothing about it.
+test -r dest5 # Ditto.
+rm -f dest dest5
+test ! -e dest4
+
+mkdir build
+cd build
+../configure
+$MAKE test
+
+:
diff --git a/t/conflnk4.sh b/t/conflnk4.sh
new file mode 100644
index 000000000..06b16d60b
--- /dev/null
+++ b/t/conflnk4.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure links to _identical files_ created by AC_CONFIG_LINKS get
+# removed with 'make distclean' only if doing a VPATH build.
+
+. test-init.sh
+
+mkdir nonmk-subdir sdir sdir/mk-subdir
+: > src
+: > sdir/Makefile.am
+: > sdir/src2
+: > nonmk-subdir/src3
+: > sdir/mk-subdir/src4
+
+cat >> Makefile.am <<'EOF'
+SUBDIRS = sdir
+.PHONY: test
+test: distdir
+ test -f $(distdir)/src
+ test -f $(distdir)/sdir/src2
+ test -f $(distdir)/nonmk-subdir/src3
+ test -f $(distdir)/sdir/mk-subdir/src4
+EOF
+
+cat >>configure.ac << 'EOF'
+AC_CONFIG_FILES([sdir/Makefile])
+AC_CONFIG_LINKS([src:src])
+AC_CONFIG_LINKS([sdir/src2:sdir/src2])
+AC_CONFIG_LINKS([nonmk-subdir/src3:nonmk-subdir/src3])
+AC_CONFIG_LINKS([sdir/mk-subdir/src4:sdir/mk-subdir/src4])
+AC_OUTPUT
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+mkdir build
+cd build
+../configure
+
+$MAKE test
+
+# Make sure nothing is deleted by 'make clean'
+$MAKE clean
+
+test -f ../src
+test -f ../sdir/src2
+test -f ../nonmk-subdir/src3
+test -f ../sdir/mk-subdir/src4
+
+# Make sure the links are deleted by 'make distclean' and the original files
+# are not.
+$MAKE distclean
+
+test -f ../src
+test -f ../sdir/src2
+test -f ../nonmk-subdir/src3
+test -f ../sdir/mk-subdir/src4
+
+test -r src && exit 1
+test -r sdir/src2 && exit 1
+test -r nonmk-subdir/src3 && exit 1
+test -r sdir/mk-subdir/src4 && exit 1
+
+cd ..
+./configure
+
+$MAKE test
+
+# Make sure nothing is deleted by 'make distclean'
+$MAKE distclean
+
+test -f src
+test -f sdir/src2
+test -f nonmk-subdir/src3
+test -f sdir/mk-subdir/src4
+
+:
diff --git a/t/confsub.sh b/t/confsub.sh
new file mode 100644
index 000000000..0dab4a026
--- /dev/null
+++ b/t/confsub.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure config.h can be in subdir.
+# Also, make sure config.h is properly rebuilt.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([subdir/Makefile])
+AC_CONFIG_HEADERS([subdir/config.h:subdir/config.hin])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = subdir
+END
+
+mkdir subdir
+cat > subdir/Makefile.am << 'END'
+END
+
+echo 'Before.' > subdir/config.hin
+
+$ACLOCAL
+$AUTOMAKE
+
+# Make sure subdir Makefile.in doesn't itself look in the subdir.
+# One line is allowed though:
+#
+# cd $(top_builddir) && $(SHELL) ./config.status subdir/config.h
+($FGREP 'subdir/config.h' subdir/Makefile.in |
+ $FGREP -v 'cd $(top_builddir)') && exit 1
+
+$AUTOCONF
+./configure
+$FGREP 'Before.' subdir/config.h
+
+$sleep
+echo 'After.' > subdir/config.hin
+$MAKE
+$FGREP 'After.' subdir/config.h
+
+:
diff --git a/t/confvar.sh b/t/confvar.sh
new file mode 100644
index 000000000..84748d3b2
--- /dev/null
+++ b/t/confvar.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure configure_vars stuff works.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([QBERT])
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^QBERT =' Makefile.in
+
+:
diff --git a/t/confvar2.sh b/t/confvar2.sh
new file mode 100644
index 000000000..d03dc64f0
--- /dev/null
+++ b/t/confvar2.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug reported by Jim Meyering.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([OTHER_SCRIPTS])
+END
+
+cat > Makefile.am << 'END'
+bin_SCRIPTS = foo
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^OTHER_SCRIPTS =' Makefile.in
+
+:
diff --git a/t/copy.sh b/t/copy.sh
new file mode 100644
index 000000000..da446c706
--- /dev/null
+++ b/t/copy.sh
@@ -0,0 +1,101 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure '-c' works. Report from Andris Pavenis.
+# See also the much more in-depth test 'add-missing'.
+
+. test-init.sh
+
+# We'll have to cater to systems like MSYS/MinGW where there are no
+# true symlinks ('ln -s' behaves like 'cp -p'); see automake bug#10441.
+
+echo dummy > foo
+if ln -s foo bar && test -h bar; then
+ is_symlink () { test -h "$1"; }
+ is_not_symlink () { test ! -h "$1"; }
+else
+ is_symlink () { return 0; } # Avoid spurious failures.
+ is_not_symlink () { return 0; }
+fi
+rm -f foo bar
+
+# First a simple test, where the auxdir is automatically determined
+# by automake.
+
+: > Makefile.am
+rm -f install-sh
+
+$ACLOCAL
+$AUTOMAKE -c -a
+ls -l # For debugging.
+
+test -f install-sh
+is_not_symlink install-sh
+
+# Let's do a couple of more elaborated tests, this time with the auxdir
+# explicitly defined in configure.ac.
+
+mkdir sub
+cd sub
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([auxdir])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<END
+bin_PROGRAMS = foo
+END
+
+$ACLOCAL
+
+# 'automake -a' called without '-c' should create symlinks by default,
+# even when there is already a non-symlinked required auxiliary file.
+
+mkdir auxdir
+echo FAKE-DEPCOMP > auxdir/depcomp
+$AUTOMAKE -a
+ls -l auxdir # For debugging.
+test -f auxdir/install-sh
+is_symlink auxdir/install-sh
+test -f auxdir/depcomp
+is_not_symlink auxdir/depcomp
+test FAKE-DEPCOMP = "$(cat auxdir/depcomp)"
+
+# 'automake -a -c' should not create symlinks, even when there are
+# already symlinked required auxiliary files.
+
+rm -rf auxdir
+mkdir auxdir
+cd auxdir
+ln -s "$am_scriptdir/missing" "$am_scriptdir/install-sh" .
+cd ..
+
+$AUTOMAKE -a -c
+ls -l auxdir # For debugging.
+test -f auxdir/install-sh
+is_symlink auxdir/install-sh
+test -f auxdir/missing
+is_symlink auxdir/missing
+test -f auxdir/depcomp
+is_not_symlink auxdir/depcomp
+diff "$am_scriptdir"/depcomp auxdir/depcomp
+
+:
diff --git a/t/cscope.tap b/t/cscope.tap
new file mode 100644
index 000000000..b7fbb210d
--- /dev/null
+++ b/t/cscope.tap
@@ -0,0 +1,170 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test cscope functionality.
+
+. test-init.sh
+
+plan_ 18
+
+ocwd=$(pwd) || fatal_ "getting top-level directory"
+
+cat > configure.ac << 'END'
+AC_INIT([cscope-test], [1.0])
+AM_INIT_AUTOMAKE([subdir-objects])
+AC_CONFIG_FILES([Makefile sub/Makefile])
+AC_SUBST([CC], [who-cares])
+AC_SUBST([CXX], [who-cares])
+AC_SUBST([FC], [who-cares])
+AC_SUBST([GCJ], [who-cares])
+AM_PATH_LISPDIR
+AC_OUTPUT
+END
+
+mkdir sub sub/subsub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c bar.cpp baz.f90
+lisp_LISP = foo.el
+EXTRA_DIST = foo.el
+END
+
+cat > sub/Makefile.am <<'END'
+bin_PROGRAMS = bar
+bar_SOURCES = subsub/dist.c
+nodist_bar_SOURCES = subsub/gen.c
+subsub/gen.c:
+ $(MKDIR_P) subsub
+ echo 'int generated_subsub () { return 0; }' > $@
+CLEANFILES = subsub/gen.c
+END
+
+echo 'int foo_func () { return 0; }' > foo.c
+echo 'int main () { return 0; }' > bar.cpp
+cat > baz.f90 <<'END'
+ subroutine baz
+ end
+END
+: > foo.el
+echo 'int main () { return 0; }' > sub/subsub/dist.c
+
+$ACLOCAL || fatal_ "aclocal failed"
+$AUTOCONF || fatal_ "autoconf failed"
+$AUTOMAKE -i -a || fatal_ "automake -i -a failed"
+
+# Sun cscope is interactive without redirection; also, it might not
+# support the '-q' option, which is required by our generated recipes.
+if cscope -q --version </dev/null; then
+ have_cscope=yes
+else
+ have_cscope=no
+fi
+
+test_cleanup ()
+{
+ r=ok
+ if test -f configure; then
+ # In-tree build.
+ $MAKE distclean
+ else
+ # VPATH build.
+ $MAKE distcleancheck
+ fi \
+ && test ! -e cscope.files \
+ && test ! -e cscope.out \
+ && test ! -e cscope.in.out \
+ && test ! -e cscope.po.out \
+ || r='not ok'
+ result_ "$r" "[$pfx] make distcheck"
+}
+
+test_cscope ()
+{
+ r=ok
+ $MAKE -n cscope || r='not ok'
+ result_ "$r" "[$pfx] make -n cscope"
+
+ if test $have_cscope = no; then
+ # For later tests.
+ touch cscope.files cscope.out cscope.in.out cscope.po.out
+ skip_row_ 3 -r "no proper cscope program available"
+ return 0
+ fi
+
+ r=ok
+ run_make -E cscope || r='not ok'
+ grep 'cannot find file' stderr && r='not ok'
+ rm -f stderr
+ result_ "$r" "[$pfx] make cscope"
+
+ r=ok
+ test -f cscope.files \
+ && $FGREP foo.c cscope.files \
+ && $FGREP bar.cpp cscope.files \
+ && $FGREP sub/subsub/dist.c cscope.files \
+ && $FGREP sub/subsub/gen.c cscope.files \
+ || r='not ok'
+ result_ "$r" "[$pfx] cscope.files looks correct"
+
+ r=ok
+ # cscope.files might not exist of the earlier "make cscope" failed.
+ cp cscope.files cscope.files1 \
+ && $MAKE cscope \
+ && diff cscope.files cscope.files1 \
+ || r='not ok'
+ rm -f cscope.files1
+ result_ "$r" "[$pfx] second \"make cscope\" is consistent"
+}
+
+my_configure ()
+{
+ command_ok_ "[$pfx] configure" \
+ "$1"/configure EMACS=no --with-lispdir=/who/cares
+}
+
+if using_gmake; then
+
+ cd "$ocwd"
+ pfx="relative VPATH"
+ mkdir build
+ cd build
+ my_configure ..
+ test_cscope
+ test_cleanup
+
+ cd "$ocwd"
+ pfx="absolute VPATH"
+ mkdir build2
+ cd build2
+ my_configure "$ocwd"
+ test_cscope
+ test_cleanup
+
+else
+
+ skip_row_ 12 -r "cscope in VPATH requires GNU make"
+
+fi
+
+cd "$ocwd"
+pfx="in-tree build"
+my_configure .
+test_cscope
+test_cleanup
+
+:
diff --git a/t/cscope2.sh b/t/cscope2.sh
new file mode 100644
index 000000000..2137cc9b9
--- /dev/null
+++ b/t/cscope2.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The 'cscope' target should not fail if there are no sources.
+
+required=
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+: >Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE cscope
+
+:
diff --git a/t/cscope3.sh b/t/cscope3.sh
new file mode 100644
index 000000000..0ec2a3194
--- /dev/null
+++ b/t/cscope3.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The 'cscope' target should not fail if there are no sources in a subdir.
+# In practice this means 'cscope' should not be invoked if cscope.files
+# is empty.
+
+required=cscope
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+mkdir sub
+echo 'SUBDIRS = sub' >Makefile.am
+: >sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE cscope
+
+:
diff --git a/t/cxx-demo.sh b/t/cxx-demo.sh
new file mode 100644
index 000000000..c3be764ab
--- /dev/null
+++ b/t/cxx-demo.sh
@@ -0,0 +1,182 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Demo on C++ support.
+
+required=c++
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([GNU C++ Demo], [1.3], [bug-automake@gnu.org])
+AC_CONFIG_SRCDIR([play.c++])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE
+# The C compiler shouldn't be required in any way.
+CC=false; AC_SUBST([CC])
+AC_PROG_CXX
+AH_BOTTOM([
+#ifndef GREETINGS
+# define GREETINGS "Howdy"
+#endif])
+AC_DEFINE([OK_AC], [1],
+ [Give "good to go" declaration from configure.ac])
+AC_CONFIG_HEADERS([config.hxx])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+
+bin_PROGRAMS = work play
+common_sources = common.hpp foo.cpp sub/bar.cc
+AM_CPPFLAGS = -DOK_AM=1
+play_SOURCES = play.c++ play.hh $(common_sources)
+work_SOURCES = work.cxx work.h++ $(common_sources)
+work_CXXFLAGS = -D'GREETINGS="Good morning"'
+
+.PHONY: test-objs
+check-local: test-objs
+test-objs:
+ test -f play.$(OBJEXT)
+ test -f foo.$(OBJEXT)
+ test -f sub/bar.$(OBJEXT)
+ test -f work-foo.$(OBJEXT)
+ test -f sub/work-bar.$(OBJEXT)
+ test -f work-work.$(OBJEXT)
+END
+
+mkdir sub build-aux
+
+$ACLOCAL
+$AUTOHEADER
+test -f config.hxx.in
+$AUTOCONF
+$AUTOMAKE --add-missing
+test -f build-aux/depcomp
+# Not needed by C++ compilers.
+test ! -e build-aux/compile
+
+cat > work.h++ << 'END'
+#define ACTION "work"
+class Hello_CXX
+{
+ public:
+ Hello_CXX() { }
+ virtual ~Hello_CXX () { }
+ void hello_cxx_class ();
+};
+END
+
+cat > play.hh << 'END'
+#define ACTION "play"
+void hello_cxx_function (void);
+END
+
+cat > common.hpp << 'END'
+/* Common header. */
+
+#include <config.hxx>
+
+#if !OK_AM
+#error "missing OK from Makefile.am"
+choke me
+#endif
+
+#if !OK_AC
+#error "missing OK from configure.ac"
+choke me
+#endif
+
+#include <iostream>
+END
+
+cat > work.cxx << 'END'
+#include "common.hpp"
+#include "work.h++"
+#include <cstdlib>
+using namespace std;
+int main (void)
+{
+ cout << "We are working :-(" << endl;
+ Hello_CXX *hello = new Hello_CXX;
+ hello->hello_cxx_class ();
+ return EXIT_SUCCESS;
+}
+END
+
+cat > play.c++ << 'END'
+#include "common.hpp"
+#include "play.hh"
+int main (void)
+{
+ std::cout << "We are playing :-)" << std::endl;
+ hello_cxx_function ();
+ return 0;
+}
+END
+
+cat > foo.cpp <<'END'
+#include <config.hxx>
+#include "work.h++"
+#include <iostream>
+using namespace std;
+void Hello_CXX::hello_cxx_class (void)
+{
+ cout << GREETINGS << ", " << ACTION << "." << endl;
+}
+END
+
+cat > sub/bar.cc << 'END'
+#include <config.hxx>
+#include "play.hh"
+#include <stdio.h>
+void hello_cxx_function (void)
+{
+ printf ("%s, %s!\n", GREETINGS, ACTION);
+}
+END
+
+./configure
+$MAKE
+$MAKE test-objs
+
+if ! cross_compiling; then
+ unindent > exp.play << 'END'
+ We are playing :-)
+ Howdy, play!
+END
+ unindent > exp.work << 'END'
+ We are working :-(
+ Good morning, work.
+END
+ for p in play work; do
+ # The program must run correctly (exit status = 0).
+ ./$p
+ # And it must have the expected output. Note that we strip extra
+ # CR characters (if any), to cater to MinGW programs on MSYS.
+ # See automake bug#14493.
+ ./$p | tr -d '\015' > got.$p || { cat got.$p; exit 1; }
+ cat exp.$p
+ cat got.$p
+ diff exp.$p got.$p
+ done
+fi
+
+$MAKE distcheck
+
+:
diff --git a/t/cxx-lt-demo.sh b/t/cxx-lt-demo.sh
new file mode 100644
index 000000000..a6b401475
--- /dev/null
+++ b/t/cxx-lt-demo.sh
@@ -0,0 +1,134 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Demo on Libtool/C++ support.
+
+required='libtoolize c++'
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([GNU C++/Libtool Demo], [0.73], [bug-automake@gnu.org])
+AC_CONFIG_SRCDIR([lib/libfoo.c++])
+AC_CONFIG_AUX_DIR([ax])
+AM_INIT_AUTOMAKE
+AC_CANONICAL_HOST
+AC_CANONICAL_BUILD
+AC_PROG_CXX
+AM_PROG_AR
+LT_INIT
+AC_CONFIG_FILES([
+ Makefile
+ src/Makefile
+ lib/Makefile
+ try.sh:try.in
+])
+AC_OUTPUT
+END
+
+mkdir ax lib src
+
+cat > Makefile.am <<'END'
+SUBDIRS = lib src
+
+AUTOMAKE_OPTIONS = parallel-tests
+TEST_EXTENSIONS = .sh
+SH_LOG_COMPILER = $(SHELL) -ex
+TESTS = try.sh
+
+.PHONY: test-objs
+check-local: test-objs
+test-objs:
+ test -f src/main.$(OBJEXT)
+ test -f lib/libfoo.lo
+END
+
+cat > src/Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = main.cc
+zardoz_LDADD = $(top_builddir)/lib/libfoo.la
+AM_CPPFLAGS = -I$(top_builddir)/lib
+END
+
+cat > lib/Makefile.am << 'END'
+lib_LTLIBRARIES = libfoo.la
+nodist_libfoo_la_SOURCES = libfoo.h++
+libfoo_la_SOURCES = libfoo.c++
+libfoo.h++: $(srcdir)/libfoo.c++
+ echo '#include <string>' >$@-t
+ grep "target *(" "$(srcdir)/libfoo.c++" >>$@-t
+ echo ';' >>$@-t
+ chmod a-w $@-t && mv -f $@-t $@
+BUILT_SOURCES = libfoo.h++
+DISTCLEANFILES = $(BUILT_SOURCES)
+END
+
+cat > try.in << 'END'
+#!/bin/sh
+set -e
+if test x"$host_alias" = x || test x"$build_alias" = x"$host_alias"; then
+ ./src/zardoz
+ test "`./src/zardoz`" = 'Howdy, Testsuite!'
+else
+ echo "Skip: cannot run a cross-compiled program"
+ exit 77
+fi
+END
+
+libtoolize --copy
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing --copy
+
+ls -l . ax # For debugging.
+# Ideally, the 'compile' script should not be required by C++ compilers.
+# But alas, LT_INIT seems to invoke AC_PROG_CC anyway, and that brings in
+# that script.
+for f in ltmain.sh depcomp compile config.guess config.sub; do
+ test -f ax/$f && test ! -h ax/$f || exit 1
+done
+
+cat > src/main.cc << 'END'
+#include "libfoo.h++"
+#include <iostream>
+using namespace std;
+int main (void)
+{
+ cout << "Howdy, " << target () << "!" << endl;
+ return 0;
+}
+END
+
+cat > lib/libfoo.c++ << 'END'
+#include "libfoo.h++"
+std::string target (void)
+{
+ std::string s1 = "Test";
+ std::string s2 = "suite";
+ return (s1 + s2);
+}
+END
+
+./configure
+run_make CC=false
+ls -l . src lib # For debugging.
+$MAKE test-objs
+VERBOSE=yes $MAKE check-TESTS
+grep 'Howdy.*Testsuite' try.log || grep 'Skip:.*cross-compiled' try.log
+
+$MAKE distcheck
+
+:
diff --git a/t/cxx.sh b/t/cxx.sh
new file mode 100644
index 000000000..528e2c74c
--- /dev/null
+++ b/t/cxx.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that '.c++' extension works.
+# From Ralf Corsepius.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = hello
+hello_SOURCES = hello.c++
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^\.SUFFIXES:.*c[+][+]' Makefile.in
diff --git a/t/cxx2.sh b/t/cxx2.sh
new file mode 100644
index 000000000..66b668208
--- /dev/null
+++ b/t/cxx2.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that Automake suggests using AC_PROG_CXX if C++ sources are used.
+
+. test-init.sh
+
+echo AC_PROG_CC >>configure.ac
+
+cat >Makefile.am <<'END'
+bin_PROGRAMS = hello
+hello_SOURCES = hello.cpp
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep AC_PROG_CXX stderr
diff --git a/t/cxxcpp.sh b/t/cxxcpp.sh
new file mode 100644
index 000000000..d4d692eb2
--- /dev/null
+++ b/t/cxxcpp.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure automake sees AC_PROG_CXXCPP. From Garth Corral.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXXCPP
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^CXXCPP =' Makefile.in
+
+:
diff --git a/t/cxxlibobj.sh b/t/cxxlibobj.sh
new file mode 100644
index 000000000..c6cbb02b4
--- /dev/null
+++ b/t/cxxlibobj.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure LIBOBJS and C++ sources work right.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_PROG_CC
+AC_REPLACE_FUNCS(strdup)
+END
+
+cat > Makefile.am << 'END'
+sbin_PROGRAMS = anonymous
+anonymous_SOURCES = doe.C jane.C
+anonymous_LDADD = @LIBOBJS@
+END
+
+: > strdup.c
+: > doe.C
+: > jane.C
+
+$ACLOCAL
+$AUTOMAKE
+
+grep CC Makefile.in
diff --git a/t/cxxlink.sh b/t/cxxlink.sh
new file mode 100644
index 000000000..de1d6ce20
--- /dev/null
+++ b/t/cxxlink.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure C++ linker is used when appropriate.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lavalamp
+lavalamp_SOURCES = lava.c lamp.cxx
+END
+
+: > lava.c
+: > lamp.cxx
+
+$ACLOCAL
+$AUTOMAKE
+
+# Look for this macro not at the beginning of any line; that will have
+# to be good enough for now.
+grep '.CXXLINK' Makefile.in
diff --git a/t/cxxnoc.sh b/t/cxxnoc.sh
new file mode 100644
index 000000000..32286371b
--- /dev/null
+++ b/t/cxxnoc.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure pure C++ sources don't include C-specific code.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+END
+
+cat > Makefile.am << 'END'
+sbin_PROGRAMS = anonymous
+anonymous_SOURCES = doe.C jane.C
+END
+
+: > doe.C
+: > jane.C
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP '(CC)' Makefile.in && exit 1
+exit 0
diff --git a/t/cygnus-no-more.sh b/t/cygnus-no-more.sh
new file mode 100644
index 000000000..425283b81
--- /dev/null
+++ b/t/cygnus-no-more.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that support for Cygnus-style trees is deprecated.
+# That feature will be removed in the next major Automake release.
+# See automake bug#11034.
+
+. test-init.sh
+
+warn_rx='support for Cygnus.*trees.*removed'
+
+$ACLOCAL
+
+# Use of 'cygnus' option must raise an unconditional error, not a
+# warning.
+AUTOMAKE="$am_original_AUTOMAKE -Wnone -Wno-error"
+
+# 'cygnus' option in Makefile.am
+echo "AUTOMAKE_OPTIONS = cygnus" > Makefile.am
+AUTOMAKE_fails
+grep "^Makefile\.am:1:.*$warn_rx" stderr
+
+rm -rf autom4te*.cache
+
+# 'cygnus' option in configure.ac
+: > Makefile.am
+sed "s|^\\(AM_INIT_AUTOMAKE\\).*|\1([cygnus])|" configure.ac > t
+diff configure.ac t && fatal_ "failed to edit configure.ac"
+mv -f t configure.ac
+AUTOMAKE_fails
+grep "^configure\.ac:2:.*$warn_rx" stderr
+
+:
diff --git a/t/cygwin32.sh b/t/cygwin32.sh
new file mode 100644
index 000000000..c45cfc46c
--- /dev/null
+++ b/t/cygwin32.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test basic Cygwin32 functionality.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = www
+www_SOURCES = www.c
+EXTRA_www_SOURCES = xtra.c
+www_LDADD = @extra_stuff@
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^CYGWIN' Makefile.in && exit 1
+grep 'EXEEXT' Makefile.in
+
+:
diff --git a/t/dash.sh b/t/dash.sh
new file mode 100644
index 000000000..ccf6a81a6
--- /dev/null
+++ b/t/dash.sh
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure '-' can be used in path.
+# Report from Matthew D. Langston.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+include Make-lang
+END
+
+: > Make-lang
+
+$ACLOCAL
+$AUTOMAKE
diff --git a/t/defun.sh b/t/defun.sh
new file mode 100644
index 000000000..b91c93c8a
--- /dev/null
+++ b/t/defun.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal picks up on all macro definitions.
+
+. test-init.sh
+
+cat > acinclude.m4 << 'END'
+AC_DEFUN([AM_FUNC_THREE])
+AC_DEFUN([AM_FUNC_TWO], [@!GrepThisString!@AM_FUNC_THREE])
+AC_DEFUN([AM_FUNC_ONE], [AC_REQUIRE([AM_FUNC_TWO])])
+END
+
+cat >>configure.ac << 'END'
+AM_FUNC_ONE
+END
+
+$ACLOCAL
+$AUTOCONF
+grep '^@!GrepThisString!@$' configure
+
+:
diff --git a/t/defun2.sh b/t/defun2.sh
new file mode 100644
index 000000000..711b8731d
--- /dev/null
+++ b/t/defun2.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we don't mistake a macro definition for an invocation.
+# From Jim Meyering.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+dnl if buggy this will require getloadavg.c
+AC_PROG_CC
+AC_DEFUN([AC_FUNC_GETLOADAVG])
+dnl need this to avoid LIBOBJS used but not defined.
+AC_FUNC_MEMCMP
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_LDADD = @LIBOBJS@
+END
+
+: > memcmp.c
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/dejagnu-absolute-builddir.sh b/t/dejagnu-absolute-builddir.sh
new file mode 100644
index 000000000..4b76d8c98
--- /dev/null
+++ b/t/dejagnu-absolute-builddir.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that DejaGnu testsuites have 'objdir' defined (as a TCL variable)
+# to an absolute path.
+
+required=runtest
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+DEJATOOL = tcl env
+EXTRA_DIST = tcl.test/tcl.exp
+END
+
+mkdir tcl.test
+
+cat > tcl.test/tcl.exp << 'END'
+send_user "tcl_objdir: $objdir\n"
+if { [ regexp "^/" $objdir ] } {
+ pass "test_tcl_objdir"
+} else {
+ fail "test_tcl_objdir"
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE check
+
+# Sanity check: all tests have run.
+test -f env.log
+test -f env.sum
+test -f tcl.log
+test -f tcl.sum
+
+$MAKE distcheck
+
+:
diff --git a/t/dejagnu-relative-srcdir.sh b/t/dejagnu-relative-srcdir.sh
new file mode 100644
index 000000000..2737efcd2
--- /dev/null
+++ b/t/dejagnu-relative-srcdir.sh
@@ -0,0 +1,84 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that DejaGnu testsuites have 'srcdir' defined to a relative path
+# (both as TCL variable and as environment variable).
+
+required=runtest
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+DEJATOOL = tcl env
+EXTRA_DIST = env.test/env.exp tcl.test/tcl.exp lib/tcl.exp
+END
+
+mkdir env.test tcl.test lib
+
+# DejaGnu can change $srcdir behind our backs, so we have to
+# save its original value. Thanks to Ian Lance Taylor for the
+# suggestion.
+cat > lib/tcl.exp << 'END'
+send_user "tcl_lib_srcdir: $srcdir\n"
+set orig_srcdir $srcdir
+END
+
+cat > env.test/env.exp << 'END'
+set env_srcdir $env(srcdir)
+send_user "env_srcdir: $env_srcdir\n"
+if { [ regexp "^\.(\./\.\.)?$" $env_srcdir ] } {
+ pass "test_env_src"
+} else {
+ fail "test_env_src"
+}
+END
+
+cat > tcl.test/tcl.exp << 'END'
+send_user "tcl_srcdir: $srcdir\n"
+if { [ regexp "^\.(\./\.\.)?$" $srcdir ] } {
+ pass "test_tcl_src"
+} else {
+ fail "test_tcl_src"
+}
+send_user "tcl_orig_srcdir: $orig_srcdir\n"
+if { [ regexp "^\.(\./\.\.)?$" $orig_srcdir ] } {
+ pass "test_tcl_orig_src"
+} else {
+ fail "test_tcl_orig_src"
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure --srcdir=.
+
+$MAKE check
+
+# Sanity check: all tests have run.
+test -f env.log
+test -f env.sum
+test -f tcl.log
+test -f tcl.sum
+
+$MAKE distcheck
+
+:
diff --git a/t/dejagnu-siteexp-append.sh b/t/dejagnu-siteexp-append.sh
new file mode 100644
index 000000000..d25848f53
--- /dev/null
+++ b/t/dejagnu-siteexp-append.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the files in $(EXTRA_DEJAGNU_SITE_CONFIG) get appended to
+# site.exp in the same order in which they're listed in that variable.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+DEJATOOL = tool
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE site.exp
+sed '/^##.*##$/d' site.exp > expected
+
+cat > foo.exp << 'END'
+foo1
+foo2
+foo3
+END
+
+cat foo.exp - >> expected << 'END'
+BAR 1
+# foo
+BAR 2
+END
+
+cat >> Makefile.am << 'END'
+EXTRA_DEJAGNU_SITE_CONFIG = foo.exp bar.exp
+bar.exp:
+ @(echo 'BAR 1' && echo '# foo' && echo 'BAR 2') > $@
+END
+
+$AUTOMAKE Makefile
+./config.status Makefile
+
+rm -f site.exp
+$MAKE site.exp
+sed '/^##.*##$/d' site.exp > obtained
+
+cat expected
+cat site.exp
+
+diff expected obtained
+
+:
diff --git a/t/dejagnu-siteexp-extend.sh b/t/dejagnu-siteexp-extend.sh
new file mode 100644
index 000000000..600dd0848
--- /dev/null
+++ b/t/dejagnu-siteexp-extend.sh
@@ -0,0 +1,159 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the developer can extend the site.exp generated by the
+# automake-generated Makefile.
+
+required=runtest
+. test-init.sh
+
+write_check_for ()
+{
+ echo "send_user \"$1: \$$1\\n\""
+ unindent << END
+ if { \$$1 == "/$1/" } {
+ pass "test_$1"
+ } else {
+ fail "test_$1"
+ }
+END
+}
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+DEJATOOL = tool
+
+EXTRA_DIST = tool.test/tool.exp
+
+EXTRA_DEJAGNU_SITE_CONFIG = foo.exp
+EXTRA_DIST += foo.exp
+END
+
+echo 'set foo "/foo/"' > foo.exp
+
+mkdir tool.test
+write_check_for foo > tool.test/tool.exp
+cat tool.test/tool.exp
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE check
+cat foo.exp
+cat site.exp
+grep 'PASS: test_foo' tool.sum
+
+write_check_for bar >> tool.test/tool.exp
+write_check_for baz >> tool.test/tool.exp
+cat tool.test/tool.exp
+
+# Ensure that foo.exp will be newer than site.exp, which will
+# thus have to be remade.
+$sleep
+# With this, below we'll also check that settings in files coming later in
+# $(EXTRA_DEJAGNU_SITE_CONFIG) override those in files coming earlier.
+cat >> foo.exp <<'END'
+set bar "/foo/"
+set baz "/foo/"
+set qux "/foo/"
+END
+
+$MAKE check && { cat site.exp; exit 1; }
+grep 'PASS: test_foo' tool.sum
+grep 'FAIL: test_bar' tool.sum
+grep 'FAIL: test_baz' tool.sum
+
+cat >> Makefile.am << 'END'
+EXTRA_DEJAGNU_SITE_CONFIG += bar bar.dir/bar
+EXTRA_DIST += bar
+DISTCLEANFILES = bar.dir/bar
+bar.dir/bar:
+ test -d bar.dir || mkdir bar.dir
+ echo 'set baz "/baz/"' > $@
+END
+
+echo 'set bar "/bar/"' > bar
+# This will allow us to check one more time that settings in files
+# coming later in $(EXTRA_DEJAGNU_SITE_CONFIG) override those in
+# files coming earlier.
+echo 'set baz "/xyz/"' >> bar
+
+# Ensure that the Makefile will be newer than site.exp, which will
+# thus have to be remade.
+$sleep
+$AUTOMAKE Makefile
+./config.status Makefile
+
+$MAKE check || { cat site.exp; exit 1; }
+cat site.exp
+cat bar.dir/bar
+$FGREP '/bar/' site.exp
+$FGREP '/baz/' site.exp
+grep 'PASS: test_foo' tool.sum
+grep 'PASS: test_bar' tool.sum
+grep 'PASS: test_baz' tool.sum
+
+# Check that the features we're testing behave well in VPATH builds.
+$MAKE distcheck
+
+# Check that the user can edit the site.exp file, and that his edits
+# are retained.
+write_check_for zardoz >> tool.test/tool.exp
+cat tool.test/tool.exp
+echo 'set zardoz "/zardoz/"' >> site.exp
+
+$MAKE check
+cat site.exp
+grep 'PASS: test_zardoz' tool.sum
+
+cat >> Makefile.am << 'END'
+EXTRA_DEJAGNU_SITE_CONFIG += quux.exp
+quux.exp:
+ echo 'set zardoz "/quux/"' > $@
+END
+
+# Ensure that the Makefile will be newer than on site.exp, which will
+# thus have to be remade.
+$sleep
+$AUTOMAKE Makefile
+./config.status Makefile
+grep 'zardoz.*/quux/' Makefile
+
+$MAKE site.exp
+cat site.exp
+cat quux.exp
+grep 'zardoz.*/quux/' site.exp
+
+$MAKE check
+grep 'PASS: test_zardoz' tool.sum
+grep 'zardoz: /zardoz/' tool.log
+grep 'zardoz.*quux' tool.log && exit 1
+
+# Check that files in $(EXTRA_DEJAGNU_SITE_CONFIG) are not distributed
+# by default.
+$MAKE distdir
+ls -l $distdir
+test ! -e $distdir/bar.dir/bar
+test ! -e $distdir/quux.exp
+
+:
diff --git a/t/dejagnu-siteexp-useredit.sh b/t/dejagnu-siteexp-useredit.sh
new file mode 100644
index 000000000..b8d596641
--- /dev/null
+++ b/t/dejagnu-siteexp-useredit.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the user can edit the Makefile-generated site.exp, and
+# have its edits survive to the remaking of that file.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+DEJATOOL = foo
+END
+
+# Deliberately select a variable defined automatically by
+# the Makefile-generated site.exp.
+mkdir foo.test
+cat > foo.test/foo.exp << 'END'
+send_user "objdir: $objdir\n"
+set pipe "|"
+if { $objdir == "${pipe}objdir${pipe}" } {
+ pass "test_obj"
+} else {
+ fail "test_obj"
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE site.exp
+echo 'set objdir "|objdir|"' >> site.exp
+cat site.exp
+$sleep
+touch Makefile
+$MAKE site.exp
+cat site.exp
+is_newest site.exp Makefile # Sanity check.
+grep '|objdir|' site.exp
+test $($FGREP -c '|objdir|' site.exp) -eq 1
+
+# We can do a "more semantic" check if DejaGnu is available.
+if runtest SOMEPROGRAM=someprogram --version; then
+ $MAKE check
+ grep 'PASS: test_obj' foo.sum
+fi
+
+:
diff --git a/t/dejagnu.sh b/t/dejagnu.sh
new file mode 100644
index 000000000..94bd4be0f
--- /dev/null
+++ b/t/dejagnu.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Superficial test to check that dejagnu tests and automake-style
+# tests can coexist. See also related deeper test 'check12.sh'.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+TESTS = frob.test
+END
+
+test x"$am_serial_tests" = x"yes" || : > test-driver
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^check-TESTS' Makefile.in
+grep '^check-DEJAGNU' Makefile.in
+
+:
diff --git a/t/dejagnu2.sh b/t/dejagnu2.sh
new file mode 100644
index 000000000..ad5f83d4a
--- /dev/null
+++ b/t/dejagnu2.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we don't override the user's site.exp rule.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+
+site.exp:
+ echo :GREP:ME: > $@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -Wno-override
+
+grep 'site\.exp' Makefile.in
+test $(grep -c '^site\.exp:' Makefile.in) -eq 1
+
+./configure
+$MAKE site.exp
+grep ':GREP:ME:' site.exp
+
+AUTOMAKE_fails
+grep '^Makefile\.am:3:.*site\.exp' stderr
+
+:
diff --git a/t/dejagnu3.sh b/t/dejagnu3.sh
new file mode 100644
index 000000000..18aefdd38
--- /dev/null
+++ b/t/dejagnu3.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the DejaGnu rules work for a simple program and test case.
+
+required=runtest
+. test-init.sh
+
+cat > hammer << 'END'
+#! /bin/sh
+echo "Everything looks like a nail to me!"
+END
+
+chmod +x hammer
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+DEJATOOL = hammer
+AM_RUNTESTFLAGS = HAMMER=$(srcdir)/hammer
+EXTRA_DIST = hammer hammer.test/hammer.exp
+END
+
+mkdir hammer.test
+
+cat > hammer.test/hammer.exp << 'END'
+set test test
+spawn $HAMMER
+expect {
+ "Everything looks like a nail to me!" { pass "$test" }
+ default { fail "$test" }
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE check
+test -f hammer.log
+test -f hammer.sum
+
+$MAKE distcheck
+
+# Ensure that the envvar RUNTESTFLAGS is used.
+# Report from Mark Mitchell.
+RUNTESTFLAGS=--unknown-runtest-option; export RUNTESTFLAGS
+run_make -M -e FAIL check
+$FGREP 'unknown-runtest-option' output
+
+:
diff --git a/t/dejagnu4.sh b/t/dejagnu4.sh
new file mode 100644
index 000000000..c94573ea3
--- /dev/null
+++ b/t/dejagnu4.sh
@@ -0,0 +1,102 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the DejaGnu rules work for a simple program and test case.
+# Also check PR 488: Failure of the first of several tools tested.
+# From the original bug report:
+# If you use dejagnu for testing and have multiple tools (i.e.,
+# multiple entries in the DEJATOOL variable) then the success/failure
+# of "make check" is only dependent on the success/failure of the
+# tests on the final tool. Thus there may be failures in the tests on
+# previous tools, but at first glance "make check" has passed.
+
+required=runtest
+. test-init.sh
+
+cat > hammer << 'END'
+#! /bin/sh
+echo "Everything looks like a nail to me!"
+END
+chmod +x hammer
+
+cat > spanner << 'END'
+#! /bin/sh
+echo "I'm a right spanner!"
+END
+chmod +x spanner
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+
+DEJATOOL = hammer spanner
+
+AM_RUNTESTFLAGS = HAMMER=$(srcdir)/hammer SPANNER=$(srcdir)/spanner
+
+EXTRA_DIST = hammer hammer.test/hammer.exp
+EXTRA_DIST += spanner spanner.test/spanner.exp
+END
+
+mkdir hammer.test spanner.test
+
+cat > hammer.test/hammer.exp << 'END'
+set test test
+spawn $HAMMER
+expect {
+ "Everything looks like a nail to me!" { pass "$test" }
+ default { fail "$test" }
+}
+END
+
+cat > spanner.test/spanner.exp << 'END'
+set test test
+spawn $SPANNER
+expect {
+ "I'm a right spanner!" { pass "$test" }
+ default { fail "$test" }
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE check
+test -f hammer.log
+test -f hammer.sum
+test -f spanner.log
+test -f spanner.sum
+
+$MAKE distcheck
+
+# Test for PR 488.
+sed 's/E\(verything\)/Not e\1/' hammer > thammer
+mv -f thammer hammer
+chmod +x hammer
+
+rm -f hammer.log hammer.sum spanner.log spanner.sum
+$MAKE check && exit 1
+test -f hammer.log
+test -f hammer.sum
+test -f spanner.log
+test -f spanner.sum
+
+:
diff --git a/t/dejagnu5.sh b/t/dejagnu5.sh
new file mode 100644
index 000000000..7cfab7022
--- /dev/null
+++ b/t/dejagnu5.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the DejaGnu rules do look for a testsuite named after
+# the package by default.
+
+required=runtest
+. test-init.sh
+
+package=$me
+
+cat > $package << 'END'
+#! /bin/sh
+echo "Ah, we have been expecting you, Mr. Blond."
+END
+chmod +x $package
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << END
+AUTOMAKE_OPTIONS = dejagnu
+EXTRA_DIST = $package $package.test/$package.exp
+AM_RUNTESTFLAGS = PACKAGE=\$(srcdir)/$package
+END
+
+mkdir $package.test
+cat > $package.test/$package.exp << 'END'
+set test "a_dejagnu_test"
+spawn $PACKAGE
+expect {
+ "Ah, we have been expecting you, Mr. Blond." { pass "$test" }
+ default { fail "$test" }
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE check
+test -f $package.log
+test -f $package.sum
+
+$MAKE distcheck
+
+:
diff --git a/t/dejagnu6.sh b/t/dejagnu6.sh
new file mode 100644
index 000000000..889916d5d
--- /dev/null
+++ b/t/dejagnu6.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that "make check" fails, when a DejaGnu test fails.
+
+required=runtest
+. test-init.sh
+
+cat > faildeja << 'END'
+#! /bin/sh
+echo whatever
+END
+chmod +x faildeja
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+DEJATOOL = faildeja
+AM_RUNTESTFLAGS = FAILDEJA=$(srcdir)/faildeja
+END
+
+mkdir faildeja.test
+cat > faildeja.test/faildeja.exp << 'END'
+set test failing_deja_test
+spawn $FAILDEJA
+expect {
+ default { fail "$test" }
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE check && exit 1
+test -f faildeja.log
+test -f faildeja.sum
+$FGREP 'FAIL: failing_deja_test' faildeja.sum
+
+:
diff --git a/t/dejagnu7.sh b/t/dejagnu7.sh
new file mode 100644
index 000000000..4ee57ddac
--- /dev/null
+++ b/t/dejagnu7.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that "make check" fails, when we invoke DejaGnu tests with --status
+# (to detect TCL errors) on a file with TCL errors.
+
+required=runtest
+. test-init.sh
+
+runtest --help | grep '.*--status' \
+ || skip_ "dejagnu lacks support for '--status'"
+
+cat > failtcl << 'END'
+#! /bin/sh
+echo whatever
+END
+chmod +x failtcl
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = dejagnu
+DEJATOOL = failtcl
+AM_RUNTESTFLAGS = --status FAILTCL=$(srcdir)/failtcl
+END
+
+mkdir failtcl.test
+cat > failtcl.test/failtcl.exp << 'END'
+set test test
+spawn $FAILTCL
+expect {
+ default { pass "$test" }
+# Oops, no closing brace.
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE check && exit 1
+test -f failtcl.log
+test -f failtcl.sum
+$FGREP 'missing close-brace' failtcl.sum
+
+:
diff --git a/t/deleted-am.sh b/t/deleted-am.sh
new file mode 100644
index 000000000..696864ba9
--- /dev/null
+++ b/t/deleted-am.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The stub rules emitted to work around the "deleted header problem"
+# for '.am' files shouldn't prevent the remake rules from correctly
+# erroring out when a still-required file is missing.
+# See also discussion about automake bug#9768.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+echo 'include $(top_srcdir)/foobar.am' > Makefile.am
+echo 'include zardoz.am' > foobar.am
+: > zardoz.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+
+rm -f zardoz.am
+using_gmake || $sleep # Required by BSD make.
+run_make -e FAIL -M
+# This error will come from automake, not make, so we can be stricter
+# in our grepping of it.
+grep 'cannot open.*zardoz\.am' output
+grep 'foobar\.am' output && exit 1 # No spurious error, please.
+
+# Try with one less indirection.
+: > foobar.am
+$AUTOMAKE Makefile
+./config.status Makefile
+$MAKE # Sanity check.
+rm -f foobar.am
+using_gmake || $sleep # Required by BSD make.
+run_make -e FAIL -M
+# This error will come from automake, not make, so we can be stricter
+# in our grepping of it.
+grep 'cannot open.*foobar\.am' output
+
+:
diff --git a/t/deleted-m4.sh b/t/deleted-m4.sh
new file mode 100644
index 000000000..41b07d69c
--- /dev/null
+++ b/t/deleted-m4.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The stub rules emitted to work around the "deleted header problem"
+# for '.m4' files shouldn't prevent the remake rules from correctly
+# erroring out when a still-required file is missing.
+# See also discussion about automake bug#9768.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+m4_include([foobar.m4])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+echo 'm4_include([zardoz.m4])' > foobar.m4
+: > zardoz.m4
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+
+rm -f zardoz.m4
+run_make -e FAIL -M
+# This error will come from aclocal, not make, so we can be stricter
+# in our grepping of it.
+grep ' foobar\.m4:1:.*zardoz\.m4.*does not exist' output
+# No spurious errors, please.
+$FGREP -v ' foobar.m4:1:' output | $FGREP 'foobar.m4' && exit 1
+
+# Try with one less indirection.
+: > foobar.m4
+$ACLOCAL --force
+$AUTOCONF
+./configure
+$MAKE # Sanity check.
+rm -f foobar.m4
+run_make -e FAIL -M
+# This error will come from aclocal, not make, so we can be stricter
+# in our grepping of it.
+grep 'foobar\.m4.*does not exist' output
+# No spurious errors, please (ok, this is really paranoid).
+$FGREP 'zardoz.m4' output && exit 1
+
+:
diff --git a/t/depacl2.sh b/t/depacl2.sh
new file mode 100644
index 000000000..11d0cf9d1
--- /dev/null
+++ b/t/depacl2.sh
@@ -0,0 +1,27 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure dependencies work when required macro is part of
+# autoconf.
+
+. test-init.sh
+
+echo 'AM_FOO' >> configure.ac
+echo 'AC_DEFUN([AM_FOO], [AC_REQUIRE([AC_HEADER_STDC])])' > AM_FOO.m4
+
+$ACLOCAL -I .
+
+:
diff --git a/t/depcomp-implicit-auxdir.sh b/t/depcomp-implicit-auxdir.sh
new file mode 100644
index 000000000..33d52e386
--- /dev/null
+++ b/t/depcomp-implicit-auxdir.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure a top-level depcomp file is found when
+# AC_CONFIG_AUX_DIR is not specified.
+
+. test-init.sh
+
+mkdir lib src
+
+cat >> configure.ac << 'END'
+AC_PROG_RANLIB
+AC_PROG_CC
+AM_PROG_AR
+AC_CONFIG_FILES([lib/Makefile src/Makefile])
+AC_OUTPUT
+END
+
+# Files required because we are using '--gnu'.
+: > INSTALL
+: > NEWS
+: > README
+: > COPYING
+: > AUTHORS
+: > ChangeLog
+
+cat > Makefile.am << 'END'
+SUBDIRS = lib src
+END
+
+cat > lib/Makefile.am << 'END'
+pkgdata_DATA =
+noinst_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+cat > lib/foo.c << 'END'
+int foo () {}
+END
+
+cat > src/Makefile.am << 'END'
+pkgdata_DATA =
+END
+
+: > ar-lib
+
+$ACLOCAL
+$AUTOMAKE --gnu
+
+# Make sure that depcomp is *not* included in the definition
+# of DIST_COMMON in lib/Makefile.in. If you change this test
+# so that more files are included in lib's DIST_COMMON definition,
+# then you must handle the case in which depcomp is listed on a
+# continued line.
+grep '^DIST_COMMON.*depcomp' lib/Makefile.in && exit 1
+
+:
diff --git a/t/depcomp.sh b/t/depcomp.sh
new file mode 100644
index 000000000..24425b912
--- /dev/null
+++ b/t/depcomp.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure depcomp is installed and found properly
+# when required for multiple directories.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([subdir/Makefile subdir2/Makefile])
+AC_PROG_CC
+AC_OUTPUT
+END
+
+rm -f depcomp
+mkdir subdir
+mkdir subdir2
+
+cat > subdir/Makefile.am << 'END'
+noinst_PROGRAMS = foo
+foo_SOURCES = foo.c
+END
+
+cp subdir/Makefile.am subdir2/Makefile.am
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+# There used to be a bug where this was created in the first subdir with C
+# sources in it instead of in $top_srcdir or $ac_auxdir.
+test -f depcomp
+
+:
diff --git a/t/depcomp2.sh b/t/depcomp2.sh
new file mode 100644
index 000000000..0ea91b854
--- /dev/null
+++ b/t/depcomp2.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that depcomp is not used when it's not installed
+# From Pavel Roskin.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([subdir/Makefile])
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = subdir
+END
+
+rm -f depcomp
+mkdir subdir
+
+cat > subdir/Makefile.in << 'END'
+foo:
+ $(CC) -o foo foo.c
+END
+
+: > subdir/foo.c
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+./configure 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+# Ignore warning messages sometimes seen on Mac OS X; they are
+# not automake's fault anyway, but either autoconf's or Mac's.
+sed '/rm:.*conftest\.dSYM/d' stderr >stderr2
+test -s stderr2 && { cat stderr2; exit 1; }
+
+:
diff --git a/t/depcomp8a.sh b/t/depcomp8a.sh
new file mode 100644
index 000000000..e18318061
--- /dev/null
+++ b/t/depcomp8a.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for regressions in computation of names of .Po files for
+# automatic dependency tracking.
+# Keep this in sync with sister test 'depcomp8b.sh', which checks the
+# same thing for libtool objects.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = foo.c sub/bar.c
+END
+
+mkdir sub
+cat > foo.c << 'END'
+int main (void)
+{
+ extern int bar (void);
+ return bar ();
+}
+END
+cat > sub/bar.c << 'END'
+int bar (void)
+{
+ return 0;
+}
+END
+
+$ACLOCAL
+# FIXME: stop disabling the warnings in the 'unsupported' category
+# FIXME: once the 'subdir-objects' option has been mandatory.
+$AUTOMAKE -a -Wno-unsupported
+grep '\.P' Makefile.in # For debugging.
+grep '\./\$(DEPDIR)/foo\.Po' Makefile.in
+grep '\./\$(DEPDIR)/bar\.Po' Makefile.in
+grep '/\./\$(DEPDIR)' Makefile.in && exit 1
+
+$AUTOCONF
+# Don't reject slower dependency extractors, for better coverage.
+./configure --enable-dependency-tracking
+$MAKE
+cross_compiling || ./zardoz
+DISTCHECK_CONFIGURE_FLAGS='--enable-dependency-tracking' $MAKE distcheck
+
+# Try again with subdir-objects option.
+
+echo AUTOMAKE_OPTIONS = subdir-objects >> Makefile.am
+
+$AUTOMAKE
+grep '\.P' Makefile.in # For debugging.
+grep '\./\$(DEPDIR)/foo\.Po' Makefile.in
+grep '[^a-zA-Z0-9_/]sub/\$(DEPDIR)/bar\.Po' Makefile.in
+$EGREP '/(\.|sub)/\$\(DEPDIR\)' Makefile.in && exit 1
+
+$AUTOCONF
+# Don't reject slower dependency extractors, for better coverage.
+./configure --enable-dependency-tracking
+$MAKE
+cross_compiling || ./zardoz
+DISTCHECK_CONFIGURE_FLAGS='--enable-dependency-tracking' $MAKE distcheck
+
+:
diff --git a/t/depcomp8b.sh b/t/depcomp8b.sh
new file mode 100644
index 000000000..a4d5a77d6
--- /dev/null
+++ b/t/depcomp8b.sh
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for regressions in computation of names of .Plo files for
+# automatic dependency tracking.
+# Keep this in sync with sister test 'depcomp8a.sh', which checks the
+# same thing for non-libtool objects.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+#x AM_PROG_CC_C_O
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+## FIXME: stop disabling the warnings in the 'unsupported' category
+## FIXME: once the 'subdir-objects' option has been mandatory.
+AUTOMAKE_OPTIONS = -Wno-unsupported
+lib_LTLIBRARIES = libzardoz.la
+libzardoz_la_SOURCES = foo.c sub/bar.c
+END
+
+mkdir sub
+echo 'int foo (void) { return 0; }' > foo.c
+echo 'int bar (void) { return 0; }' > sub/bar.c
+
+libtoolize
+
+$ACLOCAL
+# FIXME: stop disabling the warnings in the 'unsupported' category
+# FIXME: once the 'subdir-objects' option has been mandatory.
+$AUTOMAKE -a -Wno-unsupported
+grep '\.P' Makefile.in # For debugging.
+grep '\./\$(DEPDIR)/foo\.Plo' Makefile.in
+grep '\./\$(DEPDIR)/bar\.Plo' Makefile.in
+grep '/\./\$(DEPDIR)' Makefile.in && exit 1
+
+$AUTOCONF
+# Don't reject slower dependency extractors, for better coverage.
+./configure --enable-dependency-tracking
+$MAKE
+DISTCHECK_CONFIGURE_FLAGS='--enable-dependency-tracking' $MAKE distcheck
+
+# Try again with subdir-objects option.
+
+echo AUTOMAKE_OPTIONS += subdir-objects >> Makefile.am
+
+$AUTOMAKE
+grep '\.P' Makefile.in # For debugging.
+grep '\./\$(DEPDIR)/foo\.Plo' Makefile.in
+grep '[^a-zA-Z0-9_/]sub/\$(DEPDIR)/bar\.Plo' Makefile.in
+$EGREP '/(\.|sub)/\$\(DEPDIR\)' Makefile.in && exit 1
+
+$AUTOCONF
+# Don't reject slower dependency extractors, for better coverage.
+./configure --enable-dependency-tracking
+$MAKE
+DISTCHECK_CONFIGURE_FLAGS='--enable-dependency-tracking' $MAKE distcheck
+
+:
diff --git a/t/depdist.sh b/t/depdist.sh
new file mode 100644
index 000000000..cc35bc710
--- /dev/null
+++ b/t/depdist.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure depcomp is found for the distribution.
+# From Eric Magnien.
+
+required=cc
+. test-init.sh
+
+rm -f configure.ac
+
+mkdir config
+for i in *; do
+ if test "$i" != "config"; then
+ mv -f "$i" config
+ fi
+done
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([config])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AC_CONFIG_FILES([subdir/Makefile Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = subdir
+check-local: test1 test2
+.PHONY: test1 test2
+test1:
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]config/depcomp '
+test2: distdir
+ ls -l $(distdir)/*
+ test -f $(distdir)/config/depcomp
+END
+
+mkdir subdir
+cat > subdir/foo.c << 'END'
+int main(void)
+{
+ return 0;
+}
+END
+
+cat > subdir/Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/depend-postproc.sh b/t/depend-postproc.sh
new file mode 100644
index 000000000..24f30a59f
--- /dev/null
+++ b/t/depend-postproc.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check to make sure we recognize a Makefile.in, even if post-processed
+# and renamed. The particularly tricky code for automatic dependency
+# tracking support used to have issues with that.
+
+required=cc
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AC_CONFIG_FILES([myMakefile])
+dnl: AC_CONFIG_LINKS([Makefile:Makefile])
+AC_OUTPUT
+END
+
+cat > myMakefile.am <<'END'
+bin_PROGRAMS = fred
+fred_SOURCES = fred.c
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -- myMakefile
+
+mv myMakefile.in myMakefile.old
+echo '# Post-processed by post-processor 3.14.' > myMakefile.in
+cat myMakefile.old >> myMakefile.in
+
+./configure
+
+test -f .deps/fred.Po || test -f _deps/fred.Po || exit 1
+
+$sleep
+
+cat > Makefile <<'END'
+include myMakefile
+END
+
+sed 's/^dnl: *//' configure.ac >t
+mv -f t configure.ac
+
+$MAKE myMakefile Makefile
+
+rm -rf .deps _deps
+./config.status
+
+test ! -e fred.c
+echo 'int main (void) { return 0; }' > fred.c
+
+$MAKE
+test -f .deps/fred.Po || test -f _deps/fred.Po || exit 1
+$MAKE distcheck
+
+:
diff --git a/t/depend.sh b/t/depend.sh
new file mode 100644
index 000000000..641741137
--- /dev/null
+++ b/t/depend.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# This tests for a bug reported by Henrik Frystyk Nielsen <frystyk@w3.org>
+# In some cases the auto-dependency can get confused and try
+# to '-include' a directory (if a backslash-newline appears in _SOURCES).
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = fred
+fred_SOURCES = \
+ fred.c
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+test 1 -eq $(grep -c '^@AMDEP_TRUE@@am__include@' Makefile.in)
+
+:
diff --git a/t/depend3.sh b/t/depend3.sh
new file mode 100644
index 000000000..770a6e569
--- /dev/null
+++ b/t/depend3.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test _DEPENDENCIES variable. From Lee Iverson.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_SUBST(DEPS)
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = TerraVision
+
+TerraVision_SOURCES = \
+ AboutDialog.c Clock.c Dialogs.c DrawModel.c \
+ TsmWidget.c Gats.c GATSDialogs.c Model.c ModelAnim.c \
+ ScannedMap.c \
+ TerraVision.c TerraVisionAvs.c TerraVisionCAVE.c \
+ Texture.c ThreeDControl.c ThreeDPanel.c \
+ ThreeDWidget.c ThreeDWidget1.c TileManager.c \
+ TileRequester.c TwoDWidget.c \
+ Visible.c RequestGenerator.c X11FrameGrab.c \
+ matrix.c pixmaps.c xpmhash.c xpmread.c xcolor.c xv24to8.c
+
+DEPS = @DEPS@
+
+TerraVision_DEPENDENCIES = $(DEPS)
+END
+
+$ACLOCAL
+$AUTOMAKE
diff --git a/t/depend4.sh b/t/depend4.sh
new file mode 100644
index 000000000..14d80f5e3
--- /dev/null
+++ b/t/depend4.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that dependencies are included when there are many header files.
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+$ACLOCAL
+
+headers=
+for header in one.h two.h three.h four.h five.h six.h; do
+ headers="$headers $header"
+ unindent > Makefile.am << END
+ bin_PROGRAMS = fred
+ fred_SOURCES = fred1.c $headers
+END
+ $AUTOMAKE
+ test 1 -eq $(grep -c '^@AMDEP_TRUE@@am__include@' Makefile.in)
+done
+
+:
diff --git a/t/depend5.sh b/t/depend5.sh
new file mode 100644
index 000000000..ce0a70315
--- /dev/null
+++ b/t/depend5.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that _AM_OUTPUT_DEPENDENCY_COMMANDS works with eval-style
+# quoting in $CONFIG_FILES, done by newer Autoconf.
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac << END
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << END
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c foo.h
+END
+
+cat >foo.c << END
+#include "foo.h"
+END
+: >foo.h
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure --enable-dependency-tracking
+if test -d .deps; then
+ depdir=.deps
+elif test -d _deps; then
+ depdir=_deps
+else
+ depdir=
+fi
+
+# For the fun of it, we should also cope with Makefile names
+# that contain weird characters and newer.
+# Pick the first name that the file system will accept.
+for name in \
+ 'weird name with $ `#() &! characters"' \
+ 'weird name with $ `#() characters"' \
+ 'weird name with characters'
+do
+ cp Makefile.in "$name.in" && break || :
+done
+
+for arg in Makefile \
+ --file=Makefile \
+ "--file=$name"
+do
+ rm -rf .deps _deps
+ ./config.status "$arg" depfiles >stdout 2>stderr ||
+ { cat stdout; cat stderr >&2; exit 1; }
+ cat stdout
+ cat stderr >&2
+ grep '[Nn]o such file' stderr && exit 1
+
+ if test -n "$depdir"; then
+ test -d $depdir || exit 1
+ fi
+done
+
+:
diff --git a/t/depend6.sh b/t/depend6.sh
new file mode 100644
index 000000000..6de2e3cf8
--- /dev/null
+++ b/t/depend6.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for _AM_OUTPUT_DEPENDENCY_COMMANDS grouping bug,
+# reported by Markus Duft.
+
+. test-init.sh
+
+cat >>configure.ac << END
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << END
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c foo.h
+END
+
+cat >foo.c << END
+#include "foo.h"
+END
+: >foo.h
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure --disable-dependency-tracking 2>stderr || {
+ stat=$?; cat stderr >&2; exit $stat;
+}
+cat stderr >&2
+grep shift stderr && exit 1
+
+:
diff --git a/t/deprecated-acinit.sh b/t/deprecated-acinit.sh
new file mode 100644
index 000000000..e447dd122
--- /dev/null
+++ b/t/deprecated-acinit.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake and autoconf complain about an old-style AC_INIT
+# call used with a new-style AM_AUTOMAKE_INIT call.
+
+. test-init.sh
+
+: > Makefile.am
+
+# We'll need a proper aclocal.m4, but aclocal is expected to fail
+# later, so get and store it now.
+$ACLOCAL
+mv aclocal.m4 aclocal-m4.sav
+
+errmsg='AC_INIT should be called with package and version argument'
+
+for ac_init in AC_INIT 'AC_INIT([Makefile.am])'; do
+ for am_init_automake in AM_INIT_AUTOMAKE 'AM_INIT_AUTOMAKE([1.11])'; do
+ rm -rf autom4te*.cache aclocal.m4
+ unindent > configure.ac <<END
+ $ac_init
+ $am_init_automake
+ AC_CONFIG_FILES([Makefile])
+END
+ cat configure.ac # For debugging.
+ $ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+ cat stderr >&2
+ grep "^configure\\.ac:.* $errmsg" stderr
+ cp aclocal-m4.sav aclocal.m4
+ $AUTOCONF 2>stderr && { cat stderr >&2; exit 1; }
+ cat stderr >&2
+ grep "^configure\\.ac:.* $errmsg" stderr
+ AUTOMAKE_fails
+ grep "^configure\\.ac:.* $errmsg" stderr
+ done
+done
+
+:
diff --git a/t/destdir.sh b/t/destdir.sh
new file mode 100644
index 000000000..5323a1ee7
--- /dev/null
+++ b/t/destdir.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that 'make distcheck' can find some $(DESTDIR) omissions.
+# PR/186.
+
+# The feature we test here relies on read-only directories.
+# It will only work for non-root users.
+required='ro-dir'
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+dist_data_DATA = foo
+
+# This rule is bogus because it doesn't use $(DESTDIR) on the
+# second argument of cp. distcheck is expected to catch this.
+install-data-hook:
+ cp $(DESTDIR)$(datadir)/foo $(datadir)/bar
+
+uninstall-local:
+ rm -f $(DESTDIR)$(datadir)/bar
+EOF
+
+: > foo
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE distcheck && exit 1
+
+:
diff --git a/t/dir-named-obj-is-bad.sh b/t/dir-named-obj-is-bad.sh
new file mode 100644
index 000000000..602d4b48c
--- /dev/null
+++ b/t/dir-named-obj-is-bad.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Naming a subdirectory 'obj/' is a bad idea. Automake should say so.
+
+. test-init.sh
+
+mkdir obj
+
+cat >>configure.ac << 'END'
+AC_CONFIG_FILES([obj/Makefile])
+AC_OUTPUT
+END
+
+: > obj/Makefile.am
+echo 'SUBDIRS = obj' > Makefile.am
+
+$ACLOCAL
+
+AUTOMAKE_fails
+grep "^Makefile\.am:1:.*'obj'.*BSD make" stderr
+
+cat >Makefile.am <<'END'
+SUBDIRS = @STH@
+FOO = obj
+DIST_SUBDIRS = $(FOO)
+END
+
+AUTOMAKE_fails
+grep "^Makefile\\.am:2:.*'obj'.*BSD make" stderr
+
+rm -rf autom4te*.cache
+
+cat >configure.ac << 'END'
+AC_INIT([x], [1.0])
+AC_CONFIG_AUX_DIR([obj])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+rm -f obj/Makefile.am
+: > Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails -a
+grep "^configure\.ac:2:.*'obj'.*BSD make" stderr
+
+:
diff --git a/t/discover.sh b/t/discover.sh
new file mode 100644
index 000000000..3159a975c
--- /dev/null
+++ b/t/discover.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure LIBOBJS file cannot be mentioned explicitly.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AM_PROG_AR
+AC_LIBOBJ([fsusage])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES = fsusage.c
+libtu_a_LIBADD = @LIBOBJS@
+END
+
+: > fsusage.c
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+
+grep 'automatically discovered.*fsusage\.c.*explicitly mentioned' stderr
+
+:
diff --git a/t/dist-auxdir-many-subdirs.sh b/t/dist-auxdir-many-subdirs.sh
new file mode 100644
index 000000000..486375fbe
--- /dev/null
+++ b/t/dist-auxdir-many-subdirs.sh
@@ -0,0 +1,137 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# It should be legitimate for many subdir Makefiles to require the
+# same config-aux files.
+
+am_create_testdir=empty
+required=cc
+. test-init.sh
+
+count=0
+ocwd=$(pwd) || fatal_ "cannot get current working directory"
+
+# Usage: do_check [--add-missing] [CONFIG-AUXDIR-PATH=.]
+do_check ()
+{
+ case $1 in
+ -a|--add-missing) add_missing=yes; shift;;
+ *) add_missing=no;;
+ esac
+ auxdir=${1-.}
+
+ count=$(($count + 1))
+ mkdir T$count.d
+ cd T$count.d
+
+ distdir=$me-$count
+ unindent > configure.ac << END
+ AC_INIT([$me], [$count])
+ AC_CONFIG_AUX_DIR([$auxdir])
+ AM_INIT_AUTOMAKE
+ AC_PROG_CC
+ # We don't want to require python or emcas in this test, so
+ # the tricks below.
+ AM_PATH_PYTHON([2.2], [], [:])
+ EMACS=no; AM_PATH_LISPDIR
+ AC_CONFIG_FILES([Makefile])
+END
+
+ unindent > Makefile.stub <<'END'
+ ## For depcomp.
+ bin_PROGRAMS = foo
+ foo_SOURCES = foo.c
+ ## For py-compile.
+ python_PYTHON = bar.py
+ ## For test-driver.
+ TESTS =
+END
+
+ required_files='
+ install-sh
+ missing
+ compile
+ depcomp
+ py-compile
+ test-driver
+ '
+
+ echo "SUBDIRS =" > Makefile.am
+
+ suffixes='0 1 2 3 4 5 6 7 8 9'
+
+ for x in $suffixes; do
+ mkdir sub$x
+ echo "SUBDIRS += sub$x" >> Makefile.am
+ echo "AC_CONFIG_FILES([sub$x/Makefile])" >> configure.ac
+ cp Makefile.stub sub$x/Makefile.am
+ echo 'int main (void) { return 0; }' > sub$x/foo.c
+ touch sub$x/bar.py sub$x/baz.el
+ done
+ echo AC_OUTPUT >> configure.ac
+
+ $ACLOCAL
+ $AUTOCONF
+
+ "$am_scriptdir"/install-sh -d $auxdir \
+ || fatal_ "creating directory '$auxdir' with install-sh"
+ if test $add_missing = yes; then
+ $AUTOMAKE -a --copy
+ for f in $required_files; do
+ test -f $auxdir/$f
+ # To ensure that if a auxiliary file is required and distributed
+ # by many Makefiles, the "dist" rule won't try to copy it multiple
+ # times in $(distdir).
+ chmod a-w $auxdir/$f
+ done
+ else
+ for f in $required_files; do
+ cp "$am_scriptdir"/$f $auxdir/$f \
+ || fatal_ "faild to fetch auxiliary script '$f'"
+ # See comments above.
+ chmod a-w $auxdir/$f
+ done
+ $AUTOMAKE
+ fi
+
+ for vpath in : false; do
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+ $srcdir/configure
+ $MAKE distdir
+ find $distdir # For debugging.
+ for f in $required_files; do
+ test -f $distdir/$auxdir/$f
+ done
+ cd $srcdir
+ done
+
+ cd "$ocwd" || fatal_ "cannot chdir back to '$ocwd'"
+}
+
+do_check .
+do_check --add-missing .
+do_check build-aux
+do_check --add-missing build-aux
+do_check a/b/c
+do_check --add-missing a/b/c
+
+:
diff --git a/t/dist-auxfile-2.sh b/t/dist-auxfile-2.sh
new file mode 100644
index 000000000..f9a60d7fa
--- /dev/null
+++ b/t/dist-auxfile-2.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Files specified by AC_REQUIRE_AUX_FILE must exist, and if a Makefile
+# is present in the build-aux directory, they correctly get automatically
+# distributed.
+# Related to automake bug#9651.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([sub])
+AM_INIT_AUTOMAKE
+AC_REQUIRE_AUX_FILE([zardoz])
+AC_CONFIG_FILES([Makefile sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+test: distdir
+ ls -l $(distdir) $(distdir)/* ;: For debugging.
+ test -f $(distdir)/sub/zardoz
+.PHONY: test
+check-local: test
+END
+
+mkdir sub
+: > sub/Makefile.am
+
+echo dummy > sub/zardoz
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+test -f sub/install-sh
+# Should work also without '--add-missing'.
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/dist-auxfile.sh b/t/dist-auxfile.sh
new file mode 100644
index 000000000..70adcae3d
--- /dev/null
+++ b/t/dist-auxfile.sh
@@ -0,0 +1,95 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Files specified by AC_REQUIRE_AUX_FILE must exist, and they get
+# automatically distributed by the top-level Makefile.am.
+# Automake bug#9651 reported that this didn't happen when the build-aux
+# directory was set to '.' by AC_CONFIG_AUX_DIR.
+
+am_create_testdir=empty
+. test-init.sh
+
+i=0
+for auxdir in build-aux ''; do
+
+ echo "*** Testing with auxdir '$auxdir' ***"
+
+ i=$(($i + 1))
+ mkdir T$i.d
+ cd T$i.d
+
+ unindent > configure.ac <<END
+ AC_INIT([$me], [1.0])
+ AC_CONFIG_AUX_DIR([${auxdir:-.}])
+ AM_INIT_AUTOMAKE
+ AC_REQUIRE_AUX_FILE([foo.txt])
+ AC_REQUIRE_AUX_FILE([bar.sh])
+ AC_REQUIRE_AUX_FILE([zardoz])
+ AC_CONFIG_FILES([Makefile subdir/Makefile])
+ AC_OUTPUT
+END
+
+ echo auxdir = ${auxdir:+"$auxdir/"} > Makefile.am
+ unindent >> Makefile.am <<'END'
+ SUBDIRS = subdir
+ test: distdir
+ ls -l $(distdir) $(distdir)/* ;: For debugging.
+ @echo DIST_COMMON = $(DIST_COMMON) ;: Likewise.
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]$(auxdir)foo.txt '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]$(auxdir)bar.sh '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]$(auxdir)zardoz '
+ test -f $(distdir)/$(auxdir)foo.txt
+ test -f $(distdir)/$(auxdir)bar.sh
+ test -f $(distdir)/$(auxdir)zardoz
+ .PHONY: test
+ check-local: test
+END
+
+ mkdir subdir
+ : > subdir/Makefile.am
+
+ test -z "$auxdir" || mkdir "$auxdir" || exit 99
+
+ if test -z "$auxdir"; then
+ auxdir=.
+ auxdir_rx='\.'
+ else
+ auxdir_rx=$auxdir
+ fi
+
+ $ACLOCAL
+ $AUTOCONF
+
+ AUTOMAKE_fails
+ grep "^configure\\.ac:4:.* required file.*$auxdir_rx/foo\\.txt" stderr
+ grep "^configure\\.ac:5:.* required file.*$auxdir_rx/bar\\.sh" stderr
+ grep "^configure\\.ac:6:.* required file.*$auxdir_rx/zardoz" stderr
+
+ touch $auxdir/foo.txt $auxdir/bar.sh $auxdir/zardoz
+ cp "$am_scriptdir"/missing "$am_scriptdir"/install-sh $auxdir \
+ || fatal_ "fetching auxiliary scripts 'missing' and 'install-sh'"
+ $AUTOMAKE
+ ./configure
+ $MAKE test
+ $EGREP '(foo\.txt|bar\.sh|zardoz)' subdir/Makefile.in && exit 1
+
+ $MAKE distcheck
+
+ cd ..
+
+done
+
+:
diff --git a/t/dist-formats.tap b/t/dist-formats.tap
new file mode 100644
index 000000000..a597964c2
--- /dev/null
+++ b/t/dist-formats.tap
@@ -0,0 +1,469 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for different compression formats used by distribution
+# archives.
+
+am_create_testdir=empty
+. test-init.sh
+
+plan_ 66
+
+# ---------------------------------------------------- #
+# Common and/or auxiliary subroutines and variables. #
+# ---------------------------------------------------- #
+
+ocwd=$(pwd) || fatal_ "getting current working directory"
+
+unset TAR
+
+# Create common aclocal.m4 file, for later tests.
+mkdir setup \
+ && cd setup \
+ && echo 'AC_INIT([x], [0]) AM_INIT_AUTOMAKE' > configure.ac \
+ && $ACLOCAL \
+ && mv aclocal.m4 .. \
+ && cd .. \
+ && rm -rf setup \
+ || fatal_ "creating common aclocal.m4 file"
+
+# Some make implementations (e.g., HP-UX) don't grok '-j', some require
+# no space between '-j' and the number of jobs (e.g., older GNU make
+# versions), and some *do* require a space between '-j' and the number
+# of jobs (e.g., Solaris dmake). We need a runtime test to see what
+# works.
+for MAKE_j4 in "$MAKE -j4" "$MAKE -j 4" false; do
+ echo all: | $MAKE_j4 -f - && break
+ : For shells with buggy 'set -e'.
+done
+
+# Set variables '$compressor' and '$suffix'.
+setup_vars_for_compression_format ()
+{
+ suffix=NONE compressor=NONE
+ case $1 in
+ gzip) suffix=tar.gz compressor=gzip ;;
+ lzip) suffix=tar.lz compressor=lzip ;;
+ xz) suffix=tar.xz compressor=xz ;;
+ bzip2) suffix=tar.bz2 compressor=bzip2 ;;
+ zip) suffix=zip compressor=zip ;;
+ *) fatal_ "invalid compression format '$1'";;
+ esac
+}
+
+have_compressor ()
+{
+ test $# -eq 1 || fatal_ "have_compressor(): bad usage"
+ if test $1 = gzip; then
+ # Assume gzip(1) is available on every reasonable portability target.
+ return 0
+ fi
+ needed_programs=$1
+ # Assume by default the other compressors we care about support the
+ # '--version' option. We'll special-case the one which don't.
+ checker_option=--version
+ case $1 in
+ bzip2)
+ # Do not use --version, or older versions bzip2 would try to
+ # compress stdin. This would cause binary output in the test
+ # logs, with potential breakage of our testsuite harness.
+ checker_option=--help
+ ;;
+ zip)
+ # OpenSolaris zip do not support the '--version' option, but
+ # accepts the '-v' one with a similar meaning (if no further
+ # arguments are given).
+ checker_option=-v
+ # Also, we need 'unzip' to decompress the created zipped archives
+ # (bug#15181).
+ needed_programs='zip unzip'
+ ;;
+ esac
+ # Redirect to stderr to avoid polluting the output, in case this
+ # function is used in a command substitution (as it is, later in
+ # this script).
+ for p in $needed_programs; do
+ $p $checker_option </dev/null >&2 || return 1
+ done
+ return 0
+}
+
+all_compression_formats='gzip lzip xz bzip2 zip'
+
+all_compressors=$(
+ for x in $all_compression_formats; do
+ setup_vars_for_compression_format $x
+ echo $compressor
+ done | tr "$nl" ' ')
+echo All compressors: $all_compressors
+
+missing_compressors=$(
+ for c in $all_compressors; do
+ have_compressor $c || echo $c
+ done | tr "$nl" ' ')
+echo Missing compressors: $missing_compressors
+
+# Redefine to avoid re-running the already executed checks.
+have_compressor ()
+{
+ case " $missing_compressors " in *\ $1\ *) false;; *) : ;; esac
+}
+
+have_all_compressors ()
+{
+ test -z "$missing_compressors"
+}
+
+start_subtest ()
+{
+ name=$1; shift
+ test -n "$name" || fatal_ "start_subtest: no subtest name given"
+ if test $# -gt 0; then
+ eval "$@" || fatal_ "start_subtest: evaluating assignments"
+ fi
+ ac_opts=$(echo $ac_opts | tr ',' ' ')
+ am_opts=$(echo $am_opts | tr ',' ' ')
+ mkdir "$name"
+ cd "$name"
+ unindent > configure.ac <<END
+ AC_INIT([$name], [1.0])
+ AM_INIT_AUTOMAKE([$ac_opts])
+ AC_CONFIG_FILES([Makefile])
+ AC_OUTPUT
+END
+ echo "AUTOMAKE_OPTIONS = $am_opts" > Makefile.am
+ # It is imperative that aclocal.m4 is copied after configure.ac has
+ # been created, to avoid a spurious trigger of the automatic remake
+ # rules for configure & co.
+ cp "$ocwd"/aclocal.m4 \
+ "$am_scriptdir"/missing \
+ "$am_scriptdir"/install-sh \
+ .
+}
+
+end_subtest ()
+{
+ unset name; unset ac_opts; unset am_opts;
+ cd "$ocwd" || fatal_ "couldn't chdir back to '$ocwd'"
+}
+
+command_ok_if_have_compressor ()
+{
+ if have_compressor "$compressor"; then
+ command_ok_ "$@"
+ else
+ skip_ -r "'$compressor' not available" "$1"
+ fi
+}
+
+can_compress ()
+{
+ test $# -eq 2 || fatal_ "can_compress: bad number of arguments"
+ tarname=$1 format=$2
+ setup_vars_for_compression_format "$format"
+
+ command_ok_ "'dist-$format' target always created" $MAKE -n dist-$format
+
+ command_ok_if_have_compressor "'make dist-$format' work by default" \
+ eval '
+ rm -rf *$tarname* \
+ && $MAKE dist-$format \
+ && test -f $tarname-1.0.$suffix \
+ && ls -l *$tarname* \
+ && test "$(echo *$tarname*)" = $tarname-1.0.$suffix'
+
+ unset suffix compressor format tarname
+}
+
+# ---------------------------------------- #
+# Defaults layout of the dist-* targets. #
+# ---------------------------------------- #
+
+start_subtest defaults
+
+command_ok_ "default [automake]" $AUTOMAKE
+command_ok_ "default [autoconf]" $AUTOCONF
+command_ok_ "default [configure]" ./configure
+command_ok_ "default [make distcheck]" $MAKE distcheck
+
+command_ok_ "'make dist' only builds *.tar.gz by default" \
+ test "$(ls *defaults*)" = defaults-1.0.tar.gz
+
+rm -rf *defaults*
+
+for fmt in $all_compression_formats; do
+ can_compress defaults $fmt
+done
+unset fmt
+
+end_subtest
+
+# ----------------------------------------------------------- #
+# Check diagnostic for no-dist-gzip without another dist-*. #
+# ----------------------------------------------------------- #
+
+nogzip_stderr ()
+{
+ grep "$1:.*no-dist-gzip" stderr \
+ && grep "$1:.* at least one archive format must be enabled" stderr
+}
+
+nogzip_automake_failure ()
+{
+ AUTOMAKE_fails -d "no-dist-gzip ($1) without other formats is an error"
+ command_ok_ "no-dist-gzip ($1) without other formats gives diagnostic" \
+ nogzip_stderr "$2"
+}
+
+start_subtest am-nogz-only am_opts=no-dist-gzip ac_opts=
+nogzip_automake_failure 'am' 'Makefile\.am:1'
+end_subtest
+
+start_subtest ac-nogz-only am_opts= ac_opts=no-dist-gzip
+nogzip_automake_failure 'ac' 'configure\.ac:2'
+end_subtest
+
+# ------------------------------------------------- #
+# Check use of no-dist-gzip with a dist-* option. #
+# ------------------------------------------------- #
+
+append_to_opt ()
+{
+ var=$1_opts val=$2
+ eval "$var=\${$var:+\"\$$var,\"}\$val" || fatal_ "evaluating \${$var}"
+ unset var val
+}
+
+nogzip ()
+{
+ test $#,$1,$3,$5 = 6,in,and,in \
+ && case $2,$6 in ac,ac|ac,am|am,ac|am,am) :;; *) false;; esac \
+ || fatal_ "nogzip: invalid usage"
+ format=$4 where_dist_nogzip=$2 where_dist_format=$6
+ shift 6
+
+ am_opts= ac_opts=
+ append_to_opt $where_dist_format dist-$format
+ append_to_opt $where_dist_nogzip no-dist-gzip
+ setup_vars_for_compression_format "$format"
+ # Do these before the am_opts and ac_opts variable can be munged
+ # by 'start_subtest'.
+ desc=
+ test -n "$am_opts" && desc=${desc:+"$desc "}"am=$am_opts"
+ test -n "$ac_opts" && desc=${desc:+"$desc "}"ac=$ac_opts"
+
+ start_subtest nogzip-$format am_opts=$am_opts ac_opts=$ac_opts
+
+ unindent >> Makefile.am <<END
+ check-ark-name:
+ test \$(DIST_ARCHIVES) = \$(distdir).$suffix
+ check-ark-exists:
+ test -f \$(distdir).$suffix
+ check-no-tar-gz:
+ test ! -f \$(distdir).tar.gz
+END
+
+ command_ok_ "$desc [automake]" $AUTOMAKE
+ command_ok_ "$desc [autoconf]" $AUTOCONF
+ command_ok_ "$desc [configure]" ./configure
+ command_ok_ "$desc [ark-name]" $MAKE check-ark-name
+ command_ok_if_have_compressor "$desc [distcheck]" $MAKE distcheck
+ command_ok_if_have_compressor "$desc [ark-exists]" $MAKE check-ark-exists
+ command_ok_ "$desc [no .tar.gz]" $MAKE check-no-tar-gz
+
+ unset desc
+
+ end_subtest
+}
+
+# $1 $2 $3 $4 $5 $6
+nogzip in am and bzip2 in am
+nogzip in ac and xz in am
+nogzip in am and lzip in ac
+nogzip in ac and zip in ac
+
+
+# ----------------------------------------------------------- #
+# The 'dist-gzip' target is created also with no-dist-gzip. #
+# ----------------------------------------------------------- #
+
+start_subtest dist-gzip-persistence am_opts=no-dist-gzip,dist-xz
+command_ok_ "dist-gzip persistence [automake]" $AUTOMAKE
+command_ok_ "dist-gzip persistence [autoconf]" $AUTOCONF
+command_ok_ "dist-gzip persistence [configure]" ./configure
+can_compress dist-gzip-persistence gzip
+end_subtest
+
+
+# ----------------------- #
+# Parallel compression. #
+# ----------------------- #
+
+# We only use formats requiring 'gzip', 'bzip2' and 'xz' programs,
+# since there are the most likely to be all found on the majority
+# of systems.
+
+start_subtest parallel-compression ac_opts=dist-bzip2 am_opts=dist-xz
+
+desc=gzip+bzip2+xz
+tarname=parallel-compression-1.0
+
+check_tarball ()
+{
+ format=$1
+ setup_vars_for_compression_format $format
+ (
+ tarball=$tarname.$suffix \
+ && test -f $tarball \
+ && mkdir check-$format \
+ && cp $tarball check-$format \
+ && cd check-$format \
+ && $compressor -d $tarball \
+ && tar xvf $tarname.tar \
+ && diff ../Makefile.in $tarname/Makefile.in \
+ && cd .. \
+ && rm -rf check-$format
+ )
+}
+
+command_ok_ "$desc [automake]" $AUTOMAKE
+
+if ! have_compressor xz && ! have_compressor bzip2; then
+ skip_reason="both 'bzip2' and 'xz' are unavailable"
+elif ! have_compressor xz; then
+ skip_reason="'xz' not available"
+elif ! have_compressor bzip2; then
+ skip_reason="'bzip2' not available"
+else
+ skip_reason=
+fi
+if test "$MAKE_j4" = false; then
+ test -z "$skip_reason" || skip_reason="$skip_reason, and "
+ skip_reason="${skip_reason}make concurrency unavailable"
+fi
+
+if test -n "$skip_reason"; then
+ skip_row_ 6 -r "$skip_reason" "$desc"
+else
+ command_ok_ "$desc [autoconf]" $AUTOCONF
+ command_ok_ "$desc [configure]" ./configure
+ command_ok_ "$desc [make -j4 dist-all]" $MAKE_j4 dist
+ ls -l # For debugging.
+ command_ok_ "$desc [check .tar.gz tarball]" check_tarball gzip
+ command_ok_ "$desc [check .tar.bz2 tarball]" check_tarball bzip2
+ command_ok_ "$desc [check .tar.xz tarball]" check_tarball xz
+fi
+
+unset tarname desc skip_reason
+
+end_subtest
+
+
+# --------------------------------------------------------- #
+# The various 'dist-*' targets can happily work together. #
+# --------------------------------------------------------- #
+
+start_subtest all-together
+
+desc='all compressors together'
+tarname=all-together-1.0
+
+echo 'AM_INIT_AUTOMAKE([' > am-init.m4
+echo 'AUTOMAKE_OPTIONS =' > Makefile.am
+
+# Add half 'dist-*' options to AM_INIT_AUTOMAKE, half to AUTOMAKE_OPTIONS.
+flip=:
+for fmt in $all_compression_formats; do
+ test $fmt = gzip && continue
+ if $flip; then
+ echo " dist-$fmt" >> am-init.m4
+ flip=false
+ else
+ echo "AUTOMAKE_OPTIONS += dist-$fmt" >> Makefile.am
+ flip=:
+ fi
+done
+unset flip fmt
+
+echo '])' >> am-init.m4
+
+sed 's/AM_INIT_AUTOMAKE.*/m4_include([am-init.m4])/' configure.ac > t
+mv -f t configure.ac
+
+# For debugging.
+cat Makefile.am
+cat configure.ac
+cat am-init.m4
+
+command_ok_ "$desc [aclocal]" $ACLOCAL --force
+command_ok_ "$desc [automake]" $AUTOMAKE
+command_ok_ "$desc [autoconf]" $AUTOCONF
+command_ok_ "$desc [configure]" ./configure
+
+if have_all_compressors; then
+ command_ok_ "$desc [make distcheck, real]" $MAKE distcheck
+else
+ skip_ -r "not all compressors available" "$desc [make distcheck, real]"
+fi
+
+# We fake existence of all the compressors here, so that we don't have
+# to require any of them to run the further tests. This is especially
+# important since it's very unlikely that a non-developer has all the
+# compression tools installed on his machine at the same time.
+
+mkdir bin
+cd bin
+cat > check-distdir <<END
+#!/bin/sh
+{ ls -l '$tarname' && diff Makefile.am '$tarname'/Makefile.am; } >&2 \
+ || { echo "== distdir fail =="; exit 1; }
+END
+cat > grep-distdir-error <<'END'
+#!/bin/sh
+grep 'distdir fail' && exit 1
+:
+END
+chmod a+x check-distdir grep-distdir-error
+for prog in tar $all_compressors; do
+ case $prog in
+ tar|zip) cp check-distdir $prog;;
+ *) cp grep-distdir-error $prog;;
+ esac
+done
+unset prog
+ls -l # For debugging.
+cd ..
+
+oPATH=$PATH
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
+
+command_ok_ \
+ "$desc ['make dist-all', stubbed]" \
+ $MAKE dist-all
+
+subdesc="$desc ['make dist -j4', stubbed]"
+if test "$MAKE_j4" = false; then
+ skip_ -r "make concurrency unavailable" "$subdesc"
+else
+ command_ok_ "$subdesc" $MAKE_j4 dist
+fi
+unset subdesc
+
+PATH=$oPATH; export PATH
+
+end_subtest
+
+:
diff --git a/t/dist-included-parent-dir.sh b/t/dist-included-parent-dir.sh
new file mode 100644
index 000000000..5ebb8f4bd
--- /dev/null
+++ b/t/dist-included-parent-dir.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure included files in parent directory are distributed.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+test: distdir
+ test -f $(distdir)/foo
+ test -f $(distdir)/bar
+ test 2 -gt `find $(distdir)/sub -type d | wc -l`
+END
+
+: > foo
+: > bar
+
+mkdir sub
+cat > sub/Makefile.am << 'END'
+include $(top_srcdir)/foo
+include ../bar
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+# Use --srcdir with an absolute path because it's harder
+# to support in 'distdir'.
+./configure --srcdir "$(pwd)"
+$MAKE test
+
+:
diff --git a/t/dist-install-sh.sh b/t/dist-install-sh.sh
new file mode 100644
index 000000000..441982e7b
--- /dev/null
+++ b/t/dist-install-sh.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug where install-sh not included in distribution.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+pkgdata_DATA =
+.PHONY: test
+test: distdir
+ find $(distdir) ;: For debugging.
+ echo ' ' $(DISTFILES) ' ' | grep '[ /]install-sh '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]install-sh '
+ test -f $(distdir)/install-sh
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE test
+
+:
diff --git a/t/dist-lzma.sh b/t/dist-lzma.sh
new file mode 100644
index 000000000..d5da5a3e6
--- /dev/null
+++ b/t/dist-lzma.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for no-dist-gzip with lzma.
+
+. test-init.sh
+
+errmsg='support for lzma.*removed'
+
+echo AUTOMAKE_OPTIONS = dist-lzma > Makefile.am
+$ACLOCAL --force
+AUTOMAKE_fails -Wnone -Wno-error
+grep "^Makefile\\.am:1:.*$errmsg" stderr
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([no-dist-gzip dist-lzma])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+: > Makefile.am
+
+rm -rf autom4te*.cache
+$ACLOCAL
+AUTOMAKE_fails -Wnone -Wno-error
+grep "^configure\\.ac:2:.*$errmsg" stderr
+
+:
diff --git a/t/dist-missing-am.sh b/t/dist-missing-am.sh
new file mode 100644
index 000000000..7b564d6ef
--- /dev/null
+++ b/t/dist-missing-am.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The stub rules emitted to work around the "deleted header problem"
+# for '.am' files shouldn't prevent "make" from diagnosing a missing
+# required '.am' file from a distribution tarball.
+# See discussion about automake bug#9768.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+include $(srcdir)/foobar.am
+include $(srcdir)/zardoz.am
+END
+
+: > foobar.am
+: > zardoz.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# A faulty distribution tarball, with a required '.am' file missing.
+# Building from it should fail, both for in-tree and VPATH builds.
+ocwd=$(pwd) || fatal_ "cannot get current working directory"
+for vpath in false :; do
+ $MAKE distdir
+ test -f $distdir/zardoz.am # Sanity check.
+ rm -f $distdir/zardoz.am
+ if $vpath; then
+ # We can't just build in a subdirectory of $distdir, otherwise
+ # we'll hit automake bug#10111.
+ mkdir vpath-distcheck
+ cd vpath-distcheck
+ ../$distdir/configure
+ else
+ cd $distdir
+ ./configure
+ fi
+ run_make -e FAIL -M
+ # This error comes from automake, not make, so we can be stricter
+ # in our grepping of it.
+ grep 'cannot open.*zardoz\.am' output
+ grep 'foobar\.am' output && exit 1 # No spurious error, please.
+ cd "$ocwd" || fatal_ "cannot chdir back to top-level test directory"
+done
+
+:
diff --git a/t/dist-missing-included-m4.sh b/t/dist-missing-included-m4.sh
new file mode 100644
index 000000000..0ba466873
--- /dev/null
+++ b/t/dist-missing-included-m4.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The stub rules emitted to work around the "deleted header problem"
+# for '.m4' files shouldn't prevent "make" from diagnosing a missing
+# required '.m4' file from a distribution tarball.
+# See discussion about automake bug#9768.
+# See also sister test 'dist-missing-m4.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+m4_include([foobar.m4])
+m4_include([zardoz.m4])
+AC_OUTPUT
+END
+
+: > foobar.m4
+: > zardoz.m4
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# A faulty distribution tarball, with a required '.m4' file missing.
+# Building from it should fail, both for in-tree and VPATH builds.
+ocwd=$(pwd) || fatal_ "cannot get current working directory"
+for vpath in false :; do
+ $MAKE distdir
+ test -f $distdir/zardoz.m4 # Sanity check.
+ rm -f $distdir/zardoz.m4
+ if $vpath; then
+ # We can't just build in a subdirectory of $distdir, otherwise
+ # we'll hit automake bug#10111.
+ mkdir vpath-distcheck
+ cd vpath-distcheck
+ ../$distdir/configure
+ else
+ cd $distdir
+ ./configure
+ fi
+ run_make -e FAIL -M
+ # This error will come from automake, not make, so we can be stricter
+ # in our grepping of it.
+ grep 'zardoz\.m4.*does not exist' output
+ grep 'foobar\.m4' output && exit 1 # No spurious error, please.
+ cd "$ocwd" || fatal_ "cannot chdir back to top-level test directory"
+done
+
+:
diff --git a/t/dist-missing-m4.sh b/t/dist-missing-m4.sh
new file mode 100644
index 000000000..a721e2789
--- /dev/null
+++ b/t/dist-missing-m4.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The stub rules emitted to work around the "deleted header problem"
+# for '.m4' files shouldn't prevent "make" from diagnosing a missing
+# required '.m4' file from a distribution tarball.
+# See discussion about automake bug#9768.
+# See also sister test 'dist-missing-included-m4.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+m4_pattern_forbid([^MY_])
+MY_FOOBAR || exit 1
+MY_ZARDOZ || exit 1
+AC_OUTPUT
+END
+
+mkdir m4
+echo 'AC_DEFUN([MY_FOOBAR], [:])' > m4/foobar.m4
+echo 'AC_DEFUN([MY_ZARDOZ], [:])' > m4/zardoz.m4
+
+echo 'ACLOCAL_AMFLAGS = -I m4' > Makefile.am
+
+$ACLOCAL -I m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# A faulty distribution tarball, with a required '.m4' file missing.
+# Building from it should fail, both for in-tree and VPATH builds.
+ocwd=$(pwd) || fatal_ "cannot get current working directory"
+for vpath in false :; do
+ $MAKE distdir
+ test -f $distdir/m4/zardoz.m4 # Sanity check.
+ rm -f $distdir/m4/zardoz.m4
+ if $vpath; then
+ # We can't just build in a subdirectory of $distdir, otherwise
+ # we'll hit automake bug#10111.
+ mkdir vpath-distcheck
+ cd vpath-distcheck
+ ../$distdir/configure
+ else
+ cd $distdir
+ ./configure
+ fi
+ run_make -e FAIL -M
+ # This error will come from autoconf, not make, so we can be stricter
+ # in our grepping of it.
+ grep 'possibly undefined .*MY_ZARDOZ' output
+ grep 'MY_FOOBAR' output && exit 1 # No spurious error, please.
+ cd "$ocwd" || fatal_ "cannot chdir back to top-level test directory"
+done
+
+:
diff --git a/t/dist-pr109765.sh b/t/dist-pr109765.sh
new file mode 100644
index 000000000..031301bf4
--- /dev/null
+++ b/t/dist-pr109765.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Expose automake bug#10975: when several "dist-*" targets are invoked
+# on the make command line, the first one ends up removing the distdir,
+# so that the latter ones fail.
+
+required=bzip2
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+: > Makefile.am
+
+$ACLOCAL || fatal_ "aclocal failed"
+$AUTOCONF || fatal_ "autoconf failed"
+$AUTOMAKE || fatal_ "automake failed"
+
+./configure
+$MAKE dist-gzip dist-bzip2
+
+gzip -dc $distdir.tar.gz | tar tf - > one || { cat one; exit 1; }
+cat one
+bzip2 -dc $distdir.tar.gz | tar tf - > two || { cat two; exit 1; }
+cat two
+
+$FGREP "$distdir/Makefile.am" one
+diff one two
+
+:
diff --git a/t/dist-readonly.sh b/t/dist-readonly.sh
new file mode 100644
index 000000000..2b4124851
--- /dev/null
+++ b/t/dist-readonly.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that a readonly files are distributed as such, and not make
+# writable while being copied in the $(distdir).
+
+# This test expect the user to be unable to write on files lacking
+# write permissions -- so it won't work if the user is 'root'.
+required='non-root cc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c
+EXTRA_DIST = bar.txt
+check-local: test
+.PHONY: test
+test:
+ test -f $(srcdir)/foo.c && test ! -w $(srcdir)/foo.c
+ if (echo x > $(srcdir)/foo.c); then exit 1; else :; fi
+ grep 'main (void)' $(srcdir)/foo.c
+ test -f $(srcdir)/bar.txt && test ! -w $(srcdir)/bar.txt
+ if (echo x > $(srcdir)/bar.txt); then exit 1; else :; fi
+ grep 'To be, or not to be' $(srcdir)/bar.txt
+END
+
+echo 'int main (void) { return 0; }' > foo.c
+echo To be, or not to be ... > bar.txt
+chmod a-w foo.c bar.txt
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE distdir
+ls -l $distdir # For debugging.
+test -f foo.c && test ! -w foo.c || exit 1
+(echo x > foo.c) && exit 1
+test -f bar.txt && test ! -w bar.txt || exit 1
+(echo x > bar.txt) && exit 1
+$MAKE distcheck
+
+:
diff --git a/t/dist-repeated.sh b/t/dist-repeated.sh
new file mode 100644
index 000000000..2b9ee05f2
--- /dev/null
+++ b/t/dist-repeated.sh
@@ -0,0 +1,102 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that we can distribute the same file as many times as we want.
+# The distdir target should take care of not copying it more than one
+# time anyway.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo bar
+foo_SOURCES = foo.c
+bar_SOURCES = foo.c
+python_PYTHON = bar.py
+EXTRA_DIST = foo.c bar.py
+
+.PHONY: sanity-check
+sanity-check:
+ for f in $(DISTFILES); do echo " $$f "; done > dist.txt
+ cat dist.txt
+ test `grep ' foo\.c ' dist.txt | wc -l` -eq 3
+ test `grep ' bar\.py ' dist.txt | wc -l` -eq 2
+
+# So that we don't have to require a C compiler.
+AUTOMAKE_OPTIONS = no-dependencies
+CC = false
+
+# So that we don't have to require a Python interpreter.
+pythondir = ${prefix}/py
+PYTHON = false
+END
+
+ocwd=$(pwd) || fatal_ "cannot get current working directory"
+
+# Help to ensure cp won't see the same file twice.
+mkdir bin
+cat > bin/cp <<END
+#!/bin/sh
+PATH='$PATH'; export PATH
+
+case " \$* " in
+ *foo.c\ *)
+ if test -f '$ocwd'/foo-c-copied; then
+ echo "\$0: we tried to copy foo.c twice" >&2
+ exit 1
+ else
+ # For a sanity check later.
+ echo ok > '$ocwd'/cp-wrapper-has-seen-foo-c
+ fi
+ ;;
+esac
+
+case " \$* " in
+ *bar.py\ *)
+ if test -f '$ocwd'/bar-py-copied; then
+ echo "\$0: we tried to copy bar.py twice" >&2
+ exit 1
+ else
+ # For a sanity check later.
+ echo ok > '$ocwd'/cp-wrapper-has-seen-bar-py
+ fi
+ ;;
+esac
+
+exec cp "\$@"
+END
+chmod a+x bin/cp
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH;
+
+: > foo.c
+: > bar.py
+: > py-compile
+
+# Help to ensure cp won't try to copy the same file twice.
+chmod a-w foo.c bar.py
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE sanity-check || fatal_ "expected invariants not verified"
+$MAKE distdir
+test -f cp-wrapper-has-seen-foo-c && test -f cp-wrapper-has-seen-bar-py \
+ || fatal_ "our cp wrapper hasn't run correctly"
+
+:
diff --git a/t/dist-shar.sh b/t/dist-shar.sh
new file mode 100644
index 000000000..611480c2c
--- /dev/null
+++ b/t/dist-shar.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for no-dist-gzip with dist-shar.
+
+required='shar unshar'
+. test-init.sh
+
+errmsg='support for shar .*deprecated'
+
+echo AUTOMAKE_OPTIONS = dist-shar > Makefile.am
+$ACLOCAL
+AUTOMAKE_fails -Wnone -Wobsolete
+grep "^Makefile\\.am:1:.*$errmsg" stderr
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([no-dist-gzip dist-shar])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+: > Makefile.am
+
+rm -rf autom4te*.cache
+$ACLOCAL
+AUTOMAKE_run -Wno-error
+grep "^configure\\.ac:2:.*$errmsg" stderr
+
+$AUTOCONF
+./configure
+$MAKE distcheck
+test -f $distdir.shar.gz
+
+:
diff --git a/t/dist-tarZ.sh b/t/dist-tarZ.sh
new file mode 100644
index 000000000..c4888facc
--- /dev/null
+++ b/t/dist-tarZ.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for no-dist-gzip with dist-tarZ.
+
+. test-init.sh
+
+# On Cygwin, as of 9/2/2012, 'compress' is provided by sharutils
+# and is just a dummy script that is not able to actually compress
+# (it can only decompress). So, check that the 'compress' program
+# is actually able to compress input.
+# Note that, at least on GNU/Linux, 'compress' does (and is
+# documented to) exit with status 2 if the output is larger than
+# the input after (attempted) compression; so we need to pass it
+# an input that it can actually reduce in size when compressing.
+for x in 1 2 3 4 5 6 7 8; do
+ echo aaaaaaaaaaaaaaaaaaaaa
+done | compress -c >/dev/null \
+ || skip_ "cannot find a working 'compress' program"
+
+errmsg=".*legacy .*'compress' .*deprecated"
+
+echo AUTOMAKE_OPTIONS = dist-tarZ > Makefile.am
+$ACLOCAL
+AUTOMAKE_fails -Wnone -Wobsolete
+grep "^Makefile\\.am:1:.*$errmsg" stderr
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([no-dist-gzip dist-tarZ])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+: > Makefile.am
+
+rm -rf autom4te*.cache
+$ACLOCAL
+AUTOMAKE_run -Wno-error
+grep "^configure\\.ac:2:.*$errmsg" stderr
+
+$AUTOCONF
+./configure
+$MAKE distcheck
+test -f dist-tarz-1.0.tar.Z
+
+:
diff --git a/t/dist-with-unreadable-makefile-fails.sh b/t/dist-with-unreadable-makefile-fails.sh
new file mode 100644
index 000000000..21fd10886
--- /dev/null
+++ b/t/dist-with-unreadable-makefile-fails.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in 'make dist'
+# From Pavel Roskin.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+dnl Prevent automake from looking in .. and ../..
+AC_CONFIG_AUX_DIR([.])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = .
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+chmod 000 Makefile.am
+
+# On some systems (like DOS and Windows), files are always readable.
+test ! -r Makefile.am || skip_ "cannot drop file read permissions"
+
+./configure
+
+# 'dist' should fail because we can't copy Makefile.am.
+if $MAKE dist; then
+ exit 1
+else
+ exit 0
+fi
diff --git a/t/distcheck-configure-flags-am.sh b/t/distcheck-configure-flags-am.sh
new file mode 100644
index 000000000..9d205d1ee
--- /dev/null
+++ b/t/distcheck-configure-flags-am.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for AM_DISTCHECK_CONFIGURE_FLAGS at "make distcheck"
+# time, and its interactions with DISTCHECK_CONFIGURE_FLAGS.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_ARG_ENABLE([success], [], [success=$enableval], [success=no])
+AS_IF([test $success = yes && test "$sentence" = 'it works :-)'],
+ [:],
+ [AC_MSG_ERROR([success='$success', sentence='$sentence'])])
+AC_OUTPUT
+END
+
+unset sentence
+
+cat > Makefile.am << 'END'
+AM_DISTCHECK_CONFIGURE_FLAGS = $(dc_flags1) $(dc_flags2)
+dc_flags1 = --enable-success sentence='it works :-)'
+dc_flags2 =
+END
+
+$ACLOCAL
+$AUTOMAKE
+$FGREP '$(DISTCHECK_CONFIGURE_FLAGS)' Makefile.in
+$FGREP '$(AM_DISTCHECK_CONFIGURE_FLAGS)' Makefile.in
+grep 'DISTCHECK_CONFIGURE_FLAGS.*AM_DISTCHECK_CONFIGURE_FLAGS' Makefile.in \
+ && exit 1
+
+$AUTOCONF
+./configure --enable-success sentence='it works :-)'
+
+# The configure call in "make distcheck" should honour
+# $(AM_DISTCHECK_CONFIGURE_FLAGS).
+
+$MAKE distcheck
+
+# $(DISTCHECK_CONFIGURE_FLAGS) takes precedence over
+# $(AM_DISTCHECK_CONFIGURE_FLAGS)
+
+cat >> Makefile.am << 'END'
+dc_flags2 += --disable-success
+END
+$AUTOMAKE Makefile
+./config.status Makefile
+
+run_make -e FAIL -M distcheck
+grep "^configure:.* success='no', sentence='it works :-)'" output
+
+$MAKE distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-success=yes"
+
+:
diff --git a/t/distcheck-configure-flags-subpkg.sh b/t/distcheck-configure-flags-subpkg.sh
new file mode 100644
index 000000000..e5bc8860b
--- /dev/null
+++ b/t/distcheck-configure-flags-subpkg.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check AM_DISTCHECK_CONFIGURE_FLAGS and DISTCHECK_CONFIGURE_FLAGS
+# are not honored in a subpackage Makefile.am, but the flags from
+# AM_DISTCHECK_CONFIGURE_FLAGS and DISTCHECK_CONFIGURE_FLAGS are
+# passed down to the configure script of the subpackage. This is
+# explicitly documented in the manual.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_SUBDIRS([subpkg])
+if test $dc != ok || test $am_dc != ok; then
+ AC_MSG_ERROR([dc=$dc am_dc=$dc])
+fi
+AC_OUTPUT
+END
+
+mkdir subpkg
+
+sed <configure.ac >subpkg/configure.ac \
+ -e 's/^AC_INIT.*/AC_INIT([subpkg], [2.0])/' \
+ -e '/^AC_CONFIG_SUBDIRS/d' \
+
+cat configure.ac
+cat subpkg/configure.ac
+
+dc=KO am_dc=KO; export dc am_dc
+
+cat > Makefile.am << 'END'
+AM_DISTCHECK_CONFIGURE_FLAGS = am_dc=ok
+DISTCHECK_CONFIGURE_FLAGS = dc=ok
+END
+
+: > subpkg/Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+cd subpkg
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+cd ..
+
+# For debugging.
+$FGREP 'DISTCHECK_CONFIGURE_FLAGS' Makefile.in subpkg/Makefile.in
+
+grep '^AM_DISTCHECK_CONFIGURE_FLAGS =' Makefile.in
+grep '^DISTCHECK_CONFIGURE_FLAGS =' Makefile.in
+$EGREP '^(AM_)?DISTCHECK_CONFIGURE_FLAGS' subpkg/Makefile.in && exit 1
+
+./configure dc=ok am_dc=ok
+
+# Flags in $(DISTCHECK_CONFIGURE_FLAGS) and $(AM_DISTCHECK_CONFIGURE_FLAGS)
+# should be passed down to the subpackage configure when "make distcheck"
+# is run from the top-level package ...
+$MAKE distcheck
+
+# ... but not when "make distcheck" is run from the subpackage.
+cd subpkg
+run_make -e FAIL -M distcheck
+grep '^configure:.* dc=KO am_dc=KO' output
+
+:
diff --git a/t/distcheck-configure-flags.sh b/t/distcheck-configure-flags.sh
new file mode 100644
index 000000000..5ac12f034
--- /dev/null
+++ b/t/distcheck-configure-flags.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for DISTCHECK_CONFIGURE_FLAGS at "make distcheck" time.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_ARG_ENABLE([success], [], [success=$enableval], [success=no])
+AS_IF([test $success = yes && test "$sentence" = 'it works :-)'],
+ [:],
+ [AC_MSG_ERROR([success='$success', sentence='$sentence'])])
+AC_OUTPUT
+END
+
+unset sentence
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+$FGREP '$(DISTCHECK_CONFIGURE_FLAGS)' Makefile.in
+
+$AUTOCONF
+./configure --enable-success sentence='it works :-)'
+
+# It should be ok to define DISTCHECK_CONFIGURE_FLAGS either on the
+# make command line or in the environment.
+
+env DISTCHECK_CONFIGURE_FLAGS='--enable-success sentence=it\ works\ :-\)' \
+ $MAKE distcheck
+
+$MAKE distcheck \
+ DISTCHECK_CONFIGURE_FLAGS="--enable-success=yes sentence='it works :-)'"
+
+# Sanity check.
+run_make -M -e FAIL distcheck
+grep "^configure:.* success='no', sentence=''" output
+
+:
diff --git a/t/distcheck-hook.sh b/t/distcheck-hook.sh
new file mode 100644
index 000000000..2174040d0
--- /dev/null
+++ b/t/distcheck-hook.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check basic support for distcheck-hook.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+distcheck-hook:
+ ls -l $(distdir)
+ chmod u+w $(distdir)
+ : > $(distdir)/dc-hook-has-run
+ chmod a-w $(distdir)
+check-local:
+ ls -l $(srcdir)
+ test -f $(srcdir)/dc-hook-has-run
+END
+
+$ACLOCAL
+$AUTOMAKE
+$FGREP 'distcheck-hook' Makefile.in
+$FGREP '$(MAKE) $(AM_MAKEFLAGS) distcheck-hook' Makefile.in
+grep '^distcheck-hook:' Makefile.in
+
+$AUTOCONF
+./configure
+
+$MAKE
+$MAKE check && exit 1
+$MAKE distdir
+test -f $distdir/dc-hook-has-run && exit 1
+$MAKE distcheck
+
+:
diff --git a/t/distcheck-hook2.sh b/t/distcheck-hook2.sh
new file mode 100644
index 000000000..a1e304ca6
--- /dev/null
+++ b/t/distcheck-hook2.sh
@@ -0,0 +1,79 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that no 'distcheck-hook' target is created automatically by
+# Automake, and that a used-defined 'distcheck-hook' is *not* honored
+# in a subpackage Makefile.am.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_SUBDIRS([subpkg])
+AC_OUTPUT
+END
+
+mkdir subpkg
+
+cat > subpkg/configure.ac << 'END'
+AC_INIT([subpkg], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+distcheck-hook:
+ ls -l $(distdir)
+ chmod u+w $(distdir)
+ : > $(distdir)/dc-hook-has-run
+ chmod a-w $(distdir)
+check-local:
+ ls -l $(srcdir)
+ test -f $(srcdir)/dc-hook-has-run
+END
+
+cat > subpkg/Makefile.am <<'END'
+check-local:
+ ls -l $(srcdir)
+ test ! -r $(srcdir)/dc-hook-has-run
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+cd subpkg
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+cd ..
+
+# For debugging.
+$FGREP 'distcheck-hook' Makefile.in subpkg/Makefile.in
+
+$FGREP 'distcheck-hook' subpkg/Makefile.in && exit 1
+$FGREP '$(MAKE) $(AM_MAKEFLAGS) distcheck-hook' Makefile.in
+grep '^distcheck-hook:' Makefile.in
+
+./configure
+
+$MAKE
+$MAKE check && exit 1
+cd subpkg
+$MAKE check
+cd ..
+$MAKE distcheck
+
+:
diff --git a/t/distcheck-missing-m4.sh b/t/distcheck-missing-m4.sh
new file mode 100644
index 000000000..c4e77e98c
--- /dev/null
+++ b/t/distcheck-missing-m4.sh
@@ -0,0 +1,116 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that we can define a distcheck-hook to diagnose m4 files
+# missing from the dist tarball (interaction with '--install').
+# See automake bug#9037.
+
+. test-init.sh
+
+cwd=$(pwd) || fatal_ "cannot get current working directory"
+
+cp "$am_testaux_srcdir"/distcheck-hook-m4.am . \
+ || fatal_ "cannot fetch makefile fragment 'distcheck-hook-m4.am'"
+
+cat > Makefile.am << 'END'
+## The lack of '--install' here is meant.
+ACLOCAL_AMFLAGS = -I m4
+include $(srcdir)/distcheck-hook-m4.am
+END
+
+cat >> configure.ac << 'END'
+dnl We *deliberately* don't use m4_pattern_forbid here.
+AC_OUTPUT
+MY_FOO
+MY_BAR
+MY_BAZ
+MY_ZAR
+END
+
+mkdir m4 acdir acdir1 acdir2 pth
+
+cat > acdir/dirlist << END
+$cwd/acdir1
+$cwd/acdir2
+END
+
+echo 'AC_DEFUN([MY_FOO], [:])' > m4/foo.m4
+echo 'AC_DEFUN([MY_BAR], [:])' > acdir1/bar.m4
+echo 'AC_DEFUN([MY_BAZ], [:])' > acdir1/baz.m4
+echo 'AC_DEFUN([MY_QUX], [:])' > acdir2/qux.m4
+echo 'AC_DEFUN([MY_ZAR], [:])' > pth/zar.m4
+echo 'AC_DEFUN([MY_BLA], [:])' > pth/bla.m4
+
+ACLOCAL="$ACLOCAL --system-acdir=$cwd/acdir"; export ACLOCAL
+ACLOCAL_PATH=$cwd/pth; export ACLOCAL_PATH
+
+# We don't use '--install' here. Our distcheck-hook should catch this.
+$ACLOCAL -I m4
+$AUTOCONF
+$EGREP 'MY_(FOO|BAR|BAZ|ZAR)' configure && exit 1 # Sanity check.
+$AUTOMAKE
+
+check_no_spurious_error ()
+{
+ $EGREP -i 'mkdir:|:.*(permission|denied)' output && exit 1
+ # On failure, some make implementations (such as Solaris make) print the
+ # whole failed recipe on stdout. The first grep works around this.
+ grep -v 'rm -rf ' output | grep -i 'autom4te.*\.cache' && exit 1
+ : To placate 'set -e'.
+}
+
+./configure
+
+run_make -M -e FAIL distcheck
+for x in bar baz zar; do
+ $EGREP "required m4 file.*not distributed.* $x.m4( |$)" output
+done
+check_no_spurious_error
+
+# Now we use '--install', and "make distcheck" should pass.
+$ACLOCAL -I m4 --install
+test -f m4/bar.m4 # Sanity check.
+test -f m4/baz.m4 # Likewise.
+test -f m4/zar.m4 # Likewise.
+using_gmake || $MAKE Makefile
+$MAKE distcheck
+
+# We start to use new "third-party" macros from new .m4 files, but forget
+# to re-run "aclocal --install" by hand, relying on automatic remake rules.
+# Our distcheck-hook should catch this too.
+cat >> configure.ac << 'END'
+MY_QUX
+MY_BLA
+END
+
+$MAKE
+$EGREP 'MY_(FOO|BAR|BAZ|QUX|ZAR|BLA)' configure && exit 1 # Sanity check.
+
+run_make -M -e FAIL distcheck
+$EGREP "required m4 file.*not distributed.* qux.m4( |$)" output
+$EGREP "required m4 file.*not distributed.* bla.m4( |$)" output
+check_no_spurious_error
+# Check that we don't complain for files that should have been found.
+$FGREP " (bar|baz|zar).m4" output && exit 1
+
+# Now we again use '--install', and "make distcheck" should pass.
+$ACLOCAL -I m4 --install
+test -f m4/qux.m4 # Sanity check.
+test -f m4/bla.m4 # Likewise.
+using_gmake || $MAKE Makefile
+$MAKE distcheck
+
+:
diff --git a/t/distcheck-no-prefix-or-srcdir-override.sh b/t/distcheck-no-prefix-or-srcdir-override.sh
new file mode 100644
index 000000000..e143e1229
--- /dev/null
+++ b/t/distcheck-no-prefix-or-srcdir-override.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that "make distcheck" overrides any --srcdir or --prefix flag
+# (mistakenly) defined in $(AM_DISTCHECK_CONFIGURE_FLAGS) or
+# $(DISTCHECK_CONFIGURE_FLAGS). See automake bug#14991.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+orig_cwd=$(pwd); export orig_cwd
+
+cat > Makefile.am << 'END'
+# configure should choke on non-absolute prefix or non-existent
+# srcdir. We'll sanity-check that later.
+AM_DISTCHECK_CONFIGURE_FLAGS = --srcdir am-src --prefix am-pfx
+END
+
+# Same comments as above applies.
+DISTCHECK_CONFIGURE_FLAGS='--srcdir user-src --prefix user-pfx'
+export DISTCHECK_CONFIGURE_FLAGS
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+# Sanity check: configure should choke on non-absolute prefix
+# or non-existent srcdir.
+./configure --prefix foobar 2>stderr && { cat stderr >&2; exit 99; }
+cat stderr >&2
+grep "expected an absolute directory name for --prefix" stderr || exit 99
+./configure --srcdir foobar 2>stderr && { cat stderr >&2; exit 99; }
+cat stderr >&2
+grep "cannot find sources.* in foobar" stderr || exit 99
+
+./configure
+run_make -E -O distcheck
+test ! -s stderr
+# Sanity check: the flags have been actually seen.
+$PERL -e 'undef $/; $_ = <>; s/ \\\n/ /g; print;' <stdout >t
+grep '/configure .* --srcdir am-src' t || exit 99
+grep '/configure .* --prefix am-pfx' t || exit 99
+grep '/configure .* --srcdir user-src' t || exit 99
+grep '/configure .* --prefix user-pfx' t || exit 99
+
+:
diff --git a/t/distcheck-outdated-m4.sh b/t/distcheck-outdated-m4.sh
new file mode 100644
index 000000000..a27e8d615
--- /dev/null
+++ b/t/distcheck-outdated-m4.sh
@@ -0,0 +1,134 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that we can define a distcheck-hook to diagnose outdated m4
+# files in a dist tarball (interaction with '--install').
+# See automake bug#9037.
+
+. test-init.sh
+
+cwd=$(pwd) || fatal_ "cannot get current working directory"
+
+cp "$am_testaux_srcdir"/distcheck-hook-m4.am . \
+ || fatal_ "cannot fetch makefile fragment 'distcheck-hook-m4.am'"
+
+cat > Makefile.am << 'END'
+## The lack of '--install' here is meant.
+ACLOCAL_AMFLAGS = -I m4
+include $(srcdir)/distcheck-hook-m4.am
+END
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+MY_FOO
+MY_BAR
+MY_BAZ
+END
+
+mkdir m4 acdir
+echo 'AC_DEFUN([MY_FOO], [:])' > m4/foo.m4
+echo 'AC_DEFUN([MY_BAR], [:])' > acdir/bar.m4
+cat > acdir/baz.m4 << 'END'
+# serial 1
+AC_DEFUN([MY_BAZ], [:])
+END
+
+ACLOCAL="$ACLOCAL --system-acdir=$cwd/acdir"; export ACLOCAL
+
+# The use of '--install' here won't help when the installed file '.m4'
+# will become out-of-date w.r.t. the one in the system acdir.
+$ACLOCAL -I m4 --install
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE distcheck # Sanity check.
+
+check_no_spurious_error ()
+{
+ $EGREP -i 'mkdir:|:.*(permission|denied)' output && exit 1
+ # On failure, some make implementations (such as Solaris make) print the
+ # whole failed recipe on stdout. The first grep works around this.
+ grep -v 'rm -rf ' output | grep -i 'autom4te.*\.cache' && exit 1
+ : To placate 'set -e'.
+}
+
+# We start to use a new "third-party" macro in a new version
+# of a pre-existing third-party m4 file, but forget to re-run
+# "aclocal --install" by hand, relying on automatic remake
+# rules. Our distcheck-hook should catch this too.
+echo MY_ZARDOZ >> configure.ac
+
+cat > acdir/baz.m4 << 'END'
+# serial 2
+AC_DEFUN([MY_BAZ], [:])
+AC_DEFUN([MY_ZARDOZ], [:])
+END
+
+$MAKE # Rebuild configure and makefiles.
+run_make -M -e FAIL distcheck
+$EGREP "required m4 file.* outdated.* baz.m4( |$)" output
+check_no_spurious_error
+# Check that we don't complain for files that aren't outdated.
+$EGREP " (foo|bar).m4" output && exit 1
+
+# Now we again use '--install' explicitly, and "make distcheck"
+# should pass.
+$ACLOCAL -I m4 --install
+using_gmake || $MAKE Makefile
+$MAKE distcheck
+
+# Similar to what have been done above, but this time we:
+# - use ACLOCAL_PATH, and
+# - do not add the use of a new macro.
+
+echo MY_FNORD >> configure.ac
+
+mkdir pth
+cat > pth/fnord.m4 << 'END'
+# serial 1
+AC_DEFUN([MY_FNORD], [:])
+END
+
+ACLOCAL_PATH="$cwd/pth"; export ACLOCAL_PATH
+
+# The explicit use of '--install' here won't help when the installed file
+# '.m4' will become out-of-date w.r.t. the one in the system acdir.
+$ACLOCAL -I m4 --install
+using_gmake || $MAKE Makefile
+$MAKE distcheck
+
+# Only increase serial number, without changing the other contents; this
+# is deliberate.
+cat > pth/fnord.m4 << 'END'
+# serial 2
+AC_DEFUN([MY_FNORD], [:])
+END
+
+$MAKE # Rebuild configure and makefiles.
+run_make -M -e FAIL distcheck
+$EGREP "required m4 file.* outdated.* fnord.m4( |$)" output
+check_no_spurious_error
+# Check that we don't complain for files that aren't outdated.
+$EGREP " (foo|bar|baz).m4" output && exit 1
+
+# Now we again use '--install' explicitly, and "make distcheck"
+# should pass.
+$ACLOCAL -I m4 --install
+using_gmake || $MAKE Makefile
+$MAKE distcheck
+
+:
diff --git a/t/distcheck-override-infodir.sh b/t/distcheck-override-infodir.sh
new file mode 100644
index 000000000..b895867a0
--- /dev/null
+++ b/t/distcheck-override-infodir.sh
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that we can override ${infodir} while having distcheck still
+# working. Related to automake bug#9579.
+
+required='makeinfo tex texi2dvi install-info'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+infodir = ${prefix}/blah/blah/foobar
+info_TEXINFOS = main.texi
+## Sanity check.
+installcheck-local:
+ if test x$${infodir+set} != xset; then \
+ ls -l "$(DESTDIR)$(prefix)/blah/blah/foobar/" || exit 1; \
+ test -f "$(DESTDIR)$(prefix)/blah/blah/foobar/dir" || exit 1; \
+ else \
+ ls -l "$(DESTDIR)$$infodir/" || exit 1; \
+ test -f "$(DESTDIR)$$infodir/dir" || exit 1; \
+ fi
+END
+
+# Protect with leading " # " to avoid spurious maintainer-check failures.
+sed 's/^ *# *//' > main.texi << 'END'
+ # \input texinfo
+ # @setfilename main.info
+ # @settitle main
+ #
+ # @c Explicit calls to @dircategory and @direntry required to ensure that
+ # @c a 'dir' file will be created also by older versions of 'install-info'
+ # @c (e.g., the one coming with Texinfo 4.8).
+ #
+ # @dircategory Software development
+ # @direntry
+ # * Automake: (automake). Making GNU standards-compliant Makefiles
+ # @end direntry
+ #
+ # @dircategory Individual utilities
+ # @direntry
+ # * aclocal-invocation: (automake)aclocal Invocation. Generating aclocal.m4
+ # * automake-invocation: (automake)automake Invocation. Generating Makefile.in
+ # @end direntry
+ #
+ # @node Top
+ # Hello walls.
+ # @bye
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+./configure
+$MAKE
+
+$MAKE distcheck
+run_make infodir="$(pwd)/_info" distcheck
+test -f _info/dir || exit 99 # Sanity check.
+
+:
diff --git a/t/distcheck-pr10470.sh b/t/distcheck-pr10470.sh
new file mode 100644
index 000000000..15e0ee066
--- /dev/null
+++ b/t/distcheck-pr10470.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure "make distcheck" does not experience racy failures on
+# systems (like MinGW/MSYS) that cannot remove a directory "in use"
+# by a process (e.g., that is its "current working directory").
+# See automake bug#10470.
+
+. test-init.sh
+
+mkdir foo.d
+sh -c "cd foo.d && sleep '4'" &
+# Without this sleep, the "rm -rf foo.d" below would reliably beat
+# the "cd foo.d" in the subshell above, and the test would be always
+# skipped, even on MinGW/MSYS.
+sleep '1'
+rm -rf foo.d && skip_ 'system is able to remove "in use" directories'
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<END
+TESTS = foo.test
+EXTRA_DIST= foo.test
+END
+
+cat > foo.test <<END
+#!/bin/sh
+sleep '4' &
+exit 0
+END
+chmod a+x foo.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+
+# We can build the distribution.
+run_make -M distcheck
+# Sanity check: verify that our code has hit a problem removing
+# the distdir, but has recovered from it.
+$EGREP "(^| )(rm|find):.*$distdir" output || fatal_ "expected code path not covered"
+
+:
diff --git a/t/distcheck-pr18286.sh b/t/distcheck-pr18286.sh
new file mode 100644
index 000000000..49ec04840
--- /dev/null
+++ b/t/distcheck-pr18286.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2014-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure "make distcheck" detects all missing files, without getting
+# confused by the fact that they exists in the "original" source tree
+# from which "make distcheck" is run. See automake bug#18286.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+$(srcdir)/test_data.am: $(srcdir)/test_data.txt $(srcdir)/gen-testdata.sh
+ cd $(srcdir) && $(SHELL) gen-testdata.sh <test_data.txt >test_data.am
+
+include $(srcdir)/test_data.am
+
+check-local:
+ is $(testdata) == foo bar
+END
+
+cat > test_data.txt <<'END'
+foo
+bar
+END
+
+
+cat > gen-testdata.sh <<'END'
+#!/bin/sh
+printf 'testdata = \\\n'
+sed 's/$/ \\/'
+echo '$(empty_string)'
+END
+chmod a+x gen-testdata.sh
+
+$sleep
+./gen-testdata.sh <test_data.txt >test_data.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE check
+
+# Oops, we failed to distribute some required files!
+run_make -e FAIL -M distcheck
+$FGREP '../../test_data.txt' output
+
+# But if we distribute them, everything will be OK.
+echo 'EXTRA_DIST = test_data.txt gen-testdata.sh' >> Makefile.am
+
+using_gmake || $MAKE Makefile
+$MAKE distcheck
+
+:
diff --git a/t/distcheck-pr9579.sh b/t/distcheck-pr9579.sh
new file mode 100644
index 000000000..886d3ef2c
--- /dev/null
+++ b/t/distcheck-pr9579.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check against automake bug#9579: distcheck does not always detect
+# incomplete uninstall as advertised.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+# NOTE: the use of 'dir' as the name of the data file installed by hand
+# is deliberate, and enhances coverage -- see definition and comments of
+# lib/am/distdir.am:$(am__distuninstallcheck_listfiles).
+
+cat > Makefile.am << 'END'
+dist_data_DATA = foo
+EXTRA_DIST = dir
+install-data-local:
+ $(MKDIR_P) '$(DESTDIR)$(datadir)'
+ cp '$(srcdir)/dir' '$(DESTDIR)$(datadir)/dir'
+END
+
+: > foo
+: > dir
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure --prefix="$(pwd)/inst"
+
+# Sanity checks.
+$MAKE install
+find inst -type f
+test -f inst/share/foo
+test -f inst/share/dir
+# We expect the uninstall target of our Makefile to be definitely broken.
+$MAKE uninstall
+test -f inst/share/dir
+rm -rf inst
+
+run_make -M -e FAIL distcheck
+$FGREP 'ERROR: files left after uninstall:' output
+grep '/share/dir *$' output
+
+# A few trickier corner cases.
+
+cat > Makefile.am << 'END'
+EXTRA_DIST = dir
+install-data-local:
+install-data-local:
+ $(MKDIR_P) '$(DESTDIR)$(prefix)/mu/share/info'
+ cp '$(srcdir)/dir' '$(DESTDIR)$(prefix)/mu/share/info'
+ $(MKDIR_P) '$(DESTDIR)$(infodir)/more'
+ cp '$(srcdir)/dir' '$(DESTDIR)$(infodir)/more'
+END
+
+$AUTOMAKE
+./config.status Makefile
+
+# Sanity checks, again.
+$MAKE install
+find inst -type f
+test -f inst/mu/share/info/dir
+test -f inst/share/info/more/dir
+# We expect the uninstall target of our Makefile to be definitely broken.
+$MAKE uninstall
+test -f inst/mu/share/info/dir
+test -f inst/share/info/more/dir
+rm -rf inst
+
+run_make -M -e FAIL distcheck
+$FGREP 'ERROR: files left after uninstall:' output
+grep '/mu/share/info/dir *$' output
+grep '/share/info/more/dir *$' output
+
+:
diff --git a/t/distcheck-writable-srcdir.sh b/t/distcheck-writable-srcdir.sh
new file mode 100644
index 000000000..6c1842f0c
--- /dev/null
+++ b/t/distcheck-writable-srcdir.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the user abuse 'distcheck-hook' to ensure his packages
+# is built by "make distcheck" with a writable srcdir. This goes
+# against the GNU Coding Standards, but some package authors might
+# not care about them too much, and it's nice to support their use
+# case too (since it doesn't cost us anything but this test).
+# See automake bug#10878.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+EXTRA_DIST = old
+distcheck-hook:
+ find $(distdir) -exec chmod u+w '{}' ';'
+check-local:
+ test -f $(srcdir)/old
+ test ! -f $(srcdir)/new
+ test ! -r $(srcdir)/new
+## Don't do this in real life, or I'll kill you.
+ echo foo > $(srcdir)/old
+ echo bar > $(srcdir)/new
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure
+: > old
+$MAKE distcheck
+
+:
diff --git a/t/distcleancheck.sh b/t/distcleancheck.sh
new file mode 100644
index 000000000..2e565b56e
--- /dev/null
+++ b/t/distcleancheck.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the suggested 'distcleancheck_listfiles' in the manual works.
+# The example Makefile.am we use is from the FAQ entry 'distcleancheck'.
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# This Makefile.am is bogus. See @node{distcleancheck} in the manual
+# for how to fix it properly.
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c
+dist_man_MANS = foo.1
+
+# We write './foo.1' inside the rule on purpose, to avoid VPATH rewriting
+# done by some 'make' implementations.
+foo.1: foo$(EXEEXT)
+ echo man page for foo$(EXEEXT) > ./foo.1
+
+## Ignore warnings about overridden variables
+AUTOMAKE_OPTIONS = -Wno-override
+distcleancheck_listfiles = \
+ find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
+ sh '{}' ';'
+END
+
+cat >foo.c <<'END'
+int main () { return 0; }
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+$MAKE distcheck
+
+# Now ensure that we really needed the override.
+sed '/distcleancheck_listfiles/,$d' Makefile.am > t
+mv -f t Makefile.am
+$AUTOMAKE
+./configure
+$MAKE
+run_make -E -e FAIL distcheck
+grep 'ERROR:.*files left in build directory after distclean' stderr
+grep '^\./foo\.1$' stderr
+
+:
diff --git a/t/distcom-subdir.sh b/t/distcom-subdir.sh
new file mode 100644
index 000000000..500ddf046
--- /dev/null
+++ b/t/distcom-subdir.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that if an auxfile (here depcomp) is required
+# by a subdir Makefile.am, it is distributed by that Makefile.am.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([subdir/Makefile])
+AC_PROG_CC
+AC_PROG_FGREP
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = subdir
+test-distdir: distdir
+ test -f $(distdir)/depcomp
+.PHONY: test-distdir
+check-local: test-distdir
+END
+
+rm -f depcomp
+mkdir subdir
+
+cat > subdir/Makefile.am << 'END'
+.PHONY: test-distcom
+test-distcom:
+ echo ' ' $(DIST_COMMON) ' ' | $(FGREP) ' $(top_srcdir)/depcomp '
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+test ! -e depcomp
+
+cat >> subdir/Makefile.am << 'END'
+bin_PROGRAMS = foo
+.PHONY: test-distcom
+test-distcom:
+ echo ' ' $(DIST_COMMON) ' ' | $(FGREP) ' $(top_srcdir)/depcomp '
+check-local: test-distcom
+END
+
+cat > subdir/foo.c <<'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+$AUTOMAKE -a subdir/Makefile
+test -f depcomp
+
+./configure
+(cd subdir && $MAKE test-distcom)
+$MAKE test-distdir
+
+$MAKE distcheck
+
+:
diff --git a/t/distcom2.sh b/t/distcom2.sh
new file mode 100644
index 000000000..7c7a9da25
--- /dev/null
+++ b/t/distcom2.sh
@@ -0,0 +1,79 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that depcomp and compile are added to DIST_COMMON.
+# Report from Pavel Roskin. Report of problems with '--no-force' from
+# Scott James Remnant (Debian #206299)
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_CONFIG_FILES([subdir/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = subdir
+END
+
+mkdir subdir
+: > subdir/foo.c
+
+cat > subdir/Makefile.am << 'END'
+noinst_PROGRAMS = foo
+foo_SOURCES = foo.c
+foo_CFLAGS = -DBAR
+END
+
+$ACLOCAL
+
+for opt in '' --no-force; do
+
+ rm -f compile depcomp
+
+ $AUTOMAKE $opt --add-missing
+
+ test -f compile
+ test -f depcomp
+
+ for dir in . subdir; do
+ sed -n -e "
+ /^am__DIST_COMMON =.*/ {
+ b body
+ :loop
+ n
+ :body
+ p
+ s/\\\\$/\\\\/
+ t loop
+ s/$/ /
+ s/[$tab ][$tab ]*/ /g
+ p
+ }" $dir/Makefile.in > $dir/dc.txt
+ done
+
+ cat dc.txt # For debugging.
+ cat subdir/dc.txt # Likewise.
+
+ $FGREP ' $(top_srcdir)/depcomp ' subdir/dc.txt
+ # The 'compile' script will be listed in the DIST_COMMON of the top-level
+ # Makefile because it's required in configure.ac (by AC_PROG_CC).
+ $FGREP ' $(top_srcdir)/compile ' dc.txt || $FGREP ' compile ' dc.txt
+
+done
+
+:
diff --git a/t/distcom3.sh b/t/distcom3.sh
new file mode 100644
index 000000000..04f0c5dba
--- /dev/null
+++ b/t/distcom3.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that non-existing common files are distributed
+# if they are buildable.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+README:
+ echo 'I bet you are reading me.' > README
+test-distcommon:
+ echo ' ' $(DIST_COMMON) ' ' | grep ' README '
+END
+
+# Files required by '--gnu'.
+: > NEWS
+: > AUTHORS
+: > ChangeLog
+
+$ACLOCAL
+
+# Should not warn about missing README, since it is a target.
+$AUTOMAKE --add-missing --gnu >output 2>&1 || { cat output; exit 1; }
+cat output
+grep README output && exit 1
+
+$AUTOCONF
+./configure
+$MAKE test-distcommon
+$MAKE distdir
+test -f $distdir/README
+
+# Should warn about missing README.
+rm -f README
+: > Makefile.am
+AUTOMAKE_fails --add-missing --gnu
+grep 'required file.*README.*not found' stderr
+
+:
diff --git a/t/distcom4.sh b/t/distcom4.sh
new file mode 100644
index 000000000..ddfce3793
--- /dev/null
+++ b/t/distcom4.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure config files are distributed, and only once.
+# This tries to distribute a file from a subdirectory, without
+# Makefile in that directory. 'distcom5.sh' performs the same
+# test with a Makefile in the directory.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+ AC_CONFIG_FILES([tests/autoconf:tests/wrapper.in],
+ [chmod +x tests/autoconf])
+ AC_CONFIG_FILES([tests/autoheader:tests/wrapper.in],
+ [chmod +x tests/autoheader])
+ AC_CONFIG_FILES([tests/autom4te:tests/wrapper.in],
+ [chmod +x tests/autom4te])
+ AC_CONFIG_FILES([tests/autoreconf:tests/wrapper.in],
+ [chmod +x tests/autoreconf])
+ AC_CONFIG_FILES([tests/autoscan:tests/wrapper.in],
+ [chmod +x tests/autoscan])
+ AC_CONFIG_FILES([tests/autoupdate:tests/wrapper.in],
+ [chmod +x tests/autoupdate])
+ AC_CONFIG_FILES([tests/ifnames:tests/wrapper.in],
+ [chmod +x tests/ifnames])
+ AC_OUTPUT
+END
+
+mkdir tests
+: > README
+: > tests/wrapper.in
+cat > Makefile.am << 'END'
+.PHONY: test1 test 2
+test1:
+ for x in $(DIST_COMMON); do echo $$x; done \
+ | grep 'tests/' > lst
+ cat lst # For debugging.
+ test `wc -l <lst` -eq 1
+test2: distdir
+ test -f $(distdir)/tests/wrapper.in
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE test1 test2
+
+:
diff --git a/t/distcom5.sh b/t/distcom5.sh
new file mode 100644
index 000000000..09abe5d76
--- /dev/null
+++ b/t/distcom5.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure config files are distributed, and only once.
+# This tries to distribute a file from a subdirectory, with
+# a Makefile in that directory. 'distcom4.sh' performs the same
+# test without Makefile in the directory.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+ AC_CONFIG_FILES([tests/autoconf:tests/wrapper.in],
+ [chmod +x tests/autoconf])
+ AC_CONFIG_FILES([tests/autoheader:tests/wrapper.in],
+ [chmod +x tests/autoheader])
+ AC_CONFIG_FILES([tests/autom4te:tests/wrapper.in],
+ [chmod +x tests/autom4te])
+ AC_CONFIG_FILES([tests/autoreconf:tests/wrapper.in],
+ [chmod +x tests/autoreconf])
+ AC_CONFIG_FILES([tests/autoscan:tests/wrapper.in],
+ [chmod +x tests/autoscan])
+ AC_CONFIG_FILES([tests/autoupdate:tests/wrapper.in],
+ [chmod +x tests/autoupdate])
+ AC_CONFIG_FILES([tests/ifnames:tests/wrapper.in],
+ [chmod +x tests/ifnames])
+ AC_CONFIG_FILES([tests/Makefile])
+ AC_OUTPUT
+END
+
+mkdir tests
+: > tests/wrapper.in
+
+cat > Makefile.am << 'END'
+SUBDIRS = tests
+.PHONY: test
+test: distdir
+ test -f $(distdir)/tests/wrapper.in
+check-local: test
+ for x in $(DIST_COMMON); do echo $$x; done \
+ | grep tests && exit 1; :
+END
+
+cat > tests/Makefile.am <<'END'
+check-local:
+ for x in $(DIST_COMMON); do echo $$x; done \
+ | grep wrapper.in > lst
+ cat lst # For debugging.
+ test `wc -l <lst` -eq 1
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE check
+# Sanity check.
+test -f tests/lst
+
+:
diff --git a/t/distdir.sh b/t/distdir.sh
new file mode 100644
index 000000000..66c817fca
--- /dev/null
+++ b/t/distdir.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure subdirs in EXTRA_DIST work. Also tests to make
+# sure *srcdir is properly handled. Note that using './', as in
+# EXTRA_DIST = ./joe
+# does not work portably: it fails with HP-UX and Tru64 make.
+# Also test DISTFILES containing a directory and a file in it,
+# and repeated directories.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+include_HEADERS = some/file another/sub/subsub/file2 yet/another/file3
+EXTRA_DIST = foo/bar joe $(top_srcdir)/woo/doo $(srcdir)/dada \
+ some another/sub yet \
+ some another/sub yet
+
+
+all-local:
+ $(MKDIR_P) another/sub/subsub
+ touch another/sub/subsub/file2
+
+CLEANFILES = another/sub/subsub/file2
+
+check-local:
+ test -f $(srcdir)/foo/bar
+ test -f $(srcdir)/woo/doo
+ test -f $(srcdir)/joe
+ test -f $(srcdir)/dada
+ test -f $(srcdir)/some/file
+ test -f $(srcdir)/another/sub/subsub/file2 \
+ || test -f /another/sub/subsub/file2
+ test -f $(srcdir)/yet/another/file3
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+mkdir foo woo some another another/sub another/sub/subsub yet yet/another
+touch foo/bar joe woo/doo dada some/file another/sub/subsub/file2
+touch yet/another/file3
+
+mkdir build
+cd build
+../configure
+$MAKE distdir
+# Check to make sure 'foo' isn't made in build directory.
+test -d foo && exit 1
+
+rm -rf $me-1.0
+# Remove the dot from VERSION for the next grep.
+run_make -O -e IGNORE VERSION=10 MKDIR_P='echo MKDIR_P' distdir
+
+# Make sure no './' appear in the directory names. srcdir is '..', so
+# this also checks that no directory is created in the source tree.
+grep 'MKDIR_P.*\.' stdout && exit 1
+
+cd ..
+./configure --prefix "$(pwd)"
+$MAKE distcheck
+
+:
diff --git a/t/disthook.sh b/t/disthook.sh
new file mode 100644
index 000000000..d3d118500
--- /dev/null
+++ b/t/disthook.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that 'dist-hook' works. See automake bug#10878.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+EXTRA_DIST = write execute removed doc
+
+removed:
+ echo I will be deleted > $@
+DISTCLEANFILES = removed
+
+dist-hook:
+ chmod u+w $(distdir)/write $(distdir)/doc
+ chmod u+x $(distdir)/execute
+ rm -f $(distdir)/removed
+ rm -f $(distdir)/doc/HACKING
+ rm -f $(distdir)/doc/RELEASE-DATE
+ date > $(distdir)/doc/RELEASE-DATE
+ echo all is ok > $(distdir)/write
+
+check-local:
+ ls -l $(srcdir) $(srcdir)/doc
+ test "`cat $(srcdir)/write`" = "all is ok"
+ test -f $(srcdir)/doc/README
+ test -f $(srcdir)/doc/RELEASE-DATE
+ test ! -f $(srcdir)/removed
+ test ! -r $(srcdir)/removed
+ test ! -f $(srcdir)/doc/HACKING
+ test ! -r $(srcdir)/doc/HACKING
+ $(srcdir)/execute
+ $(srcdir)/execute | grep 'I run successfully'
+## Sanity check.
+ echo ok > $(srcdir)/../distcheck-run
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+mkdir doc
+: > doc/README
+: > doc/HACKING
+echo will be clobbered > write
+cat > execute <<'END'
+#!/bin/sh
+echo I run successfully
+END
+
+chmod a-w write
+chmod a-x execute
+
+$MAKE distdir
+ls -l $distdir $distdir/doc
+cd $distdir
+test "$(cat write)" = "all is ok"
+test ! -e removed
+test -f doc/README
+test -f doc/RELEASE-DATE
+test ! -e doc/HACING
+./execute
+./execute | grep 'I run successfully'
+cd ..
+
+$MAKE distcheck
+test -f distcheck-run
+
+:
diff --git a/t/distlinks.sh b/t/distlinks.sh
new file mode 100644
index 000000000..7b6ba0eae
--- /dev/null
+++ b/t/distlinks.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that distributed symlinks in the source tree will be expanded
+# as regular files in $(distdir).
+
+. test-init.sh
+
+echo text > file
+
+ln -s file lnk || skip_ "cannot create symlinks to files"
+
+mkdir A
+mkdir B
+echo aaa > A/aaa
+cd B
+ln -s ../A/aaa bbb
+cd ..
+
+echo FooBarBaz > foo
+
+ln -s foo bar1
+ln -s bar1 bar2
+ln -s bar2 bar3
+
+ln -s "$(pwd)/foo" quux
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+echo "me = $me" > Makefile.am # For better failure messages.
+cat >> Makefile.am << 'END'
+EXTRA_DIST = lnk B/bbb bar1 bar2 bar3 quux
+.PHONY: test
+test: distdir
+ ls -l $(distdir) $(distdir)/B
+ fail() { echo "$(me): $$*" >&2; e=1; }; \
+ e=0; \
+ set file lnk A/aaa B/bbb foo quux foo bar1 foo bar2 foo bar3; \
+ while test $$# -ge 2; do \
+ file=$$1; shift; link=$(distdir)/$$1; shift; \
+ test -f $$link || fail "$$link is not a regular file"; \
+ test ! -h $$link || fail "$$link is a symlink"; \
+ diff $$file $$link || fail "$$link differs from $$file"; \
+ done; \
+ exit $$e;
+END
+
+ls -l . A B
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+:
diff --git a/t/distlinksbrk.sh b/t/distlinksbrk.sh
new file mode 100644
index 000000000..66b71a3ad
--- /dev/null
+++ b/t/distlinksbrk.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that distributed broken symlinks cause 'make dist' to fail, and
+# to do so with (mostly) meaningful diagnostic.
+
+. test-init.sh
+
+# We need, for our broken symlinks, names that make it hard to get false
+# positives when grepping make output to look for them.
+lnk_base=BrknSymlnk
+lnk1=${lnk_base}__001
+lnk2=${lnk_base}__002
+lnka=${lnk_base}__aaa
+lnkb=${lnk_base}__bbb
+
+ln -s nonesuch $lnk1 || skip_ "cannot create broken symlinks"
+
+ln -s "$(pwd)/nonesuch" $lnk2
+
+ln -s $lnk1 $lnka
+ln -s $lnka $lnkb
+
+# Sanity checks.
+test ! -e $lnk1
+test ! -e $lnk2
+test ! -e $lnka
+test ! -e $lnkb
+test -h $lnk1
+test -h $lnk2
+test -h $lnka
+test -h $lnkb
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+
+ls -l # For debugging.
+
+# Don't try to use "make -k", because some botched make implementations
+# (HP-UX, IRIX) might still exit on the first error in this situations.
+for lnk in $lnk1 $lnk2 $lnka $lnkb; do
+ echo "EXTRA_DIST = $lnk" > Makefile.am
+ $AUTOMAKE
+ ./configure
+ # Distribution must fail, with a decent error message.
+ run_make -M -e FAIL distdir
+ $FGREP $lnk output
+done
+
+:
diff --git a/t/distname.sh b/t/distname.sh
new file mode 100644
index 000000000..355fd066d
--- /dev/null
+++ b/t/distname.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of names in tar file.
+# From Rainer Orth.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_SRCDIR([a.c])
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = wish
+wish_SOURCES = a.c
+END
+
+: > a.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --include-deps --copy --add-missing
+./configure
+$MAKE dist
+
+gzip -d $me-1.0.tar.gz
+tar tf $me-1.0.tar > stdout || { cat stdout; exit 1; }
+cat stdout
+$FGREP ./$me-1.0/a.c stdout && exit 1
+
+:
diff --git a/t/dmalloc.sh b/t/dmalloc.sh
new file mode 100644
index 000000000..a297e0a46
--- /dev/null
+++ b/t/dmalloc.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Simple checks on the 'AM_WITH_DMALLOC' macro.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_HEADERS([config.h])
+AM_WITH_DMALLOC
+AC_SUBST([LDFLAGS])
+AC_OUTPUT
+END
+
+cat > config.h.in <<'END'
+#undef WITH_DMALLOC
+END
+
+cat > Makefile.am <<'END'
+check-with-dmalloc:
+## The AM_WITH_DMALLOC assumes that the user is a developer, so that
+## he is expected to install and make available the 'dmalloc' library
+## by his own. So we just check that proper linker and libs flags get
+## added.
+ echo ' ' $(LDFLAGS) ' ' | grep ' -g '
+ echo ' ' $(LIBS) ' ' | grep ' -ldmalloc '
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+cat config.h # For debugging.
+grep '^ */\* *# *undef *WITH_DMALLOC *\*/ *$' config.h
+
+./configure --without-dmalloc
+cat config.h # For debugging.
+grep '^ */\* *# *undef *WITH_DMALLOC *\*/ *$' config.h
+
+./configure --with-dmalloc
+cat config.h # For debugging.
+grep '^# *define *WITH_DMALLOC *1 *$' config.h
+$MAKE check-with-dmalloc
+
+:
diff --git a/t/doc-parsing-buglets-colneq-subst.sh b/t/doc-parsing-buglets-colneq-subst.sh
new file mode 100644
index 000000000..0f8dfe8de
--- /dev/null
+++ b/t/doc-parsing-buglets-colneq-subst.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check a documented limitation of the Automake's Makefile parser
+# w.r.t. POSIX variable substitutions used in the name of targets.
+# See Section "General Operation" in the Automake manual.
+# If you cause some parts of this test to fail, chances are that you've
+# improved the Automake parser ;-)
+# See: <https://lists.gnu.org/archive/html/automake/2010-08/msg00074.html>
+# or: <http://thread.gmane.org/gmane.comp.sysutils.automake.general/11943/focus=11962>
+
+. test-init.sh
+
+cat > Makefile.am <<'END'
+$(FOO:=x): bar
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+
+grep 'bad characters.*variable name.*\$(FOO' stderr
+grep ':=.*assignments.*not portable' stderr
+
+:
diff --git a/t/doc-parsing-buglets-tabs.sh b/t/doc-parsing-buglets-tabs.sh
new file mode 100644
index 000000000..9e84f806d
--- /dev/null
+++ b/t/doc-parsing-buglets-tabs.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check the documented limitation of the Automake's Makefile parser w.r.t.
+# use of TAB characters; see Section "General Operation" in the Automake
+# manual, and automake bug#8360.
+# If you cause some parts of this test to fail, chances are that you've
+# improved the Automake parser ;-)
+
+. test-init.sh
+
+cat > Makefile.am <<END
+.PHONY: test
+test: all check
+
+fail:
+${tab}@echo "'\$@ recipe executed'"; exit 1
+
+## This won't be recognized as a target+recipe by Automake.
+all-local${tab}:
+${tab}@exit 1
+
+## This won't be recognized as a target+rdependency by Automake.
+all-local${tab}: fail
+
+just_to_separate: dummy deps
+
+## This won't be recognized as a variable assignment by Automake.
+${tab}bin_PROGRAMS = foo
+END
+
+echo AC_OUTPUT >> configure.ac
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP '$(EXEEEXT)' Makefile.in && exit 1
+grep 'all:.*all-local' Makefile.in && exit 1
+grep "^${tab}bin_PROGRAMS = foo" Makefile.in
+
+$AUTOCONF
+./configure
+
+$MAKE test
+
+:
diff --git a/t/dollar.sh b/t/dollar.sh
new file mode 100644
index 000000000..f9e0e026b
--- /dev/null
+++ b/t/dollar.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# We should support files with '$' characters in their names.
+# Java people need this.
+# PR/317, reported by Eric Siegerman and Philip Fong.
+
+# Require GNU make for this test. SunOS Make does not support
+# '$$' in a target or a dependency (it outputs the empty string instead).
+required=GNUmake
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'EOF'
+mydir = $(prefix)/my
+dist_my_DATA = hello$$world
+
+check-dist: distdir
+ test -f '$(distdir)/hello$$world'
+EOF
+
+: > 'hello$world'
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure --prefix "$(pwd)/inst"
+$MAKE install
+test -f 'inst/my/hello$world'
+$MAKE check-dist
+
+:
diff --git a/t/dollarvar.sh b/t/dollarvar.sh
new file mode 100644
index 000000000..09d93d61f
--- /dev/null
+++ b/t/dollarvar.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that -Wportability complains about recursive
+# variable expansions and variables containing '$', '$(...)', or
+# '${...}' in the name. We support recursive variable expansions using
+# the latter two constructs for the 'silent-rules' option, and they are
+# rather widely supported in practice. OTOH variable definitions
+# containing a '$' on the left hand side of an assignment are not
+# portable in practice, even though POSIX allows them. :-/
+
+. test-init.sh
+
+cat >Makefile.am <<'EOF'
+x = 1
+foo$x = 1
+bar$(x) = 1
+baz${x} = 1
+bla = $(foo$x)
+bli = $(foo$(x))
+blo = $(foo${x})
+EOF
+
+$ACLOCAL
+
+AUTOMAKE_fails -Wportability
+grep 'Makefile.am:2' stderr
+grep 'Makefile.am:3' stderr
+grep 'Makefile.am:4' stderr
+grep 'Makefile.am:5' stderr
+grep 'Makefile.am:6' stderr
+grep 'Makefile.am:7' stderr
+
+AUTOMAKE_fails -Wportability -Wno-portability-recursive
+grep 'Makefile.am:2' stderr
+grep 'Makefile.am:3' stderr
+grep 'Makefile.am:4' stderr
+grep 'Makefile.am:5' stderr
+grep 'Makefile.am:6' stderr && exit 1
+grep 'Makefile.am:7' stderr && exit 1
+
+
+:
diff --git a/t/dollarvar2.sh b/t/dollarvar2.sh
new file mode 100644
index 000000000..1af16f9d3
--- /dev/null
+++ b/t/dollarvar2.sh
@@ -0,0 +1,86 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that -Wportability turns on portability-recursive,
+# likewise for -Wno-...
+
+. test-init.sh
+
+#
+# First, try a setup where we have a 'portability-recursive' warning,
+# but no "simple" 'portability' warning.
+#
+
+cat >Makefile.am <<'EOF'
+x = 1
+bla = $(foo$(x))
+EOF
+
+$ACLOCAL
+
+# Enabling 'portability' warnings should enable 'portability-recursive'
+# warnings.
+AUTOMAKE_fails -Wnone -Wportability
+grep 'recursive variable expansion' stderr
+# 'portability-recursive' warnings can be enabled by themselves.
+AUTOMAKE_fails -Wnone -Wportability-recursive
+grep 'recursive variable expansion' stderr
+
+# Various ways to disable 'portability-recursive'.
+$AUTOMAKE -Wno-all
+$AUTOMAKE -Wno-portability
+$AUTOMAKE -Wall -Wno-portability-recursive
+
+# '-Wno-portability-recursive' after '-Wportability' correctly disables
+# 'portability-recursive' warnings.
+$AUTOMAKE -Wportability -Wno-portability-recursive
+
+# '-Wno-portability' disables 'portability-recursive' warnings; but
+# a later '-Wportability-recursive' re-enables them. This time, we
+# use AUTOMAKE_OPTIONS to specify the warning levels.
+echo 'AUTOMAKE_OPTIONS = -Wno-portability' >> Makefile.am
+$AUTOMAKE
+echo 'AUTOMAKE_OPTIONS += -Wportability-recursive' >> Makefile.am
+AUTOMAKE_fails
+grep 'recursive variable expansion' stderr
+
+#
+# Now try a setup where we have both a 'portability' warning and
+# a 'portability-recursive' one.
+#
+
+cat >Makefile.am <<'EOF'
+x = 1
+bla = $(foo$(x))
+oops = $(var-with-dash)
+EOF
+
+# Can disable both 'portability' and 'portability-recursive' warnings.
+$AUTOMAKE -Wno-portability
+
+# Disabling 'portability-recursive' warnings should not disable
+# 'portability' warnings.
+AUTOMAKE_fails -Wportability -Wno-portability-recursive
+grep 'var-with-dash' stderr
+grep 'recursive variable expansion' stderr && exit 1
+
+# Enabling 'portability-recursive' warnings should not enable
+# all the 'portability' warning.
+AUTOMAKE_fails -Wno-portability -Wportability-recursive
+grep 'var-with-dash' stderr && exit 1
+grep 'recursive variable expansion' stderr
+
+:
diff --git a/t/double.sh b/t/double.sh
new file mode 100644
index 000000000..9fd39bd29
--- /dev/null
+++ b/t/double.sh
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure listing a program twice is ok.
+# Report from Manu Rouat.
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = spice nutmeg help sconvert multidec nutmeg
+END
+
+$ACLOCAL
+$AUTOMAKE
diff --git a/t/dup2.sh b/t/dup2.sh
new file mode 100644
index 000000000..cc0f92744
--- /dev/null
+++ b/t/dup2.sh
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure aclocal only warns about definitions overridden by acinclude.m4.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_FUNC_STRTOD
+END
+
+cat > acinclude.m4 << 'END'
+AC_DEFUN([AM_FUNC_STRTOD])
+END
+
+$ACLOCAL
diff --git a/t/else.sh b/t/else.sh
new file mode 100644
index 000000000..1205c1504
--- /dev/null
+++ b/t/else.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure line numbers are correct in some error reports.
+
+. test-init.sh
+
+echo 'AM_CONDITIONAL(FOO, true)' >> configure.ac
+
+cat > Makefile.am << 'END'
+# Flag to tell us if apache dir is a source distribution.
+APACHE_DIR_IS_SRC = @APACHE_DIR_IS_SRC@
+
+# We only need to descend into the c dir if we're doing a 1.3 DSO
+# configuration.
+ifeq ("${APACHE_DIR_IS_SRC}","yes")
+SUBDIRS = java
+else
+SUBDIRS = c java
+endif
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile\.am:8:.*else without if' stderr
diff --git a/t/empty-data-primary.sh b/t/empty-data-primary.sh
new file mode 100644
index 000000000..170a27bb6
--- /dev/null
+++ b/t/empty-data-primary.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug where if the list of installables is empty, invalid sh
+# code is generated.
+
+. test-init.sh
+
+echo AC_OUTPUT >>configure.ac
+echo 'data_DATA =' >Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure --prefix "$(pwd)/inst"
+$MAKE install
+
+:
diff --git a/t/empty-sources-primary.tap b/t/empty-sources-primary.tap
new file mode 100644
index 000000000..029625606
--- /dev/null
+++ b/t/empty-sources-primary.tap
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# A test for missing _SOURCES variable. Also test to make sure empty
+# _SOURCES suppresses assumption about default name.
+
+. test-init.sh
+
+plan_ 5
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_SUBST([zoo_obj])
+END
+
+cat > Makefile.am << 'END'
+sbin_PROGRAMS = pavel
+
+bin_PROGRAMS = pavel2
+pavel2_SOURCES =
+
+noinst_PROGRAMS = zoo
+zoo_SOURCES =
+EXTRA_zoo_SOURCES = bar.c foo.c
+zoo_DEPENDENCIES = $(zoo_obj)
+zoo_LDADD = $(zoo_DEPENDENCIES)
+END
+
+command_ok_ "aclocal" $ACLOCAL
+command_ok_ "automake" $AUTOMAKE
+
+command_ok_ "default _SOURCES" $FGREP ' pavel.c' Makefile.in
+command_ok_ "empty _SOURCES (basic)" not $FGREP 'pavel2.' Makefile.in
+command_ok_ "empty _SOURCES (elaborate)" not $FGREP 'zoo.' Makefile.in
+
+:
diff --git a/t/exdir.sh b/t/exdir.sh
new file mode 100644
index 000000000..778d0b70f
--- /dev/null
+++ b/t/exdir.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check to make sure new extended directory mechanism works.
+
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+htmldir = $(prefix)/html
+html_DATA = zot.html
+pkgdata_DATA = qbert
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^DATA' Makefile.in | grep html
diff --git a/t/exdir2.sh b/t/exdir2.sh
new file mode 100644
index 000000000..39c1a3ba8
--- /dev/null
+++ b/t/exdir2.sh
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure undefined directories are invalid.
+
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+quuz_DATA = zot.html
+pkgdata_DATA = qbert
+EOF
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'pkgdatadir' stderr && exit 1
+grep 'Makefile.am:1:.*quuzdir.*undefined' stderr
diff --git a/t/exdir3.sh b/t/exdir3.sh
new file mode 100644
index 000000000..43a79ef23
--- /dev/null
+++ b/t/exdir3.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure pkgdatadir can be overridden via AC_SUBST.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AC_SUBST([pkgdatadir], ["FOO"])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'EOF'
+showme:
+ @echo $(pkgdatadir)
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE showme | grep FOO
diff --git a/t/exeext.sh b/t/exeext.sh
new file mode 100644
index 000000000..eca03e502
--- /dev/null
+++ b/t/exeext.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure '.' in an exe name doesn't fool us.
+# Report from Robert Collins.
+# Also make sure we rewrite conditionals variables.
+# Also check for PR/352.
+# Also make sure the old definitions of bin_PROGRAMS and friend
+# aren't left around. Report from Jim Meyering.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([WANT_MT], [test -z "$revert"])
+AM_CONDITIONAL([WANT_RMT], [test -z "$revert"])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = maude
+sbin_PROGRAMS = maude.static
+## We don't define this one for now. Probably it is an error.
+## noinst_PROGRAMS = maude2.exe
+check_PROGRAMS = maude3$(EXEEXT)
+
+if WANT_MT
+ bin_PROGRAMS += mt
+endif
+if WANT_RMT
+ libexec_PROGRAMS = rmt
+endif
+
+test-default:
+ is $(bin_PROGRAMS) == maude$(EXEEXT) mt$(EXEEXT)
+ is $(sbin_PROGRAMS) == maude.static$(EXEEXT)
+ is $(check_PROGRAMS) == maude3$(EXEEXT)
+ is $(libexec_PROGRAMS) == rmt$(EXEEXT)
+
+test-revert:
+ is $(bin_PROGRAMS) == maude$(EXEEXT)
+ is $(sbin_PROGRAMS) == maude.static$(EXEEXT)
+ is $(check_PROGRAMS) == maude3$(EXEEXT)
+ is $(libexec_PROGRAMS) ==
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+grep '^maude$(EXEEXT):' Makefile.in
+grep '^maude\.static$(EXEEXT):' Makefile.in
+grep '^maude3$(EXEEXT):' Makefile.in
+grep '^mt$(EXEEXT):' Makefile.in
+grep '^rmt$(EXEEXT):' Makefile.in
+test $(grep -c '^bin_PROGRAMS =' Makefile.in) -eq 1
+
+# Make sure $(EXEEXT) gets stripped before canonicalization.
+grep 'maude3__EXEEXT__OBJECTS' Makefile.in && exit 1
+
+./configure
+run_make test-default
+run_make test-default EXEEXT=.foo
+
+./configure revert=yes
+run_make test-revert
+run_make test-revert EXEEXT=.foo
+
+:
diff --git a/t/exeext2.sh b/t/exeext2.sh
new file mode 100644
index 000000000..2ff0cd081
--- /dev/null
+++ b/t/exeext2.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure no-exeext option works.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = maude
+
+maude:
+ yeah
+END
+
+$ACLOCAL
+
+$AUTOMAKE -Wnone
+AUTOMAKE_fails -Wnone -Wobsolete
+grep 'deprecated.*maude' stderr
+AUTOMAKE_fails -Wall
+grep 'deprecated.*maude' stderr
+grep 'overrid.*maude' stderr
+
+echo 'AUTOMAKE_OPTIONS = no-exeext' >> Makefile.am
+
+$AUTOMAKE -Wall -Wno-override
diff --git a/t/exeext3.sh b/t/exeext3.sh
new file mode 100644
index 000000000..be699473f
--- /dev/null
+++ b/t/exeext3.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we can override a program rule.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = maude 3dldf
+
+maude$(EXEEXT):
+ yeah
+
+3dldf$(EXEEXT):
+ yippie
+END
+
+$ACLOCAL
+$AUTOMAKE -Wno-override
+
+$FGREP 'maude$(EXEEXT):' Makefile.in
+test 1 -eq $(grep -c 'maude.*:' Makefile.in)
+$FGREP '3dldf$(EXEEXT):' Makefile.in
+test 1 -eq $(grep -c '3dldf.*:' Makefile.in)
+
+:
diff --git a/t/exeext4.sh b/t/exeext4.sh
new file mode 100644
index 000000000..35b495d11
--- /dev/null
+++ b/t/exeext4.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure $(EXEEXT) is appended to programs and to tests that are
+# programs, but not to @substitutions@.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND], [test -n "$cond"])
+AC_SUBST([programs], ['prg1$(EXEEXT) prg2$(EXEEXT)'])
+AC_SUBST([CC], [whocares])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+EXEEXT = .x
+if COND
+ BAR = bar
+ DEP = bar
+ BAZE = baz$(EXEEXT)
+ BAZ = baz $(DEP)
+endif
+bin_PROGRAMS = $(programs) @programs@ prg3 $(BAR) $(BAZE)
+EXTRA_PROGRAMS = prg1 prg2 prg3
+TESTS = prg1 prg3 prg4 $(BAZ)
+
+.PHONY: test-cond test-nocond
+test-nocond:
+ is $(bin_PROGRAMS) == prg1.x prg2.x prg1.x prg2.x prg3.x
+ is $(EXTRA_PROGRAMS) == prg1.x prg2.x prg3.x
+ is $(TESTS) == prg1.x prg3.x prg4
+test-cond:
+ is $(bin_PROGRAMS) == prg1.x prg2.x prg1.x prg2.x prg3.x bar.x baz.x
+ is $(EXTRA_PROGRAMS) == prg1.x prg2.x prg3.x
+ is $(TESTS) == prg1.x prg3.x prg4 baz.x bar.x
+ is $(BAR) $(BAZ) == bar baz bar
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing --copy
+
+./configure
+$MAKE test-nocond
+
+./configure cond=yes
+$MAKE test-cond
+
+# Only two am__EXEEXT_* variables are needed here: one for BAR, and one
+# BAZ. The latter must use the former.
+test 2 -eq $(grep -c '__EXEEXT_. =' Makefile.in)
+grep 'am__EXEEXT_2 = .*am__EXEEXT_1' Makefile.in
+
+:
diff --git a/t/ext.sh b/t/ext.sh
new file mode 100644
index 000000000..23e1e0b5e
--- /dev/null
+++ b/t/ext.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure extensions are set correctly for various languages.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_F77
+AC_PROG_FC
+AC_PROG_OBJC
+AC_PROG_OBJCXX
+AM_PROG_UPC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = 1.f 2.for 3.f90 4.f95 5.F 6.F90 7.F95 8.r 9.m 10.mm 11.upc
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+for ext in f for f90 f95 F F90 F95 r m mm upc; do
+ grep "^\.$ext\.o:" Makefile.in
+ grep "^$ext\.o:" Makefile.in && exit 1
+ : For shells with busted 'set -e'.
+done
+
+:
diff --git a/t/ext2.sh b/t/ext2.sh
new file mode 100644
index 000000000..f1ed2fe22
--- /dev/null
+++ b/t/ext2.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for a bug reported by Ladislav Strojil.
+# Using different extensions for the same language should not
+# output the build rules several times.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_PROG_CXX
+EOF
+
+cat >Makefile.am <<EOF
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = p q r
+p_SOURCES = a.cc b.cpp c.cxx
+q_SOURCES = sub/d.cc sub/e.cpp sub/f.cxx
+r_SOURCES = g.cc h.cpp i.cxx
+r_CXXFLAGS = -DFOO
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '\.o:' Makefile.in > rules
+cat rules
+
+# Here is an example of bogus output. The rules are output several
+# times.
+#| .cc.o:
+#| d.o: sub/d.cc
+#| e.o: sub/e.cpp
+#| f.o: sub/f.cxx
+#| r-g.o: g.cc
+#| r-h.o: h.cpp
+#| r-i.o: i.cxx
+#| .cpp.o:
+#| d.o: sub/d.cc
+#| e.o: sub/e.cpp
+#| f.o: sub/f.cxx
+#| r-g.o: g.cc
+#| r-h.o: h.cpp
+#| r-i.o: i.cxx
+#| .cxx.o:
+#| #d.o: sub/d.cc
+#| #e.o: sub/e.cpp
+#| #f.o: sub/f.cxx
+#| #r-g.o: g.cc
+#| #r-h.o: h.cpp
+#| #r-i.o: i.cxx
+
+# Bail out if we find a duplicate.
+$PERL -ne 'if (exists $a{$_}) { exit (1) } else { $a{$_} = 1 }' < rules
diff --git a/t/ext3.sh b/t/ext3.sh
new file mode 100644
index 000000000..6ff565bdf
--- /dev/null
+++ b/t/ext3.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Cover corner cases of derive_suffix wrt. file extensions:
+# - extension declared with SUFFIXES but with no suffix rule for it
+# - extension with a suffix rule but none that leads us to $(OBJEXT)
+# In both cases, we don't try to create a rule; but we shouldn't
+# fail either, because magic might be happening behind our back.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo bar
+foo_SOURCES = foo.goo
+SUFFIXES = .goo
+bar_SOURCES = bar.woo
+.woo.zoo: ; making a zoo $@ from a woo $<
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+exit 0
diff --git a/t/extra-data.sh b/t/extra-data.sh
new file mode 100644
index 000000000..054416ea1
--- /dev/null
+++ b/t/extra-data.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Checks on the obsolete EXTRA_DATA variable.
+
+. test-init.sh
+
+echo 'AC_SUBST([CODICIL])' >> configure.ac
+
+$ACLOCAL
+
+# EXTRA_DATA is not required ....
+echo sysconf_DATA = @CODICIL@ > Makefile.am
+$AUTOMAKE
+
+# ... but it can nonetheless be specified.
+echo EXTRA_DATA = codicil.txt >> Makefile.am
+$AUTOMAKE
+
+:
diff --git a/t/extra-deps-lt.sh b/t/extra-deps-lt.sh
new file mode 100644
index 000000000..e3c8ba08f
--- /dev/null
+++ b/t/extra-deps-lt.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test EXTRA_*_DEPENDENCIES, libtool version; see 'extra-deps.sh' for
+# non-libtool variant.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_SUBST([deps], [bardep])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LTLIBRARIES = libfoo.la
+EXTRA_libfoo_la_DEPENDENCIES = libfoodep
+libfoodep:
+ @echo making $@
+ @: > $@
+CLEANFILES = libfoodep
+
+bin_PROGRAMS = bar
+bar_LDADD = libfoo.la
+EXTRA_bar_DEPENDENCIES = $(deps)
+
+EXTRA_DIST = bardep
+
+.PHONY: bar-has-been-updated
+bar-has-been-updated:
+ is_newest bar$(EXEEXT) libfoo.la
+END
+
+cat >libfoo.c <<'END'
+int libfoo () { return 0; }
+END
+
+cat >bar.c <<'END'
+extern int libfoo ();
+int main () { return libfoo (); }
+END
+
+libtoolize
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure
+
+# Hypothesis: EXTRA_*_DEPENDENCIES are honored.
+
+: >foodep
+: >foodep2
+: >bardep
+run_make -O
+grep 'making libfoodep' stdout
+
+rm -f bardep
+$MAKE && exit 1
+: >bardep
+
+$MAKE
+$sleep
+touch libfoo.la
+$MAKE
+$MAKE bar-has-been-updated
+
+$MAKE distcheck
+
+:
diff --git a/t/extra-deps.sh b/t/extra-deps.sh
new file mode 100644
index 000000000..a36c7e712
--- /dev/null
+++ b/t/extra-deps.sh
@@ -0,0 +1,104 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test EXTRA_*_DEPENDENCIES. See 'extra-deps-lt.sh' for libtool variant.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_SUBST([deps], [bardep])
+AM_CONDITIONAL([COND], [test -n "$cond"])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libfoo.a
+EXTRA_libfoo_a_DEPENDENCIES = libfoodep
+libfoodep:
+ @echo making $@
+ @: > $@
+CLEANFILES = libfoodep
+
+bin_PROGRAMS = foo bar
+EXTRA_foo_DEPENDENCIES = foodep
+if COND
+EXTRA_foo_DEPENDENCIES += foodep2
+endif
+bar_LDADD = libfoo.a
+EXTRA_bar_DEPENDENCIES = $(deps)
+
+EXTRA_DIST = foodep bardep
+
+.PHONY: bar-has-been-updated
+bar-has-been-updated:
+ is_newest bar$(EXEEXT) libfoo.a
+END
+
+cat >libfoo.c <<'END'
+int libfoo () { return 0; }
+END
+
+cat >foo.c <<'END'
+int main () { return 0; }
+END
+
+cat >bar.c <<'END'
+extern int libfoo ();
+int main () { return libfoo (); }
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure cond=yes
+
+# Hypotheses:
+# - EXTRA_*_DEPENDENCIES are honored.
+# - Conditionals and substitutions are honored.
+# - *_DEPENDENCIES are not overwritten by their EXTRA_* counterparts.
+
+: >foodep
+: >foodep2
+: >bardep
+run_make -O
+grep 'making libfoodep' stdout
+
+rm -f foodep
+$MAKE && exit 1
+: >foodep
+
+rm -f foodep2
+$MAKE && exit 1
+: >foodep2
+
+rm -f bardep
+$MAKE && exit 1
+: >bardep
+
+$MAKE
+$sleep
+touch libfoo.a
+$MAKE
+$MAKE bar-has-been-updated
+
+$MAKE distcheck
+
+:
diff --git a/t/extra-dist-dirs-and-subdirs.sh b/t/extra-dist-dirs-and-subdirs.sh
new file mode 100644
index 000000000..eb958a0d5
--- /dev/null
+++ b/t/extra-dist-dirs-and-subdirs.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check to make sure EXTRA_DIST can contain a directory or
+# a subdirectory, in $(builddir) or $(srcdir).
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+EXTRA_DIST=foo/bar baz foo2/bar2 baz2
+
+check: distdir
+ test -f $(distdir)/foo/bar/baz
+ test -f $(distdir)/baz/foo
+ test -f $(distdir)/foo2/bar2/baz2
+ test -f $(distdir)/baz2/foo2
+END
+
+# Create some files in $(srcdir)
+mkdir foo
+mkdir foo/bar
+touch foo/bar/baz
+mkdir baz
+touch baz/foo
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+mkdir build
+cd build
+../configure
+
+# Create some files in $(builddir)
+mkdir foo2
+mkdir foo2/bar2
+touch foo2/bar2/baz2
+mkdir baz2
+touch baz2/foo2
+
+$MAKE check
+
+:
diff --git a/t/extra-dist-vpath-dir-merge.sh b/t/extra-dist-vpath-dir-merge.sh
new file mode 100644
index 000000000..95095e575
--- /dev/null
+++ b/t/extra-dist-vpath-dir-merge.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check to make sure that when distdir is invoked in a VPATH
+# configuration and has to distribute directory X, it actually merge
+# $(srcdir)/X and ./X, with the files from the later overriding the
+# files from the former.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+EXTRA_DIST=foo/bar baz
+
+check: distdir
+ test -f $(distdir)/foo/bar/baz
+ test -f $(distdir)/foo/bar/baz2
+ test -f $(distdir)/baz/foo
+ test -f $(distdir)/baz/foo2
+ grep source $(distdir)/foo/bar/baz
+ grep build $(distdir)/foo/bar/baz2
+ grep source $(distdir)/baz/foo
+ grep build $(distdir)/baz/foo2
+END
+
+# Create some files in $(srcdir)
+mkdir foo
+mkdir foo/bar
+echo source > foo/bar/baz
+echo source > foo/bar/baz2
+mkdir baz
+echo source > baz/foo
+echo source > baz/foo2
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+mkdir build
+cd build
+../configure
+
+# Create some files in $(builddir) that will override part of the
+# files if $(srcdir) when the distribution is made.
+mkdir foo
+mkdir foo/bar
+echo build > foo/bar/baz2
+mkdir baz
+echo build > baz/foo2
+
+$MAKE check
+
+:
diff --git a/t/extra-dist-vpath-dir.sh b/t/extra-dist-vpath-dir.sh
new file mode 100644
index 000000000..bce2b44eb
--- /dev/null
+++ b/t/extra-dist-vpath-dir.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check to make sure EXTRA_DIST can contain a directory from $buildir.
+# From Dean Povey.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+EXTRA_DIST=foo
+
+foo:
+ mkdir foo
+ touch foo/bar
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+mkdir build
+cd build
+../configure
+$MAKE distdir
+
+:
diff --git a/t/extra-dist-wildcards-gnu.sh b/t/extra-dist-wildcards-gnu.sh
new file mode 100644
index 000000000..a0536b8c4
--- /dev/null
+++ b/t/extra-dist-wildcards-gnu.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for more complex usage of wildcards in EXTRA_DIST.
+# Suggested by observations from Braden McDaniel.
+
+required=GNUmake
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = -Wno-portability
+
+EXTRA_DIST = $(wildcard [!c-z].t d.t [ab].dir foo.* *zardoz*)
+
+.PHONY: prereq
+prereq:
+ echo a > a.t
+ echo b > b.t
+ echo c > c.t
+ echo d > d.t
+ echo m > m.t
+ echo z > z.t
+ mkdir a.dir b.dir c.dir
+ echo a1 > a.dir/f1
+ echo a2 > a.dir/f2
+ echo bb > b.dir/f
+ echo cc > c.dir/x
+ echo 0 > foo
+ echo 1 > foo.x
+ echo 2 > foo.bar
+ echo foo > _zardoz_
+
+.PHONY: test
+test: distdir
+ ls -l $(distdir) $(distdir)/*.dir ;: For debugging.
+ diff a.t $(distdir)/a.t
+ diff b.t $(distdir)/b.t
+ test ! -r $(distdir)/c.t
+ diff d.t $(distdir)/d.t
+ test ! -r $(distdir)/m.t
+ test ! -r $(distdir)/z.t
+ diff a.dir/f1 $(distdir)/a.dir/f1
+ diff a.dir/f2 $(distdir)/a.dir/f2
+ diff b.dir/f $(distdir)/b.dir/f
+ test ! -r $(distdir)/c.dir
+ diff foo.x $(distdir)/foo.x
+ diff foo.bar $(distdir)/foo.bar
+ test ! -r $(distdir)/foo
+ diff _zardoz_ $(distdir)/_zardoz_
+check-local:
+ ls -l . *.dir ;: For debugging.
+ test -f $(srcdir)/a.t
+ test -f $(srcdir)/b.t
+ test ! -r $(srcdir)/c.t
+ test -f $(srcdir)/d.t
+ test ! -r $(srcdir)/m.t
+ test ! -r $(srcdir)/z.t
+ test -f $(srcdir)/a.dir/f1
+ test -f $(srcdir)/a.dir/f2
+ test -f $(srcdir)/b.dir/f
+ test ! -r $(srcdir)/c.dir
+ test -f $(srcdir)/foo.x
+ test -f $(srcdir)/foo.bar
+ test ! -r $(srcdir)/foo
+ test -f $(srcdir)/_zardoz_
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE prereq
+ls -l . *.dir # For debugging.
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/extra-dist-wildcards-vpath.sh b/t/extra-dist-wildcards-vpath.sh
new file mode 100644
index 000000000..f0be87e81
--- /dev/null
+++ b/t/extra-dist-wildcards-vpath.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that wildcards in elements of EXTRA_DIST are honoured when
+# $srcdir != $builddir, if properly declared.
+# Suggested by observations from Braden McDaniel.
+
+required=GNUmake
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+
+cat > Makefile.am <<'END'
+EXTRA_DIST = *.foo $(srcdir)/*.foo $(builddir)/*.bar $(srcdir)/*.bar
+
+.PHONY: test
+test: distdir
+ ls -l $(srcdir) $(builddir) $(distdir)
+ diff $(srcdir)/a.foo $(distdir)/a.foo
+ diff $(srcdir)/b.bar $(distdir)/b.bar
+ diff $(builddir)/c.foo $(distdir)/c.foo
+ diff $(builddir)/d.bar $(distdir)/d.bar
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+echo aaa > a.foo
+echo bbb > b.bar
+mkdir build
+echo ccc > build/c.foo
+echo ddd > build/d.bar
+
+cd build
+../configure
+$MAKE test
+
+:
diff --git a/t/extra-dist-wildcards.sh b/t/extra-dist-wildcards.sh
new file mode 100644
index 000000000..4c44caa5b
--- /dev/null
+++ b/t/extra-dist-wildcards.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that wildcards in EXTRA_DIST are honoured.
+# Suggested by observations from Braden McDaniel.
+# See also sister test 'extra-dist-wildcards-gnu.sh', that checks a
+# similar usage with the involvement of the $(wildcard) GNU make builtin.
+
+required=GNUmake
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+EXTRA_DIST = *.foo
+.PHONY: test
+test: distdir
+ diff a.foo $(distdir)/a.foo
+ diff b.foo $(distdir)/b.foo
+ test ! -r $(distdir)/c.bar
+check-local:
+ test -f $(srcdir)/a.foo
+ test -f $(srcdir)/b.foo
+ test ! -r $(srcdir)/c.bar
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+echo aaa > a.foo
+echo bbb > b.foo
+echo ccc > c.bar
+./configure
+$MAKE test
+
+:
diff --git a/t/extra-portability.sh b/t/extra-portability.sh
new file mode 100644
index 000000000..487513514
--- /dev/null
+++ b/t/extra-portability.sh
@@ -0,0 +1,95 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check interactions between the 'portability' and 'extra-portability'
+# warning categories:
+# 1. '-Wextra-portability' must imply '-Wportability'.
+# 2. '-Wno-portability' must imply '-Wno-extra-portability'.
+# 3. '-Wall' must imply '-Wextra-portability'.
+
+. test-init.sh
+
+# We want (almost) complete control over automake options.
+AUTOMAKE="$am_original_AUTOMAKE --foreign -Werror"
+
+cat >>configure.ac <<END
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+$ACLOCAL
+
+#
+# First, a setup where only an extra-portability warning is present
+# (no "simple" portability-warnings are).
+#
+
+cat >Makefile.am <<END
+EXTRA_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+# Sanity check: extra-portability warnings causes the expected error.
+AUTOMAKE_fails -Wextra-portability
+grep 'requires.*AM_PROG_AR' stderr
+
+# Warnings in extra-portability category are not enabled by default.
+$AUTOMAKE
+
+# -Wall enables extra-portability.
+AUTOMAKE_fails -Wall
+grep 'requires.*AM_PROG_AR' stderr
+
+# Disabling portability disables extra-portability as well.
+$AUTOMAKE -Wextra-portability -Wno-portability
+$AUTOMAKE -Wall -Wno-portability
+
+#
+# Now, a setup where also a "simple" portability warning is present.
+#
+
+echo 'var = $(foo--bar)' >> Makefile.am
+
+# Enabling extra-portability enables portability as well ...
+AUTOMAKE_fails -Wextra-portability
+grep 'foo--bar' stderr
+grep 'requires.*AM_PROG_AR' stderr
+# ... even if it had been previously disabled.
+AUTOMAKE_fails -Wno-portability -Wextra-portability
+grep 'foo--bar' stderr
+grep 'requires.*AM_PROG_AR' stderr
+
+# Disabling extra-portability leaves portability intact (1).
+AUTOMAKE_fails -Wportability -Wno-extra-portability
+grep 'foo--bar' stderr
+grep 'requires.*AM_PROG_AR' stderr && exit 1
+# Disabling extra-portability leaves portability intact (2).
+AUTOMAKE_fails -Wall -Wno-extra-portability
+grep 'foo--bar' stderr
+grep 'requires.*AM_PROG_AR' stderr && exit 1
+
+# Enabling portability does not enable extra-portability.
+AUTOMAKE_fails -Wportability
+grep 'foo--bar' stderr
+grep 'requires.*AM_PROG_AR' stderr && exit 1
+
+# Disabling portability disables extra-portability.
+$AUTOMAKE -Wno-portability
+$AUTOMAKE -Wextra-portability -Wno-portability
+$AUTOMAKE -Wall -Wno-portability
+
+:
diff --git a/t/extra-portability2.sh b/t/extra-portability2.sh
new file mode 100644
index 000000000..dbb43fea5
--- /dev/null
+++ b/t/extra-portability2.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that extra-portability warnings are not enabled by --gnits,
+# --gnu and --foreign.
+
+. test-init.sh
+
+# We want complete control over automake options.
+AUTOMAKE=$am_original_AUTOMAKE
+
+cat >>configure.ac <<END
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat >Makefile.am <<END
+EXTRA_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+$ACLOCAL
+
+# Make sure the test is useful.
+AUTOMAKE_fails -Wextra-portability \
+ || fatal_ "setup doesn't trigger 'extra-portability' warnings"
+
+$AUTOMAKE --foreign
+
+touch INSTALL NEWS README AUTHORS ChangeLog COPYING # Satisfy --gnu.
+$AUTOMAKE --gnu
+
+touch THANKS # Satisfy also --gnits.
+$AUTOMAKE --gnits
+
+:
diff --git a/t/extra-portability3.sh b/t/extra-portability3.sh
new file mode 100644
index 000000000..0ea3e7ab4
--- /dev/null
+++ b/t/extra-portability3.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check interactions between the 'portability-recursive' and
+# 'extra-portability' warning categories.
+
+. test-init.sh
+
+# We want (almost) complete control over automake options.
+AUTOMAKE="$am_original_AUTOMAKE --foreign -Werror"
+
+cat >>configure.ac <<END
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+$ACLOCAL
+
+cat >Makefile.am <<'END'
+baz = $(foo$(bar))
+lib_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+# 'extra-portability' implies 'portability-recursive'.
+AUTOMAKE_fails -Wextra-portability
+grep 'requires.*AM_PROG_AR' stderr
+grep 'recursive variable expansion' stderr
+
+# We can disable 'extra-portability' while leaving
+# 'portability-recursive' intact.
+AUTOMAKE_fails -Wportability-recursive -Wno-extra-portability
+grep 'requires.*AM_PROG_AR' stderr && exit 1
+grep 'recursive variable expansion' stderr
+
+# We can disable 'portability-recursive' while leaving
+# 'extra-portability' intact.
+AUTOMAKE_fails -Wextra-portability -Wno-portability-recursive
+grep 'requires.*AM_PROG_AR' stderr
+grep 'recursive variable expansion' stderr && exit 1
+
+# Disabling 'portability' disables 'portability-recursive' and
+# 'extra-portability'.
+$AUTOMAKE -Wextra-portability -Wno-portability
+
+:
diff --git a/t/extra-programs-and-libs.sh b/t/extra-programs-and-libs.sh
new file mode 100644
index 000000000..998643b68
--- /dev/null
+++ b/t/extra-programs-and-libs.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure we warn about substitutions in bin_PROGRAMS if EXTRA_PROGRAMS
+# are missing; but only if the former is not AC_SUBSTed itself
+# (lib_LIBRARIES is in the same boat here).
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_SUBST([lib_LIBRARIES])
+AC_SUBST([bins])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+bin_PROGRAMS = @bins@
+END
+
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'bin_PROGRAMS.*contains configure substitution' stderr
+grep 'lib_LIBRARIES.*contains configure substitution' stderr && exit 1
+
+:
diff --git a/t/extra-programs-empty.sh b/t/extra-programs-empty.sh
new file mode 100644
index 000000000..5a7390857
--- /dev/null
+++ b/t/extra-programs-empty.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that EXTRA_PROGRAMS doesn't get removed because it is empty.
+# This check has been introduced in commit 'Release-1-9-254-g9d0eaef'
+# into the former test 'subst2.test'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([Makefile2 Makefile3])
+AC_SUBST([prog])
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+EXTRA_PROGRAMS =
+END
+
+cat > Makefile2.am <<'END'
+bin_PROGRAMS = a @prog@ b
+EXTRA_PROGRAMS =
+END
+
+cat > Makefile3.am <<'END'
+empty =
+EXTRA_PROGRAMS = $(empty)
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^EXTRA_PROGRAMS = *$' Makefile.in
+grep '^EXTRA_PROGRAMS = *$' Makefile2.in
+# Be laxer here, since EXTRA_PROGRAMS might be internally rewritten
+# by Automake when it contains references to other variables.
+grep '^EXTRA_PROGRAMS =' Makefile3.in
+
+:
diff --git a/t/extra-programs-misc.sh b/t/extra-programs-misc.sh
new file mode 100644
index 000000000..a34a7cf9f
--- /dev/null
+++ b/t/extra-programs-misc.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure defining bin_PROGRAMS in terms of EXTRA_PROGRAMS works,
+# and that referring to the same program with inconsistent addition
+# of $(EXEEXT) works, too.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+cat >Makefile.am <<'END'
+EXTRA_PROGRAMS = foo bar
+bin_PROGRAMS = $(EXTRA_PROGRAMS) baz
+noinst_PROGRAMS = baz$(EXEEXT)
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/extra-sources-no-spurious.sh b/t/extra-sources-no-spurious.sh
new file mode 100644
index 000000000..cf4ff167f
--- /dev/null
+++ b/t/extra-sources-no-spurious.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check to make sure EXTRA_foo_SOURCES are not defined unnecessarily.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep EXTRA_foo_SOURCES Makefile.in && exit 1
+
+:
diff --git a/t/extra-sources.sh b/t/extra-sources.sh
new file mode 100644
index 000000000..db00e6a9e
--- /dev/null
+++ b/t/extra-sources.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure EXTRA_..._SOURCES actually works.
+# Bug report from Henrik Frystyk Nielsen.
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = www
+www_SOURCES = www.c
+EXTRA_www_SOURCES = xtra.c
+www_LDADD = @extra_stuff@
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '@am__include@ .*/xtra\.Po' Makefile.in
+grep '^am__depfiles_remade =.*/xtra.Po' Makefile.in
+
+:
diff --git a/t/extra.sh b/t/extra.sh
new file mode 100644
index 000000000..b67c0d756
--- /dev/null
+++ b/t/extra.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure EXTRA_ targets are generated. This test used to
+# make sure the targets were *not* generated. That is wrong; the
+# targets should always be generated. However, they should not be
+# built by default.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = @foo@
+EXTRA_PROGRAMS = zardoz
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep "^zardoz" Makefile.in
+
+# Can't have EXTRA clean rules.
+grep 'clean.*EXTRA' Makefile.in && exit 1
+
+:
diff --git a/t/f90only.sh b/t/f90only.sh
new file mode 100644
index 000000000..2f0c02ace
--- /dev/null
+++ b/t/f90only.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure programs with only Fortran 90 source are handled properly.
+# (copied from 'fonly.sh') Mike Nolta <mrnolta@princeton.edu>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_FC
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = zardoz.f90
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep 'zardoz.f90' Makefile.in
diff --git a/t/flavor.sh b/t/flavor.sh
new file mode 100644
index 000000000..e6156994b
--- /dev/null
+++ b/t/flavor.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure flavors like 'cygnus', 'gnu', 'gnits' and command line
+# options like '--ignore-deps' and '--silent-rules' are preserved across
+# automake reruns.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_MAINTAINER_MODE
+AC_OUTPUT
+END
+
+: > Makefile.am
+: > NEWS
+: > README
+: > AUTHORS
+: > ChangeLog
+: > THANKS
+
+$ACLOCAL
+$AUTOCONF
+# Order flavors so that all needed files are installed early.
+for flavor in --gnits --gnu --foreign --ignore-deps; do
+
+ $AUTOMAKE --add-missing $flavor
+ ./configure --enable-maintainer-mode
+ grep " $flavor" Makefile
+ $MAKE
+
+ # Two code paths in configure.am:
+ # - either a file in $(am__configure_deps) has been updated ...
+ $sleep
+ touch aclocal.m4
+ $MAKE
+ grep " $flavor" Makefile
+
+ # - ... or not; i.e., Makefile.am or an included file has.
+ $sleep
+ touch Makefile.am
+ $MAKE
+ grep " $flavor" Makefile
+
+done
+
+:
diff --git a/t/flibs.sh b/t/flibs.sh
new file mode 100644
index 000000000..c43f4f4ac
--- /dev/null
+++ b/t/flibs.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'AC_F77_LIBRARY_LDFLAGS' works properly.
+# Matthew D. Langston <langston@SLAC.Stanford.EDU>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_F77
+AC_F77_LIBRARY_LDFLAGS
+END
+
+# Tue Aug 11 09:50:48 1998 Matthew D. Langston <langston@SLAC.Stanford.EDU>
+#
+# This test currently fails with automake v. 1.3 since automake assumes
+# that elements of 'bin_PROGRAMS' (e.g. zardoz) without a corresponding
+# '_SOURCES' (e.g. zardoz_SOURCES) should be compiled from 'zardoz.c'
+# whether or not 'zardoz.c' actually exists. For example, even if the
+# file 'zardoz.c' doesn't exist but the file 'zardoz.f' does exist, this
+# tests would still fail.
+#
+# Therefore, for now I have put in the line 'zardoz_SOURCES = zardoz.f'
+# (see below) so that automake's top-level 'make check' won't fail, but
+# this line should be removed once automake handles this situation
+# correctly.
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = zardoz.f
+zardoz_LDADD = @FLIBS@
+END
+
+: > zardoz.f
+: > config.guess
+: > config.sub
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '@FLIBS@' Makefile.in
diff --git a/t/fn99.sh b/t/fn99.sh
new file mode 100644
index 000000000..8305d637f
--- /dev/null
+++ b/t/fn99.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check the filename-length-max=99 option.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat >Makefile.am <<'END'
+AUTOMAKE_OPTIONS = filename-length-max=99
+EXTRA_DIST = 12345678
+END
+
+(for i in 1 2 3 4 5 6 7 8 9; do
+ mkdir -p 12345678 && cd 12345678 && touch x || exit 1
+done) || skip_ "failed to create deep directory hierarchy"
+
+# AIX 5.3 'cp -R' is too buggy for 'make dist'.
+cp -R 12345678 t \
+ || skip_ "'cp -R' failed to copy deep directory hierarchy"
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
+
+(for i in 1 2 3 4 5 6 7 8 9 10 11; do
+ mkdir -p 12345678 && cd 12345678 && touch x || exit 1
+done) || skip_ "failed to create deeper directory hierarchy"
+
+run_make -E -e FAIL dist
+grep 'filenames are too long' stderr
+test 2 -eq $(grep -c 12345678 stderr)
+
+:
diff --git a/t/fn99subdir.sh b/t/fn99subdir.sh
new file mode 100644
index 000000000..5d6c37c2d
--- /dev/null
+++ b/t/fn99subdir.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# PR 507: Check the filename-length-max=99 option
+# in conjunction with AC_CONFIG_SUBDIRS.
+
+. test-init.sh
+
+# The name is so that 99 is exactly hit (including final \0).
+subdirname='cnfsubdir'
+
+cat >>configure.ac <<END
+AC_CONFIG_SUBDIRS([$subdirname])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<END
+AUTOMAKE_OPTIONS = filename-length-max=99
+SUBDIRS = $subdirname
+END
+
+mkdir $subdirname
+
+cat >> $subdirname/configure.ac <<EOF
+AC_INIT([$subdirname], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+EOF
+
+cat >$subdirname/Makefile.am <<'END'
+AUTOMAKE_OPTIONS = filename-length-max=99
+EXTRA_DIST = 12345678
+END
+
+(cd $subdirname || exit 1
+for i in 1 2 3 4 5 6 7 8; do
+ mkdir -p 12345678 && cd 12345678 && touch x || exit 1
+done) || skip_ "failed to create deep directory hierarchy"
+
+# AIX 5.3 'cp -R' is too buggy for 'make dist'.
+cp -R $subdirname t \
+ || skip_ "'cp -R' failed to copy deep directory hierarchy"
+
+cd $subdirname
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+cd ..
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE distcheck
+
+(cd $subdirname || exit 1
+for i in 1 2 3 4 5 6 7 8 9; do
+ mkdir -p 12345678 && cd 12345678 && touch x || exit 1
+done) || skip_ "failed to create deeper directory hierarchy"
+
+run_make -E -e FAIL dist
+grep 'filenames are too long' stderr
+test 1 -eq $(grep -c 12345678 stderr)
+
+:
diff --git a/t/fnoc.sh b/t/fnoc.sh
new file mode 100644
index 000000000..4672e37e2
--- /dev/null
+++ b/t/fnoc.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that pure Fortran 77 sources don't include
+# C-specific code.
+# Matthew D. Langston <langston@SLAC.Stanford.EDU>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_F77
+END
+
+cat > Makefile.am << 'END'
+sbin_PROGRAMS = anonymous
+anonymous_SOURCES = doe.f jane.f
+END
+
+: > doe.f
+: > jane.f
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '[^F]CC' Makefile.in | grep -v MKDEP && exit 1
+exit 0
diff --git a/t/fonly.sh b/t/fonly.sh
new file mode 100644
index 000000000..de693e120
--- /dev/null
+++ b/t/fonly.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure programs with only Fortran 77 source are handled properly.
+# Matthew D. Langston <langston@SLAC.Stanford.EDU>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_F77
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = zardoz.f
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep 'zardoz.f' Makefile.in
diff --git a/t/forcemiss.sh b/t/forcemiss.sh
new file mode 100644
index 000000000..8d9491231
--- /dev/null
+++ b/t/forcemiss.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that 'automake --force-missing' works.
+
+. test-init.sh
+
+rm -f install-sh
+
+echo zot > install-sh
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE --add-missing --force-missing
+
+ls -l install-sh
+test -f install-sh
+grep zot install-sh && exit 1
+
+:
diff --git a/t/forcemiss2.sh b/t/forcemiss2.sh
new file mode 100644
index 000000000..5a9bbeff6
--- /dev/null
+++ b/t/forcemiss2.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that 'automake --force-missing' works, even with
+# symlinked files.
+
+. test-init.sh
+
+rm -f install-sh
+
+echo zot > foo
+cp foo foo2
+
+ln -s foo2 install-sh || skip_ "cannot create symlinks to files"
+
+: > Makefile.am
+
+$ACLOCAL
+ls -l install-sh
+$AUTOMAKE --add-missing --force-missing
+ls -l install-sh
+
+test -f install-sh
+grep zot install-sh && exit 1
+diff foo foo2
+
+:
diff --git a/t/fort1.sh b/t/fort1.sh
new file mode 100644
index 000000000..7a96934c8
--- /dev/null
+++ b/t/fort1.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that Automake suggests using AC_PROG_F77/FC if Fortran sources
+# are used.
+
+. test-init.sh
+
+cat >Makefile.am <<END
+bin_PROGRAMS = hello
+hello_SOURCES = hello.f foo.f95
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep AC_PROG_F77 stderr
+grep AC_PROG_FC stderr
diff --git a/t/fort2.sh b/t/fort2.sh
new file mode 100644
index 000000000..cba91f9a8
--- /dev/null
+++ b/t/fort2.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that AC_FC_SRCEXT(f9x) works as intended:
+# - $(FCFLAGS_f) will be used
+
+# Cf. 'fort1.sh' and 'link_f90_only.sh'.
+
+required=gfortran # Required only in order to run ./configure.
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'END'
+AC_PROG_FC
+AC_FC_SRCEXT([f90])
+AC_FC_SRCEXT([f95])
+AC_FC_SRCEXT([f03])
+AC_FC_SRCEXT([f08])
+AC_FC_SRCEXT([blabla])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+FC = fake-fc
+bin_PROGRAMS = hello goodbye
+hello_SOURCES = hello.f90 foo.f95 sub/bar.f95 hi.f03 sub/howdy.f03 \
+ greets.f08 sub/bonjour.f08
+goodbye_SOURCES = bye.f95 sub/baz.f90
+goodbye_FCFLAGS = --gby
+END
+
+$ACLOCAL
+$AUTOMAKE
+grep '.\$(LINK)' Makefile.in && exit 1
+grep '.\$(FCLINK)' Makefile.in
+grep '.\$(FCCOMPILE)' Makefile.in > stdout
+cat stdout
+grep -v '\$(FCFLAGS_f' stdout && exit 1
+grep '.\$(FC.*\$(FCFLAGS_blabla' Makefile.in && exit 1
+
+sed '/^AC_FC_SRCEXT.*blabla/d' configure.ac >t
+mv -f t configure.ac
+
+rm -rf autom4te*.cache
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+
+touch hello.f90 foo.f95 sub/bar.f95 hi.f03 sub/howdy.f03 greets.f08 \
+ sub/bonjour.f08 bye.f95 sub/baz.f90
+
+run_make -O -- -n \
+ FCFLAGS_f90=--@90 FCFLAGS_f95=--@95 FCFLAGS_f03=--@03 FCFLAGS_f08=--@08
+# To make it easier to have stricter grepping below.
+sed -e 's/[ ][ ]*/ /g' -e 's/^/ /' -e 's/$/ /' stdout > out
+cat out
+
+grep ' fake-fc .* --@90 .* hello\.f90 ' out
+grep ' fake-fc .* --@95 .* foo\.f95 ' out
+grep ' fake-fc .* --@95 .* sub/bar\.f95 ' out
+grep ' fake-fc .* --@03 .* hi\.f03 ' out
+grep ' fake-fc .* --@03 .* sub/howdy\.f03 ' out
+grep ' fake-fc .* --@08 .* greets\.f08 ' out
+grep ' fake-fc .* --@08 .* sub/bonjour\.f08 ' out
+grep ' fake-fc .* --gby .* --@95 .*[` ]bye\.f95 ' out
+grep ' fake-fc .* --gby .* --@90 .*[` ]sub/baz\.f90 ' out
+
+test $(grep -c '.*--gby.*\.f' out) -eq 2
+
+$EGREP 'fake-fc.*--@(95|03|08).*\.f90' out && exit 1
+$EGREP 'fake-fc.*--@(90|03|08).*\.f95' out && exit 1
+$EGREP 'fake-fc.*--@(90|95|08).*\.f03' out && exit 1
+$EGREP 'fake-fc.*--@(95|95|03).*\.f08' out && exit 1
+
+:
diff --git a/t/fort4.sh b/t/fort4.sh
new file mode 100644
index 000000000..c9459dfff
--- /dev/null
+++ b/t/fort4.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test mixing Fortran 77 and Fortran (FC).
+
+# For now, require the GNU compilers (to avoid some Libtool/Autoconf
+# issues).
+required='g77 gfortran'
+. test-init.sh
+
+mkdir sub
+
+cat >hello.f <<'END'
+ program hello
+ call foo
+ call bar
+ stop
+ end
+END
+
+cat >bye.f90 <<'END'
+program goodbye
+ call baz
+ stop
+end
+END
+
+cat >foo.f90 <<'END'
+ subroutine foo
+ return
+ end
+END
+
+sed s,foo,bar, foo.f90 > sub/bar.f90
+sed s,foo,baz, foo.f90 > sub/baz.f
+
+cat >>configure.ac <<'END'
+AC_PROG_F77
+AC_PROG_FC
+AC_FC_SRCEXT([f90], [],
+ [AC_MSG_FAILURE([$FC compiler cannot create executables], 77)])
+AC_FC_LIBRARY_LDFLAGS
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+bin_PROGRAMS = hello goodbye
+hello_SOURCES = hello.f foo.f90 sub/bar.f90
+goodbye_SOURCES = bye.f90 sub/baz.f
+goodbye_FCFLAGS =
+LDADD = $(FCLIBS)
+END
+
+$ACLOCAL
+$AUTOMAKE -a -Wno-unsupported
+# The Fortran 77 linker should be preferred:
+grep '.\$(FCLINK)' Makefile.in && exit 1
+
+$AUTOCONF
+# ./configure may exit with status 77 if no compiler is found,
+# or if the compiler cannot compile Fortran 90 files).
+./configure
+$MAKE
+subobjs=$(echo sub/*.o sub/*.obj)
+test "$subobjs" = 'sub/*.o sub/*.obj'
+$MAKE distcheck
+
+$MAKE distclean
+echo 'AUTOMAKE_OPTIONS = subdir-objects' >> Makefile.am
+$AUTOMAKE
+./configure
+$MAKE
+test ! -e bar.o
+test ! -e bar.obj
+test ! -e baz.o
+test ! -e baz.obj
+test ! -e goodbye-baz.o
+test ! -e goodbye-baz.obj
+$MAKE distcheck
+
+:
diff --git a/t/fort5.sh b/t/fort5.sh
new file mode 100644
index 000000000..706339dfd
--- /dev/null
+++ b/t/fort5.sh
@@ -0,0 +1,109 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test mixing Fortran 77 and Fortran (FC), libtool version.
+
+# For now, require the GNU compilers (to avoid some Libtool/Autoconf
+# issues).
+required='libtoolize g77 gfortran'
+. test-init.sh
+
+mkdir sub
+
+cat >hello.f <<'END'
+ program hello
+ call foo
+ call bar
+ call goodbye
+ stop
+ end
+END
+
+cat >bye.f90 <<'END'
+subroutine goodbye
+ call baz
+ return
+end
+END
+
+cat >foo.f90 <<'END'
+ subroutine foo
+ return
+ end
+END
+
+sed s,foo,bar, foo.f90 > sub/bar.f90
+sed s,foo,baz, foo.f90 > sub/baz.f
+
+cat >>configure.ac <<'END'
+AC_PROG_F77
+AC_PROG_FC
+AC_FC_SRCEXT([f90], [],
+ [AC_MSG_FAILURE([$FC compiler cannot create executables], 77)])
+AC_FC_LIBRARY_LDFLAGS
+AM_PROG_AR
+LT_PREREQ([2.0])
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+bin_PROGRAMS = hello
+lib_LTLIBRARIES = libhello.la
+noinst_LTLIBRARIES = libgoodbye.la
+hello_SOURCES = hello.f
+hello_LDADD = libhello.la
+libhello_la_SOURCES = foo.f90 sub/bar.f90
+libhello_la_LIBADD = libgoodbye.la
+libgoodbye_la_SOURCES = bye.f90 sub/baz.f
+libgoodbye_la_FCFLAGS =
+LDADD = $(FCLIBS)
+END
+
+libtoolize --force
+$ACLOCAL
+# FIXME: stop disabling the warnings in the 'unsupported' category
+# FIXME: once the 'subdir-objects' option has been mandatory.
+$AUTOMAKE -a -Wno-unsupported
+$AUTOCONF
+
+# This test requires Libtool >= 2.0. Earlier Libtool does not
+# have the LT_PREREQ macro to cause autoconf failure.
+grep LT_PREREQ configure && skip_ "libtool is too old (probably < 2.0)"
+
+# Ensure we use --tag for f90, too.
+grep " --tag=FC" Makefile.in
+
+# ./configure may exit with status 77 if no compiler is found,
+# or if the compiler cannot compile Fortran 90 files).
+./configure
+$MAKE
+subobjs=$(echo sub/*.lo)
+test "$subobjs" = 'sub/*.lo'
+$MAKE distcheck
+
+# The following will be fixed in a later patch:
+$MAKE distclean
+echo 'AUTOMAKE_OPTIONS = subdir-objects' >> Makefile.am
+$AUTOMAKE -a
+./configure
+$MAKE
+test ! -e bar.lo
+test ! -e baz.lo
+test ! -e libgoodbye_la-baz.lo
+$MAKE distcheck
+
+:
diff --git a/t/fortdep.sh b/t/fortdep.sh
new file mode 100644
index 000000000..97015c740
--- /dev/null
+++ b/t/fortdep.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure dependency tracking doesn't interfere with Fortran.
+# For PR 75.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_SRCDIR([foo.f])
+AC_PROG_F77
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS=foo
+foo_SOURCES=foo.f
+END
+
+: > foo.f
+
+$ACLOCAL
+$AUTOMAKE
+
+grep 'foo\.Po' Makefile.in && exit 1
+exit 0
diff --git a/t/gcj.sh b/t/gcj.sh
new file mode 100644
index 000000000..06816f3d1
--- /dev/null
+++ b/t/gcj.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of compiled java.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+_AM_DEPENDENCIES([GCJ])
+AC_SUBST([GCJ])
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = convert
+convert_SOURCES = x/y/convert.java
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^x/y/convert' Makefile.in
+
+:
diff --git a/t/gcj2.sh b/t/gcj2.sh
new file mode 100644
index 000000000..5226947d5
--- /dev/null
+++ b/t/gcj2.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure '..' invalid in subdir .o's.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+_AM_DEPENDENCIES(GCJ)
+AC_SUBST(GCJ)
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = convert
+convert_SOURCES = x/../convert.java
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'Makefile.am:.*\.\.' stderr
diff --git a/t/gcj3.sh b/t/gcj3.sh
new file mode 100644
index 000000000..2eaf135a1
--- /dev/null
+++ b/t/gcj3.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure dependency tracking works for java.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+_AM_DEPENDENCIES([GCJ])
+AC_SUBST([GCJ])
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = convert
+convert_SOURCES = x/y/convert.java
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+test $($FGREP -c depcomp Makefile.in) -gt 1
+
+:
diff --git a/t/gcj4.sh b/t/gcj4.sh
new file mode 100644
index 000000000..0438d607c
--- /dev/null
+++ b/t/gcj4.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure dependency tracking works for Java.
+
+required=gcj
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_GCJ
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = convert
+convert_SOURCES = convert.java
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure >stdout || { cat stdout; exit 1; }
+cat stdout
+
+# Configure must be checking the dependency style of gcj ...
+grep 'dependency style of gcj' stdout >filt
+cat filt
+
+# ... only once.
+test $(wc -l < filt) = 1
+
+# Accept any outcome but 'none'
+# (at the time of writing it should be gcc or gcc3).
+grep -v none filt
+
+:
diff --git a/t/gcj5.sh b/t/gcj5.sh
new file mode 100644
index 000000000..d52590b6f
--- /dev/null
+++ b/t/gcj5.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake suggests AM_PROG_GCJ when GCJ is needed.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+_AM_DEPENDENCIES(GCJ)
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = convert
+convert_SOURCES = convert.java
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep AM_PROG_GCJ stderr
diff --git a/t/gcj6.sh b/t/gcj6.sh
new file mode 100644
index 000000000..9f80a2578
--- /dev/null
+++ b/t/gcj6.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# AM_PROG_GCJ should cause OBJEXT and EXEEXT to be set.
+
+required='gcj'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_GCJ
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = test
+test_SOURCES = Test.java
+test_LDFLAGS = --main=Test
+END
+
+cat >Test.java << 'END'
+public class Test {
+ public static void main(String[] argv) {
+ System.out.println("Hello, automake!");
+ }
+}
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure
+
+# These fail without e.g., AC_PROG_CC.
+$MAKE
+grep "OBJEXT = " Makefile
+grep "EXEEXT = " Makefile
+
+:
diff --git a/t/get-sysconf.sh b/t/get-sysconf.sh
new file mode 100644
index 000000000..f2a4145e0
--- /dev/null
+++ b/t/get-sysconf.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Dummy test case, aimed at reporting useful system information in the
+# final 'test-suite.log'. This way, if a user experiences a failure in
+# the Automake test suite and then only sends us the 'test-suite.log',
+# we won't have to ask him for more information to start analyzing the
+# failure (that had happened too many times in the past!).
+
+. test-init.sh
+
+st=0
+if test -d "$am_top_srcdir"/.git; then
+ # We are running from a git checkout.
+ (cd "$am_top_srcdir" && git log -1) || st=1
+elif test -f "$am_top_srcdir"/ChangeLog; then
+ # We are probably running from a distribution tarball.
+ awk '
+ BEGIN { first = 1 }
+ (first == 1) { print; first = 0; next; }
+ /^[^\t]/ { exit(0); }
+ { print }
+ ' "$am_top_srcdir"/ChangeLog || st=1
+else
+ # Some non-common but possibly valid setup (see for example the Homebrew
+ # problem reported in automake bug#10866); so just give an harmless
+ # warning instead of failing.
+ warn_ "no .git directory nor ChangeLog file found, some info won't" \
+ "be available"
+fi
+$PERL -V || st=1
+# It's OK for the user not to have the TAP::Parser module; this can
+# happen with older perl installation, or on MinGW/MSYS.
+$PERL -e 'use TAP::Parser; print $TAP::Parser::VERSION, "\n"' || :
+
+# It's OK if the selected Lex and Yacc programs don't know how to print
+# the version number or the help screen; those are usually available only
+# for Flex and Bison.
+$LEX --version || :
+$LEX --help || :
+$YACC --version || :
+$YACC --help || :
+
+cat "$am_top_builddir/config.log" || st=1
+cat "$am_top_builddir/bin/aclocal-$APIVERSION" || st=1
+cat "$am_top_builddir/bin/automake-$APIVERSION" || st=1
+
+if test $st -eq 0; then
+ # This test SKIPs, so that all the information it has gathered and
+ # printed will get unconditionally copied into the 'test-suite.log'
+ # file.
+ exit 77
+fi
+
+# Some unexpected error occurred; this must be reported as an hard
+# error by the testsuite driver.
+exit 99
diff --git a/t/gettext-basics.sh b/t/gettext-basics.sh
new file mode 100644
index 000000000..31cb346e1
--- /dev/null
+++ b/t/gettext-basics.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check basic gettext support.
+
+required='gettext'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_GNU_GETTEXT
+AC_OUTPUT
+END
+
+: > Makefile.am
+: > config.rpath
+mkdir po intl
+
+$ACLOCAL
+$AUTOCONF
+
+# po/ and intl/ are required.
+
+AUTOMAKE_fails --add-missing
+grep 'AM_GNU_GETTEXT.*SUBDIRS' stderr
+
+echo 'SUBDIRS = po' >Makefile.am
+AUTOMAKE_fails --add-missing
+grep 'AM_GNU_GETTEXT.*intl' stderr
+
+echo 'SUBDIRS = intl' >Makefile.am
+AUTOMAKE_fails --add-missing
+grep 'AM_GNU_GETTEXT.*po' stderr
+
+# Ok.
+
+echo 'SUBDIRS = po intl' >Makefile.am
+$AUTOMAKE --add-missing
+
+# Make sure distcheck runs './configure --with-included-gettext'.
+./configure
+echo distdir: > po/Makefile
+echo distdir: > intl/Makefile
+$MAKE -n distcheck | grep '.*--with-included-gettext'
+
+:
diff --git a/t/gettext-config-rpath.sh b/t/gettext-config-rpath.sh
new file mode 100644
index 000000000..939182d7e
--- /dev/null
+++ b/t/gettext-config-rpath.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check the config.rpath requirement.
+
+required='gettext'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_GNU_GETTEXT
+# config.rpath is required by versions >= 0.14.3.
+AM_GNU_GETTEXT_VERSION([0.14.3])
+AC_OUTPUT
+END
+
+echo 'SUBDIRS = po intl' >Makefile.am
+mkdir po intl
+
+# If aclocal fails here, it may be that gettext is too old to provide
+# AM_GNU_GETTEXT_VERSION. Similarly, autopoint will fail if it's
+# from an older version. If gettext is too old to provide autopoint,
+# this will fail as well, so we're safe here.
+if ! $ACLOCAL && autopoint -n; then
+ skip_ "too old gettext installation"
+fi
+
+AUTOMAKE_fails --add-missing
+grep '^configure\.ac:.*required file.*config.rpath' stderr
+: > config.rpath
+$AUTOMAKE
+
+:
diff --git a/t/gettext-external-pr338.sh b/t/gettext-external-pr338.sh
new file mode 100644
index 000000000..d1a60f0b4
--- /dev/null
+++ b/t/gettext-external-pr338.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check gettext 'external' support.
+# PR/338, reported by Charles Wilson.
+
+required='gettext'
+. test-init.sh
+
+cat >>configure.ac <<END
+AM_GNU_GETTEXT([external])
+AC_OUTPUT
+END
+
+: >Makefile.am
+mkdir foo po
+
+$ACLOCAL
+$AUTOCONF
+
+# config.rpath is required.
+: >config.rpath
+
+# po/ is required, but intl/ isn't.
+
+AUTOMAKE_fails --add-missing
+grep 'AM_GNU_GETTEXT.*SUBDIRS' stderr
+
+echo 'SUBDIRS = foo' >Makefile.am
+AUTOMAKE_fails --add-missing
+grep 'AM_GNU_GETTEXT.*po' stderr
+
+# Ok.
+
+echo 'SUBDIRS = po' >Makefile.am
+$AUTOMAKE --add-missing
+
+
+# Don't try running ./configure --with-included-gettext if the
+# user is using AM_GNU_GETTEXT([external]).
+grep 'with-included-gettext' Makefile.in && exit 1
+./configure
+$MAKE -n distcheck | grep 'with-included-gettext' && exit 1
+
+# intl/ isn't wanted with AM_GNU_GETTEXT([external]).
+
+mkdir intl
+echo 'SUBDIRS = po intl' >Makefile.am
+AUTOMAKE_fails --add-missing
+grep 'intl.*AM_GNU_GETTEXT' stderr
+
+:
diff --git a/t/gettext-intl-subdir.sh b/t/gettext-intl-subdir.sh
new file mode 100644
index 000000000..7f3322eac
--- /dev/null
+++ b/t/gettext-intl-subdir.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check gettext 'AM_GNU_GETTEXT_INTL_SUBDIR' support.
+
+required='gettext'
+. test-init.sh
+
+cat >>configure.ac <<END
+AM_GNU_GETTEXT([external])
+AM_GNU_GETTEXT_INTL_SUBDIR
+AC_OUTPUT
+END
+
+echo 'SUBDIRS = po' >Makefile.am
+mkdir po
+
+# If aclocal fails, assume the gettext macros are too old and do not
+# define AM_GNU_GETTEXT_INTL_SUBDIR.
+$ACLOCAL || skip_ "your gettext macros are probably too old"
+
+# config.rpath is required.
+: >config.rpath
+
+# intl/ is required.
+AUTOMAKE_fails --add-missing
+grep 'AM_GNU_GETTEXT.*intl.*SUBDIRS' stderr
+
+mkdir intl
+AUTOMAKE_fails --add-missing
+grep 'AM_GNU_GETTEXT.*intl.*SUBDIRS' stderr
+
+echo 'SUBDIRS = po intl' > Makefile.am
+$AUTOMAKE --add-missing
+
+:
diff --git a/t/gettext-macros.sh b/t/gettext-macros.sh
new file mode 100644
index 000000000..edb131146
--- /dev/null
+++ b/t/gettext-macros.sh
@@ -0,0 +1,96 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Try to find the gettext '.m4' files and make them easily accessed
+# to the test cases requiring them.
+# See also automake bug#9807.
+
+. test-init.sh
+
+extract_program_version ()
+{
+ "$1" --version | sed 1q | $PERL -ne '/(\d(?:\.\d+)+)/ and print "$1\n"'
+}
+
+echo "# Automatically generated by $me." > get.sh
+echo : >> get.sh
+
+# The 'autopoint' script will look into Makefile.am.
+echo ACLOCAL_AMFLAGS = -I m4 > Makefile.am
+
+# Prefer autopoint to gettextize, since the latter unconditionally
+# requires user interaction to complete; yes, this means confirmation
+# from /dev/tty (!) -- see:
+# <https://lists.gnu.org/archive/html/bug-gettext/2011-12/msg00000.html>
+
+# We will need to specify the correct autopoint version in the
+# AM_GNU_GETTEXT_VERSION call in configure.ac if we want autopoint to
+# setup the correct infrastructure -- in particular, for what concerns
+# us, to bring in all the required .m4 files.
+autopoint_version=$(extract_program_version autopoint) \
+ && test -n "$autopoint_version" \
+ || autopoint_version=0.10.35
+
+cat > configure.ac <<END
+AC_INIT([foo], [1.0])
+AC_PROG_CC
+# Both required by autopoint.
+AM_GNU_GETTEXT
+AM_GNU_GETTEXT_VERSION([$autopoint_version])
+END
+
+if autopoint --force && test -f m4/gettext.m4; then
+ echo "ACLOCAL_PATH='$(pwd)/m4':\$ACLOCAL_PATH" >> get.sh
+ echo "export ACLOCAL_PATH" >> get.sh
+else
+ # Older versions of gettext might not have an autopoint program
+ # available, but this doesn't mean the user hasn't made the gettext
+ # macros available, e.g., by properly setting ACLOCAL_PATH.
+ rm -rf m4
+ mkdir m4
+ # See below for an explanation about the use the of '-Wno-syntax'.
+ if $ACLOCAL -Wno-syntax -I m4 --install && test -f m4/gettext.m4; then
+ : # Gettext macros already accessible by default.
+ else
+ echo "skip_all_ \"couldn't find or get gettext macros\"" >> get.sh
+ fi
+fi
+
+cat >> get.sh <<'END'
+# Even recent versions of gettext used the now-obsolete 'AM_PROG_MKDIR_P'
+# m4 macro. So we need the following to avoid spurious errors.
+ACLOCAL="$ACLOCAL -Wno-obsolete"
+AUTOMAKE="$AUTOMAKE -Wno-obsolete"
+END
+
+. ./get.sh
+
+$ACLOCAL --force -I m4 || cat >> get.sh <<'END'
+# We need to use '-Wno-syntax', since we do not want our test suite
+# to fail merely because some third-party '.m4' file is underquoted.
+ACLOCAL="$ACLOCAL -Wno-syntax"
+END
+
+# Remove any Makefile.in possibly created by autopoint, to avoid spurious
+# maintainer-check failures.
+rm -f $(find . -name Makefile.in)
+
+# The file autopoint might have copied in the 'm4' subdirectory of the
+# test directory are going to be needed by other tests, so we must not
+# remove the test directory.
+keep_testdirs=yes
+
+:
diff --git a/t/gettext-pr381.sh b/t/gettext-pr381.sh
new file mode 100644
index 000000000..750765fb0
--- /dev/null
+++ b/t/gettext-pr381.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automake gettext support: regression check for PR/381:
+# 'SUBDIRS = po intl' must not be required if 'po/' doesn't exist.
+
+required='gettext'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_GNU_GETTEXT
+AC_OUTPUT
+END
+
+$ACLOCAL
+
+: > config.guess
+: > config.rpath
+: > config.sub
+
+test ! -d po # Sanity check.
+mkdir sub
+echo 'SUBDIRS = sub' > Makefile.am
+$AUTOMAKE
+
+# Still, SUBDIRS must be defined.
+
+: > Makefile.am
+AUTOMAKE_fails
+grep '^configure\.ac:.*AM_GNU_GETTEXT used but SUBDIRS not defined' stderr
+
+:
diff --git a/t/gnits.sh b/t/gnits.sh
new file mode 100644
index 000000000..f101f826a
--- /dev/null
+++ b/t/gnits.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to ensure --gnits version checking is correct.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [3.5.3.2])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES(Makefile)
+END
+
+cat > Makefile.am << 'END'
+pkgdata_DATA =
+END
+
+# Files required by Gnits.
+: > INSTALL
+: > NEWS
+: > README
+: > COPYING
+: > AUTHORS
+: > ChangeLog
+: > THANKS
+
+$ACLOCAL
+AUTOMAKE_fails --gnits
+grep 'configure.ac:.*3\.5\.3\.2' stderr
diff --git a/t/gnits2.sh b/t/gnits2.sh
new file mode 100644
index 000000000..a5e4065b2
--- /dev/null
+++ b/t/gnits2.sh
@@ -0,0 +1,115 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to ensure std-options checking is correct.
+
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = gnits
+noinst_PROGRAMS = fubar2
+bin_PROGRAMS = fubar sub/fine
+nobase_bin_PROGRAMS = sub/fubar3
+fubar_SOURCES = fubar.c
+fubar2_SOURCES = fubar.c
+sub_fubar3_SOURCES = fubar.c
+sub_fine_SOURCES = fine.c
+bin_SCRIPTS = sub/scriptok.sh sub/scriptnok.sh
+
+grep-stderr:
+ grep 'pfubar$(EXEEXT) does not support' stderr
+ grep 'pfubar3$(EXEEXT) does not support' stderr
+ grep 'pscriptnok\.sh does not support' stderr
+## Only three failures please.
+ test `grep 'does not support --help' stderr | wc -l` = 3
+ test `grep 'does not support --version' stderr | wc -l` = 3
+
+test-install: install
+ test -f ../inst-dir/bin/pfine$(EXEEXT)
+ test ! -f ../inst-dir/bin/fine$(EXEEXT)
+END
+
+cat > fubar.c <<'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+cat > fine.c << 'END'
+#include <stdio.h>
+int main (void)
+{
+ puts ("Which version? Which usage?");
+ return 0;
+}
+END
+
+mkdir sub
+
+cat >sub/scriptok.sh <<EOF
+#!/bin/sh
+echo "Which version? Which usage?"
+EOF
+
+# Not only does this script not support --help/--version, but
+# it will also hang when run without input.
+cat >sub/scriptnok.sh <<EOF
+#!/bin/sh
+cat
+EOF
+
+chmod +x sub/scriptok.sh
+chmod +x sub/scriptnok.sh
+
+# Files required by Gnits.
+: > INSTALL
+: > NEWS
+: > README
+: > COPYING
+: > AUTHORS
+: > ChangeLog
+: > THANKS
+
+# The following file should not be distributed.
+# (alpha.sh checks the case where it must be distributed.)
+: > README-alpha
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+grep README-alpha Makefile.in && exit 1
+
+mkdir build
+cd build
+
+# Use --program-prefix to make sure the std-options check honors it.
+../configure "--prefix=$(pwd)/../inst-dir" --program-prefix=p
+$MAKE all
+$MAKE test-install
+# Don't trust th exit status of "make -k" for non-GNU makes.
+if using_gmake; then status=FAIL; else status=IGNORE; fi
+run_make -e $status -E -- -k installcheck
+$MAKE grep-stderr
+
+:
diff --git a/t/gnits3.sh b/t/gnits3.sh
new file mode 100644
index 000000000..5cb169cdd
--- /dev/null
+++ b/t/gnits3.sh
@@ -0,0 +1,105 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that AM_INSTALLCHECK_STD_OPTIONS_EXEMPT works.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+# We use the same basename for all targets on purpose. This way
+# we make sure that 'AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = nok'
+# will not match anything containing 'nok'.
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = gnits
+
+nobase_bin_PROGRAMS = nok sub/nok
+nok_SOURCES = nok.c
+sub_nok_SOURCES = nok.c
+
+nobase_bin_SCRIPTS = nok.sh sub/nok.sh
+
+AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = nok$(EXEEXT) nok.sh
+
+grep-stderr:
+ grep 'sub/pnok$(EXEEXT) does not support' stderr
+ grep 'sub/pnok\.sh does not support' stderr
+## Only two failures please.
+ test `grep 'does not support --help' stderr | wc -l` = 2
+ test `grep 'does not support --version' stderr | wc -l` = 2
+END
+
+cat > nok.c <<'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+mkdir sub
+
+cat >nok.sh <<EOF
+#!/bin/sh
+echo "Which version? Which usage?"
+exit 1
+EOF
+
+cp nok.sh sub/nok.sh
+
+chmod +x nok.sh
+chmod +x sub/nok.sh
+
+# Files required by Gnits.
+: > INSTALL
+: > NEWS
+: > README
+: > COPYING
+: > AUTHORS
+: > ChangeLog
+: > THANKS
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkdir build
+cd build
+
+# Use --program-prefix to make sure the std-options check honors it.
+../configure "--prefix=$(pwd)/../inst-dir" --program-prefix=p
+$MAKE
+$MAKE install
+$MAKE installcheck && exit 1
+# Don't trust th exit status of "make -k" for non-GNU makes.
+if using_gmake; then status=FAIL; else status=IGNORE; fi
+run_make -e $status -E -- -k installcheck
+$MAKE grep-stderr
+
+# Make sure there is no more error when all targets are exempted.
+cd ..
+cat >> Makefile.am <<'END'
+AM_INSTALLCHECK_STD_OPTIONS_EXEMPT += sub/nok$(EXEEXT) sub/nok.sh
+END
+$AUTOMAKE
+cd build
+./config.status # Don't rely on the rebuild rules (they need GNU make).
+$MAKE installcheck
+
+:
diff --git a/t/gnumake.sh b/t/gnumake.sh
new file mode 100644
index 000000000..7ecd9717a
--- /dev/null
+++ b/t/gnumake.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automake should not assume that make files are called Makefile.
+# Report from Braden McDaniel.
+
+required=GNUmake
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/GNUmakefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+echo SUBDIRS = sub > Makefile.am
+
+cat > sub/GNUmakefile.am <<'EOF'
+# In this project, the Makefile is an installed data file.
+dist_data_DATA = Makefile
+EOF
+
+echo 'this should not cause any problem' > sub/Makefile
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
diff --git a/t/gnuwarn.sh b/t/gnuwarn.sh
new file mode 100644
index 000000000..6ce9927d6
--- /dev/null
+++ b/t/gnuwarn.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that Automake warns about user variables being overridden.
+
+. test-init.sh
+
+# We need (almost) complete control over automake options.
+AUTOMAKE="$am_original_AUTOMAKE -Werror"
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+# Needed by --gnu.
+: > NEWS
+: > README
+: > AUTHORS
+: > ChangeLog
+
+cat > Makefile.am << 'END'
+CFLAGS += -I..
+LDFLAGS = -lfoo
+CXXFLAGS = -Wall
+bin_PROGRAMS = bar
+END
+
+$ACLOCAL
+# Don't warn in foreign mode
+$AUTOMAKE --add-missing --foreign
+# Warn in gnu mode
+AUTOMAKE_fails --add-missing --gnu
+grep '^Makefile\.am:1:.*CFLAGS' stderr
+grep '^Makefile\.am:2:.*LDFLAGS' stderr
+# No reason to warn about CXXFLAGS since it's not used.
+grep CXXFLAGS stderr && exit 1
+# Don't warn if -Wno-gnu.
+$AUTOMAKE --gnu -Wno-gnu
+
+:
diff --git a/t/gnuwarn2.sh b/t/gnuwarn2.sh
new file mode 100644
index 000000000..c86dd38f5
--- /dev/null
+++ b/t/gnuwarn2.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check diagnostics about no-installman being disallowed in 'gnu'.
+
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([gnuwarn2], [1.0])
+AM_INIT_AUTOMAKE([no-installman])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+# --gnu files
+: > NEWS
+: > README
+: > AUTHORS
+: > ChangeLog
+: > COPYING
+: > INSTALL
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = gnu
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'configure.ac:2:.*no-installman' stderr
diff --git a/t/hdr-vars-defined-once.sh b/t/hdr-vars-defined-once.sh
new file mode 100644
index 000000000..9dce441e4
--- /dev/null
+++ b/t/hdr-vars-defined-once.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure header vars defined only once when including.
+# Report from Marcus G. Daniels.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+include Will_Be_Included_In_Makefile
+test-distcommon:
+ echo ' ' $(DIST_COMMON) ' ' \
+ | grep '[ /]Will_Be_Included_In_Makefile '
+END
+
+id=0c35bbde7c95b569a
+echo "# $id" > Will_Be_Included_In_Makefile
+
+$ACLOCAL
+$AUTOMAKE
+test $(grep -c '^srcdir' Makefile.in) -eq 1
+
+$AUTOCONF
+./configure
+$MAKE test-distcommon
+$MAKE distdir
+grep "$id" $distdir/Will_Be_Included_In_Makefile
+
+:
diff --git a/t/header.sh b/t/header.sh
new file mode 100644
index 000000000..a9b612b7c
--- /dev/null
+++ b/t/header.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 68.
+#
+# == Report ==
+# If an autoconf substitution variable of the form "*_HEADERS" --
+# for example "MY_HEADERS" -- is used in an "include_" variable
+# in conjunction with EXTRA_HEADERS, $(MY_HEADERS) gets included
+# in the HEADERS variable for *all* generated Makefile.ins in the
+# project.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([MY_HEADERS])
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zoo
+zoo_SOURCES = joe.c
+END
+
+: > joe.c
+: > qq.h
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '[^@]MY_HEADERS' Makefile.in && exit 1
+exit 0
diff --git a/t/help-depend.sh b/t/help-depend.sh
new file mode 100644
index 000000000..b777b7d44
--- /dev/null
+++ b/t/help-depend.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that our private macro 'AM_DEP_TRACK' adds proper text to
+# the configure help screen.
+# Keep this in sync with sister test 'help-depend2.sh'
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_DEP_TRACK
+END
+
+$ACLOCAL
+$AUTOCONF
+
+grep_configure_help --enable-dependency-tracking \
+ ' not reject slow dependency extract'
+
+grep_configure_help --disable-dependency-tracking \
+ ' speeds up one-time build'
+
+:
diff --git a/t/help-depend2.sh b/t/help-depend2.sh
new file mode 100644
index 000000000..b65ae07e8
--- /dev/null
+++ b/t/help-depend2.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that when automake automatically activates support for
+# dependency tracking, it adds proper text to the configure help screen.
+# Keep this in sync with sister test 'help-depend.sh'
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+END
+
+$ACLOCAL
+$AUTOCONF
+
+grep_configure_help --enable-dependency-tracking \
+ ' not reject slow dependency extract'
+
+grep_configure_help --disable-dependency-tracking \
+ ' speeds up one-time build'
+
+:
diff --git a/t/help-dmalloc.sh b/t/help-dmalloc.sh
new file mode 100644
index 000000000..e01edac44
--- /dev/null
+++ b/t/help-dmalloc.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that our macro 'AM_WITH_DMALLOC' adds proper text to
+# the configure help screen.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_WITH_DMALLOC
+END
+
+$ACLOCAL
+$AUTOCONF
+
+grep_configure_help --with-dmalloc ' use dmalloc.*http://www\.dmalloc\.com'
+
+:
diff --git a/t/help-init.sh b/t/help-init.sh
new file mode 100644
index 000000000..33305549f
--- /dev/null
+++ b/t/help-init.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that our grand macro 'AM_INIT_AUTOMAKE' add proper text
+# to the configure help screen.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+END
+
+$ACLOCAL
+$AUTOCONF
+
+./configure --help >stdout || { cat stdout; exit 1; }
+cat stdout
+
+grep '^ --program-prefix[= ]' stdout
+grep '^ --program-suffix[= ]' stdout
+grep '^ --program-transform-name[= ]' stdout
+
+:
diff --git a/t/help-lispdir.sh b/t/help-lispdir.sh
new file mode 100644
index 000000000..228338f21
--- /dev/null
+++ b/t/help-lispdir.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that our macro 'AM_PATH_LISPDIR' adds proper text to
+# the configure help screen.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_PATH_LISPDIR
+END
+
+$ACLOCAL
+$AUTOCONF
+
+./configure --help >stdout || { cat stdout; exit 1; }
+cat stdout
+
+grep_configure_help --with-lispdir ' override.*lisp directory'
+grep_configure_help EMACS ' [eE]macs editor'
+grep_configure_help EMACSLOADPATH ' [eE]macs library search path'
+
+:
diff --git a/t/help-python.sh b/t/help-python.sh
new file mode 100644
index 000000000..78cdf3bfb
--- /dev/null
+++ b/t/help-python.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that macro 'AM_PATH_PYTHON' adds proper text to the
+# configure help screen.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_PATH_PYTHON
+END
+
+$ACLOCAL
+$AUTOCONF
+
+grep_configure_help PYTHON 'the Python interpreter'
+
+:
diff --git a/t/help-silent.sh b/t/help-silent.sh
new file mode 100644
index 000000000..2127d4f65
--- /dev/null
+++ b/t/help-silent.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure configure options relative to automake silent rules are
+# added to the configure help screen.
+
+. test-init.sh
+
+: > Makefile.am
+$ACLOCAL
+
+cp configure.ac configure.tmpl
+
+for args in '' 'yes' 'no'; do
+ cp -f configure.tmpl configure.ac
+ test x"$args" = x || echo "AM_SILENT_RULES([$args])/" >> configure.ac
+ cat configure.ac # For debugging.
+ $AUTOCONF --force
+ grep_configure_help --enable-silent-rules \
+ ' less verbose build.*\(undo.*"make V=1".*\)'
+ grep_configure_help --disable-silent-rules \
+ ' verbose build.*\(undo.*"make V=0".*\)'
+done
+
+:
diff --git a/t/help-upc.sh b/t/help-upc.sh
new file mode 100644
index 000000000..e2f5e8daa
--- /dev/null
+++ b/t/help-upc.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that our macro 'AM_PROG_UPC' adds proper text to
+# the configure help screen.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_PROG_UPC
+END
+
+$ACLOCAL
+$AUTOCONF
+
+grep_configure_help UPC '[Uu]nified Parallel C compiler command'
+grep_configure_help UPCFLAGS '[Uu]nified Parallel C compiler flags'
+
+:
diff --git a/t/help.sh b/t/help.sh
new file mode 100644
index 000000000..7df39d2ad
--- /dev/null
+++ b/t/help.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure --help and --version work, even when no configure.ac nor
+# configure.in is in the current directory.
+
+. test-init.sh
+
+# Ensure we run in an empty directory.
+mkdir emptydir
+cd emptydir
+
+# Honour user overrides for $ACLOCAL and $AUTOMAKE, but without
+# adding extra options.
+ACLOCAL=$am_original_ACLOCAL
+AUTOMAKE=$am_original_AUTOMAKE
+
+$ACLOCAL --version
+$ACLOCAL --help
+$AUTOMAKE --version
+$AUTOMAKE --help
+
+# Sanity checks: aclocal and automake cannot work without configure.ac
+# nor configure.in.
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+$FGREP configure.ac stderr
+AUTOMAKE_fails
+$FGREP configure.ac stderr
+
+:
diff --git a/t/help2.sh b/t/help2.sh
new file mode 100644
index 000000000..6b93448ab
--- /dev/null
+++ b/t/help2.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure --help and --version work, even when the current directory
+# contains a broken configure.ac and a broken acinclude.m4.
+. test-init.sh
+
+# Ensure we run in a new, clean directory.
+mkdir cleandir
+cd cleandir
+
+# Honour user overrides for $ACLOCAL and $AUTOMAKE, but without
+# adding extra options.
+ACLOCAL=$am_original_ACLOCAL
+AUTOMAKE=$am_original_AUTOMAKE
+
+echo '[' > configure.ac
+echo '[' > acinclude.m4
+
+$AUTOMAKE --version
+$AUTOMAKE --help
+$ACLOCAL --version
+$ACLOCAL --help
+
+# Sanity check: aclocal cannot work with broken acinclude.m4.
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+$FGREP acinclude.m4 stderr
+
+rm -f acinclude.m4
+
+# Sanity checks: aclocal and automake cannot work with broken configure.ac.
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+$FGREP configure.ac stderr
+AUTOMAKE_fails
+$FGREP configure.ac stderr
+
+:
diff --git a/t/help3.sh b/t/help3.sh
new file mode 100644
index 000000000..9353ea629
--- /dev/null
+++ b/t/help3.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure --help and --version takes precedence over other options.
+
+. test-init.sh
+
+# We must have full control over the content of the current directory.
+mkdir cleandir
+cd cleandir
+
+# Honour user overrides for $ACLOCAL and $AUTOMAKE, but without
+# adding extra options.
+ACLOCAL=$am_original_ACLOCAL
+AUTOMAKE=$am_original_AUTOMAKE
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([.]) dnl prevent automake from looking into '..'
+AM_INIT_AUTOMAKE([foreign])
+AC_CONFIG_FILES([Makefile])
+END
+
+cat > Makefile.am <<END
+# So that install-sh will be required.
+pkgdata_DATA =
+END
+
+$ACLOCAL --force --help --output=foo.m4
+test ! -e foo.m4
+$ACLOCAL --output=foo.m4 --version --force
+test ! -e foo.m4
+# Sanity check.
+$ACLOCAL --output=foo.m4 --force
+test -f foo.m4
+
+mv -f foo.m4 aclocal.m4 # autoconf will need aclocal.m4
+
+$AUTOMAKE --add-missing --help --copy
+test ! -e install-sh
+$AUTOMAKE --copy --version --add-mising
+test ! -e install-sh
+# Sanity check.
+$AUTOMAKE --add-missing --copy
+test -f install-sh
+
+:
diff --git a/t/help4.sh b/t/help4.sh
new file mode 100644
index 000000000..301dbd101
--- /dev/null
+++ b/t/help4.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the first among --help and --version to be specified on
+# the command line takes precedence over the following one.
+
+. test-init.sh
+
+# Ensure we run in an empty directory.
+mkdir emptydir
+cd emptydir
+
+# Honour user overrides for $ACLOCAL and $AUTOMAKE, but without
+# adding extra options.
+ACLOCAL=$am_original_ACLOCAL
+AUTOMAKE=$am_original_AUTOMAKE
+
+escape_dots () { sed 's/\./\\./g'; } # Avoid issues with "\" in backquotes.
+apiversion_rx=$(echo "$APIVERSION" | escape_dots)
+
+$ACLOCAL --version --help >stdout || { cat stdout; exit 1; }
+cat stdout
+grep "^aclocal.*$apiversion_rx" stdout
+grep "^Usage" stdout && exit 1
+
+$ACLOCAL --help --version >stdout || { cat stdout; exit 1; }
+cat stdout
+grep "^Usage" stdout
+grep "^aclocal.*$apiversion_rx" stdout && exit 1
+
+$AUTOMAKE --version --help >stdout || { cat stdout; exit 1; }
+cat stdout
+grep "^automake.*$apiversion_rx" stdout
+grep "^Usage" stdout && exit 1
+
+$AUTOMAKE --help --version >stdout || { cat stdout; exit 1; }
+cat stdout
+grep "^Usage" stdout
+grep "^automake.*$apiversion_rx" stdout && exit 1
+
+:
diff --git a/t/hfs.sh b/t/hfs.sh
new file mode 100644
index 000000000..6502c99e1
--- /dev/null
+++ b/t/hfs.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+
+# Automake should not think that ChangeLog == CHANGELOG on
+# case-preserving case-insensitive filesystems (such as HFS+, on
+# Darwin).
+# Report from Peter O'Gorman.
+
+. test-init.sh
+echo AC_OUTPUT >>configure.ac
+
+: >CHANGELOG
+echo 'EXTRA_DIST = CHANGELOG' >Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
diff --git a/t/implicit.sh b/t/implicit.sh
new file mode 100644
index 000000000..b95a5a6fc
--- /dev/null
+++ b/t/implicit.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure implicit .o's are listed as appropriate. Report
+# from Henrik Frystyk Nielsen.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = libapp_1
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^libapp_1_OBJECTS' Makefile.in | $FGREP '.$(OBJEXT)'
+
+:
diff --git a/t/init.sh b/t/init.sh
new file mode 100644
index 000000000..180bd3344
--- /dev/null
+++ b/t/init.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we give a sensible error message when AC_INIT and
+# AM_INIT_AUTOMAKE are both given less than two arguments.
+
+. test-init.sh
+
+for ac_init_args in '' '([x])'; do
+ for am_init_args in '' '([1.10])'; do
+ rm -rf aclocal.m4 autom4te*.cache
+ unindent >configure.ac <<END
+ AC_INIT$ac_init_args
+ AM_INIT_AUTOMAKE$am_init_args
+END
+ cat configure.ac # For debugging.
+ # The error message should mention AC_INIT, not AC_PACKAGE_VERSION.
+ ($ACLOCAL && $AUTOCONF) 2>stderr && { cat stderr >&2; exit 1; }
+ cat stderr >&2
+ $FGREP AC_PACKAGE_VERSION stderr && exit 1
+ grep 'configure\.ac:.* AC_INIT .*arguments' stderr
+ done
+done
+
+:
diff --git a/t/init2.sh b/t/init2.sh
new file mode 100644
index 000000000..24fbcef52
--- /dev/null
+++ b/t/init2.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we give a sensible error message when AM_INIT_AUTOMAKE
+# contains junk.
+
+. test-init.sh
+
+cat >configure.ac <<END
+AC_INIT([init2], [1.0])
+AM_INIT_AUTOMAKE([nosuchoption])
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'nosuchoption.*recognized' stderr
+exit 0
diff --git a/t/install-info-dir.sh b/t/install-info-dir.sh
new file mode 100644
index 000000000..f112e4281
--- /dev/null
+++ b/t/install-info-dir.sh
@@ -0,0 +1,190 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Checks on the 'install-info' target.
+# Details about the individual checks' purposes and motivations are
+# inlined, below.
+
+# FIXME: this test is a good candidate for a conversion to TAP,
+# FIXME: and could be merged with 'txinfo27.sh'.
+
+required=makeinfo
+. test-init.sh
+
+cwd=$(pwd) || fatal_ "cannot get current working directory"
+
+mkdir bin
+saved_PATH=$PATH; export saved_PATH
+PATH=$cwd/bin$PATH_SEPARATOR$PATH; export PATH
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = foo.texi
+END
+
+cat > foo.texi << 'END'
+\input texinfo
+@setfilename foo.info
+@c All the following directives might be required to allow older
+@c versions of the 'install-info' program (e.g., version 4.8) to
+@c create the 'dir' index file in ${infodir}. Don't remove them.
+@settitle foo
+@dircategory Dummy utilities
+@direntry
+* Foo: (foo). Does nothing at all, but has a nice name.
+@end direntry
+@node Top
+Hello world!
+@bye
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+instdir=_inst
+destdir=_dest
+
+./configure --prefix="$cwd/$instdir" --infodir="$cwd/$instdir/info"
+
+$MAKE info
+test -f foo.info
+
+if install-info --version; then
+ # Skip some checks even if 'install-info' is the one from dpkg, not
+ # the one from GNU info, as the former might try to create files in
+ # '/var/backups/', causing spurious failures like this for non-root
+ # users.
+ if install-info --version | $EGREP -i '(dpkg|debian) install-info'; then
+ have_installinfo=no
+ else
+ have_installinfo=yes
+ fi
+else
+ have_installinfo=no
+fi
+
+# The 'install-info' target updates the '${infodir}/dir' file
+# by default (if the 'install-info' program is available).
+# This should happen in a normal as well as in a DESTDIR installation.
+if test $have_installinfo = yes; then
+
+ $MAKE install-info
+ test -f $instdir/info/foo.info
+ cat $instdir/info/dir
+ $FGREP 'Does nothing at all, but has a nice name' $instdir/info/dir
+
+ $MAKE uninstall
+ test ! -e $instdir/info/foo.info
+ cat $instdir/info/dir
+ $FGREP 'but has a nice name' $instdir/info/dir && exit 1
+
+ dir="$destdir/$cwd/$instdir/info"
+
+ $MAKE DESTDIR="$cwd/$destdir" install-info
+ test -f "$dir"/foo.info
+ cat "$dir"/dir
+ $FGREP 'Does nothing at all, but has a nice name' "$dir"/dir
+ $MAKE DESTDIR="$cwd/$destdir" uninstall
+ test ! -e "$dir"/foo.info
+ $FGREP 'but has a nice name' "$dir"/dir && exit 1
+
+ unset dir
+
+fi
+
+rm -rf $instdir $destdir
+
+# The 'install-info' target doesn't fail if the 'install-info'
+# program is not available.
+cat > bin/install-info <<'END'
+#!/bin/sh
+echo error from install-info >&2
+exit 127
+END
+chmod a+x bin/install-info
+run_make -M install-info
+test -f $instdir/info/foo.info
+test ! -e $instdir/info/dir
+grep 'error from install-info' output && exit 1
+
+rm -rf $instdir output
+
+if test $have_installinfo = yes; then
+ # The 'install-info' target doesn't try to guess whether the 'install-info'
+ # is the GNU or debian version.
+ unindent > bin/install-info <<'END'
+ #!/bin/sh
+ set -e; set -u;
+ for fd in 1 2; do
+ for str in dpkg debian Debian; do
+ eval "echo This is $str install-info >&$fd"
+ done
+ done
+ PATH=$saved_PATH; export PATH
+ exec install-info ${1+"$@"}
+END
+ $MAKE install-info
+ test -f $instdir/info/foo.info
+ cat $instdir/info/dir
+ $MAKE uninstall
+ test ! -e $instdir/info/foo.info
+ cat $instdir/info/dir
+ $FGREP 'but has a nice name' $instdir/info/dir && exit 1
+ : For shells with busted 'set -e'.
+fi
+
+rm -rf $instdir bin/install-info
+
+# The 'AM_UPDATE_INFO_DIR' environment variable can be used to
+# prevent the creation or update of the '${infodir}/dir' file,
+# if set to a "no" value.
+for val in no NO n; do
+ rm -rf $instdir
+ env AM_UPDATE_INFO_DIR="$val" $MAKE install-info
+ test -f $instdir/info/foo.info
+ test ! -e $instdir/info/dir
+done
+
+$MAKE install-info
+if test $have_installinfo != yes; then
+ echo 'Does nothing at all, but has a nice name' > $instdir/info/dir
+fi
+
+chmod a-w $instdir/info/dir
+for val in no NO n; do
+ env AM_UPDATE_INFO_DIR="$val" $MAKE uninstall
+ cat $instdir/info/dir
+ $FGREP 'Does nothing at all, but has a nice name' $instdir/info/dir
+done
+
+if test $have_installinfo = yes; then
+ for val in 'yes' 'who cares!'; do
+ rm -rf $instdir
+ env AM_UPDATE_INFO_DIR="$val" $MAKE install-info
+ test -f $instdir/info/foo.info
+ cat $instdir/info/dir
+ env AM_UPDATE_INFO_DIR="$val" $MAKE uninstall
+ test ! -e $instdir/info/foo.info
+ $FGREP 'but has a nice name' $instdir/info/dir && exit 1
+ : For shells with busted 'set -e'.
+ done
+fi
+
+:
diff --git a/t/install-sh-option-C.sh b/t/install-sh-option-C.sh
new file mode 100644
index 000000000..b6bcb06fe
--- /dev/null
+++ b/t/install-sh-option-C.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# More install-sh checks: check -C.
+
+am_create_testdir=empty
+required=non-root
+. test-init.sh
+
+# Solaris /usr/ucb/touch does not accept -t.
+touch -t "$old_timestamp" foo \
+ || skip_ "touch utility doesn't accept '-t' option"
+
+get_shell_script install-sh
+
+./install-sh -d d1
+
+# Do not change the timestamps when using -C.
+echo foo >file
+./install-sh -C file d1
+TZ=UTC0 touch -t $old_timestamp d1/file
+./install-sh -C file d1
+is_newest file d1/file
+echo foo1 >file
+./install-sh -C file d1
+diff file d1/file
+# Rights must be updated.
+./install-sh -C -m 444 file d1
+test -r d1/file
+test ! -w d1/file
+
+:
diff --git a/t/install-sh-unittests.sh b/t/install-sh-unittests.sh
new file mode 100644
index 000000000..e97a1f3fa
--- /dev/null
+++ b/t/install-sh-unittests.sh
@@ -0,0 +1,152 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Various install-sh checks.
+
+am_create_testdir=empty
+. test-init.sh
+
+install_sh_fail ()
+{
+ err_rx=$1; shift
+ ./install-sh ${1+"$@"} 2>stderr && { cat stderr >&2; exit 1; }
+ cat stderr >&2
+ $EGREP "install-sh:.* $err_rx" stderr || exit 1
+}
+
+get_shell_script install-sh
+
+# Basic errors.
+install_sh_fail 'no input file specified'
+install_sh_fail 'no input file specified' dest
+install_sh_fail 'no input file specified' -m 644 dest
+install_sh_fail 'no input file specified' -c -t dest
+
+# Incorrect usages.
+: > bar
+: > baz
+: > qux
+install_sh_fail 'target directory not allowed when installing a directory' \
+ -d -t foo
+install_sh_fail 'target directory not allowed when installing a directory' \
+ -d -t foo bar
+install_sh_fail 'foo: [iI]s not a directory' -t foo bar
+install_sh_fail 'foo: [iI]s not a directory' bar baz foo
+mkdir foo
+install_sh_fail 'target directory not allowed when installing a directory' \
+ -d -t foo
+install_sh_fail 'target directory not allowed when installing a directory' \
+ -d -t foo bar
+rmdir foo
+rm -f bar baz qux
+
+# Directories.
+for opts in '-d' '-d -T' '-T -d' '-d -T -d' '-T -d -T -d -T'; do
+ # It should be OK to create no directory. We sometimes need
+ # this when directory are conditionally defined.
+ ./install-sh $opts
+ # One directory.
+ ./install-sh $opts d0
+ test -d d0
+ # Multiple directories (for make installdirs).
+ ./install-sh $opts d1 d2 d3 d4
+ test -d d1
+ test -d d2
+ test -d d3
+ test -d d4
+ rmdir d[0-9]
+ # Subdirectories.
+ ./install-sh $opts p1/p2/p3 p4//p5//p6//
+ test -d p1/p2/p3
+ test -d p4/p5/p6
+ rmdir p[0-9]/p[0-9]/p[0-9]
+ rmdir p[0-9]/p[0-9]
+ rmdir p[0-9]
+done
+
+# Files.
+mkdir d0 d1 d2 d3 d4
+: > x
+./install-sh -c -m 644 x y
+test -f x
+test -f y
+./install-sh -m 644 y z
+test -f y
+test -f z
+# Multiple files.
+./install-sh -m 644 -c x z d1
+test -f x
+test -f z
+test -f d1/x
+test -f d1/z
+./install-sh -m 644 x z d2//
+test -f x
+test -f z
+test -f d2/x
+test -f d2/z
+./install-sh -t d3 -m 644 x z
+test -f x
+test -f z
+test -f d3/x
+test -f d3/z
+./install-sh -t d4// -m 644 x z
+test -f x
+test -f z
+test -f d4/x
+test -f d4/z
+./install-sh -T x d3/y
+test -f x
+test -f d3/y
+install_sh_fail 'd3: [iI]s a directory' -T x d3
+install_sh_fail 'd4(//)?: [iI]s a directory' -T x d4//
+
+# Ensure that install-sh works with names that include spaces.
+touch 'a b'
+mkdir 'x y'
+./install-sh 'a b' 'x y'
+test -f x\ \ y/a\ \ b
+test -f 'a b'
+
+# Ensure we do not run into 'test' operator precedence bugs with Tru64 sh.
+for c in = '(' ')' '!'; do
+ install_sh_fail 'no input file specified' $c
+ test -f stderr # sanity check
+ grep 'test: ' stderr && exit 1
+ # Skip tests if the file system is not capable.
+ mkdir ./$c || continue
+ rmdir ./$c
+ ./install-sh -d $c/$c/$c
+ rm -rf ./$c
+ ./install-sh -d $c d5/$c/$c
+ test -d ./$c
+ test -d d5/$c/$c
+ ./install-sh x $c
+ test -f ./$c/x
+ rm -f ./$c/x
+ ./install-sh -t $c x
+ test -f ./$c/x
+ rm -rf ./$c
+ ( : > ./$c ) || continue
+ ./install-sh $c x d5/$c/$c
+ test -f d5/$c/$c/x
+ test -f d5/$c/$c/$c
+ rm -f d5/$c/$c/?
+ ./install-sh -t d5/$c/$c $c x
+ test -f d5/$c/$c/x
+ test -f d5/$c/$c/$c
+done
+
+:
diff --git a/t/installdir.sh b/t/installdir.sh
new file mode 100644
index 000000000..45d81aaea
--- /dev/null
+++ b/t/installdir.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 203.
+# See also automake bug#11030.
+#
+# == Original Report for PR/203 ==
+# Some standard targets are missing '-local' hooks. For instance,
+# installdirs is missing this. Ideally this would be an automatic
+# feature of any exported target.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+foodir = $(datadir)/$(distdir)
+installdirs-local:
+ $(MKDIR_P) $(DESTDIR)$(foodir)
+install-data-hook: installdirs-local
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+test $(grep -c installdirs-local Makefile.in) -eq 4
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+$AUTOCONF
+./configure --prefix="$cwd/inst"
+
+$MAKE installdirs
+test -d inst/share/$me-1.0
+rm -rf inst
+
+$MAKE install
+test -d inst/share/$me-1.0
+rm -rf inst
+
+./configure --prefix=/foo
+
+$MAKE installdirs DESTDIR="$cwd/dest"
+test -d dest/foo/share/$me-1.0
+rm -rf dest
+
+$MAKE install DESTDIR="$cwd/dest"
+test -d dest/foo/share/$me-1.0
+rm -rf dest
+
+:
diff --git a/t/instdat.sh b/t/instdat.sh
new file mode 100644
index 000000000..6d766ad87
--- /dev/null
+++ b/t/instdat.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to see if defining INSTALL_DATA causes problems. From EGCS
+# list.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_SUBST([INSTALL_DATA])
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^DATA =' Makefile.in | grep 'INSTALL_DATA' && exit 1
+
+:
diff --git a/t/instdat2.sh b/t/instdat2.sh
new file mode 100644
index 000000000..0240b6412
--- /dev/null
+++ b/t/instdat2.sh
@@ -0,0 +1,88 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that installing under $exec_prefix is handled by install-exec.
+# Testing with headers for instance.
+
+. test-init.sh
+
+cat >Makefile.am << 'EOF'
+# User directories.
+inclexecdir = $(exec_prefix)/include
+inclexec_HEADERS = my-config.h
+
+incldatadir = $(prefix)/include
+incldata_HEADERS = my-data.h
+
+## Standard directories: _DATA
+## Commented out are invalid combinations.
+##bin_DATA = data
+##sbin_DATA = data
+##libexec_DATA = data
+data_DATA = data
+sysconf_DATA = data
+localstate_DATA = data
+##lib_DATA = data
+##info_DATA = data
+##man_DATA = data
+##include_DATA = data
+##oldinclude_DATA = data
+pkgdata_DATA = data
+##pkglib_DATA = data
+##pkginclude_DATA = data
+
+## Standard directories: _SCRIPTS
+## Commented out are invalid combinations.
+bin_SCRIPTS = script
+sbin_SCRIPTS = script
+libexec_SCRIPTS = script
+##data_SCRIPTS = script
+##sysconf_SCRIPTS = script
+##localstate_SCRIPTS = script
+##lib_SCRIPTS = script
+##info_SCRIPTS = script
+##man_SCRIPTS = script
+##include_SCRIPTS = script
+##oldinclude_SCRIPTS = script
+pkgdata_SCRIPTS = script
+##pkglib_SCRIPTS = script
+##pkginclude_SCRIPTS = script
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+
+# install-SCRIPTS targets.
+sed -n '/^install-data-am/,/^ /p' Makefile.in > produced
+
+cat > expected <<'EOF'
+install-data-am: install-dataDATA install-incldataHEADERS \
+ install-pkgdataDATA install-pkgdataSCRIPTS
+EOF
+
+diff expected produced
+
+# install-exec targets.
+sed -n '/^install-exec-am/,/^ /p' Makefile.in > produced
+
+cat > expected <<'EOF'
+install-exec-am: install-binSCRIPTS install-inclexecHEADERS \
+ install-libexecSCRIPTS install-localstateDATA \
+EOF
+
+diff expected produced
+
+:
diff --git a/t/instdir-cond.sh b/t/instdir-cond.sh
new file mode 100644
index 000000000..f85e98c22
--- /dev/null
+++ b/t/instdir-cond.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check against automake bug#10997: directories holding only
+# conditionally-installed files should not be created unconditionally.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([ENABLE_FOO], [false])
+AC_OUTPUT
+END
+
+: > foo
+: > bar
+
+cat > Makefile.am << 'END'
+pkglibexec_SCRIPTS =
+if ENABLE_FOO
+pkgdata_DATA = foo
+pkglibexec_SCRIPTS += bar
+endif
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure --prefix="$(pwd)/inst"
+
+$MAKE install
+test ! -e inst/share/instdir-cond
+test ! -e inst/libexec/instdir-cond
+
+:
diff --git a/t/instdir-cond2.sh b/t/instdir-cond2.sh
new file mode 100644
index 000000000..557d18a11
--- /dev/null
+++ b/t/instdir-cond2.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check against automake bug#10997: directories holding only
+# conditionally-installed files should not be created unconditionally.
+# FIXME: this test tries to check that the above also hold for the
+# FIXME: "installdirs" target, but that doesn't currently work :-(
+# FIXME: So this test is still xfailing.
+# See sister test 'instdir-cond.sh' for the succeeding part.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([ENABLE_FOO], [false])
+AC_OUTPUT
+END
+
+: > foo
+: > bar
+
+cat > Makefile.am << 'END'
+pkglibexec_SCRIPTS =
+if ENABLE_FOO
+pkgdata_DATA = foo
+pkglibexec_SCRIPTS += bar
+endif
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure --prefix="$(pwd)/inst"
+
+$MAKE installdirs
+test ! -e inst || { find inst; exit 1; }
+
+:
diff --git a/t/instdir-java.sh b/t/instdir-java.sh
new file mode 100644
index 000000000..8800b8562
--- /dev/null
+++ b/t/instdir-java.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# If $(javadir) is the empty string, then nothing should be installed there.
+
+required=javac
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+javadir = $(datarootdir)/java
+java_JAVA = foo.java
+END
+
+cat >foo.java <<'END'
+class foo {
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+instdir=$cwd/inst
+destdir=$cwd/dest
+mkdir build
+cd build
+../configure --prefix="$instdir"
+$MAKE
+
+nulldirs='javadir='
+null_install
+
+:
diff --git a/t/instdir-lisp.sh b/t/instdir-lisp.sh
new file mode 100644
index 000000000..2f12c3442
--- /dev/null
+++ b/t/instdir-lisp.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# If $(lispdir) is the empty string, then nothing should be installed there.
+
+required=emacs
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_PATH_LISPDIR
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+lisp_LISP = l.el
+END
+
+: >l.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+instdir=$cwd/inst
+destdir=$cwd/dest
+mkdir build
+cd build
+../configure --prefix="$instdir"
+$MAKE
+
+nulldirs='lispdir='
+null_install
+
+:
diff --git a/t/instdir-ltlib.sh b/t/instdir-ltlib.sh
new file mode 100644
index 000000000..414d1bc6a
--- /dev/null
+++ b/t/instdir-ltlib.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# If $(libdir) or $(pyexecdir) is the empty string, then nothing should
+# be installed there.
+# This test exercises the libtool code paths.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AM_PATH_PYTHON
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat >Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = p
+nobase_bin_PROGRAMS = np sub/np
+lib_LTIBRARIES = libfoo.la
+nobase_lib_LTLIBRARIES = libnfoo.la sub/libnfoo.la
+pyexec_LTIBRARIES = libpy.la
+nobase_pyexec_LTLIBRARIES = libnpy.la sub/libnpy.la
+END
+
+cat >p.c <<'END'
+int main () { return 0; }
+END
+cp p.c np.c
+cp p.c sub/np.c
+cp p.c libfoo.c
+cp p.c libnfoo.c
+cp p.c sub/libnfoo.c
+cp p.c libpy.c
+cp p.c libnpy.c
+cp p.c sub/libnpy.c
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+instdir=$cwd/inst
+destdir=$cwd/dest
+mkdir build
+cd build
+../configure --prefix="$instdir" PYTHON="echo" \
+ am_cv_python_pythondir="$instdir/python" \
+ am_cv_python_pyexecdir="$instdir/pyexec"
+
+nulldirs='bindir= libdir= pyexecdir='
+null_install
+
+:
diff --git a/t/instdir-no-empty.sh b/t/instdir-no-empty.sh
new file mode 100644
index 000000000..a0f312bb9
--- /dev/null
+++ b/t/instdir-no-empty.sh
@@ -0,0 +1,122 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# An empty "foo_PRIMARY" declaration should *not* cause "make install"
+# to create directory $(foodir). See automake bug#10997 and bug#11030.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_SUBST([CC], [whatever])
+AC_SUBST([JAVAC], [whatever])
+AM_PATH_PYTHON(,,:)
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+mydir = $(prefix)/my
+myexecdir = $(prefix)/myexec
+javadir = $(prefix)/java
+END
+
+# Write Makefile.am.
+{
+
+ for dir in sbin bin libexec pkglibexec myexec; do
+ for dst in '' dist_ nodist_; do
+ echo "${dst}${dir}_SCRIPTS ="
+ done
+ echo "${dir}_PROGRAMS ="
+ done
+
+ for dir in lib pkglib myexec my; do
+ echo "${dir}_LIBRARIES ="
+ echo "${dir}_LTLIBRARIES ="
+ done
+
+ for p1 in '' notrans_; do
+ for p2 in '' dist_ nodist_; do
+ for s in '' 1 2 3 4 5 6 7 8 9; do
+ echo "${p1}${p2}man${s}_MANS ="
+ done
+ done
+ done
+
+ for dst in '' dist_ nodist_; do
+ for dir in dataroot data pkgdata doc lisp my; do
+ echo "${dst}${dir}_DATA ="
+ done
+ for dir in include pkginclude oldinclude my; do
+ echo "${dst}${dir}_HEADERS ="
+ done
+ for dir in python my; do
+ echo "${dst}${dir}_PYTHON ="
+ done
+ for dir in info my; do
+ echo "${dst}${dir}_TEXINFOS ="
+ done
+ for dir in java my; do
+ echo "${dst}${dir}_JAVA ="
+ done
+ for dir in lisp my; do
+ echo "${dst}${dir}_LISP ="
+ done
+ done
+
+} > t
+
+cat t >> Makefile.am
+sed 's/^/nobase_/' t >> Makefile.am
+rm -f t
+
+cat Makefile.am # For debugging.
+
+# Sanity check.
+grep '^oldinclude_HEADERS =' Makefile.am \
+ && grep '^nodist_my_PYTHON =' Makefile.am \
+ && grep '^notrans_dist_man5_MANS =' Makefile.am \
+ || fatal_ "creating Makefile.am"
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+doinst ()
+{
+ run_make install install-pdf install-ps install-dvi ${1+"$@"}
+}
+
+: > foo.sh
+
+./configure --prefix="$cwd/inst"
+doinst
+test ! -e inst || { find inst; exit 1; }
+$MAKE uninstall
+doinst bin_SCRIPTS=foo.sh
+test -f inst/bin/foo.sh
+
+# Explicitly pass prefix to avoid spurious influences from
+# global config.site scripts.
+./configure --prefix="/usr/local"
+test ! -e dest || { find dest; exit 1; }
+$MAKE uninstall
+doinst DESTDIR="$cwd/dest" bin_SCRIPTS=foo.sh
+test -f dest/usr/local/bin/foo.sh
+
+:
diff --git a/t/instdir-prog.sh b/t/instdir-prog.sh
new file mode 100644
index 000000000..de55050b6
--- /dev/null
+++ b/t/instdir-prog.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# If $(bindir), $(libdir) or $(pyexecdir) is the empty string, then
+# nothing should be installed there.
+# This test exercises the prog and libs code paths.
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AM_PATH_PYTHON
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat >Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = p
+nobase_bin_PROGRAMS = np sub/np
+lib_LIBRARIES = libfoo.a
+nobase_lib_LIBRARIES = libnfoo.a sub/libnfoo.a
+pyexec_PROGRAMS = py
+nobase_pyexec_PROGRAMS = npy sub/npy
+END
+
+cat >p.c <<'END'
+int main () { return 0; }
+END
+cp p.c np.c
+cp p.c sub/np.c
+cp p.c libfoo.c
+cp p.c libnfoo.c
+cp p.c sub/libnfoo.c
+cp p.c py.c
+cp p.c npy.c
+cp p.c sub/npy.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+instdir=$cwd/inst
+destdir=$cwd/dest
+mkdir build
+cd build
+../configure --prefix="$instdir" PYTHON="echo" \
+ am_cv_python_pythondir="$instdir/python" \
+ am_cv_python_pyexecdir="$instdir/pyexec"
+
+nulldirs='bindir= libdir= pyexecdir='
+null_install
+
+:
diff --git a/t/instdir-python.sh b/t/instdir-python.sh
new file mode 100644
index 000000000..5b46c4536
--- /dev/null
+++ b/t/instdir-python.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# If $(pythondir) is the empty string, then nothing should be installed there.
+
+required=python
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_PATH_PYTHON
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat >Makefile.am <<'END'
+python_PYTHON = one.py
+END
+
+cat >one.py <<'END'
+def one(): return 1
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+instdir=$cwd/inst
+destdir=$cwd/dest
+mkdir build
+cd build
+../configure --prefix="$instdir"
+$MAKE
+
+nulldirs='pythondir='
+null_install
+
+:
diff --git a/t/instdir-texi.sh b/t/instdir-texi.sh
new file mode 100644
index 000000000..c00772124
--- /dev/null
+++ b/t/instdir-texi.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# If $(infodir) is the empty string, then nothing should be installed there.
+# Likewise for the other install-* targets used for texinfo files.
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+dvips --help \
+ || skip_ "dvips is missing"
+pdfetex --version || pdftex --version \
+ || skip_ "pdeftex and pdftex are both missing"
+
+cat >>configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+info_TEXINFOS = foo.texi
+END
+
+cat >foo.texi << 'END'
+\input texinfo
+@setfilename foo.info
+@settitle foo
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+instdir=$cwd/inst
+destdir=$cwd/dest
+mkdir build
+cd build
+../configure --prefix="$instdir"
+$MAKE all dvi ps pdf html
+ls -l
+
+nulldirs='infodir= htmldir= dvidir= psdir= pdfdir='
+null_install --texi
+
+:
diff --git a/t/instdir.sh b/t/instdir.sh
new file mode 100644
index 000000000..e29167d61
--- /dev/null
+++ b/t/instdir.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# If $(foodir) is the empty string, then nothing should be installed there.
+# This test only ensures this if $(foo_PRIMARY) is also empty, see
+# 'instdir2.sh' and siblings 'instdir-*.sh' for nonempty contents.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_SUBST([foodir], ['${datadir}'/foo])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+bin_SCRIPTS =
+nobase_bin_SCRIPTS =
+data_DATA =
+nobase_data_DATA =
+include_HEADERS =
+nobase_include_HEADERS =
+foo_DATA =
+nobase_foo_DATA =
+bardir = $(datadir)/bar
+bar_DATA =
+nobase_bar_DATA =
+man1_MANS =
+man_MANS =
+notrans_man1_MANS =
+notrans_man_MANS =
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+instdir=$cwd/inst
+destdir=$cwd/dest
+mkdir build
+cd build
+../configure --prefix="$instdir"
+$MAKE
+
+nulldirs='bindir= datadir= includedir= foodir= bardir= man1dir= man2dir='
+null_install
+
+:
diff --git a/t/instdir2.sh b/t/instdir2.sh
new file mode 100644
index 000000000..80bc99d85
--- /dev/null
+++ b/t/instdir2.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# If $(foodir) is the empty string, then nothing should be installed there.
+# This test ensures this also if $(foo_PRIMARY) is nonempty, see
+# 'instdir.sh'.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_SUBST([foodir], ['${datadir}'/foo])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat >Makefile.am <<'END'
+bin_SCRIPTS = s
+nobase_bin_SCRIPTS = ns sub/ns
+data_DATA = d
+nobase_data_DATA = nd sub/nd
+include_HEADERS = h
+nobase_include_HEADERS = nh sub/nh
+foo_DATA = f
+nobase_foo_DATA = nf sub/nf
+bardir = $(datadir)/bar
+bar_DATA = b
+nobase_bar_DATA = nb sub/nb
+man1_MANS = m1.1
+man_MANS = m.2
+notrans_man1_MANS = nm1.1
+notrans_man_MANS = nm.2
+END
+
+: >s
+: >ns
+: >sub/ns
+: >d
+: >nd
+: >sub/nd
+: >h
+: >nh
+: >sub/nh
+: >f
+: >nf
+: >sub/nf
+: >b
+: >nb
+: >sub/nb
+: >m1.1
+: >m.2
+: >nm1.1
+: >nm.2
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+instdir=$cwd/inst
+destdir=$cwd/dest
+mkdir build
+cd build
+../configure --prefix="$instdir"
+$MAKE
+
+nulldirs='bindir= datadir= includedir= foodir= bardir= man1dir= man2dir='
+null_install
+
+:
diff --git a/t/instexec.sh b/t/instexec.sh
new file mode 100644
index 000000000..0d61664ef
--- /dev/null
+++ b/t/instexec.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for this bug: when a Makefile.am builds nothing, no
+# install-exec target is generated.
+
+. test-init.sh
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^install-exec:' Makefile.in
diff --git a/t/instfail-info.sh b/t/instfail-info.sh
new file mode 100644
index 000000000..31326a786
--- /dev/null
+++ b/t/instfail-info.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The install rule should honor failures of the install program.
+# Some of these are already caught by 'instmany.sh'.
+
+# This test has a few sister tests, for java, info, libtool.
+
+required='makeinfo'
+. test-init.sh
+
+cat >>configure.ac <<END
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+info_TEXINFOS = info1.texi info2.texi info3.texi
+END
+
+for n in 1 2 3; do
+ cat >info$n.texi <<END
+\input texinfo
+@setfilename info$n.info
+@settitle main
+@node Top
+Hello walls.
+@bye
+END
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+instdir=$(pwd)/inst || fatal_ "getting current working directory"
+./configure --prefix="$instdir"
+$MAKE
+
+$MAKE install
+$MAKE uninstall
+
+for file in info1.info
+do
+ chmod a-r $file
+ test ! -r $file || skip_ "cannot drop file read permissions"
+ $MAKE install-data && exit 1
+ chmod u+r $file
+done
+
+:
diff --git a/t/instfail-java.sh b/t/instfail-java.sh
new file mode 100644
index 000000000..360c685a0
--- /dev/null
+++ b/t/instfail-java.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The install rule should honor failures of the install program.
+# Some of these are already caught by 'instmany.sh'.
+
+# This is the java sister test of 'instfail.sh'.
+
+required=javac
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+javadir = $(datadir)/java
+java_JAVA = java1.java java2.java java3.java
+END
+
+for n in 1 2 3; do
+ echo "class java$n { }" >java$n.java
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+instdir=$(pwd)/inst || fatal_ "getting current working directory"
+./configure --prefix="$instdir"
+$MAKE
+
+$MAKE install
+$MAKE uninstall
+
+for file in java1.class
+do
+ chmod a-r $file
+ test ! -r $file || skip_ "cannot drop file read permissions"
+ $MAKE install-data && exit 1
+ chmod u+r $file
+done
+
+:
diff --git a/t/instfail-libtool.sh b/t/instfail-libtool.sh
new file mode 100644
index 000000000..39946f763
--- /dev/null
+++ b/t/instfail-libtool.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The install rule should honor failures of the install program.
+# Some of these are already caught by 'instmany.sh'.
+
+# This is the libtool sister test of 'instfail.sh'.
+
+required='cc libtool libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<END
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+bin_PROGRAMS = prog1 prog2 prog3
+nobase_bin_PROGRAMS = progn1 progn2 progn3
+lib_LTLIBRARIES = liblt1.la liblt2.la liblt3.la
+nobase_lib_LTLIBRARIES = libltn1.la libltn2.la libltn3.la
+unreadable-prog:
+ chmod a-r prog1$(EXEEXT)
+readable-prog:
+ chmod a+r prog1$(EXEEXT)
+unreadable-progn:
+ chmod a-r progn1$(EXEEXT)
+readable-progn:
+ chmod a+r progn1$(EXEEXT)
+END
+
+for n in 1 2 3; do
+ echo "int main () { return 0; }" > prog$n.c
+ echo "int main () { return 0; }" > progn$n.c
+ echo "int foolt$n () { return 0; }" > liblt$n.c
+ echo "int fooltn$n () { return 0; }" > libltn$n.c
+done
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+instdir=$(pwd)/inst || fatal_ "getting current working directory"
+./configure --prefix="$instdir"
+$MAKE
+
+$MAKE install
+$MAKE uninstall
+
+for file in liblt1.la libltn1.la
+do
+ chmod a-r $file
+ test ! -r $file || skip_ "cannot drop file read permissions"
+ $MAKE install-exec && exit 1
+ chmod u+r $file
+done
+
+$MAKE unreadable-prog
+$MAKE install-exec && exit 1
+$MAKE readable-prog
+
+$MAKE unreadable-progn
+$MAKE install-exec && exit 1
+$MAKE readable-progn
+
+:
diff --git a/t/instfail.sh b/t/instfail.sh
new file mode 100644
index 000000000..5efc754b8
--- /dev/null
+++ b/t/instfail.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The install rule should honor failures of the install program.
+# Some of these are already caught by 'instmany.sh'.
+
+# This test has a few sister tests, for java, info, libtool.
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac <<END
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AM_PATH_LISPDIR
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+bin_PROGRAMS = prog1 prog2 prog3
+nobase_bin_PROGRAMS = progn1 progn2 progn3
+lisp_LISP = lisp1.el lisp2.el lisp3.el
+nobase_lisp_LISP = lispn1.el lispn2.el lispn3.el
+lib_LIBRARIES = lib1.a lib2.a lib3.a
+nobase_lib_LIBRARIES = libn1.a libn2.a libn3.a
+unreadable-prog:
+ chmod a-r prog1$(EXEEXT)
+readable-prog:
+ chmod a+r prog1$(EXEEXT)
+unreadable-progn:
+ chmod a-r progn1$(EXEEXT)
+readable-progn:
+ chmod a+r progn1$(EXEEXT)
+END
+
+for n in 1 2 3; do
+ echo "int main () { return 0; }" > prog$n.c
+ echo "int main () { return 0; }" > progn$n.c
+ echo "int foo$n () { return 0; }" > lib$n.c
+ echo "int foon$n () { return 0; }" > libn$n.c
+ echo >lisp$n.el
+ echo >lispn$n.el
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+instdir=$(pwd)/inst || fatal_ "getting current working directory"
+./configure --prefix="$instdir"
+$MAKE
+
+$MAKE install
+$MAKE uninstall
+
+for file in lib1.a libn1.a
+do
+ chmod a-r $file
+ test ! -r $file || skip_ "cannot drop file read permissions"
+ $MAKE install-exec && exit 1
+ chmod u+r $file
+done
+
+$MAKE unreadable-prog
+$MAKE install-exec && exit 1
+$MAKE readable-prog
+
+$MAKE unreadable-progn
+$MAKE install-exec && exit 1
+$MAKE readable-progn
+
+if ! grep "^EMACS = no" Makefile; then
+ for file in lisp1.el lisp1.elc; do
+ chmod a-r $file
+ $MAKE install-data && exit 1
+ chmod u+r $file
+ done
+fi
+
+:
diff --git a/t/insthook.sh b/t/insthook.sh
new file mode 100644
index 000000000..103577260
--- /dev/null
+++ b/t/insthook.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the install-exec-hook example we give in the manual works.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AC_PROG_LN_S
+AC_OUTPUT
+EOF
+
+cat >Makefile.am <<'END'
+dist_bin_SCRIPTS = foo
+
+install-exec-hook:
+ cd "$(DESTDIR)$(bindir)" \
+ && mv -f foo foo-$(VERSION) \
+ && $(LN_S) foo-$(VERSION) foo
+
+installcheck-local:
+ test -f "$(bindir)/foo"
+ test -f "$(bindir)/foo-$(VERSION)"
+ : > $(top_srcdir)/../ok
+
+uninstall-hook:
+ rm -f $(DESTDIR)$(bindir)/foo-$(VERSION)
+END
+
+echo a > foo
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE distcheck
+# Sanity check to make sure installcheck-local was run.
+test -f ok
+
+# Make sure that installing a second version doesn't erase the first
+# one. (This is error prone since 'foo' symlinks to 'foo-1.0' and the
+# second version will overwrite 'foo'. Hopefully 'install' and 'install-sh'
+# are smart enough to erase the 'foo' symlink before installing the new
+# version.)
+./configure "--bindir=$(pwd)/bin"
+$MAKE install
+echo b > foo
+run_make VERSION=2.0 install
+test $(cat bin/foo-1.0) = a
+test $(cat bin/foo-2.0) = b
+test $(cat bin/foo) = b
+
+# install-hook is an error.
+cat >>Makefile.am <<EOF
+install-hook:
+ echo test
+EOF
+
+AUTOMAKE_fails
+grep install-data-hook stderr
+grep install-exec-hook stderr
+
+:
diff --git a/t/instman.sh b/t/instman.sh
new file mode 100644
index 000000000..3f31835f1
--- /dev/null
+++ b/t/instman.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the MKDIR_P invocation is correct in install-man
+# target. Bug reported by Gordon Irlam <gordoni@cygnus.com>.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'EOF'
+man_MANS = frob.8
+EOF
+
+: > frob.8
+
+$ACLOCAL
+$AUTOMAKE
+
+grep 'MKDIR_P' Makefile.in # For debugging.
+test $(grep -c '[^(/]MKDIR_P' Makefile.in) -eq 1
+
+:
diff --git a/t/instman2.sh b/t/instman2.sh
new file mode 100644
index 000000000..09a087e69
--- /dev/null
+++ b/t/instman2.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure mkinstalldirs invocation correct in install-man
+# target. Bug reported by Gordon Irlam <gordoni@cygnus.com>.
+
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+man8_MANS = frob.8
+EOF
+
+: > frob.8
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^install-man' Makefile.in
+
+:
diff --git a/t/instmany-mans.sh b/t/instmany-mans.sh
new file mode 100644
index 000000000..08a66dabd
--- /dev/null
+++ b/t/instmany-mans.sh
@@ -0,0 +1,168 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Installing many files should not exceed the command line length limit.
+
+# This is the mans sister test of 'instmany.sh', see there for details.
+
+. test-init.sh
+
+# In order to have a useful test on modern systems (which have a high
+# limit, if any), use a fake install program that errors out for more
+# than 2K characters in a command line. The POSIX limit is 4096, but
+# that may include space taken up by the environment.
+
+limit=2500
+subdir=long_subdir_name_with_many_characters
+nfiles=81
+list=$(seq_ 1 $nfiles)
+
+oPATH=$PATH; export oPATH
+nPATH=$(pwd)/x-bin$PATH_SEPARATOR$PATH; export nPATH
+
+mkdir x-bin
+
+sed "s|@limit@|$limit|g" >x-bin/my-install <<'END'
+#! /bin/sh
+limit=@limit@
+PATH=$oPATH; export PATH
+if test -z "$orig_INSTALL"; then
+ echo "$0: \$orig_INSTALL variable not set" >&2
+ exit 1
+fi
+len=`expr "$orig_INSTALL $*" : ".*" 2>/dev/null || echo $limit`
+if test $len -ge $limit; then
+ echo "$0: safe command line limit of $limit characters exceeded" >&2
+ exit 1
+fi
+exec $orig_INSTALL "$@"
+exit 1
+END
+
+# Creative quoting in the next line to please maintainer-check.
+sed "s|@limit@|$limit|g" >x-bin/'rm' <<'END'
+#! /bin/sh
+limit=@limit@
+PATH=$oPATH; export PATH
+RM='rm -f'
+len=`expr "$RM $*" : ".*" 2>/dev/null || echo $limit`
+if test $len -ge $limit; then
+ echo "$0: safe command line limit of $limit characters exceeded" >&2
+ exit 1
+fi
+exec $RM "$@"
+exit 1
+END
+
+# Creative quoting in the next line to please maintainer-check.
+chmod +x x-bin/'rm' x-bin/my-install
+
+cat >setenv.in <<'END'
+orig_INSTALL='@INSTALL@'
+# In case we've falled back on the install-sh script (seen e.g.,
+# on AIX 7.1), we need to make sure we use its absolute path,
+# as we don't know from which directory we'll be run.
+case "$orig_INSTALL" in
+ /*) ;;
+ */*) orig_INSTALL=$(pwd)/$orig_INSTALL;;
+esac
+export orig_INSTALL
+END
+
+cat >>configure.ac <<END
+AC_CONFIG_FILES([setenv.sh:setenv.in])
+AC_CONFIG_FILES([$subdir/Makefile])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<END
+SUBDIRS = $subdir
+END
+
+mkdir $subdir
+cd $subdir
+
+cat >Makefile.am <<'END'
+man_MANS =
+man3_MANS =
+notrans_man_MANS =
+notrans_man3_MANS =
+END
+
+for n in $list; do
+ unindent >>Makefile.am <<END
+ man_MANS += page$n.1
+ man3_MANS += page$n.man
+ notrans_man_MANS += npage$n.1
+ notrans_man3_MANS += npage$n.man
+END
+ echo >page$n.1
+ echo >page$n.man
+ echo >npage$n.1
+ echo >npage$n.man
+done
+
+cd ..
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+instdir=$(pwd)/inst
+mkdir build
+cd build
+../configure --prefix="$instdir"
+. ./setenv.sh
+test -n "$orig_INSTALL"
+$MAKE
+# Try whether native install (or install-sh) works.
+$MAKE install
+test -f "$instdir/share/man/man1/page1.1"
+# Multiple uninstall should work, too.
+$MAKE uninstall
+$MAKE uninstall
+test $(find "$instdir" -type f -print | wc -l) -eq 0
+
+# Try whether we don't exceed the low limit.
+PATH=$nPATH; export PATH
+run_make INSTALL=my-install install
+test -f "$instdir/share/man/man1/page1.1"
+run_make INSTALL=my-install uninstall
+test $(find "$instdir" -type f -print | wc -l) -eq 0
+PATH=$oPATH; export PATH
+
+cd $subdir
+srcdir=../../$subdir
+
+# Ensure 'make install' fails when 'install' fails.
+
+# We cheat here, for efficiency, knowing the internal rule names.
+# For correctness, one should '$MAKE install' here always, or at
+# least use install-exec or install-data.
+
+for file in page3.1 page$nfiles.1 npage3.1 npage$nfiles.1; do
+ chmod a-r $srcdir/$file
+ test ! -r $srcdir/$file || skip_ "cannot drop file read permissions"
+ $MAKE install-man1 && exit 1
+ chmod u+r $srcdir/$file
+done
+
+for file in page3.man page$nfiles.man npage3.man npage$nfiles.man; do
+ chmod a-r $srcdir/$file
+ $MAKE install-man3 && exit 1
+ chmod u+r $srcdir/$file
+done
+
+:
diff --git a/t/instmany-python.sh b/t/instmany-python.sh
new file mode 100644
index 000000000..542251b97
--- /dev/null
+++ b/t/instmany-python.sh
@@ -0,0 +1,157 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Installing many files should not exceed the command line length limit.
+
+# This is the python sister test of 'instmany.sh', see there for details.
+
+required='python'
+. test-init.sh
+
+limit=2500
+subdir=long_subdir_name_with_many_characters
+nfiles=81
+list=$(seq_ 1 $nfiles)
+
+oPATH=$PATH; export oPATH
+nPATH=$(pwd)/x-bin$PATH_SEPARATOR$PATH; export nPATH
+
+mkdir x-bin
+
+sed "s|@limit@|$limit|g" >x-bin/my-install <<'END'
+#! /bin/sh
+limit=@limit@
+PATH=$oPATH; export PATH
+if test -z "$orig_INSTALL"; then
+ echo "$0: \$orig_INSTALL variable not set" >&2
+ exit 1
+fi
+len=`expr "$orig_INSTALL $*" : ".*" 2>/dev/null || echo $limit`
+if test $len -ge $limit; then
+ echo "$0: safe command line limit of $limit characters exceeded" >&2
+ exit 1
+fi
+exec $orig_INSTALL "$@"
+exit 1
+END
+
+# Creative quoting in the next line to please maintainer-check.
+sed "s|@limit@|$limit|g" >x-bin/'rm' <<'END'
+#! /bin/sh
+limit=@limit@
+PATH=$oPATH; export PATH
+RM='rm -f'
+len=`expr "$RM $*" : ".*" 2>/dev/null || echo $limit`
+if test $len -ge $limit; then
+ echo "$0: safe command line limit of $limit characters exceeded" >&2
+ exit 1
+fi
+exec $RM "$@"
+exit 1
+END
+
+# Creative quoting in the next line to please maintainer-check.
+chmod +x x-bin/'rm' x-bin/my-install
+
+cat >setenv.in <<'END'
+orig_INSTALL='@INSTALL@'
+# In case we've falled back on the install-sh script (seen e.g.,
+# on AIX 7.1), we need to make sure we use its absolute path,
+# as we don't know from which directory we'll be run.
+case "$orig_INSTALL" in
+ /*) ;;
+ */*) orig_INSTALL=$(pwd)/$orig_INSTALL;;
+esac
+export orig_INSTALL
+END
+
+cat >>configure.ac <<END
+AM_PATH_PYTHON
+AC_CONFIG_FILES([setenv.sh:setenv.in])
+AC_CONFIG_FILES([$subdir/Makefile])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<END
+SUBDIRS = $subdir
+END
+
+mkdir $subdir
+cd $subdir
+
+cat >Makefile.am <<'END'
+python_PYTHON =
+nobase_python_PYTHON =
+END
+
+for n in $list; do
+ unindent >>Makefile.am <<END
+ python_PYTHON += python$n.py
+ nobase_python_PYTHON += npython$n.py
+END
+ echo >python$n.py
+ echo >npython$n.py
+done
+
+cd ..
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+instdir=$(pwd)/inst
+mkdir build
+cd build
+../configure --prefix="$instdir"
+. ./setenv.sh
+test -n "$orig_INSTALL"
+$MAKE
+# Try whether native install (or install-sh) works.
+$MAKE install
+test -n "$(find "$instdir" -name python1.py)"
+# Multiple uninstall should work, too.
+$MAKE uninstall
+$MAKE uninstall
+test $(find "$instdir" -type f -print | wc -l) -eq 0
+
+# Try whether we don't exceed the low limit.
+PATH=$nPATH; export PATH
+run_make INSTALL=my-install install
+test -n "$(find "$instdir" -name python1.py)"
+run_make INSTALL=my-install uninstall
+test $(find "$instdir" -type f -print | wc -l) -eq 0
+PATH=$oPATH; export PATH
+
+cd $subdir
+srcdir=../../$subdir
+
+# Ensure 'make install' fails when 'install' fails.
+
+for file in python3.py python$nfiles.py
+do
+ chmod a-r $srcdir/$file
+ test ! -r $srcdir/$file || skip_ "cannot drop file read permissions"
+ $MAKE install && exit 1
+ chmod u+r $srcdir/$file
+done
+
+for file in npython3.py npython$nfiles.py
+do
+ chmod a-r $srcdir/$file
+ $MAKE install && exit 1
+ chmod u+r $srcdir/$file
+done
+
+:
diff --git a/t/instmany.sh b/t/instmany.sh
new file mode 100644
index 000000000..7bb92d2b9
--- /dev/null
+++ b/t/instmany.sh
@@ -0,0 +1,212 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Installing many files should not exceed the command line length limit.
+# Here, the main issue is that we may prepend '$(srcdir)/' to each file,
+# which may cause much longer command lines. The list of files must
+# anyway remain below the limit, otherwise 'make' won't be able to even
+# fork the command.
+#
+# Further, the install rule should honor failures of the install program.
+
+# Python is done in the sister test.
+# For texinfos, we expand names using $(srcdir) in the first place.
+# Let's hope nobody uses many texinfos.
+
+. test-init.sh
+
+# In order to have a useful test on modern systems (which have a high
+# limit, if any), use a fake install program that errors out for more
+# than 2K characters in a command line. The POSIX limit is 4096, but
+# that may include space taken up by the environment.
+
+limit=2500
+subdir=long_subdir_name_with_many_characters
+nfiles=81
+list=$(seq_ 1 $nfiles)
+
+oPATH=$PATH; export oPATH
+nPATH=$(pwd)/x-bin$PATH_SEPARATOR$PATH; export nPATH
+
+mkdir x-bin
+
+sed "s|@limit@|$limit|g" >x-bin/my-install <<'END'
+#! /bin/sh
+limit=@limit@
+PATH=$oPATH; export PATH
+if test -z "$orig_INSTALL"; then
+ echo "$0: \$orig_INSTALL variable not set" >&2
+ exit 1
+fi
+len=`expr "$orig_INSTALL $*" : ".*" 2>/dev/null || echo $limit`
+if test $len -ge $limit; then
+ echo "$0: safe command line limit of $limit characters exceeded" >&2
+ exit 1
+fi
+exec $orig_INSTALL "$@"
+exit 1
+END
+
+# Creative quoting in the next line to please maintainer-check.
+sed "s|@limit@|$limit|g" >x-bin/'rm' <<'END'
+#! /bin/sh
+limit=@limit@
+PATH=$oPATH; export PATH
+RM='rm -f'
+len=`expr "$RM $*" : ".*" 2>/dev/null || echo $limit`
+if test $len -ge $limit; then
+ echo "$0: safe command line limit of $limit characters exceeded" >&2
+ exit 1
+fi
+exec $RM "$@"
+exit 1
+END
+
+# Creative quoting in the next line to please maintainer-check.
+chmod +x x-bin/'rm' x-bin/my-install
+
+cat >setenv.in <<'END'
+orig_INSTALL='@INSTALL@'
+# In case we've falled back on the install-sh script (seen e.g.,
+# on AIX 7.1), we need to make sure we use its absolute path,
+# as we don't know from which directory we'll be run.
+case "$orig_INSTALL" in
+ /*) ;;
+ */*) orig_INSTALL=$(pwd)/$orig_INSTALL;;
+esac
+export orig_INSTALL
+END
+
+cat >>configure.ac <<END
+AC_CONFIG_FILES([setenv.sh:setenv.in])
+AC_CONFIG_FILES([$subdir/Makefile])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<END
+SUBDIRS = $subdir
+END
+
+mkdir $subdir
+cd $subdir
+
+cat >Makefile.am <<'END'
+bin_SCRIPTS =
+nobase_bin_SCRIPTS =
+data_DATA =
+nobase_data_DATA =
+include_HEADERS =
+nobase_include_HEADERS =
+END
+
+for n in $list; do
+ unindent >>Makefile.am <<END
+ bin_SCRIPTS += script$n
+ nobase_bin_SCRIPTS += nscript$n
+ data_DATA += data$n
+ nobase_data_DATA += ndata$n
+ include_HEADERS += header$n.h
+ nobase_include_HEADERS += nheader$n.h
+END
+ echo >script$n
+ echo >nscript$n
+ echo >data$n
+ echo >ndata$n
+ echo >header$n.h
+ echo >nheader$n.h
+done
+
+cd ..
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+instdir=$(pwd)/inst
+mkdir build
+cd build
+../configure --prefix="$instdir"
+. ./setenv.sh
+test -n "$orig_INSTALL"
+$MAKE
+# Try whether native install (or install-sh) works.
+$MAKE install
+test -f "$instdir/bin/script1"
+# Multiple uninstall should work, too.
+$MAKE uninstall
+$MAKE uninstall
+test $(find "$instdir" -type f -print | wc -l) -eq 0
+
+# Try whether we don't exceed the low limit.
+PATH=$nPATH; export PATH
+run_make INSTALL=my-install install
+test -f "$instdir/bin/script1"
+run_make INSTALL=my-install uninstall
+test $(find "$instdir" -type f -print | wc -l) -eq 0
+PATH=$oPATH; export PATH
+
+cd $subdir
+srcdir=../../$subdir
+
+# Ensure 'make install' fails when 'install' fails.
+
+# We cheat here, for efficiency, knowing the internal rule names.
+# For correctness, one should '$MAKE install' here always, or at
+# least use install-exec or install-data.
+
+for file in script3 script$nfiles
+do
+ chmod a-r $srcdir/$file
+ test ! -r $srcdir/$file || skip_ "cannot drop file read permissions"
+ $MAKE install-binSCRIPTS && exit 1
+ chmod u+r $srcdir/$file
+done
+
+for file in nscript3 nscript$nfiles
+do
+ chmod a-r $srcdir/$file
+ $MAKE install-nobase_binSCRIPTS && exit 1
+ chmod u+r $srcdir/$file
+done
+
+for file in data3 data$nfiles
+do
+ chmod a-r $srcdir/$file
+ $MAKE install-dataDATA && exit 1
+ chmod u+r $srcdir/$file
+done
+
+for file in ndata3 ndata$nfiles
+do
+ chmod a-r $srcdir/$file
+ $MAKE install-nobase_dataDATA && exit 1
+ chmod u+r $srcdir/$file
+done
+
+for file in header3.h header$nfiles.h
+do
+ chmod a-r $srcdir/$file
+ $MAKE install-includeHEADERS && exit 1
+ chmod u+r $srcdir/$file
+done
+
+for file in nheader3.h nheader$nfiles.h
+do
+ chmod a-r $srcdir/$file
+ $MAKE install-nobase_includeHEADERS && exit 1
+ chmod u+r $srcdir/$file
+done
+
+:
diff --git a/t/instspc.tap b/t/instspc.tap
new file mode 100644
index 000000000..01ef38bd9
--- /dev/null
+++ b/t/instspc.tap
@@ -0,0 +1,341 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that building from, or installing to, directories with shell
+# metacharacters succeed.
+# Original report from James Amundson about file names with spaces.
+# Other characters added by Paul Eggert.
+
+. test-init.sh
+
+# Usage: is_in_list ITEM [LIST...]
+is_in_list ()
+{
+ item=$1; shift;
+ case " $* " in
+ *[\ \ ]"$item"[\ \ ]*) return 0;;
+ *) return 1;;
+ esac
+}
+
+# Helper subroutine for test data definition.
+# Usage: define_problematic_string NAME STRING
+define_problematic_string ()
+{
+ tst=$1; shift
+ eval "instspc__$tst=\$1" \
+ || fatal_ "define_problematic_string: bad argument: '$tst'"
+ shift
+ all_test_names_list="$all_test_names_list $tst"
+ # Some of the "problematic" characters cannot be used in the name of
+ # a build or install directory on a POSIX host. These lists should
+ # be empty, but are not due to limitations in Autoconf, Automake, Make,
+ # M4, or the shell.
+ if is_in_list fail-builddir "$@"; then
+ builddir_xfails="$builddir_xfails $tst"
+ fi
+ if is_in_list fail-destdir "$@"; then
+ destdir_xfails="$destdir_xfails $tst"
+ fi
+}
+
+# Be sure to avoid interferences from the environment.
+all_test_names_list=''
+builddir_xfails=''
+destdir_xfails=''
+
+expected_to_fail ()
+{
+ case $1 in
+ build) is_in_list "$2" $builddir_xfails;;
+ dest) is_in_list "$2" $destdir_xfails;;
+ *) fatal_ "incorrect 'expected_to_fail' usage";;
+ esac
+}
+
+# Helper subroutines for creation of input data files.
+create_input_data ()
+{
+ mkdir sub
+
+ unindent >> configure.ac << 'EOF'
+ AC_PROG_CC
+ AM_PROG_AR
+ AC_PROG_RANLIB
+ AC_OUTPUT
+EOF
+
+ : > sub/base.h
+ : > sub/nobase.h
+ : > sub/base.dat
+ : > sub/nobase.dat
+ : > sub/base.sh
+ : > sub/nobase.sh
+
+ unindent > source.c << 'EOF'
+ int
+ main (int argc, char **argv)
+ {
+ return 0;
+ }
+EOF
+
+ unindent > Makefile.am << 'EOF'
+ foodir = $(prefix)/foo
+ fooexecdir = $(prefix)/foo
+
+ foo_HEADERS = sub/base.h
+ nobase_foo_HEADERS = sub/nobase.h
+
+ dist_foo_DATA = sub/base.dat
+ nobase_dist_foo_DATA = sub/nobase.dat
+
+ dist_fooexec_SCRIPTS = sub/base.sh
+ nobase_dist_fooexec_SCRIPTS = sub/nobase.sh
+
+ fooexec_PROGRAMS = sub/base
+ nobase_fooexec_PROGRAMS = sub/nobase
+ sub_base_SOURCES = source.c
+ sub_nobase_SOURCES = source.c
+
+ fooexec_LIBRARIES = sub/libbase.a
+ nobase_fooexec_LIBRARIES = sub/libnobase.a
+ sub_libbase_a_SOURCES = source.c
+ sub_libnobase_a_SOURCES = source.c
+
+ .PHONY: test-inst
+ test-inst: install
+ test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase.h'
+ test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase.h'
+ test -f '$(DESTDIR)/$(file)-prefix/foo/base.h'
+ test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase.dat'
+ test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase.dat'
+ test -f '$(DESTDIR)/$(file)-prefix/foo/base.dat'
+ test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase.sh'
+ test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase.sh'
+ test -f '$(DESTDIR)/$(file)-prefix/foo/base.sh'
+ test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase$(EXEEXT)'
+ test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase$(EXEEXT)'
+ test -f '$(DESTDIR)/$(file)-prefix/foo/base$(EXEEXT)'
+ test -f '$(DESTDIR)/$(file)-prefix/foo/sub/libnobase.a'
+ test ! -f '$(DESTDIR)/$(file)-prefix/foo/libnobase.a'
+ test -f '$(DESTDIR)/$(file)-prefix/foo/libbase.a'
+EOF
+
+ $ACLOCAL || framework_failure_ "aclocal failed"
+ $AUTOCONF || framework_failure_ "autoconf failed"
+ $AUTOMAKE -a || framework_failure_ "automake failed"
+}
+
+# ================= #
+# Test data begin #
+# ----------------- #
+
+# Some control characters that are white space.
+bs='' # back space
+cr=' ' # carriage return
+ff=' ' # form feed
+ht=' ' # horizontal tab
+lf='
+' # line feed (aka newline)
+
+# Hack to save typing and make code visually clearer.
+def=define_problematic_string
+
+$def squote \' fail-builddir fail-destdir
+$def dquote '"' fail-builddir fail-destdir
+$def bquote '`' fail-builddir fail-destdir
+$def sharp '#' fail-builddir fail-destdir
+$def dollar '$' fail-builddir fail-destdir
+$def bang '!'
+$def bslash '\' fail-builddir
+$def ampersand '&' fail-builddir
+$def percent '%'
+$def leftpar '('
+$def rightpar ')'
+$def pipe '|'
+$def caret '^'
+$def tilde '~'
+$def qmark '?'
+$def star '*'
+$def plus '+'
+$def minus '-'
+$def comma ','
+$def colon ':'
+$def semicol ';'
+$def equal '='
+$def less '<'
+$def more '>'
+$def at '@'
+$def lqbrack '['
+$def rqbrack ']'
+$def lcbrack '{'
+$def rcbrack '}'
+$def space ' '
+$def tab "$ht"
+$def linefeed "$lf" fail-builddir fail-destdir
+$def backspace "$bs"
+$def formfeed "$ff"
+$def carriageret "$cr"
+$def quadrigraph0 '@&t@' fail-builddir
+$def quadrigraph1 '@<:@'
+$def quadrigraph2 '@:>@'
+$def quadrigraph3 '@S|@'
+$def quadrigraph4 '@%:@'
+$def a_b 'a b'
+$def a__b 'a b'
+$def a_lf_b "a${lf}b" fail-builddir fail-destdir
+$def dotdotdot '...'
+$def dosdrive 'a:'
+$def miscglob1 '?[a-z]*'
+$def miscglob2 '.*?[0-9]'
+
+unset def
+
+# --------------- #
+# Test data end #
+# =============== #
+
+# Allow the user to select a subset of the tests.
+if test $# -gt 0; then
+ test_names_list=$*
+ for test_name in $test_names_list; do
+ case " $all_test_names_list " in
+ *" $test_name "*);;
+ *) fatal_ "invalid user-specified test_name '$test_name'"
+ esac
+ done
+ # We need to determine the TAP plan adaptively.
+ n=$(for t in $test_names_list; do echo $t; done | wc -l)
+ plan_ $(($n * 2)) # Two tests per "problematic string".
+ unset n
+else
+ test_names_list=$all_test_names_list
+ # Prefer static TAP plan if possible, it minimizes the chance of errors.
+ plan_ 94
+fi
+
+ocwd=$(pwd) || fatal_ "getting current working directory"
+
+create_input_data
+
+for test_name in $test_names_list; do
+
+ eval "test_string=\${instspc__$test_name}" \
+ || fatal_ "invalid test name: '$test_name'"
+
+ if test x"$test_string" = x; then
+ if test x"$test_name" != xcarriageret; then
+ fatal_ "invalid test name: '$test_name'"
+ else
+ # MSYS version 1.0.17 still mishandles carriage returns; see
+ # automake bug#7849.
+ skip_ -r "carriage-return treated as null char" "$test_name in builddir"
+ skip_ -r "carriage-return treated as null char" "$test_name in destdir"
+ continue
+ fi
+ fi
+
+ # Skip the next checks if this system doesn't support the required
+ # characters in file names.
+
+ mkdir "./$test_string" || {
+ skip_ -r "mkdir failed" "$test_name in builddir"
+ skip_ -r "mkdir failed" "$test_name in destdir"
+ continue
+ }
+
+ case $test_string in
+ *:*)
+ # On MSYS 1.0.17, "mkdir ./a:" creates ./a, and "cd ./a:" takes you
+ # to a strange directory with pwd equal to "a". But only for
+ # interactive shells. Or something? In this script, "cd ./a:" fails
+ # on MSYS. Marvelous.
+ ( cd "./$test_string" ) || {
+ rmdir "./$test_string" || fatal_ "removing directory"
+ skip_ -r "cd failed" "$test_name in builddir"
+ skip_ -r "cd failed" "$test_name in destdir"
+ continue
+ }
+ ;;
+ esac
+
+ # Where are the "weird" characters going to be used, in $(builddir)
+ # or in $(DESTDIR)? They are always going to be used in $(prefix)
+ # though; should we maybe separate this into a dedicated check?
+ for where in build dest; do
+
+ case $where in
+ build)
+ build=./$test_string
+ dest=$ocwd/dest-$test_name
+ ;;
+ dest)
+ build=build-$test_name
+ # Also use $test_name in the definition of $dest, to avoid
+ # interferences among different tests in case $test_string
+ # is strangely munged (which is not unexpected, considering
+ # how tricky its characters are). With some shells, this
+ # has already happened (at least on OpenIndiana 11 and on
+ # Solaris 10).
+ dest=$ocwd/dest-$test_name/$test_string
+ mkdir "$build" || fatal_ "cannot create '$build'"
+ ;;
+ *)
+ fatal_ "invalid where '$where'"
+ ;;
+ esac
+
+ cd "$build" || fatal_ "cannot chdir into '$build'"
+
+ # Some make implementations eliminate leading and trailing whitespace
+ # from macros passed on the command line, and some eliminate leading
+ # whitespace from macros set from environment variables, so prepend
+ # './' and use the latter here.
+ r=ok
+ ../configure --prefix "/$test_string-prefix" \
+ && $MAKE all \
+ && DESTDIR="$dest" file="./$test_string" $MAKE test-inst \
+ || r='not ok'
+
+ description="$test_name in ${where}dir"
+ if expected_to_fail "$where" "$test_name"; then
+ directive=TODO
+ reason="long-standing limitation"
+ else
+ directive=
+ reason=
+ fi
+ # Test case outcome is here.
+ result_ "$r" -D "$directive" -r "$reason" -- "$description"
+
+ cd "$ocwd" || fatal_ "cannot chdir back to test directory"
+
+ # Remove subdirectories for tests that have passed, to avoid ending up
+ # with a too big test directory. This is especially important since
+ # some tests in this tests are expected to fail, and this will cause
+ # the test directory not to be removed when the script terminates.
+ if not am_keeping_testdirs && test "$r" = ok; then
+ rm_rf_ "$build" "$dest" || fatal_ "removing temporary subdirectory"
+ fi
+
+ : For shells with busted 'set -e'.
+
+ done # $instspc_action
+
+done # $test_name
+
+:
diff --git a/t/interp.sh b/t/interp.sh
new file mode 100644
index 000000000..992083812
--- /dev/null
+++ b/t/interp.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure variable interpolation works.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+xs = a.c b.c
+foo_SOURCES = c.c $(xs)
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP ' a.$(OBJEXT)' Makefile.in
+$FGREP ' b.$(OBJEXT)' Makefile.in
+$FGREP ' c.$(OBJEXT)' Makefile.in
+
+:
diff --git a/t/interp2.sh b/t/interp2.sh
new file mode 100644
index 000000000..5b543f276
--- /dev/null
+++ b/t/interp2.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure variable interpolation doesn't break other
+# features. Report from Joel N. Weber, II.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PATH_X
+AC_PATH_XTRA
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = x
+x_SOURCES = x.c
+x_LDADD = $(X_EXTRA_LIBS)
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/java-check.sh b/t/java-check.sh
new file mode 100644
index 000000000..ae2ef54ed
--- /dev/null
+++ b/t/java-check.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that check_JAVA causes *.class files to be built only with
+# "make check", and not also with "make all".
+# See automake bug#8234.
+
+required=javac
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+check_JAVA = One.java Two.java
+END
+
+cat > One.java <<'END'
+class One { }
+END
+
+cat > Two.java <<'END'
+class Two { // Deliberately missing closing bracket.
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+inst=$(pwd)/_inst
+
+./configure --prefix="$inst"
+
+$MAKE
+ls | $EGREP '\.(class|stamp)$' && exit 1
+
+# Make Two.java compilable.
+echo '}' >> Two.java
+
+# "make check" should compile files in $(check_JAVA) ...
+$MAKE check
+ls -l # For debugging.
+test -f One.class
+test -f Two.class
+# ... but should *not* install them.
+$FGREP checkdir Makefile && exit 1
+$MAKE install
+test -d _inst && exit 1
+
+:
diff --git a/t/java-clean.sh b/t/java-clean.sh
new file mode 100644
index 000000000..1d82de801
--- /dev/null
+++ b/t/java-clean.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test cleaning of Java class files and timestamps.
+
+required=javac
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+
+java_JAVA = Class.java
+dist_java_JAVA = ClassDist.java
+nodist_java_JAVA = ClassNodist.java
+
+nobase_java_JAVA = ClassNobase.java
+nobase_dist_java_JAVA = ClassNobaseDist.java
+nobase_nodist_java_JAVA = ClassNobaseNodist.java
+END
+
+for base in '' Nobase; do
+ for dist in '' Dist Nodist; do
+ echo "class Class$base$dist {}" > Class$base$dist.java
+ done
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+ls -l
+test -f classjava.stamp
+for base in '' Nobase; do
+ for dist in '' Dist Nodist; do
+ test -f Class$base$dist.class
+ done
+done
+$MAKE clean
+find . -name '*.class' -o -name '*.stamp' | grep . && exit 1
+# We should not remove unrelated stamp files.
+echo timestamp > classjava2.stamp
+echo timestamp > classdist_java.stamp
+$MAKE clean
+test -f classjava2.stamp
+test -f classdist_java.stamp
+
+:
diff --git a/t/java-compile-install.sh b/t/java-compile-install.sh
new file mode 100644
index 000000000..4956aeee4
--- /dev/null
+++ b/t/java-compile-install.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test on compilation and installation of Java class files.
+
+required=javac
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+java_JAVA = Foo.java
+nobase_java_JAVA = Foo2.java
+nobase_dist_java_JAVA = Bar.java
+nodist_java_JAVA = Baz.java
+
+# Java files are not distributed by default, so we distribute
+# one "by hand" ...
+EXTRA_DIST = Foo.java
+# ... and make the other one generated.
+Foo2.java:
+ rm -f $@ $@-t
+ echo 'class bClass {}' > $@-t
+ chmod a-w $@-t && mv -f $@-t $@
+
+# Explicitly declared as 'nodist_', so generate it.
+Baz.java:
+ rm -f $@ $@-t
+ echo 'class Baz {}' > $@-t
+ echo 'class Baz2 {}' >> $@-t
+ chmod a-w $@-t && mv -f $@-t $@
+
+test:
+ ls -l $(srcdir) . ;: For debugging.
+ test -f $(srcdir)/Foo.java
+ test -f $(srcdir)/Bar.java
+ test -f Foo2.java
+ test -f Baz.java
+ test -f aClass.class
+ test -f bClass.class
+ test -f Zardoz.class
+ test -f Baz.class
+ test -f Baz2.class
+ test ! -r Foo.class
+ test ! -r Bar.class
+ test -f classjava.stamp
+
+test-install:
+ ls -l $(javadir) ;: For debugging.
+ test -f '$(javadir)/bClass.class'
+ test -f '$(javadir)/aClass.class'
+ test -f '$(javadir)/Zardoz.class'
+ test -f '$(javadir)/Baz.class'
+ test -f '$(javadir)/Baz2.class'
+ test ! -r '$(javadir)/Foo.class'
+ test ! -r '$(javadir)/Bar.class'
+ if find $(prefix) | grep '\.stamp$$'; then exit 1; else :; fi
+
+check-local: test
+installcheck-local: test-install
+
+.PHONY: test test-install
+
+DISTCLEANFILES = Baz.java Foo2.java
+END
+
+echo 'class aClass {}' > Foo.java
+echo 'class Zardoz {}' > Bar.java
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure --prefix="$(pwd)"/_inst
+$MAKE
+$MAKE test
+$MAKE install
+$MAKE test-install
+$MAKE distcheck
+
+:
diff --git a/t/java-compile-run-flat.sh b/t/java-compile-run-flat.sh
new file mode 100644
index 000000000..1f74a3c62
--- /dev/null
+++ b/t/java-compile-run-flat.sh
@@ -0,0 +1,241 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test on compilation and execution of Java class files.
+# Also meddle with wrapper scripts, as would be probably seen in a real
+# "UNIX-style" use case.
+# This test uses a "flat" setup for the source tree (i.e., everything in
+# the top-level directory), and forces the use of the old, non-parallel
+# testsuite driver. The sister test 'java-compile-run-nested.sh' do
+# similar checks with a more usual, "nested" setup, and using the older
+# 'serial-tests' driver.
+
+required='java javac'
+am_serial_tests=yes
+. test-init.sh
+
+echo "AC_SUBST([PATH_SEPARATOR], ['$PATH_SEPARATOR'])" >> configure.ac
+
+cat >> configure.ac <<'END'
+AC_SUBST([JAVA], [java])
+AC_CONFIG_SRCDIR([PkgLocation.jin])
+AC_CONFIG_FILES([PkgLocation.java:PkgLocation.jin])
+AC_OUTPUT
+END
+
+## TOP-LEVEL SETUP AND TARGETS ##
+
+cat > Makefile.am <<'END'
+EXTRA_DIST = # Will be updated later.
+
+test-built:
+ ls -l $(srcdir) ;: For debugging.
+ test $(srcdir) = . || ls -l . ;: Likewise.
+ test -f $(srcdir)/Main.java
+ test -f $(srcdir)/HelloStream.java
+ test -f $(srcdir)/PkgLocation.jin
+ test -f PkgLocation.java
+ test -f HelloStream.class
+ test -f PkgLocation.class
+ test -f Main.class
+ test -f classjava.stamp
+
+test-installed:
+ ls -l $(javadir) ;: For debugging.
+ test -f $(javadir)/HelloStream.class
+ test -f $(javadir)/PkgLocation.class
+ test -f $(javadir)/Main.class
+ if find $(prefix) | grep '\.stamp$$'; then exit 1; else :; fi
+
+run-installed:
+ jprog_doing_installcheck=yes $(MAKE) $(AM_MAKEFLAGS) check
+
+check-local: test-built
+installcheck-local: test-installed run-installed
+
+.PHONY: test-built test-installed run-installed
+END
+
+## WRAPPER SCRIPT ##
+
+cat >> Makefile.am <<'END'
+bin_SCRIPTS = jprog
+
+edit_script = sed -e 's|[@]JAVA@|$(JAVA)|g' \
+ -e 's|[@]javadir@|$(javadir)|g' \
+ -e 's|[@]SHELL@|$(SHELL)|g' \
+ -e 's|[@]PATH_SEPARATOR@|$(PATH_SEPARATOR)|g'
+
+jprog: jprog.sh
+ rm -f $@ $@-t
+ $(edit_script) `test -f '$@.sh' || echo $(srcdir)/`$@.sh >$@-t
+ chmod a-w $@-t && chmod a+x $@-t && mv -f $@-t $@
+ sed 's/^/ | /' $@ ;: for debugging.
+
+EXTRA_DIST += jprog.sh
+CLEANFILES = jprog
+END
+
+cat > jprog.sh <<'END'
+#!@SHELL@
+CLASSPATH=${jprog_classpath-'@javadir@'}${CLASSPATH+"@PATH_SEPARATOR@$CLASSPATH"}
+export CLASSPATH
+case $# in
+ 0) exec @JAVA@ Main;;
+ *) exec @JAVA@ Main "$@";;
+esac
+END
+
+## JAVA SOURCES ##
+
+cat >> Makefile.am <<'END'
+javadir = $(pkgdatadir)/java
+
+dist_java_JAVA = Main.java HelloStream.java
+nodist_java_JAVA = PkgLocation.java
+END
+
+cat > PkgLocation.jin <<'END'
+public class PkgLocation {
+ public static String prefix() {
+ return new String("@prefix@");
+ }
+}
+END
+
+cat > Main.java <<'END'
+public class Main {
+ public static void main(String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals("--print-prefix")) {
+ System.out.println(PkgLocation.prefix());
+ } else if (args[i].equals("--hello-stdout")) {
+ HelloStream.to(System.out);
+ } else if (args[i].equals("--hello-stderr")) {
+ HelloStream.to(System.err);
+ } else {
+ System.err.println("jprog: invalid option '" + args[i] +
+ "'");
+ System.exit(2);
+ }
+ }
+ System.exit(0);
+ }
+}
+END
+
+cat > HelloStream.java <<'END'
+import java.io.PrintStream;
+class HelloStream {
+ public static void to(PrintStream stream) {
+ stream.println("Hello, Stream!");
+ }
+}
+END
+
+## TESTS ##
+
+cat >> Makefile.am <<'END'
+## We must use 'TESTS_ENVIRONMENT', not 'AM_TESTS_ENVIRONMENT',
+## because the latter is not hnoured by the old serial test
+## harness.
+TESTS_ENVIRONMENT = \
+ if test x"$$jprog_doing_installcheck" != x"yes"; then \
+ jprog_classpath='$(abs_top_builddir):$(abs_top_srcdir)'; \
+ export jprog_classpath; \
+ PATH='$(abs_top_builddir)$(PATH_SEPARATOR)'$$PATH; \
+ export PATH; \
+ else \
+ unset jprog_classpath || :; \
+ PATH='$(prefix)/bin$(PATH_SEPARATOR)'$$PATH; \
+ export PATH; \
+ fi; \
+ config_time_prefix='@prefix@'; export config_time_prefix;
+
+TESTS = \
+ simple.test \
+ prefix.test \
+ stdout.test \
+ stderr.test \
+ badarg.test
+
+XFAIL_TESTS = badarg.test
+
+EXTRA_DIST += $(TESTS)
+END
+
+cat > simple.test <<'END'
+#!/bin/sh
+jprog
+END
+
+cat > prefix.test <<'END'
+#!/bin/sh
+jprefix=`jprog --print-prefix` || exit 1
+echo "$0: exp prefix: $config_time_prefix"
+echo "$0: got prefix: $jprefix"
+test x"$jprefix" = x"$config_time_prefix"
+END
+
+cat > stdout.test <<'END'
+#!/bin/sh
+rc=0
+jprog --hello-stdout >stdout.out 2>stdout.err || { echo \$?=$?; rc=1; }
+sed 's/^/out:/' <stdout.out # For debugging.
+sed 's/^/err:/' <stdout.err >&2 # Likewise.
+test -s stdout.err && rc=1
+test "`cat stdout.out`" = 'Hello, Stream!' || rc=1
+rm -f stdout.out stdout.err || rc=1
+exit $rc
+END
+
+cat > stderr.test <<'END'
+#!/bin/sh
+rc=0
+jprog --hello-stderr >stderr.out 2>stderr.err || { echo \$?=$?; rc=1; }
+sed 's/^/out:/' <stderr.out # For debugging.
+sed 's/^/err:/' <stderr.err >&2 # Likewise.
+test -s stderr.out && rc=1
+test "`cat stderr.err`" = 'Hello, Stream!' || rc=1
+rm -f stderr.out stderr.err || rc=1
+exit $rc
+END
+
+cat > badarg.test <<'END'
+#!/bin/sh
+jprog --bad-argument
+END
+
+chmod a+x *.test
+
+## DO CHECKS ##
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+# To have the parallel testsuite more verbose.
+VERBOSE=yes; export VERBOSE
+
+./configure --prefix="$(pwd)/_inst"
+cat PkgLocation.java # For debugging.
+$MAKE check
+$MAKE install
+$MAKE test-installed
+$MAKE run-installed
+$MAKE distcheck
+
+:
diff --git a/t/java-compile-run-nested.sh b/t/java-compile-run-nested.sh
new file mode 100644
index 000000000..788b584fe
--- /dev/null
+++ b/t/java-compile-run-nested.sh
@@ -0,0 +1,250 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test on compilation and execution of Java class files.
+# Also meddle with wrapper scripts, as would be probably seen in a real
+# "UNIX-style" use case.
+# This test uses a typical "nested" source tree setup (i.e., different
+# components/aspects are separated into different subdirectories), and
+# uses the parallel testsuite driver.
+# The sister test 'java-compile-run-flat.sh' do similar checks with
+# a "flat" setup (i.e., everything in the top-level directory), and
+# forcing the use of the older 'serial-tests' driver.
+
+required='java javac'
+. test-init.sh
+
+echo "AC_SUBST([PATH_SEPARATOR], ['$PATH_SEPARATOR'])" >> configure.ac
+
+cat >> configure.ac <<'END'
+AC_SUBST([JAVA], [java])
+AC_CONFIG_SRCDIR([jprog/PkgLocation.jin])
+AC_SUBST([jprogdatadir], ['${pkgdatadir}'])
+AC_SUBST([jprogclassdir], ['${jprogdatadir}/jprog'])
+AC_CONFIG_FILES([jprog/PkgLocation.java:jprog/PkgLocation.jin])
+AC_CONFIG_FILES([jprog/Makefile bin/Makefile tests/Makefile])
+AC_OUTPUT
+END
+
+## TOP-LEVEL SETUP AND TARGETS ##
+
+cat > Makefile.am <<'END'
+SUBDIRS = bin jprog tests
+
+test-built:
+ ls -l $(srcdir)/* ;: For debugging.
+ test $(srcdir) = . || ls -l * ;: Likewise.
+ test -f $(srcdir)/jprog/Main.java
+ test -f $(srcdir)/jprog/HelloStream.java
+ test -f $(srcdir)/jprog/PkgLocation.jin
+ test -f jprog/PkgLocation.java
+ test -f jprog/HelloStream.class
+ test -f jprog/Main.class
+ test -f jprog/PkgLocation.class
+ test -f jprog/classjprogclass.stamp
+
+test-installed:
+ ls -l $(jprogclassdir) ;: For debugging.
+ test -f $(jprogclassdir)/HelloStream.class
+ test -f $(jprogclassdir)/Main.class
+ test -f $(jprogclassdir)/PkgLocation.class
+ if find $(prefix) | grep '\.stamp$$'; then exit 1; else :; fi
+
+run-installed:
+ jprog_doing_installcheck=yes $(MAKE) $(AM_MAKEFLAGS) check
+
+check-local: test-built
+installcheck-local: test-installed run-installed
+
+.PHONY: test-built test-installed run-installed
+END
+
+## WRAPPER SCRIPT ##
+
+mkdir bin
+
+cat > bin/Makefile.am <<'END'
+bin_SCRIPTS = jprog
+
+edit_script = sed -e 's|[@]JAVA@|$(JAVA)|g' \
+ -e 's|[@]jprogdatadir@|$(jprogdatadir)|g' \
+ -e 's|[@]SHELL@|$(SHELL)|g' \
+ -e 's|[@]PATH_SEPARATOR@|$(PATH_SEPARATOR)|g'
+
+jprog: jprog.sh
+ rm -f $@ $@-t
+ $(edit_script) `test -f '$@.sh' || echo $(srcdir)/`$@.sh >$@-t
+ chmod a-w $@-t && chmod a+x $@-t && mv -f $@-t $@
+ sed 's/^/ | /' $@ ;: for debugging.
+
+EXTRA_DIST = jprog.sh
+CLEANFILES = jprog
+END
+
+cat > bin/jprog.sh <<'END'
+#!@SHELL@
+CLASSPATH=${jprog_classpath-'@jprogdatadir@'}${CLASSPATH+"@PATH_SEPARATOR@$CLASSPATH"}
+export CLASSPATH
+case $# in
+ 0) exec @JAVA@ jprog.Main;;
+ *) exec @JAVA@ jprog.Main "$@";;
+esac
+END
+
+## JAVA SOURCES ##
+
+mkdir jprog
+
+cat > jprog/Makefile.am <<'END'
+dist_jprogclass_JAVA = Main.java HelloStream.java
+nodist_jprogclass_JAVA = PkgLocation.java
+END
+
+cat > jprog/PkgLocation.jin <<'END'
+package jprog;
+public class PkgLocation {
+ public static String prefix() {
+ return new String("@prefix@");
+ }
+}
+END
+
+cat > jprog/Main.java <<'END'
+package jprog;
+import jprog.PkgLocation;
+import jprog.HelloStream;
+public class Main {
+ public static void main(String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals("--print-prefix")) {
+ System.out.println(PkgLocation.prefix());
+ } else if (args[i].equals("--hello-stdout")) {
+ HelloStream.to(System.out);
+ } else if (args[i].equals("--hello-stderr")) {
+ HelloStream.to(System.err);
+ } else {
+ System.err.println("jprog: invalid option '" + args[i] +
+ "'");
+ System.exit(2);
+ }
+ }
+ System.exit(0);
+ }
+}
+END
+
+cat > jprog/HelloStream.java <<'END'
+package jprog;
+import java.io.PrintStream;
+class HelloStream {
+ public static void to(PrintStream stream) {
+ stream.println("Hello, Stream!");
+ }
+}
+END
+
+## TESTS ##
+
+mkdir tests
+
+cat > tests/Makefile.am <<'END'
+AM_TESTS_ENVIRONMENT = \
+ if test x"$$jprog_doing_installcheck" != x"yes"; then \
+ jprog_classpath='$(abs_top_builddir):$(abs_top_srcdir)'; \
+ export jprog_classpath; \
+ PATH='$(abs_top_builddir)/bin$(PATH_SEPARATOR)'$$PATH; \
+ export PATH; \
+ else \
+ unset jprog_classpath || :; \
+ PATH='$(prefix)/bin$(PATH_SEPARATOR)'$$PATH; \
+ export PATH; \
+ fi; \
+ config_time_prefix='@prefix@'; export config_time_prefix;
+
+TESTS = \
+ simple.test \
+ prefix.test \
+ stdout.test \
+ stderr.test \
+ badarg.test
+
+XFAIL_TESTS = badarg.test
+
+EXTRA_DIST = $(TESTS)
+END
+
+cat > tests/simple.test <<'END'
+#!/bin/sh
+jprog
+END
+
+cat > tests/prefix.test <<'END'
+#!/bin/sh
+jprefix=`jprog --print-prefix` || exit 1
+echo "$0: exp prefix: $config_time_prefix"
+echo "$0: got prefix: $jprefix"
+test x"$jprefix" = x"$config_time_prefix"
+END
+
+cat > tests/stdout.test <<'END'
+#!/bin/sh
+rc=0
+jprog --hello-stdout >stdout.out 2>stdout.err || { echo \$?=$?; rc=1; }
+sed 's/^/out:/' <stdout.out # For debugging.
+sed 's/^/err:/' <stdout.err >&2 # Likewise.
+test -s stdout.err && rc=1
+test "`cat stdout.out`" = 'Hello, Stream!' || rc=1
+rm -f stdout.out stdout.err || rc=1
+exit $rc
+END
+
+cat > tests/stderr.test <<'END'
+#!/bin/sh
+rc=0
+jprog --hello-stderr >stderr.out 2>stderr.err || { echo \$?=$?; rc=1; }
+sed 's/^/out:/' <stderr.out # For debugging.
+sed 's/^/err:/' <stderr.err >&2 # Likewise.
+test -s stderr.out && rc=1
+test "`cat stderr.err`" = 'Hello, Stream!' || rc=1
+rm -f stderr.out stderr.err || rc=1
+exit $rc
+END
+
+cat > tests/badarg.test <<'END'
+#!/bin/sh
+jprog --bad-argument
+END
+
+chmod a+x tests/*.test
+
+## DO CHECKS ##
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# To have the parallel testsuite more verbose.
+VERBOSE=yes; export VERBOSE
+
+./configure --prefix="$(pwd)/_inst"
+cat jprog/PkgLocation.java # For debugging.
+$MAKE check
+$MAKE install
+$MAKE test-installed
+$MAKE run-installed
+$MAKE distcheck
+
+:
diff --git a/t/java-empty-classpath.sh b/t/java-empty-classpath.sh
new file mode 100644
index 000000000..68f1ce4be
--- /dev/null
+++ b/t/java-empty-classpath.sh
@@ -0,0 +1,88 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Java compilation works also when CLASSPATH is unset or empty at
+# compilation time. See automake bug#9306.
+
+required=javac
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_SRCDIR([org/gnu/bug/Library.java])
+AC_CONFIG_FILES([
+ org/Makefile
+ org/gnu/Makefile
+ org/gnu/bug/Makefile
+])
+AC_OUTPUT
+END
+
+mkdir org org/gnu org/gnu/bug
+cat > Makefile.am <<END
+CLEANFILES = *.class
+SUBDIRS = org
+END
+echo SUBDIRS = gnu > org/Makefile.am
+echo SUBDIRS = bug > org/gnu/Makefile.am
+cat > org/gnu/bug/Makefile.am <<'END'
+JAVAROOT = ../../..
+dist_noinst_JAVA = Library.java Application.java
+END
+
+cat > org/gnu/bug/Library.java <<'END'
+package org.gnu.bug;
+public class Library
+{
+ public Library ()
+ {
+ // Nothing to do.
+ }
+ public static void doSomethingUseful (String arg)
+ {
+ System.out.println (arg);
+ }
+}
+END
+
+cat > org/gnu/bug/Application.java <<'END'
+import org.gnu.bug.*;
+public class Application
+{
+ public static void main (String args[])
+ {
+ Library lib = new Library ();
+ lib.doSomethingUseful ("PLUGH");
+ }
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+unset CLASSPATH
+$MAKE
+$MAKE clean
+
+CLASSPATH=''; export CLASSPATH
+$MAKE
+$MAKE clean
+
+unset CLASSPATH
+$MAKE distcheck
+
+:
diff --git a/t/java-extra.sh b/t/java-extra.sh
new file mode 100644
index 000000000..22b07d012
--- /dev/null
+++ b/t/java-extra.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check use of EXTRA with the JAVA primary. Also test interaction
+# of JAVA with conditionals (it's natural to test it here, since
+# EXTRA_JAVA exists mostly for ensuring interoperation with Automake
+# conditionals).
+
+required=javac
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND], [test x"$cond" = x"yes"])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+javadir = $(pkgdatadir)/java
+
+EXTRA_JAVA = Class1.java Class2.java Class3.java
+
+java_JAVA = Class1.java
+
+if COND
+java_JAVA += Class2.java
+else !COND
+java_JAVA += Class3.java
+endif !COND
+
+Class3.java: Makefile
+ echo 'class Class3 {}' > $@
+CLEANFILES = Class3.java
+END
+
+echo "class Class1 {}" > Class1.java
+echo "class Class2 {}" > Class2.java
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure cond=yes
+$MAKE
+ls -l
+test -f Class1.class
+test -f Class2.class
+test ! -e Class3.class
+test ! -e Class3.java
+
+$MAKE distclean
+
+./configure cond=no
+$MAKE
+ls -l
+test -f Class1.class
+test ! -e Class2.class
+test -f Class3.class
+test -f Class3.java
+
+:
diff --git a/t/java-mix.sh b/t/java-mix.sh
new file mode 100644
index 000000000..011c08b29
--- /dev/null
+++ b/t/java-mix.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the JAVA primary can be used freely in the same Makefile.am
+# with proper combinations of the 'dist_', 'nodist_' and 'nobase_'
+# modifiers. Also check that '.java' files are not distributed by
+# default.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# This test does not require compilation of *.java files.
+JAVAC = false
+javadir = $(prefix)
+
+java_JAVA = Class.java
+dist_java_JAVA = ClassDist.java
+nodist_java_JAVA = ClassNodist.java
+
+nobase_java_JAVA = ClassNobase.java
+nobase_dist_java_JAVA = ClassNobaseDist.java
+nobase_nodist_java_JAVA = ClassNobaseNodist.java
+
+Class.java ClassNodist.java ClassNobase.java ClassNobaseNodist.java:
+ @echo '$@ should not be generated!' >&2; exit 1
+END
+
+: > ClassDist.java
+: > ClassNobaseDist.java
+
+$ACLOCAL
+$AUTOCONF
+# Automake used to display non-fatal warnings with this test, but
+# they were unexpected, so we want to consider them as failures in
+# this test.
+$AUTOMAKE 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+test ! -s stderr
+
+./configure
+
+$MAKE distdir
+ls -l $distdir # For debugging.
+test ! -e $distdir/Class.java
+test -f $distdir/ClassDist.java
+test ! -e $distdir/ClassNobase.java
+test -f $distdir/ClassNobaseDist.java
+test ! -e $distdir/ClassNodist.java
+test ! -e $distdir/ClassNobaseNodist.java
+
+:
diff --git a/t/java-no-duplicate.sh b/t/java-no-duplicate.sh
new file mode 100644
index 000000000..cac0c20e2
--- /dev/null
+++ b/t/java-no-duplicate.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that some Java-related variables and rules are not repeatedly
+# defined.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+java_JAVA = a.java
+dist_java_JAVA = b.java
+nodist_java_JAVA = c.java
+nobase_java_JAVA = d.java
+nobase_dist_java_JAVA = e.java
+nobase_nodist_java_JAVA = f.java
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$EGREP -i '\.stamp|\.class|java|classpath' Makefile.in # For debugging.
+
+for var in JAVAC JAVAROOT CLASSPATH_ENV am__java_sources; do
+ grep "^$var =" Makefile.in
+ test $(grep -c "^[$sp$tab]*$var[$sp$tab]*=" Makefile.in) -eq 1
+done
+
+grep '^classjava\.stamp:' Makefile.in
+test $(grep -c "class.*java.*\.stamp.*:" Makefile.in) -eq 1
+
+:
diff --git a/t/java-nobase.sh b/t/java-nobase.sh
new file mode 100644
index 000000000..8673675a1
--- /dev/null
+++ b/t/java-nobase.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test support of 'nobase_' with the 'JAVA' primary.
+
+required=javac
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+nobase_java_JAVA = sub/subsub/Foo.java
+nobase_dist_java_JAVA = sub/Bar.java
+nobase_nodist_java_JAVA = sub2/Baz.java
+
+# Java files are not distributed by default.
+EXTRA_DIST = sub/subsub/Foo.java
+
+sub2/Baz.java:
+ rm -f $@ $@-t
+ test -d sub2 || mkdir sub2
+ echo 'class Baz {}' > $@-t
+ chmod a-w $@-t && mv -f $@-t $@
+
+.PHONY: test-install
+test-install:
+ find $(prefix) ;: For debugging.
+ test -f $(javadir)/sub/subsub/Foo.class
+ test -f $(javadir)/sub/Bar.class
+ test -f $(javadir)/sub2/Baz.class
+installcheck-local: test-install
+DISTCLEANFILES = sub2/Baz.java
+END
+
+mkdir sub sub/subsub
+echo 'class Foo {}' > sub/subsub/Foo.java
+echo 'class Bar {}' > sub/Bar.java
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure --prefix="$(pwd)"/_inst
+$MAKE check
+$MAKE install
+$MAKE test-install
+$MAKE distcheck
+
+:
diff --git a/t/java-noinst.sh b/t/java-noinst.sh
new file mode 100644
index 000000000..d0075b158
--- /dev/null
+++ b/t/java-noinst.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that noinst_JAVA causes generated *.class files not to
+# be installed.
+
+required=javac
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+noinst_JAVA = 1.java
+dist_noinst_JAVA = 2.java
+nodist_noinst_JAVA = 3.java
+nobase_noinst_JAVA = 4.java
+nobase_dist_noinst_JAVA = 5.java
+nobase_nodist_noinst_JAVA = 6.java
+END
+
+for i in 1 2 3 4 5 6; do
+ echo "class Class$i {}" > $i.java
+done
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure --prefix="$(pwd)/_inst"
+
+$MAKE
+ls -l
+for i in 1 2 3 4 5 6; do
+ test -f Class$i.class
+done
+
+$MAKE install
+test -d _inst && { ls -l _inst; exit 1; }
+
+:
diff --git a/t/java-rebuild.sh b/t/java-rebuild.sh
new file mode 100644
index 000000000..3f10a6499
--- /dev/null
+++ b/t/java-rebuild.sh
@@ -0,0 +1,124 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test rebuild rules for Java class files.
+
+required='javac'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+AM_JAVACFLAGS = -verbose
+foodir = $(datadir)/java
+foo_JAVA = a.java
+dist_foo_JAVA = d.java
+nodist_foo_JAVA = n.java
+nobase_foo_JAVA = Nobase.java
+nobase_dist_foo_JAVA = NobaseDist.java
+nobase_nodist_foo_JAVA = NobaseNoDist.java
+END
+
+echo 'class _x {}' > a.java
+echo 'class x_ {}' > d.java
+echo 'class a {} class d {}' > n.java
+echo 'class Nobase_Foo {} class Nobase_Bar {}' > Nobase.java
+echo 'class NobaseDist {}' > NobaseDist.java
+echo 'class NobaseNoDist {}' > NobaseNoDist.java
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+all_classes='_x x_ a d Nobase_Foo Nobase_Bar NobaseDist NobaseNoDist'
+
+for vpath in : false; do
+
+ if $vpath; then
+ srcdir=..
+ mkdir build
+ cd build
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+ $MAKE
+ ls -l # For debugging.
+
+ # Sanity check.
+ test -f classfoo.stamp
+ for cls in $all_classes; do
+ test -f $cls.class
+ done
+
+ # When the stampfile is removed, all the *.class files should
+ # be considered out-of-date.
+ echo timestamp > older
+ $sleep
+ rm -f classfoo.stamp
+ $MAKE
+ for cls in $all_classes; do
+ is_newest $cls.class older
+ done
+
+ # When only a java file is modified, only the *.class files derived from
+ # it should be updated.
+ # The strings we loop on here have the following format:
+ # "JAVA-FILES-TO-BE-TOUCHED -- CLASSES-THAT-SHOULD-BE-UPDATED"
+ for args in \
+ 'a -- _x' \
+ 'd -- x_' \
+ 'n -- a d' \
+ 'a d Nobase -- _x x_ Nobase_Foo Nobase_Bar' \
+ 'n NobaseDist -- a d NobaseDist' \
+ 'd NobaseNoDist -- x_ NobaseNoDist' \
+ "a d n Nobase NobaseDist NobaseNoDist -- $all_classes" \
+ ; do
+ set $args
+ touched_javas=
+ while test $# -gt 0; do
+ if test x"$1" = x"--"; then
+ shift
+ break
+ else
+ touched_javas="$touched_javas $1"
+ shift
+ fi
+ done
+ updated_classes=$*
+ echo timestamp > older
+ $sleep
+ for j in $touched_javas; do
+ touch $srcdir/$j.java
+ done
+ $MAKE
+ is_newest classfoo.stamp older
+ for cls in $all_classes; do
+ case " $updated_classes " in
+ *" $cls "*) is_newest $cls.class older;;
+ *) is_newest older $cls.class;;
+ esac
+ done
+ done # $args ...
+
+ cd $srcdir
+
+done # $vpath ...
+
+:
diff --git a/t/java-sources.sh b/t/java-sources.sh
new file mode 100644
index 000000000..d7dbcb2ca
--- /dev/null
+++ b/t/java-sources.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test definition of automake-generated private Makefile variable
+# '$(am__java_sources)'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+foodir = $(prefix)
+
+foo_JAVA = a.java
+dist_foo_JAVA = b.java
+nodist_foo_JAVA = c.java
+nobase_foo_JAVA = d.java
+nobase_dist_foo_JAVA = e.java
+nobase_nodist_foo_JAVA = f.java
+
+.PHONY: debug
+debug:
+ @echo 'am__java_sources: "$(am__java_sources)"'
+got:
+ @lst='$(am__java_sources)'; \
+ for f in $$lst; do echo $$f; done | sort > $@
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+cat > exp << 'END'
+a.java
+b.java
+c.java
+d.java
+e.java
+f.java
+END
+
+./configure
+$MAKE debug
+$MAKE got
+
+cat got
+cat exp
+diff exp got
+
+:
diff --git a/t/java-uninstall.sh b/t/java-uninstall.sh
new file mode 100644
index 000000000..3e79050eb
--- /dev/null
+++ b/t/java-uninstall.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check uninstallation of Java class files.
+
+required=javac
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+javadir = $(prefix)/java
+java_JAVA = Foo.java
+nobase_java_JAVA = Foo2.java
+nobase_dist_java_JAVA = Bar.java
+nodist_java_JAVA = Baz.java
+
+# Java files are not distributed by default, so we distribute
+# one "by hand" ...
+EXTRA_DIST = Foo.java
+# ... and make the other one generated.
+Foo2.java:
+ rm -f $@ $@-t
+ echo 'class bClass {}' > $@-t
+ chmod a-w $@-t && mv -f $@-t $@
+
+# Explicitly declared as 'nodist_', so generate it.
+Baz.java:
+ rm -f $@ $@-t
+ echo 'class Baz {}' > $@-t
+ echo 'class Baz2 {}' >> $@-t
+ chmod a-w $@-t && mv -f $@-t $@
+
+DISTCLEANFILES = Baz.java Foo2.java
+END
+
+echo 'class aClass {}' > Foo.java
+echo 'class Zardoz {}' > Bar.java
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure --prefix="$(pwd)"/_inst
+javadir=_inst/java
+
+check_uninstallation()
+{
+ test ! -e $javadir/aClass.class
+ test ! -e $javadir/bClass.class
+ test ! -e $javadir/Zardoz.class
+ test ! -e $javadir/Baz.class
+ test ! -e $javadir/Baz2.class
+ test -f $javadir/Foo.class
+ test -f $javadir/Bar.class
+ test -f $javadir/xClass.class
+}
+
+$MAKE
+ls -l
+$MAKE install
+: > $javadir/Foo.class
+: > $javadir/Bar.class
+: > $javadir/xClass.class
+ls -l $javadir
+$MAKE uninstall
+ls -l $javadir
+check_uninstallation
+
+# FIXME: "make uninstall" should continue to work also after "make clean",
+# but currently this doesn't happen. See automake bug#8540.
+$MAKE install
+ls -l $javadir
+$MAKE clean
+ls -l
+$MAKE uninstall
+ls -l $javadir
+#check_uninstallation
+
+$MAKE distcheck
+
+:
diff --git a/t/java.sh b/t/java.sh
new file mode 100644
index 000000000..6fad13bab
--- /dev/null
+++ b/t/java.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Minimal test of Java functionality.
+
+required=javac
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+dist_java_JAVA = a.java b.java
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+$EGREP '\.stamp|class' Makefile.in # For debugging.
+grep '^all[-a-z]*:.*classjava\.stamp' Makefile.in
+test $(grep -c '^all[-a-z]*:.*classjava\.stamp' Makefile.in) -eq 1
+
+echo 'class a { }' > a.java
+echo 'class b { }' > b.java
+
+./configure
+$MAKE distcheck
+
+:
diff --git a/t/java2.sh b/t/java2.sh
new file mode 100644
index 000000000..626ad6eaa
--- /dev/null
+++ b/t/java2.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that Java rules doesn't attempt to run javac when there is
+# no classes to compile.
+# Report from Braden McDaniel.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL(WITH_JDK, false)
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+JAVAC = false
+JAVAROOT = $(top_builddir)/java
+
+JAVA_FILES = MyClass1.java
+
+if WITH_JDK
+noinst_JAVA = $(JAVA_FILES)
+endif
+
+EXTRA_DIST = $(JAVA_FILES)
+END
+
+: >MyClass1.java
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
diff --git a/t/java3.sh b/t/java3.sh
new file mode 100644
index 000000000..b7d1f1968
--- /dev/null
+++ b/t/java3.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that Java rules don't attempt to compile or install
+# *.java files when there are none.
+# Report from Johannes Nicolai (PR/441).
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([WHO_CARES], [false])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if WHO_CARES
+JAVA_FILES = MyClass1.java
+endif
+
+javadir = $(prefix)/java
+java_JAVA = $(JAVA_FILES)
+END
+
+cat > MyClass1.java << 'END'
+class MyClass1 { // Deliberately missing right curly bracket.
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure --prefix="$(pwd)/_inst"
+$MAKE
+$MAKE install
+ls -l .
+find . -name '*.class' | grep . && exit 1
+# If we have nothing to install, we shouldn't create any installation
+# directory. Related to automake bug#11030.
+test ! -e _inst
+$MAKE uninstall
+$MAKE distcheck
+
+:
diff --git a/t/javadir-undefined.sh b/t/javadir-undefined.sh
new file mode 100644
index 000000000..e5285470f
--- /dev/null
+++ b/t/javadir-undefined.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Use of JAVA primary should not allow the use of the 'java_' prefix
+# when $(javadir) is undefined. Otherwise, we could silently end up
+# with a broken Makefile.in (where "make install" doesn't install
+# the *.class files).
+# See automake bug#8461.
+
+. test-init.sh
+
+$ACLOCAL
+
+echo java_JAVA = a.java > Makefile.am
+AUTOMAKE_fails
+grep '^Makefile\.am:1:.*java_JAVA.*javadir.* undefined' stderr
+$EGREP '(uninitialized|line) ' stderr && exit 1
+
+echo javadir = a-dummy-value >> Makefile.am
+$AUTOMAKE
+
+:
diff --git a/t/javaflags.sh b/t/javaflags.sh
new file mode 100644
index 000000000..1d8e0b7ae
--- /dev/null
+++ b/t/javaflags.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for $(JAVACFLAGS) and $(AM_JAVACFLAGS).
+
+. test-init.sh
+
+cat > fake-javac <<'END'
+#!/bin/sh
+echo "$*" > javaflags.list
+END
+chmod a+x fake-javac
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+# Simulate presence of the java compiler using our fake-javac script.
+AC_SUBST([JAVAC], ['$(abs_top_srcdir)'/fake-javac])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+foodir = $(prefix)
+foo_JAVA = bar.java
+AM_JAVACFLAGS = __am_flags__
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '\$(JAVACFLAGS).*\$(AM_JAVACFLAGS)' Makefile.in && exit 1
+
+: > bar.java
+
+$AUTOCONF
+./configure
+run_make JAVACFLAGS=__user_flags__
+
+ls -l
+
+cat javaflags.list
+grep '__am_flags__.*__user_flags__' javaflags.list
+
+:
diff --git a/t/javaprim.sh b/t/javaprim.sh
new file mode 100644
index 000000000..857e41e8f
--- /dev/null
+++ b/t/javaprim.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure JAVA variable can be defined by AC_SUBST.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([JAVA])
+END
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+java_JAVA = a.java b.java c.java
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep -i java Makefile.in # For debugging.
+grep '^JAVA = *@JAVA@ *$' Makefile.in
+
+:
diff --git a/t/javasubst.sh b/t/javasubst.sh
new file mode 100644
index 000000000..c761a8fae
--- /dev/null
+++ b/t/javasubst.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure redefining JAVAC with AC_SUBST works.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([JAVAC])
+END
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+java_JAVA = a.java b.java c.java
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep -i java Makefile.in # For debugging.
+grep '^JAVAC = *@JAVAC@ *$' Makefile.in
+
+:
diff --git a/t/ldadd.sh b/t/ldadd.sh
new file mode 100644
index 000000000..3083fc381
--- /dev/null
+++ b/t/ldadd.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check to make sure incorrect LDADD usage is diagnosed.
+
+required=libtool
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AC_SUBST([LTLIBOBJS], [q.lo])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libtu.la
+libtu_la_SOURCES = foo.c
+libtu_la_LDADD = @LTLIBOBJS@
+END
+
+: > ltconfig
+: > ltmain.sh
+: > config.guess
+: > config.sub
+: > q.c
+
+$ACLOCAL || exit 1
+AUTOMAKE_fails -Wno-extra-portability
+grep "libtu_la_LDADD" stderr
+grep " use 'libtu_la_LIBADD'" stderr
+
+:
diff --git a/t/ldflags.sh b/t/ldflags.sh
new file mode 100644
index 000000000..68dc553e9
--- /dev/null
+++ b/t/ldflags.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for LDFLAGS in conditional.
+# PR 77.
+
+required=libtool
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_SUBST([LTLIBOBJS], [q.o])
+AM_CONDITIONAL([USE_SWIG], [:])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if USE_SWIG
+lib_LTLIBRARIES = libtu.la
+libtu_la_SOURCES = foo.c
+libtu_la_LDFLAGS = -module
+endif
+END
+
+: > ltconfig
+: > ltmain.sh
+: > ar-lib
+: > config.guess
+: > config.sub
+: > q.c
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/lex-clean-cxx.sh b/t/lex-clean-cxx.sh
new file mode 100644
index 000000000..10749dcc4
--- /dev/null
+++ b/t/lex-clean-cxx.sh
@@ -0,0 +1,126 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that C++ source files derived from non-distributed Lex sources
+# are cleaned by "make clean", while C++ source files derived from
+# distributed Lex sources are cleaned by "make maintainer-clean".
+# See also sister test 'lex-clean.sh'.
+
+required='c++ lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo bar baz qux
+
+foo_SOURCES = mainfoo.cc parsefoo.lxx
+
+bar_SOURCES = mainbar.cpp parsebar.ll
+bar_LFLAGS = $(AM_LFLAGS)
+
+baz_SOURCES = mainbaz.c++
+nodist_baz_SOURCES = parsebaz.l++
+
+qux_SOURCES = mainqux.cxx
+nodist_qux_SOURCES = parsequx.lpp
+qux_LFLAGS = $(AM_LFLAGS)
+
+parsebaz.l++ parsequx.lpp:
+ cp $(srcdir)/parsefoo.lxx $@
+
+CLEANFILES = parsebaz.l++ parsequx.lpp
+
+LDADD = $(LEXLIB)
+END
+
+cat > parsefoo.lxx << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+int isatty (int fd) { return 0; }
+%}
+%%
+"GOOD" return EOF;
+.
+%%
+int yywrap (void)
+{
+ return 1;
+}
+END
+cp parsefoo.lxx parsebar.ll
+
+cat > mainfoo.cc << 'END'
+// This file should contain valid C++ but invalid C.
+using namespace std;
+int main (int argc, char **argv)
+{
+ extern int yylex (void);
+ return yylex ();
+}
+END
+cp mainfoo.cc mainbar.cpp
+cp mainfoo.cc mainbaz.c++
+cp mainfoo.cc mainqux.cxx
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+cp config.status config.sav
+
+$MAKE
+ls -l
+# Sanity checks.
+test -f parsefoo.cxx
+test -f bar-parsebar.cc
+test -f parsebaz.l++
+test -f parsebaz.c++
+test -f parsequx.lpp
+test -f qux-parsequx.cpp
+
+for target in clean distclean; do
+ $MAKE $target
+ ls -l
+ test -f parsefoo.cxx
+ test -f bar-parsebar.cc
+ test ! -e parsebaz.l++
+ test ! -e parsebaz.c++
+ test ! -e parsequx.lpp
+ test ! -e qux-parsequx.cpp
+done
+
+cp config.sav config.status
+./config.status # re-create Makefile
+
+$MAKE maintainer-clean
+ls -l
+test -f parsefoo.lxx
+test -f parsebar.ll
+test ! -e parsefoo.cxx
+test ! -e bar-parsebar.cc
+test -f parsefoo.lxx
+test -f parsebar.ll
+test ! -e parsefoo.cxx
+test ! -e bar-parsebar.cc
+
+:
diff --git a/t/lex-clean.sh b/t/lex-clean.sh
new file mode 100644
index 000000000..c32c2f2da
--- /dev/null
+++ b/t/lex-clean.sh
@@ -0,0 +1,114 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that .c files derived from non-distributed .l sources
+# are cleaned by "make clean", while .c files derived from
+# distributed .l sources are cleaned by "make maintainer-clean".
+# See also sister test 'lex-clean-cxx.sh'.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo bar baz qux
+
+foo_SOURCES = main.c lexer.l
+
+bar_SOURCES = main.c lexer.l
+bar_LFLAGS = $(AM_LFLAGS)
+
+baz_SOURCES = main.c
+nodist_baz_SOURCES = baz.l
+
+qux_SOURCES = main.c
+nodist_qux_SOURCES = baz.l
+qux_LFLAGS = $(AM_LFLAGS)
+
+baz.l:
+ cp $(srcdir)/lexer.l $@
+
+CLEANFILES = baz.l
+
+LDADD = $(LEXLIB)
+END
+
+cat > lexer.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"GOOD" return EOF;
+.
+END
+
+cat > main.c << 'END'
+int main (void)
+{
+ return yylex ();
+}
+
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+ return 1;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+cp config.status config.sav
+
+$MAKE
+ls -l
+# Sanity checks.
+test -f lexer.l
+test -f lexer.c
+test -f bar-lexer.c
+test -f baz.l
+test -f baz.c
+test -f qux-baz.c
+
+for target in clean distclean; do
+ $MAKE $target
+ ls -l
+ test -f lexer.l
+ test -f lexer.c
+ test -f bar-lexer.c
+ test ! -e baz.l
+ test ! -e baz.c
+ test ! -e qux-baz.c
+done
+
+cp config.sav config.status
+./config.status # re-create Makefile
+
+$MAKE maintainer-clean
+ls -l
+test -f lexer.l
+test ! -e lexer.c
+test ! -e bar-lexer.c
+
+:
diff --git a/t/lex-depend-cxx.sh b/t/lex-depend-cxx.sh
new file mode 100644
index 000000000..b9fad4696
--- /dev/null
+++ b/t/lex-depend-cxx.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure dependencies work with Lex/C++.
+# Test synthesized from PR automake/6.
+
+required='c++ lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AM_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = joe moe
+joe_SOURCES = joe.ll
+moe_SOURCES = moe.l++
+LDADD = $(LEXLIB)
+
+.PHONY: test-deps-exist
+test-deps-exist:
+ ls -l $(DEPDIR) ;: For debugging.
+ test -f $(DEPDIR)/joe.Po
+ test -f $(DEPDIR)/moe.Po
+
+.PHONY: test-obj-updated
+test-obj-updated: joe.$(OBJEXT) moe.$(OBJEXT)
+ is_newest joe.$(OBJEXT) my-hdr.hxx
+ is_newest moe.$(OBJEXT) my-hdr.hxx
+END
+
+cat > joe.ll << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+int isatty (int fd) { return 0; }
+%}
+%%
+"foo" return EOF;
+.
+%%
+#include "my-hdr.hxx"
+int yywrap (void)
+{
+ return 1;
+}
+int main (int argc, char **argv)
+{
+ return 0;
+}
+END
+
+cp joe.ll moe.l++
+
+cat > my-hdr.hxx <<'END'
+// This header contains deliberately invalid C (but valid C++).
+using namespace std;
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+$FGREP joe.Po Makefile.in
+$FGREP moe.Po Makefile.in
+
+$AUTOCONF
+# Try to enable dependency tracking if possible, even if that means
+# using slow dependency extractors.
+./configure --enable-dependency-tracking
+
+# For debugging.
+for f in $(find . -name '*.Po'); do
+ cat $f
+done
+
+$MAKE test-deps-exist
+$MAKE
+
+$sleep
+touch my-hdr.hxx
+$MAKE test-obj-updated
+
+:
diff --git a/t/lex-depend-grep.sh b/t/lex-depend-grep.sh
new file mode 100644
index 000000000..a6453bab7
--- /dev/null
+++ b/t/lex-depend-grep.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure dependencies for Lex and C/C++ does not break
+# in obvious ways. See PR automake/6, and related semantic tests
+# 'lex-depend.sh' and 'lex-depend-cxx.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AM_PROG_LEX
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zoo foo
+zoo_SOURCES = joe.ll
+foo_SOURCES = moe.l
+noinst_PROGRAMS = zardoz
+zardoz_SOURCES = _0.l _1.ll _2.lxx _3.l++ _4.lpp
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+$EGREP '([mj]oe|_[01234]|include|\.P)' Makefile.in # For debugging.
+
+for x in joe moe _0 _1 _2 _3 _4; do
+ $EGREP '\$\(DEPDIR\)/'"$x"'\.Po( |$)' Makefile.in
+done
+
+:
diff --git a/t/lex-depend.sh b/t/lex-depend.sh
new file mode 100644
index 000000000..e181af25f
--- /dev/null
+++ b/t/lex-depend.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure automatic dependency tracking work with Lex/C.
+# Test suggested by PR automake/6.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zoo
+zoo_SOURCES = joe.l
+LDADD = $(LEXLIB)
+
+.PHONY: test-deps-exist
+test-deps-exist:
+ ls -l $(DEPDIR) ;: For debugging.
+ test -f $(DEPDIR)/joe.Po
+
+.PHONY: test-obj-updated
+test-obj-updated: joe.$(OBJEXT)
+ is_newest joe.$(OBJEXT) my-hdr.h
+END
+
+cat > joe.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"foo" return EOF;
+.
+%%
+#include "my-hdr.h"
+int main (void)
+{
+ printf("%s\n", MESSAGE);
+ return 0;
+}
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+ return 1;
+}
+END
+
+cat > my-hdr.h <<'END'
+#include <stdio.h>
+#define MESSAGE "Hello, World!"
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+$FGREP joe.Po Makefile.in
+
+$AUTOCONF
+# Try to enable dependency tracking if possible, even if that means
+# using slow dependency extractors.
+./configure --enable-dependency-tracking
+
+$MAKE test-deps-exist
+$MAKE
+cross_compiling || test "$(./zoo)" = 'Hello, World!' || exit 1
+
+$sleep
+cat >> my-hdr.h << 'END'
+#undef MESSAGE
+#define MESSAGE "Howdy, Earth!"
+END
+$MAKE test-obj-updated
+$MAKE
+cross_compiling || test "$(./zoo)" = 'Howdy, Earth!' || exit 1
+
+:
diff --git a/t/lex-header.sh b/t/lex-header.sh
new file mode 100644
index 000000000..d0810c7d3
--- /dev/null
+++ b/t/lex-header.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automake lex support can work with flex '--header-file' option (see
+# bugs #8844 and #9933).
+
+required='cc flex'
+. test-init.sh
+
+# Here, we need to use the use flex option '--header-file', but some
+# older flex versions don't support is (see automake bug#11524 and
+# bug#12836). Skip this test if such an old flex version is detected.
+$LEX --help | grep '.*--header-file' \
+ || skip_ "flex doesn't support the '--header-file' option"
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = lexer.l main.c mylex.h
+foo_LFLAGS = --header-file=mylex.h
+BUILT_SOURCES = mylex.h
+# Recover from removal of header.
+mylex.h: foo-lexer.c
+ test -f $@ || rm -f foo-lexer.c
+ test -f $@ || $(MAKE) $(AM_MAKEFLAGS) foo-lexer.c
+END
+
+cat > lexer.l << 'END'
+%option noyywrap
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"GOOD" return EOF;
+.
+%%
+END
+
+cat > main.c <<'END'
+#define YY_NO_UNISTD_H 1
+#include "mylex.h"
+int main (void)
+{
+ /* We don't use a 'while' loop here (like a real lexer would do)
+ to avoid possible hangs. */
+ if (yylex () == EOF)
+ return 0;
+ else
+ return 1;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+# Program should build and run.
+$MAKE
+if ! cross_compiling; then
+ echo GOOD | ./foo
+ echo BAD | ./foo && exit 1
+ : For shells with busted 'set -e'.
+fi
+
+# Recovering from header removal.
+rm -f mylex.h
+$MAKE
+test -f mylex.h
+
+# Sanity check on distribution.
+yl_distcheck
+
+:
diff --git a/t/lex-lib-external.sh b/t/lex-lib-external.sh
new file mode 100644
index 000000000..902bedc95
--- /dev/null
+++ b/t/lex-lib-external.sh
@@ -0,0 +1,79 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that we can get use the 'yywrap' function from a system-wide
+# library, if that's available.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lexer
+lexer_SOURCES = foo.l
+lexer_LDADD = $(LEXLIB)
+
+.PHONY: have-lexlib
+have-lexlib:
+ test x'$(LEXLIB)' != x
+ echo 'int main (void) { return yywrap (); }' > x.c
+ $(CC) -c x.c
+ $(CC) x.$(OBJEXT) $(LEXLIB)
+ rm -f x.c *.$(OBJEXT) *.o *.out *.exe
+END
+
+cat > foo.l <<'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"GOOD" return EOF;
+.
+%%
+int main (void)
+{
+ /* We don't use a 'while' loop here (like a real lexer would do)
+ to avoid possible hangs. */
+ if (yylex () == EOF)
+ return 0;
+ else
+ return 1;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE have-lexlib || skip_ "no system-wide lex library found"
+
+# Program should build and run and distribute.
+$MAKE all
+if ! cross_compiling; then
+ echo GOOD | ./lexer
+ echo BAD | ./lexer && exit 1
+ : For shells with busted 'set -e'.
+fi
+yl_distcheck
+
+:
diff --git a/t/lex-lib.sh b/t/lex-lib.sh
new file mode 100644
index 000000000..b0bdd904b
--- /dev/null
+++ b/t/lex-lib.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that we can provide a personal 'yywrap' function in a custom
+# library.
+# See also test 'lex-lib-external.sh'.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+LEXLIB=libmylex.a
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lexer
+lexer_SOURCES = foo.l
+lexer_LDADD = $(LEXLIB)
+EXTRA_lexer_DEPENDENCIES = $(LEXLIB)
+noinst_LIBRARIES = libmylex.a
+libmylex_a_SOURCES = mu.c
+END
+
+cat > mu.c << 'END'
+int yywrap (void)
+{
+ return 1;
+}
+END
+
+cat > foo.l <<'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+int main (void)
+{
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+test -f foo.c
+test -f libmylex.a
+
+:
diff --git a/t/lex-libobj.sh b/t/lex-libobj.sh
new file mode 100644
index 000000000..2d4fe5916
--- /dev/null
+++ b/t/lex-libobj.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that we can provide a personal 'yywrap' function through the
+# LIBOBJ machinery.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_PROG_LEX
+save_LIBS=$LIBS
+LIBS="$LEXLIB $LIBS"
+AC_REPLACE_FUNCS([yywrap])
+LIBS=$save_LIBS
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = foo
+foo_SOURCES = foo.l
+foo_LDADD = $(LEXLIB) $(LIBOBJS)
+END
+
+cat > yywrap.c << 'END'
+int yywrap (void)
+{
+ return 1;
+}
+END
+
+cat > foo.l <<'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+int main (void)
+{
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+grep LIBOBJS Makefile # For debugging.
+$MAKE
+$MAKE distclean
+
+# Force "no system lex library". Setting LEXLIB to a non-empty value
+# ensures that configure won't search for a "lex library", and simply
+# rely on the LEXLIB to provide it, if needed. So, by setting LEXLIB
+# to a blank but non-empty value we can fool configure into thinking
+# that no system-level library providing a 'yywrap' function is
+# available. See also discussion on automake bug#11306.
+./configure LEXLIB=' '
+grep LIBOBJS Makefile # For debugging.
+grep '^LIBOBJS *=.*yywrap.*\.o' Makefile # Sanity check.
+$MAKE
+
+yl_distcheck
+
+:
diff --git a/t/lex-line.sh b/t/lex-line.sh
new file mode 100644
index 000000000..d93d0deb0
--- /dev/null
+++ b/t/lex-line.sh
@@ -0,0 +1,135 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake lex support ensures that lex-generated C
+# files use correct "#line" directives. Try also with the
+# 'subdir-object' option enabled.
+# See also sister test 'yacc-line.sh'.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_PROG_CC
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+mkdir dir sub sub/dir
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+bin_PROGRAMS = foo bar
+LDADD = $(LEXLIB)
+bar_LFLAGS = -v
+foo_SOURCES = zardoz.l
+bar_SOURCES = dir/quux.l
+## Avoid spurious failures with Solaris make.
+zardoz.@OBJEXT@: zardoz.c
+bar-quux.@OBJEXT@: bar-quux.c
+END
+
+cat > sub/Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+noinst_PROGRAMS = foo bar
+## We already used $(LEXLIB) above, so try @LEXLIB@ now.
+LDADD = @LEXLIB@
+foo_LFLAGS = -v
+foo_SOURCES = zardoz.l
+bar_SOURCES = dir/quux.l
+## Avoid spurious failures with Solaris make.
+foo-zardoz.@OBJEXT@: foo-zardoz.c
+dir/quux.@OBJEXT@: dir/quux.c
+END
+
+cat > zardoz.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+int main ()
+{
+ while (yylex () != EOF)
+ ;
+ return 0;
+}
+
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+ return 1;
+}
+END
+
+cp zardoz.l dir/quux.l
+cp zardoz.l sub/zardoz.l
+cp zardoz.l sub/dir/quux.l
+
+c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
+
+$ACLOCAL
+$AUTOCONF
+# FIXME: stop disabling the warnings in the 'unsupported' category
+# FIXME: once the 'subdir-objects' option has been mandatory.
+$AUTOMAKE -a -Wno-unsupported
+
+for vpath in : false; do
+
+ if $vpath; then
+ srcdir=..
+ mkdir build
+ cd build
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+ $MAKE
+
+ # For debugging,
+ ls -l . sub sub/dir
+ $EGREP 'line|\.l' $c_outputs
+
+ grep '#.*line.*build.*\.l' $c_outputs && exit 1
+ # Adjusted "#line" should not contain reference to the absolute
+ # srcdir.
+ $EGREP '#.*line *"?/.*\.l' $c_outputs && exit 1
+ # Adjusted "#line" should not contain reference to the default
+ # output file names, e.g., 'lex.yy.c'.
+ grep '#.*line.*lex\.yy' $c_outputs && exit 1
+ # Look out for a silly regression.
+ grep "#.*\.l.*\.l" $c_outputs && exit 1
+ if $vpath; then
+ grep '#.*line.*"\.\./zardoz\.l"' zardoz.c
+ grep '#.*line.*"\.\./dir/quux\.l"' bar-quux.c
+ grep '#.*line.*"\.\./\.\./sub/zardoz\.l"' sub/foo-zardoz.c
+ grep '#.*line.*"\.\./\.\./sub/dir/quux\.l"' sub/dir/quux.c
+ else
+ grep '#.*line.*"zardoz\.l"' zardoz.c
+ grep '#.*line.*"dir/quux\.l"' bar-quux.c
+ grep '#.*line.*"zardoz\.l"' sub/foo-zardoz.c
+ grep '#.*line.*"dir/quux\.l"' sub/dir/quux.c
+ fi
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/lex-multiple.sh b/t/lex-multiple.sh
new file mode 100644
index 000000000..5d6d74c26
--- /dev/null
+++ b/t/lex-multiple.sh
@@ -0,0 +1,107 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that we can build a program using several lexers at once
+# (assuming Flex is used). That is a little tricky, but possible.
+# See:
+# <https://lists.gnu.org/archive/html/automake/2010-10/msg00081.html>
+# <https://lists.gnu.org/archive/html/automake/2009-03/msg00061.html>
+
+required='cc flex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_LEX
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+
+zardoz_SOURCES = main.c
+# Convenience libraries.
+noinst_LIBRARIES = liblex.a liblex-foo.a liblex-bar.a
+zardoz_LDADD = $(noinst_LIBRARIES)
+
+liblex_a_SOURCES = 0.l
+
+# We need the output to always be named 'lex.yy.c', in order for
+# ylwrap to pick it up.
+liblex_foo_a_LFLAGS = -Pfoo -olex.yy.c
+liblex_foo_a_SOURCES = a.l
+
+# Ditto.
+liblex_bar_a_LFLAGS = -Pbar_ -olex.yy.c
+liblex_bar_a_SOURCES = b.l
+END
+
+cat > main.c << 'END'
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main (int argc, char *argv[])
+{
+ if (argc != 2)
+ abort ();
+ else if (!strcmp(argv[1], "--vanilla"))
+ return (yylex () != 121);
+ else if (!strcmp(argv[1], "--foo"))
+ return (foolex () != 121);
+ else if (!strcmp(argv[1], "--bar"))
+ return (bar_lex () != 121);
+ else
+ abort ();
+}
+END
+
+cat > 0.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"VANILLA" { printf (":%s:\n", yytext); return 121; }
+. { printf (":%s:\n", yytext); return 1; }
+%%
+/* Avoid possible link errors. */
+int yywrap (void) { return 1; }
+END
+
+sed 's/VANILLA/FOO/' 0.l > a.l
+sed 's/VANILLA/BAR/' 0.l > b.l
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+$MAKE
+
+if ! cross_compiling; then
+ echo VANILLA | ./zardoz --vanilla
+ echo FOO | ./zardoz --foo
+ echo BAR | ./zardoz --bar
+ ./zardoz --vanilla </dev/null && exit 1
+ echo BAR | ./zardoz --foo && exit 1
+ : For shells with busted 'set -e'.
+fi
+
+yl_distcheck
+
+:
diff --git a/t/lex-nodist.sh b/t/lex-nodist.sh
new file mode 100644
index 000000000..5cadcff0c
--- /dev/null
+++ b/t/lex-nodist.sh
@@ -0,0 +1,90 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Checks for .c files derived from non-distributed .l sources.
+# The test 'lex-pr204.sh' does similar check with AM_MAINTAINER_MODE
+# enabled.
+# The tests 'yacc-nodist.sh' and 'yacc-pr204.sh' does similar checks
+# for yacc-generated .c and .h files.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+dnl Sister test 'lex-pr204.sh' should use 'AC_PROG_LEX' instead.
+AM_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+.PHONY: test-build test-dist
+test-build: all
+ ls -l
+ test -f lexer.l
+ test -f lexer.c
+test-dist: distdir
+ ls -l $(distdir)
+ test ! -r $(distdir)/lexer.l
+ test ! -r $(distdir)/lexer.c
+check-local: test-build test-dist
+
+lexer.l:
+ rm -f $@ $@-t
+ :; { : \
+ && echo '%{' \
+ && echo '#define YY_NO_UNISTD_H 1' \
+ && echo '%}' \
+ && echo '%%' \
+ && echo '"GOOD" return EOF;' \
+ && echo '.'; \
+ } > $@-t
+ chmod a-w $@-t && mv -f $@-t $@
+
+bin_PROGRAMS = prog
+prog_SOURCES = main.c
+nodist_prog_SOURCES = lexer.l
+prog_LDADD = $(LEXLIB)
+CLEANFILES = $(nodist_prog_SOURCES)
+END
+
+cat > main.c << 'END'
+int main ()
+{
+ return yylex ();
+}
+
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+ return 1;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+$MAKE test-build
+$MAKE test-dist
+
+# But the distribution must work correctly, assuming the user has
+# the proper tools to process yacc files.
+$MAKE distcheck
+
+:
diff --git a/t/lex-noyywrap.sh b/t/lex-noyywrap.sh
new file mode 100644
index 000000000..dbbf8590a
--- /dev/null
+++ b/t/lex-noyywrap.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check Lex support with flex using the '%noyywrap' option.
+
+required='cc flex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.l
+
+.PHONY: test-no-lexlib
+check-local: test-no-lexlib
+test-no-lexlib:
+ test x'$(LEXLIB)' = x'none needed'
+END
+
+cat > foo.l << 'END'
+%option noyywrap
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"GOOD" return EOF;
+.
+%%
+int main (void)
+{
+ /* We don't use a 'while' loop here (like a real lexer would do)
+ to avoid possible hangs. */
+ if (yylex () == EOF)
+ return 0;
+ else
+ return 1;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure LEXLIB="none needed"
+
+# Program should build and run.
+$MAKE
+if ! cross_compiling; then
+ echo GOOD | ./foo
+ echo BAD | ./foo && exit 1
+ : For shells with busted 'set -e'.
+fi
+
+# Sanity check on distribution. Escape in LEXLIB must use backspace,
+# not double-quotes, to avoid a spurious failure with AIX make.
+yl_distcheck DISTCHECK_CONFIGURE_FLAGS='LEXLIB=none\ needed'
+
+:
diff --git a/t/lex-pr204.sh b/t/lex-pr204.sh
new file mode 100644
index 000000000..e388353e8
--- /dev/null
+++ b/t/lex-pr204.sh
@@ -0,0 +1,88 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Related to PR 204.
+# C sources derived from nodist_ lex sources should not be distributed.
+# See also related test 'lex-nodist.sh'.
+# The tests 'yacc-nodist.sh' and 'yacc-pr204.sh' does similar checks
+# for yacc-generated .c and .h files.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AM_MAINTAINER_MODE
+AC_PROG_CC
+dnl We use AC_PROG_LEX deliberately.
+dnl Sister 'lex-nodist.sh' should use 'AM_PROG_LEX' instead.
+AC_PROG_LEX
+AC_OUTPUT
+EOF
+
+# The LEXER2 intermediate variable is there to make sure Automake
+# matches 'nodist_' against the right variable name...
+cat > Makefile.am << 'EOF'
+EXTRA_PROGRAMS = foo
+LEXER2 = lexer2.l
+nodist_foo_SOURCES = lexer.l $(LEXER2)
+
+distdirtest: distdir
+ test ! -f $(distdir)/lexer.c
+ test ! -f $(distdir)/lexer.l
+ test ! -f $(distdir)/lexer.h
+ test ! -f $(distdir)/lexer2.c
+ test ! -f $(distdir)/lexer2.l
+ test ! -f $(distdir)/lexer2.h
+EOF
+
+cat > lexer.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"GOOD" return EOF;
+.
+%%
+int main (void)
+{
+ return yylex ();
+}
+END
+
+cp lexer.l lexer2.l
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE distdirtest
+
+# Make sure lexer.c and lexer2.c are still targets.
+$MAKE lexer.c lexer2.c
+test -f lexer.c
+test -f lexer2.c
+
+# Ensure the rebuild rule works despite AM_MAINTAINER_MODE, because
+# it's a nodist_ lexer.
+$sleep
+touch lexer.l lexer2.l
+$sleep
+$MAKE lexer.c lexer2.c
+is_newest lexer.c lexer.l
+is_newest lexer2.c lexer2.l
+
+:
diff --git a/t/lex-subobj-nodep.sh b/t/lex-subobj-nodep.sh
new file mode 100644
index 000000000..4f79ce047
--- /dev/null
+++ b/t/lex-subobj-nodep.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure subdirs for subdir scanners are generated when subdir-objects
+# are used, even when dependency tracking is disabled.
+
+required='cc lex'
+. test-init.sh
+
+cat >>configure.ac <<\END
+AC_PROG_CC
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+cat >Makefile.am <<\END
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = p1 p2
+p1_SOURCES = sub1/s1.l
+p2_SOURCES = sub2/s2.l
+p2_CPPFLAGS = -DWHATEVER
+END
+
+mkdir sub1 sub2
+
+cat >sub1/s1.l <<\END
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+int main (void)
+{
+ while (yylex () != EOF)
+ ;
+ return 0;
+}
+
+int yywrap(void)
+{
+ return 1;
+}
+END
+
+cp sub1/s1.l sub2/s2.l
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+mkdir build
+cd build
+../configure --disable-dependency-tracking
+$MAKE sub1/s1.c
+$MAKE sub2/s2.c
+rm -rf sub1 sub2
+$MAKE
+
+:
diff --git a/t/lex.sh b/t/lex.sh
new file mode 100644
index 000000000..94b11bc9c
--- /dev/null
+++ b/t/lex.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_LEX
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zot
+zot_SOURCES = joe.l
+LDADD = @LEXLIB@
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+# Test to make sure that lex source generates correct target.
+$FGREP '$(LEX)' Makefile.in
+
+# Test to make sure that lex source generates correct clean rule.
+# From Ralf Corsepius.
+$FGREP joel Makefile.in && exit 1
+
+:
diff --git a/t/lex2.sh b/t/lex2.sh
new file mode 100644
index 000000000..e9c4665bf
--- /dev/null
+++ b/t/lex2.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that Automake suggest using AM_PROG_LEX when a lexer is used.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zot
+zot_SOURCES = joe.l
+END
+
+$ACLOCAL
+AUTOMAKE_fails -a
+grep 'LEX.* undefined' stderr
+grep 'add .*AM_PROG_LEX' stderr
+
+:
diff --git a/t/lex3.sh b/t/lex3.sh
new file mode 100644
index 000000000..9f1737a78
--- /dev/null
+++ b/t/lex3.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic semantic checks on Lex support.
+# Test associated with PR 19.
+# From Matthew D. Langston.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = foo
+foo_SOURCES = foo.l
+END
+
+cat > foo.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"GOOD" return EOF;
+.
+%%
+
+int main (void)
+{
+ /* We don't use a 'while' loop here (like a real lexer would do)
+ to avoid possible hangs. */
+ if (yylex () == EOF)
+ return 0;
+ else
+ return 1;
+}
+
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+ return 1;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+# Program should build and run.
+$MAKE
+if ! cross_compiling; then
+ echo GOOD | ./foo
+ echo BAD | ./foo && exit 1
+ : For shells with busted 'set -e'.
+fi
+
+# The generated file 'foo.c' must be shipped.
+$MAKE distdir
+test -f $distdir/foo.c
+
+# Sanity check on distribution.
+yl_distcheck
+
+# While we are at it, make sure that foo.c is erased by
+# maintainer-clean, and not by distclean.
+test -f foo.c
+$MAKE distclean
+test -f foo.c
+./configure # Re-create 'Makefile'.
+$MAKE maintainer-clean
+test ! -e foo.c
+
+:
diff --git a/t/lex5.sh b/t/lex5.sh
new file mode 100644
index 000000000..ed20ef76f
--- /dev/null
+++ b/t/lex5.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for subdir lexers.
+
+required='cc lex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+LDADD = @LEXLIB@
+
+bin_PROGRAMS = foo/foo
+foo_foo_SOURCES = foo/foo.l
+END
+
+mkdir foo
+
+cat > foo/foo.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+int
+main ()
+{
+ while (yylex () != EOF)
+ ;
+
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# We expect ylwrap to be used and distributed even if there is
+# only one lexer.
+test -f ylwrap
+
+mkdir sub
+cd sub
+../configure
+$MAKE foo/foo.o
+ls -l # For debugging.
+
+test -f foo/foo.c
+test -f foo/foo.o
+
+# Now, adds another lexer to test ylwrap.
+
+cd ..
+cp foo/foo.l foo/foo2.l
+cat >> Makefile.am << 'END'
+EXTRA_foo_foo_SOURCES = foo/foo2.l
+END
+
+# Make sure Makefile.in has a new time stamp: the rebuild rules are
+# used below. We do this after updating Makefile.am, that way we can
+# ensure that automake, even with --no-force, is not confused if the
+# new Makefile.am has the same time stamp as the older one (since the
+# output will change, --no-force should have no effect).
+$sleep
+
+$AUTOMAKE -a --no-force
+
+cd sub
+using_gmake || $MAKE Makefile
+$MAKE foo/foo2.o
+ls -l # For debugging.
+test -f foo/foo2.c
+test -f foo/foo2.o
+
+:
diff --git a/t/lexcpp.sh b/t/lexcpp.sh
new file mode 100644
index 000000000..a639b964b
--- /dev/null
+++ b/t/lexcpp.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure Lex + C++ is supported.
+# Please keep this is sync with sister test 'yaccpp.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_PROG_LEX
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo bar baz qux
+foo_SOURCES = foo.l++
+bar_SOURCES = bar.lpp
+baz_SOURCES = baz.ll
+qux_SOURCES = qux.lxx
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+sed -e 's/^/ /' -e 's/$/ /' Makefile.in >mk
+$FGREP ' foo.c++ ' mk
+$FGREP ' bar.cpp ' mk
+$FGREP ' baz.cc ' mk
+$FGREP ' qux.cxx ' mk
+
+:
diff --git a/t/lexvpath.sh b/t/lexvpath.sh
new file mode 100644
index 000000000..927d655ec
--- /dev/null
+++ b/t/lexvpath.sh
@@ -0,0 +1,128 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# This test checks that dependent files are updated before including
+# in the distribution. 'lexer.c' depends on 'lexer.l'. The latter is
+# updated so that 'lexer.c' should be rebuild. Then we are running
+# 'make' and 'make distdir' and check whether the version of 'lexer.c'
+# to be distributed is up to date.
+
+# Please keep this in sync with sister test 'yaccvapth.sh'.
+
+required='cc lex'
+. test-init.sh
+
+cat > lexoutroot.in << 'END'
+LEX_OUTPUT_ROOT='@LEX_OUTPUT_ROOT@'
+END
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([lexoutroot])
+AC_PROG_CC
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = lexer.l foo.c
+LDADD = $(LEXLIB)
+END
+
+# Original lexer, with a "foobar" comment
+cat > lexer.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+/*foobar*/
+END
+
+cat > foo.c << 'END'
+int main (void)
+{
+ return 0;
+}
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+ return 1;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkdir sub
+
+# We must run configure early, to find out why $LEX_OUTPUT_ROOT is.
+cd sub
+../configure
+. ./lexoutroot
+test -n "$LEX_OUTPUT_ROOT" # Sanity check.
+cd ..
+
+$LEX lexer.l
+mv "$LEX_OUTPUT_ROOT".c lexer.c
+
+cd sub
+
+# Ensure that lexer.l will be newer than lexer.c.
+$sleep
+
+# New lexer, with 'fubar' comment.
+cat > ../lexer.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+/*fubar*/
+END
+
+$MAKE
+$MAKE distdir
+$FGREP '/*fubar*/' $distdir/lexer.c
+
+#
+# Now check to make sure that 'make dist' will rebuilt the parser.
+#
+
+# Ensure that lexer.l will be newer than lexer.c.
+$sleep
+
+# New lexer, with 'maude' comment.
+cat > ../lexer.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+/*maude*/
+END
+
+$MAKE distdir
+$FGREP '/*maude*/' $distdir/lexer.c
+
+:
diff --git a/t/lflags-cxx.sh b/t/lflags-cxx.sh
new file mode 100644
index 000000000..72231e722
--- /dev/null
+++ b/t/lflags-cxx.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that $(LFLAGS) takes precedence over both $(AM_LFLAGS) and
+# $(foo_LFLAGS). This is the C++ case.
+# Please keep this in sync with the sister tests:
+# - lflags.sh
+# - yflags.sh
+# - yflags-cxx.sh
+
+. test-init.sh
+
+cat >fake-lex <<'END'
+#!/bin/sh
+echo '/*' "$*" '*/' >lex.yy.c
+echo 'extern int dummy;' >> lex.yy.c
+END
+chmod a+x fake-lex
+
+cat >> configure.ac <<'END'
+AC_SUBST([CXX], [false])
+# Simulate presence of Lex using our fake-lex script.
+AC_SUBST([LEX], ['$(abs_top_srcdir)'/fake-lex])
+AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
+AC_SUBST([LEXLIB], [''])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = no-dependencies
+bin_PROGRAMS = foo bar
+foo_SOURCES = main.cc foo.ll
+bar_SOURCES = main.cc bar.l++
+AM_LFLAGS = __am_flags__
+bar_LFLAGS = __bar_flags__
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+grep '\$(LFLAGS).*\$(bar_LFLAGS)' Makefile.in && exit 1
+grep '\$(LFLAGS).*\$(AM_LFLAGS)' Makefile.in && exit 1
+
+: > foo.ll
+: > bar.l++
+
+$AUTOCONF
+./configure
+run_make LFLAGS=__user_flags__ foo.cc bar-bar.c++
+
+cat foo.cc
+cat bar-bar.c++
+
+grep '__am_flags__.*__user_flags__' foo.cc
+grep '__bar_flags__.*__user_flags__' bar-bar.c++
+
+:
diff --git a/t/lflags.sh b/t/lflags.sh
new file mode 100644
index 000000000..fefd9cc55
--- /dev/null
+++ b/t/lflags.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that $(LFLAGS) takes precedence over both $(AM_LFLAGS) and
+# $(foo_LFLAGS).
+# Please keep this in sync with the sister tests:
+# - lflags-cxx.sh
+# - yflags.sh
+# - yflags-cxx.sh
+
+required=cc
+. test-init.sh
+
+cat >fake-lex <<'END'
+#!/bin/sh
+echo '/*' "$*" '*/' >lex.yy.c
+echo 'extern int dummy;' >> lex.yy.c
+END
+chmod a+x fake-lex
+
+cat >> configure.ac <<'END'
+AC_SUBST([CC], [false])
+# Simulate presence of Lex using our fake-lex script.
+AC_SUBST([LEX], ['$(abs_top_srcdir)'/fake-lex])
+AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
+AC_SUBST([LEXLIB], [''])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = no-dependencies
+bin_PROGRAMS = foo bar
+foo_SOURCES = main.c foo.l
+bar_SOURCES = main.c bar.l
+AM_LFLAGS = __am_flags__
+bar_LFLAGS = __bar_flags__
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+grep '\$(LFLAGS).*\$(bar_LFLAGS)' Makefile.in && exit 1
+grep '\$(LFLAGS).*\$(AM_LFLAGS)' Makefile.in && exit 1
+
+: > foo.l
+: > bar.l
+
+$AUTOCONF
+./configure
+run_make LFLAGS=__user_flags__ foo.c bar-bar.c
+
+cat foo.c
+cat bar-bar.c
+
+grep '__am_flags__.*__user_flags__' foo.c
+grep '__bar_flags__.*__user_flags__' bar-bar.c
+
+:
diff --git a/t/libexec.sh b/t/libexec.sh
new file mode 100644
index 000000000..fdb63ae7b
--- /dev/null
+++ b/t/libexec.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# PROGRAMS and LIBRARIES can be installed in (pkg)libexecdir.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+libexec_PROGRAMS = foo
+pkglibexec_PROGRAMS = bar
+END
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+: > foo.c
+: > bar.c
+
+$ACLOCAL
+$AUTOMAKE
diff --git a/t/libobj-basic.sh b/t/libobj-basic.sh
new file mode 100644
index 000000000..686888d22
--- /dev/null
+++ b/t/libobj-basic.sh
@@ -0,0 +1,112 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure AC_LIBSOURCE and AC_LIBSOURCES work.
+
+required=cc
+. test-init.sh
+
+mv configure.ac configure.proto
+cat >> configure.proto << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES = foo.c
+libtu_a_LIBADD = $(LIBOBJS)
+
+include extra-checks.am
+.PHONY: $(extra_checks) pre-test
+
+pre-test: distdir
+ ls -l $(srcdir) $(builddir) $(distdir)
+ $(AR) tv libtu.a
+$(extra_checks): pre-test
+check-local: $(extra_checks)
+
+maude-src:
+ grep dummy_maude $(srcdir)/maude.c
+maude-dist:
+ grep dummy_maude $(distdir)/maude.c
+liver-src:
+ grep dummy_liver $(srcdir)/liver.c
+liver-dist:
+ grep dummy_liver $(distdir)/liver.c
+liver-not-dist:
+ test -d $(distdir)
+ test ! -r $(distdir)/liver.c
+maude-not-dist:
+ test -d $(distdir)
+ test ! -r $(distdir)/maude.c
+END
+
+cat > foo.c << 'END'
+extern int dummy_foo;
+END
+
+cat > maude.c << 'END'
+extern int dummy_maude;
+END
+
+cat > liver.c << 'END'
+extern int dummy_liver;
+END
+
+# AC_LIBSOURCE should work also if called after AC_OUTPUT.
+cat configure.proto - > configure.ac <<END
+AC_LIBSOURCE([maude.c])
+END
+
+cat > extra-checks.am << 'END'
+extra_checks = maude-src maude-dist liver-not-dist
+END
+
+cp "$am_scriptdir/ar-lib" . || fatal_ "fetching auxiliary script 'ar-lib'"
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+$MAKE distclean
+# Avoid timestamp-related differences.
+rm -rf autom4te*.cache
+
+cat > extra-checks.am << 'END'
+extra_checks = maude-src maude-dist liver-src liver-dist
+END
+
+# AC_LIBSOURCES should work also if called after AC_OUTPUT.
+cat configure.proto - > configure.ac <<END
+AC_LIBSOURCES([maude.c, liver.c])
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/libobj-no-dependency-tracking.sh b/t/libobj-no-dependency-tracking.sh
new file mode 100644
index 000000000..793b56f9e
--- /dev/null
+++ b/t/libobj-no-dependency-tracking.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure that LIBOBJS source files are properly built without dependency
+# tracking when using out of tree builds.
+#
+# This is a non regression test which is following an issue in flex-2.6.4 when
+# "malloc.o" was required, see <https://github.com/westes/flex/issues/244>.
+
+. test-init.sh
+
+# The LIBOBJS are in a separate LIBOBJ_DIR directory without anything else in
+# it to not trigger the creation of the build directory accidentally.
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_CONFIG_LIBOBJ_DIR([foo])
+AC_LIBOBJ([foo])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = helldl
+LDADD = $(LIBOBJS)
+.PHONY: dummy
+dummy: $(LIBOBJS)
+END
+
+mkdir foo
+cat > foo/foo.c << 'END'
+int foo() { return 0; }
+END
+
+mkdir build
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cd build
+../configure --disable-dependency-tracking
+run_make dummy
+:
diff --git a/t/libobj10.sh b/t/libobj10.sh
new file mode 100644
index 000000000..5c10e4aa0
--- /dev/null
+++ b/t/libobj10.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Do not complain about the nonexistence of a source for LIBOBJS if
+# it's in BUILT_SOURCES. Reported by Erez Zadok.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_LIBOBJ([foo])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libfoo.a
+libfoo_a_SOURCES =
+libfoo_a_LIBADD = $(LIBOBJS)
+BUILT_SOURCES = foo.c
+CLEANFILES = foo.c
+foo.c:
+ echo 'extern int dummy;' > $@
+.PHONY: debugging
+debugging:
+ $(AR) t libfoo.a
+END
+
+cp "$am_scriptdir/ar-lib" . || fatal_ "fetching auxiliary script 'ar-lib'"
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE
+$MAKE debugging
+$MAKE distcheck
+
+:
diff --git a/t/libobj12.sh b/t/libobj12.sh
new file mode 100644
index 000000000..6b1a537b5
--- /dev/null
+++ b/t/libobj12.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test if a file can be mentioned in LIBOBJS and explicitly.
+# (See libobj13.sh for the LTLIBRARIES check.)
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_LIBOBJ([foo])
+AC_LIBOBJ([bar])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libfoo.a libbar.a
+noinst_PROGRAMS = p1 p2
+
+libfoo_a_SOURCES =
+libfoo_a_LIBADD = @LIBOBJS@
+
+libbar_a_SOURCES = foo.c
+
+p1_SOURCES =
+p1_LDADD = @LIBOBJS@
+
+p2_SOURCES = bar.c
+END
+
+: > ar-lib
+: > foo.c
+: > bar.c
+
+$ACLOCAL
+
+# This however should be diagnosed, since foo.c and bar.c are in @LIBOBJS@.
+cat >> Makefile.am << 'END'
+libfoo_a_SOURCES += foo.c
+p1_SOURCES += bar.c
+END
+
+AUTOMAKE_fails
+grep 'foo\.c.*explicitly mentioned' stderr
+grep 'bar\.c.*explicitly mentioned' stderr
+
+# Global 'LDADD' can also come into play.
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = a b
+LDADD = @LIBOBJS@
+END
+
+$AUTOMAKE
+grep 'a_DEPENDENCIES.*LIBOBJS' Makefile.in
+
+cat >> Makefile.am << 'END'
+a_SOURCES = foo.c
+END
+AUTOMAKE_fails
+grep 'foo\.c.*explicitly mentioned' stderr
+
+:
diff --git a/t/libobj13.sh b/t/libobj13.sh
new file mode 100644
index 000000000..8483f1553
--- /dev/null
+++ b/t/libobj13.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test if a file can be mentioned in LTLIBOBJS and explicitly.
+# (Like libobj12.sh, but for Libtool libraries.)
+
+required='libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_LIBOBJ([foo])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LTLIBRARIES = libfoo.la libbar.la
+
+libfoo_la_SOURCES =
+libfoo_la_LIBADD = @LTLIBOBJS@
+
+libbar_la_SOURCES = foo.c
+END
+
+: > foo.c
+
+$ACLOCAL
+: > ltmain.sh
+$AUTOMAKE --add-missing
+
+# This however should be diagnosed, since foo.c is in @LIBOBJS@.
+echo 'libfoo_la_SOURCES += foo.c' >> Makefile.am
+AUTOMAKE_fails
+grep 'foo\.c.*explicitly mentioned' stderr
+
+:
diff --git a/t/libobj14.sh b/t/libobj14.sh
new file mode 100644
index 000000000..10f101ed8
--- /dev/null
+++ b/t/libobj14.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for an internal error when @LIBOBJS@ is used in
+# a variable that is not defined in the same conditions as the _LDADD
+# that uses it.
+# Report from Bill Davidson.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AC_PROG_CC
+AC_LIBSOURCE([bar.c])
+AM_CONDITIONAL([CASE], [:])
+AC_OUTPUT
+EOF
+
+: >bar.c
+
+cat >>Makefile.am <<'EOF'
+COMMON_LIBS = @LIBOBJS@
+bin_PROGRAMS = foo
+if ! CASE
+foo_LDADD = $(COMMON_LIBS)
+endif
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/libobj15a.sh b/t/libobj15a.sh
new file mode 100644
index 000000000..28f0552ca
--- /dev/null
+++ b/t/libobj15a.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Nonexistent sources for AC_LIBOBJ should cause an Automake failure.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_LIBOBJ([foobar])
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+END
+
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'configure\.ac:.*required file.*foobar\.c.*' stderr
+
+:
diff --git a/t/libobj15b.sh b/t/libobj15b.sh
new file mode 100644
index 000000000..4f939eec6
--- /dev/null
+++ b/t/libobj15b.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Nonexistent source for AC_LIBSOURCE should cause Automake to fail.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_LIBSOURCE([foobar.c])
+# NOTE: this call to AC_OUTPUT is really needed; see Automake bug #7635
+# <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=7635>
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+END
+
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'configure\.ac:.*required file.*foobar\.c.*' stderr
+
+:
diff --git a/t/libobj15c.sh b/t/libobj15c.sh
new file mode 100644
index 000000000..b03451335
--- /dev/null
+++ b/t/libobj15c.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Nonexistent sources for AC_LIBSOURCES should cause Automake to fail.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_LIBSOURCES([foobar.c, bazquux.c])
+# NOTE: this call to AC_OUTPUT is really needed; see Automake bug #7635
+# <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=7635>
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+END
+
+# Don't trip on errors due to missing 'AM_PROG_AR'.
+AUTOMAKE="$AUTOMAKE -Wno-extra-portability"
+
+$ACLOCAL
+
+AUTOMAKE_fails
+grep 'configure\.ac:.*required file.*foobar\.c.*' stderr
+grep 'configure\.ac:.*required file.*bazquux\.c.*' stderr
+
+: > foobar.c
+AUTOMAKE_fails
+grep 'configure\.ac:.*required file.*bazquux\.c.*' stderr
+grep 'foobar\.c' stderr && exit 1
+
+:
diff --git a/t/libobj16a.sh b/t/libobj16a.sh
new file mode 100644
index 000000000..dcd46666f
--- /dev/null
+++ b/t/libobj16a.sh
@@ -0,0 +1,139 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure AC_LIBOBJ and friends work.
+# Please keep this in sync with sister test 'libobj16b.sh'.
+
+required=cc
+. test-init.sh
+
+mv configure.ac configure.proto
+cat >> configure.proto << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+%LIBOBJ-STUFF% # Will be activated later.
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+
+include extra-checks.am
+.PHONY: $(extra_checks) pre-test
+
+pre-test: distdir
+ ls -l $(srcdir) $(builddir) $(distdir)
+ $(AR) tv libtu.a
+$(extra_checks): pre-test
+check-local: $(extra_checks)
+
+maude-src:
+ grep dummy_maude $(srcdir)/maude.c
+maude-dist:
+ grep dummy_maude $(distdir)/maude.c
+liver-src:
+ grep dummy_liver $(srcdir)/liver.c
+liver-dist:
+ grep dummy_liver $(distdir)/liver.c
+liver-not-dist: distdir
+ test ! -r $(distdir)/liver.c
+maude-not-dist: distdir
+ test ! -r $(distdir)/maude.c
+maude-lib:
+ $(AR) t libtu.a | grep maude
+maude-not-lib:
+ $(AR) t libtu.a | grep maude && exit 1; exit 0
+liver-lib:
+ $(AR) t libtu.a | grep liver
+liver-not-lib:
+ $(AR) t libtu.a | grep liver && exit 1; exit 0
+END
+
+cat > maude.c << 'END'
+extern int dummy_maude;
+END
+
+cat > liver.c << 'END'
+extern int dummy_liver;
+END
+
+sed '/%LIBOBJ-STUFF%/{
+s/.*//
+i\
+AC_LIBOBJ([maude])
+}' configure.proto > configure.ac
+cat configure.ac # For debugging.
+
+cat > extra-checks.am << 'END'
+extra_checks = maude-src maude-dist maude-lib liver-not-dist
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE
+$MAKE check
+$MAKE distcheck
+$MAKE distclean
+
+# Avoid timestamp-related differences.
+rm -rf autom4te*.cache
+
+cat > extra-checks.am << 'END'
+extra_checks = maude-src maude-dist liver-src liver-dist
+if MAUDE_COND
+extra_checks += maude-lib liver-not-lib
+else
+extra_checks += maude-not-lib liver-lib
+endif
+END
+
+sed '/%LIBOBJ-STUFF%/{
+s/.*//
+i\
+AM_CONDITIONAL([MAUDE_COND], [test x"$MAUDE" = x"yes"])\
+if test x"$MAUDE" = x"yes"; then\
+ AC_LIBOBJ([maude])\
+else\
+ AC_LIBOBJ([liver])\
+fi\
+AC_LIBSOURCES([maude.c, liver.c])
+}' configure.proto > configure.ac
+cat configure.ac # For debugging.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure MAUDE=yes
+$MAKE
+$MAKE check
+$MAKE distcheck
+$MAKE distclean
+
+./configure MAUDE=no
+$MAKE
+$MAKE check
+$MAKE distcheck
+$MAKE distclean
+
+:
diff --git a/t/libobj16b.sh b/t/libobj16b.sh
new file mode 100644
index 000000000..be1d32829
--- /dev/null
+++ b/t/libobj16b.sh
@@ -0,0 +1,140 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure AC_LIBOBJ and friends work.
+# Please keep this in sync with sister test 'libobj16a.sh'.
+
+required=cc
+. test-init.sh
+
+mv configure.ac configure.proto
+cat >> configure.proto << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+%LIBOBJ-STUFF% # Will be activated later.
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = @LIBOBJS@
+
+include extra-checks.am
+.PHONY: $(extra_checks) pre-test
+
+pre-test: distdir
+ ls -l $(srcdir) $(builddir) $(distdir)
+ $(AR) tv libtu.a
+$(extra_checks): pre-test
+check-local: $(extra_checks)
+
+maude-src:
+ grep dummy_maude $(srcdir)/maude.c
+maude-dist:
+ grep dummy_maude $(distdir)/maude.c
+liver-src:
+ grep dummy_liver $(srcdir)/liver.c
+liver-dist:
+ grep dummy_liver $(distdir)/liver.c
+liver-not-dist: distdir
+ test ! -r $(distdir)/liver.c
+maude-not-dist: distdir
+ test ! -r $(distdir)/maude.c
+maude-lib:
+ $(AR) t libtu.a | grep maude
+maude-not-lib:
+ $(AR) t libtu.a | grep maude && exit 1; exit 0
+liver-lib:
+ $(AR) t libtu.a | grep liver
+liver-not-lib:
+ $(AR) t libtu.a | grep liver && exit 1; exit 0
+END
+
+cat > maude.c << 'END'
+extern int dummy_maude;
+END
+
+cat > liver.c << 'END'
+extern int dummy_liver;
+END
+
+sed '/%LIBOBJ-STUFF%/{
+s/.*//
+i\
+AC_LIBOBJ(maude) dnl: do not quote this!
+}' configure.proto > configure.ac
+cat configure.ac # For debugging.
+
+cat > extra-checks.am << 'END'
+extra_checks = maude-src maude-dist maude-lib liver-not-dist
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE
+$MAKE check
+$MAKE distcheck
+$MAKE distclean
+
+# Avoid timestamp-related differences.
+rm -rf autom4te*.cache
+
+cat > extra-checks.am << 'END'
+extra_checks = maude-src maude-dist liver-src liver-dist
+if MAUDE_COND
+extra_checks += maude-lib liver-not-lib
+else
+extra_checks += maude-not-lib liver-lib
+endif
+END
+
+sed '/%LIBOBJ-STUFF%/{
+s/.*//
+i\
+AM_CONDITIONAL([MAUDE_COND], [test x"$MAUDE" = x"yes"])\
+if test x"$MAUDE" = x"yes"; then\
+ AC_LIBOBJ(maude) dnl: do not quote this!\
+else\
+ AC_LIBOBJ(liver) dnl: do not quote this!\
+fi\
+AC_LIBSOURCE(maude.c) dnl: do not quote this!\
+AC_LIBSOURCE(liver.c) dnl: do not quote this!
+}' configure.proto > configure.ac
+cat configure.ac # For debugging.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure MAUDE=yes
+$MAKE
+$MAKE check
+$MAKE distcheck
+$MAKE distclean
+
+./configure MAUDE=no
+$MAKE
+$MAKE check
+$MAKE distcheck
+$MAKE distclean
+
+:
diff --git a/t/libobj17.sh b/t/libobj17.sh
new file mode 100644
index 000000000..85e84d597
--- /dev/null
+++ b/t/libobj17.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure AC_LIBOBJ accept non-literal arguments.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AM_PROG_AR
+foo=${FOO-oops}
+AC_LIBSOURCES([quux.c, zardoz.c])
+AC_LIBOBJ([$foo])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+.PHONY: check-quux check-zardoz
+check-quux:
+ $(AR) t libtu.a | grep quux
+ $(AR) t libtu.a | grep zardoz && exit 1; exit 0
+check-zardoz:
+ $(AR) t libtu.a | grep zardoz
+ $(AR) t libtu.a | grep quux && exit 1; exit 0
+END
+
+cat > quux.c <<'END'
+extern int dummy;
+END
+
+cat > zardoz.c <<'END'
+extern int dummy;
+END
+
+# These might print warnings, but should not error out.
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+./configure FOO=quux
+$MAKE
+ls -l # For debugging.
+test -f libtu.a
+$MAKE check-quux
+
+$MAKE distclean
+
+./configure FOO=zardoz
+$MAKE
+ls -l # For debugging.
+test -f libtu.a
+$MAKE check-zardoz
+
+:
diff --git a/t/libobj18.sh b/t/libobj18.sh
new file mode 100644
index 000000000..c920b071b
--- /dev/null
+++ b/t/libobj18.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure AC_LIBSOURCE and AC_LIBSOURCES use arguments literally.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+foo=dummy bar=dummy baz=dummy
+AC_LIBSOURCE([$foo.c])
+AC_LIBSOURCES([$bar.c, $baz.c])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+END
+
+: > dummy.c
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'configure\.ac:.*required file.*\$foo\.c.*not found' stderr
+grep 'configure\.ac:.*required file.*\$bar\.c.*not found' stderr
+grep 'configure\.ac:.*required file.*\$baz\.c.*not found' stderr
+
+:
diff --git a/t/libobj19.sh b/t/libobj19.sh
new file mode 100644
index 000000000..21ce31e50
--- /dev/null
+++ b/t/libobj19.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test support for AC_CONFIG_LIBOBJ_DIR.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_LIBOBJ_DIR([libobj-dir])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_LIBOBJ([foobar])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+## Hack with this variable ans with extra make recursion in the check-local
+## rule are required for when we move this Makefile in a subdir, later.
+my_distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)
+check-local:
+ (cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) distdir)
+ ls -l $(top_srcdir)/* $(top_builddir)/* $(my_distdir)/*
+ test -f libtu.a
+ test ! -r $(top_srcdir)/foobar.c
+ test -f $(top_srcdir)/libobj-dir/foobar.c
+ test ! -r $(my_distdir)/foobar.c
+ test -f $(my_distdir)/libobj-dir/foobar.c
+ $(AR) t libtu.a
+ $(AR) t libtu.a | grep foobar
+END
+
+mkdir libobj-dir
+cat > libobj-dir/foobar.c << 'END'
+extern int dummy;
+END
+
+cp "$am_scriptdir/ar-lib" . || fatal_ "fetching auxiliary script 'ar-lib'"
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE
+$MAKE check
+$MAKE distcheck
+
+# Same check, but with the Makefile.am using $(LIBOBJS) not being
+# the top-level one.
+
+$MAKE distclean
+rm -rf autom4te*.cache aclocal.m4 configure
+
+mkdir sub
+mv -f Makefile.am sub
+echo SUBDIRS = sub > Makefile.am
+
+sed '/^AC_OUTPUT/i\
+AC_CONFIG_FILES([sub/Makefile])
+' configure.ac > t
+mv -f t configure.ac
+cat configure.ac # For debugging.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/libobj2.sh b/t/libobj2.sh
new file mode 100644
index 000000000..c52ae31a5
--- /dev/null
+++ b/t/libobj2.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure LIBOBJS works in subdirs.
+# Bug from Josh MacDonald.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([subdir/Makefile])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_CHECK_TOOLS([AR], [ar])
+AC_LIBOBJ([fsusage])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = subdir
+check-local: distdir
+ ls -l $(srcdir) $(srcdir)/subdir
+ ls -l $(distdir) $(distdir)/subdir
+ ls -l $(builddir) $(builddir)/subdir
+ test -f $(srcdir)/subdir/fsusage.c
+ test -f $(distdir)/subdir/fsusage.c
+ $(AR) tv $(builddir)/subdir/libtu.a
+END
+
+mkdir subdir
+
+cat > subdir/Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = @LIBOBJS@
+END
+
+cat > subdir/fsusage.c << 'END'
+extern int dummy;
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# Older grepping check, kept "just to be sure".
+$FGREP 'fsusage.c' subdir/Makefile.in
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/libobj20a.sh b/t/libobj20a.sh
new file mode 100644
index 000000000..b07a6bb3c
--- /dev/null
+++ b/t/libobj20a.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test error reporting for AC_CONFIG_LIBOBJ_DIR.
+# See also sister tests 'libobj20b.sh' and 'libobj20c.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_LIBOBJ_DIR([libobj-dir])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_LIBOBJ([foo])
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+END
+
+mkdir libobj-dir
+: > libobj-dir/foo.c
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'LIBOBJS.*used outside.*libobj-dir' stderr
+grep 'subdir-objects.*not set' stderr
+
+:
diff --git a/t/libobj20b.sh b/t/libobj20b.sh
new file mode 100644
index 000000000..3a466bf07
--- /dev/null
+++ b/t/libobj20b.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test error reporting for AC_CONFIG_LIBOBJ_DIR.
+# See also sister tests 'libobj20a.sh' and 'libobj20c.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_LIBOBJ_DIR([libobj-dir])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_LIBSOURCE([foobar.c])
+# NOTE: this call to AC_OUTPUT is really needed; see Automake bug #7635
+# <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=7635>
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+END
+
+: > ar-lib
+
+$ACLOCAL
+
+AUTOMAKE_fails
+grep 'configure\.ac:.*required directory.*libobj-dir' stderr
+
+mkdir libobj-dir
+: > foobar.c # Oops, it should be in libobj-dir!
+AUTOMAKE_fails
+grep 'configure\.ac:.*required file.*libobj-dir/foobar.c.*' stderr
+
+rm -f foobar.c
+
+: > libobj-dir/foobar.c
+$AUTOMAKE # Now we should succeed.
+
+:
diff --git a/t/libobj20c.sh b/t/libobj20c.sh
new file mode 100644
index 000000000..b12eea618
--- /dev/null
+++ b/t/libobj20c.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test error reporting for AC_CONFIG_LIBOBJ_DIR.
+# See also sister tests 'libobj20a.sh' and 'libobj20b.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_LIBOBJ_DIR([libobj-dir])
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_LIBOBJ([foobar])
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = $(LIBOBJS)
+END
+
+$ACLOCAL
+
+# Don't trip on errors due to missing 'AM_PROG_AR'.
+AUTOMAKE="$AUTOMAKE -Wno-extra-portability"
+
+AUTOMAKE_fails
+grep 'configure\.ac:.*required directory.*\./libobj-dir' stderr
+
+mkdir libobj-dir
+: > foobar.c # Oops, it should be in libobj-dir!
+AUTOMAKE_fails
+grep 'configure\.ac:.*required file.*libobj-dir/foobar.c.*' stderr
+
+rm -f foobar.c
+
+: > libobj-dir/foobar.c
+$AUTOMAKE # Now we should succeed.
+
+:
diff --git a/t/libobj3.sh b/t/libobj3.sh
new file mode 100644
index 000000000..2d0e6b017
--- /dev/null
+++ b/t/libobj3.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we complain if @LIBOBJS@ is used without being set in
+# configure.ac.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_RANLIB
+AM_PROG_AR
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = @LIBOBJS@
+END
+
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'Makefile\.am:3:.*LIBOBJS' stderr
+
+:
diff --git a/t/libobj4.sh b/t/libobj4.sh
new file mode 100644
index 000000000..daefa43bb
--- /dev/null
+++ b/t/libobj4.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure LIBOBJS error only occurs if LIBOBJS seen. Report
+# from Jim Meyering.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+END
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_REPLACE_FUNCS([foo])
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/libobj5.sh b/t/libobj5.sh
new file mode 100644
index 000000000..e5769e372
--- /dev/null
+++ b/t/libobj5.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure AC_REPLACE_FUNCS works across lines. Report from
+# Jim Meyering.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = joe
+LDADD = @LIBOBJS@
+END
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_REPLACE_FUNCS(\
+ foo_bar_quux)
+END
+
+: > foo_bar_quux.c
+
+$ACLOCAL
+$AUTOMAKE
+$FGREP foo_bar_quux.c Makefile.in
+
+:
diff --git a/t/libobj7.sh b/t/libobj7.sh
new file mode 100644
index 000000000..0ec302e81
--- /dev/null
+++ b/t/libobj7.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for multiple replacement functions.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+# 'am__dummy_function' is there to ensure that at least one function is
+# replaced, to avoid creating an empty archive which can cause problems
+# with e.g. Solaris ar.
+AC_REPLACE_FUNCS([basename dirname am__dummy_function])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libtu.a
+libtu_a_SOURCES =
+libtu_a_LIBADD = @LIBOBJS@
+check-local: test1 test2 test3
+.PHONY: test1 test2 test3
+test1: all
+ $(AR) tv libtu.a
+test2:
+ @echo DIST_COMMON = $(DIST_COMMON)
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]basename\.c '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]dirname\.c '
+ echo ' ' $(DIST_COMMON) ' ' | grep '[ /]am__dummy_function\.c '
+test3: distdir
+ test -f $(distdir)/basename.c
+ test -f $(distdir)/dirname.c
+ test -f $(distdir)/am__dummy_function.c
+END
+
+cat > basename.c <<'END'
+extern int dummy1;
+END
+cat > dirname.c <<'END'
+extern int dummy2;
+END
+cat > am__dummy_function.c <<'END'
+extern int dummy3;
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/library.sh b/t/library.sh
new file mode 100644
index 000000000..1d0e487d3
--- /dev/null
+++ b/t/library.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for _DEPENDENCIES with libraries.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_RANLIB
+AC_PROG_CC
+AM_PROG_AR
+END
+
+cat > Makefile.am << 'END'
+lib_LIBRARIES = libfoo.a
+libfoo_a_DEPENDENCIES = libzot.a
+END
+
+: > ar-lib
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/library2.sh b/t/library2.sh
new file mode 100644
index 000000000..72eae1f83
--- /dev/null
+++ b/t/library2.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake suggest using AC_PROG_RANLIB when *_LIBRARIES is used.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+EXTRA_LIBRARIES = libfoo.a
+END
+
+$ACLOCAL
+AUTOMAKE_fails -Wno-portability
+grep AC_PROG_RANLIB stderr
diff --git a/t/library3.sh b/t/library3.sh
new file mode 100644
index 000000000..2068c101f
--- /dev/null
+++ b/t/library3.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake simplify conditions in diagnostics.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_PROG_CC
+AM_CONDITIONAL([A], [:])
+AM_CONDITIONAL([B], [:])
+AM_CONDITIONAL([C], [:])
+AM_CONDITIONAL([D], [:])
+EOF
+
+cat > Makefile.am << 'END'
+if A
+if !B
+ RANLIB = anb
+else
+ RANLIB = ab
+endif
+endif
+if C
+ RANLIB = c
+endif
+if !C
+if D
+ RANLIB = ncd
+endif
+endif
+EXTRA_LIBRARIES = libfoo.a
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile.am:.*: !A and !C and !D$' stderr
+# Is there only one missing condition?
+test $(grep -c ': !' stderr) -eq 1
+
+:
diff --git a/t/libtoo10.sh b/t/libtoo10.sh
new file mode 100644
index 000000000..ddc83b6c0
--- /dev/null
+++ b/t/libtoo10.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure .libs directories are removed for _PROGRAMS.
+# Report from Guillermo Ontañón.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = lib/libfoo.la
+lib_libfoo_la_SOURCES = foo.c
+bin_PROGRAMS = src/main
+check_PROGRAMS = check/test
+src_main_SOURCES = main.c
+check_test_SOURCES = main.c
+LDADD = lib/libfoo.la
+END
+
+mkdir lib src check
+cat > foo.c << 'END'
+int foo () { return 0; }
+END
+
+cat > main.c << 'END'
+extern int foo ();
+int main () { return foo (); }
+END
+
+libtoolize
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+./configure
+$MAKE all check
+$MAKE clean
+test ! -e src/.libs
+test ! -e src/_libs
+test ! -e check/.libs
+test ! -e check/_libs
+$MAKE distcheck
+
+:
diff --git a/t/libtoo11.sh b/t/libtoo11.sh
new file mode 100644
index 000000000..900b3bec6
--- /dev/null
+++ b/t/libtoo11.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure config.lt is removed with Libtool 2.2.x's LT_OUTPUT.
+# Report by Charles Wilson.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_LIBTOOL
+m4_ifdef([LT_OUTPUT], [LT_OUTPUT])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+libtoolize
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+./configure
+$MAKE distcheck
+
+:
diff --git a/t/libtool-macros.sh b/t/libtool-macros.sh
new file mode 100644
index 000000000..903a25d3f
--- /dev/null
+++ b/t/libtool-macros.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Try to find the libtool '.m4' files and make them easily accessed
+# to the test cases requiring them.
+# See also automake bug#9807.
+
+. test-init.sh
+
+echo "# Automatically generated by $me." > get.sh
+echo : >> get.sh
+
+# The 'libtoolize' script will look into Makefile.am.
+echo ACLOCAL_AMFLAGS = -I m4 > Makefile.am
+
+if libtoolize --copy --install && test -f m4/libtool.m4; then
+ echo "ACLOCAL_PATH='$(pwd)/m4':\$ACLOCAL_PATH" >> get.sh
+ echo "export ACLOCAL_PATH" >> get.sh
+else
+ # Libtoolize from libtool < 2.0 didn't support the '--install' option,
+ # but this doesn't mean the user hasn't made the libtool macros
+ # available, e.g., by properly setting ACLOCAL_PATH.
+ rm -rf m4
+ mkdir m4
+ echo AC_PROG_LIBTOOL >> configure.ac
+ # See below for an explanation about the use the of '-Wno-syntax'.
+ if $ACLOCAL -Wno-syntax -I m4 --install && test -f m4/libtool.m4; then
+ : # Libtool macros already accessible by default.
+ else
+ echo "skip_all_ \"couldn't find or get libtool macros\"" >> get.sh
+ fi
+fi
+
+. ./get.sh
+
+$ACLOCAL --force -I m4 || cat >> get.sh <<'END'
+# We need to use '-Wno-syntax', since we do not want our test suite
+# to fail merely because some third-party '.m4' file is underquoted.
+ACLOCAL="$ACLOCAL -Wno-syntax"
+END
+
+# The file libtoolize might have just copied in the 'm4' subdirectory of
+# the test directory are going to be needed by other tests, so we must
+# not remove the test directory.
+keep_testdirs=yes
+
+:
diff --git a/t/libtool.sh b/t/libtool.sh
new file mode 100644
index 000000000..eab01f037
--- /dev/null
+++ b/t/libtool.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure libtool is removed.
+# Report from Kevin Dalley.
+
+required=libtool
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_LIBTOOL_DLOPEN
+AC_DISABLE_SHARED
+AC_PROG_LIBTOOL
+AC_SUBST([LIBTOOL_DEPS])
+END
+
+: > Makefile.am
+
+: > ltmain.sh
+: > config.guess
+: > config.sub
+
+$ACLOCAL
+$AUTOMAKE
+
+grep 'rm -f libtool' Makefile.in
+
+:
diff --git a/t/libtool2.sh b/t/libtool2.sh
new file mode 100644
index 000000000..a14cae019
--- /dev/null
+++ b/t/libtool2.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure libtool clean targets exist.
+# Report from Eric Magnien.
+
+required=libtoolize
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIR = subdir
+lib_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = foo.c
+END
+
+mkdir sub
+cat > sub/Makefile.am << 'END'
+lib_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = foo.c
+END
+
+$ACLOCAL
+: > ltmain.sh
+$AUTOMAKE -a
+
+grep 'rm -f .*\.lo' sub/Makefile.in
+
+:
diff --git a/t/libtool3.sh b/t/libtool3.sh
new file mode 100644
index 000000000..5e5fd0df3
--- /dev/null
+++ b/t/libtool3.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Try to build and package a program linked to a Libtool library.
+# Also make sure we do not bloat the Makefile with unneeded rules.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AM_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# FIXME: stop disabling the warnings in the 'unsupported' category
+# FIXME: once the 'subdir-objects' option has been mandatory.
+AUTOMAKE_OPTIONS = -Wno-unsupported
+
+lib_LTLIBRARIES = lib0.la liba/liba.la
+lib0_la_SOURCES = 0.c
+liba_liba_la_SOURCES = liba/a.c
+
+bin_PROGRAMS = 1
+1_SOURCES = sub/1.c
+1_LDADD = lib0.la liba/liba.la
+END
+
+mkdir liba sub
+
+cat > 0.c << 'END'
+int
+zero (void)
+{
+ return 0;
+}
+END
+
+cat > sub/1.c << 'END'
+int zero ();
+
+int
+main (void)
+{
+ return zero ();
+}
+END
+
+cat > liba/a.c << 'END'
+int
+a (void)
+{
+ return 'a';
+}
+END
+
+# Use --copy to workaround a bug in Cygwin's 'cp -p' during distcheck.
+# (This bug is already exhibited by subobj9.sh.) In brief: Cygwin's
+# 'cp -p' tries to preserve group and owner of the source and fails
+# to do so under normal accounts. With --copy we ensure we own all files.
+
+libtoolize --force --copy
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing --copy
+
+# We need explicit rules to build 1.o and a.lo. Make sure
+# Automake did not output additional rules for 1.lo and and a.lo.
+$FGREP '1.o:' Makefile.in
+$FGREP '1.lo:' Makefile.in && exit 1
+$FGREP 'a.o:' Makefile.in && exit 1
+$FGREP 'a.lo:' Makefile.in
+
+./configure
+
+$MAKE
+$MAKE distcheck
+
+:
diff --git a/t/libtool4.sh b/t/libtool4.sh
new file mode 100644
index 000000000..0bfd2faa7
--- /dev/null
+++ b/t/libtool4.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake suggests AC_PROG_LIBTOOL when *_LTLIBRARIES is used.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+END
+
+cat > Makefile.am << 'END'
+EXTRA_LTLIBRARIES = liblib.la
+END
+
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '[Ll]ibtool library .*LIBTOOL.* undefined' stderr
+grep 'define .*LIBTOOL.* add .*LT_INIT' stderr
+
+:
diff --git a/t/libtool5.sh b/t/libtool5.sh
new file mode 100644
index 000000000..ccbeb3ce2
--- /dev/null
+++ b/t/libtool5.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure it's ok to install a library under different conditions
+# in the same directory.
+# Report from Harlan Stenn.
+
+required='libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [false])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+if COND1
+ lib_LTLIBRARIES = liba.la
+endif
+if COND2
+ lib_LTLIBRARIES = liba.la
+endif
+END
+
+libtoolize
+$ACLOCAL
+$AUTOMAKE --add-missing
diff --git a/t/libtool6.sh b/t/libtool6.sh
new file mode 100644
index 000000000..905c35267
--- /dev/null
+++ b/t/libtool6.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure it's OK to install a library under different conditions
+# in different directories. PR/285.
+
+required='libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [false])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+if COND1
+ lib_LTLIBRARIES = liba.la
+endif
+if COND2
+ pkglib_LTLIBRARIES = liba.la
+endif
+END
+
+libtoolize
+$ACLOCAL
+$AUTOMAKE --add-missing
+# am_liba_la_rpath is defined twice, and used once
+test 3 -eq $(grep -c 'am_liba_la_rpath' Makefile.in)
+
+:
diff --git a/t/libtool7.sh b/t/libtool7.sh
new file mode 100644
index 000000000..3e6342d99
--- /dev/null
+++ b/t/libtool7.sh
@@ -0,0 +1,98 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we allow Libtool's -dlopen/-dlpreopen
+# Also check basic support for AM_LIBTOOLFLAGS/LIBTOOLFLAGS
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_LIBTOOL_DLOPEN
+AM_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+AM_LIBTOOLFLAGS = --silent
+lib_LTLIBRARIES = libmod1.la mod2.la
+libmod1_la_SOURCES = sub/mod1.c
+libmod1_la_LDFLAGS = -module
+libmod1_la_LIBADD = -dlopen mod2.la
+mod2_la_SOURCES = mod2.c
+mod2_la_LDFLAGS = -module
+mod2_la_LIBTOOLFLAGS =
+
+bin_PROGRAMS = prg
+prg_SOURCES = prg.c
+prg_LDADD = -dlopen libmod1.la -dlpreopen mod2.la
+
+.PHONY: print
+print:
+ @echo 1BEG: $(prg_DEPENDENCIES) :END1
+ @echo 2BEG: $(libmod1_la_DEPENDENCIES) :END2
+ @echo 3BEG: $(LTCOMPILE) :END3
+END
+
+mkdir sub liba
+
+cat > sub/mod1.c << 'END'
+int mod1 (void)
+{
+ return 1;
+}
+END
+
+cat > mod2.c << 'END'
+int mod2 (void)
+{
+ return 2;
+}
+END
+
+cat > prg.c << 'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+libtoolize --force --copy
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing --copy
+
+./configure "--prefix=$(pwd)/_inst"
+
+run_make -M print LIBTOOLFLAGS=--silent
+grep '1BEG: libmod1.la mod2.la :END1' output
+grep '2BEG: mod2.la :END2' output
+grep '3BEG: .*silent.*silent.* :END3' output
+test 2 -le $(grep mod2_la_LIBTOOLFLAGS Makefile | wc -l)
+
+$MAKE
+
+run_make -M install LIBTOOLFLAGS=--silent
+grep 'silent.*silent.*prg' output
+grep 'silent.*silent.*libmod1' output
+
+run_make -M uninstall LIBTOOLFLAGS=--silent
+grep 'silent.*silent.*libmod1' output
+
+:
diff --git a/t/libtool8.sh b/t/libtool8.sh
new file mode 100644
index 000000000..1e983401e
--- /dev/null
+++ b/t/libtool8.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake diagnoses conflicting installations.
+
+required='libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [false])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+if COND1
+ lib_LTLIBRARIES = liba.la
+ EXTRA_LTLIBRARIES = libc.la libc.la libb.la
+else
+ lib_LTLIBRARIES = libb.la
+endif
+if COND2
+if COND1
+ pkglib_LTLIBRARIES = liba.la
+endif
+LIBTOOLFLAGS = ouch
+endif
+END
+
+libtoolize
+$ACLOCAL
+AUTOMAKE_fails --add-missing
+grep libb stderr && exit 1
+grep 'Makefile.am:3:.*libc.la.*multiply defined' stderr
+grep "Makefile.am:9:.*'pkglib" stderr
+grep "Makefile.am:2:.*'lib" stderr
+grep 'Makefile.am:11:.*AM_LIBTOOLFLAGS' stderr
diff --git a/t/libtool9.sh b/t/libtool9.sh
new file mode 100644
index 000000000..a4c392661
--- /dev/null
+++ b/t/libtool9.sh
@@ -0,0 +1,106 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure xxx_LINK is defined for each target that requires specific
+# flags.
+# Quite similar to 'libtool7.sh', using AM_LDFLAGS in addition to
+# xxx_LDFLAGS.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_LIBTOOL_DLOPEN
+AM_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_LDFLAGS = -module
+lib_LTLIBRARIES = libmod1.la mod2.la
+libmod1_la_SOURCES = mod1.c
+libmod1_la_LDFLAGS =
+libmod1_la_LIBADD = -dlopen mod2.la
+mod2_la_SOURCES = mod2.c
+
+bin_PROGRAMS = prg prg2
+prg_SOURCES = prg.c
+prg_LDADD = -dlopen libmod1.la -dlpreopen mod2.la
+prg_CPPFLAGS = -DXYZ=1
+prg2_SOURCES = prg.c
+prg2_CFLAGS =
+
+print:
+ @echo 1BEG: $(prg_DEPENDENCIES) :END1
+ @echo 2BEG: $(libmod1_la_DEPENDENCIES) :END2
+ @echo 3BEG: $(libmod1_la_LINK) :END3
+ @echo 4BEG: $(mod2_la_LINK) :END4
+ @echo 5BEG: $(prg_LINK) :END5
+ @echo 6BEG: $(prg2_LINK) :END6
+
+END
+
+mkdir liba
+
+cat > mod1.c << 'END'
+int mod1 (void)
+{
+ return 1;
+}
+END
+
+cat > mod2.c << 'END'
+int mod2 (void)
+{
+ return 2;
+}
+END
+
+cat > prg.c << 'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+libtoolize --force --copy
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing --copy
+
+./configure
+run_make -M -- print \
+ LDFLAGS=ldflags \
+ AM_LDFLAGS=am_ldflags \
+ libmod1_la_LDFLAGS=lm1_la_ldflags \
+ CFLAGS=cflags \
+ AM_CFLAGS=am_cflags \
+ prg2_CFLAGS=prg2_cflags
+
+grep '1BEG: libmod1.la mod2.la :END1' output
+grep '2BEG: mod2.la :END2' output
+grep '3BEG:.* am_cflags cflags .*lm1_la_ldflags ldflags.* :END3' output
+grep '3BEG: .*am_ldflags.* :END3' output && exit 1
+grep '4BEG: :END4' output
+grep '5BEG: :END5' output
+grep '6BEG:.* prg2_cflags cflags .*am_ldflags ldflags.* :END6' output
+grep '6BEG: .*am_cflags.* :END6' output && exit 1
+
+$MAKE
+
+:
diff --git a/t/license.sh b/t/license.sh
new file mode 100644
index 000000000..13813d111
--- /dev/null
+++ b/t/license.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure COPYING is not overwritten, even with -a -f.
+
+. test-init.sh
+
+echo AC_OUTPUT >>configure.ac
+
+cat >Makefile.am <<\EOF
+test1: distdir
+ grep 'GNU GENERAL PUBLIC LICENSE' $(distdir)/COPYING
+test2: distdir
+ grep 'MY-OWN-LICENSE' $(distdir)/COPYING
+test3: distdir
+ test ! -f $(distdir)/COPYING
+ grep 'MY-OWN-LICENSE' $(distdir)/COPYING.LIB
+EOF
+
+:> NEWS
+:> AUTHORS
+:> ChangeLog
+:> README
+
+test ! -e COPYING
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --gnu --add-missing
+
+./configure
+$MAKE test1
+
+# Use 'rm' before 'echo', because COPYING is likely to be a symlink to
+# the real COPYING...
+rm -f COPYING
+echo 'MY-OWN-LICENSE' >COPYING
+$MAKE test2
+
+$AUTOMAKE --gnu --add-missing --force-missing
+./configure
+$MAKE test2
+
+rm -f COPYING
+echo 'MY-OWN-LICENSE' >COPYING.LIB
+$AUTOMAKE --gnu --add-missing --force-missing
+./configure
+$MAKE test3
diff --git a/t/license2.sh b/t/license2.sh
new file mode 100644
index 000000000..12bb31a6b
--- /dev/null
+++ b/t/license2.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that installing 'COPYING' outputs a warning.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = gnu
+END
+
+: >AUTHORS
+: >NEWS
+: >README
+: >ChangeLog
+: >INSTALL
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'COPYING' stderr
+
+AUTOMAKE_run --add-missing
+grep 'COPYING' stderr
+grep 'GNU General Public License' stderr
+grep 'Consider adding.*version control' stderr
+test -f COPYING
diff --git a/t/link_c_cxx.sh b/t/link_c_cxx.sh
new file mode 100644
index 000000000..0ac7c01bc
--- /dev/null
+++ b/t/link_c_cxx.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure the C++ linker is used when appropriate.
+# Matthew D. Langston <langston@SLAC.Stanford.EDU>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lavalamp
+lavalamp_SOURCES = lava.c lamp.cxx
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# We should only see the C++ linker in the rules of 'Makefile.in'.
+
+# Look for this macro not at the beginning of any line; that will have
+# to be good enough for now.
+grep '.\$(CXXLINK)' Makefile.in
+
+# We should not see these patterns:
+grep '.\$(FLINK)' Makefile.in && exit 1
+grep '.\$(LINK)' Makefile.in && exit 1
+
+exit 0
diff --git a/t/link_cond.sh b/t/link_cond.sh
new file mode 100644
index 000000000..382e4a6e1
--- /dev/null
+++ b/t/link_cond.sh
@@ -0,0 +1,88 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that automatic determination of the linker works well with
+# conditional use of languages in a single program.
+# This currently doesn't truly work, but we have an easy workaround
+# at least, that is tested here.
+# See automake bug#11089.
+
+required='cc c++'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AM_CONDITIONAL([HAVE_CXX], [test $have_cxx = yes])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+if HAVE_CXX
+foo_SOURCES = more.c++
+else
+foo_SOURCES = less.c
+endif
+## FIXME: ideally, this workaround shouldn't be needed.
+if HAVE_CXX
+foo_LINK = $(CXXLINK)
+else
+foo_LINK = $(LINK)
+endif
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+rm -f *.c++
+cat > less.c <<'END'
+/* Valid C but deliberately invalid C++ */
+main ()
+{
+ int new = 0;
+ return new;
+}
+END
+
+./configure have_cxx=no
+run_make CXX=false
+
+# Sanity check.
+rm -f foo foo.exe
+run_make CC=false && fatal_ '"make CC=false" succeeded unexpectedly'
+
+$MAKE distclean
+
+rm -f *.c
+cat > more.c++ <<'END'
+/* Valid C++ but deliberately invalid C */
+using namespace std;
+int main (void)
+{
+ return 0;
+}
+END
+
+./configure have_cxx=yes
+run_make CC=false
+
+# Sanity check.
+rm -f foo foo.exe
+run_make CXX=false && fatal_ '"make CXX=false" succeeded unexpectedly'
+
+:
diff --git a/t/link_dist.sh b/t/link_dist.sh
new file mode 100644
index 000000000..b1bad18e9
--- /dev/null
+++ b/t/link_dist.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure the linker for a dist_*_SOURCES can override that for
+# *_SOURCES
+# Richard Boulton <richard@tartarus.org>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lavalamp
+lavalamp_SOURCES = lava.c
+dist_lavalamp_SOURCES = lamp.cxx
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# We should only see the C++ linker in the rules of 'Makefile.in'.
+
+# Look for this macro not at the beginning of any line; that will have
+# to be good enough for now.
+grep '.\$(CXXLINK)' Makefile.in
+
+# We should not see these patterns:
+grep '.\$(FLINK)' Makefile.in && exit 1
+grep '.\$(LINK)' Makefile.in && exit 1
+
+exit 0
diff --git a/t/link_f90_only.sh b/t/link_f90_only.sh
new file mode 100644
index 000000000..79e7a2627
--- /dev/null
+++ b/t/link_f90_only.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure the Fortran 90 linker is used when appropriate.
+# (copied from 'link_f_only.sh') Mike Nolta <mrnolta@princeton.edu>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_FC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lavalamp
+lavalamp_SOURCES = lamp.f90
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# We should only see the Fortran linker in the rules of 'Makefile.in'.
+
+# Look for this macro not at the beginning of any line; that will have
+# to be good enough for now.
+grep '.\$(FCLINK)' Makefile.in
+
+# We should not see these patterns:
+grep '.\$(CXXLINK)' Makefile.in && exit 1
+grep '.\$(LINK)' Makefile.in && exit 1
+
+exit 0
diff --git a/t/link_f_only.sh b/t/link_f_only.sh
new file mode 100644
index 000000000..f8a9dcda0
--- /dev/null
+++ b/t/link_f_only.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure the Fortran 77 linker is used when appropriate.
+# Matthew D. Langston <langston@SLAC.Stanford.EDU>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_F77
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lavalamp
+lavalamp_SOURCES = lamp.f
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# We should only see the Fortran linker in the rules of 'Makefile.in'.
+
+# Look for this macro not at the beginning of any line; that will have
+# to be good enough for now.
+grep '.\$(F77LINK)' Makefile.in
+
+# We should not see these patterns:
+grep '.\$(CXXLINK)' Makefile.in && exit 1
+grep '.\$(LINK)' Makefile.in && exit 1
+
+exit 0
diff --git a/t/link_fc.sh b/t/link_fc.sh
new file mode 100644
index 000000000..f0a77b82e
--- /dev/null
+++ b/t/link_fc.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure the Fortran 77 linker is used when appropriate.
+# Matthew D. Langston <langston@SLAC.Stanford.EDU>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_F77
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lavalamp
+lavalamp_SOURCES = lava.c lamp.f
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# We should only see the Fortran 77 linker in the rules of
+# 'Makefile.in'.
+
+# Look for this macro not at the beginning of any line; that will have
+# to be good enough for now.
+grep '.\$(F77LINK)' Makefile.in
+
+# We should not see these patterns:
+grep '.\$(LINK)' Makefile.in && exit 1
+grep '.\$(CXXLINK)' Makefile.in && exit 1
+
+exit 0
diff --git a/t/link_fccxx.sh b/t/link_fccxx.sh
new file mode 100644
index 000000000..7c2001712
--- /dev/null
+++ b/t/link_fccxx.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure the C++ linker is used when appropriate.
+# Matthew D. Langston <langston@SLAC.Stanford.EDU>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_F77
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lavalamp
+lavalamp_SOURCES = lava.c lamp.cxx lamp2.f
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# We should only see the C++ linker in the rules of 'Makefile.in'.
+
+# Look for this macro not at the beginning of any line; that will have
+# to be good enough for now.
+grep '.\$(CXXLINK)' Makefile.in
+
+# We should not see these patterns:
+grep '.\$(F77LINK)' Makefile.in && exit 1
+grep '.\$(LINK)' Makefile.in && exit 1
+
+exit 0
diff --git a/t/link_fcxx.sh b/t/link_fcxx.sh
new file mode 100644
index 000000000..8a044d2df
--- /dev/null
+++ b/t/link_fcxx.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure the C++ linker is used when appropriate.
+# Matthew D. Langston <langston@SLAC.Stanford.EDU>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_PROG_F77
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lavalamp
+lavalamp_SOURCES = lava.cxx lamp.f
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# We should only see the C++ linker in the rules of 'Makefile.in'.
+
+# Look for this macro not at the beginning of any line; that will have
+# to be good enough for now.
+grep '.\$(CXXLINK)' Makefile.in
+
+# We should not see these patterns:
+grep '.\$(F77LINK)' Makefile.in && exit 1
+grep '.\$(LINK)' Makefile.in && exit 1
+
+exit 0
diff --git a/t/link_override.sh b/t/link_override.sh
new file mode 100644
index 000000000..5ac59f850
--- /dev/null
+++ b/t/link_override.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure _LINK variables are detected and used as documented.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo bar baz boo
+foo_LINK = $(LINK)
+bar_LINK = $(LINK)
+bar_LDFLAGS = $(AM_LDFLAGS)
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+# We should use foo_LINK not LINK.
+grep '.\$(foo_LINK)' Makefile.in
+grep '.\$(LINK).*foo' Makefile.in && exit 1
+
+# We should not override the user definition of bar_LINK.
+# IOW, bar_LDFLAGS is useless unless bar_LINK refers to it.
+grep '^ *bar_LINK *=.*bar_LDFLAGS' Makefile.in && exit 1
+grep '.\$(bar_LINK).*bar' Makefile.in
+
+exit 0
diff --git a/t/lisp-flags.sh b/t/lisp-flags.sh
new file mode 100644
index 000000000..34bb85ccd
--- /dev/null
+++ b/t/lisp-flags.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Elisp byte-compilation honours AM_ELCFLAFS and ELCFLAGS.
+
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+lisp_LISP = foo.el
+AM_ELCFLAGS = __am_elcflags__
+EOF
+
+cat >> configure.ac << 'EOF'
+AM_PATH_LISPDIR
+AC_OUTPUT
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure EMACS='echo >$@' --with-lispdir="$(pwd)/unused"
+
+: > foo.el
+run_make ELCFLAGS='__usr_elcflags__'
+grep '__am_elcflags__.*__usr_elcflags__' foo.elc
+
+:
diff --git a/t/lisp-loadpath.sh b/t/lisp-loadpath.sh
new file mode 100644
index 000000000..fa5b97010
--- /dev/null
+++ b/t/lisp-loadpath.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Emacs lisp files in both $(srcdir) and $(builddir) are found if
+# required by other files. Related to automake bug#11806.
+
+required=emacs
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PATH_LISPDIR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LISP = requirer.el
+lisp_LISP = foo.el
+lisp_DATA = bar.el
+END
+
+echo "(require 'foo) (require 'bar)" >> requirer.el
+echo "(provide 'foo)" > foo.el
+echo "(provide 'bar)" > bar.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkdir build
+cd build
+../configure
+$MAKE
+test -f requirer.elc
+test -f foo.elc
+test ! -e bar.elc
+
+$MAKE clean
+test ! -e requirer.elc
+test ! -e foo.elc
+
+# In the spirit of VPATH, stuff in the builddir is preferred to
+# stuff in the srcdir.
+echo "(provide" > ../foo.el # Break it.
+echo "defun)" > ../bar.el # Likewise.
+$MAKE && exit 1
+$sleep
+echo "(provide 'foo)" > foo.el
+echo "(provide 'bar)" > bar.el
+$MAKE
+test -f requirer.elc
+test -f foo.elc
+test ! -e bar.elc
+
+:
diff --git a/t/lisp-pr11806.sh b/t/lisp-pr11806.sh
new file mode 100644
index 000000000..d27df9507
--- /dev/null
+++ b/t/lisp-pr11806.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Compiling .el files that requires each other in a VPATH build.
+# See automake bug#11806.
+
+required=emacs
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PATH_LISPDIR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lisp_LISP = foo.el
+lisp_DATA = bar.el
+END
+
+echo "(require 'bar)" > foo.el
+echo "(provide 'bar)" > bar.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkdir build
+cd build
+../configure
+$MAKE
+test -f foo.elc
+cd ..
+
+./configure
+$MAKE
+test -f foo.elc
+
+:
diff --git a/t/lisp-subdir-mix.sh b/t/lisp-subdir-mix.sh
new file mode 100644
index 000000000..526591bfc
--- /dev/null
+++ b/t/lisp-subdir-mix.sh
@@ -0,0 +1,96 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check compiling elisp files in different subdirectories, where a
+# file in a subdirectory might require a file in another one.
+# This doesn't work out of the box, but can be made to work with a
+# judicious use of $(AM_ELCFLAGS).
+
+required=emacs
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PATH_LISPDIR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+dist_lisp_LISP = \
+ am-here.el \
+ sub1/am-one.el \
+ sub2/am-two.el \
+ sub3/subsub/am-three.el
+
+AM_ELCFLAGS = \
+ -L $(srcdir)/sub1 \
+ -L $(srcdir)/sub2 \
+ -L $(srcdir)/sub3/subsub
+
+elc-test:
+ test -f sub1/am-one.elc
+ test -f sub2/am-two.elc
+ test -f sub3/subsub/am-three.elc
+.PHONY: elc-test
+check-local: elc-test
+END
+
+mkdir sub1 sub2 sub3 sub3/subsub
+
+cat > am-here.el << 'END'
+(provide 'am-here)
+(require 'am-one)
+(require 'am-two)
+(require 'am-three)
+END
+
+cat > sub1/am-one.el << 'END'
+(require 'am-here)
+(provide 'am-one)
+(require 'am-two)
+(require 'am-three)
+END
+
+cat > sub2/am-two.el << 'END'
+(require 'am-here)
+(require 'am-one)
+(provide 'am-two)
+(require 'am-three)
+END
+
+cat > sub3/subsub/am-three.el << 'END'
+(require 'am-here)
+(require 'am-one)
+(require 'am-two)
+(provide 'am-three)
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE
+$MAKE elc-test
+$MAKE clean
+for x in am-here sub1/am-one sub2/am-two sub3/subsub/am-three; do
+ test -f $x.el
+ test ! -e $x.elc
+done
+
+$MAKE distcheck
+
+:
diff --git a/t/lisp-subdir.sh b/t/lisp-subdir.sh
new file mode 100644
index 000000000..7a3ed7fab
--- /dev/null
+++ b/t/lisp-subdir.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Emacs lisp files in subdirectories.
+
+required=emacs
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PATH_LISPDIR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+nobase_lisp_LISP = sub/am-one.el sub/am-two.el sub/am-three.el
+nobase_dist_lisp_LISP = sub/am-three.el
+dist_noinst_LISP = sub/am-four.el
+EXTRA_DIST = sub/am-one.el sub/am-two.el
+END
+
+mkdir sub
+echo "(require 'am-two) (provide 'am-one)" > sub/am-one.el
+echo "(require 'am-three) (provide 'am-two)" > sub/am-two.el
+echo "(provide 'am-three)" > sub/am-three.el
+echo "(require 'am-one) (require 'am-two)" > sub/am-four.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure --prefix="$(pwd)/inst" \
+ --with-lispdir="$(pwd)/inst/elisp" \
+
+$MAKE
+# No byte-compiled elisp files in the top-level directory.
+test "$(echo *.elc)" = '*.elc'
+test -f sub/am-one.elc
+test -f sub/am-two.elc
+test -f sub/am-three.elc
+test -f sub/am-four.elc
+$MAKE clean
+test ! -e sub/am-one.elc
+test ! -e sub/am-two.elc
+test ! -e sub/am-three.elc
+test ! -e sub/am-four.elc
+
+# Check installation.
+
+sort > exp << 'END'
+inst/elisp/sub/am-one.elc
+inst/elisp/sub/am-two.elc
+inst/elisp/sub/am-three.elc
+END
+
+$MAKE install
+find inst # For debugging.
+find inst -name '*.elc' > lst || { cat lst; exit 1; }
+sort lst > got
+
+cat exp
+cat got
+diff exp got
+
+# Also check VPATH builds and uninstall completeness.
+$MAKE distcheck
+
+:
diff --git a/t/lisp-subdir2.sh b/t/lisp-subdir2.sh
new file mode 100644
index 000000000..681549207
--- /dev/null
+++ b/t/lisp-subdir2.sh
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Compiling elisp files in different subdirectories.
+
+required=emacs
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PATH_LISPDIR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+dist_lisp_LISP = am-one.el
+nodist_lisp_LISP = sub/am-two.el
+sub/am-two.el:
+ mkdir sub
+ echo "(provide 'am-two)" > $@
+DISTCLEANFILES = $(nodist_lisp_LISP)
+dist_noinst_LISP = x/y/z/am-three.el
+
+elc-test:
+ test -f am-one.elc
+ test -f sub/am-two.elc
+ test -f x/y/z/am-three.elc
+.PHONY: elc-test
+check-local: elc-test
+END
+
+mkdir x x/y x/y/z
+echo "(provide 'am-one)" > am-one.el
+# sub/am-two.el is generated at make runtime
+echo "(provide 'am-three)" > x/y/z/am-three.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+
+$MAKE
+$MAKE elc-test
+$MAKE clean
+test ! -e am-one.elc
+test ! -e sub/am-two.elc
+test ! -e x/y/z/am-three.elc
+test -f am-one.el
+test -f sub/am-two.el
+test -f x/y/z/am-three.el
+
+# Byte-compiling only a subset of the elisp files.
+$MAKE am-one.elc sub/am-two.elc
+test -f am-one.elc
+test -f sub/am-two.elc
+test ! -e x/y/z/am-three.elc
+rm -f am-one.elc sub/am-two.elc
+$MAKE x/y/z/am-three.elc
+test ! -e am-one.elc
+test ! -e sub/am-two.elc
+test -f x/y/z/am-three.elc
+
+$MAKE distcheck
+
+:
diff --git a/t/lisp2.sh b/t/lisp2.sh
new file mode 100644
index 000000000..5e9903544
--- /dev/null
+++ b/t/lisp2.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that Automake suggest using AM_PATH_LISPDIR to define lispdir.
+
+. test-init.sh
+
+
+: TRY 1 -- We lack both EMACS and lispdir.
+
+cat > Makefile.am << 'END'
+lisp_LISP = foo.el
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep AM_PATH_LISPDIR stderr
+grep '[Ll]isp source.*EMACS.* undefined' stderr
+grep '[Ll]isp source.*lispdir.* undefined' stderr
+grep ' add .*AM_PATH_LISPDIR' stderr
+
+
+: TRY 2 -- Setting lispdir should not be enough.
+
+cat > Makefile.am << 'END'
+lispdir = /usr/share/emacs/site-lisp
+lisp_LISP = foo.el
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'lispdir.*undefined' stderr && exit 1
+grep '[Ll]isp source.*EMACS.* undefined' stderr
+grep 'define .*EMACS.* add .*AM_PATH_LISPDIR' stderr
+
+
+: TRY 3 -- Setting EMACS should not be enough.
+
+cat > Makefile.am << 'END'
+EMACS = emacs
+lisp_LISP = foo.el
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'EMACS.*undefined' stderr && exit 1
+grep '[Ll]isp source.*lispdir.* undefined' stderr
+grep 'define .*lispdir.* add .*AM_PATH_LISPDIR' stderr
+
+
+: TRY 4 -- Setting both EMACS and lispdir is OK.
+
+cat > Makefile.am << 'END'
+lispdir = /usr/share/emacs/site-lisp
+EMACS = emacs
+lisp_LISP = foo.el
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+:
diff --git a/t/lisp3.sh b/t/lisp3.sh
new file mode 100644
index 000000000..642b391c6
--- /dev/null
+++ b/t/lisp3.sh
@@ -0,0 +1,84 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that compiling interdependent elisp files works.
+
+required=emacs
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+lisp_LISP = am-one.el am-two.el am-three.el
+EXTRA_DIST = am-one.el am-two.el
+am-three.el:
+ echo "(provide 'am-three)" > $@
+CLEANFILES = am-three.el
+EOF
+
+cat >> configure.ac << 'EOF'
+AM_PATH_LISPDIR
+AC_OUTPUT
+EOF
+
+echo "(require 'am-two)" > am-one.el
+echo "(require 'am-three) (provide 'am-two)" > am-two.el
+# am-three.el is a built source
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure --prefix="$(pwd)/_inst"
+
+$MAKE
+
+test -f am-one.elc
+test -f am-two.elc
+test -f am-three.elc
+
+# Make sure we can recover from a deletion.
+rm -f am-one.elc
+$MAKE
+test -f am-one.elc
+
+# Test installation/deinstallation.
+
+$MAKE install
+
+find _inst # For debugging.
+
+# Keep thin in sync with m4/lispdir.m4.
+for dir in lib/emacs lib/xemacs share/emacs share/xemacs :; do
+ if test $dir = :; then
+ exit 1
+ elif test -d _inst/$dir/site-lisp; then
+ break
+ fi
+done
+
+test -f _inst/$dir/site-lisp/am-one.el
+test -f _inst/$dir/site-lisp/am-one.elc
+test -f _inst/$dir/site-lisp/am-two.el
+test -f _inst/$dir/site-lisp/am-two.elc
+test -f _inst/$dir/site-lisp/am-three.el
+test -f _inst/$dir/site-lisp/am-three.elc
+
+$MAKE uninstall
+find _inst | $EGREP '\.elc?$' && exit 1
+
+# It should also work for VPATH-builds.
+$MAKE distcheck
+
+:
diff --git a/t/lisp4.sh b/t/lisp4.sh
new file mode 100644
index 000000000..5eacc8842
--- /dev/null
+++ b/t/lisp4.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure setting ELCFILES= disable byte-compilation as documented.
+# Report from Simon Josefsson.
+
+required=emacs
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+lisp_LISP = am-one.el am-two.el am-three.el
+EXTRA_DIST = am-one.el am-two.el
+ELCFILES=
+am-three.el:
+ echo "(provide 'am-three)" > $@
+CLEANFILES = am-three.el
+
+test:
+ test ! -f am-one.elc
+ test ! -f am-two.elc
+ test ! -f am-three.elc
+
+install-test: install
+ test -f "$(lispdir)/am-one.el"
+ test -f "$(lispdir)/am-two.el"
+ test -f "$(lispdir)/am-three.el"
+ test ! -f "$(lispdir)/am-one.elc"
+ test ! -f "$(lispdir)/am-two.elc"
+ test ! -f "$(lispdir)/am-three.elc"
+
+not-installed:
+ find "$(lispdir)" | grep '\.el$$' && exit 1; :
+ find "$(lispdir)" | grep '\.elc$$' && exit 1; :
+EOF
+
+cat >> configure.ac << 'EOF'
+AM_PATH_LISPDIR
+AC_OUTPUT
+EOF
+
+echo "(require 'am-two)" > am-one.el
+echo "(require 'am-three) (provide 'am-two)" > am-two.el
+# am-tree.el is a built source
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+./configure --prefix "$cwd"
+$MAKE
+$MAKE test
+$MAKE install-test
+$MAKE uninstall
+$MAKE not-installed
+
+# Fake the absence of emacs.
+# *.el files should not be installed, but "make install" and
+# "make uninstall" should continue to work.
+./configure EMACS=no --prefix "$cwd"
+$MAKE
+$MAKE test
+$MAKE install
+$MAKE not-installed
+$MAKE uninstall
+
+:
diff --git a/t/lisp5.sh b/t/lisp5.sh
new file mode 100644
index 000000000..a98673e0b
--- /dev/null
+++ b/t/lisp5.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Same as 'lisp4.sh', but using the now-recommended way to install
+# non-bytecompiled *.el files.
+
+required=emacs
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+lisp_DATA = am-one.el am-two.el am-three.el
+EXTRA_DIST = am-one.el am-two.el
+am-three.el:
+ echo "(provide 'am-three)" > $@
+CLEANFILES = am-three.el
+
+test:
+ test ! -f am-one.elc
+ test ! -f am-two.elc
+ test ! -f am-three.elc
+
+install-test: install
+ test -f "$(lispdir)/am-one.el"
+ test -f "$(lispdir)/am-two.el"
+ test -f "$(lispdir)/am-three.el"
+ test ! -f "$(lispdir)/am-one.elc"
+ test ! -f "$(lispdir)/am-two.elc"
+ test ! -f "$(lispdir)/am-three.elc"
+
+not-installed:
+ find "$(lispdir)" | grep '\.el$$' && exit 1; :
+ find "$(lispdir)" | grep '\.elc$$' && exit 1; :
+EOF
+
+cat >> configure.ac << 'EOF'
+AM_PATH_LISPDIR
+AC_OUTPUT
+EOF
+
+echo "(require 'am-two)" > am-one.el
+echo "(require 'am-three) (provide 'am-two)" > am-two.el
+# am-tree.el is a built source
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+./configure --prefix "$cwd"
+$MAKE
+$MAKE test
+$MAKE install-test
+$MAKE uninstall
+$MAKE not-installed
+
+# Fake the absence of emacs.
+# *.el files SHOULD be installed by "make install" (and uninstalled
+# by "make uninstall").
+./configure EMACS=no --prefix "$cwd"
+$MAKE
+$MAKE test
+$MAKE install-test
+$MAKE uninstall
+$MAKE not-installed
+
+:
diff --git a/t/lisp6.sh b/t/lisp6.sh
new file mode 100644
index 000000000..07c8e1d4d
--- /dev/null
+++ b/t/lisp6.sh
@@ -0,0 +1,105 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for conditional _LISP.
+
+required=emacs
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+dist_lisp_LISP = am-one.el
+if WANT_TWO
+ dist_lisp_LISP += am-two.el
+endif
+dist_noinst_LISP = am-three.el
+
+dist-test: distdir
+ test -f $(distdir)/am-one.el
+ test -f $(distdir)/am-two.el
+ test -f $(distdir)/am-three.el
+EOF
+
+cat >> configure.ac << 'EOF'
+AM_CONDITIONAL([WANT_TWO], [test -n "$want_two"])
+AM_PATH_LISPDIR
+AC_OUTPUT
+EOF
+
+# Avoid possible spurious influences from the environment.
+unset want_two
+
+echo "(provide 'am-one)" > am-one.el
+echo "(require 'am-one)" > am-two.el
+echo "(require 'am-one)" > am-three.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+./configure --with-lispdir="$cwd/lisp"
+
+$MAKE
+test -f am-one.elc
+test ! -e am-two.elc
+test -f am-three.elc
+
+$MAKE install
+test -f lisp/am-one.el
+test -f lisp/am-one.elc
+test ! -e lisp/am-two.el
+test ! -e lisp/am-two.elc
+test ! -e lisp/am-three.el
+test ! -e lisp/am-three.elc
+
+$MAKE dist-test
+
+$MAKE distclean
+test ! -e am-one.elc
+test ! -e am-two.elc
+test ! -e am-three.elc
+
+./configure --with-lispdir="$cwd/lisp" want_two=1
+
+$MAKE
+test -f am-one.elc
+test -f am-two.elc
+test -f am-three.elc
+
+# Let's mutilate the source tree, to check the recover rule.
+rm -f am-*.elc
+$MAKE
+test -f am-one.elc
+test -f am-two.elc
+test -f am-three.elc
+
+$MAKE install
+test -f lisp/am-one.el
+test -f lisp/am-one.elc
+test -f lisp/am-two.el
+test -f lisp/am-two.elc
+test ! -e lisp/am-three.el
+test ! -e lisp/am-three.elc
+
+$MAKE dist-test
+
+$MAKE distclean
+test ! -e am-one.elc
+test ! -e am-two.elc
+test ! -e am-three.elc
+
+:
diff --git a/t/lisp7.sh b/t/lisp7.sh
new file mode 100644
index 000000000..833807843
--- /dev/null
+++ b/t/lisp7.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that lisp_LISP also works when emacs is not installed.
+
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+dist_lisp_LISP = am-one.el am-two.el am-three.el
+EOF
+
+cat >> configure.ac << 'EOF'
+AM_PATH_LISPDIR
+EMACS=no # Simulate no emacs.
+AC_OUTPUT
+EOF
+
+echo "(require 'am-two)" > am-one.el
+echo "(require 'am-three) (provide 'am-two)" > am-two.el
+echo "(provide 'am-three)" > am-three.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+
+run_make -O
+test ! -e am-one.elc
+test ! -e am-two.elc
+test ! -e am-three.elc
+
+$MAKE distcheck
+
+:
diff --git a/t/lisp8.sh b/t/lisp8.sh
new file mode 100644
index 000000000..92b81900b
--- /dev/null
+++ b/t/lisp8.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check the recover rule of lisp_LISP with parallel make.
+
+required='GNUmake emacs'
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+dist_lisp_LISP = am-one.el am-two.el am-three.el
+EOF
+
+cat >> configure.ac << 'EOF'
+AM_PATH_LISPDIR
+AC_OUTPUT
+EOF
+
+echo "(require 'am-two)" > am-one.el
+echo "(require 'am-three) (provide 'am-two)" > am-two.el
+echo "(provide 'am-three)" > am-three.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+
+run_make -O -- -j
+
+test -f am-one.elc
+test -f am-two.elc
+test -f am-three.elc
+
+# Delete ...
+rm -f am-*.elc
+
+# ... and recover.
+run_make -O -- -j
+test -f am-one.elc
+test -f am-two.elc
+test -f am-three.elc
+
+:
diff --git a/t/lispdry.sh b/t/lispdry.sh
new file mode 100644
index 000000000..1f50061e4
--- /dev/null
+++ b/t/lispdry.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that 'make -n' works with the lisp_LISP recover rule.
+
+required='emacs non-root'
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+dist_lisp_LISP = am-one.el am-two.el am-three.el
+EOF
+
+cat >> configure.ac << 'EOF'
+AM_PATH_LISPDIR
+AC_OUTPUT
+EOF
+
+echo "(require 'am-two)" > am-one.el
+echo "(require 'am-three) (provide 'am-two)" > am-two.el
+echo "(provide 'am-three)" > am-three.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+
+$MAKE
+
+test -f am-one.elc
+test -f am-two.elc
+test -f am-three.elc
+
+rm -f am-*.elc
+
+chmod a-w .
+
+$MAKE -n
+
+test ! -e am-one.elc
+test ! -e am-two.elc
+test ! -e am-three.elc
+
+:
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
new file mode 100644
index 000000000..b49a3ad0f
--- /dev/null
+++ b/t/list-of-tests.mk
@@ -0,0 +1,1323 @@
+## Makefile fragment that holds the list of test scripts of the automake
+## testsuite. This fragment is meant to be included by the Makefile.am,
+## but also to be executed directly by make when bootstrapping automake.
+
+## Copyright (C) 2011-2017 Free Software Foundation, Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# FIXME: this "expected failures" are in truth an hack used to
+# FIXME: to verify that some incorrect usages of our perl libraries
+# FIXME: raise an error. We should find a cleaner way to check that.
+perl_fake_XFAIL_TESTS = \
+t/pm/Cond2.pl \
+t/pm/Cond3.pl \
+t/pm/DisjCon2.pl \
+t/pm/DisjCon3.pl \
+t/pm/Version2.pl \
+t/pm/Version3.pl
+
+XFAIL_TESTS = \
+t/all.sh \
+t/auxdir-pr19311.sh \
+t/cond17.sh \
+t/gcj6.sh \
+t/override-conditional-2.sh \
+t/override-conditional-pr13940.sh \
+t/dist-pr109765.sh \
+t/instdir-cond2.sh \
+t/java-nobase.sh \
+t/objext-pr10128.sh \
+t/remake-timing-bug-pr8365.sh \
+t/lex-subobj-nodep.sh \
+t/remake-am-pr10111.sh \
+t/remake-m4-pr10111.sh \
+$(perl_fake_XFAIL_TESTS)
+
+perl_TESTS = \
+t/pm/Cond2.pl \
+t/pm/Cond3.pl \
+t/pm/Condition.pl \
+t/pm/Condition-t.pl \
+t/pm/DisjCon2.pl \
+t/pm/DisjCon3.pl \
+t/pm/DisjConditions.pl \
+t/pm/DisjConditions-t.pl \
+t/pm/Version.pl \
+t/pm/Version2.pl \
+t/pm/Version3.pl \
+t/pm/Wrap.pl
+
+perf_TESTS = \
+t/perf/cond.sh \
+t/perf/testsuite-recheck.sh \
+t/perf/testsuite-summary.sh
+
+# The order here is mostly alphabetical, with the deliberate exception
+# that tests having a high runtime (especially TAP tests that run various
+# checks sequentially) are listed early; this improves performance on
+# concurrent testsuite runs.
+handwritten_TESTS = \
+t/get-sysconf.sh \
+$(perl_TESTS) \
+t/instspc.tap \
+t/aclocal.sh \
+t/aclocal-I-order-1.sh \
+t/aclocal-I-order-2.sh \
+t/aclocal-I-order-3.sh \
+t/aclocal-I-and-install.sh \
+t/aclocal-acdir.sh \
+t/aclocal-amflags.sh \
+t/aclocal-autoconf-version-check.sh \
+t/aclocal-comments-respected.sh \
+t/aclocal-deleted-header-aclocal-amflags.sh \
+t/aclocal-deleted-header.sh \
+t/aclocal-deps-subdir.sh \
+t/aclocal-deps.sh \
+t/aclocal-dirlist.sh \
+t/aclocal-dirlist-globbing.sh \
+t/aclocal-dirlist-abspath.sh \
+t/aclocal-install-absdir.sh \
+t/aclocal-install-fail.sh \
+t/aclocal-install-mkdir.sh \
+t/aclocal-m4-include-are-scanned-aclocal-amflags.sh \
+t/aclocal-m4-include-are-scanned.sh \
+t/aclocal-m4-sinclude.sh \
+t/aclocal-macrodir.tap \
+t/aclocal-macrodirs.tap \
+t/aclocal-missing-macros.sh \
+t/aclocal-no-extra-scan.sh \
+t/aclocal-no-force.sh \
+t/aclocal-no-install-no-mkdir.sh \
+t/aclocal-no-symlinked-overwrite.sh \
+t/aclocal-no-unused-required.sh \
+t/aclocal-path.sh \
+t/aclocal-path-install.sh \
+t/aclocal-path-install-serial.sh \
+t/aclocal-path-nonexistent.sh \
+t/aclocal-path-precedence.sh \
+t/aclocal-pr450.sh \
+t/aclocal-print-acdir.sh \
+t/aclocal-req.sh \
+t/aclocal-remake-misc.sh \
+t/aclocal-scan-configure-ac-pr319.sh \
+t/aclocal-serial.sh \
+t/aclocal-underquoted-defun.sh \
+t/aclocal-verbose-install.sh \
+t/auxdir-pr15981.sh \
+t/auxdir-cc-pr15981.sh \
+t/ac-output-old.tap \
+t/acsilent.sh \
+t/acsubst.sh \
+t/acsubst2.sh \
+t/add-missing.tap \
+t/add-missing-multiple.sh \
+t/all.sh \
+t/all2.sh \
+t/alloca.sh \
+t/alloca2.sh \
+t/alpha.sh \
+t/alpha2.sh \
+t/amhello-cflags.sh \
+t/amhello-cross-compile.sh \
+t/amhello-binpkg.sh \
+t/aminit-moreargs-deprecation.sh \
+t/aminit-trailing-dnl-comment-pr16841.sh \
+t/amassign.sh \
+t/am-config-header.sh \
+t/am-prog-cc-stdc.sh \
+t/am-prog-cc-c-o.sh \
+t/am-macro-not-found.sh \
+t/amopt.sh \
+t/amopts-location.sh \
+t/amopts-variable-expansion.sh \
+t/amsubst.sh \
+t/am-default-source-ext.sh \
+t/am-include-only-one-generated-fragment.sh \
+t/ansi2knr-no-more.sh \
+t/ar-lib.sh \
+t/ar-lib2.sh \
+t/ar-lib3.sh \
+t/ar-lib4.sh \
+t/ar-lib5a.sh \
+t/ar-lib5b.sh \
+t/ar-lib6a.sh \
+t/ar-lib6b.sh \
+t/ar-lib7.sh \
+t/ar.sh \
+t/ar2.sh \
+t/ar3.sh \
+t/ar4.sh \
+t/ar5.sh \
+t/asm.sh \
+t/asm2.sh \
+t/asm3.sh \
+t/autodist.sh \
+t/autodist-subdir.sh \
+t/autodist-acconfig.sh \
+t/autodist-acconfig-no-subdir.sh \
+t/autodist-aclocal-m4.sh \
+t/autodist-config-headers.sh \
+t/autodist-configure-no-subdir.sh \
+t/autodist-no-duplicate.sh \
+t/autodist-stamp-vti.sh \
+t/autohdr.sh \
+t/autohdr3.sh \
+t/autohdr4.sh \
+t/autohdr-subdir-pr12495.sh \
+t/autohdrdry.sh \
+t/automake-cmdline.tap \
+t/auxdir.sh \
+t/auxdir6.sh \
+t/auxdir7.sh \
+t/auxdir8.sh \
+t/auxdir-autodetect.sh \
+t/auxdir-computed.tap \
+t/auxdir-misplaced.sh \
+t/auxdir-nonexistent.sh \
+t/auxdir-pr19311.sh \
+t/auxdir-unportable.tap \
+t/backcompat.sh \
+t/backcompat2.sh \
+t/backcompat3.sh \
+t/backcompat6.sh \
+t/backcompat-acout.sh \
+t/backslash-issues.sh \
+t/backslash-before-trailing-whitespace.sh \
+t/badline.sh \
+t/badopt.sh \
+t/badprog.sh \
+t/built-sources-check.sh \
+t/built-sources-cond.sh \
+t/built-sources-fork-bomb.sh \
+t/built-sources-install.sh \
+t/built-sources-subdir.sh \
+t/built-sources.sh \
+t/candist.sh \
+t/canon.sh \
+t/canon2.sh \
+t/canon3.sh \
+t/canon4.sh \
+t/canon5.sh \
+t/canon6.sh \
+t/canon7.sh \
+t/canon8.sh \
+t/canon-name.sh \
+t/ccnoco.sh \
+t/ccnoco-lib.sh \
+t/ccnoco-lt.sh \
+t/ccnoco3.sh \
+t/ccnoco4.sh \
+t/ccnoco-deps.sh \
+t/check.sh \
+t/check2.sh \
+t/check4.sh \
+t/check5.sh \
+t/check6.sh \
+t/check7.sh \
+t/check8.sh \
+t/check10.sh \
+t/check11.sh \
+t/check12.sh \
+t/check-subst.sh \
+t/check-subst-prog.sh \
+t/check-exported-srcdir.sh \
+t/check-fd-redirect.sh \
+t/check-tests-in-builddir.sh \
+t/check-no-test-driver.sh \
+t/check-concurrency-bug9245.sh \
+t/checkall.sh \
+t/clean.sh \
+t/colneq.sh \
+t/colneq2.sh \
+t/colneq3.sh \
+t/colon.sh \
+t/colon2.sh \
+t/colon3.sh \
+t/colon4.sh \
+t/colon5.sh \
+t/colon6.sh \
+t/colon7.sh \
+t/color-tests.sh \
+t/color-tests2.sh \
+t/color-tests-opt.sh \
+t/comment.sh \
+t/comment2.sh \
+t/comment3.sh \
+t/comment4.sh \
+t/comment5.sh \
+t/comment6.sh \
+t/comment7.sh \
+t/comment8.sh \
+t/comment9.sh \
+t/commen10.sh \
+t/commen11.sh \
+t/comment-block.sh \
+t/comments-in-var-def.sh \
+t/compile.sh \
+t/compile2.sh \
+t/compile3.sh \
+t/compile4.sh \
+t/compile5.sh \
+t/compile6.sh \
+t/compile7.sh \
+t/compile_f90_c_cxx.sh \
+t/compile_f_c_cxx.sh \
+t/cond-basic.sh \
+t/cond.sh \
+t/cond3.sh \
+t/cond4.sh \
+t/cond5.sh \
+t/cond6.sh \
+t/cond7.sh \
+t/cond8.sh \
+t/cond9.sh \
+t/cond10.sh \
+t/cond11.sh \
+t/cond13.sh \
+t/cond14.sh \
+t/cond15.sh \
+t/cond16.sh \
+t/cond17.sh \
+t/cond18.sh \
+t/cond19.sh \
+t/cond20.sh \
+t/cond21.sh \
+t/cond22.sh \
+t/cond23.sh \
+t/cond24.sh \
+t/cond25.sh \
+t/cond26.sh \
+t/cond27.sh \
+t/cond28.sh \
+t/cond30.sh \
+t/cond31.sh \
+t/cond32.sh \
+t/cond33.sh \
+t/cond34.sh \
+t/cond35.sh \
+t/cond36.sh \
+t/cond37.sh \
+t/cond38.sh \
+t/cond39.sh \
+t/cond40.sh \
+t/cond41.sh \
+t/cond42.sh \
+t/cond43.sh \
+t/cond44.sh \
+t/cond45.sh \
+t/cond46.sh \
+t/condd.sh \
+t/condhook.sh \
+t/condhook2.sh \
+t/condinc.sh \
+t/condinc2.sh \
+t/condlib.sh \
+t/condman2.sh \
+t/condman3.sh \
+t/configure.sh \
+t/confdeps.sh \
+t/conff.sh \
+t/conff2.sh \
+t/conffile-leading-dot.sh \
+t/confh.sh \
+t/confh4.sh \
+t/confh5.sh \
+t/confh6.sh \
+t/confh7.sh \
+t/confh8.sh \
+t/confh-subdir-clean.sh \
+t/confincl.sh \
+t/conflnk.sh \
+t/conflnk2.sh \
+t/conflnk3.sh \
+t/conflnk4.sh \
+t/confsub.sh \
+t/confvar.sh \
+t/confvar2.sh \
+t/copy.sh \
+t/cscope.tap \
+t/cscope2.sh \
+t/cscope3.sh \
+t/c-demo.sh \
+t/cxx.sh \
+t/cxx2.sh \
+t/cxxcpp.sh \
+t/cxx-demo.sh \
+t/cxx-lt-demo.sh \
+t/cxxlibobj.sh \
+t/cxxlink.sh \
+t/cxxnoc.sh \
+t/cygnus-no-more.sh \
+t/cygwin32.sh \
+t/dash.sh \
+t/defun.sh \
+t/defun2.sh \
+t/dejagnu.sh \
+t/dejagnu2.sh \
+t/dejagnu3.sh \
+t/dejagnu4.sh \
+t/dejagnu5.sh \
+t/dejagnu6.sh \
+t/dejagnu7.sh \
+t/dejagnu-absolute-builddir.sh \
+t/dejagnu-relative-srcdir.sh \
+t/dejagnu-siteexp-extend.sh \
+t/dejagnu-siteexp-append.sh \
+t/dejagnu-siteexp-useredit.sh \
+t/deleted-am.sh \
+t/deleted-m4.sh \
+t/depacl2.sh \
+t/depcomp.sh \
+t/depcomp2.sh \
+t/depcomp8a.sh \
+t/depcomp8b.sh \
+t/depcomp-implicit-auxdir.sh \
+t/depdist.sh \
+t/depend.sh \
+t/depend3.sh \
+t/depend4.sh \
+t/depend5.sh \
+t/depend6.sh \
+t/depend-postproc.sh \
+t/deprecated-acinit.sh \
+t/destdir.sh \
+t/dir-named-obj-is-bad.sh \
+t/discover.sh \
+t/dist-formats.tap \
+t/dist-lzma.sh \
+t/dist-tarZ.sh \
+t/dist-shar.sh \
+t/dist-auxdir-many-subdirs.sh \
+t/dist-auxfile-2.sh \
+t/dist-auxfile.sh \
+t/dist-included-parent-dir.sh \
+t/dist-missing-am.sh \
+t/dist-missing-included-m4.sh \
+t/dist-missing-m4.sh \
+t/dist-readonly.sh \
+t/dist-repeated.sh \
+t/dist-pr109765.sh \
+t/distcleancheck.sh \
+t/distcom2.sh \
+t/distcom3.sh \
+t/distcom4.sh \
+t/distcom5.sh \
+t/distcom-subdir.sh \
+t/distdir.sh \
+t/disthook.sh \
+t/distlinks.sh \
+t/distlinksbrk.sh \
+t/distname.sh \
+t/distcheck-configure-flags.sh \
+t/distcheck-configure-flags-am.sh \
+t/distcheck-configure-flags-subpkg.sh \
+t/distcheck-hook.sh \
+t/distcheck-hook2.sh \
+t/distcheck-writable-srcdir.sh \
+t/distcheck-missing-m4.sh \
+t/distcheck-outdated-m4.sh \
+t/distcheck-no-prefix-or-srcdir-override.sh \
+t/distcheck-override-infodir.sh \
+t/distcheck-pr9579.sh \
+t/distcheck-pr10470.sh \
+t/distcheck-pr18286.sh \
+t/dmalloc.sh \
+t/doc-parsing-buglets-colneq-subst.sh \
+t/doc-parsing-buglets-tabs.sh \
+t/dollar.sh \
+t/dollarvar.sh \
+t/dollarvar2.sh \
+t/double.sh \
+t/dup2.sh \
+t/else.sh \
+t/empty-data-primary.sh \
+t/empty-sources-primary.tap \
+t/exdir.sh \
+t/exdir2.sh \
+t/exdir3.sh \
+t/exeext.sh \
+t/exeext2.sh \
+t/exeext3.sh \
+t/exeext4.sh \
+t/extra-sources.sh \
+t/ext.sh \
+t/ext2.sh \
+t/ext3.sh \
+t/extra.sh \
+t/extra-sources-no-spurious.sh \
+t/extra-data.sh \
+t/extra-dist-vpath-dir.sh \
+t/extra-dist-dirs-and-subdirs.sh \
+t/extra-dist-vpath-dir-merge.sh \
+t/extra-dist-wildcards.sh \
+t/extra-dist-wildcards-gnu.sh \
+t/extra-dist-wildcards-vpath.sh \
+t/extra-programs-misc.sh \
+t/extra-programs-and-libs.sh \
+t/extra-programs-empty.sh \
+t/extra-portability.sh \
+t/extra-portability2.sh \
+t/extra-portability3.sh \
+t/extra-deps.sh \
+t/extra-deps-lt.sh \
+t/f90only.sh \
+t/flavor.sh \
+t/flibs.sh \
+t/fn99.sh \
+t/fn99subdir.sh \
+t/fnoc.sh \
+t/forcemiss.sh \
+t/forcemiss2.sh \
+t/fort1.sh \
+t/fort2.sh \
+t/fort4.sh \
+t/fort5.sh \
+t/fonly.sh \
+t/fortdep.sh \
+t/gcj.sh \
+t/gcj2.sh \
+t/gcj3.sh \
+t/gcj4.sh \
+t/gcj5.sh \
+t/gcj6.sh \
+t/gettext-basics.sh \
+t/gettext-config-rpath.sh \
+t/gettext-external-pr338.sh \
+t/gettext-intl-subdir.sh \
+t/gettext-pr381.sh \
+t/gnumake.sh \
+t/gnuwarn.sh \
+t/gnuwarn2.sh \
+t/gnits.sh \
+t/gnits2.sh \
+t/gnits3.sh \
+t/hdr-vars-defined-once.sh \
+t/header.sh \
+t/help.sh \
+t/help2.sh \
+t/help3.sh \
+t/help4.sh \
+t/help-depend.sh \
+t/help-depend2.sh \
+t/help-dmalloc.sh \
+t/help-init.sh \
+t/help-lispdir.sh \
+t/help-python.sh \
+t/help-silent.sh \
+t/help-upc.sh \
+t/hfs.sh \
+t/implicit.sh \
+t/init.sh \
+t/init2.sh \
+t/dist-install-sh.sh \
+t/dist-with-unreadable-makefile-fails.sh \
+t/installdir.sh \
+t/add-missing-install-sh.sh \
+t/install-sh-unittests.sh \
+t/install-sh-option-C.sh \
+t/instdat.sh \
+t/instdat2.sh \
+t/instdir.sh \
+t/instdir2.sh \
+t/instdir-cond.sh \
+t/instdir-cond2.sh \
+t/instdir-no-empty.sh \
+t/instdir-java.sh \
+t/instdir-lisp.sh \
+t/instdir-ltlib.sh \
+t/instdir-prog.sh \
+t/instdir-python.sh \
+t/instdir-texi.sh \
+t/instexec.sh \
+t/instfail.sh \
+t/instfail-info.sh \
+t/instfail-java.sh \
+t/instfail-libtool.sh \
+t/insthook.sh \
+t/instman.sh \
+t/instman2.sh \
+t/instmany.sh \
+t/instmany-mans.sh \
+t/instmany-python.sh \
+t/install-info-dir.sh \
+t/interp.sh \
+t/interp2.sh \
+t/java.sh \
+t/java2.sh \
+t/java3.sh \
+t/javadir-undefined.sh \
+t/javaflags.sh \
+t/java-check.sh \
+t/java-clean.sh \
+t/java-compile-install.sh \
+t/java-compile-run-flat.sh \
+t/java-compile-run-nested.sh \
+t/java-empty-classpath.sh \
+t/javaprim.sh \
+t/javasubst.sh \
+t/java-extra.sh \
+t/java-mix.sh \
+t/java-no-duplicate.sh \
+t/java-nobase.sh \
+t/java-noinst.sh \
+t/java-rebuild.sh \
+t/java-sources.sh \
+t/java-uninstall.sh \
+t/ldadd.sh \
+t/ldflags.sh \
+t/lex.sh \
+t/lex2.sh \
+t/lex3.sh \
+t/lex5.sh \
+t/lexcpp.sh \
+t/lexvpath.sh \
+t/lex-subobj-nodep.sh \
+t/lex-header.sh \
+t/lex-lib.sh \
+t/lex-lib-external.sh \
+t/lex-libobj.sh \
+t/lex-multiple.sh \
+t/lex-noyywrap.sh \
+t/lex-clean-cxx.sh \
+t/lex-clean.sh \
+t/lex-depend-cxx.sh \
+t/lex-depend-grep.sh \
+t/lex-depend.sh \
+t/lex-line.sh \
+t/lex-nodist.sh \
+t/lex-pr204.sh \
+t/lflags.sh \
+t/lflags-cxx.sh \
+t/libexec.sh \
+t/libobj-basic.sh \
+t/libobj-no-dependency-tracking.sh \
+t/libobj2.sh \
+t/libobj3.sh \
+t/libobj4.sh \
+t/libobj5.sh \
+t/libobj7.sh \
+t/libobj10.sh \
+t/libobj12.sh \
+t/libobj13.sh \
+t/libobj14.sh \
+t/libobj15a.sh \
+t/libobj15b.sh \
+t/libobj15c.sh \
+t/libobj16a.sh \
+t/libobj16b.sh \
+t/libobj17.sh \
+t/libobj18.sh \
+t/libobj19.sh \
+t/libobj20a.sh \
+t/libobj20b.sh \
+t/libobj20c.sh \
+t/library.sh \
+t/library2.sh \
+t/library3.sh \
+t/libtool.sh \
+t/libtool2.sh \
+t/libtool3.sh \
+t/libtool4.sh \
+t/libtool5.sh \
+t/libtool6.sh \
+t/libtool7.sh \
+t/libtool8.sh \
+t/libtool9.sh \
+t/libtoo10.sh \
+t/libtoo11.sh \
+t/license.sh \
+t/license2.sh \
+t/link_c_cxx.sh \
+t/link_cond.sh \
+t/link_dist.sh \
+t/link_f90_only.sh \
+t/link_fc.sh \
+t/link_fccxx.sh \
+t/link_fcxx.sh \
+t/link_f_only.sh \
+t/link_override.sh \
+t/lisp2.sh \
+t/lisp3.sh \
+t/lisp4.sh \
+t/lisp5.sh \
+t/lisp6.sh \
+t/lisp7.sh \
+t/lisp8.sh \
+t/lisp-loadpath.sh \
+t/lisp-subdir.sh \
+t/lisp-subdir2.sh \
+t/lisp-subdir-mix.sh \
+t/lispdry.sh \
+t/lisp-pr11806.sh \
+t/lisp-flags.sh \
+t/listval.sh \
+t/location.sh \
+t/longline.sh \
+t/longlin2.sh \
+t/ltcond.sh \
+t/ltcond2.sh \
+t/ltconv.sh \
+t/ltdeps.sh \
+t/ltinit.sh \
+t/ltinstloc.sh \
+t/ltlibobjs.sh \
+t/ltlibsrc.sh \
+t/ltorder.sh \
+t/m4-inclusion.sh \
+t/maintclean.sh \
+t/maintclean-vpath.sh \
+t/maintmode-configure-msg.sh \
+t/make.sh \
+t/makefile-deps.sh \
+t/makej.sh \
+t/makej2.sh \
+t/maken.sh \
+t/maken3.sh \
+t/makevars.sh \
+t/make-dryrun.tap \
+t/make-keepgoing.tap \
+t/make-is-gnu.sh \
+t/man.sh \
+t/man2.sh \
+t/man3.sh \
+t/man5.sh \
+t/man6.sh \
+t/man7.sh \
+t/man8.sh \
+t/mdate.sh \
+t/mdate2.sh \
+t/mdate3.sh \
+t/mdate4.sh \
+t/mdate5.sh \
+t/mdate6.sh \
+t/missing-version-mismatch.sh \
+t/missing3.sh \
+t/am-missing-prog.sh \
+t/missing-auxfile-stops-makefiles-creation.sh \
+t/mkdir_p.sh \
+t/mkdirp-deprecation.sh \
+t/mkinstall.sh \
+t/mkinst2.sh \
+t/mkinst3.sh \
+t/mmode.sh \
+t/mmodely.sh \
+t/no-extra-c-stuff.sh \
+t/no-extra-makefile-code.sh \
+t/no-spurious-install-recursive.sh \
+t/nobase.sh \
+t/nobase-libtool.sh \
+t/nobase-python.sh \
+t/nobase-nodist.sh \
+t/nodef.sh \
+t/nodef2.sh \
+t/nodep.sh \
+t/nodep2.sh \
+t/nodepcomp.sh \
+t/nodist.sh \
+t/nodist2.sh \
+t/nodist3.sh \
+t/noinst.sh \
+t/noinstdir.sh \
+t/nolink.sh \
+t/nostdinc.sh \
+t/notrans.sh \
+t/number.sh \
+t/objc-basic.sh \
+t/objc-minidemo.sh \
+t/objc-flags.sh \
+t/objc-deps.sh \
+t/objcxx-basic.sh \
+t/objcxx-minidemo.sh \
+t/objcxx-flags.sh \
+t/objcxx-deps.sh \
+t/objc-megademo.sh \
+t/objext-pr10128.sh \
+t/oldvars.sh \
+t/order.sh \
+t/output.sh \
+t/output2.sh \
+t/output3.sh \
+t/output4.sh \
+t/output5.sh \
+t/output6.sh \
+t/output7.sh \
+t/output8.sh \
+t/output9.sh \
+t/output10.sh \
+t/output11.sh \
+t/output12.sh \
+t/output13.sh \
+t/output-order.sh \
+t/override-conditional-1.sh \
+t/override-conditional-2.sh \
+t/override-conditional-pr13940.sh \
+t/override-html.sh \
+t/override-suggest-local.sh \
+t/parallel-am.sh \
+t/parallel-am2.sh \
+t/parallel-am3.sh \
+t/serial-tests.sh \
+t/parallel-tests-basics.sh \
+t/parallel-tests-concurrency.sh \
+t/parallel-tests-concurrency-2.sh \
+t/parallel-tests-empty.sh \
+t/parallel-tests-exit-status-reported.sh \
+t/parallel-tests-generated-and-distributed.sh \
+t/parallel-tests-recheck.sh \
+t/parallel-tests-trailing-whitespace.sh \
+t/parallel-tests-recheck-depends-on-all.sh \
+t/parallel-tests-recheck-pr11791.sh \
+t/parallel-tests-exeext.sh \
+t/parallel-tests-suffix.sh \
+t/parallel-tests-suffix-prog.sh \
+t/parallel-tests-log-compiler-1.sh \
+t/parallel-tests-log-compiler-2.sh \
+t/parallel-tests-dry-run-1.sh \
+t/parallel-tests-dry-run-2.sh \
+t/parallel-tests-fd-redirect.sh \
+t/parallel-tests-fd-redirect-exeext.sh \
+t/parallel-tests-extra-programs.sh \
+t/parallel-tests-unreadable.sh \
+t/parallel-tests-subdir.sh \
+t/parallel-tests-interrupt.tap \
+t/parallel-tests-reset-term.sh \
+t/parallel-tests-harderror.sh \
+t/parallel-tests-log-override-1.sh \
+t/parallel-tests-log-override-2.sh \
+t/parallel-tests-log-override-recheck.sh \
+t/parallel-tests-log-compiler-example.sh \
+t/parallel-tests-cmdline-override.sh \
+t/parallel-tests-fork-bomb.sh \
+t/parallel-tests-empty-testlogs.sh \
+t/parallel-tests-driver-install.sh \
+t/parallel-tests-no-color-in-log.sh \
+t/parallel-tests-no-spurious-summary.sh \
+t/parallel-tests-exit-statuses.sh \
+t/parallel-tests-console-output.sh \
+t/parallel-tests-once.sh \
+t/tests-environment.sh \
+t/am-tests-environment.sh \
+t/tests-environment-backcompat.sh \
+t/testsuite-summary-color.sh \
+t/testsuite-summary-count.sh \
+t/testsuite-summary-count-many.sh \
+t/testsuite-summary-reference-log.sh \
+t/test-driver-acsubst.sh \
+t/test-driver-cond.sh \
+t/test-driver-custom-no-extra-driver.sh \
+t/test-driver-custom.sh \
+t/test-driver-custom-xfail-tests.sh \
+t/test-driver-custom-multitest.sh \
+t/test-driver-custom-multitest-recheck.sh \
+t/test-driver-custom-multitest-recheck2.sh \
+t/test-driver-create-log-dir.sh \
+t/test-driver-strip-vpath.sh \
+t/test-driver-trs-suffix-registered.sh \
+t/test-driver-fail.sh \
+t/test-driver-is-distributed.sh \
+t/test-harness-vpath-rewrite.sh \
+t/test-log.sh \
+t/test-logs-repeated.sh \
+t/test-metadata-global-log.sh \
+t/test-metadata-global-result.sh \
+t/test-metadata-recheck.sh \
+t/test-metadata-results.sh \
+t/test-missing.sh \
+t/test-missing2.sh \
+t/test-trs-basic.sh \
+t/test-trs-recover.sh \
+t/test-trs-recover2.sh \
+t/test-extensions.sh \
+t/test-extensions-cond.sh \
+t/parse.sh \
+t/percent.sh \
+t/percent2.sh \
+t/per-target-flags.sh \
+t/phony.sh \
+t/precious.sh \
+t/pluseq.sh \
+t/pluseq2.sh \
+t/pluseq3.sh \
+t/pluseq4.sh \
+t/pluseq5.sh \
+t/pluseq6.sh \
+t/pluseq7.sh \
+t/pluseq8.sh \
+t/pluseq9.sh \
+t/pluseq10.sh \
+t/pluseq11.sh \
+t/posixsubst-data.sh \
+t/posixsubst-extradist.sh \
+t/posixsubst-ldadd.sh \
+t/posixsubst-libraries.sh \
+t/posixsubst-ltlibraries.sh \
+t/posixsubst-programs.sh \
+t/posixsubst-scripts.sh \
+t/posixsubst-sources.sh \
+t/posixsubst-tests.sh \
+t/ppf77.sh \
+t/pr2.sh \
+t/pr9.sh \
+t/pr72.sh \
+t/pr87.sh \
+t/pr211.sh \
+t/pr220.sh \
+t/pr224.sh \
+t/pr229.sh \
+t/pr243.sh \
+t/pr266.sh \
+t/pr279.sh \
+t/pr279-2.sh \
+t/pr287.sh \
+t/pr300-lib.sh \
+t/pr300-ltlib.sh \
+t/pr300-prog.sh \
+t/pr307.sh \
+t/pr401.sh \
+t/pr401b.sh \
+t/pr401c.sh \
+t/prefix.sh \
+t/preproc-basics.sh \
+t/preproc-c-compile.sh \
+t/preproc-demo.sh \
+t/preproc-errmsg.sh \
+t/primary.sh \
+t/primary2.sh \
+t/primary3.sh \
+t/primary-prefix-invalid-couples.tap \
+t/primary-prefix-valid-couples.sh \
+t/primary-prefix-couples-force-valid.sh \
+t/primary-prefix-couples-documented-valid.sh \
+t/print-libdir.sh \
+t/proginst.sh \
+t/programs-primary-rewritten.sh \
+t/py-compile-basic.sh \
+t/py-compile-basedir.sh \
+t/py-compile-destdir.sh \
+t/py-compile-env.sh \
+t/py-compile-option-terminate.sh \
+t/py-compile-usage.sh \
+t/python.sh \
+t/python2.sh \
+t/python3.sh \
+t/python10.sh \
+t/python11.sh \
+t/python12.sh \
+t/python-am-path-iftrue.sh \
+t/python-missing.sh \
+t/python-too-old.sh \
+t/python-dist.sh \
+t/python-vars.sh \
+t/python-virtualenv.sh \
+t/python-pr10995.sh \
+t/recurs-user.sh \
+t/recurs-user2.sh \
+t/recurs-user-deeply-nested.sh \
+t/recurs-user-indir.sh \
+t/recurs-user-keep-going.sh \
+t/recurs-user-many.sh \
+t/recurs-user-no-subdirs.sh \
+t/recurs-user-no-top-level.sh \
+t/recurs-user-override.sh \
+t/recurs-user-phony.sh \
+t/recurs-user-wrap.sh \
+t/relativize.tap \
+t/remake-fail.sh \
+t/remake-not-after-make-dist.sh \
+t/remake-maintainer-mode.sh \
+t/remake-makefile-intree.sh \
+t/remake-makefile-vpath.sh \
+t/remake-after-configure-ac.sh \
+t/remake-after-makefile-am.sh \
+t/remake-after-acinclude-m4.sh \
+t/remake-after-aclocal-m4.sh \
+t/remake-include-configure.sh \
+t/remake-include-makefile.sh \
+t/remake-include-aclocal.sh \
+t/remake-config-status-dependencies.sh \
+t/remake-configure-dependencies.sh \
+t/remake-deeply-nested.sh \
+t/remake-mild-stress.sh \
+t/remake-all-1.sh \
+t/remake-all-2.sh \
+t/remake-recurs-user.sh \
+t/remake-subdir.sh \
+t/remake-subdir2.sh \
+t/remake-subdir3.sh \
+t/remake-subdir-only.sh \
+t/remake-subdir-grepping.sh \
+t/remake-subdir-from-subdir.sh \
+t/remake-subdir-gnu.sh \
+t/remake-subdir-no-makefile.sh \
+t/remake-subdir-long-time.sh \
+t/remake-gnulib-add-acsubst.sh \
+t/remake-gnulib-add-header.sh \
+t/remake-gnulib-remove-header.sh \
+t/remake-moved-m4-file.sh \
+t/remake-deleted-m4-file.sh \
+t/remake-renamed-m4-file.sh \
+t/remake-renamed-m4-macro-and-file.sh \
+t/remake-renamed-m4-macro.sh \
+t/remake-am-pr10111.sh \
+t/remake-m4-pr10111.sh \
+t/remake-deleted-am-2.sh \
+t/remake-deleted-am-subdir.sh \
+t/remake-deleted-am.sh \
+t/remake-renamed-am.sh \
+t/remake-aclocal-version-mismatch.sh \
+t/remake-macrodir.sh \
+t/remake-timing-bug-pr8365.sh \
+t/reqd2.sh \
+t/repeated-options.sh \
+t/rm-f-probe.sh \
+t/rulepat.sh \
+t/self-check-cc-no-c-o.sh \
+t/self-check-configure-help.sh \
+t/self-check-dir.tap \
+t/self-check-exit.tap \
+t/self-check-explicit-skips.sh \
+t/self-check-is_newest.tap \
+t/self-check-me.tap \
+t/self-check-report.sh \
+t/self-check-seq.tap \
+t/self-check-shell-no-trail-bslash.sh \
+t/self-check-is-blocked-signal.tap \
+t/self-check-unindent.tap \
+t/sanity.sh \
+t/seenc.sh \
+t/silent-c.sh \
+t/silent-cxx.sh \
+t/silent-lt.sh \
+t/silent-f77.sh \
+t/silent-f90.sh \
+t/silent-many-languages.sh \
+t/silent-gen.sh \
+t/silent-texi.sh \
+t/silent-lex.sh \
+t/silent-yacc.sh \
+t/silent-yacc-headers.sh \
+t/silent-configsite.sh \
+t/silent-nested-vars.sh \
+t/silent-custom.sh \
+t/src-acsubst.sh \
+t/sourcefile-in-subdir.sh \
+t/space.sh \
+t/specflg6.sh \
+t/specflg7.sh \
+t/specflg8.sh \
+t/specflg9.sh \
+t/specflg-dummy.sh \
+t/spell.sh \
+t/spell2.sh \
+t/spell3.sh \
+t/spelling.sh \
+t/spy-double-colon.sh \
+t/spy-rm.tap \
+t/stdinc.sh \
+t/stamph2.sh \
+t/stdlib.sh \
+t/stdlib2.sh \
+t/strictness-override.sh \
+t/strictness-precedence.sh \
+t/strip.sh \
+t/strip2.sh \
+t/strip3.sh \
+t/subdir.sh \
+t/subdir-ac-subst.sh \
+t/subdir-add-pr46.sh \
+t/subdir-add2-pr46.sh \
+t/subdir-am-cond.sh \
+t/subdir-cond-err.sh \
+t/subdir-cond-gettext.sh \
+t/subdir-env-interference.sh \
+t/subdir-order.sh \
+t/subdir-with-slash.sh \
+t/subdir-subsub.sh \
+t/subdir-distclean.sh \
+t/subdir-keep-going-pr12554.sh \
+t/subobj.sh \
+t/subobj2.sh \
+t/subobj4.sh \
+t/subobj5.sh \
+t/subobj6.sh \
+t/subobj7.sh \
+t/subobj8.sh \
+t/subobj9.sh \
+t/subobj10.sh \
+t/subobj11a.sh \
+t/subobj11b.sh \
+t/subobj11c.sh \
+t/subobjname.sh \
+t/subobj-clean-pr10697.sh \
+t/subobj-clean-lt-pr10697.sh \
+t/subobj-indir-pr13928.sh \
+t/subobj-objname-clash.sh \
+t/subobj-vpath-pr13928.sh \
+t/subobj-pr13928-more-langs.sh \
+t/subpkg.sh \
+t/subpkg2.sh \
+t/subpkg3.sh \
+t/subpkg4.sh \
+t/subpkg-yacc.sh \
+t/subpkg-macrodir.sh \
+t/subst.sh \
+t/subst3.sh \
+t/subst4.sh \
+t/subst5.sh \
+t/subst-no-trailing-empty-line.sh \
+t/substref.sh \
+t/substre2.sh \
+t/substtarg.sh \
+t/suffix.sh \
+t/suffix2.sh \
+t/suffix3.tap \
+t/suffix4.sh \
+t/suffix5.sh \
+t/suffix6.sh \
+t/suffix6b.sh \
+t/suffix6c.sh \
+t/suffix7.sh \
+t/suffix8.tap \
+t/suffix9.sh \
+t/suffix10.tap \
+t/suffix11.tap \
+t/suffix-chain.tap \
+t/suffix-custom-pr14441.sh \
+t/suffix-custom-subobj.sh \
+t/suffix-custom-subobj-and-specflg.sh \
+t/suffix-extra-c-stuff-pr14560.sh \
+t/symlink.sh \
+t/symlink2.sh \
+t/syntax.sh \
+t/tap-ambiguous-directive.sh \
+t/tap-autonumber.sh \
+t/tap-bailout.sh \
+t/tap-bailout-leading-space.sh \
+t/tap-bailout-and-logging.sh \
+t/tap-bailout-suppress-badexit.sh \
+t/tap-bailout-suppress-later-diagnostic.sh \
+t/tap-bailout-suppress-later-errors.sh \
+t/tap-color.sh \
+t/tap-deps.sh \
+t/tap-diagnostic.sh \
+t/tap-empty-diagnostic.sh \
+t/tap-empty.sh \
+t/tap-escape-directive.sh \
+t/tap-escape-directive-2.sh \
+t/tap-exit.sh \
+t/tap-signal.tap \
+t/tap-fancy.sh \
+t/tap-fancy2.sh \
+t/tap-global-log.sh \
+t/tap-global-result.sh \
+t/tap-log.sh \
+t/tap-msg0-result.sh \
+t/tap-msg0-directive.sh \
+t/tap-msg0-planskip.sh \
+t/tap-msg0-bailout.sh \
+t/tap-msg0-misc.sh \
+t/tap-merge-stdout-stderr.sh \
+t/tap-no-merge-stdout-stderr.sh \
+t/tap-no-disable-hard-error.sh \
+t/tap-no-spurious-summary.sh \
+t/tap-no-spurious-numbers.sh \
+t/tap-no-spurious.sh \
+t/tap-not-ok-skip.sh \
+t/tap-number-wordboundary.sh \
+t/tap-numeric-description.sh \
+t/tap-negative-numbers.sh \
+t/tap-numbers-leading-zero.sh \
+t/tap-out-of-order.sh \
+t/tap-passthrough.sh \
+t/tap-passthrough-exit.sh \
+t/tap-plan.sh \
+t/tap-plan-corner.sh \
+t/tap-plan-errors.sh \
+t/tap-plan-middle.sh \
+t/tap-plan-whitespace.sh \
+t/tap-plan-leading-zero.sh \
+t/tap-plan-malformed.sh \
+t/tap-missing-plan-and-bad-exit.sh \
+t/tap-planskip.sh \
+t/tap-planskip-late.sh \
+t/tap-planskip-and-logging.sh \
+t/tap-planskip-unplanned.sh \
+t/tap-planskip-unplanned-corner.sh \
+t/tap-planskip-case-insensitive.sh \
+t/tap-planskip-whitespace.sh \
+t/tap-planskip-badexit.sh \
+t/tap-planskip-bailout.sh \
+t/tap-planskip-later-errors.sh \
+t/tap-test-number-0.sh \
+t/tap-recheck-logs.sh \
+t/tap-result-comment.sh \
+t/tap-todo-skip-together.sh \
+t/tap-todo-skip-whitespace.sh \
+t/tap-todo-skip.sh \
+t/tap-unplanned.sh \
+t/tap-whitespace-normalization.sh \
+t/tap-with-and-without-number.sh \
+t/tap-xfail-tests.sh \
+t/tap-common-setup.sh \
+t/tap-bad-prog.tap \
+t/tap-basic.sh \
+t/tap-diagnostic-custom.sh \
+t/tap-driver-stderr.sh \
+t/tap-doc.sh \
+t/tap-doc2.sh \
+t/tap-more.sh \
+t/tap-more2.sh \
+t/tap-recheck.sh \
+t/tap-summary.sh \
+t/tap-summary-color.sh \
+t/tags.sh \
+t/tags2.sh \
+t/tagsub.sh \
+t/tags-pr12372.sh \
+t/tar-ustar.sh \
+t/tar-pax.sh \
+t/tar-opts-errors.sh \
+t/tar-ustar-id-too-high.sh \
+t/tar-override.sh \
+t/target-cflags.sh \
+t/targetclash.sh \
+t/tests-environment-fd-redirect.sh \
+t/tests-environment-and-log-compiler.sh \
+t/txinfo-absolute-srcdir-pr408.sh \
+t/txinfo-add-missing-and-dist.sh \
+t/txinfo-bsd-make-recurs.sh \
+t/txinfo-builddir.sh \
+t/txinfo-clean.sh \
+t/txinfo-dvi-recurs.sh \
+t/txinfo-info-in-srcdir.sh \
+t/txinfo-include.sh \
+t/txinfo-makeinfo-error-no-clobber.sh \
+t/txinfo-many-output-formats.sh \
+t/txinfo-many-output-formats-vpath.sh \
+t/txinfo-nodist-info.sh \
+t/txinfo-no-clutter.sh \
+t/txinfo-no-extra-dist.sh \
+t/txinfo-no-installinfo.sh \
+t/txinfo-no-repeated-targets.sh \
+t/txinfo-other-suffixes.sh \
+t/txinfo-override-infodeps.sh \
+t/txinfo-override-texinfo-tex.sh \
+t/txinfo-setfilename-repeated.sh \
+t/txinfo-setfilename-suffix-strip.sh \
+t/txinfo-subdir-pr343.sh \
+t/txinfo-tex-dist.sh \
+t/txinfo-unrecognized-extension.sh \
+t/txinfo-unrecognized-info-suffix.sh \
+t/txinfo-vtexi.sh \
+t/txinfo-vtexi2.sh \
+t/txinfo-vtexi3.sh \
+t/txinfo-vtexi4.sh \
+t/txinfo-without-info-suffix.sh \
+t/txinfo19.sh \
+t/txinfo23.sh \
+t/txinfo24.sh \
+t/txinfo25.sh \
+t/txinfo28.sh \
+t/transform.sh \
+t/transform2.sh \
+t/transform3.sh \
+t/uninstall-fail.sh \
+t/uninstall-pr9578.sh \
+t/unused.sh \
+t/upc.sh \
+t/upc2.sh \
+t/upc3.sh \
+t/vala-configure.sh \
+t/vala-grepping.sh \
+t/vala-headers.sh \
+t/vala-libs.sh \
+t/vala-mix.sh \
+t/vala-mix2.sh \
+t/vala-non-recursive-setup.sh \
+t/vala-parallel.sh \
+t/vala-per-target-flags.sh \
+t/vala-recursive-setup.sh \
+t/vala-vapi.sh \
+t/vala-vpath.sh \
+t/vars.sh \
+t/vars3.sh \
+t/var-recurs.sh \
+t/var-recurs2.sh \
+t/vartar.sh \
+t/vartypos.sh \
+t/vartypo2.sh \
+t/version3.sh \
+t/version4.sh \
+t/version6.sh \
+t/version7.sh \
+t/version8.sh \
+t/vpath.sh \
+t/warnings-obsolete-default.sh \
+t/warnings-override.sh \
+t/warnings-precedence.sh \
+t/warnings-strictness-interactions.sh \
+t/warnings-unknown.sh \
+t/warnopts.sh \
+t/warnings-win-over-strictness.sh \
+t/warning-groups-win-over-strictness.sh \
+t/werror.sh \
+t/werror2.sh \
+t/werror3.sh \
+t/werror4.sh \
+t/whoami.sh \
+t/xsource.sh \
+t/yacc-misc.sh \
+t/yacc-dry.sh \
+t/yacc-cxx-grepping.sh \
+t/yacc-vpath.sh \
+t/yacc-auxdir.sh \
+t/yacc-basic.sh \
+t/yacc-cxx.sh \
+t/yacc-bison-skeleton-cxx.sh \
+t/yacc-bison-skeleton.sh \
+t/yacc-clean.sh \
+t/yacc-clean-cxx.sh \
+t/yacc-d-basic.sh \
+t/yacc-d-cxx.sh \
+t/yacc-d-vpath.sh \
+t/yacc-deleted-headers.sh \
+t/yacc-depend.sh \
+t/yacc-depend2.sh \
+t/yacc-dist-nobuild-subdir.sh \
+t/yacc-dist-nobuild.sh \
+t/yacc-grepping.sh \
+t/yacc-grepping2.sh \
+t/yacc-headers-and-dist-pr47.sh \
+t/yacc-line.sh \
+t/yacc-mix-c-cxx.sh \
+t/yacc-nodist.sh \
+t/yacc-pr204.sh \
+t/yacc-subdir.sh \
+t/yacc-weirdnames.sh \
+t/yflags.sh \
+t/yflags-cxx.sh \
+t/yflags-cmdline-override.sh \
+t/yflags-conditional.sh \
+t/yflags-d-false-positives.sh \
+t/yflags-force-conditional.sh \
+t/yflags-force-override.sh \
+t/yflags-var-expand.sh \
+t/libtool-macros.sh \
+t/gettext-macros.sh \
+t/pkg-config-macros.sh
+
+print-list-of-tests:
+ @echo $(handwritten_TESTS)
+.PHONY: print-list-of-tests
diff --git a/t/listval.sh b/t/listval.sh
new file mode 100644
index 000000000..95970c705
--- /dev/null
+++ b/t/listval.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure variable is expanded properly.
+# From Adam J. Richter.
+
+required=libtool
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([LTLIBOBJS])
+AM_PROG_AR
+AC_PROG_LIBTOOL
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libpanel_applet.la
+libpanel_applet_la_SOURCES = \
+ applet-widget.c
+libpanel_applet_la_LDFLAGS = -version-info 0:1:0 -rpath $(libdir)
+libpanel_applet_la_LIBADD = -lm
+END
+
+: > ltconfig
+: > ltmain.sh
+: > ar-lib
+: > config.guess
+: > config.sub
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/local.mk b/t/local.mk
new file mode 100644
index 000000000..082edb0a9
--- /dev/null
+++ b/t/local.mk
@@ -0,0 +1,268 @@
+## Included by top-level Makefile for Automake.
+
+## Copyright (C) 1995-2017 Free Software Foundation, Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+## ------------ ##
+## Testsuite. ##
+## ------------ ##
+
+# Run the tests with a proper shell detected at configure time.
+LOG_COMPILER = ./pre-inst-env $(AM_TEST_RUNNER_SHELL)
+
+TEST_EXTENSIONS = .pl .sh .tap
+SH_LOG_COMPILER = $(LOG_COMPILER)
+TAP_LOG_COMPILER = $(LOG_COMPILER)
+PL_LOG_COMPILER = ./pre-inst-env $(PERL)
+AM_PL_LOG_FLAGS = -Mstrict -w
+
+TAP_LOG_DRIVER = AM_TAP_AWK='$(AWK)' $(SHELL) $(srcdir)/lib/tap-driver.sh
+
+AM_TAP_LOG_DRIVER_FLAGS = --merge
+
+EXTRA_DIST += %D%/README %D%/ax/is %D%/ax/is_newest %D%/ax/deltree.pl
+
+
+## Will be updated later.
+TESTS =
+
+# Some testsuite-influential variables should be overridable from the
+# test scripts, but not from the environment.
+# Keep this in sync with the similar list in ax/runtest.in.
+AM_TESTS_ENVIRONMENT = \
+ for v in \
+ required \
+ am_test_protocol \
+ am_serial_tests \
+ am_test_prefer_config_shell \
+ am_original_AUTOMAKE \
+ am_original_ACLOCAL \
+ am_test_lib_sourced \
+ test_lib_sourced \
+ ; do \
+ eval test x"\$${$$v}" = x || unset $$v; \
+ done;
+# We want warning messages and explanations for skipped tests to go to
+# the console if possible, so set up 'stderr_fileno_' properly.
+AM_TESTS_FD_REDIRECT = 9>&2
+AM_TESTS_ENVIRONMENT += stderr_fileno_=9; export stderr_fileno_;
+
+# For sourcing of extra "shell libraries" by our test scripts. As per
+# POSIX, sourcing a file with '.' will cause it to be looked up in $PATH
+# in case it is given with a relative name containing no slashes.
+AM_TESTS_ENVIRONMENT += \
+ if test $(srcdir) != .; then \
+ PATH='$(abs_srcdir)/%D%/ax$(PATH_SEPARATOR)'$$PATH; \
+ fi; \
+ PATH='$(abs_builddir)/%D%/ax$(PATH_SEPARATOR)'$$PATH; \
+ export PATH;
+
+# Hand-written tests.
+
+include $(srcdir)/%D%/list-of-tests.mk
+
+TESTS += $(handwritten_TESTS)
+EXTRA_DIST += $(handwritten_TESTS)
+
+# Automatically-generated tests wrapping hand-written ones.
+# Also, automatically-computed dependencies for tests.
+
+include $(srcdir)/%D%/testsuite-part.am
+
+TESTS += $(generated_TESTS)
+EXTRA_DIST += $(generated_TESTS)
+
+$(srcdir)/%D%/testsuite-part.am:
+ $(AM_V_at)rm -f %D%/testsuite-part.tmp $@
+ $(AM_V_GEN)$(PERL) $(srcdir)/gen-testsuite-part \
+ --srcdir $(srcdir) > %D%/testsuite-part.tmp
+ $(AM_V_at)chmod a-w %D%/testsuite-part.tmp
+ $(AM_V_at)mv -f %D%/testsuite-part.tmp $@
+EXTRA_DIST += gen-testsuite-part
+
+# The dependecies declared here are not truly complete, but such
+# completeness would cause more issues than it would solve. See
+# automake bug#11347.
+$(generated_TESTS): $(srcdir)/gen-testsuite-part
+$(srcdir)/%D%/testsuite-part.am: $(srcdir)/gen-testsuite-part
+$(srcdir)/%D%/testsuite-part.am: Makefile.am
+
+# Hand-written tests for stuff in 'contrib/'.
+include $(srcdir)/contrib/%D%/local.mk
+TESTS += $(contrib_TESTS)
+EXTRA_DIST += $(contrib_TESTS)
+
+# Static dependencies valid for each test case (also further
+# extended later). Note that use 'noinst_' rather than 'check_'
+# as the prefix, because we really want them to be built by
+# "make all". This makes it easier to run the test cases by
+# hand after having simply configured and built the package.
+
+dist_noinst_DATA += \
+ %D%/ax/test-init.sh \
+ %D%/ax/test-lib.sh \
+ %D%/ax/am-test-lib.sh \
+ %D%/ax/tap-functions.sh
+
+# Few more static dependencies.
+%D%/distcheck-missing-m4.log: %D%/ax/distcheck-hook-m4.am
+%D%/distcheck-outdated-m4.log: %D%/ax/distcheck-hook-m4.am
+EXTRA_DIST += %D%/ax/distcheck-hook-m4.am
+
+%D%/ax/test-defs.sh: %D%/ax/test-defs.in Makefile
+ $(AM_V_at)rm -f $@ $@-t
+ $(AM_V_at)$(MKDIR_P) %D%/ax
+ $(AM_V_GEN)in=%D%/ax/test-defs.in \
+ && $(do_subst) <$(srcdir)/$$in >$@-t
+ $(generated_file_finalize)
+EXTRA_DIST += %D%/ax/test-defs.in
+CLEANFILES += %D%/ax/test-defs.sh
+nodist_noinst_DATA += %D%/ax/test-defs.sh
+
+%D%/ax/shell-no-trail-bslash: %D%/ax/shell-no-trail-bslash.in Makefile
+ $(AM_V_at)rm -f $@ $@-t
+ $(AM_V_GEN)in=%D%/ax/shell-no-trail-bslash.in \
+ && $(MKDIR_P) %D%/ax \
+ && $(do_subst) <$(srcdir)/$$in >$@-t \
+ && chmod a+x $@-t
+ $(generated_file_finalize)
+EXTRA_DIST += %D%/ax/shell-no-trail-bslash.in
+CLEANFILES += %D%/ax/shell-no-trail-bslash
+nodist_noinst_SCRIPTS += %D%/ax/shell-no-trail-bslash
+
+%D%/ax/cc-no-c-o: %D%/ax/cc-no-c-o.in Makefile
+ $(AM_V_at)rm -f $@ $@-t
+ $(AM_V_GEN)in=%D%/ax/cc-no-c-o.in \
+ && $(MKDIR_P) %D%/ax \
+ && $(do_subst) <$(srcdir)/$$in >$@-t \
+ && chmod a+x $@-t
+ $(generated_file_finalize)
+EXTRA_DIST += %D%/ax/cc-no-c-o.in
+CLEANFILES += %D%/ax/cc-no-c-o
+nodist_noinst_SCRIPTS += %D%/ax/cc-no-c-o
+
+runtest: %D%/ax/runtest.in Makefile
+ $(AM_V_at)rm -f $@ $@-t
+ $(AM_V_GEN)in=%D%/ax/runtest.in \
+ && $(MKDIR_P) %D%/ax \
+ && $(do_subst) <$(srcdir)/$$in >$@-t \
+ && chmod a+x $@-t
+ $(generated_file_finalize)
+EXTRA_DIST += %D%/ax/runtest.in
+CLEANFILES += runtest
+nodist_noinst_SCRIPTS += runtest
+
+# If two test scripts have the same basename, they will end up sharing
+# the same log file, leading to all sort of undefined and undesired
+# behaviours.
+check-no-repeated-test-name:
+ @LC_ALL=C; export LC_ALL; \
+ lst='$(TEST_LOGS)'; for log in $$lst; do echo $$log; done \
+ | sort | uniq -c | awk '($$1 > 1) { print }' \
+ | sed 's/\.log$$//' | grep . >&2 \
+ && { \
+ echo $@: test names listed above are duplicated >&2; \
+ exit 1; \
+ }; :
+check-local: check-no-repeated-test-name
+.PHONY: check-no-repeated-test-name
+
+# Check that our test cases are syntactically correct.
+# See automake bug#11898.
+check-tests-syntax:
+ @st=0; \
+ err () { echo "$@: $$*" >&2; st=1; }; \
+## The user might do something like "make check TESTS=t/foo" or
+## "make check TESTS_LOGS=t/foo.log" and expect (say) the test
+## 't/foo.sh' to be run; this has worked well until today, and
+## we want to continue supporting this use case.
+ bases=`for log in : $(TEST_LOGS); do echo $$log; done \
+ | sed -e '/^:$$/d' -e 's/\.log$$//'`; \
+ for bas in $$bases; do \
+ for suf in sh tap pl; do \
+ tst=$$bas.$$suf; \
+## Emulate VPATH search.
+ if test -f $$tst; then \
+ break; \
+ elif test -f $(srcdir)/$$tst; then \
+ tst=$(srcdir)/$$tst; \
+ break; \
+ else \
+ tst=''; \
+ fi; \
+ done; \
+ test -n "$$tst" || err "couldn't find test '$$bas'"; \
+## Don't check that perl tests are valid shell scripts!
+ test $$suf = pl && continue; \
+ $(AM_V_P) && echo " $(AM_TEST_RUNNER_SHELL) -n $$tst"; \
+ $(AM_TEST_RUNNER_SHELL) -n "$$tst" \
+ || err "test '$$tst' syntactically invalid"; \
+ done; \
+ exit $$st
+check-local: check-tests-syntax
+.PHONY: check-tests-syntax
+
+# Recipes with a trailing backslash character (possibly followed by
+# blank characters only) can cause spurious syntax errors with at
+# least older bash versions (e.g., bash 2.05b), and can be potentially
+# be unportable to other weaker shells. Run the testsuite in a way
+# that helps catching such problems in Automake-generated recipes.
+# See automake bug#10436.
+check-no-trailing-backslash-in-recipes:
+ $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) check \
+ CONFIG_SHELL='$(abs_top_builddir)/%D%/ax/shell-no-trail-bslash'
+.PHONY: check-no-trailing-backslash-in-recipes
+
+# Some compilers out there (hello, MSVC) still choke on "-c -o" being
+# passed together on the command line. Run the whole testsuite faking
+# the presence of such a compiler, to help catch regressions that would
+# otherwise only present themselves later "in the wild". See also the
+# long discussion about automake bug#13378.
+check-cc-no-c-o:
+ $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) check \
+ AM_TESTSUITE_SIMULATING_NO_CC_C_O=yes
+.PHONY: check-cc-no-c-o
+
+# Automake-generated Makefiles should work when run with parallel make.
+check-parallel:
+ $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) check \
+ AM_TESTSUITE_MAKE="$${AM_TESTSUITE_MAKE-$${MAKE-make}} -j4"
+.PHONY: check-parallel
+
+## Checking the list of tests.
+test_subdirs = %D% %D%/pm contrib/%D%
+include %D%/CheckListOfTests.am
+
+# Run the testsuite with the installed aclocal and automake.
+installcheck-local: installcheck-testsuite
+installcheck-testsuite:
+ $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) check \
+ am_running_installcheck=yes
+
+# Performance tests.
+.PHONY: perf
+perf: all
+ $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) check \
+ TEST_SUITE_LOG='$(PERF_TEST_SUITE_LOG)' TESTS='$(perf_TESTS)'
+PERF_TEST_SUITE_LOG = %D%/perf/test-suite.log
+CLEANFILES += $(PERF_TEST_SUITE_LOG)
+EXTRA_DIST += $(perf_TESTS)
+
+clean-local: clean-local-check
+.PHONY: clean-local-check
+clean-local-check:
+ $(AM_V_GEN)$(PERL) $(srcdir)/t/ax/deltree.pl t/*.dir t/*/*.dir */t/*.dir
+
+# vim: ft=automake noet
diff --git a/t/location.sh b/t/location.sh
new file mode 100644
index 000000000..d13fc6251
--- /dev/null
+++ b/t/location.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for locations in error messages.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [true])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = libfoo.a
+if COND2
+ lib_LIBRARIES = libfoo.a
+endif
+if COND1
+ bin_PROGRAMS += ctags
+endif
+VAR = 1 \
+ 2 \
+ 3
+
+VAR = 1 \
+ 2 \
+ 3
+END
+
+: > ar-lib
+
+# Smash the useless difference of lib file locations.
+smash_useless_diffs ()
+{
+ sed -e "s,^$am_amdir/\\([a-z]*\.am\\),\\1," \
+ -e "s,^automake-$APIVERSION:,automake:," ${1+"$@"};
+}
+
+$ACLOCAL
+AUTOMAKE_fails -Wno-error
+
+smash_useless_diffs stderr >observed
+
+# Apparently useless use of sed here required to avoid spuriously
+# triggering some maintainer-checks failures.
+sed 's/^> //' > expected << 'END'
+> Makefile.am:12: warning: VAR multiply defined in condition TRUE ...
+> Makefile.am:8: ... 'VAR' previously defined here
+> automake: error: libfoo_a_OBJECTS should not be defined
+> Makefile.am:3: while processing library 'libfoo.a'
+> automake: error: use 'libfoo_a_LDADD', not 'libfoo_a_LIBADD'
+> Makefile.am:3: while processing library 'libfoo.a'
+> library.am: warning: deprecated feature: target 'libfoo.a' overrides 'libfoo.a$(EXEEXT)'
+> library.am: change your target to read 'libfoo.a$(EXEEXT)'
+> Makefile.am:3: while processing library 'libfoo.a'
+> program.am: target 'libfoo.a$(EXEEXT)' was defined here
+> Makefile.am:1: while processing program 'libfoo.a'
+> program.am: warning: redefinition of 'libfoo.a$(EXEEXT)' ...
+> Makefile.am:1: while processing program 'libfoo.a'
+> library.am: ... 'libfoo.a' previously defined here
+> Makefile.am:3: while processing library 'libfoo.a'
+> tags.am: warning: redefinition of 'ctags' ...
+> program.am: ... 'ctags$(EXEEXT)' previously defined here
+> Makefile.am:6: while processing program 'ctags'
+END
+
+cat expected
+cat observed
+diff expected observed || exit 1
+
+AUTOMAKE_fails -Werror
+smash_useless_diffs stderr >observed
+(echo 'automake: warnings are treated as errors' && cat expected) > t
+mv -f t expected
+
+cat expected
+cat observed
+
+diff expected observed || exit 1
+
+:
diff --git a/t/longlin2.sh b/t/longlin2.sh
new file mode 100644
index 000000000..858f3f95a
--- /dev/null
+++ b/t/longlin2.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Long lines should be wrapped.
+# Report from Albert Chin.
+
+. test-init.sh
+
+n=1 files= match=
+while test $n -le 100
+do
+ files="$files filename$n"
+ match="..........$match"
+ n=$(($n + 1))
+done
+files2=$(echo "$files" | sed s/filename/filenameb/g)
+
+cat >Makefile.am <<EOF
+FOO = $files $files2 \
+ grepme
+EOF
+
+# The 'FOO = ...' line is 2293-byte long. More than what a POSIX
+# conformant system is expected to support. So do not use grep
+# on the non-text file.
+
+# grep $match Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+grep $match Makefile.in && exit 1
+grep 'filenameb100 grepme' Makefile.in
+
+:
diff --git a/t/longline.sh b/t/longline.sh
new file mode 100644
index 000000000..25920c689
--- /dev/null
+++ b/t/longline.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Long lines of += should be wrapped.
+# Report from Simon Josefsson.
+
+. test-init.sh
+
+(echo DUMMY = some_long_filename_1;
+for i in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20;
+do
+ echo DUMMY += some_long_filename_$i
+done) > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+test 80 -ge $(grep DUMMY Makefile.in | wc -c)
+
+:
diff --git a/t/ltcond.sh b/t/ltcond.sh
new file mode 100644
index 000000000..1c013e821
--- /dev/null
+++ b/t/ltcond.sh
@@ -0,0 +1,106 @@
+#!/bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for conditional libtool libraries.
+# This combines two examples from the manual.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_CONDITIONAL([WANT_LIBFOO], [true])
+AM_CONDITIONAL([WANT_LIBBAR], [false])
+AC_SUBST([WANTEDLIBS], ['lib1foo.la lib1bar.la'])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+EXTRA_LTLIBRARIES = lib1foo.la lib1bar.la lib3bar.la
+lib_LTLIBRARIES = $(WANTEDLIBS)
+lib1foo_la_SOURCES = foo.c
+lib1foo_la_LDFLAGS = -rpath '$(libdir)'
+lib1bar_la_SOURCES = bar.c
+lib1bar_la_LDFLAGS = -rpath '$(libdir)'
+lib3bar_la_SOURCES = bar.c
+
+if WANT_LIBFOO
+lib_LTLIBRARIES += lib2foo.la
+check_LTLIBRARIES = lib3foo.la
+endif
+if WANT_LIBBAR
+lib_LTLIBRARIES += lib2bar.la
+endif
+lib2foo_la_SOURCES = foo.c
+lib2bar_la_SOURCES = bar.c
+lib3foo_la_SOURCES = foo.c
+END
+
+echo 'int one () { return 1; }' >foo.c
+echo 'int two () { return 2; }' >bar.c
+
+mkdir empty
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+# Install libraries in lib/, and the rest in empty/.
+# (in fact there is no "rest", so as the name imply empty/ is
+# expected to remain empty).
+./configure --prefix="$cwd/empty" --libdir="$cwd/lib"
+
+$MAKE
+test -f lib1foo.la
+test -f lib1bar.la
+test -f lib2foo.la
+test ! -e lib2bar.la
+test ! -e lib3foo.la
+test ! -e lib3bar.la
+
+$MAKE check
+test ! -e lib2bar.la
+test -f lib3foo.la
+test ! -e lib3bar.la
+
+$MAKE install
+test -f lib/lib1foo.la
+test -f lib/lib1bar.la
+test -f lib/lib2foo.la
+test ! -e lib/lib3foo.la
+find empty -type f -print > empty.lst
+test -s empty.lst && { cat empty.lst; exit 1; }
+
+$MAKE uninstall
+find lib -type f -print > lib.lst
+test -s lib.lst && { cat lib.lst; exit 1; }
+test -f lib1foo.la
+test -f lib1bar.la
+test -f lib2foo.la
+test -f lib3foo.la
+
+$MAKE clean
+test ! -e lib1foo.la
+test ! -e lib1bar.la
+test ! -e lib2foo.la
+test ! -e lib3foo.la
+
+:
diff --git a/t/ltcond2.sh b/t/ltcond2.sh
new file mode 100644
index 000000000..e39935107
--- /dev/null
+++ b/t/ltcond2.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in conditionals.
+
+required='cc native libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_SUBST([HELLO_SYSTEM], [hello-generic.lo])
+AM_CONDITIONAL([LINUX], [true])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libhello.la
+libhello_la_SOURCES = hello-common.c
+EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
+libhello_la_LIBADD = $(HELLO_SYSTEM)
+libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
+
+lib_LTLIBRARIES += libhello2.la
+libhello2_la_SOURCES = hello-common.c
+if LINUX
+libhello2_la_SOURCES += hello-linux.c
+else
+libhello2_la_SOURCES += hello-generic.c
+endif
+
+bin_PROGRAMS = hello hello2
+hello_SOURCES = main.c
+hello_LDADD = libhello.la
+hello2_SOURCES = main.c
+hello2_LDADD = libhello2.la
+
+check-local:
+ ./hello$(EXEEXT) | grep hello-generic
+ ./hello2$(EXEEXT) | grep hello-linux
+ : > check-ok
+END
+
+cat > hello-linux.c <<'END'
+const char* str = "hello-linux";
+END
+
+cat > hello-generic.c <<'END'
+const char* str = "hello-generic";
+END
+
+cat > hello-common.c <<'END'
+#include <stdio.h>
+extern const char* str;
+void print (void)
+{
+ puts (str);
+}
+END
+
+cat > main.c <<'END'
+int main (void)
+{
+ print();
+ return 0;
+}
+END
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE check
+test -f check-ok
+
+:
diff --git a/t/ltconv.sh b/t/ltconv.sh
new file mode 100644
index 000000000..6f8a6fc2d
--- /dev/null
+++ b/t/ltconv.sh
@@ -0,0 +1,158 @@
+#!/bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for libtool convenience libraries.
+# This example is taken from the manual.
+
+required='cc native libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_CONFIG_FILES([sub1/Makefile
+ sub2/Makefile
+ sub2/sub21/Makefile
+ sub2/sub22/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub1
+mkdir sub2
+mkdir sub2/sub21
+mkdir sub2/sub22
+mkdir empty
+
+cat >Makefile.am <<'END'
+SUBDIRS = sub1 sub2
+lib_LTLIBRARIES = libtop.la
+libtop_la_SOURCES =
+libtop_la_LIBADD = \
+ sub1/libsub1.la \
+ sub2/libsub2.la
+
+bin_PROGRAMS = ltconvtest
+ltconvtest_SOURCES = test.c
+ltconvtest_LDADD = libtop.la
+
+check-local:
+ ./ltconvtest$(EXEEXT)
+ : > check-ok
+installcheck-local:
+ $(bindir)/ltconvtest$(EXEEXT)
+ : > installcheck-ok
+END
+
+cat >sub1/Makefile.am <<'END'
+noinst_LTLIBRARIES = libsub1.la
+libsub1_la_SOURCES = sub1.c
+END
+
+echo 'int sub1 () { return 1; }' > sub1/sub1.c
+
+cat >sub2/Makefile.am <<'END'
+SUBDIRS = sub21 sub22
+noinst_LTLIBRARIES = libsub2.la
+libsub2_la_SOURCES = sub2.c
+libsub2_la_LIBADD = \
+ sub21/libsub21.la \
+ sub22/libsub22.la
+END
+
+echo 'int sub2 () { return 2; }' > sub2/sub2.c
+
+cat >sub2/sub21/Makefile.am <<'END'
+noinst_LTLIBRARIES = libsub21.la
+libsub21_la_SOURCES = sub21.c
+END
+
+echo 'int sub21 () { return 21; }' > sub2/sub21/sub21.c
+
+cat >sub2/sub22/Makefile.am <<'END'
+noinst_LTLIBRARIES = libsub22.la
+libsub22_la_SOURCES = sub22.c
+END
+
+echo 'int sub22 () { return 22; }' > sub2/sub22/sub22.c
+
+cat >test.c <<'EOF'
+#include <stdio.h>
+int main ()
+{
+ if (1 != sub1 ())
+ return 1;
+ if (2 != sub2 ())
+ return 2;
+ if (21 != sub21 ())
+ return 3;
+ if (22 != sub22 ())
+ return 4;
+ return 0;
+}
+EOF
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+# Install libraries in lib/, programs in bin/, and the rest in empty/.
+# (in fact there is no "rest", so as the name imply empty/ is
+# expected to remain empty).
+./configure --prefix="$cwd/empty" --libdir="$cwd/lib" --bindir="$cwd/bin"
+
+$MAKE
+test -f libtop.la
+test -f sub1/libsub1.la
+test -f sub2/libsub2.la
+test -f sub2/sub21/libsub21.la
+test -f sub2/sub22/libsub22.la
+$MAKE check
+test -f check-ok
+rm -f check-ok
+
+$MAKE install
+test -f lib/libtop.la
+$MAKE installcheck
+test -f installcheck-ok
+rm -f installcheck-ok
+
+find empty -type f -print > empty.lst
+test -s empty.lst && { cat empty.lst; exit 1; }
+
+$MAKE clean
+test ! -e libtop.la
+test ! -e sub1/libsub1.la
+test ! -e sub2/libsub2.la
+test ! -e sub2/sub21/libsub21.la
+test ! -e sub2/sub22/libsub22.la
+test ! -e ltconvtest
+
+$MAKE installcheck
+test -f installcheck-ok
+rm -f installcheck-ok
+
+$MAKE uninstall
+for d in lib bin; do
+ find $d -type f -print > $d.lst
+ test -s $d.lst && { cat $d.lst; exit 1; }
+ : For shells with busted 'set -e'.
+done
+
+:
diff --git a/t/ltdeps.sh b/t/ltdeps.sh
new file mode 100644
index 000000000..40e39a1df
--- /dev/null
+++ b/t/ltdeps.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure libtool library dependencies are correct.
+# Report from Lars J. Aas.
+required=libtool
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_PROG_CXX
+AM_CONDITIONAL(HACKING_COMPACT_BUILD, whatever)
+END
+
+cat > Makefile.am << 'END'
+RegularSources = \
+ SbBSPTree.cpp \
+ SbBox2f.cpp \
+ SbBox2s.cpp
+
+LinkHackSources = \
+ all.cpp
+
+if HACKING_COMPACT_BUILD
+BuildSources = $(LinkHackSources)
+else
+BuildSources = $(RegularSources)
+endif
+
+noinst_LTLIBRARIES = libbase.la
+libbase_la_SOURCES = $(BuildSources)
+
+EXTRA_libbase_la_SOURCES = \
+ $(RegularSources) $(LinkHackSources)
+END
+
+: > ltconfig
+: > ltmain.sh
+: > ar-lib
+: > config.guess
+: > config.sub
+
+$ACLOCAL
+$AUTOMAKE
+
+grep 'OBJECTS =$' Makefile.in && exit 1
+exit 0
diff --git a/t/ltinit.sh b/t/ltinit.sh
new file mode 100644
index 000000000..70b109083
--- /dev/null
+++ b/t/ltinit.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that libtool support works correctly when "newer" libtool
+# interface (with LT_INIT etc.) is used (this interface has been
+# present since libtool 1.9b, circa 2004).
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+dnl Older libtool versions don't define LT_PREREQ :-(
+m4_ifdef([LT_PREREQ],
+ [LT_PREREQ([2.0])],
+ [m4_fatal([Libtool version too old], [63])])
+LT_INIT([dlopen])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+lib_LTLIBRARIES = libfoo.la
+END
+
+cat > libfoo.c <<'END'
+int foo (void)
+{
+ return 1;
+}
+END
+
+libtoolize
+# Skip if older libtool (pre-2.0) is used.
+{ $ACLOCAL && $AUTOCONF; } || {
+ if test $? -eq 63; then
+ skip_ "libtool is too old (probably < 2.0)"
+ else
+ exit 1
+ fi
+}
+$EGREP 'LT_(INIT|PREREQ)' configure && exit 1 # Sanity check.
+$AUTOMAKE -a
+
+./configure --prefix="$(pwd)/inst" >stdout || { cat stdout; exit 1; }
+cat stdout
+grep '^checking.*dlfcn\.h.* no$' stdout || grep '^checking.*dlopen' stdout
+
+$MAKE
+$MAKE install
+$MAKE distcheck
+
+:
diff --git a/t/ltinstloc.sh b/t/ltinstloc.sh
new file mode 100644
index 000000000..521547bce
--- /dev/null
+++ b/t/ltinstloc.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for libtool errors for multiple install locations, esp. with nobase.
+
+
+required='libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AM_CONDITIONAL([COND], [:])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+if COND
+lib_LTLIBRARIES = liba1.la sub/liba2.la
+#else
+pkglib_LTLIBRARIES = liba1.la
+nobase_lib_LTLIBRARIES = sub/liba2.la
+endif
+AUTOMAKE_OPTIONS = subdir-objects
+END
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+AUTOMAKE_fails --add-missing
+
+# libtoolize might have installed config.guess and config.sub already,
+# and autom4te might warn about bugs in Libtool macro files, so filter
+# out warnings about Makefile.am only. We don't care in this test
+# whether automake installs config.guess, config.sub and ar-lib.
+
+cat >expected <<'END'
+Makefile.am:5: error: sub/liba2.la multiply defined in condition COND
+Makefile.am:5: 'sub/liba2.la' should be installed below 'lib' in condition COND ...
+Makefile.am:2: ... and should also be installed in 'lib' in condition COND.
+Makefile.am:4: error: liba1.la multiply defined in condition COND
+Makefile.am:4: 'liba1.la' should be installed in 'pkglib' in condition COND ...
+Makefile.am:2: ... and should also be installed in 'lib' in condition COND.
+Makefile.am:2: Libtool libraries can be built for only one destination
+END
+
+grep '^Makefile.am' stderr | diff - expected
+
+sed 's/#//' < Makefile.am > t
+mv -f t Makefile.am
+
+$AUTOMAKE
+grep ' -rpath \$(libdir)/sub' Makefile.in
+
+:
diff --git a/t/ltlibobjs.sh b/t/ltlibobjs.sh
new file mode 100644
index 000000000..4c00e4841
--- /dev/null
+++ b/t/ltlibobjs.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure LTLIBOBJS alone works ok.
+# Report from Vadim Zeitlin.
+required=libtool
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([LTLIBOBJS])
+AM_PROG_AR
+AC_PROG_LIBTOOL
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libtu.la
+libtu_la_SOURCES = foo.c
+libtu_la_LIBADD = @LTLIBOBJS@
+END
+
+: > ltconfig
+: > ltmain.sh
+: > ar-lib
+: > config.guess
+: > config.sub
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/ltlibsrc.sh b/t/ltlibsrc.sh
new file mode 100644
index 000000000..1ca9b71a9
--- /dev/null
+++ b/t/ltlibsrc.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure a sensible default source for libraries is used.
+
+required='cc libtool'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+mkdir zoo.d
+
+cat > Makefile.am << 'END'
+AM_LDFLAGS = -module
+pkglib_LTLIBRARIES = zoo.d/bar.la old.la
+noinst_LTLIBRARIES = foo.la zoo.d/old2.la
+
+$(srcdir)/zoo_d_old2_la.c: $(srcdir)/old_la.c
+ cp $(srcdir)/old_la.c $@
+
+AUTOMAKE_OPTIONS = -Wno-unsupported
+END
+
+cat > foo.c << 'END'
+int foo (void)
+{
+ return 0;
+}
+END
+
+cp foo.c zoo.d/bar.c
+cp foo.c old_la.c
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+AUTOMAKE_fails -a
+grep '^Makefile\.am:2:.*old_la\.c' stderr
+grep '^Makefile\.am:2:.*old\.c' stderr
+grep '^Makefile\.am:3:.*zoo_d_old2_la\.c' stderr
+grep '^Makefile\.am:3:.*zoo\.d/old2\.c' stderr
+
+$AUTOMAKE -Wno-obsolete
+
+mkdir sub
+cd sub
+
+../configure
+$MAKE
+
+test -f foo.la
+test -f zoo.d/bar.la
+test -f old.la
+test -f zoo.d/old2.la
+
+$MAKE distcheck
+
+:
diff --git a/t/ltorder.sh b/t/ltorder.sh
new file mode 100644
index 000000000..4e092037f
--- /dev/null
+++ b/t/ltorder.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for correct installation order of nobase libtool libraries.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+nobase_lib_LTLIBRARIES = liba1.la sub/liba2.la sub/liba3.la liba4.la liba5.la
+sub_liba2_la_LIBADD = liba1.la
+sub_liba3_la_LIBADD = sub/liba2.la
+liba4_la_LIBADD = sub/liba3.la
+liba5_la_LIBADD = liba4.la
+bin_PROGRAMS = p
+p_LDADD = liba5.la
+END
+
+mkdir sub
+echo 'int a1 () { return 1; }' >liba1.c
+echo 'extern int a1 (); int a2 () { return a1 (); }' >sub/liba2.c
+echo 'extern int a2 (); int a3 () { return a2 (); }' >sub/liba3.c
+echo 'extern int a3 (); int a4 () { return a3 (); }' >liba4.c
+echo 'extern int a4 (); int a5 () { return a4 (); }' >liba5.c
+echo 'extern int a5 (); int main () { return a5 (); }' >p.c
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure --prefix="$(pwd)/inst"
+
+$MAKE
+run_make -E install
+grep 'has not been installed' stderr && exit 1
+
+$MAKE uninstall
+test $(find inst -type f -print | wc -l) -eq 0
+
+:
diff --git a/t/m4-inclusion.sh b/t/m4-inclusion.sh
new file mode 100644
index 000000000..15f5f336f
--- /dev/null
+++ b/t/m4-inclusion.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to see if 'm4_sinclude' and 'm4_include' works.
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+sinclude([doesntexist.m4])
+EOF
+
+mkdir sub
+
+cat > sub/p.m4 << 'END'
+AC_SUBST([MAGICALPIG])
+END
+
+cat > sub/h.m4 << 'END'
+AC_SUBST([MAGICALHOG])
+END
+
+cat > sub/g.m4 << 'END'
+AC_SUBST([GREPME])
+END
+
+: > Makefile.am
+
+echo 'sinclude([sub/g.m4])' >> acinclude.m4
+echo 'm4_sinclude([sub/doesntexist.m4])' >> acinclude.m4
+
+$ACLOCAL
+
+echo 'm4_sinclude([sub/p.m4])' >> aclocal.m4
+echo 'm4_include([sub/h.m4])' >> aclocal.m4
+
+$AUTOMAKE
+
+grep doesntexist Makefile.in && exit 1
+grep MAGICALPIG Makefile.in
+grep MAGICALHOG Makefile.in
+grep GREPME Makefile.in
+
+:
diff --git a/t/maintclean-vpath.sh b/t/maintclean-vpath.sh
new file mode 100644
index 000000000..efb82c485
--- /dev/null
+++ b/t/maintclean-vpath.sh
@@ -0,0 +1,104 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure distclean and maintainer-clean erase the right files.
+# This test is for VPATH builds; see sister test 'maintclean.sh'
+# for in-tree builds.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([bar sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+noinst_DATA = foo.c
+foo.c:
+ touch foo.c
+MAINTAINERCLEANFILES = foo.c
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+noinst_SCRIPTS = zap
+zap: zap.sh
+ cp $(srcdir)/zap.sh $@ && chmod a+x $@
+MAINTAINERCLEANFILES = zap
+END
+
+: > bar.in
+: > sub/zap.sh
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+# Users can disable autom4te.cache.
+if test -d autom4te.cache; then
+ test_cache='test -d ../autom4te.cache'
+else
+ test_cache=:
+fi
+
+mkdir build
+
+chmod a-w . sub
+
+cd build
+
+../configure
+test -f bar
+
+$MAKE
+test -f foo.c
+test -f sub/zap
+$test_cache
+
+$MAKE distclean
+test ! -e bar
+test ! -e Makefile
+test ! -e sub/Makefile
+test ! -e config.status
+test -f foo.c
+test -f sub/zap
+test -f ../sub/zap.sh
+$test_cache
+
+../configure
+test -f bar
+
+$MAKE foo.c
+test -f foo.c
+cd sub
+$MAKE zap
+test -f zap
+cd ..
+
+chmod u+w ..
+
+$MAKE maintainer-clean
+test -f ../sub/zap.sh
+test ! -e bar
+test ! -e foo.c
+test ! -e sub/zap
+test ! -e Makefile
+test ! -e sub/Makefile
+test ! -e config.status
+test ! -e ../autom4te.cache
+
+:
diff --git a/t/maintclean.sh b/t/maintclean.sh
new file mode 100644
index 000000000..6cec08f8e
--- /dev/null
+++ b/t/maintclean.sh
@@ -0,0 +1,96 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure distclean and maintainer-clean erase the right files.
+# This test is for in-tree builds; see sister test 'maintclean-vpath.sh'
+# for VPATH builds.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([bar sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+noinst_DATA = foo.c
+foo.c:
+ touch foo.c
+MAINTAINERCLEANFILES = foo.c
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+noinst_SCRIPTS = zap
+zap: zap.sh
+ cp $(srcdir)/zap.sh $@ && chmod a+x $@
+MAINTAINERCLEANFILES = zap
+END
+
+: > bar.in
+: > sub/zap.sh
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+# Users can disable autom4te.cache.
+if test -d autom4te.cache; then
+ test_cache='test -d autom4te.cache'
+else
+ test_cache=:
+fi
+
+./configure
+test -f bar
+
+$MAKE
+test -f foo.c
+test -f sub/zap
+$test_cache
+
+$MAKE distclean
+test ! -e bar
+test ! -e Makefile
+test ! -e sub/Makefile
+test ! -e config.status
+test -f foo.c
+test -f sub/zap
+test -f sub/zap.sh
+$test_cache
+
+./configure
+test -f bar
+
+$MAKE foo.c
+test -f foo.c
+cd sub
+$MAKE zap
+test -f zap
+cd ..
+
+$MAKE maintainer-clean
+test -f sub/zap.sh
+test ! -e bar
+test ! -e foo.c
+test ! -e sub/zap
+test ! -e Makefile
+test ! -e sub/Makefile
+test ! -e config.status
+test ! -e autom4te.cache
+
+:
diff --git a/t/maintmode-configure-msg.sh b/t/maintmode-configure-msg.sh
new file mode 100644
index 000000000..6368f2710
--- /dev/null
+++ b/t/maintmode-configure-msg.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that our macro 'AM_MAINTAINER_MODE' adds proper text to
+# the configure help screen. Also make sure the "checking ..." messages
+# related to the enabling/disabling of maintainer mode are correct (see
+# automake bug#9890).
+
+. test-init.sh
+
+set_maintmode ()
+{
+ rm -rf autom4te*.cache # Just to be sure not to use a stale cache.
+ echo "AC_INIT([$me], [1.0])" > configure.ac
+ case $1 in
+ DEFAULT) echo AM_MAINTAINER_MODE;;
+ *) echo "AM_MAINTAINER_MODE([$*])";;
+ esac >> configure.ac
+}
+
+check_configure_message_with ()
+{
+ answer=$1; shift
+ ./configure ${1+"$@"} >stdout || { cat stdout; exit 1; }
+ cat stdout
+ grep "^checking whether to enable maintainer-specific.*\\.\\.\\. $answer$" stdout
+ test $(grep -c 'checking.*maint' stdout) -eq 1
+}
+
+set_maintmode "DEFAULT"
+
+$ACLOCAL
+
+$AUTOCONF --force
+
+grep_configure_help --enable-maintainer-mode 'enable make rules'
+
+check_configure_message_with "no"
+check_configure_message_with "yes" --enable-maintainer-mode
+
+set_maintmode "disable"
+
+$AUTOCONF --force
+grep_configure_help --enable-maintainer-mode 'enable make rules'
+
+check_configure_message_with "no"
+check_configure_message_with "yes" --enable-maintainer-mode
+
+set_maintmode "enable"
+
+$AUTOCONF --force
+./configure --help >stdout || { cat stdout; exit 1; }
+cat stdout
+grep_configure_help --disable-maintainer-mode 'disable make rules'
+
+check_configure_message_with "yes"
+check_configure_message_with "no" --disable-maintainer-mode
+
+:
diff --git a/t/make-dryrun.tap b/t/make-dryrun.tap
new file mode 100644
index 000000000..98189f0e7
--- /dev/null
+++ b/t/make-dryrun.tap
@@ -0,0 +1,147 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that $(am__make_dryrun) works as expected.
+
+. test-init.sh
+
+plan_ 60
+
+if echo "all: ; +@printf %sbb%s aa cc" | $MAKE -n -f - | grep aabbcc; then
+ make_plus_silence () { return 0; }
+else
+ make_plus_silence () { return 1; }
+fi
+
+mkdir none # Also used later.
+if echo nil: | $MAKE -I none -f -; then
+ make_supports_option_I () { return 0; }
+else
+ make_supports_option_I () { return 1; }
+fi
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+all:
+ : Dummy, nothing to do.
+run:
+ @echo ":: $$MAKEFLAGS :: $$MFLAGS ::" ;: For debugging.
+ $(am__make_dryrun) && exit 1; echo ok > from-run
+dry:
+ +@echo ":: $$MAKEFLAGS :: $$MFLAGS ::" ;: For debugging.
+ +$(am__make_dryrun) || exit 1; echo ok > from-dry
+END
+
+check_make ()
+{
+ msg= mode= condition=: directive= reason= skip_reason=
+ case $1 in
+ --dry) mode=dry;;
+ --run) mode=run;;
+ *) fatal_ "check_run: invalid usage";;
+ esac
+ shift
+ while test $# -gt 0; do
+ case $1 in
+ -C) condition=$2 skip_reason=$3; shift; shift;;
+ -M) msg=$2; shift;;
+ --) shift; break;;
+ *) break;;
+ esac
+ shift
+ done
+ for opts in '' '-s' '-s -r'; do
+ r=ok
+ pmsg=${mode}${msg:+" [$msg]"}${opts:+" ($opts)"}
+ if $condition; then
+ $MAKE $opts "$mode" ${1+"$@"} || r='not ok'
+ test -f from-$mode || r='not ok'
+ test ! -e bad || r='not ok'
+ rm -f bad from-* || fatal_ "cleaning up"
+ else
+ directive=SKIP reason=$skip_reason
+ fi
+ result_ "$r" -D "$directive" -r "$reason" "$pmsg"
+ done
+ unset r msg pmsg opts mode condition directive reason skip_reason
+}
+
+# ----------------------------------------------------------------------
+
+$ACLOCAL || fatal_ "aclocal failed"
+$AUTOCONF || fatal_ "autoconf failed"
+$AUTOMAKE || fatal_ "automake failed"
+./configure || fatal_ "configure failed"
+
+# ----------------------------------------------------------------------
+
+check_make --run
+
+# Test against a known regression. This was especially heinous, since
+# make running in normal mode was sometimes mistaken for make running
+# in dry mode.
+check_make --run TESTS="n1.test n2.test"
+check_make --run TESTS="n1 n2" AM_MAKEFLAGS="TESTS='n1 n2'"
+check_make --run TESTS="n1 n2" AM_MAKEFLAGS='TESTS="n1 n2"'
+check_make --run FOOFLAGS="-n -n -knf2 n --none -n"
+check_make --run MYFLAGS="-n --dryrun -n --dry-run -n"
+
+# ----------------------------------------------------------------------
+
+check_make --dry -C make_plus_silence 'recipe prefix "+" unsupported' -n
+check_make --dry -C using_gmake "\$MAKE is not GNU make" --dry-run -k
+
+# ----------------------------------------------------------------------
+
+# Automake bug#13760: the "n" in "none" used to confound am__make_dryrun
+# into thinking the '-n' option had been passed.
+
+pr='bug#13760'
+
+check_make --run -C make_supports_option_I "-I make option unsupported" \
+ -M "$pr" -I none
+
+check_make --run -C using_gmake "\$MAKE is not GNU make" \
+ -M "$pr" -I none --include dry-run
+
+check_make --dry -C make_supports_option_I "-I make option unsupported" \
+ -M "$pr" -I none -n
+
+check_make --dry -C using_gmake "\$MAKE is not GNU make" \
+ -M "$pr" --dry-run -I none --include dry-run
+
+# ----------------------------------------------------------------------
+
+# Test for when shell metacharacters or backslashes are in $(MAKEFLAGS).
+
+check_metachars ()
+{
+ check_make --run -M "metachars" "$@"
+}
+
+check_metachars MYFLAGS="-n \"n\" '-n' --none -n"
+check_metachars MYFLAGS='-knf2\ n\ \\n'
+check_metachars MYFLAGS="(&) | ; \" \` '"
+check_metachars MYFLAGS=" ' # ' "
+check_metachars MYFLAGS='$(foo)'
+check_metachars MYFLAGS='$(foo -n)'
+check_metachars MYFLAGS='`touch bad`'
+check_metachars MYFLAGS='`touch --dry-run bad`'
+
+# ----------------------------------------------------------------------
+
+:
diff --git a/t/make-is-gnu.sh b/t/make-is-gnu.sh
new file mode 100644
index 000000000..c8478c9e8
--- /dev/null
+++ b/t/make-is-gnu.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that $(am__is_gnu_make) can be used to correctly determine if
+# we are running under GNU make.
+
+. test-init.sh
+
+if using_gmake; then
+ as_expected () { test $1 -eq 0 && test -f ok && test ! -e ko; }
+else
+ as_expected () { test $1 -gt 0 && test -f ko && test ! -e ok; }
+fi
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+all: file
+ $(am__is_gnu_make)
+file:
+ if $(am__is_gnu_make); then : > ok; else : > ko; fi
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+st=0; $MAKE || st=$?
+if using_gmake; then
+ test $st -eq 0
+ test -f ok
+ test ! -e ko
+else
+ test $st -gt 0
+ test -f ko
+ test ! -e ok
+fi
+
+rm -f ok ko
+
+run_make -M -- -s file
+if using_gmake; then
+ test -f ok
+ test ! -e ko
+else
+ test -f ko
+ test ! -e ok
+fi
+test ! -s output
+
+:
diff --git a/t/make-keepgoing.tap b/t/make-keepgoing.tap
new file mode 100644
index 000000000..8cb5bb599
--- /dev/null
+++ b/t/make-keepgoing.tap
@@ -0,0 +1,137 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that $(am__make_keepgoing) works as expected.
+
+. test-init.sh
+
+plan_ 60
+
+mkdir kool # Also used later.
+if echo nil: | $MAKE -I kool -f -; then
+ make_supports_option_I () { return 0; }
+else
+ make_supports_option_I () { return 1; }
+fi
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+all:
+ @echo 'Default target $@ should not be called'>&2; exit 1;
+k-y:
+ @echo ":: $$MAKEFLAGS :: $$MFLAGS ::" ;: For debugging.
+ $(am__make_keepgoing)
+k-n:
+ @echo ":: $$MAKEFLAGS :: $$MFLAGS ::" ;: For debugging.
+ $(am__make_keepgoing) && exit 1; exit 0
+END
+
+check_make ()
+{
+ msg= mode= condition=: directive= reason= skip_reason=
+ case $1 in
+ k-[yn]) mode=$1;;
+ *) fatal_ "check_run: invalid usage";;
+ esac
+ shift
+ while test $# -gt 0; do
+ case $1 in
+ -C) condition=$2 skip_reason=$3; shift; shift;;
+ -M) msg=$2; shift;;
+ -X) directive=TODO;;
+ --) shift; break;;
+ *) break;;
+ esac
+ shift
+ done
+ for opts in '' '-s' '-s -r'; do
+ r=ok
+ pmsg=${mode}${msg:+" [$msg]"}${opts:+" ($opts)"}
+ if $condition; then
+ $MAKE $opts "$mode" ${1+"$@"} || r='not ok'
+ else
+ directive=SKIP reason=$skip_reason
+ fi
+ result_ "$r" -D "$directive" -r "$reason" "$pmsg"
+ done
+ unset r msg pmsg opts mode condition directive reason skip_reason
+}
+
+# ----------------------------------------------------------------------
+
+$ACLOCAL || fatal_ "aclocal failed"
+$AUTOCONF || fatal_ "autoconf failed"
+$AUTOMAKE || fatal_ "automake failed"
+./configure || fatal_ "configure failed"
+
+# ----------------------------------------------------------------------
+
+check_make k-n
+
+# Test against a possible regressions similar to those that affected
+# detection of dry mode ("make -n").
+check_make k-n TESTS="k.test k2.test"
+check_make k-n TESTS="k1 k2" AM_MAKEFLAGS="TESTS='k1 k2'"
+check_make k-n TESTS="k1 k k2" AM_MAKEFLAGS='TESTS="k1 k k2"'
+check_make k-n FOOFLAGS="-k -k -nkf2 k -ks --keep -k"
+check_make k-n MYFLAGS="-k --keepgoing -k --keep-run -k"
+
+# ----------------------------------------------------------------------
+
+check_make k-y -k
+check_make k-y -C using_gmake "\$MAKE is not GNU make" --keep-going
+
+# ----------------------------------------------------------------------
+
+# Related to automake bug#12554: the "k" in "kool" used to confound
+# am__make_keepgoing into thinking the '-k' option had been passed.
+
+pr='bug#12554'
+
+check_make k-n -C make_supports_option_I "-I make option unsupported" \
+ -M "$pr" -I kool
+
+check_make k-n -C using_gmake "\$MAKE is not GNU make" \
+ -M "$pr" -I kool --include keep-going
+
+check_make k-y -C make_supports_option_I "-I make option unsupported" \
+ -M "$pr" -I kool -k
+
+check_make k-y -C using_gmake "\$MAKE is not GNU make" \
+ -M "$pr" --keep-going -I kool --include keep-going
+
+# ----------------------------------------------------------------------
+
+# Test for when shell metacharacters or backslashes are in $(MAKEFLAGS).
+
+check_metachars ()
+{
+ check_make k-n -M "metachars" "$@"
+}
+
+check_metachars MYFLAGS="-k \"k\" '-k' --keep-going -k"
+check_metachars MYFLAGS='-knf2\ k\ \\k'
+check_metachars MYFLAGS="(&) | ; \" \` '"
+check_metachars MYFLAGS=" ' # ' "
+check_metachars MYFLAGS='$(foo)'
+check_metachars MYFLAGS='$(foo -k)'
+check_metachars MYFLAGS='`touch bad`'
+check_metachars MYFLAGS='`touch --keep-going bad`'
+
+# ----------------------------------------------------------------------
+
+:
diff --git a/t/make.sh b/t/make.sh
new file mode 100644
index 000000000..36c010364
--- /dev/null
+++ b/t/make.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure 'make' check works.
+# From Ralf Corsepius.
+
+required=GNUmake
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_MAKE_INCLUDE
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+export ACLOCAL
+export AUTOCONF
+export AUTOMAKE
+
+# Do the test twice -- once with make and once with make -w.
+# This tests for a bug reported by Rainer Orth (see PR 175).
+
+save="$MAKE"
+for flag in '' -w; do
+ MAKE="$save $flag" ./configure
+ $FGREP 'am__include = include' Makefile
+ $sleep
+ touch configure.ac
+ $MAKE $flag
+ $FGREP 'am__include = include' Makefile
+ rm -f config.cache
+done
+
+exit 0
diff --git a/t/makefile-deps.sh b/t/makefile-deps.sh
new file mode 100644
index 000000000..8f50a0977
--- /dev/null
+++ b/t/makefile-deps.sh
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we don't emit a rule with empty target if list of
+# automatically-computed dependencies for Makefile.in is empty.
+
+. test-init.sh
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+grep "^ *:" Makefile.in && exit 1
+
+:
diff --git a/t/makej.sh b/t/makej.sh
new file mode 100644
index 000000000..6ebbac13a
--- /dev/null
+++ b/t/makej.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# 'make -j' used to fail with Autoconf < 2.58, because tools like
+# autoconf and automake can try to update autom4te's cache in parallel.
+#
+# Note that failures might not be reproducible systematically as they
+# depend on the time at which autoconf and automake update the cache
+# via autom4te.
+
+required=GNUmake
+. test-init.sh
+
+cat >configure.ac <<END
+m4_include([version.m4])
+AC_INIT([$me], [THE_VERSION])
+AM_INIT_AUTOMAKE
+AC_CONFIG_HEADER([config.h])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+echo 'm4_define([THE_VERSION], [2.718])' > version.m4
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE --add-missing
+./configure --version | grep '2\.718'
+./configure
+$MAKE
+
+$sleep
+echo 'm4_define([THE_VERSION], [3.141])' > version.m4
+$MAKE -j
+./configure --version | grep '3\.141'
+
+:
diff --git a/t/makej2.sh b/t/makej2.sh
new file mode 100644
index 000000000..d2a7f6b3e
--- /dev/null
+++ b/t/makej2.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure known BSD 'make -jN' issues are fixed:
+# without -B, it may reuse the same shell for separate commands in a
+# rule, which can lead to interesting results.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+test-distdir-removed:
+ test ! -d $(distdir)
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+mkdir build
+cd build
+../configure --prefix="$(pwd)/inst"
+
+$MAKE -j2 || skip_ "$MAKE failed to run with two parallel jobs"
+$MAKE -j2 distcheck
+$MAKE test-distdir-removed
+
+:
diff --git a/t/maken.sh b/t/maken.sh
new file mode 100644
index 000000000..bb9705786
--- /dev/null
+++ b/t/maken.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure that 'make -n dist' and 'make -n distcheck' do not change files
+# on disk, due to GNU make executing rules containing '$(MAKE)'.
+# Also, ensure that 'make -n dist' and 'make -n distcheck' show what
+# would happen, at least when using GNU make.
+
+. test-init.sh
+
+mkdir sub
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+distcheck-hook:
+ @: > stamp-distcheck-hook
+test-no-distdir:
+ test ! -d $(distdir)
+ test ! -f stamp-distcheck-hook
+ test ! -f sub/stamp-sub-dist-hook
+END
+cat >sub/Makefile.am <<'END'
+dist-hook:
+ @: > stamp-sub-dist-hook
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+echo stamp > stampfile
+$sleep
+for target in dist distcheck; do
+ $MAKE -n $target
+ if using_gmake; then
+ $MAKE -n $target | grep stamp-sub-dist-hook || exit 1
+ fi
+ $MAKE test-no-distdir
+ # No file has been actually touched or created.
+ is_newest stampfile $(find . -type f) sub
+done
+
+:
diff --git a/t/maken3.sh b/t/maken3.sh
new file mode 100644
index 000000000..1e5d02315
--- /dev/null
+++ b/t/maken3.sh
@@ -0,0 +1,188 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test 'make -n' for various targets, to ensure that:
+#
+# 1. no files or directories are created or removed, and
+#
+# 2. if using GNU make or a make implementation supporting the .MAKE
+# special target, the output from make is sufficiently complete.
+#
+# This test exercises the GCS-mandated targets (except for dist)
+# as well as tags.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+# Does $MAKE support the '.MAKE' special target?
+have_dotmake=false
+if using_gmake; then
+ have_dotmake=: # GNU make must support it.
+else
+ unindent > mk.tmp << 'END'
+ targ.tmp:
+ : > $@
+ .MAKE: targ.tmp
+END
+ if $MAKE -n -f mk.tmp targ.tmp && test -f targ.tmp; then
+ have_dotmake=:
+ fi
+fi
+
+mkdir sub sub2
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile sub2/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+TESTS = foo.test
+SUBDIRS = sub sub2
+##BUILT_SOURCES = foo
+foo:
+foo.test:
+all-local:
+ @: > stamp-all
+install-data-local:
+ @: > stamp-install
+uninstall-local:
+ @: > stamp-uninstall
+clean-local:
+ @: > stamp-clean
+distclean-local:
+ @: > stamp-distclean
+info-local:
+ @: > stamp-info
+html-local:
+ @: > stamp-html
+dvi-local:
+ @: > stamp-dvi
+ps-local:
+ @: > stamp-ps
+pdf-local:
+ @: > stamp-pdf
+check-local:
+ @: > stamp-check
+installcheck-local:
+ @: > stamp-installcheck
+mostlyclean-local:
+ @: > stamp-mostlyclean
+maintainer-clean-local:
+ @: > stamp-maintainer-clean
+END
+cat >sub/Makefile.am <<'END'
+all-local:
+ @: > stamp-all-sub
+install-data-local:
+ @: > stamp-install-sub
+uninstall-local:
+ @: > stamp-uninstall-sub
+clean-local:
+ @: > stamp-clean-sub
+distclean-local:
+ @: > stamp-distclean-sub
+info-local:
+ @: > stamp-info-sub
+html-local:
+ @: > stamp-html-sub
+dvi-local:
+ @: > stamp-dvi-sub
+ps-local:
+ @: > stamp-ps-sub
+pdf-local:
+ @: > stamp-pdf-sub
+check-local:
+ @: > stamp-check-sub
+installcheck-local:
+ @: > stamp-installcheck-sub
+tags:
+ @: > stamp-tags-sub
+mostlyclean-local:
+ @: > stamp-mostlyclean-sub
+maintainer-clean-local:
+ @: > stamp-maintainer-clean-sub
+END
+cat >sub2/Makefile.am <<'END'
+all install uninstall clean check:
+ @: > sub2-$@-should-not-be-executed
+info dvi pdf ps:
+ @: > sub2-$@-should-not-be-executed
+html:
+ @: > sub2-$@-should-not-be-executed
+install-info install-html install-dvi install-pdf install-ps:
+ @: > sub2-$@-should-not-be-executed
+installcheck installdirs tags mostlyclean:
+ @: > sub2-$@-should-not-be-executed
+## These targets cannot be overridden like this:
+## install-strip distclean maintainer-clean
+END
+
+$ACLOCAL
+$AUTOCONF
+
+check_targets ()
+{
+ for target in \
+ all install install-strip uninstall clean distclean check \
+ info html dvi pdf ps \
+ install-info install-html install-dvi install-pdf install-ps \
+ installcheck installdirs tags mostlyclean maintainer-clean
+ do
+ run_make -O -- -n $target
+ case $target in
+ install-* | installdirs | tags ) ;;
+ *)
+ if $have_dotmake; then
+ grep "stamp-$target$" stdout || exit 1
+ fi
+ test ! -e "stamp-$target" || exit 1
+ ;;
+ esac
+ case $target in
+ install-* | installdirs ) ;;
+ *)
+ if $have_dotmake; then
+ grep "stamp-$target-sub" stdout || exit 1
+ fi
+ test ! -e "sub/stamp-$target-sub" || exit 1
+ ;;
+ esac
+ case $target in
+ distclean | maintainer-clean ) ;;
+ *)
+ if $have_dotmake; then
+ grep "should-not-be-executed" stdout || exit 1
+ fi
+ test ! -e "sub2/sub2-$target-should-not-be-executed" || exit 1
+ ;;
+ esac
+ done
+}
+
+$AUTOMAKE -a -Wno-override
+./configure
+check_targets || exit 1
+
+# Now, introduce BUILT_SOURCES into the toplevel Makefile
+# TODO: add BUILT_SOURCES to sub2, fix fallout.
+sed 's/##//' < Makefile.am > t
+mv -f t Makefile.am
+$AUTOMAKE -Wno-override --force Makefile
+./configure
+check_targets || exit 1
+
+exit 0
diff --git a/t/makevars.sh b/t/makevars.sh
new file mode 100644
index 000000000..883038759
--- /dev/null
+++ b/t/makevars.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that automake includes the needed variables,
+# but not too many.
+
+. test-init.sh
+
+# Find the macros wanted by Automake.
+$ACLOCAL
+
+# Create some dummy Makefile.in.
+: > Makefile.am
+
+$AUTOMAKE
+
+# We are definitely not needing a compiler or preprocessor.
+$EGREP '^ *(CC|CPP|CXX|CXXCPP) *=' Makefile.in && exit 1
+
+:
diff --git a/t/man.sh b/t/man.sh
new file mode 100644
index 000000000..46f9c676b
--- /dev/null
+++ b/t/man.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure 'dist' prefix works with man pages.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+dist_man_MANS = foo.1
+nodist_man1_MANS = bar.man
+END
+
+: > foo.1
+: > bar.man
+
+$ACLOCAL
+$AUTOMAKE
+grep '^MANS *=' Makefile.in
+
+:
diff --git a/t/man2.sh b/t/man2.sh
new file mode 100644
index 000000000..512fb93f9
--- /dev/null
+++ b/t/man2.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that man pages listed in man_MANS are installed and
+# renamed as documented.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+man_MANS = foo.2
+man4_MANS = foo.4 bar.man
+END
+
+: > foo.2
+: > foo.4
+: > bar.man
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+# Let's play with $DESTDIR too, it shouldn't hurt.
+./configure --prefix='' --mandir=/man
+$MAKE DESTDIR="$cwd/_inst" install
+
+test -f _inst/man/man2/foo.2
+test -f _inst/man/man4/foo.4
+test -f _inst/man/man4/bar.4
+
+$MAKE DESTDIR="$cwd/_inst" uninstall
+
+test ! -e _inst/man/man2/foo.2
+test ! -e _inst/man/man4/foo.4
+test ! -e _inst/man/man4/bar.4
+
+:
diff --git a/t/man3.sh b/t/man3.sh
new file mode 100644
index 000000000..582448ae1
--- /dev/null
+++ b/t/man3.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# PR 516: Prefer generated manpages to distributed ones.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+dist_man_MANS = foo.1
+installcheck-local:
+ grep bar "$(mandir)/man1/foo.1"
+END
+
+cat >>configure.ac <<'END'
+: ${foo=foo}
+AC_SUBST([foo])
+AC_CONFIG_FILES([foo.1])
+AC_OUTPUT
+END
+
+cat > foo.1.in <<'END'
+@foo@
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure
+run_make DISTCHECK_CONFIGURE_FLAGS='foo=bar' distcheck
+
+:
diff --git a/t/man5.sh b/t/man5.sh
new file mode 100644
index 000000000..0fb2abd8e
--- /dev/null
+++ b/t/man5.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure to extract the correct mansection from files in man_MANS.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+man_MANS = foo-1.4.5/foo.2 foo-1.4.5/bar.3 baz-1.4.2
+notrans_man_MANS = foo-1.4.5/nfoo.2 foo-1.4.5/nbar.3 nbaz-1.4.2
+END
+
+mkdir foo-1.4.5
+
+: > foo-1.4.5/foo.2
+: > foo-1.4.5/nfoo.2
+: > foo-1.4.5/bar.3
+: > foo-1.4.5/nbar.3
+: > baz-1.4.2
+: > nbaz-1.4.2
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+# Let's play with $DESTDIR too, it shouldn't hurt.
+./configure --mandir=/man
+$MAKE DESTDIR="$cwd/_inst" install
+
+test -f _inst/man/man2/foo.2
+test -f _inst/man/man2/nfoo.2
+test -f _inst/man/man2/baz-1.4.2
+test -f _inst/man/man2/nbaz-1.4.2
+test -f _inst/man/man3/bar.3
+test -f _inst/man/man3/nbar.3
+
+test ! -e _inst/man/man1
+test ! -e _inst/man/man4
+test ! -e _inst/man/man5
+
+$MAKE DESTDIR="$cwd/_inst" uninstall
+
+test ! -e _inst/man/man2/foo.2
+test ! -e _inst/man/man2/nfoo.2
+test ! -e _inst/man/man2/baz-1.4.2
+test ! -e _inst/man/man2/nbaz-1.4.2
+test ! -e _inst/man/man3/bar.3
+test ! -e _inst/man/man3/nbar.3
+
+:
diff --git a/t/man6.sh b/t/man6.sh
new file mode 100644
index 000000000..9c05fa904
--- /dev/null
+++ b/t/man6.sh
@@ -0,0 +1,101 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure 'make distcheck' passes when help2man generates man pages,
+# even if the 'missing' script is involved.
+
+required=help2man
+. test-init.sh
+
+# Avoid a spurious failure due to a known FreeBSD make incompatibility.
+useless_vpath_rebuild \
+ && skip_ "VPATH useless rebuild detected (see bug#7884)"
+
+cat > Makefile.am << 'END'
+dist_man_MANS = $(srcdir)/foobar.1 bazquux.1 zardoz.1
+dist_bin_SCRIPTS = foobar bazquux zardoz
+$(srcdir)/foobar.1:
+ $(HELP2MAN) --output=$@ $(srcdir)/foobar
+bazquux.1:
+ $(HELP2MAN) --output=$@ $(srcdir)/bazquux
+zardoz.1:
+ $(HELP2MAN) --output=$(srcdir)/zardoz.1 $(srcdir)/zardoz
+END
+
+cat >> configure.ac <<'END'
+AM_MISSING_PROG([HELP2MAN], [help2man])
+AC_OUTPUT
+END
+
+cat > foobar <<'END'
+#! /bin/sh
+while test $# -gt 0; do
+ case $1 in
+ -h | --help) echo "usage: $0 [OPTIONS]..."; exit 0;;
+ -v | --version) echo "$0 1.0"; exit 0;;
+ esac
+ shift
+done
+END
+
+cp foobar bazquux
+cp foobar zardoz
+
+chmod +x foobar bazquux zardoz
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+mkdir build
+cd build
+
+../configure
+# Sanity check.
+grep '^HELP2MAN *=.*/missing help2man' Makefile
+
+$MAKE
+$FGREP foobar ../foobar.1
+$FGREP bazquux ./bazquux.1
+$FGREP zardoz ../zardoz.1
+
+$MAKE distdir
+$FGREP foobar $me-1.0/foobar.1
+$FGREP bazquux $me-1.0/bazquux.1
+$FGREP zardoz $me-1.0/zardoz.1
+
+$MAKE distcheck
+
+cd ..
+rm -f *.1 # Remove leftover generated manpages.
+
+./configure
+# Sanity check.
+grep '^HELP2MAN *=.*/missing help2man' Makefile
+
+$MAKE
+$FGREP foobar foobar.1
+$FGREP bazquux bazquux.1
+$FGREP zardoz zardoz.1
+
+$MAKE distdir
+$FGREP foobar $me-1.0/foobar.1
+$FGREP bazquux $me-1.0/bazquux.1
+$FGREP zardoz $me-1.0/zardoz.1
+
+$MAKE distcheck
+
+:
diff --git a/t/man7.sh b/t/man7.sh
new file mode 100644
index 000000000..5a95aada9
--- /dev/null
+++ b/t/man7.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for a bug in maintainer-clean w.r.t. generated manpages.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+dist_man_MANS = $(srcdir)/foo.1 bar.1
+$(srcdir)/foo.1 bar.1:
+ : > $@
+MAINTAINERCLEANFILES = $(dist_man_MANS)
+END
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+mkdir build
+cd build
+../configure
+
+$MAKE
+test -f bar.1
+test -f ../foo.1
+
+$MAKE maintainer-clean
+test ! -e bar.1
+test ! -e ../foo.1
+
+cd ..
+./configure
+
+$MAKE
+test -f bar.1
+test -f foo.1
+
+$MAKE maintainer-clean
+test ! -e bar.1
+test ! -e foo.1
+
+:
diff --git a/t/man8.sh b/t/man8.sh
new file mode 100644
index 000000000..dcf619f4a
--- /dev/null
+++ b/t/man8.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for a bug in distcheck w.r.t. generated manpages.
+
+. test-init.sh
+
+# Avoid a spurious failure due to a known FreeBSD make incompatibility.
+useless_vpath_rebuild \
+ && skip_ "VPATH useless rebuild detected (see bug#7884)"
+
+cat > Makefile.am << 'END'
+dist_man_MANS = foo.1
+foo.1:
+## This 'rm' command will fail if $(srcdir) is unwritable.
+ rm -f $(srcdir)/$@
+ : > $(srcdir)/$@
+END
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+mkdir build
+cd build
+../configure
+
+$MAKE
+test -f ../foo.1
+$MAKE distdir
+test -f $me-1.0/foo.1
+$MAKE distcheck
+
+cd ..
+rm -f foo.1
+./configure
+
+$MAKE
+test -f foo.1
+$MAKE distdir
+test -f $me-1.0/foo.1
+$MAKE distcheck
+
+:
diff --git a/t/mdate.sh b/t/mdate.sh
new file mode 100644
index 000000000..6b43e6269
--- /dev/null
+++ b/t/mdate.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that mdate-sh is required when Texinfo used and version.texi needed.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = textutils.texi
+END
+
+cat > textutils.texi << 'END'
+@include version.texi
+@setfilename textutils.info
+END
+
+# Required when using Texinfo.
+: > texinfo.tex
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'required file.*mdate-sh.*not found' stderr
+
+:
diff --git a/t/mdate2.sh b/t/mdate2.sh
new file mode 100644
index 000000000..519503911
--- /dev/null
+++ b/t/mdate2.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure mdate-sh is included in distribution.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = textutils.texi
+END
+
+cat > textutils.texi << 'END'
+@include version.texi
+END
+
+# Required when using Texinfo.
+: > texinfo.tex
+: > mdate-sh
+echo '@setfilename textutils.info' > textutils.texi
+
+# Use "././" to confuse Automake into thinking this is a subdir build.
+$ACLOCAL
+$AUTOMAKE ././Makefile
+
+grep 'mdate-sh' Makefile.in | grep -v SHELL
+
+:
diff --git a/t/mdate3.sh b/t/mdate3.sh
new file mode 100644
index 000000000..7948482f6
--- /dev/null
+++ b/t/mdate3.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure mdate-sh run correctly.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([foo])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = textutils.texi
+END
+
+cat > textutils.texi << 'END'
+@include version.texi
+@setfilename textutils.info
+END
+
+mkdir foo
+
+# Required when using Texinfo.
+: > foo/texinfo.tex
+: > foo/mdate-sh
+mv install-sh foo
+mv missing foo
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '[^/]mdate-sh' Makefile.in && exit 1
+exit 0
diff --git a/t/mdate4.sh b/t/mdate4.sh
new file mode 100644
index 000000000..fa2d9d4f5
--- /dev/null
+++ b/t/mdate4.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that mdate-sh is added to the right directory.
+# Report from Kevin Dalley.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+END
+
+mkdir sub
+
+cat > sub/Makefile.am << 'END'
+info_TEXINFOS = textutils.texi
+END
+
+cat > sub/textutils.texi << 'END'
+@include version.texi
+@setfilename textutils.info
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+ls -l sub
+test -f sub/mdate-sh
+
+:
diff --git a/t/mdate5.sh b/t/mdate5.sh
new file mode 100644
index 000000000..9426e53eb
--- /dev/null
+++ b/t/mdate5.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure mdate-sh works correctly.
+
+am_create_testdir=empty
+. test-init.sh
+
+get_shell_script mdate-sh
+
+set x $(./mdate-sh mdate-sh)
+shift
+echo "$*" # For debugging.
+
+# Check that mdate output looks like a date:
+test $# = 3
+case $1$3 in *[!0-9]*) exit 1;; esac
+test $1 -lt 32
+# Hopefully automake will be obsolete in 80 years ;-)
+case $3 in 20[0-9][0-9]) :;; *) exit 1;; esac
+case $2 in
+ January|February|March|April|May|June|July|August) ;;
+ September|October|November|December) ;;
+ *) exit 1
+esac
+
+# Stricter checks on the year required a POSIX date(1) command.
+if year=$(date +%Y) && test $year -gt 2010; then
+ test $year = $3 || exit 1
+fi
+
+:
diff --git a/t/mdate6.sh b/t/mdate6.sh
new file mode 100644
index 000000000..21729c8b5
--- /dev/null
+++ b/t/mdate6.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# mdate-sh can work with weird file names, doesn't eval too much.
+
+am_create_testdir=empty
+. test-init.sh
+
+a=
+file='file name $a'
+( : > "$file" ) \
+ || skip_ "file name with spaces and metacharacters not accepted"
+
+get_shell_script mdate-sh
+
+./mdate-sh "$file" >stdout 2>stderr ||
+ { cat stdout; cat stderr >&2; exit 1; }
+cat stdout
+cat stderr >&2
+grep '[12][0-9]\{3\}' stdout
+test ! -s stderr
+
+:
diff --git a/t/missing-auxfile-stops-makefiles-creation.sh b/t/missing-auxfile-stops-makefiles-creation.sh
new file mode 100644
index 000000000..6d794a3a8
--- /dev/null
+++ b/t/missing-auxfile-stops-makefiles-creation.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automake should stop the creation of Makefile.in files at the first
+# encountered error due to a required auxiliary file not found.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AM_PATH_PYTHON
+END
+
+echo SUBDIRS = > Makefile.am
+
+for i in 1 2 3 4 5; do
+ echo "AC_CONFIG_FILES([sub$i/Makefile])" >> configure.ac
+ echo "SUBDIRS += sub$i" >> Makefile.am
+ mkdir sub$i
+ echo python_PYTHON = foo.py > sub$i/Makefile.am
+done
+
+: > sub1/Makefile.am
+
+$ACLOCAL
+
+unset AUTOMAKE_JOBS
+
+AUTOMAKE_fails
+ls -l Makefile.in */Makefile.in || : # For debugging.
+# Top-level Makefile.in might be created or not, we don't want to set
+# too strict semantics here, so don't check for it. But the later
+# files shouldn't exist.
+test -f sub1/Makefile.in
+test ! -e sub2/Makefile.in
+test ! -e sub3/Makefile.in
+test ! -e sub4/Makefile.in
+test ! -e sub5/Makefile.in
+
+rm -f Makefile.in */Makefile.in
+
+: > sub2/Makefile.am
+: > sub3/Makefile.am
+
+AUTOMAKE_fails
+ls -l Makefile.in */Makefile.in || : # For debugging.
+test -f sub1/Makefile.in
+test -f sub2/Makefile.in
+test -f sub3/Makefile.in
+test ! -e sub4/Makefile.in
+test ! -e sub5/Makefile.in
+
+:
diff --git a/t/missing-version-mismatch.sh b/t/missing-version-mismatch.sh
new file mode 100644
index 000000000..41146746b
--- /dev/null
+++ b/t/missing-version-mismatch.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test missing with version mismatches.
+
+am_create_testdir=empty
+. test-init.sh
+
+get_shell_script missing
+
+do_check ()
+{
+ progname=$1; shift;
+ ./missing "$@" 2>stderr && { cat stderr >&2; exit 1; }
+ cat stderr >&2
+ $FGREP "WARNING: '$progname' is probably too old." stderr
+}
+
+echo 'AC_INIT([x], [1.0]) AC_PREREQ([9999])' >> configure.ac
+
+do_check autoconf $AUTOCONF
+do_check autoheader $AUTOHEADER
+do_check aclocal-$APIVERSION $am_original_ACLOCAL
+
+cat > configure.ac << 'END'
+AC_INIT([x], [0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+echo AUTOMAKE_OPTIONS = 9999.9999 > Makefile.am
+$ACLOCAL
+: > install-sh
+# FIXME: this doesn't work due to a bug in automake (not 'missing').
+#do_check automake-$APIVERSION $am_original_AUTOMAKE
+
+:
diff --git a/t/missing3.sh b/t/missing3.sh
new file mode 100644
index 000000000..f0bdeed36
--- /dev/null
+++ b/t/missing3.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test missing when running a tool's --version.
+
+am_create_testdir=empty
+. test-init.sh
+
+get_shell_script missing
+
+# b7cb8259 assumed not to exist.
+
+run_cmd ()
+{
+ st=0; "$@" >stdout 2>stderr || st=$?
+ cat stdout
+ cat stderr >&2
+ return $st
+}
+
+run_cmd ./missing b7cb8259 --version && exit 1
+grep WARNING stderr && exit 1
+run_cmd ./missing b7cb8259 --grep && exit 1
+
+if test x"$am_test_prefer_config_shell" != x"yes"; then
+ # The /bin/sh from Solaris 10 is a spectacular failure. After a failure
+ # due to a "command not found", it sets '$?' to '1'.
+ if (st=0; /bin/sh -c 'no--such--command' || st=$?; test $st -eq 127); then
+ grep 'WARNING:.*missing on your system' stderr
+ fi
+fi
+
+# missing itself it known to exist :)
+
+run_cmd ./missing ./missing --version || exit 1
+grep 'missing .*(GNU [aA]utomake)' stdout
+test -s stderr && exit 1
+run_cmd ./missing ./missing --grep && exit 1
+grep WARNING stderr && exit 1
+grep "missing:.* unknown '--grep'" stderr
+
+:
diff --git a/t/mkdir_p.sh b/t/mkdir_p.sh
new file mode 100644
index 000000000..36d91fc24
--- /dev/null
+++ b/t/mkdir_p.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# AM_INIT_AUTOMAKE should still define $(mkdir_p), for backward
+# compatibility.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+all-local:
+ $(mkdir_p) . dir1/a
+ @mkdir_p@ . dir2/b
+check-local: all
+ test -d dir1/a
+ test -d dir2/b
+ test -d dir3/c
+ test -d dir3/d
+END
+
+mkdir sub
+cat > sub/Makefile.am << 'END'
+# '$(mkdir_p)' should continue to work even in subdir makefiles.
+all-local:
+ $(mkdir_p) .. ../dir3/c
+ @mkdir_p@ .. ../dir3/d
+END
+
+$ACLOCAL
+$AUTOCONF -Werror -Wall
+$AUTOMAKE
+
+./configure
+$MAKE check-local
+$MAKE distcheck
+
+:
diff --git a/t/mkdirp-deprecation.sh b/t/mkdirp-deprecation.sh
new file mode 100644
index 000000000..39e8d8a43
--- /dev/null
+++ b/t/mkdirp-deprecation.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the AM_PROG_MKDIR_P macro is deprecated. It will be
+# be removed in the next major Automake release.
+
+. test-init.sh
+
+echo AM_PROG_MKDIR_P >> configure.ac
+: > Makefile.am
+
+grep_err ()
+{
+ loc='^configure.ac:4:'
+ grep "$loc.*AM_PROG_MKDIR_P.*deprecated" stderr
+ grep "$loc.* use .*AC_PROG_MKDIR_P" stderr
+ grep "$loc.* use '\$(MKDIR_P)' instead of '\$(mkdir_p)'.*Makefile" stderr
+}
+
+$ACLOCAL
+
+$AUTOCONF -Werror -Wobsolete 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep_err
+
+$AUTOCONF -Werror -Wno-obsolete
+
+#AUTOMAKE_fails
+#grep_err
+AUTOMAKE_fails --verbose -Wnone -Wobsolete
+grep_err
+
+$AUTOMAKE -Wno-obsolete
+
+:
diff --git a/t/mkinst2.sh b/t/mkinst2.sh
new file mode 100644
index 000000000..9a5f03cbe
--- /dev/null
+++ b/t/mkinst2.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure no-installman suppresses man dir creation.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-installman
+man_MANS = foo.1
+END
+
+: > foo.1
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure --prefix "$(pwd)/sub"
+
+$MAKE installdirs
+test ! -e sub/man
+$MAKE install
+test ! -e sub/man
+
+:
diff --git a/t/mkinst3.sh b/t/mkinst3.sh
new file mode 100644
index 000000000..dad26b74d
--- /dev/null
+++ b/t/mkinst3.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test mkinstalldirs with spaces in directory names.
+
+am_create_testdir=empty
+. test-init.sh
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+# Make sure the directory we will create can be created...
+mkdir '~a b' && mkdir '~a b/-x y' \
+ || skip_ "directory names with spaces and metacharacters not accepted"
+rm -rf '~a b'
+
+get_shell_script mkinstalldirs
+
+# Test mkinstalldirs with the installed mkdir.
+
+./mkinstalldirs '~a b/-x y'
+test -d '~a b/-x y'
+rm -rf '~a b'
+
+# Trick mkinstalldirs into thinking mkdir does not support -p.
+
+mkdir bin
+cat >bin/mkdir <<'EOF'
+#!/bin/sh
+for arg
+do
+ case $arg in
+ -p) exit 1;;
+ esac
+done
+PATH=$AM_PATH
+export PATH
+exec mkdir "$@"
+EOF
+
+chmod +x bin/mkdir
+
+AM_PATH=$PATH; export AM_PATH
+PATH=$cwd/bin$PATH_SEPARATOR$PATH; export PATH
+
+# Test mkinstalldirs without mkdir -p.
+
+./mkinstalldirs '~a b/-x y'
+test -d '~a b/-x y'
+rm -rf '~a b'
+
+./mkinstalldirs "$cwd///~a b//-x y"
+test -d "$cwd/~a b/-x y"
+rm -rf '~a b'
+
+:
diff --git a/t/mkinstall.sh b/t/mkinstall.sh
new file mode 100644
index 000000000..eb3787161
--- /dev/null
+++ b/t/mkinstall.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug where mkinstalldirs variable can be set incorrectly.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+pkgdata_DATA =
+END
+
+# The "././" prefix confuses Automake into thinking it is doing a
+# subdir build. Yes, this is hacky.
+$ACLOCAL
+$AUTOMAKE ././Makefile
+
+grep ' /mkinstalldirs' Makefile.in && exit 1
+exit 0
diff --git a/t/mmode.sh b/t/mmode.sh
new file mode 100644
index 000000000..2dabcd612
--- /dev/null
+++ b/t/mmode.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for AM_MAINTAINER_MODE defaults.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_MAINTAINER_MODE
+AC_OUTPUT
+END
+
+: >Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+grep '^MAINT.*#' Makefile
+
+./configure --disable-maintainer-mode
+grep '^MAINT.*#' Makefile
+
+./configure --enable-maintainer-mode
+grep '^MAINT.*#' Makefile && exit 1
+
+sed 's/\(AM_MAINTAINER_MODE\).*/\1([disable])/' configure.ac > configure.tmp
+mv -f configure.tmp configure.ac
+mv configure configure1
+$AUTOCONF --force
+diff configure configure1
+
+sed 's/\(AM_MAINTAINER_MODE\).*/\1([enable])/' configure.ac > configure.tmp
+mv -f configure.tmp configure.ac
+$AUTOCONF --force
+
+./configure
+grep '^MAINT.*#' Makefile && exit 1
+
+./configure --enable-maintainer-mode
+grep '^MAINT.*#' Makefile && exit 1
+
+./configure --disable-maintainer-mode
+grep '^MAINT.*#' Makefile
+
+sed 's/\(AM_MAINTAINER_MODE\).*/\1([foo])/' configure.ac > configure.tmp
+mv -f configure.tmp configure.ac
+$AUTOCONF --force -Werror && exit 1
+
+:
diff --git a/t/mmodely.sh b/t/mmodely.sh
new file mode 100644
index 000000000..19df3eac8
--- /dev/null
+++ b/t/mmodely.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Verify that intermediate files are only built from Yacc and Lex
+# sources in maintainer mode.
+# From Derek R. Price.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_MAINTAINER_MODE
+AC_PROG_CC
+AM_PROG_LEX
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+YACC = false
+LEX = false
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = zardoz.y joe.l
+LDADD = @LEXLIB@
+END
+
+# The point of this test is that it is not dependent on a working lex
+# or yacc.
+cat > joe.c <<EOF
+int joe (int arg)
+{
+ return arg * 2;
+}
+EOF
+# On systems which link in libraries non-lazily and whose linkers
+# complain about unresolved symbols by default, such as Solaris, an
+# yylex function needs to be defined to avoid an error due to an
+# unresolved symbol.
+cat > zardoz.c <<EOF
+int joe (int arg);
+int yylex (void)
+{
+ return 0;
+}
+int main (int argc, char **argv)
+{
+ return joe (argc);
+}
+EOF
+
+# Ensure a later timestamp for our Lex & Yacc sources.
+$sleep
+: > joe.l
+: > zardoz.y
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+
+cat >myyacc.sh <<'END'
+#! /bin/sh
+echo "$@" >y.tab.c
+END
+cat >mylex.sh <<'END'
+echo "$@" >lex.yy.c
+END
+chmod +x myyacc.sh mylex.sh
+PATH=$(pwd)$PATH_SEPARATOR$PATH; export PATH
+
+# "make maintainer-clean; ./configure; make" should always work,
+# per GNU Standard.
+$MAKE maintainer-clean
+./configure
+run_make YACC=myyacc.sh LEX=mylex.sh LEX_OUTPUT_ROOT=lex.yy zardoz.c joe.c
+$FGREP zardoz.y zardoz.c
+$FGREP joe.l joe.c
+
+:
diff --git a/t/no-extra-c-stuff.sh b/t/no-extra-c-stuff.sh
new file mode 100644
index 000000000..6939059a9
--- /dev/null
+++ b/t/no-extra-c-stuff.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that Automake doesn't generated rules or definitions related
+# to compilation of C sources for a project that doesn't use nor need
+# a C Compiler. Inspired by the issues reported in automake bug#14560.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([.])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([
+ Makefile
+ sub/Makefile
+ sub2/Makefile
+])
+AC_PROG_CXX
+AC_PROG_F77
+AC_OUTPUT
+END
+
+cat > Makefile.am <<END
+SUBDIRS = sub sub2
+bin_PROGRAMS = bar
+bar_SOURCES = bar.cc
+END
+
+mkdir sub sub2
+
+cat > sub/Makefile.am <<END
+bin_PROGRAMS = foo
+foo_SOURCES = foo.f
+END
+
+cat > sub2/Makefile.am <<END
+bin_PROGRAMS = baz
+baz_SOURCES = baz.cxx
+END
+
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+test -f install-sh
+test ! -e compile
+
+# Sanity checks.
+$FGREP '$(CXX)' Makefile.in
+$FGREP '$(CXX)' sub2/Makefile.in
+$FGREP '$(F77)' Makefile.in sub2/Makefile.in && exit 1
+$FGREP '$(F77)' sub/Makefile.in
+$FGREP '$(CXX)' sub/Makefile.in && exit 1
+
+$EGREP '(^COMPILE|$\(CC\)|AM_V_CC)' \
+ Makefile.in sub/Makefile.in sub2/Makefile.in && exit 1
+
+:
diff --git a/t/no-extra-makefile-code.sh b/t/no-extra-makefile-code.sh
new file mode 100644
index 000000000..48a7990b6
--- /dev/null
+++ b/t/no-extra-makefile-code.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that we don't emit harmless but useless code in the generated
+# Makefile.in when the project does not use compiled languages. Motivated
+# by a regression caused by removal of automatic de-ANSI-fication support:
+# <https://lists.gnu.org/archive/html/automake-patches/2011-08/msg00200.html>
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+: > Makefile.am
+
+# Automake shouldn't need nor require these.
+rm -f depcomp compile
+
+$ACLOCAL
+
+# Don't use '--add-missing' here, so that we can implicitly
+# check that the auxiliary scripts 'compile' and 'depcomp'
+# are not spuriously required by Automake.
+$AUTOMAKE
+
+$EGREP 'INCLUDES|@am__isrc@|-compile|\$\(OBJEXT\)|tab\.[ch]' \
+ Makefile.in && exit 1
+
+:
diff --git a/t/no-spurious-install-recursive.sh b/t/no-spurious-install-recursive.sh
new file mode 100644
index 000000000..f5c91374e
--- /dev/null
+++ b/t/no-spurious-install-recursive.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for install-recursive appearing in a non recursive Makefile.
+# Report from Bruno Haible.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+noinst_SCRIPTS = hostname
+include_HEADERS = gettext-po.h
+BUILT_SOURCES = po-hash-gen.c
+END
+
+$ACLOCAL
+$AUTOMAKE
+grep 'install-recursive' Makefile.in && exit 1
+
+:
diff --git a/t/nobase-libtool.sh b/t/nobase-libtool.sh
new file mode 100644
index 000000000..a17c44d6a
--- /dev/null
+++ b/t/nobase-libtool.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure nobase_* works for libtool libraries and programs as well.
+# This is just the libtool equivalent of 'nobase.sh', split up to allow
+# greater exposure of that test.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'EOF'
+fooexecdir = $(prefix)/foo
+fooexec_LTLIBRARIES = sub/libbase.la
+nobase_fooexec_LTLIBRARIES = sub/libnobase.la
+fooexec_PROGRAMS = sub/base
+nobase_fooexec_PROGRAMS = sub/nobase
+sub_libbase_la_SOURCES = source2.c
+sub_libnobase_la_SOURCES = source2.c
+sub_base_SOURCES = source.c
+sub_nobase_SOURCES = source.c
+
+test-install-data: install-data
+ test ! -f inst/foo/sub/libnobase.la
+ test ! -f inst/foo/libbase.la
+
+test-install-exec: install-exec
+ test -f inst/foo/sub/libnobase.la
+ test ! -f inst/foo/libnobase.la
+ test -f inst/foo/libbase.la
+
+.PHONY: test-install-exec test-install-data
+EOF
+
+mkdir sub
+
+cat >source.c <<'EOF'
+int main (int argc, char *argv[])
+{
+ return 0;
+}
+EOF
+cp source.c source2.c
+
+rm -f install-sh
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a --copy
+./configure --prefix "$(pwd)/inst" --program-prefix=p
+
+$MAKE
+$MAKE test-install-data
+$MAKE test-install-exec
+$MAKE uninstall
+
+test $(find inst/foo -type f -print | wc -l) -eq 0
+
+$MAKE install-strip
+
+# Likewise, in a VPATH build.
+
+$MAKE uninstall
+$MAKE distclean
+mkdir build
+cd build
+../configure --prefix "$(pwd)/inst" --program-prefix=p
+$MAKE
+$MAKE test-install-data
+$MAKE test-install-exec
+$MAKE uninstall
+test $(find inst/foo -type f -print | wc -l) -eq 0
+
+:
diff --git a/t/nobase-nodist.sh b/t/nobase-nodist.sh
new file mode 100644
index 000000000..3a6342b30
--- /dev/null
+++ b/t/nobase-nodist.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Interaction of 'nobase_' and 'nodist_' prefixes.
+
+. test-init.sh
+
+# Simulate no emacs and no python (it shouldn't be needed in this test).
+EMACS="no" PYTHON=":"; export EMCAS PYTHON
+
+cat >> configure.ac << 'END'
+AM_PATH_LISPDIR
+AM_PATH_PYTHON([], [], [:])
+# Simulate no javac (it shouldn't be needed in this test).
+AC_SUBST([JAVAC], [false])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+nobase_nodist_noinst_PYTHON = baz1.py sub/baz2.py
+# Lisp and Java sources are not distributed by default, so try both
+# with and without the 'nodist_' prefix, for more coverage.
+nobase_noinst_LISP = foo1.el sub/foo2.el
+nobase_nodist_noinst_LISP = foo3.el sub/foo4.el
+nobase_noinst_JAVA = bar1.java sub/bar2.java
+nobase_nodist_noinst_JAVA = bar3.java sub/bar4.java
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE distdir
+
+ls -l $distdir $distdir/* # For debugging.
+test ! -e $distdir/foo1.el
+test ! -e $distdir/sub/foo2.el
+test ! -e $distdir/foo3.el
+test ! -e $distdir/sub/foo4.el
+test ! -e $distdir/bar1.java
+test ! -e $distdir/sub/bar2.java
+test ! -e $distdir/bar3.java
+test ! -e $distdir/sub/bar4.java
+test ! -e $distdir/baz1.py
+test ! -e $distdir/sub/baz2.py
+
+:
diff --git a/t/nobase-python.sh b/t/nobase-python.sh
new file mode 100644
index 000000000..436bb5e82
--- /dev/null
+++ b/t/nobase-python.sh
@@ -0,0 +1,84 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure nobase_* works for python files.
+
+required=python
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AM_PATH_PYTHON
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'END'
+mydir=$(prefix)/my
+my_PYTHON = one.py sub/base.py
+nobase_my_PYTHON = two.py sub/nobase.py
+END
+
+test_install()
+{
+ $MAKE install-data
+ find inst -print # For debugging.
+ py_installed inst/my/one.py
+ py_installed inst/my/one.pyc
+ py_installed inst/my/two.py
+ py_installed inst/my/two.pyc
+ py_installed inst/my/base.py
+ py_installed inst/my/base.pyc
+ py_installed inst/my/sub/nobase.py
+ py_installed inst/my/sub/nobase.pyc
+ py_installed --not inst/my/nobase.py
+ py_installed --not inst/my/nobase.pyc
+}
+
+test_uninstall()
+{
+ $MAKE uninstall
+ test -d inst/my
+ ! find inst/my -type f -print | grep .
+}
+
+mkdir sub
+
+for file in one.py sub/base.py two.py sub/nobase.py; do
+ echo 'def one(): return 1' >$file
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure --prefix "$(pwd)/inst" --program-prefix=p
+
+$MAKE
+test_install
+test_uninstall
+
+$MAKE install-strip
+test_uninstall
+
+# Likewise, in a VPATH build.
+
+$MAKE distclean
+mkdir build
+cd build
+../configure --prefix "$(pwd)/inst" --program-prefix=p
+test_install
+test_uninstall
+
+:
diff --git a/t/nobase.sh b/t/nobase.sh
new file mode 100644
index 000000000..2bd1aa7ab
--- /dev/null
+++ b/t/nobase.sh
@@ -0,0 +1,147 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure nobase_* works.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'EOF'
+foodir = $(prefix)/foo
+fooexecdir = $(prefix)/foo
+
+foo_HEADERS = sub/base.h sub/base-gen.h
+nobase_foo_HEADERS = sub/nobase.h sub/nobase-gen.h
+
+dist_foo_DATA = sub/base.dat sub/base-gen.dat
+nobase_dist_foo_DATA = sub/nobase.dat sub/nobase-gen.dat
+
+dist_fooexec_SCRIPTS = sub/base.sh sub/base-gen.sh
+nobase_dist_fooexec_SCRIPTS = sub/nobase.sh sub/nobase-gen.sh
+
+fooexec_PROGRAMS = sub/base
+nobase_fooexec_PROGRAMS = sub/nobase
+sub_base_SOURCES = source.c
+sub_nobase_SOURCES = source.c
+
+fooexec_LIBRARIES = sub/libbase.a
+nobase_fooexec_LIBRARIES = sub/libnobase.a
+sub_libbase_a_SOURCES = source.c
+sub_libnobase_a_SOURCES = source.c
+
+generated_files = sub/base-gen.h sub/nobase-gen.h sub/base-gen.dat \
+sub/nobase-gen.dat sub/base-gen.sh sub/nobase-gen.sh
+
+$(generated_files):
+ $(MKDIR_P) sub
+ echo "generated file $@" > $@
+
+CLEANFILES = $(generated_files)
+
+test-install-data: install-data
+ test -f inst/foo/sub/nobase.h
+ test ! -f inst/foo/nobase.h
+ test -f inst/foo/sub/nobase-gen.h
+ test ! -f inst/foo/nobase-gen.h
+ test -f inst/foo/base.h
+ test -f inst/foo/base-gen.h
+ test -f inst/foo/sub/nobase.dat
+ test ! -f inst/foo/nobase.dat
+ test -f inst/foo/sub/nobase-gen.dat
+ test ! -f inst/foo/nobase-gen.dat
+ test -f inst/foo/base.dat
+ test -f inst/foo/base-gen.dat
+ test ! -f inst/foo/sub/pnobase.sh
+ test ! -f inst/foo/sub/pnobase-gen.sh
+ test ! -f inst/foo/pbase.sh
+ test ! -f inst/foo/pbase-gen.sh
+ test ! -f inst/foo/sub/pnobase$(EXEEXT)
+ test ! -f inst/foo/pbase$(EXEEXT)
+ test ! -f inst/foo/sub/libnobase.a
+ test ! -f inst/foo/libbase.a
+
+test-install-exec: install-exec
+ test -f inst/foo/sub/pnobase.sh
+ test ! -f inst/foo/pnobase.sh
+ test -f inst/foo/sub/pnobase-gen.sh
+ test ! -f inst/foo/pnobase-gen.sh
+ test -f inst/foo/pbase.sh
+ test -f inst/foo/pbase-gen.sh
+ test -f inst/foo/sub/pnobase$(EXEEXT)
+ test ! -f inst/foo/pnobase$(EXEEXT)
+ test -f inst/foo/pbase$(EXEEXT)
+ test -f inst/foo/sub/libnobase.a
+ test ! -f inst/foo/libnobase.a
+ test -f inst/foo/libbase.a
+
+.PHONY: test-install-exec test-install-data
+EOF
+
+mkdir sub
+
+: > sub/base.h
+: > sub/nobase.h
+: > sub/base.dat
+: > sub/nobase.dat
+: > sub/base.sh
+: > sub/nobase.sh
+
+cat >source.c <<'EOF'
+int
+main (int argc, char *argv[])
+{
+ return 0;
+}
+EOF
+cp source.c source2.c
+
+rm -f install-sh
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a --copy
+./configure --prefix "$(pwd)/inst" --program-prefix=p
+
+$MAKE
+$MAKE test-install-data
+$MAKE test-install-exec
+$MAKE uninstall
+
+test $(find inst/foo -type f -print | wc -l) -eq 0
+
+$MAKE install-strip
+
+# Likewise, in a VPATH build.
+
+$MAKE uninstall
+$MAKE distclean
+mkdir build
+cd build
+../configure --prefix "$(pwd)/inst" --program-prefix=p
+$MAKE
+$MAKE test-install-data
+$MAKE test-install-exec
+$MAKE uninstall
+test $(find inst/foo -type f -print | wc -l) -eq 0
+
+:
diff --git a/t/nodef.sh b/t/nodef.sh
new file mode 100644
index 000000000..1b1de36de
--- /dev/null
+++ b/t/nodef.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that PACKAGE and VERSION are AC_DEFINEd when requested.
+
+. test-init.sh
+
+# -------------------------------------------------------------------
+# Do not upgrade this file to use the modern AC_INIT/AM_INIT_AUTOMAKE
+# forms. The day these obsolete AC_INIT and AM_INIT_AUTOMAKE forms
+# are dropped, just erase the file.
+# nodef2.test contains the modern version of this test.
+# -------------------------------------------------------------------
+
+# First, check that PACKAGE and VERSION are output by default.
+
+cat > configure.ac << 'END'
+AC_INIT
+AM_INIT_AUTOMAKE([UnIqUe_PaCkAgE], [UnIqUe_VeRsIoN])
+AC_OUTPUT(output)
+END
+
+echo 'DEFS = @DEFS@' > output.in
+
+$ACLOCAL
+$AUTOCONF
+./configure
+
+grep 'DEFS.*-DVERSION=\\"UnIqUe' output
+
+# Then, check that PACKAGE and VERSION are not output if requested.
+
+cat > configure.ac << 'END'
+AC_INIT
+AM_INIT_AUTOMAKE([UnIqUe_PaCkAgE], [UnIqUe_VeRsIoN], [no])
+AC_OUTPUT(output)
+END
+
+$ACLOCAL
+$AUTOCONF
+./configure
+
+grep 'DEFS.*-DVERSION=\\"UnIqUe' output && exit 1
+
+:
diff --git a/t/nodef2.sh b/t/nodef2.sh
new file mode 100644
index 000000000..f39009c32
--- /dev/null
+++ b/t/nodef2.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that PACKAGE and VERSION are AC_DEFINEd when requested.
+
+. test-init.sh
+
+# First, check that PACKAGE and VERSION are output by default.
+
+cat > configure.ac << 'END'
+AC_INIT([UnIqUe_PaCkAgE], [UnIqUe_VeRsIoN])
+AM_INIT_AUTOMAKE
+AC_OUTPUT(output)
+END
+
+echo 'DEFS = @DEFS@' > output.in
+
+$ACLOCAL
+$AUTOCONF
+./configure
+
+grep 'DEFS.*-DVERSION=\\"UnIqUe' output
+
+# Then, check that PACKAGE and VERSION are not output if requested.
+
+cat > configure.ac << 'END'
+AC_INIT([UnIqUe_PaCkAgE], [UnIqUe_VeRsIoN])
+AM_INIT_AUTOMAKE([no-define])
+AC_OUTPUT(output Makefile)
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE # Dummy call to make sure Automake grok 'no-define' silently.
+./configure
+
+grep 'DEFS.*-DVERSION=\\"UnIqUe' output && exit 1
+
+:
diff --git a/t/nodep.sh b/t/nodep.sh
new file mode 100644
index 000000000..a3dc815df
--- /dev/null
+++ b/t/nodep.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure no-dependencies option does the right thing.
+# Bug report from Greg A. Woods.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = y.c
+END
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+mkdir x
+
+: > y.c
+
+$ACLOCAL
+$AUTOMAKE
+
+sed 's/printf .*%s//' Makefile.in > Makefile.tmp
+grep '%' Makefile.tmp && exit 1
+
+:
diff --git a/t/nodep2.sh b/t/nodep2.sh
new file mode 100644
index 000000000..030e8865b
--- /dev/null
+++ b/t/nodep2.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another test to make sure no-dependencies option does the right thing.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = a.c b.cpp c.m cxx.mm d.S e.java f.upc
+END
+
+cat > configure.ac << 'END'
+AC_INIT([nodep2], [1], [bug-automake@gnu.org])
+AM_INIT_AUTOMAKE([no-dependencies])
+AC_CONFIG_FILES([Makefile])
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_OBJC
+AC_PROG_OBJCXX
+AM_PROG_AS
+AM_PROG_GCJ
+AM_PROG_UPC
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep DEPMODE Makefile.in && exit 1
+
+:
diff --git a/t/nodepcomp.sh b/t/nodepcomp.sh
new file mode 100644
index 000000000..96a57ec8d
--- /dev/null
+++ b/t/nodepcomp.sh
@@ -0,0 +1,26 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure depcomp isn't always required.
+
+. test-init.sh
+
+rm -f depcomp
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
diff --git a/t/nodist.sh b/t/nodist.sh
new file mode 100644
index 000000000..c299b3abd
--- /dev/null
+++ b/t/nodist.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure dist_*_SOURCES and nodist_*_SOURCES work.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = eyeball
+
+eyeball_SOURCES = a.c
+nodist_eyeball_SOURCES = b.c
+dist_eyeball_SOURCES = c.c
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^am_eyeball_OBJECTS' Makefile.in
+grep '^DIST_SOURCES =' Makefile.in
+grep '^DIST_SOURCES =.*nodist' Makefile.in && exit 1
+
+:
diff --git a/t/nodist2.sh b/t/nodist2.sh
new file mode 100644
index 000000000..d43528628
--- /dev/null
+++ b/t/nodist2.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure nodist_noinst_HEADERS work.
+# For PR 249.
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'EOF'
+nodist_noinst_HEADERS = baz.h
+EOF
+
+: > baz.h
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure --prefix "$(pwd)/install"
+$MAKE install-data
+
+:
diff --git a/t/nodist3.sh b/t/nodist3.sh
new file mode 100644
index 000000000..354995939
--- /dev/null
+++ b/t/nodist3.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure no-dist option works.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dist
+bin_PROGRAMS = eyeball
+eyeball_SOURCES = a.c
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^dist:' Makefile.in && exit 1
+grep '^DIST_SOURCES =' Makefile.in && exit 1
+
+:
diff --git a/t/noinst.sh b/t/noinst.sh
new file mode 100644
index 000000000..4de379854
--- /dev/null
+++ b/t/noinst.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check to make sure "make install" will build all in directory with
+# nothing to install.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+all-local:
+ exit 1
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^install[-a-z]*:.* all' Makefile.in
+
+:
diff --git a/t/noinstdir.sh b/t/noinstdir.sh
new file mode 100644
index 000000000..cab00fd0c
--- /dev/null
+++ b/t/noinstdir.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that noinst_* and check_* are not installed.
+# From Pavel Roskin.
+
+required=cc
+. test-init.sh
+
+cat > Makefile.am << 'END'
+noinst_SCRIPTS = foo.sh
+noinst_DATA = foo.xpm
+noinst_LIBRARIES = libfoo.a
+noinst_PROGRAMS = foo
+noinst_HEADERS = foo.h
+check_SCRIPTS = bar.sh
+check_DATA = bar.xpm
+check_LIBRARIES = libbar.a
+check_PROGRAMS = bar
+check_HEADERS = bar.h
+END
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+: > ar-lib
+
+$ACLOCAL
+$AUTOMAKE
+
+$EGREP '(noinst|check)dir' Makefile.in && exit 1
+
+$AUTOCONF
+./configure --prefix="$(pwd)/inst"
+
+echo 'int main (void) { return 0; }' > foo.c
+echo 'int main (void) { return 0; }' > bar.c
+
+echo 'int foo (void) { return 0; }' > libfoo.c
+echo 'int bar (void) { return 0; }' > libbar.c
+
+: > foo.sh
+: > foo.xpm
+: > foo.h
+: > bar.sh
+: > bar.xpm
+: > bar.h
+
+$MAKE
+$MAKE install
+test ! -e inst
+
+:
diff --git a/t/nolink.sh b/t/nolink.sh
new file mode 100644
index 000000000..63b78fb1c
--- /dev/null
+++ b/t/nolink.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake does not emit a link rule for unknown languages.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-exeext
+
+bin_PROGRAMS = meal
+meal_SOURCES = beans.veg beef.meat
+
+meal: beans.veg beef.meat
+ cat beans.veg beef.meat > meal
+END
+
+$ACLOCAL
+$AUTOMAKE -Wno-override
+
+grep '^meal.*:' Makefile.in | grep -v beef.meat && exit 1
+
+exit 0
diff --git a/t/nostdinc.sh b/t/nostdinc.sh
new file mode 100644
index 000000000..eeb774278
--- /dev/null
+++ b/t/nostdinc.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure nostdinc option works correctly.
+
+# We don't require a C compiler explicitly, because the first part of the
+# test (where 'Makefile.in' is grepped) does not require one. Insted, we
+# just skip the rest of the test if configure fails to find a working C
+# compiler.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = nostdinc
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$EGREP '(-I *\.|-I.*srcdir|am__isrc)' Makefile.in && exit 1
+
+# We'll test the fully-processed Makefile too.
+$AUTOCONF
+
+# Test with $builddir != $srcdir
+mkdir build
+cd build
+../configure || exit $?
+$EGREP '.*-I *(\.|\$.srcdir.)' Makefile && exit 1
+
+# Test with $builddir = $srcdir
+cd ..
+./configure || exit $?
+$EGREP '.*-I *(\.|\$.srcdir.)' Makefile && exit 1
+
+exit 0
diff --git a/t/notrans.sh b/t/notrans.sh
new file mode 100644
index 000000000..ce9b421c2
--- /dev/null
+++ b/t/notrans.sh
@@ -0,0 +1,135 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check all notrans_, dist_, nodist_ prefix combinations for MANS
+# primary and install-man dependencies.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'EOF'
+man_MANS = foo.1 foo2.1
+dist_man_MANS = bar.2 bar2.2
+nodist_man_MANS = baz.3 baz2.3
+notrans_man_MANS = x-foo.4 x-foo2.4
+notrans_dist_man_MANS = x-bar.5 x-bar2.5
+notrans_nodist_man_MANS = x-baz.6 x-baz2.6
+man7_MANS = y-foo.man y-foo2.man
+dist_man5_MANS = y-bar.man y-bar2.man
+nodist_man4_MANS = y-baz.man y-baz2.man
+notrans_man3_MANS = z-foo.man z-foo2.man
+notrans_dist_man2_MANS = z-bar.man z-bar2.man
+notrans_nodist_man1_MANS = z-baz.man z-baz2.man
+
+# These two are ignored.
+dist_notrans_man_MANS = nosuch.8
+nodist_notrans_man9_MANS = nosuch.man
+
+y-foo.man y-foo2.man:
+ : >$@
+y-bar.man y-bar2.man:
+ : >$@
+y-baz.man y-baz2.man:
+ : >$@
+z-foo.man z-foo2.man:
+ : >$@
+z-bar.man z-bar2.man:
+ : >$@
+z-baz.man z-baz2.man:
+ : >$@
+
+test-install: install
+ test -f inst/man/man1/gnu-foo.1
+ test -f inst/man/man1/gnu-foo2.1
+ test -f inst/man/man2/gnu-bar.2
+ test -f inst/man/man2/gnu-bar2.2
+ test -f inst/man/man3/gnu-baz.3
+ test -f inst/man/man3/gnu-baz2.3
+ test -f inst/man/man4/x-foo.4
+ test -f inst/man/man4/x-foo2.4
+ test -f inst/man/man5/x-bar.5
+ test -f inst/man/man5/x-bar2.5
+ test -f inst/man/man6/x-baz.6
+ test -f inst/man/man6/x-baz2.6
+ test -f inst/man/man7/gnu-y-foo.7
+ test -f inst/man/man7/gnu-y-foo2.7
+ test -f inst/man/man5/gnu-y-bar.5
+ test -f inst/man/man5/gnu-y-bar2.5
+ test -f inst/man/man4/gnu-y-baz.4
+ test -f inst/man/man4/gnu-y-baz2.4
+ test -f inst/man/man3/z-foo.3
+ test -f inst/man/man3/z-foo2.3
+ test -f inst/man/man2/z-bar.2
+ test -f inst/man/man2/z-bar2.2
+ test -f inst/man/man1/z-baz.1
+ test -f inst/man/man1/z-baz2.1
+ test ! -d inst/man/man8
+ test ! -d inst/man/man9
+EOF
+
+: > foo.1
+: > foo2.1
+: > bar.2
+: > bar2.2
+: > baz.3
+: > baz2.3
+: > x-foo.4
+: > x-foo2.4
+: > x-bar.5
+: > x-bar2.5
+: > x-baz.6
+: > x-baz2.6
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+grep '^install-man1:' Makefile.in | grep '\$(man_MANS)'
+grep '^install-man2:' Makefile.in | grep '\$(dist_man_MANS)'
+grep '^install-man3:' Makefile.in | grep '\$(nodist_man_MANS)'
+grep '^install-man4:' Makefile.in | grep '\$(notrans_man_MANS)'
+grep '^install-man5:' Makefile.in | grep '\$(notrans_dist_man_MANS)'
+grep '^install-man6:' Makefile.in | grep '\$(notrans_nodist_man_MANS)'
+grep '^install-man8:' Makefile.in && exit 1
+grep '^install-man9:' Makefile.in && exit 1
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+./configure --program-prefix=gnu- --prefix "$cwd"/inst \
+ --mandir "$cwd"/inst/man
+$MAKE
+$MAKE test-install
+test $(find inst/man -type f -print | wc -l) -eq 24
+$MAKE uninstall
+test $(find inst/man -type f -print | wc -l) -eq 0
+
+# Opportunistically test for installdirs.
+rm -rf inst
+$MAKE installdirs
+test -d inst/man/man1
+test -d inst/man/man2
+test -d inst/man/man3
+test -d inst/man/man4
+test -d inst/man/man5
+test -d inst/man/man6
+test -d inst/man/man7
+test -d inst/man/man8 && exit 1
+test -d inst/man/man9 && exit 1
+
+:
diff --git a/t/number.sh b/t/number.sh
new file mode 100644
index 000000000..1a5742a6e
--- /dev/null
+++ b/t/number.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure _OBJECTS is only generated once. Bug reported by
+# Joerg-Martin Schwarz.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^zardoz_OBJECTS' Makefile.in
+test $(grep -c '^zardoz_OBJECTS' Makefile.in) -eq 1
+
+:
diff --git a/t/objc-basic.sh b/t/objc-basic.sh
new file mode 100644
index 000000000..8dad76f8b
--- /dev/null
+++ b/t/objc-basic.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# Basic tests on the Objective C support that don't actually
+# require an Objective-C compiler.
+# See also sister test 'objcxx-basic.sh'.
+
+. test-init.sh
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = hello
+hello_SOURCES = hello.m
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep "'OBJC'.* undefined" stderr
+grep "add .*'AC_PROG_OBJC'" stderr
+
+rm -rf autom4te*.cache
+
+echo AC_PROG_OBJC >> configure.ac
+
+$ACLOCAL
+$AUTOMAKE
+$EGREP '^\.SUFFIXES:.* \.m( |$)' Makefile.in
+
+:
diff --git a/t/objc-deps.sh b/t/objc-deps.sh
new file mode 100644
index 000000000..60585bbd2
--- /dev/null
+++ b/t/objc-deps.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automatic dependency tracking for Objective C.
+# See also sister test 'objcxx-deps.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_OBJC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = bar.m baz.h baz2.h
+END
+
+cat > baz.h << 'END'
+#include <stdio.h>
+#include <stdlib.h>
+#include "baz2.h"
+END
+
+cat > baz2.h << 'END'
+#define MSG "Hello, World"
+END
+
+cat > bar.m << 'END'
+/* The use of #import makes this valid Object C but invalid C. */
+#import "baz.h"
+int main (void)
+{
+ fprintf (stdout, "%s\n", MSG);
+ return EXIT_SUCCESS;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure --enable-dependency-tracking
+$MAKE
+cross_compiling || (./foo | $FGREP 'Hello, World') || exit 1
+$sleep
+: > old
+echo '#define MSG "Howdy, Earth"' > baz2.h
+$MAKE
+if test -f foo; then
+ is_newest foo old
+else
+ is_newest foo.exe old
+fi
+cross_compiling || (./foo | $FGREP 'Howdy, Earth') || exit 1
+
+$MAKE distcheck
+
+:
diff --git a/t/objc-flags.sh b/t/objc-flags.sh
new file mode 100644
index 000000000..e493935ef
--- /dev/null
+++ b/t/objc-flags.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test Objective C compilation flags.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_OBJC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_DEFAULT_SOURCE_EXT = .m
+bin_PROGRAMS = foo2 foo4
+AM_OBJCFLAGS = -DVALUE=2 -DERROR=1
+foo4_OBJCFLAGS = -DVALUE=4 -DERROR=1
+END
+
+for i in 2 4; do
+ unindent > foo$i.m << END
+ /* Let's make this file valid Objective C but invalid C. */
+ #import <stdlib.h>
+ @interface Who_Cares { } @end
+ #ifdef ERROR
+ # error "macro ERROR is defined for foo.m"
+ #else
+ # if VALUE == $i
+ int main (void) { exit (0); }
+ # else
+ # error "VALUE is != $i in foo.m"
+ # endif
+ #endif
+END
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+$FGREP OBJCFLAGS Makefile.in # For debugging.
+grep '\$(OBJCFLAGS).*\$(AM_OBJCFLAGS)' Makefile.in && exit 1
+grep '\$(OBJCFLAGS).*\$(foo.*_OBJCFLAGS)' Makefile.in && exit 1
+grep '\$(foo.*_OBJCFLAGS).*\$(AM_OBJCFLAGS)' Makefile.in && exit 1
+
+./configure OBJCFLAGS=-UERROR
+$MAKE
+
+:
diff --git a/t/objc-megademo.sh b/t/objc-megademo.sh
new file mode 100644
index 000000000..244ac9a5c
--- /dev/null
+++ b/t/objc-megademo.sh
@@ -0,0 +1,340 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Stress test on Objective C/C++.
+
+required=libtoolize
+am_create_testdir=empty
+. test-init.sh
+
+## Autotools Input Files.
+
+cat > configure.ac << 'END'
+AC_INIT([play], [1.3], [bug-automake@gnu.org])
+
+AC_CONFIG_SRCDIR([play.c])
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_MACRO_DIR([m4])
+
+AM_INIT_AUTOMAKE
+
+AM_PROG_AR
+LT_INIT
+
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_OBJC
+AC_PROG_OBJCXX
+
+AC_LANG_PUSH([Objective C])
+AC_CACHE_CHECK(
+ [whether the Objective C compiler really works],
+ [my_cv_objc_works],
+ [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#import <stdio.h>]],
+ [[printf ("foo\n");]])],
+ [my_cv_objc_works=yes],
+ [my_cv_objc_works=no])])
+AC_LANG_POP([Objective C])
+
+AC_LANG_PUSH([Objective C++])
+AC_CACHE_CHECK(
+ [whether the Objective C++ compiler really works],
+ [my_cv_objcxx_works],
+ [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#import <iostream>]],
+ [[std::cout << "foo" << "\n";]])],
+ [my_cv_objcxx_works=yes],
+ [my_cv_objcxx_works=no])])
+AC_LANG_POP([Objective C++])
+
+if test $my_cv_objc_works != yes; then
+ AC_MSG_ERROR([couldn't find a working Objective C compiler], [77])
+fi
+
+if test $my_cv_objcxx_works != yes; then
+ AC_MSG_ERROR([couldn't find a working Objective C++ compiler], [77])
+fi
+
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_FILES([Makefile])
+
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = play
+play_SOURCES = play.h play.c playxx.cxx playo.m playoxx.mm
+play_LDADD = libfoo.la
+play_LDFLAGS = -lobjc
+lib_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = foo.h foo.c fooxx.cxx fooo.m foooxx.mm
+END
+
+## Run Autotools.
+
+libtoolize
+$ACLOCAL
+$AUTOHEADER
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+## Program Sources.
+
+cat > play.h << 'END'
+#ifndef PLAY_H
+#define PLAY_H
+
+#include "foo.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void hello_cxx (void);
+void hello_objc (void);
+void hello_objcxx (void);
+
+#ifdef __OBJC__
+@interface Hello_ObjC
+{ }
++ (void)display;
+@end
+#endif /* __OBJC__ */
+
+#ifdef __cplusplus
+}
+
+class Hello_CXX
+{
+ public:
+ Hello_CXX() { }
+ virtual ~Hello_CXX () { }
+ void hello_cxx ();
+};
+
+#ifdef __OBJC__
+@interface Hello_ObjCXX
+{ }
++ (void)display;
+@end
+
+class Hello_OBJCXX
+{
+ public:
+ Hello_OBJCXX () { }
+ virtual ~Hello_OBJCXX () { }
+ void hello_objcxx();
+};
+#endif /* __OBJC__ */
+
+#endif /* __cplusplus */
+
+#endif /* PLAY_H */
+END
+
+cat > play.c << 'END'
+#include "play.h"
+int main (void)
+{
+ printf ("[Hello C,");
+ world_c ();
+ hello_cxx ();
+ hello_objc ();
+ hello_objcxx ();
+ return 0;
+}
+END
+
+cat > playxx.cxx << 'END'
+#include "play.h"
+
+void hello_cxx(void)
+{
+ Hello_CXX *hello = new Hello_CXX;
+ hello->hello_cxx();
+}
+
+void Hello_CXX::hello_cxx()
+{
+ std::cout << "[Hello C++,";
+ World_CXX *world = new World_CXX;
+ world->world_cxx();
+}
+END
+
+cat > playo.m << 'END'
+#import "play.h"
+
+void hello_objc (void)
+{
+ [Hello_ObjC display];
+}
+
+@implementation Hello_ObjC
++ (void)display
+{
+ printf ("[Hello ObjC,");
+ [World_ObjC display];
+}
+@end
+END
+
+cat > playoxx.mm << 'END'
+#import "play.h"
+
+// Calling: C -> C++ -> ObjC
+
+void hello_objcxx (void)
+{
+ Hello_OBJCXX *hello = new Hello_OBJCXX;
+ hello->hello_objcxx ();
+}
+
+void Hello_OBJCXX::hello_objcxx ()
+{
+ [Hello_ObjCXX display];
+}
+
+@implementation Hello_ObjCXX
++ (void)display
+{
+ std::cout << "[Hello ObjC++,";
+ [World_ObjCXX display];
+}
+@end
+END
+
+## Library Sources.
+
+cat > foo.h << 'END'
+#ifndef FOO_H
+#define FOO_H
+
+#ifdef __cplusplus
+#include <iostream>
+extern "C" {
+#else
+#include <stdio.h>
+#endif
+
+void world_c (void);
+
+#ifdef __OBJC__
+@interface World_ObjC
+{ }
++ (void)display;
+@end
+#endif /* __OBJC__ */
+
+#ifdef __cplusplus
+}
+
+class World_CXX
+{
+ public:
+ World_CXX() { }
+ virtual ~World_CXX () { }
+ void world_cxx ();
+};
+
+#ifdef __OBJC__
+class World_OBJCXX
+{
+ public:
+ World_OBJCXX () { }
+ virtual ~World_OBJCXX () { }
+ void world_objcxx ();
+};
+
+@interface World_ObjCXX
+{ }
++ (void)display;
+@end
+#endif /* __OBJC__ */
+
+#endif /* __cplusplus */
+
+#endif /* FOO_H */
+END
+
+cat > foo.c << 'END'
+#include "foo.h"
+
+void world_c (void)
+{
+ printf (" world C]\n");
+}
+END
+
+cat > fooxx.cxx << 'END'
+#include "foo.h"
+
+void World_CXX::world_cxx ()
+{
+ std::cout << " world C++]" << "\n";
+}
+END
+
+cat > fooo.m << 'END'
+#import "foo.h"
+
+@implementation World_ObjC
++ (void)display
+{
+ printf (" world ObjC]\n");
+}
+@end
+END
+
+cat > foooxx.mm << 'END'
+#import "foo.h"
+
+// Calling: ObjC -> C++
+
+@implementation World_ObjCXX
++ (void)display
+{
+ World_OBJCXX *world = new World_OBJCXX;
+ world->world_objcxx ();
+}
+@end
+
+void World_OBJCXX::world_objcxx ()
+{
+ std::cout << " world ObjC++]" << "\n";
+}
+END
+
+## Configure and build.
+
+./configure
+$MAKE
+
+if ! cross_compiling; then
+ unindent > exp << 'END'
+ [Hello C, world C]
+ [Hello C++, world C++]
+ [Hello ObjC, world ObjC]
+ [Hello ObjC++, world ObjC++]
+END
+ ./play > got || { cat got; exit 1; }
+ cat exp
+ cat got
+ diff exp got
+fi
+
+$MAKE distcheck
+
+:
diff --git a/t/objc-minidemo.sh b/t/objc-minidemo.sh
new file mode 100644
index 000000000..5dfa7fdf6
--- /dev/null
+++ b/t/objc-minidemo.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Dummy demo package using Objective C and doing distcheck.
+# See also sister test 'objcxx-minidemo.sh'.
+
+required=native
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_OBJC
+AC_CONFIG_HEADERS([config.h])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_DEFAULT_SOURCE_EXT = .m
+bin_PROGRAMS = ok
+noinst_PROGRAMS = ko
+TESTS = $(bin_PROGRAMS) $(XFAIL_TESTS)
+XFAIL_TESTS = $(noinst_PROGRAMS)
+END
+
+cat > ok.m << 'END'
+/* The use of #import makes this valid Object C but invalid C. */
+#import <stdio.h>
+#import <config.h>
+int main (void)
+{
+ printf ("Success (%s)\n", PACKAGE_STRING);
+ return 0;
+}
+END
+
+cat > ko.m << 'END'
+/* The use of #import makes this valid Object C but invalid C. */
+#import <stdio.h>
+int main (void)
+{
+ printf("Failure\n");
+ return 1;
+}
+END
+
+if $ACLOCAL; then
+ : We have a modern enough autoconf, go ahead.
+elif test $? -eq 63; then
+ skip_ "Object C++ support requires Autoconf 2.65 or later"
+else
+ exit 1 # Some other aclocal failure.
+fi
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE --add-missing
+
+./configure
+$MAKE
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/objcxx-basic.sh b/t/objcxx-basic.sh
new file mode 100644
index 000000000..b4a0944d9
--- /dev/null
+++ b/t/objcxx-basic.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# Basic tests on the Objective C++ support that don't actually
+# require an Objective-C++ compiler.
+# See also sister test 'objc-basic.sh'.
+
+. test-init.sh
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = hello
+hello_SOURCES = hello.mm
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep "'OBJCXX'.* undefined" stderr
+grep "add .*'AC_PROG_OBJCXX'" stderr
+
+rm -rf autom4te*.cache
+
+cat >> configure.ac <<'END'
+AC_PROG_OBJCXX
+END
+
+$ACLOCAL
+$AUTOMAKE
+$EGREP '^\.SUFFIXES:.* \.mm( |$)' Makefile.in
+
+:
diff --git a/t/objcxx-deps.sh b/t/objcxx-deps.sh
new file mode 100644
index 000000000..f7e2dbf8e
--- /dev/null
+++ b/t/objcxx-deps.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automatic dependency tracking for Objective C++.
+# See also sister test 'objc-deps.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_OBJCXX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = bar.mm baz.h++ baz2.hh
+END
+
+cat > baz.h++ << 'END'
+#include <iostream>
+#include "baz2.hh"
+END
+
+cat > baz2.hh << 'END'
+#define MSG "Hello, World"
+END
+
+cat > bar.mm << 'END'
+/* The use of #import makes this valid Object C++ but invalid C++. */
+#import "baz.h++"
+int main (void)
+{
+ std::cout << MSG << "\n";
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure --enable-dependency-tracking
+$MAKE
+cross_compiling || (./foo | $FGREP 'Hello, World') || exit 1
+
+$sleep
+: > old
+echo '#define MSG "Howdy, Earth"' > baz2.hh
+$MAKE
+if test -f foo; then
+ is_newest foo old
+else
+ is_newest foo.exe old
+fi
+cross_compiling || (./foo | $FGREP 'Howdy, Earth') || exit 1
+
+$MAKE distcheck
+
+:
diff --git a/t/objcxx-flags.sh b/t/objcxx-flags.sh
new file mode 100644
index 000000000..928bc56b7
--- /dev/null
+++ b/t/objcxx-flags.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test Objective C++ compilation flags.
+# See also sister test 'objc-flags.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_OBJCXX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_DEFAULT_SOURCE_EXT = .mm
+bin_PROGRAMS = foo2 foo4
+AM_OBJCXXFLAGS = -DVALUE=2 -DERROR=1
+foo4_OBJCXXFLAGS = -DVALUE=4 -DERROR=1
+END
+
+for i in 2 4; do
+ unindent > foo$i.mm << END
+ /* Let's make this file valid Objective C but invalid C. */
+ #import <stdlib.h>
+ @interface Who_Cares { } @end
+ #ifdef ERROR
+ # error "macro ERROR is defined for foo.mm"
+ #else
+ # if VALUE == $i
+ int main (void) { exit (0); }
+ # else
+ # error "VALUE is != $i in foo.mm"
+ # endif
+ #endif
+END
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+$FGREP OBJCXXFLAGS Makefile.in # For debugging.
+grep '\$(OBJCXXFLAGS).*\$(AM_OBJCXXFLAGS)' Makefile.in && exit 1
+grep '\$(OBJCXXFLAGS).*\$(foo.*_OBJCXXFLAGS)' Makefile.in && exit 1
+grep '\$(foo.*_OBJCXXFLAGS).*\$(AM_OBJCXXFLAGS)' Makefile.in && exit 1
+
+./configure OBJCXXFLAGS=-UERROR
+$MAKE
+
+:
diff --git a/t/objcxx-minidemo.sh b/t/objcxx-minidemo.sh
new file mode 100644
index 000000000..e8a0e4d71
--- /dev/null
+++ b/t/objcxx-minidemo.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Dummy demo package using Objective C++ and doing distcheck.
+# See also sister test 'objc-minidemo.sh'.
+
+required=native
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_OBJCXX
+AC_CONFIG_HEADERS([config.h])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_DEFAULT_SOURCE_EXT = .mm
+bin_PROGRAMS = ok
+noinst_PROGRAMS = ko
+TESTS = $(bin_PROGRAMS) $(XFAIL_TESTS)
+XFAIL_TESTS = $(noinst_PROGRAMS)
+END
+
+cat > ok.mm << 'END'
+/* The use of #import makes this valid Object C++ but invalid C++. */
+#import <iostream>
+#import <config.h>
+int main (void)
+{
+ std::cout << "Success (" << PACKAGE_STRING << ")\n";
+ return 0;
+}
+END
+
+cat > ko.mm << 'END'
+/* The use of #import makes this valid Object C++ but invalid C++. */
+#import <cstdio>
+int main (void)
+{
+ printf("Failure\n");
+ return 1;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE --add-missing
+
+./configure
+$MAKE
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/objext-pr10128.sh b/t/objext-pr10128.sh
new file mode 100644
index 000000000..ea738ecc8
--- /dev/null
+++ b/t/objext-pr10128.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for automake bug#10128: $(OBJEXT) redefinition causes
+# $(foo_OBJECTS) to be defined as empty.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+LINK = echo >$@ Linked $@ from
+OBJEXT = fasl
+EXEEXT =
+
+noinst_PROGRAMS = foo zardoz
+foo_SOURCES = foo.lisp
+zardoz_SOURCES = mu1.lisp mu2.lisp
+
+## Un-commenting this is enough to make the test pass. Weird!
+##.lisp.o:
+
+.lisp.fasl:
+ touch $@
+
+.PHONY: test
+test:
+ is $(foo_OBJECTS) == foo.fasl
+ is $(zardoz_OBJECTS) == mu1.fasl mu2.fasl
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE test
+touch foo.lisp mu1.lisp mu2.lisp
+$MAKE all
+cat foo
+cat zardoz
+test "$(cat foo)" = "Linked foo from foo.fasl"
+test "$(cat zardoz)" = "Linked zardoz from mu1.fasl mu2.fasl"
+
+:
diff --git a/t/oldvars.sh b/t/oldvars.sh
new file mode 100644
index 000000000..6a1ec9f06
--- /dev/null
+++ b/t/oldvars.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Use of these variables is deprecated:
+# LISP, HEADERS, DATA, SCRIPTS, LTLIBRARIES, LIBRARIES, PROGRAMS, MANS.
+
+. test-init.sh
+
+cat >Makefile.am <<\EOF
+DATA =
+HEADERS =
+LIBRARIES =
+LISP =
+LTLIBRARIES =
+MANS =
+PROGRAMS =
+SCRIPTS =
+EOF
+
+$ACLOCAL
+AUTOMAKE_fails
+test $(grep -c anachronism stderr) -eq 8
+
+:
diff --git a/t/order.sh b/t/order.sh
new file mode 100644
index 000000000..67a5d87b4
--- /dev/null
+++ b/t/order.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure AC_DEFUN is handled correctly. This test isn't named very
+# well. Report from Jim Meyering.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+jm_TEST
+FOO
+END
+
+cat > acinclude.m4 << 'END'
+AC_DEFUN([jm_TEST])
+AC_DEFUN([FOO], [AC_REQUIRE([jm_TEST])])
+END
+
+$ACLOCAL
diff --git a/t/output-order.sh b/t/output-order.sh
new file mode 100644
index 000000000..457d33d5e
--- /dev/null
+++ b/t/output-order.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that 'automake -a' output order is stable.
+# From report by Bruno Haible.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_OUTPUT
+END
+
+: >Makefile.am
+: >AUTHORS
+: >ChangeLog
+: >NEWS
+: >README
+
+cat >.autom4te.cfg <<'END'
+begin-language: "Autoconf"
+args: --no-cache
+end-language: "Autoconf"
+begin-language: "Autoconf-without-aclocal-m4"
+args: --no-cache
+end-language: "Autoconf-without-aclocal-m4"
+END
+
+$ACLOCAL
+$AUTOCONF
+rm -f missing install-sh
+$AUTOMAKE --add-missing --copy 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+
+for i in 1 2 3 4 5 6; do
+ rm -f missing install-sh INSTALL COPYING
+ # The grep prevents a Heisenbug with the HP-UX shell and VERBOSE=yes.
+ $AUTOMAKE --add-missing --copy 2>&1 >/dev/null |
+ grep -v /dev/null |
+ diff - stderr
+done
diff --git a/t/output.sh b/t/output.sh
new file mode 100644
index 000000000..f0474be1b
--- /dev/null
+++ b/t/output.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure files listed in AC_OUTPUT are found.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT([Makefile frob/zardoz])
+END
+
+: > Makefile.am
+
+mkdir frob
+: > frob/zardoz.in
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/output10.sh b/t/output10.sh
new file mode 100644
index 000000000..8957104c1
--- /dev/null
+++ b/t/output10.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure an AC_CONFIG_FILES can have an AC_CONFIG_FILES output as input.
+# This is comparable to 'output9.sh', but testing Makefile rules.
+# PR/411
+
+. test-init.sh
+
+cat >> configure.ac << END
+AC_SUBST([FOO], [top])
+AC_SUBST([BAR], [bot])
+AC_CONFIG_FILES([a/top])
+AC_CONFIG_FILES([a/bot])
+AC_CONFIG_FILES([b/Makefile:a/top:b/Makefile.in:a/bot])
+AC_OUTPUT
+END
+
+mkdir a
+mkdir b
+
+cat >Makefile.am <<\EOF
+SUBDIRS = b
+dist-hook:
+ test ! -f $(distdir)/a/top
+ test ! -f $(distdir)/a/bot
+EOF
+
+cat >b/Makefile.am <<\EOF
+output:
+ echo $(TOP)$(BOT) > ok
+EOF
+
+echo TOP=@FOO@ >a/top.in
+echo BOT=@BAR@ >a/bot.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+mkdir build
+cd build
+../configure
+cd b
+$MAKE output
+grep topbot ok
+cd ..
+$MAKE distcheck
diff --git a/t/output11.sh b/t/output11.sh
new file mode 100644
index 000000000..f91ec810b
--- /dev/null
+++ b/t/output11.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure an AC_CONFIG_FILES ignore filenames with shell variables.
+
+. test-init.sh
+
+cat >> configure.ac << \END
+AC_SUBST([FOO], [foo])
+file1=this.in
+echo @FOO@ >$file1
+file2=that
+file3=mumble
+file4=foo
+AC_CONFIG_FILES([this:$file1],, [file1=$file1])
+AC_CONFIG_FILES([sub/this:$file1])
+AC_CONFIG_FILES([${file2}:this],, [file2=$file2])
+AC_CONFIG_FILES([$file3],, [file3=$file3])
+AC_CONFIG_FILES([$file4:foo.in],, [file4=$file4])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat >Makefile.am <<\EOF
+SUBDIRS = sub
+EXTRA_DIST = mumble.in
+DISTCLEANFILES = this.in that mumble foo
+dist-hook:
+ test -f $(distdir)/foo.in
+ test ! -f $(distdir)/this
+EOF
+
+echo @FOO@ >mumble.in
+echo @FOO@ >foo.in
+: >sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+$FGREP ' $file' Makefile.in sub/Makefile.in && exit 1
+
+./configure
+$MAKE distcheck
+cd sub
+rm -f this
+$MAKE this
+grep foo this
diff --git a/t/output12.sh b/t/output12.sh
new file mode 100644
index 000000000..27a30b1bc
--- /dev/null
+++ b/t/output12.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure an AC_CONFIG_FILES process filenames with AC_SUBST variables.
+
+. test-init.sh
+
+cat >> configure.ac << \END
+AC_SUBST([FOO], [foo])
+AC_SUBST([file1], [this.in])
+echo @FOO@ >$file1
+AC_SUBST([file2], [that])
+AC_SUBST([file3], [mumble])
+AC_SUBST([file4], [foo])
+AC_CONFIG_FILES([this:$file1],, [file1=$file1])
+AC_CONFIG_FILES([sub/this:$file1])
+AC_CONFIG_FILES([${file2}:this],, [file2=$file2])
+AC_CONFIG_FILES([${file3}],, [file3=$file3])
+AC_CONFIG_FILES([${file4}:foo.in],, [file4=$file4])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat >Makefile.am <<\EOF
+SUBDIRS = sub
+DISTCLEANFILES = $(file1)
+dist-hook:
+ test -f $(distdir)/foo.in
+ test ! -f $(distdir)/this
+EOF
+
+echo @FOO@ >mumble.in
+echo @FOO@ >foo.in
+: >sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE distcheck
+cd sub
+rm -f this
+$MAKE this
+grep foo this
diff --git a/t/output13.sh b/t/output13.sh
new file mode 100644
index 000000000..05a0013cb
--- /dev/null
+++ b/t/output13.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure an AC_CONFIG_FILES, AC_CONFIG_LINKS, and AC_CONFIG_COMMANDS
+# are not prerequisites of 'all'.
+
+. test-init.sh
+
+cat >> configure.ac << \END
+AC_SUBST([FOO], [foo])
+if $create; then
+ AC_CONFIG_FILES([file])
+ AC_CONFIG_LINKS([link:input])
+ AC_CONFIG_COMMANDS([stamp], [echo stamp > stamp])
+fi
+AC_OUTPUT
+END
+
+: >Makefile.am
+
+echo link > input
+echo @FOO@ >file.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure create=false
+$MAKE
+test ! -e file
+test ! -e link
+test ! -e stamp
+
+./configure create=:
+test -f file
+test -f link
+test -f stamp
diff --git a/t/output2.sh b/t/output2.sh
new file mode 100644
index 000000000..32264ef64
--- /dev/null
+++ b/t/output2.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another AC_OUTPUT test. From report by Ulrich Drepper.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT([Makefile intl/intlh.inst po/Makefile.in misc/gettextize])
+END
+
+: > Makefile.am
+
+mkdir intl po misc
+: > intl/intlh.inst.in
+: > po/Makefile.in.am
+: > misc/gettextize.in
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^gettextize' Makefile.in && exit 1
+exit 0
diff --git a/t/output3.sh b/t/output3.sh
new file mode 100644
index 000000000..7870eb390
--- /dev/null
+++ b/t/output3.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Yet another AC_OUTPUT test.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT([Makefile
+tests/Makefile tests/defs],
+[blah])
+END
+
+: > Makefile.am
+
+mkdir tests
+: > tests/Makefile.am
+: > tests/defs.in
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/output4.sh b/t/output4.sh
new file mode 100644
index 000000000..cc2ba319d
--- /dev/null
+++ b/t/output4.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# It's hard to believe there are so many AC_OUTPUT-related bugs.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_OUTPUT([tests/Makefile tests/defs])
+END
+
+mkdir tests
+: > tests/defs.in
+: > tests/Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+grep tests/defs.in tests/Makefile.in && exit 1
+exit 0
diff --git a/t/output5.sh b/t/output5.sh
new file mode 100644
index 000000000..dd9466f63
--- /dev/null
+++ b/t/output5.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake complains when there is no Makefile specified.
+
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([foo], [bar], [baz])
+AM_INIT_AUTOMAKE
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'AC_CONFIG_FILES(.Makefile.)' stderr
diff --git a/t/output6.sh b/t/output6.sh
new file mode 100644
index 000000000..fad71536e
--- /dev/null
+++ b/t/output6.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for support for colon-separated input files in AC_CONFIG_FILES.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([foo:a.in:b.in:c.in:d.in])
+AC_OUTPUT
+END
+
+cat >a.in <<'EOF'
+a = A
+b = A
+c = A
+d = A
+EOF
+
+cat >b.in <<'EOF'
+b = B
+c = B
+d = B
+EOF
+
+cat >c.am <<'EOF'
+c = C
+d = C
+
+.PHONY: test1 test2
+test1:
+ test $(a)$(b)$(c)$(d) = ABCD
+test2:
+ test $(a)$(b)$(c)$(d) = GFCD
+EOF
+
+echo 'd = D' > d.in
+
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE -f foo test1
+
+$sleep
+cat >b.in <<'EOF'
+a = G
+b = F
+c = F
+d = F
+EOF
+
+using_gmake || $MAKE -f foo
+$MAKE -f foo test2
+
+:
diff --git a/t/output7.sh b/t/output7.sh
new file mode 100644
index 000000000..9fb255e80
--- /dev/null
+++ b/t/output7.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for support for colon separated input files in AC_CONFIG_FILES,
+# with sources in sub directories.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([
+ Makefile:mk/toplevel.in
+ sub/Makefile:mk/sub.in
+ mk/Makefile
+])
+AC_OUTPUT
+END
+
+mkdir mk sub
+cat >mk/Makefile.am <<'EOF'
+all-local:
+ @echo in--mk
+EOF
+
+cat >mk/sub.am <<'EOF'
+EXTRA_DIST = foo
+all-local:
+ @echo in--sub
+EOF
+
+cat >mk/toplevel.am <<'EOF'
+all-local:
+ @echo at--toplevel
+SUBDIRS = mk sub
+EOF
+
+# We have to distribute something in foo, because some versions
+# of tar do not archive empty directories when passed the 'o'
+# flags. (This was fixed in GNU tar 1.12, but older
+# versions are still used: NetBSD 1.6.1 ships with tar 1.11.2).
+#
+# If sub/ is missing from the archive, config.status will fail
+# to compute $ac_abs_srcdir during a VPATH build: config.status
+# is able to create sub/ in the build tree, but it assumes the
+# directory already exists in the source tree.
+echo bar > sub/foo
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+run_make -O
+grep in--mk stdout
+grep in--sub stdout
+grep at--toplevel stdout
+
+$MAKE distcheck
diff --git a/t/output8.sh b/t/output8.sh
new file mode 100644
index 000000000..f8c9b4f9a
--- /dev/null
+++ b/t/output8.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check AC_CONFIG_FILES support for files starting with '../'.
+# Report from Bruno Haible.
+
+. test-init.sh
+
+mkdir testdir
+cd testdir
+
+mv ../configure.ac .
+cat >> configure.ac << END
+AC_CONFIG_FILES([a/foo.sh:../testdir/a/foo.sh.in])
+AC_CONFIG_FILES([a/Makefile])
+AC_OUTPUT
+END
+
+mkdir a
+
+echo SUBDIRS = a >Makefile.am
+: >a/Makefile.am
+
+echo foo >a/foo.sh.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+$MAKE
+test "$(cat a/foo.sh)" = foo
+
+$sleep
+echo 'bar' >a/foo.sh.in
+
+cd a
+$MAKE foo.sh
+test "$(cat foo.sh)" = bar
+
+:
diff --git a/t/output9.sh b/t/output9.sh
new file mode 100644
index 000000000..b0645f325
--- /dev/null
+++ b/t/output9.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure an AC_CONFIG_FILES can have an AC_CONFIG_FILES output as input.
+
+. test-init.sh
+
+cat >> configure.ac << END
+AC_CONFIG_FILES([a/mid.in:a/input.in.in])
+AC_CONFIG_FILES([b/out:a/mid.in])
+AC_CONFIG_FILES([a/Makefile b/Makefile])
+AC_OUTPUT
+END
+
+mkdir a
+mkdir b
+
+
+cat >Makefile.am <<\EOF
+SUBDIRS = a b
+dist-hook:
+ test -f $(distdir)/a/input.in.in
+ test ! -f $(distdir)/a/mid.in
+ if test ! -f check; then :; else : > ok; fi
+EOF
+
+: >a/Makefile.am
+: >b/Makefile.am
+
+echo foo >a/input.in.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+: > check
+$MAKE distcheck
+test -f ok
diff --git a/t/override-conditional-1.sh b/t/override-conditional-1.sh
new file mode 100644
index 000000000..54ed455ee
--- /dev/null
+++ b/t/override-conditional-1.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for conditionally-defined overrides.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND], [test x"$cond" = x"yes"])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+foobar:
+ : > $@
+if COND
+ps: foobar
+ :
+endif
+END
+
+$ACLOCAL
+$AUTOMAKE -Wno-override
+
+# "ps:" should be output in two conditions
+test $(grep -c '[^-]ps:' Makefile.in) -eq 2
+grep '@COND_TRUE@ps: *foobar' Makefile.in
+grep '@COND_FALSE@ps: *ps-am' Makefile.in
+
+$AUTOCONF
+
+./configure cond=no
+$MAKE ps
+test ! -e foobar
+
+./configure cond=yes
+$MAKE ps
+test -f foobar
+
+:
diff --git a/t/override-conditional-2.sh b/t/override-conditional-2.sh
new file mode 100644
index 000000000..acf0e19d4
--- /dev/null
+++ b/t/override-conditional-2.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that conditional overrides are diagnosed.
+# This test is still xfailing; see the FIXME in Automake::Rule::define.
+# Once that is fixed, the test should succeed.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND], [:])
+END
+
+cat > Makefile.am << 'END'
+if COND
+all:
+ :
+endif
+END
+
+$ACLOCAL
+
+AUTOMAKE_fails
+grep ':.*overrides.*all' stderr
+
+:
diff --git a/t/override-conditional-pr13940.sh b/t/override-conditional-pr13940.sh
new file mode 100644
index 000000000..8c860a9f1
--- /dev/null
+++ b/t/override-conditional-pr13940.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Expose automake bug#1394: automake erroneously think that a .PHONY
+# target's rule is overridden only because we declare dependencies
+# to such targets twice: one in an Automake conditional, and once
+# unconditionally.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([FOO], [true])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# The conditional here is important: Automake only appears to warn
+# when one of the all-local rules is inside a conditional and the
+# other is not.
+if FOO
+all-local: bar
+bar: ; @echo bar
+endif
+all-local: baz
+baz: ; @echo baz
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+:
diff --git a/t/override-html.sh b/t/override-html.sh
new file mode 100644
index 000000000..aed07c57f
--- /dev/null
+++ b/t/override-html.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that overriding 'html' target causes only one "html:" rule to
+# be output.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+html:
+ :
+END
+
+$ACLOCAL
+$AUTOMAKE -Wno-override
+
+# Overriding 'html' should cause only one "html:" rule to be output.
+test $(grep -c '^html:' Makefile.in) -eq 1
+
+:
diff --git a/t/override-suggest-local.sh b/t/override-suggest-local.sh
new file mode 100644
index 000000000..32d73a45b
--- /dev/null
+++ b/t/override-suggest-local.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure automake -Woverride suggests using TARGET-local instead
+# of TARGET when possible.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+install:
+ :
+installcheck:
+ :
+html:
+ :
+clean-am:
+ :
+END
+
+$ACLOCAL
+$AUTOMAKE -Wno-override
+AUTOMAKE_fails
+# There is no such thing as 'install-local'.
+grep ':.*install-local' stderr && exit 1
+grep ':.*installcheck-local' stderr
+grep ':.*html-local' stderr
+# Make sure overriding *-am targets suggest using *-local, not *-am.
+grep ':.*clean-am-local' stderr && exit 1
+grep ':.*clean-local' stderr
+
+:
diff --git a/t/parallel-am.sh b/t/parallel-am.sh
new file mode 100644
index 000000000..6e1371c38
--- /dev/null
+++ b/t/parallel-am.sh
@@ -0,0 +1,103 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test parallel automake execution.
+
+# There are several hypotheses to be tested: Independently of the number
+# of threads used by automake,
+# 0) the generated Makefile.in files must be identical without --add-missing,
+# 1) the Makefile.in that distributes auxiliary files must be generated
+# after all other ones, so all installed aux files are caught,
+# 2) normal automake output should have identical content and be ordered
+# in the same way, when --add-missing is not passed, or when
+# --add-missing is passed but there are no concurrent file requirements
+# (i.e., two Makefile.am files call for the same needed aux file)
+# 3) normal automake output should be identical and ordered in the same way
+# with --add-missing, even with concurrent file requirements, and the
+# installation of aux files should be race-free,
+# 4) warning and normal error output should be identical, in that duplicate
+# warnings should be omitted in the same way as without threads,
+# 5) fatal error and debug messages could be identical. This is not
+# intended, though.
+#
+# This test checks (0), (1), and (2). See sister tests for further coverage.
+
+required=perl-threads
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([parallel-am], [1.0])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AM_PATH_LISPDIR
+AM_PATH_PYTHON
+AC_CONFIG_FILES([Makefile])
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS =
+END
+
+list='1 2 3 4 5 6 7 8 9'
+for i in $list; do
+ echo "AC_CONFIG_FILES([sub$i/Makefile])" >> configure.ac
+ echo "SUBDIRS += sub$i" >> Makefile.am
+ mkdir sub$i
+ echo > sub$i/Makefile.am
+done
+# Use an include chain to cause a nontrivial location object to be
+# serialized through a thread queue.
+echo 'include foo.am' >> sub7/Makefile.am
+echo 'include bar.am' > sub7/foo.am
+echo 'python_PYTHON = foo.py' > sub7/bar.am
+echo 'lisp_LISP = foo.el' >> sub8/Makefile.am
+echo 'bin_PROGRAMS = p' >> sub9/Makefile.am
+
+rm -f install-sh missing depcomp
+mkdir build-aux
+
+$ACLOCAL
+
+# This test may have to be run several times in order to expose the
+# race that, when the last Makefile.in (the toplevel one) is created
+# before the other ones have finished, not all auxiliary files may
+# be installed yet, thus some may not be distributed.
+#
+# Further, automake output should be stable.
+
+# Generate expected output using the non-threaded code.
+unset AUTOMAKE_JOBS
+AUTOMAKE_run --add-missing
+mv stderr expected
+Makefile_ins=$(find . -name Makefile.in)
+for file in $Makefile_ins; do
+ mv $file $file.exp
+done
+
+AUTOMAKE_JOBS=5
+export AUTOMAKE_JOBS
+
+for run in 1 2 3 4 5 6 7; do
+ rm -f build-aux/* sub*/Makefile.in
+ AUTOMAKE_run --add-missing
+ diff stderr expected
+ for file in $Makefile_ins; do
+ diff $file $file.exp
+ done
+done
+
+:
diff --git a/t/parallel-am2.sh b/t/parallel-am2.sh
new file mode 100644
index 000000000..c85bbeef7
--- /dev/null
+++ b/t/parallel-am2.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test parallel automake execution.
+
+# This tests:
+# 4) warning and normal error output should be identical, in that duplicate
+# warnings should be omitted in the same way as without threads.
+
+required=perl-threads
+. test-init.sh
+
+mkdir sub
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = main
+main_SOURCES = sub/main.c
+SUBDIRS =
+END
+
+list='1 2 3'
+for i in $list; do
+ echo "AC_CONFIG_FILES([sub$i/Makefile])" >> configure.ac
+ echo "SUBDIRS += sub$i" >> Makefile.am
+ mkdir sub$i sub$i/sub
+ unindent > sub$i/Makefile.am << END
+ AUTOMAKE_OPTIONS = subdir-objects
+ bin_PROGRAMS = sub$i
+ sub${i}_SOURCES = sub/main$i.c
+END
+done
+
+mkdir build-aux
+
+$ACLOCAL
+
+# Independently of the number of worker threads, automake output
+# should be
+# - stable (multiple runs should produce the same output),
+# - properly uniquified,
+# - complete (output from worker threads should not be lost).
+#
+# The parts output by --add-missing are unstable not only wrt. order
+# but also wrt. content: any of the Makefile.am files may cause the
+# depcomp script to be installed (or several of them).
+# Thus we install the auxiliary files in a prior step.
+
+# Generate expected output using non-threaded code.
+unset AUTOMAKE_JOBS
+rm -f install-sh missing depcomp
+AUTOMAKE_fails --add-missing
+mv stderr expected
+
+AUTOMAKE_JOBS=5
+export AUTOMAKE_JOBS
+
+for i in 1 2 3 4 5 6 7 8; do
+ rm -f install-sh missing depcomp
+ AUTOMAKE_fails --add-missing
+ diff expected stderr
+done
+
+:
diff --git a/t/parallel-am3.sh b/t/parallel-am3.sh
new file mode 100644
index 000000000..9d5ea02ba
--- /dev/null
+++ b/t/parallel-am3.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test parallel automake execution.
+
+# This tests:
+# 3) normal automake output should be identical and ordered in the same way
+# with --add-missing, even with concurrent file requirements, and the
+# installation of aux files should be race-free.
+
+required=perl-threads
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([parallel-am], [1.0])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AM_PATH_LISPDIR
+AM_PATH_PYTHON
+AC_CONFIG_FILES([Makefile])
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS =
+END
+
+list='1 2 3'
+for i in $list; do
+ echo "AC_CONFIG_FILES([sub$i/Makefile])" >> configure.ac
+ echo "SUBDIRS += sub$i" >> Makefile.am
+ mkdir sub$i
+ unindent > sub$i/Makefile.am <<END
+ python_PYTHON = foo$i.py
+ lisp_LISP = foo$i.el
+ bin_PROGRAMS = p$i
+END
+done
+
+rm -f install-sh missing depcomp
+mkdir build-aux
+
+$ACLOCAL
+
+# Generate expected output using the non-threaded code.
+unset AUTOMAKE_JOBS
+AUTOMAKE_run --add-missing
+mv stderr expected
+mv Makefile.in Makefile.in.exp
+
+AUTOMAKE_JOBS=3
+export AUTOMAKE_JOBS
+
+for run in 1 2 3 4 5 6 7; do
+ rm -f build-aux/* sub*/Makefile.in
+ AUTOMAKE_run --add-missing
+ diff stderr expected
+ diff Makefile.in Makefile.in.exp
+done
+
+:
diff --git a/t/parallel-tests-basics.sh b/t/parallel-tests-basics.sh
new file mode 100644
index 000000000..e1dc8cb82
--- /dev/null
+++ b/t/parallel-tests-basics.sh
@@ -0,0 +1,144 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic checks on parallel-tests support:
+# - console output
+# - log files, and what goes in 'test-suite.log'
+# - make clean
+# - dependencies between tests
+# - TESTS redefinition at runtime
+# - TEST_LOGS redefinition at runtime
+# - RECHECK_LOGS redefinition at runtime
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test bar.test baz.test
+XFAIL_TESTS = bar.test
+foo.log: bar.log
+bar.log: baz.log
+END
+
+# foo.test and bar.test sleep to ensure their logs are always strictly newer
+# than the logs of their prerequisites, for HP-UX make. The quoting pleases
+# maintainer-check.
+cat > foo.test <<'END'
+#! /bin/sh
+echo "this is $0"
+sleep '1'
+exit 0
+END
+cat > bar.test <<'END'
+#! /bin/sh
+echo "this is $0"
+sleep '1'
+exit 99
+END
+cat > baz.test <<'END'
+#! /bin/sh
+echo "this is $0"
+exit 1
+END
+chmod a+x foo.test bar.test baz.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+run_make -O -e FAIL check
+count_test_results total=3 pass=1 fail=1 skip=0 xfail=0 xpass=0 error=1
+test -f test-suite.log
+cat test-suite.log
+test $(grep -c '^FAIL:' test-suite.log) -eq 1
+test $(grep -c '^ERROR:' test-suite.log) -eq 1
+$EGREP '^(X?PASS|XFAIL|SKIP)' test-suite.log && exit 1
+test -f baz.log
+test -f bar.log
+test -f foo.log
+
+$MAKE clean
+test ! -e baz.log
+test ! -e bar.log
+test ! -e foo.log
+test ! -e test-suite.log
+
+# Check dependencies: baz.test needs to run before bar.test,
+# but foo.test is not needed.
+# Note that this usage has a problem: the summary will only
+# take bar.log into account, because the $(TEST_SUITE_LOG) rule
+# does not "see" baz.log. Hmm.
+run_make -O -e FAIL TESTS='bar.test' check
+grep '^FAIL: baz\.test$' stdout
+grep '^ERROR: bar\.test$' stdout
+
+test -f baz.log
+test -f bar.log
+test ! -e foo.log
+test -f test-suite.log
+
+# Upon a lazy rerun, foo.test should be run, but the others shouldn't.
+# Note that the lazy rerun still exits with a failure, due to the previous
+# test failures.
+# Note that the previous test and this one taken together expose the timing
+# issue that requires the check-TESTS rule to always remove TEST_SUITE_LOG
+# before running the tests lazily.
+run_make -O -e FAIL check RECHECK_LOGS=
+test -f foo.log
+grep '^PASS: foo\.test$' stdout
+grep bar.test stdout && exit 1
+grep baz.test stdout && exit 1
+grep '^# PASS: *1$' stdout
+grep '^# FAIL: *1$' stdout
+grep '^# ERROR: *1$' stdout
+
+# Now, explicitly retry with all test logs already updated, and ensure
+# that the summary is still displayed.
+run_make -O -e FAIL check RECHECK_LOGS=
+grep foo.test stdout && exit 1
+grep bar.test stdout && exit 1
+grep baz.test stdout && exit 1
+grep '^# PASS: *1$' stdout
+grep '^# FAIL: *1$' stdout
+grep '^# ERROR: *1$' stdout
+
+# Lazily rerunning only foo should only rerun this one test.
+run_make -O -e FAIL check RECHECK_LOGS=foo.log
+grep foo.test stdout
+grep bar.test stdout && exit 1
+grep baz.test stdout && exit 1
+grep '^# PASS: *1$' stdout
+grep '^# FAIL: *1$' stdout
+grep '^# ERROR: *1$' stdout
+
+$MAKE clean
+run_make -O -e FAIL TEST_LOGS=baz.log check
+grep foo.test stdout && exit 1
+grep bar.test stdout && exit 1
+grep baz.test stdout
+
+$MAKE clean
+run_make -O -e FAIL TESTS=baz.test check
+grep foo.test stdout && exit 1
+grep bar.test stdout && exit 1
+grep baz.test stdout
+
+:
diff --git a/t/parallel-tests-cmdline-override.sh b/t/parallel-tests-cmdline-override.sh
new file mode 100644
index 000000000..1efacbe06
--- /dev/null
+++ b/t/parallel-tests-cmdline-override.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that we can use indirections when overriding TESTS and
+# TEST_LOGS from the command line.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_EXTENSIONS = .test .t
+TEST_LOG_COMPILER = cat
+T_LOG_COMPILER = cat
+TESTS = bad.test
+var1 = b.test $(var2)
+var2 = c.test
+var3 = d.d
+var4 = e
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+rm -f config.log # Do not create false positives below.
+
+cat > exp-log <<'END'
+a.log
+b.log
+c.log
+d.log
+e.log
+test-suite.log
+END
+
+cat > exp-out <<'END'
+PASS: a.t
+PASS: b.test
+PASS: c.test
+PASS: d.t
+PASS: e.test
+END
+
+do_check ()
+{
+ run_make -O -- "$@" check
+ grep '^PASS:' stdout | LC_ALL=C sort > got-out
+ cat got-out
+ ls . | grep '\.log$' | LC_ALL=C sort > got-log
+ cat got-log
+ st=0
+ diff exp-out got-out || st=1
+ diff exp-log got-log || st=1
+ return $st
+}
+
+tests='a.t $(var1) $(var3:.d=.t) $(var4:=.test)'
+test_logs='a.log $(var1:.test=.log) $(var3:.d=.log) $(var4:=.log)'
+
+touch a.t b.test c.test d.t e.test
+
+do_check TESTS="$tests"
+do_check TEST_LOGS="$test_logs"
+
+:
diff --git a/t/parallel-tests-concurrency-2.sh b/t/parallel-tests-concurrency-2.sh
new file mode 100644
index 000000000..3c61a1a7d
--- /dev/null
+++ b/t/parallel-tests-concurrency-2.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - concurrent program compilation and testing (with EXTRA_PROGRAMS)
+#
+# Actually, this test doesn't ensure that things happen concurrently.
+# It merely serves as demonstration. :-)
+
+required='cc native GNUmake'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = $(programs) $(scripts)
+EXTRA_PROGRAMS = $(programs)
+CLEANFILES = $(EXTRA_PROGRAMS)
+dist_noinst_SCRIPTS = $(scripts)
+programs =
+scripts =
+END
+
+for i in 1 2 3 4 5 6 7 8; do
+ echo "scripts += foo$i.test" >> Makefile.am
+ echo "programs += foo$i.prog" >> Makefile.am
+ unindent >foo$i.test <<'END'
+ #! /bin/sh
+ echo "this is $0"
+ exit 0
+END
+ cat >foo$i.c <<'END'
+ int main (void)
+ {
+ return 0;
+ }
+END
+ chmod a+x foo$i.test
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE -j4 check
+$MAKE distcheck
+
+:
diff --git a/t/parallel-tests-concurrency.sh b/t/parallel-tests-concurrency.sh
new file mode 100644
index 000000000..69d6198b3
--- /dev/null
+++ b/t/parallel-tests-concurrency.sh
@@ -0,0 +1,120 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - concurrent parallel execution
+
+# FIXME: we should factor out (into am-test-lib.sh?) the code to determine
+# how to run make in parallel mode ...
+
+. test-init.sh
+
+case $MAKE in
+ *\ -j*) skip_ "\$MAKE contains '-j'";;
+esac
+
+if using_gmake; then
+ j=-j
+else
+ unindent > Makefile <<END
+ all: one two
+ one:
+ $sleep && test -f two
+ two:
+ echo ok > \$@
+END
+ for j in "-j" "-j " NONE; do
+ if test x"$j" = xNONE; then
+ skip_ "can't run make in parallel mode"
+ fi
+ run_make -M -- ${j}2 all || continue
+ $EGREP -i "(warning|error):|-j[\"\'\` ]" output && continue
+ break
+ done
+ rm -f one output Makefile
+fi
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS =
+END
+
+cat > x <<'END'
+#! /bin/sh
+echo "this is $0"
+# Creative quoting below to please maintainer-check.
+sleep '1'
+exit 0
+END
+chmod a+x ./x
+
+mkdir sub
+for i in 1 2 3; do
+ echo "TESTS += foo$i.test" >> Makefile.am
+ cp x foo$i.test
+ echo "TESTS += zap$i" >> Makefile.am
+ cp x zap$i
+ echo "TESTS += sub/bar$i.test" >> Makefile.am
+ cp x sub/bar$i.test
+ echo "TESTS += sub/mu$i" >> Makefile.am
+ cp x sub/mu$i
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+for build in serial parallel; do
+ mkdir $build
+ cd $build
+ ../configure
+ $MAKE
+ cd ..
+done
+
+cd serial
+# Do *not* use "make -j1" here; apparently, some make implementations
+# (e.g., AIX 7.1) interpret it as a synonym of "make -j" :-(
+$MAKE check &
+cd ..
+
+cd parallel
+$sleep
+run_make -O -- ${j}4 check
+cd ..
+
+# Ensure the tests are really being run in parallel mode: if this is
+# the case, the serial run of the dummy testsuite started above should
+# still be ongoing when the parallel one has terminated.
+kill -0 $!
+cat parallel/stdout
+test $(grep -c '^PASS:' parallel/stdout) -eq 12
+
+# Wait long enough so that there are no open files any more when the
+# post-test cleanup runs. But exit after we've waited for two minutes
+# or more, to avoid testsuite hangs in unusual situations (this has
+# already happened).
+i=1
+while test ! -f serial/test-suite.log && test $i -le 120; do
+ i=$(($i + 1))
+ sleep '1' # Extra quoting to please maintainer-check.
+done
+$sleep
+
+:
diff --git a/t/parallel-tests-console-output.sh b/t/parallel-tests-console-output.sh
new file mode 100644
index 000000000..e0fe331b5
--- /dev/null
+++ b/t/parallel-tests-console-output.sh
@@ -0,0 +1,102 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests: some checks on console output about testsuite
+# progress.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+XFAIL_TESTS = sub/xpass.test xfail.test error.test
+TESTS = $(XFAIL_TESTS) fail.test pass.test a/b/skip.test sub/error2.test
+pass.log: fail.log
+error.log: pass.log
+sub/xpass.log: error.log
+sub/error2.log: xfail.log
+a/b/skip.log: sub/error2.log
+END
+
+cat > exp <<'END'
+FAIL: fail.test
+PASS: pass.test
+ERROR: error.test
+XPASS: sub/xpass.test
+XFAIL: xfail.test
+ERROR: sub/error2.test
+SKIP: a/b/skip.test
+END
+
+mkdir sub a a/b
+
+cat > pass.test << 'END'
+#!/bin/sh
+exit 0
+END
+cp pass.test sub/xpass.test
+
+cat > fail.test << 'END'
+#!/bin/sh
+exit 1
+END
+
+cat > xfail.test << 'END'
+#!/bin/sh
+# The sleep should ensure expected execution order of tests
+# even when make is run in parallel mode.
+# Creative quoting below to plase maintainer-check.
+sleep '10'
+exit 1
+END
+
+cat > error.test << 'END'
+#!/bin/sh
+exit 99
+END
+cp error.test sub/error2.test
+
+cat > a/b/skip.test << 'END'
+#!/bin/sh
+exit 77
+END
+
+chmod a+x pass.test fail.test xfail.test sub/xpass.test \
+ a/b/skip.test error.test sub/error2.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+for vpath in : false; do
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+ $srcdir/configure
+ run_make -O -e FAIL check
+ LC_ALL=C grep '^[A-Z][A-Z]*:' stdout > got
+ cat got
+ diff $srcdir/exp got
+ cd $srcdir
+done
+
+:
diff --git a/t/parallel-tests-driver-install.sh b/t/parallel-tests-driver-install.sh
new file mode 100644
index 000000000..3bb27f0b4
--- /dev/null
+++ b/t/parallel-tests-driver-install.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that auxiliary script 'test-driver' gets automatically installed
+# in the correct directory.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([my_aux_dir])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub my_aux_dir
+
+cat > Makefile.am <<END
+SUBDIRS = sub
+TESTS = foo.test
+END
+
+cat > sub/Makefile.am <<END
+TESTS = bar.test
+END
+
+$ACLOCAL
+$AUTOMAKE -a 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+
+ls -l . sub my_aux_dir # For debugging.
+test -f my_aux_dir/test-driver
+test ! -e test-driver
+test ! -e sub/test-driver
+
+grep '^parallel-tests:.*installing.*my_aux_dir/test-driver' stderr
+
+:
diff --git a/t/parallel-tests-dry-run-1.sh b/t/parallel-tests-dry-run-1.sh
new file mode 100644
index 000000000..61e3d225b
--- /dev/null
+++ b/t/parallel-tests-dry-run-1.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check interactions between the parallel test harness and "make -n".
+# See also sister test 'parallel-tests-dry-run-2.sh'.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+TESTS = foo.test bar.test
+$(TESTS):
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+# Avoid confusion with test logs.
+rm -f config.log
+
+log_files='test-suite.log foo.log bar.log'
+
+all_exist ()
+{
+ st=0
+ for i in $*; do
+ test -f $i || { echo File $i not found; st=1; }
+ done
+ test $st -eq 0
+}
+
+none_exist ()
+{
+ st=0
+ for i in $*; do
+ if test -r $i || test -f $i; then
+ echo File $i found
+ st=1
+ fi
+ done
+ test $st -eq 0
+}
+
+for targ in check recheck $log_files; do
+ $MAKE -n "$targ"
+ none_exist $log_files
+done
+
+touch $log_files
+
+$MAKE -n mostlyclean
+all_exist $log_files
+$MAKE -n clean
+all_exist $log_files
+
+cat > foo.test <<'END'
+#! /bin/sh
+exit 0
+END
+
+cat > bar.test <<'END'
+#! /bin/sh
+exit 1
+END
+
+chmod a+x foo.test bar.test
+
+$MAKE check && exit 1
+
+for targ in recheck clean mostlyclean distclean; do
+ $MAKE -n "$targ"
+ all_exist $log_files
+done
+
+:
diff --git a/t/parallel-tests-dry-run-2.sh b/t/parallel-tests-dry-run-2.sh
new file mode 100644
index 000000000..cbe38647c
--- /dev/null
+++ b/t/parallel-tests-dry-run-2.sh
@@ -0,0 +1,110 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check interactions between the parallel test harness and "make -n".
+# See also sister test 'parallel-tests-dry-run-1.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+TESTS = foo.test bar.test
+TEST_LOG_COMPILER = $(SHELL)
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+./configure
+
+make_n_ ()
+{
+ st=0
+ run_make -M -- -n "$@" || { ls -l; exit 1; }
+ # Look out for possible errors from common tools used by recipes.
+ $EGREP -i ' (exist|permission|denied|no .*(such|file))' output && exit 1
+ $EGREP '(mv|cp|rm|cat|grep|sed|awk): ' output && exit 1
+ :
+}
+
+: > output
+
+files='foo.log bar.log foo.trs bar.trs'
+
+echo 'exit 0' > foo.test
+echo 'exit 1' > bar.test
+
+for target in check recheck test-suite.log; do
+ make_n_ $target
+ test ! -e foo.log
+ test ! -e foo.trs
+ test ! -e bar.log
+ test ! -e bar.trs
+ test ! -e test-suite.log
+done
+
+$MAKE check && exit 1
+
+chmod a-w .
+
+make_n_ clean
+test -f foo.log
+test -f foo.trs
+test -f foo.log
+test -f bar.trs
+
+cat > foo.test <<END
+echo this is bad
+exit 1
+END
+echo 'exit 0' > bar.test
+
+for target in check recheck test-suite.log; do
+ make_n_ $target
+ grep '^:test-result: *FAIL' bar.trs
+ grep 'this is bad' foo.log test-suite.log && exit 1
+ : For shells with busted 'set -e'.
+done
+
+chmod a-rw $files
+if test -r foo.log; then
+ : You can still read unreadable files! Skip these checks.
+else
+ for target in check recheck test-suite.log; do
+ make_n_ $target
+ for f in $files; do
+ test -f $f && test ! -r $f || exit 1
+ done
+ done
+fi
+chmod u+r $files
+
+chmod u+w .
+rm -f foo.log bar.trs
+chmod a-w .
+for target in check recheck test-suite.log $files; do
+ make_n_ $target
+ test ! -e foo.log
+ test -f foo.trs
+ test ! -e bar.trs
+ test -f bar.log
+done
+
+:
diff --git a/t/parallel-tests-empty-testlogs.sh b/t/parallel-tests-empty-testlogs.sh
new file mode 100644
index 000000000..55f89e60f
--- /dev/null
+++ b/t/parallel-tests-empty-testlogs.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - empty TESTS
+# - empty TEST_LOGS
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub1 sub2
+END
+
+mkdir sub1 sub2
+
+cat > sub1/Makefile.am << 'END'
+TESTS =
+END
+
+# When $(TESTS) is empty, NetBSD 5.1 make ends up defining $(TESTS_LOGS)
+# to ".log" rather than to the empty string (as would be expected).
+# But our recipes are smart enough to work around such a botched-up
+# substitution, so let's not bother too much about it.
+if using_gmake; then
+ unindent >> sub1/Makefile.am << 'END'
+ check-local:
+ echo $(TEST_LOGS) | grep . && exit 1; exit 0
+END
+fi
+
+cat > sub2/Makefile.am << 'END'
+TESTS = foo.test
+END
+
+cat > sub2/foo.test <<'END'
+#! /bin/sh
+exit 0
+END
+chmod a+x sub2/foo.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+no_test_has_run ()
+{
+ ls -1 *.log | grep -v '^test-suite\.log$' | grep . && exit 1
+ grep '^# TOTAL: *0$' test-suite.log
+ :
+}
+
+for vpath in : false; do
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+ $srcdir/configure
+ cd sub1
+ VERBOSE=yes $MAKE check
+ no_test_has_run
+ cd ../sub2
+ run_make VERBOSE=yes TESTS= check
+ no_test_has_run
+ run_make VERBOSE=yes TEST_LOGS= check
+ no_test_has_run
+ cd ..
+ $MAKE check
+ cat sub2/foo.log
+ $MAKE distclean
+ cd $srcdir
+done
+
+:
diff --git a/t/parallel-tests-empty.sh b/t/parallel-tests-empty.sh
new file mode 100644
index 000000000..828cda7d0
--- /dev/null
+++ b/t/parallel-tests-empty.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - empty TESTS
+# BSD make will expand '$(TESTS:=.log)' to '.log' unless overridden.
+# See 'parallel-tests-trailing-whitespace.sh' for a similar issue.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS =
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+run_make -O check
+for x in TOTAL PASS FAIL XPASS FAIL SKIP ERROR; do
+ grep "^# $x: *0$" stdout
+done
+
+:
diff --git a/t/parallel-tests-exeext.sh b/t/parallel-tests-exeext.sh
new file mode 100644
index 000000000..d7773e53b
--- /dev/null
+++ b/t/parallel-tests-exeext.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests:
+# - check2.am and interaction with $(EXEEXT)
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+dnl We need to fool the init.m4 internals a little.
+AC_DEFUN([_AM_FOO],
+ [m4_provide([_AM_COMPILER_EXEEXT])
+ AC_SUBST([CC], [false])
+ AC_SUBST([EXEEXT])])
+_AM_FOO
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = x y a.test b.test
+LOG_COMPILER = true
+TEST_LOG_COMPILER = true
+## We also need to fool the automake internals a little.
+EXTRA_PROGRAMS = y
+y_SOURCES =
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+$EGREP 'EXEEXT|\.log|\.test' Makefile.in # For debugging.
+
+./configure EXEEXT=
+touch x y a.test b.test
+$MAKE check
+
+$MAKE distclean
+rm -f x y a.test b.test *.log *.trs
+
+./configure EXEEXT=.bin
+touch x y.bin a.test b.test.bin
+$MAKE check
+ls -l # For debugging.
+test -f y.log
+test ! -e y.bin.log
+test -f b.log
+test ! -e b.test.log
+
+$EGREP '^y\.log: y(\$\(EXEEXT\)|\.bin)' Makefile
+$EGREP '^\.test(\$\(EXEEXT\)|\.bin)\.log:' Makefile
+
+:
diff --git a/t/parallel-tests-exit-status-reported.sh b/t/parallel-tests-exit-status-reported.sh
new file mode 100644
index 000000000..2b8420773
--- /dev/null
+++ b/t/parallel-tests-exit-status-reported.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The exit status of a test should be reported in the test logs, so
+# that one can see at a glance whether the test has succeeded or failed,
+# without having to look also into the corresponding .trs file.
+# See automake bug#11814.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+echo XFAIL_TESTS = t3.test t00.test > Makefile.am
+echo TESTS = t00.test >> Makefile.am
+for s in 0 1 2 3 5 77 78 99 100 126 127; do
+ echo "TESTS += t${s}.test" >> Makefile.am
+ cat > t${s}.test <<END
+#!/bin/sh
+printf "%s\\n%s\\n" 'random' 'will exit with status $s'
+exit $s
+END
+done
+cp t0.test t00.test
+
+chmod a+x *.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+run_make -e FAIL check
+ls -l # For debugging.
+
+match_result ()
+{
+ cat "$1.log" # For debugging.
+ test $(wc -l <"$1.log") -eq 3
+ sed -n '$p' "$1.log" | grep "^$2 $1\\.test (exit status: $3)$"
+}
+
+match_result t0 PASS 0
+match_result t00 XPASS 0
+match_result t1 FAIL 1
+match_result t2 FAIL 2
+match_result t3 XFAIL 3
+match_result t5 FAIL 5
+match_result t77 SKIP 77
+match_result t78 FAIL 78
+match_result t99 ERROR 99
+match_result t100 FAIL 100
+match_result t126 FAIL 126
+match_result t127 FAIL 127
+
+:
diff --git a/t/parallel-tests-exit-statuses.sh b/t/parallel-tests-exit-statuses.sh
new file mode 100644
index 000000000..d8419629e
--- /dev/null
+++ b/t/parallel-tests-exit-statuses.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features: normal and special exit statuses
+# in the test scripts.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+# $failure_statuses should be defined to the list of all integers between
+# 1 and 255 (inclusive), excluded 77 and 99.
+failure_statuses=$(seq_ 1 255 | $EGREP -v '^(77|99)$' | tr "$nl" ' ')
+# For debugging.
+echo "failure_statuses: $failure_statuses"
+# Sanity check.
+test $(for st in $failure_statuses; do echo $st; done | wc -l) -eq 253 \
+ || fatal_ "initializing list of exit statuses for simple failures"
+
+cat > Makefile.am <<END
+LOG_COMPILER = $AM_TEST_RUNNER_SHELL ./do-exit
+fail_tests = $failure_statuses
+TESTS = 0 77 99 $failure_statuses
+\$(TESTS):
+END
+
+cat > do-exit <<'END'
+#!/bin/sh
+echo "$0: $1"
+case $1 in
+ [0-9]|[0-9][0-9]|[0-9][0-9][0-9]) st=$1;;
+ */[0-9]|*/[0-9][0-9]|*/[0-9][0-9][0-9]) st=${1##*/};;
+ *) st=99;;
+esac
+exit $st
+END
+chmod a+x do-exit
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+{
+ echo PASS: 0
+ echo SKIP: 77
+ echo ERROR: 99
+ for st in $failure_statuses; do
+ echo "FAIL: $st"
+ done
+} | LC_ALL=C sort > exp-0
+
+sed 's/^FAIL:/XFAIL:/' exp-0 | LC_ALL=C sort > exp-1
+sed '/^ERROR:/d' exp-1 > exp-2
+
+./configure
+
+mk_ ()
+{
+ n=$1; shift
+ unset am_make_rc
+ run_make -e IGNORE -O -- ${1+"$@"} check
+ cat test-suite.log
+ LC_ALL=C grep '^[A-Z][A-Z]*:' stdout | LC_ALL=C sort > got-$n
+ cat exp-$n
+ cat got-$n
+ diff exp-$n got-$n
+}
+
+mk_ 0
+test $am_make_rc -gt 0
+mk_ 1 XFAIL_TESTS="$failure_statuses 99"
+test $am_make_rc -gt 0
+mk_ 2 XFAIL_TESTS="$failure_statuses" TESTS="0 77 $failure_statuses"
+test $am_make_rc -eq 0
+
+:
diff --git a/t/parallel-tests-extra-programs.sh b/t/parallel-tests-extra-programs.sh
new file mode 100644
index 000000000..6d33cb3cb
--- /dev/null
+++ b/t/parallel-tests-extra-programs.sh
@@ -0,0 +1,176 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Parallel test harness: check that $(TESTS) can lazily depend on
+# (or even be) $(EXTRA_PROGRAMS).
+
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+# Will be extended later.
+cat > Makefile.am << 'END'
+TEST_EXTENSIONS = .bin .test
+EXTRA_PROGRAMS =
+TESTS =
+END
+
+#
+# Now try various kinds of test dependencies ...
+#
+
+# 1. A program that is also a test, and whose source files
+# already exist.
+
+cat >> Makefile.am <<'END'
+EXTRA_PROGRAMS += foo.bin
+TESTS += foo.bin
+foo_bin_SOURCES = foo.c
+END
+
+cat > foo.c <<'END'
+#include <stdio.h>
+int main (void)
+{
+ printf ("foofoofoo\n");
+ return 0;
+}
+END
+
+# 2. A program that is also a test, and whose source files
+# are buildable by make.
+cat >> Makefile.am <<'END'
+EXTRA_PROGRAMS += bar.bin
+TESTS += bar.bin
+bar_bin_SOURCES = bar.c
+bar.c: foo.c
+ sed -e 's/foofoofoo/barbarbar/' foo.c > $@
+END
+
+# 3. A test script that already exists, whose execution depends
+# on a program whose source files already exist and which is
+# not itself a test.
+cat >> Makefile.am <<'END'
+EXTRA_PROGRAMS += y
+TESTS += baz.test
+baz.log: y$(EXEEXT)
+END
+
+cat > baz.test <<'END'
+#!/bin/sh
+$srcdir/y "$@" | sed 's/.*/&ep&ep&ep/'
+END
+chmod a+x baz.test
+
+cat > y.c <<'END'
+#include <stdio.h>
+int main (void)
+{
+ printf ("y\n");
+ return 0;
+}
+END
+
+# 4. A program that is also a test, but whose source files
+# do not exit and are not buildable by make.
+
+cat >> Makefile.am <<'END'
+EXTRA_PROGRAMS += none.bin
+TESTS += none.bin
+none_bin_SOURCES = none.c
+END
+
+#
+# Setup done, go with the tests.
+#
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+# What we check now:
+# 1. even if we cannot build the 'none.bin' program, all the other
+# test programs should be built, and all the other tests should
+# be run;
+# 2. still, since we cannot create the 'none.log' file, the
+# 'test-suite.log' file shouldn't be created (as it depends
+# on *all* the test logs).
+
+run_make -E -O -e IGNORE -- -k check
+ls -l
+if using_gmake; then
+ test $am_make_rc -gt 0 || exit 1
+else
+ # Don't trust exit status of "make -k" for non-GNU make.
+ $MAKE check && exit 1
+ : For shells with busted 'set -e'.
+fi
+
+# Files that should have been created, with the expected content.
+cat bar.c
+grep foofoofoo foo.log
+grep barbarbar bar.log
+grep yepyepyep baz.log
+# Files that shouldn't have been created.
+test ! -e none.log
+test ! -e test-suite.log
+# Expected testsuite progress output.
+grep '^PASS: baz\.test$' stdout
+# Don't anchor the end of the next two patterns, to allow for non-empty
+# $(EXEEXT).
+grep '^PASS: foo\.bin' stdout
+grep '^PASS: bar\.bin' stdout
+# Expected error messages from make. Some make implementations (e.g.,
+# FreeBSD make) seem to print the error on stdout instead, so check for
+# it there as well.
+$EGREP 'none\.(bin|o|c)' stderr stdout
+
+# What we check now:
+# 1. if we make the last EXTRA_PROGRAM buildable, the failed tests
+# pass;
+# 2. on a lazy re-run, the passed tests are not re-run, and
+# 3. their log files are not updated or touched.
+
+: > stamp
+$sleep
+
+echo 'int main (void) { return 0; }' > none.c
+
+run_make -O -e IGNORE check RECHECK_LOGS=
+ls -l # For debugging.
+test $am_make_rc -eq 0 || exit 1
+
+# For debugging.
+stat stamp foo.log bar.log baz.log || :
+
+# Files that shouldn't have been updated or otherwise touched.
+is_newest stamp foo.log bar.log baz.log
+# Files that should have been created now.
+test -f none.log
+test -f test-suite.log
+# Tests that shouldn't have been re-run.
+$EGREP '(foo|bar)\.bin|baz\.test$' stdout && exit 1
+# Tests that should have been run. Again, we don't anchor the end
+# of the next pattern, to allow for non-empty $(EXEEXT).
+grep '^PASS: none\.bin' stdout
+
+:
diff --git a/t/parallel-tests-fd-redirect-exeext.sh b/t/parallel-tests-fd-redirect-exeext.sh
new file mode 100644
index 000000000..217069140
--- /dev/null
+++ b/t/parallel-tests-fd-redirect-exeext.sh
@@ -0,0 +1,115 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests support: redirection of file descriptors with
+# AM_TESTS_FD_REDIRECT, for tests which are binary executables
+# We use some tricks to ensure that all code paths in 'lib/am/check2.am'
+# are covered, even on platforms where $(EXEEXT) would be naturally empty.
+# See also the more generic test 'check-fd-redirect.sh', and
+# sister test 'parallel-tests-fd-redirect.sh'.
+
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+# Calls like "write(9, ...)" are unlikely to work for MinGW-compiled
+# programs. We must skip this test if this is the case.
+am__ok=no
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[#include <unistd.h>]],
+ [[write (9, "foobar\n", 7); return 0;]])],
+ [AM_RUN_LOG([./conftest$EXEEXT 9>&1]) \
+dnl Leading ":;" required to avoid having two nested subshells starting
+dnl with '((' in the generated configure: that is unportable and could
+dnl confuse some shells (e.g., NetBSD 5.1 /bin/ksh) into thinking we are
+dnl trying to perform an arithmetic operation.
+ && AM_RUN_LOG([:; (./conftest$EXEEXT 9>&1) | grep "^foobar"]) \
+ && am__ok=yes])
+test $am__ok = yes || AS_EXIT([63])
+AM_CONDITIONAL([real_EXEEXT], [test -n "$EXEEXT"])
+test -n "$EXEEXT" || EXEEXT=.bin
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_TESTS_FD_REDIRECT = 9>&1
+TESTS = $(check_PROGRAMS)
+check_PROGRAMS = baz qux.test
+qux_test_SOURCES = zardoz.c
+
+## Sanity check.
+if !real_EXEEXT
+check-local:
+ test -f baz.bin
+ test -f qux.test.bin
+endif
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cat > baz.c <<'END'
+#include <stdio.h>
+#include <unistd.h>
+int main (void)
+{
+ ssize_t res = write (9, " bazbazbaz\n", 11);
+ if (res < 0)
+ perror("write failed");
+ return res != 11;
+}
+END
+
+cat > zardoz.c <<'END'
+#include <stdio.h>
+#include <unistd.h>
+int main (void)
+{
+ ssize_t res = write (9, " quxquxqux\n", 11);
+ if (res < 0)
+ perror("write failed");
+ return res != 11;
+}
+END
+
+st=0; ./configure || st=$?
+cat config.log # For debugging, as we do tricky checks in configure.
+if test $st -eq 63; then
+ skip_ "fd redirect in compiled program unsupported"
+elif test $st -eq 0; then
+ : Continue.
+else
+ fatal_ "unexpected error in ./configure"
+fi
+
+# Sanity checks.
+st=0
+grep '^baz\.log:.*baz\$(EXEEXT)' Makefile || st=1
+grep '^\.test\$(EXEEXT)\.log:' Makefile || st=1
+grep '^qux\.log:' Makefile && st=1
+test $st -eq 0 || fatal_ "doesn't cover expected code paths"
+
+run_make -O -e IGNORE check
+cat baz.log
+cat qux.log
+test $am_make_rc -eq 0
+grep "^ bazbazbaz$" stdout
+grep "^ quxquxqux$" stdout
+$EGREP '(bazbazbaz|quxquxqux)' *.log && exit 1
+
+:
diff --git a/t/parallel-tests-fd-redirect.sh b/t/parallel-tests-fd-redirect.sh
new file mode 100644
index 000000000..386b7aada
--- /dev/null
+++ b/t/parallel-tests-fd-redirect.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests support: redirection of file descriptors with
+# AM_TESTS_FD_REDIRECT, even when using tests without suffix.
+# The sister 'parallel-tests-fd-redirect-exeext.sh' do a similar
+# check for tests that are binary executables.
+# See also the more generic test 'check-fd-redirect.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_TESTS_FD_REDIRECT = 9>&1
+TEST_EXTENSIONS = .test .sh
+TESTS = foo.sh bar
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cat > foo.sh <<'END'
+#!/bin/sh
+echo " foofoofoo" >&9
+END
+chmod a+x foo.sh
+
+cat > bar <<'END'
+#!/bin/sh
+echo " barbarbar" >&9
+END
+
+chmod a+x foo.sh bar
+
+./configure
+
+# Sanity checks.
+st=0
+grep '^bar\.log:.*bar' Makefile || st=1
+grep '^foo\.log:' Makefile && st=1
+test $st -eq 0 || fatal_ "doesn't cover expected code paths"
+
+run_make -O -e IGNORE check
+cat foo.log
+cat bar.log
+test $am_make_rc -eq 0
+grep "^ foofoofoo$" stdout
+grep "^ barbarbar$" stdout
+$EGREP '(foofoofoo|barbarbar)' *.log && exit 1
+
+:
diff --git a/t/parallel-tests-fork-bomb.sh b/t/parallel-tests-fork-bomb.sh
new file mode 100644
index 000000000..315e891cb
--- /dev/null
+++ b/t/parallel-tests-fork-bomb.sh
@@ -0,0 +1,146 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - If $(TEST_SUITE_LOG) is in $(TEST_LOGS), we get a diagnosed
+# error, not a make hang or a system freeze.
+
+. test-init.sh
+
+# We don't want localized error messages from make, since we'll have
+# to grep them. See automake bug#11452.
+LANG=C LANGUAGE=C LC_ALL=C
+export LANG LANGUAGE LC_ALL
+
+# The tricky part of this test is to avoid that make hangs or even
+# freezes the system in case infinite recursion (which is the bug we
+# are testing against) is encountered. The following hacky makefile
+# should minimize the probability of that happening.
+cat > Makefile.am << 'END'
+TEST_LOG_COMPILER = true
+TESTS =
+
+errmsg = ::OOPS:: Recursion too deep
+
+if IS_GNU_MAKE
+
+ is_too_deep := $(shell test $(MAKELEVEL) -lt 10 && echo no)
+
+## Indenteation here required to avoid confusing Automake.
+ ifeq ($(is_too_deep),no)
+ else
+ $(error $(errmsg), $(MAKELEVEL) levels)
+ endif
+
+else !IS_GNU_MAKE
+
+# We use mkdir to detect the level of recursion, since it is easy
+# to use and assured to be portably atomical. Also use an higher
+# number than with GNU make above, since the level used here can
+# be incremented by tow or more per recursion.
+recursion-not-too-deep:
+ @ok=no; \
+ for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 \
+ 18 19 20 21 22 23 24 25 26 27 28 29; \
+ do \
+ echo " mkdir rec-$$i.d"; \
+ if mkdir rec-$$i.d; then \
+ ok=yes; break; \
+ else :; fi; \
+ done; \
+ test $$ok = yes || { echo '$(errmsg)' >&2; exit 1; }
+.PHONY: recursion-not-too-deep
+clean-local:
+ rmdir rec-[0-9].d
+
+targets = all check recheck $(TESTS) $(TEST_LOGS) $(TEST_SUITE_LOG)
+$(targets): recursion-not-too-deep
+
+# For BSD make.
+.BEGIN: recursion-not-too-deep
+
+endif !IS_GNU_MAKE
+END
+
+if using_gmake; then
+ cond=:
+else
+ cond=false
+fi
+
+cat >> configure.ac << END
+AM_CONDITIONAL([IS_GNU_MAKE], [$cond])
+AC_OUTPUT
+END
+
+# Another helpful idiom to avoid hanging on capable systems. The subshell
+# is needed since 'ulimit' might be a special shell builtin.
+if (ulimit -t 8); then ulimit -t 8; fi
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a -Wno-portability
+
+./configure
+
+do_check ()
+{
+ log=$1; shift
+ run_make -M -e IGNORE -- "$@" check
+ $FGREP '::OOPS::' output && exit 1 # Possible infinite recursion.
+ # Check that at least we don't create a botched global log file.
+ test ! -e "$log"
+ if using_gmake; then
+ grep "[Cc]ircular.*dependency" output | $FGREP "$log"
+ test $am_make_rc -gt 0
+ else
+ # Look for possible error messages about circular dependencies from
+ # either make or our own recipes. At least one such a message must
+ # be present. OTOH, some make implementations (e.g., NetBSD's), while
+ # smartly detecting the circular dependency early and diagnosing it,
+ # still exit with a successful exit status (yikes!). So don't check
+ # the exit status of non-GNU make, to avoid spurious failures.
+ # this case.
+ err_seen=no
+ for err_rx in \
+ 'circular.* depend' \
+ 'depend.* circular' \
+ 'graph cycle' \
+ 'infinite (loop|recursion)' \
+ 'depend.* on itself' \
+ ; do
+ $EGREP -i "$err_rx" output | $FGREP "$log" || continue
+ err_seen=yes
+ break
+ done
+ test $err_seen = yes || exit 1
+ fi
+}
+
+: > test-suite.test
+do_check test-suite.log TESTS=test-suite.test
+rm -f *.log *.test
+
+: > 0.test
+: > 1.test
+: > 2.test
+: > 3.test
+: > foobar.test
+do_check foobar.log TEST_LOGS='0.log 1.log foobar.log 2.log 3.log' \
+ TEST_SUITE_LOG=foobar.log
+rm -f *.log *.test
+
+:
diff --git a/t/parallel-tests-generated-and-distributed.sh b/t/parallel-tests-generated-and-distributed.sh
new file mode 100644
index 000000000..9627586f5
--- /dev/null
+++ b/t/parallel-tests-generated-and-distributed.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - generated distributed tests.
+# - listing $(srcdir)/ or $(top_srcdir)/ in TESTS doesn't work ATM,
+# and is thus diagnosed.
+
+# TODO: this test should also ensure that the 'make' implementation
+# properly adheres to rules in all cases. See the Autoconf
+# manual for the ugliness in this area, when VPATH comes into
+# play. :-/
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test
+## the next line will cause automake to error out:
+TESTS += $(srcdir)/bar.test $(top_srcdir)/baz.test
+.in.test:
+## Account for VPATH issues on weaker make implementations (e.g. IRIX 6.5)
+ cp `test -f '$<' || echo $(srcdir)/`$< $@
+ chmod +x $@
+check_SCRIPTS = $(TESTS)
+EXTRA_DIST = foo.in foo.test
+DISTCLEANFILES = foo.test
+END
+
+cat > foo.in <<'END'
+#! /bin/sh
+echo "this is $0"
+exit 0
+END
+
+$ACLOCAL
+$AUTOCONF
+AUTOMAKE_fails -a
+grep '$(srcdir).*TESTS.*bar\.test' stderr
+grep '$(top_srcdir).*TESTS.*baz\.test' stderr
+
+sed '/^TESTS +=.*srcdir/d' < Makefile.am > t
+mv -f t Makefile.am
+$AUTOMAKE -a
+
+./configure
+$MAKE check
+$MAKE distcheck
+$MAKE distclean
+
+mkdir build
+cd build
+../configure
+$MAKE check
+test ! -e ../foo.log
+$MAKE distcheck
+
+:
diff --git a/t/parallel-tests-harderror.sh b/t/parallel-tests-harderror.sh
new file mode 100644
index 000000000..70e21441e
--- /dev/null
+++ b/t/parallel-tests-harderror.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features: DISABLE_HARD_ERRORS
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > Makefile.am << 'END'
+SUBDIRS = . sub
+TESTS = foo.test
+XFAIL_TESTS = foo.test
+EXTRA_DIST = $(TESTS)
+END
+
+cat > sub/Makefile.am << 'END'
+TESTS = bar.test
+XFAIL_TESTS = $(TESTS)
+EXTRA_DIST = $(TESTS)
+END
+
+cat > foo.test <<'END'
+#! /bin/sh
+exit 99
+END
+chmod a+x foo.test
+cp foo.test sub/bar.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+# DISABLE_HARD_ERRORS is not defined as a make variable, so that it
+# should be possible to define either from the environment or from
+# command-line, also when recursive make invocations are involved,
+# and also without using the '-e' make flag; this should work also
+# for non-GNU make. Moreover, it shouldn't be necessary to define
+# DISABLE_HARD_ERRORS to "yes" to really disable hard errors: any
+# non-empty value should do.
+$MAKE check DISABLE_HARD_ERRORS=yes
+DISABLE_HARD_ERRORS=x $MAKE check
+
+# But an empty values for DISABLE_HARD_ERRORS means that hard errors
+# are not to be counted like normal failures.
+
+$MAKE check DISABLE_HARD_ERRORS= && exit 1
+cat test-suite.log
+grep '^ERROR: foo$' test-suite.log
+
+cd sub
+$MAKE check DISABLE_HARD_ERRORS= && exit 1
+cat test-suite.log
+grep '^ERROR: bar$' test-suite.log
+cd ..
+
+# Check the distributions.
+$MAKE DISABLE_HARD_ERRORS=y distcheck
+
+# Finally, DISABLE_HARD_ERRORS should work also when the developer
+# sets it directly in Makefile.am or Makefile. And its effects
+# should remain local to that specific Makefile, obviously.
+
+echo 'DISABLE_HARD_ERRORS = yes' >> Makefile.am
+$AUTOMAKE Makefile
+./config.status Makefile
+VERBOSE=yes $MAKE check && exit 1
+grep '^FAIL' test-suite.log && exit 1
+grep '^ERROR: bar$' sub/test-suite.log
+
+echo 'DISABLE_HARD_ERRORS = zardoz' >> sub/Makefile
+VERBOSE=yes $MAKE check
+
+:
diff --git a/t/parallel-tests-interrupt.tap b/t/parallel-tests-interrupt.tap
new file mode 100644
index 000000000..9f0c5a049
--- /dev/null
+++ b/t/parallel-tests-interrupt.tap
@@ -0,0 +1,116 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the parallel testsuite harness removes incomplete log files
+# when interrupt upon some signal. This test is definitely too hacky,
+# but we couldn't find a better way to deal with inter-processes
+# signals and the whole process-synchronization mess.
+
+. test-init.sh
+
+plan_ 16
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test
+## Provide more debugging info.
+TEST_LOG_COMPILER = $(SHELL) -ex
+## Required by foo.test; see below.
+AM_TESTS_FD_REDIRECT = 9>&1
+END
+
+# This is hacky and ugly, but has the great advantage of avoiding us a lot
+# of pain with background processes and related synchronization issues.
+
+cat - "$am_scriptdir"/test-driver > test-driver <<'END'
+#!/bin/sh
+echo $$ > pid
+END
+
+cat > foo.test << 'END'
+#!/bin/sh -e
+
+# We expect the test driver to be terminated by a signal, and so
+# to exit with non-zero status, thus causing "make check" to fail.
+# Exiting with status 0 from this test script is thus a good way to
+# make unexpected behaviours more evident, since this will likely
+# cause and unexpected success in "make check".
+trap 'exit 0' 0;
+stop_test () { exit 0; }
+
+# We need the "foo is starting to run" string flushed to standard output
+# ASAP, because we are soon going to grep for that string in the log file
+# where the test driver is redirecting this script's stdout. The safest
+# way force this flushing portably is to rely on perl I/O capabilities.
+$PERL -e 'BEGIN { $| = 1 }; print "foo is starting to run\n"' || stop_test
+
+ls -l >&9 || stop_test
+
+bailout ()
+{
+ # Print this to the original stdout (saved in the fd 9), so that the
+ # emitted "Bail out!" directive will be interpreted by the test driver
+ # running the Automake testsuite.
+ echo "Bail out! $*" >&9
+ stop_test
+}
+
+test $sig -gt 0 || bailout "\$sig not exported to test script"
+
+res=ok; cat foo.log >&9 || res="not ok"
+echo "$res - logfile created and readable [SIG $sig]" >&9
+
+res=ok; grep '^foo is starting to run$' foo.log >&9 || res='not ok'
+echo "$res - logfile contains output from test script [SIG $sig]" >&9
+
+cat pid >&9 || bailout "cannot get PID of test driver"
+kill -$sig `cat pid` || bailout "cannot send signal $sig to test driver"
+
+stop_test
+END
+chmod a+x foo.test
+
+$ACLOCAL || fatal_ "aclocal failed"
+$AUTOCONF || fatal_ "autoconf failed"
+$AUTOMAKE || fatal_ "automake failed"
+
+./configure || fatal_ "./configure failed"
+
+# The only signals that can be trapped portable are 1 "SIGHUP",
+# 2 "SIGINT", 13 "SIGPIPE" and 15 "SIGTERM".
+trapped_signals='1 2 13 15'
+
+for sig in $trapped_signals; do
+ if is_blocked_signal $sig; then
+ for i in 1 2 3 4; do echo "ok # SKIP signal $sig is blocked"; done
+ continue
+ fi
+ rm -f pid fail *.log
+ r=ok; env PERL="$PERL" sig="$sig" $MAKE check && r='not ok'
+ echo "$r - signal $sig to test driver causes \"make check\" to fail"
+ ls -l
+ # These files shouldn't exist, but in case they do, their content might
+ # provide helpful information about the causes of the failure(s).
+ cat foo.log || :
+ cat test-suite.log || :
+ r=ok; ls | $EGREP 'foo.*\.(log|tmp)' && r='not ok'
+ echo "$r - test driver clean up log and tmp files after signal $sig"
+done
+
+:
diff --git a/t/parallel-tests-log-compiler-1.sh b/t/parallel-tests-log-compiler-1.sh
new file mode 100644
index 000000000..12bdb92a1
--- /dev/null
+++ b/t/parallel-tests-log-compiler-1.sh
@@ -0,0 +1,125 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - per-extension "test runners" a.k.a. "log compilers" (xxx_LOG_COMPILER
+# and xxx_LOG_FLAGS), also with AC_SUBST'd stuff.
+# See also related test 'parallel-tests-log-compiler-2.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([acsubst_compiler], [t-compiler])
+AC_CONFIG_LINKS([chk-compiler:chk-compiler])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# Note that automake should not match the '/test' part of 'sub/test'
+# as '.test' suffix.
+TESTS = foo.chk bar.test baz bla.t bli.suff sub/test
+
+TEST_EXTENSIONS = .chk .test .t
+
+CHK_LOG_COMPILER = ./chk-compiler
+TEST_LOG_COMPILER = $(SHELL) $(srcdir)/test-compiler
+T_LOG_COMPILER = @acsubst_compiler@
+LOG_COMPILER = @SHELL@ -x $(srcdir)/noext-compiler
+
+CHK_LOG_FLAGS = --chk
+
+AM_TEST_LOG_FLAGS = --am-test
+
+T_LOG_FLAGS = --t
+AM_T_LOG_FLAGS = --am-t
+
+AM_LOG_FLAGS = -a
+LOG_FLAGS = -b
+
+# 't-compiler' is deliberately not distributed; it should be available
+# in PATH also from "make distcheck".
+EXTRA_DIST = $(TESTS) chk-compiler test-compiler noext-compiler
+END
+
+mkdir sub
+
+cat > chk-compiler <<'END'
+#! /bin/sh
+test x"$1" = x"--chk" || {
+ echo "$0: invalid command line: $*" >&2
+ exit 1
+}
+shift
+exec "$@"
+exit 127
+END
+sed 's/--chk/--am-test/' chk-compiler > test-compiler
+
+mkdir bin
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
+
+cat > bin/t-compiler <<'END'
+#! /bin/sh
+if test x"$1,$2" != x"--am-t,--t"; then
+ echo "$0: invalid command line: $*" >&2
+ exit 1
+fi
+shift; shift
+exec "$@"
+exit 127
+END
+sed 's/--am-t,--t/-a,-b/' bin/t-compiler > noext-compiler
+
+chmod a+x chk-compiler chk-compiler test-compiler bin/t-compiler noext-compiler
+
+cat >foo.chk << 'END'
+#! /bin/sh
+exit 0
+END
+chmod a+x foo.chk
+cp foo.chk bar.test
+cp foo.chk baz
+cp foo.chk bla.t
+cp foo.chk bli.suff
+cp foo.chk sub/test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE check || { cat test-suite.log; exit 1; }
+ls -l . sub
+cat test-suite.log
+test -f foo.log
+test -f bar.log
+test -f baz.log
+test -f bla.log
+test -f bli.suff.log
+test -f sub/test.log
+
+run_make -e FAIL T_LOG_FLAGS=--bad check
+cat test-suite.log
+cat bla.log
+# With the above flag overridden, bla.t should fail ...
+$EGREP '(^ *|/)t-compiler:.* invalid .*--bad' bla.log
+# ... but no other test should.
+grep -v '^FAIL: bla\.t ' bla.log | grep 'FAIL:' && exit 1
+
+# Try also with a VPATH build.
+$MAKE distcheck
+
+:
diff --git a/t/parallel-tests-log-compiler-2.sh b/t/parallel-tests-log-compiler-2.sh
new file mode 100644
index 000000000..ad9535af5
--- /dev/null
+++ b/t/parallel-tests-log-compiler-2.sh
@@ -0,0 +1,95 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - per-extension "test runners" a.k.a. "log compilers" (xxx_LOG_COMPILER
+# and xxx_LOG_FLAGS), when some tests are PROGRAMS.
+# See also related test 'parallel-tests-log-compiler-1.sh'.
+
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+## Note that automake should not match the '/test' part
+## of 'sub/test' as '.test' suffix.
+TESTS = foo.chk bar.test $(check_PROGRAMS) sub/test
+check_PROGRAMS = baz bla.test bli.suff
+TEST_EXTENSIONS = .chk .test
+CHK_LOG_COMPILER = ./chk-compiler
+TEST_LOG_COMPILER = ./test-compiler
+LOG_COMPILER = ./noext-compiler
+AM_CHK_LOG_FLAGS = 1
+CHK_LOG_FLAGS = 2
+AM_TEST_LOG_FLAGS = 3
+TEST_LOG_FLAGS = 4
+AM_LOG_FLAGS = 5
+LOG_FLAGS = 6
+END
+
+mkdir sub
+
+cat >chk-compiler <<'END'
+#! /bin/sh
+echo $0 "$@"
+shift
+shift
+exec "$@"
+exit 127
+END
+chmod a+x chk-compiler
+cp chk-compiler test-compiler
+cp chk-compiler noext-compiler
+
+cat >foo.chk << 'END'
+#! /bin/sh
+exit 0
+END
+chmod a+x foo.chk
+cp foo.chk bar.test
+cp foo.chk sub/test
+
+cat >baz.c << 'END'
+int main (void)
+{
+ return 0;
+}
+END
+cp baz.c bla.c
+cp baz.c bli.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE
+$MAKE check || { cat test-suite.log; exit 1; }
+ls -l . sub
+cat test-suite.log
+grep 'chk-compiler *1 *2' foo.log
+grep 'test-compiler *3 *4' bar.log
+grep 'noext-compiler *5 *6' baz.log
+grep 'test-compiler *3 *4' bla.log
+grep 'noext-compiler *5 *6' bli.suff.log
+grep 'noext-compiler *5 *6' sub/test.log
+
+:
diff --git a/t/parallel-tests-log-compiler-example.sh b/t/parallel-tests-log-compiler-example.sh
new file mode 100644
index 000000000..281d4ce32
--- /dev/null
+++ b/t/parallel-tests-log-compiler-example.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test the example of usage of generic and extension-specific
+# LOG_COMPILER and LOG_FLAGS given in the manual.
+
+required=python
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_SUBST([PERL], ['$PERL'])
+AM_PATH_PYTHON
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.pl bar.py baz
+TEST_EXTENSIONS = .pl .py
+PL_LOG_COMPILER = $(PERL)
+AM_PL_LOG_FLAGS = -w
+PY_LOG_COMPILER = $(PYTHON)
+AM_PY_LOG_FLAGS = -v
+LOG_COMPILER = ./wrapper-script
+AM_LOG_FLAGS = -d
+END
+
+echo 'my $a =+ 2; exit (0);' > foo.pl
+echo 'import sys; sys.exit(0);' > bar.py
+: > baz
+
+cat > wrapper-script <<'END'
+#!/bin/sh
+echo "wrapper args: $*"
+END
+chmod a+x wrapper-script
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+st=0
+$MAKE check || st=$?
+cat foo.log
+cat bar.log
+cat baz.log
+test $st -eq 0 || exit $st
+
+# Check that the wrappers have been run with the expected flags.
+grep '[rR]eversed.*+=.*operator.*foo\.pl' foo.log
+grep '^# *[cC]lear.*sys\.argv' bar.log
+grep '^wrapper args:.* -d .*baz' baz.log
+
+:
diff --git a/t/parallel-tests-log-override-1.sh b/t/parallel-tests-log-override-1.sh
new file mode 100644
index 000000000..6d4672efa
--- /dev/null
+++ b/t/parallel-tests-log-override-1.sh
@@ -0,0 +1,109 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features: runtime redefinition of $(TEST_SUITE_LOG).
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+TESTS = pass.test skip.test xfail.test
+XFAIL_TESTS = xfail.test
+EXTRA_DIST = $(TESTS)
+END
+
+cat > pass.test <<'END'
+#! /bin/sh
+exit 0
+END
+
+cat > skip.test <<'END'
+#! /bin/sh
+echo "% test skipped %"
+exit 77
+END
+
+cat > xfail.test <<'END'
+#! /bin/sh
+echo "# expected failure #"
+exit 1
+END
+
+chmod a+x *.test
+
+test_log_edit ()
+{
+ sed -e "s|^ *$me 1\.0:.*$| $me 1.0: ???|" \
+ -e "s|^=====*|=======================|" $*
+}
+
+test_log_expected ()
+{
+ test_log_edit orig > exp
+ test_log_edit $1 > got
+ diff exp got || exit 1
+ rm -f exp got
+}
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE check
+ls -l
+cat test-suite.log
+cp test-suite.log orig
+
+$MAKE clean
+test -f test-suite.log && exit 99 # Sanity check.
+
+# Check that we can override the testsuite log file at runtime.
+run_make TEST_SUITE_LOG=zardoz.log check
+ls -l
+test ! -e test-suite.log
+cat zardoz.log
+test_log_expected zardoz.log
+# Sanity check the distribution too (this also does minimal checks on
+# VPATH support).
+run_make TEST_SUITE_LOG=zardoz.log distcheck
+
+# Check that cleanup rules remove the correct file even when
+# user overrides are in place.
+cp orig test-suite.log
+run_make TEST_SUITE_LOG=zardoz.log clean
+ls -l
+test ! -e zardoz.log
+diff orig test-suite.log
+
+# Check that the default testsuite log doesn't get unduly modified.
+# Also check that the testsuite log file doesn't need to be named
+# accordingly to the '*.log' pattern.
+chmod a-w test-suite.log
+run_make TEST_SUITE_LOG=TheLogFile check
+ls -l
+diff orig test-suite.log
+test_log_expected TheLogFile
+run_make TEST_SUITE_LOG=TheLogFile clean
+ls -l
+test ! -e TheLogFile
+diff orig test-suite.log
+
+:
diff --git a/t/parallel-tests-log-override-2.sh b/t/parallel-tests-log-override-2.sh
new file mode 100644
index 000000000..470a8f8f8
--- /dev/null
+++ b/t/parallel-tests-log-override-2.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features: runtime redefinition of:
+# - $(TEST_SUITE_LOG) and $(TESTS)
+# - $(TEST_SUITE_LOG) and $(TEST_LOGS)
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+TESTS = pass.test pass2.test skip.test skip2.test fail.test
+END
+
+cat > pass.test <<'END'
+#! /bin/sh
+exit 0
+END
+
+cp pass.test pass2.test
+
+cat > skip.test <<'END'
+#! /bin/sh
+echo "% skipped test %"
+exit 77
+END
+
+cp skip.test skip2.test
+
+cat > fail.test <<'END'
+#! /bin/sh
+exit 1
+END
+
+chmod a+x *.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+for test_list_override in \
+ 'TESTS=pass.test skip.test' \
+ 'TEST_LOGS=pass.log skip.log'
+do
+ run_make -O TEST_SUITE_LOG=partial.log "$test_list_override" check
+ ls -l
+ count_test_results total=2 pass=1 fail=0 skip=1 xfail=0 xpass=0 error=0
+ cat pass.log
+ cat skip.log
+ cat partial.log
+ test ! -e test-suite.log
+ test ! -e pass2.log
+ test ! -e skip2.log
+ test ! -e fail.log
+ grep '^PASS: pass\.test$' stdout
+ grep '^SKIP: skip\.test$' stdout
+ $FGREP 'SKIP: skip' partial.log
+ $FGREP '% skipped test %' partial.log
+ $EGREP '(pass2|skip2|fail)\.test' stdout && exit 1
+ $EGREP '(pass2|skip2|fail)' partial.log && exit 1
+ rm -f *.log
+done
+
+:
diff --git a/t/parallel-tests-log-override-recheck.sh b/t/parallel-tests-log-override-recheck.sh
new file mode 100644
index 000000000..f5097f857
--- /dev/null
+++ b/t/parallel-tests-log-override-recheck.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features: runtime redefinition of $(TEST_SUITE_LOG)
+# for the recheck target.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+TESTS = foofoo.test barbar.test bazbaz.test
+END
+
+cat > foofoo.test <<'END'
+#! /bin/sh
+echo "this is $0"
+exit 0
+END
+
+cat > barbar.test <<'END'
+#! /bin/sh
+echo "this is $0"
+exit 99
+END
+
+cat > bazbaz.test <<'END'
+#! /bin/sh
+echo "this is $0"
+exit ${BAZ_EXIT_STATUS-1}
+END
+
+chmod a+x *.test
+
+unset BAZ_EXIT_STATUS
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# Filter make output before grepping it, for make implementations that,
+# like Solaris' one, print the whole of the failed recipe on failure.
+filter_stdout ()
+{
+ grep -v 'bases=.*;' stdout > t && mv -f t stdout
+}
+
+./configure
+run_make -O -e FAIL check
+
+using_gmake || $sleep # Required by BSD make.
+
+chmod a-rw test-suite.log
+run_make -O -e FAIL TEST_SUITE_LOG=my.log recheck
+ls -l
+filter_stdout
+count_test_results total=2 pass=0 fail=1 skip=0 xfail=0 xpass=0 error=1
+for x in stdout my.log; do
+ $FGREP foofoo $x && exit 1
+ $FGREP barbar $x
+ $FGREP bazbaz $x
+done
+
+using_gmake || $sleep # Required by BSD make.
+
+chmod a-rw my.log
+run_make -O -e FAIL BAZ_EXIT_STATUS=0 TEST_SUITE_LOG=my2.log recheck
+ls -l
+count_test_results total=2 pass=1 fail=0 skip=0 xfail=0 xpass=0 error=1
+filter_stdout
+$FGREP foofoo stdout && exit 1
+$FGREP barbar stdout
+$FGREP bazbaz stdout
+$FGREP foofoo my2.log && exit 1
+$FGREP barbar my2.log
+$FGREP bazbaz my2.log && exit 1
+
+chmod u+r test-suite.log my.log
+$FGREP bazbaz test-suite.log
+$FGREP bazbaz my.log
+
+:
diff --git a/t/parallel-tests-no-color-in-log.sh b/t/parallel-tests-no-color-in-log.sh
new file mode 100644
index 000000000..0c4a7b6cf
--- /dev/null
+++ b/t/parallel-tests-no-color-in-log.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Colorized output from the testsuite report shouldn't end up in log files.
+
+required='grep-nonprint'
+. test-init.sh
+
+TERM=ansi; export TERM
+
+cat >>configure.ac <<END
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+LOG_COMPILER = $(SHELL)
+AUTOMAKE_OPTIONS = color-tests
+TESTS = pass fail skip xpass xfail error
+XFAIL_TESTS = xpass xfail
+END
+
+echo 'exit 0' > pass
+echo 'exit 0' > xpass
+echo 'exit 1' > fail
+echo 'exit 1' > xfail
+echo 'exit 77' > skip
+echo 'exit 99' > error
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+mv config.log config-log # Avoid possible false positives below.
+run_make -e FAIL AM_COLOR_TESTS=always check
+# Not a useless use of cat; see above comments "grep-nonprinting"
+# requirement in 'test-init.sh'.
+cat *.log | grep "$esc" && exit 1
+
+:
diff --git a/t/parallel-tests-no-spurious-summary.sh b/t/parallel-tests-no-spurious-summary.sh
new file mode 100644
index 000000000..888a60042
--- /dev/null
+++ b/t/parallel-tests-no-spurious-summary.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that ':test-results:' directives in test scripts' output doesn't
+# originate spurious results in the testsuite summary.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test bar.test
+END
+
+cat > foo.test <<'END'
+#! /bin/sh
+echo :test-result:XFAIL
+echo :test-result: SKIP
+echo :test-result:ERROR
+exit 0
+END
+cat > bar.test <<'END'
+#! /bin/sh
+echo :test-result: ERROR
+echo :test-result:FAIL
+echo :test-result: XPASS
+exit 0
+END
+chmod a+x foo.test bar.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+run_make -O -e IGNORE check
+cat test-suite.log
+cat foo.log
+cat bar.log
+test $am_make_rc -eq 0
+
+grep '^:test-result:XFAIL$' foo.log
+grep '^:test-result: SKIP$' foo.log
+grep '^:test-result:FAIL$' bar.log
+grep '^:test-result: XPASS$' bar.log
+
+count_test_results total=2 pass=2 fail=0 skip=0 xfail=0 xpass=0 error=0
+
+:
diff --git a/t/parallel-tests-once.sh b/t/parallel-tests-once.sh
new file mode 100644
index 000000000..add9cf4eb
--- /dev/null
+++ b/t/parallel-tests-once.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Tests shouldn't be run multiple times by a simple "make check" in a
+# clean directory. An early implementation of the '.trs' intermediate
+# files incurred a similar problem.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test
+END
+
+cat > foo.test <<'END'
+#! /bin/sh
+test -f foo.run && exit 1
+: > foo.run
+END
+chmod a+x foo.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE check
+test -f foo.run # Sanity check.
+
+:
diff --git a/t/parallel-tests-recheck-depends-on-all.sh b/t/parallel-tests-recheck-depends-on-all.sh
new file mode 100644
index 000000000..736f4708a
--- /dev/null
+++ b/t/parallel-tests-recheck-depends-on-all.sh
@@ -0,0 +1,89 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The parallel-tests 'recheck' target must depend on the 'all' target.
+# See automake bug#11252.
+
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+all-local:
+ test ! -f status || echo okokok > status
+bin_PROGRAMS = foo
+TESTS = a.test b.test c.test
+END
+
+cat > foo.c << 'END'
+#include <stdio.h>
+int main (void)
+{
+ printf ("failure :-(" "\n");
+ return 1;
+}
+END
+
+cat > a.test << 'END'
+#!/bin/sh
+exit 0
+END
+
+cat > b.test << 'END'
+#!/bin/sh
+grep okokok status
+END
+
+cat > c.test << 'END'
+#!/bin/sh
+./foo
+END
+
+chmod a+x *.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+
+run_make -O -e FAIL check
+count_test_results total=3 pass=1 fail=2 skip=0 xfail=0 xpass=0 error=0
+test ! -e status
+
+$sleep
+: > status
+cat > foo.c << 'END'
+#include <stdio.h>
+int main (void)
+{
+ printf ("success :-)" "\n");
+ return 0;
+}
+END
+
+run_make -O recheck
+count_test_results total=2 pass=2 fail=0 skip=0 xfail=0 xpass=0 error=0
+grep '^PASS: b\.test$' stdout
+grep '^PASS: c\.test$' stdout
+
+run_make -O recheck
+count_test_results total=0 pass=0 fail=0 skip=0 xfail=0 xpass=0 error=0
+
+:
diff --git a/t/parallel-tests-recheck-pr11791.sh b/t/parallel-tests-recheck-pr11791.sh
new file mode 100644
index 000000000..ffb99d4f7
--- /dev/null
+++ b/t/parallel-tests-recheck-pr11791.sh
@@ -0,0 +1,85 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests: "make recheck" and "make -k recheck" in the face of
+# build failures for the test cases. See automake bug#11791.
+
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = $(EXTRA_PROGRAMS)
+EXTRA_PROGRAMS = foo
+END
+
+echo 'int main (void) { return 1; }' > foo.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+run_make -O -e FAIL check
+count_test_results total=1 pass=0 fail=1 xpass=0 xfail=0 skip=0 error=0
+
+using_gmake || $sleep # Required by BSD make.
+run_make -O -e IGNORE -- -k recheck
+# Don't trust the exit status of "make -k" for non-GNU makes.
+! using_gmake || test $am_make_rc -gt 0 || exit 1
+count_test_results total=1 pass=0 fail=1 xpass=0 xfail=0 skip=0 error=0
+
+# Introduce an error in foo.c, that should cause a compilation failure.
+$sleep
+echo choke me >> foo.c
+
+run_make -O -e FAIL recheck
+# We don't get a change to run the testsuite.
+$EGREP '(X?PASS|X?FAIL|SKIP|ERROR):' stdout && exit 1
+# These shouldn't be removed, otherwise the next make recheck will do
+# nothing.
+test -f foo.log
+test -f foo.trs
+
+using_gmake || $sleep # Required by BSD make.
+run_make -O -e IGNORE -- -k recheck
+# Don't trust the exit status of "make -k" for non-GNU makes.
+! using_gmake || test $am_make_rc -gt 0 || exit 1
+# We don't get a change to run the testsuite.
+$EGREP '(X?PASS|X?FAIL|SKIP|ERROR):' stdout && exit 1
+test -f foo.log
+test -f foo.trs
+
+# "Repair" foo.c, and expect everything to work.
+$sleep
+echo 'int main (void) { return 0; }' > foo.c
+
+run_make -O recheck
+count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
+test -f foo.log
+test -f foo.trs
+
+run_make -O recheck
+count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+test -f foo.log
+test -f foo.trs
+
+:
diff --git a/t/parallel-tests-recheck.sh b/t/parallel-tests-recheck.sh
new file mode 100644
index 000000000..2ea07d1a8
--- /dev/null
+++ b/t/parallel-tests-recheck.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - recheck
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_SUITE_LOG = mylog.log
+TESTS = foo.test bar.test baz.test
+check_SCRIPTS = bla
+CLEANFILES = bla
+bla:
+ echo bla > $@
+END
+
+cat > foo.test <<'END'
+#! /bin/sh
+echo "this is $0"
+test -f bla || exit 1
+exit 0
+END
+cat > bar.test <<'END'
+#! /bin/sh
+echo "this is $0"
+exit 99
+END
+cat > baz.test <<'END'
+#! /bin/sh
+echo "this is $0"
+exit 1
+END
+chmod a+x foo.test bar.test baz.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+run_make -O -e FAIL check
+count_test_results total=3 pass=1 fail=1 skip=0 xfail=0 xpass=0 error=1
+
+# Running this two times in a row should produce the same results the
+# second time.
+for i in 1 2; do
+ using_gmake || $sleep # Required by BSD make.
+ run_make -O -e FAIL recheck
+ count_test_results total=2 pass=0 fail=1 skip=0 xfail=0 xpass=0 error=1
+ grep 'foo\.test' stdout && exit 1
+ grep '^ERROR: bar\.test$' stdout
+ grep '^FAIL: baz\.test$' stdout
+done
+
+# Ensure that recheck builds check_SCRIPTS, and that
+# recheck reruns nothing if check has not been run.
+$MAKE clean
+$MAKE recheck
+test -f bla
+test ! -e foo.log
+test ! -e bar.log
+test ! -e baz.log
+test -f mylog.log
+
+:
diff --git a/t/parallel-tests-reset-term.sh b/t/parallel-tests-reset-term.sh
new file mode 100644
index 000000000..01cf4f9cc
--- /dev/null
+++ b/t/parallel-tests-reset-term.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the testsuite harness correctly handle overrides of the
+# TERM variable by either TESTS_ENVIRONMENT and AM_TESTS_ENVIRONMENT.
+
+required='grep-nonprint'
+. test-init.sh
+
+TERM=ansi; export TERM
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_COLOR_TESTS = always
+AUTOMAKE_OPTIONS = color-tests
+TESTS = foobar
+END
+
+cat > foobar << 'END'
+#!/bin/sh
+echo "TERM='$TERM'"
+test x"$TERM" = x"dumb"
+END
+chmod a+x foobar
+
+mkcheck ()
+{
+ run_make -O -e IGNORE "$@" check
+ cat stdout
+ cat foobar.log
+ cat test-suite.log
+ return $am_make_rc
+}
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+
+mkcheck TESTS_ENVIRONMENT='TERM=dumb'
+cat stdout | grep "PASS.*foobar" | grep "$esc\\["
+
+mkcheck AM_TESTS_ENVIRONMENT='TERM=dumb'
+cat stdout | grep "PASS.*foobar" | grep "$esc\\["
+
+:
diff --git a/t/parallel-tests-subdir.sh b/t/parallel-tests-subdir.sh
new file mode 100644
index 000000000..1647b5b55
--- /dev/null
+++ b/t/parallel-tests-subdir.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the parallel test harness creates parent directories for
+# the log files when needed.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = dir1/foo.test dir2/dir3/foo.test
+TEST_LOG_COMPILER = sh
+END
+
+mkdir dir1 dir2 dir2/dir3
+echo : > dir1/foo.test
+echo : > dir2/dir3/foo.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkdir build
+cd build
+../configure
+$MAKE check
+find . # For debugging.
+test -f test-suite.log
+test -f dir1/foo.log
+test -f dir1/foo.trs
+test -f dir2/dir3/foo.log
+test -f dir2/dir3/foo.trs
+
+:
diff --git a/t/parallel-tests-suffix-prog.sh b/t/parallel-tests-suffix-prog.sh
new file mode 100644
index 000000000..abddb6439
--- /dev/null
+++ b/t/parallel-tests-suffix-prog.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - suffix rules, with PROGRAMS involved
+# See also sister test 'parallel-tests-suffix.sh'.
+
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+## Note that automake should not match the '/test' part of 'sub/test' as
+## '.test' suffix, nor the '/chk' part of 'sub/chk' as '.chk' suffix.
+TESTS = $(dist_TESTS) $(check_PROGRAMS)
+dist_TESTS = foo.chk bar.test sub/test
+check_PROGRAMS = baz bla.test bli.suff sub/chk
+TEST_EXTENSIONS = .chk .test
+EXTRA_DIST = $(dist_TESTS)
+END
+
+mkdir sub
+
+cat >foo.chk << 'END'
+#! /bin/sh
+exit 0
+END
+chmod a+x foo.chk
+cp foo.chk bar.test
+cp foo.chk sub/test
+
+cat >baz.c << 'END'
+int main (void)
+{
+ return 0;
+}
+END
+cp baz.c bla.c
+cp baz.c bli.c
+cp baz.c sub/chk.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE check
+ls -l . sub
+test -f foo.log
+test -f bar.log
+test -f baz.log
+test -f bla.log
+test -f bli.suff.log
+test -f sub/chk.log
+test -f sub/test.log
+
+$MAKE distcheck
+
+:
diff --git a/t/parallel-tests-suffix.sh b/t/parallel-tests-suffix.sh
new file mode 100644
index 000000000..47bdccf4c
--- /dev/null
+++ b/t/parallel-tests-suffix.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - suffix rules
+# See also sister test 'parallel-tests-suffix-prog.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+## Note that automake should not match the '/test' part
+## of 'sub/test' as '.test' suffix.
+TESTS = foo.chk bar.test baz bli.suff sub/test
+TEST_EXTENSIONS = .chk .test
+EXTRA_DIST = $(TESTS)
+END
+
+mkdir sub
+
+cat >foo.chk << 'END'
+#! /bin/sh
+exit 0
+END
+chmod a+x foo.chk
+cp foo.chk bar.test
+cp foo.chk baz
+cp foo.chk bli.suff
+cp foo.chk sub/test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE check
+ls -l . sub
+test -f foo.log
+test -f bar.log
+test -f baz.log
+test -f bli.suff.log
+test -f sub/test.log
+
+$MAKE distcheck
+
+:
diff --git a/t/parallel-tests-trailing-whitespace.sh b/t/parallel-tests-trailing-whitespace.sh
new file mode 100644
index 000000000..f82f76cb3
--- /dev/null
+++ b/t/parallel-tests-trailing-whitespace.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - trailing whitespace in TESTS
+# GNU make 3.80 may expand trailing white space to '.log'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo $(BAR)
+BAR =
+END
+
+cat >foo <<'END'
+#! /bin/sh
+exit 0
+END
+
+chmod +x ./foo
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE check
+
+:
diff --git a/t/parallel-tests-unreadable.sh b/t/parallel-tests-unreadable.sh
new file mode 100644
index 000000000..e57c4c0a8
--- /dev/null
+++ b/t/parallel-tests-unreadable.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the testsuite driver copes well with unreadable '.log'
+# and '.trs' files.
+
+. test-init.sh
+
+: > t
+chmod a-r t && test ! -r t || skip_ "you can still read unreadable files"
+rm -f t
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test bar.test
+END
+
+cat > foo.test << 'END'
+#! /bin/sh
+echo foofoofoo
+exit 0
+END
+
+cat > bar.test << 'END'
+#! /bin/sh
+echo barbarbar
+exit 77
+END
+
+chmod a+x foo.test bar.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+for files in \
+ 'foo.log bar.log' \
+ 'foo.trs bar.trs' \
+ 'foo.trs bar.log' \
+ 'foo.log bar.trs' \
+; do
+ $MAKE check
+ rm -f test-suite.log
+ chmod a-r $files
+ $MAKE test-suite.log || { ls -l; exit 1; }
+ ls -l
+ grep '^foofoofoo$' foo.log
+ grep '^:test-result: PASS' foo.trs
+ grep '^barbarbar$' bar.log
+ grep '^:test-result: SKIP' bar.trs
+ grep '^SKIP: bar' test-suite.log
+ grep '^barbarbar$' test-suite.log
+ $EGREP ':.*foo|foofoofoo' test-suite.log && exit 1
+ : For shells with busted 'set -e'.
+done
+
+:
diff --git a/t/parse.sh b/t/parse.sh
new file mode 100644
index 000000000..06565c497
--- /dev/null
+++ b/t/parse.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure backslash-newline is treated as whitespace.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zot
+zot_SOURCES = \
+zar.c\
+doz.c
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP zar.cdoz Makefile.in && exit 1
+exit 0
diff --git a/t/per-target-flags.sh b/t/per-target-flags.sh
new file mode 100644
index 000000000..f9bbd32f2
--- /dev/null
+++ b/t/per-target-flags.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test executable-specific and library-specific flags, both with
+# and without dependency tracking.
+
+. test-init.sh
+
+makefiles='Makefile libMakefile Makefile2 libMakefile2'
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([-Wno-extra-portability])
+AC_CONFIG_FILES([$makefiles])
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+$ACLOCAL
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c
+foo_CFLAGS = -DBAR
+END
+
+cat > libMakefile.am << 'END'
+lib_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c bar.cc
+libfoo_a_CFLAGS = -DBAR
+libfoo_a_CXXFLAGS = -DZOT
+END
+
+cat - Makefile.am > Makefile2.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+END
+
+cat - libMakefile.am > libMakefile2.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+END
+
+makefiles=$(for mkf in $makefiles; do echo $mkf.in; done)
+
+$AUTOMAKE
+
+# Sanity check.
+for mkf in $makefiles; do test -f $mkf || exit 99; done
+
+# Regression test for missing space.
+$FGREP ')-c' $makefiles && exit 1
+
+# Regression test for botchedly transformed object names.
+$FGREP '.o.o' $makefiles && exit 1
+$FGREP '.obj.obj' $makefiles && exit 1
+$FGREP '.$(OBJEXT).$(OBJEXT)' $makefiles && exit 1
+
+# Watch against non-transformed "foo.$(OBJEXT)", "foo.o" and "foo.obj"
+# (and similarly for bar).
+$EGREP '[^-](foo|bar)\.[o$]' $makefiles && exit 1
+
+# All our programs and libraries have per-target flags, so all
+# the compilers invocations must use an explicit '-c' option.
+grep '\$.COMPILE' $makefiles | grep -v ' -c' && exit 1
+
+$FGREP 'foo-foo.$(OBJEXT)' Makefile.in
+$FGREP 'foo-foo.$(OBJEXT)' Makefile2.in
+$FGREP 'libfoo_a-foo.$(OBJEXT)' libMakefile.in
+$FGREP 'libfoo_a-foo.$(OBJEXT)' libMakefile2.in
+$FGREP 'libfoo_a-bar.$(OBJEXT)' libMakefile.in
+$FGREP 'libfoo_a-bar.$(OBJEXT)' libMakefile2.in
+
+$FGREP '$(foo_CFLAGS)' Makefile.in
+$FGREP '$(foo_CFLAGS)' Makefile2.in
+$FGREP '$(libfoo_a_CFLAGS)' libMakefile.in
+$FGREP '$(libfoo_a_CFLAGS)' libMakefile2.in
+
+:
diff --git a/t/percent.sh b/t/percent.sh
new file mode 100644
index 000000000..e8492e7b7
--- /dev/null
+++ b/t/percent.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that -Wportability understands %-style pattern
+# rules.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_PROG_CC
+EOF
+
+cat >Makefile.am <<EOF
+bin_PROGRAMS = liver
+liver_SOURCES = foo.c
+
+%.o: %.c
+ echo "gnu make extension"
+EOF
+
+$ACLOCAL
+AUTOMAKE_fails -Wportability
+grep 'Makefile.am:4:.*%' stderr
diff --git a/t/percent2.sh b/t/percent2.sh
new file mode 100644
index 000000000..1aabfa72c
--- /dev/null
+++ b/t/percent2.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another test for -Wportability warning about %-style rules, plus
+# make sure we don't warn about duplicate definition for
+# '${ARCH}/%.$(OBJEXT):'.
+# Report from Ralf Corsepius.
+
+. test-init.sh
+
+cat >>Makefile.am << 'EOF'
+${ARCH}/%.$(OBJEXT): %.S
+ test -d ${ARCH} || mkdir ${ARCH}
+ ${CCASCOMPILE} -o $@ -c $<
+
+${ARCH}/%.$(OBJEXT): %.c
+ test -d ${ARCH} || mkdir ${ARCH}
+ ${COMPILE} -o $@ -c $<
+EOF
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '%.*pattern.*rules' stderr
+
+# No error otherwise.
+$AUTOMAKE -Wno-portability
diff --git a/t/perf/cond.sh b/t/perf/cond.sh
new file mode 100755
index 000000000..07ffb945b
--- /dev/null
+++ b/t/perf/cond.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that many conditions do not lead to combinatorial explosion.
+# (This is related to PR/352.)
+
+. test-init.sh
+
+echo AC_PROG_CC >>configure.ac
+
+cat >Makefile.am <<EOF
+bin_PROGRAMS = a
+a02_LDADD =
+a03_SOURCES =
+EOF
+
+# On this test, Automake 1.7.x would compute all 2**24 = 16777216
+# possible combinations of conditionals (it would do this five times,
+# to define a01_DEPENDENCIES, a02_DEPENDENCIES, a03_OBJECTS,
+# a04_OBJECTS, and to rewrite bin_PROGRAM), eating all memory, swap,
+# or cpu time it can found.
+
+for i in \
+ 01 02 03 04 05 06 07 08 09 10 \
+ 11 12 13 14 15 16 17 18 19 20 \
+ 21 22 23 24
+do
+ unindent >>Makefile.am <<EOF
+ if C$i
+ bin_PROGRAMS += a$i
+ a01_LDADD = foo${i}.o
+ a02_LDADD += bar${i}.o
+ a03_SOURCES += baz${i}.c
+ a04_SOURCES = quux${i}.c
+ endif C$i
+EOF
+ echo "AM_CONDITIONAL([C$i], [:])" >>configure.ac
+done
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/perf/testsuite-recheck.sh b/t/perf/testsuite-recheck.sh
new file mode 100755
index 000000000..d3c63503e
--- /dev/null
+++ b/t/perf/testsuite-recheck.sh
@@ -0,0 +1,98 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check performance of recheck target in the face of many failed tests.
+# FIXME: this test is not currently able to detect whether the measured
+# FIXME: performance is too low, and FAIL accordingly; it just offers an
+# FIXME: easy way to verify how effective a performance optimization is.
+
+. test-init.sh
+
+count=5000
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<END
+count_expected = $count
+TEST_EXTENSIONS = .t
+## Updated later.
+TESTS =
+END
+
+# This should ensure that our timing won't be disturbed by the time
+# that would be actually required to run any of:
+# - the test cases
+# - the test driver executing them
+# - the recipe to create the final test-suite log.
+cat >> Makefile.am << 'END'
+AUTOMAKE_OPTIONS = -Wno-override
+## These should never be run.
+T_LOG_COMPILER = false
+T_LOG_DRIVER = false
+
+# The recipe of this also serves as a sanity check.
+$(TEST_SUITE_LOG):
+## For debugging.
+ @echo "RE-RUN:"; for i in $(TEST_LOGS); do echo " $$i"; done
+## All the test cases should have been re-run.
+ @count_got=`for i in $(TEST_LOGS); do echo $$i; done | wc -l` \
+ && echo "Count expected: $(count_expected)" \
+ && echo "Count obtained: $$count_got" \
+ && test $$count_got -eq $(count_expected)
+## Pre-existing log files of the tests to re-run should have been
+## removed by the 'recheck' target
+ @for i in $(TEST_LOGS); do \
+ test ! -f $$i.log || { echo "$$i.log exists!"; exit 1; }; \
+ done
+## Actually create the target file, for extra safety.
+ @echo dummy > $@
+END
+
+# Updated later.
+: > all
+
+# Temporarily disable shell traces, to avoid bloating the log file.
+set +x
+
+for i in $(seq_ 1 $count); do
+ echo dummy $i > $i.log
+ echo :global-test-result: PASS > $i.trs
+ echo :test-result: PASS >> $i.trs
+ echo :recheck: yes >> $i.trs
+ echo TESTS += $i.t >> Makefile.am
+ echo $i >> all
+done
+
+# Re-enable shell traces.
+set -x
+
+# So that we don't need to create a ton of dummy tests.
+echo '$(TESTS):' >> Makefile.am
+
+head -n 100 Makefile.am || : # For debugging.
+tail -n 100 Makefile.am || : # Likewise.
+cat $count.trs # Likewise, just the last specimen though.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE recheck
+
+:
diff --git a/t/perf/testsuite-summary.sh b/t/perf/testsuite-summary.sh
new file mode 100755
index 000000000..ca8e9a115
--- /dev/null
+++ b/t/perf/testsuite-summary.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check performanceof recipe generating test-suite.log file and testsuite
+# summary. That has suffered of huge inefficiencies in the past.
+# FIXME: this test is not currently able to detect whether the measured
+# FIXME: performance is too low, and FAIL accordingly; it just offers
+# FIXME: an easy way verify how effective a performance optimization is.
+
+. test-init.sh
+
+count=10000
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+TEST_EXTENSIONS = .t
+## Will be updated later.
+TESTS =
+## None of these should ever be run.
+T_LOG_COMPILER = false
+T_LOG_DRIVER = false
+END
+
+# Temporarily disable shell traces, to avoid bloating the log file.
+set +x
+
+for i in $(seq_ 1 $count); do
+ echo false > $i.t
+ echo dummy $i > $i.log
+ echo :global-test-result: PASS > $i.trs
+ echo :test-result: PASS >> $i.trs
+ echo :copy-in-global-log: yes >> $i.trs
+ echo TESTS += $i.t
+done >> Makefile.am
+
+# Re-enable shell traces.
+set -x
+
+head -n 100 Makefile.am || : # For debugging.
+tail -n 100 Makefile.am || : # Likewise.
+cat $count.trs # Likewise, just the last specimen though.
+
+# So that we don't need to create a ton of dummy tests.
+#echo '$(TESTS):' >> Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE test-suite.log >stdout || { cat stdout; exit 1; }
+cat stdout
+
+# Sanity checks.
+grep "^# TOTAL: $count$" stdout
+grep "^dummy $count$" test-suite.log
+specimen=347 # Could be any number <= $count.
+grep "^dummy $specimen$" test-suite.log
+
+:
diff --git a/t/phony.sh b/t/phony.sh
new file mode 100644
index 000000000..d6eeba829
--- /dev/null
+++ b/t/phony.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure .PHONY can be given dependencies several times.
+# From Ralf Corsepius.
+
+. test-init.sh
+
+cat >Makefile.am << 'EOF'
+.PHONY: foo
+.PHONY: bar
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+$FGREP '.PHONY:' Makefile.in # For debugging.
+test $($FGREP -c '.PHONY:' Makefile.in) -eq 3
+
+:
diff --git a/t/pkg-config-macros.sh b/t/pkg-config-macros.sh
new file mode 100644
index 000000000..e4d761fac
--- /dev/null
+++ b/t/pkg-config-macros.sh
@@ -0,0 +1,95 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Try to find the pkg-config '.m4' files and make them easily accessed
+# to the test cases requiring them.
+
+. test-init.sh
+
+echo "# Automatically generated by $me." > get.sh
+echo : >> get.sh
+
+if ver=$(pkg-config --version) && test -n "$ver"; then
+ echo "printf 'pkg-config version: %s\\n' '$ver'" >> get.sh
+else
+ echo "skip_all_ \"'pkg-config' not available\"" >> get.sh
+fi
+
+cat > configure.ac <<'END'
+AC_INIT([pkg], [1.0])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+END
+
+have_pkg_config_macros ()
+{
+ $AUTOCONF && ! $FGREP PKG_CHECK_MODULES configure
+}
+
+if have_pkg_config_macros; then
+ # The pkg-config macros are already available, nothing to do.
+ exit 0
+fi
+
+# Usual locations where pkg.m4 *might* be installed.
+XT_ACLOCAL_PATH=/usr/local/share/aclocal:/usr/share/aclocal
+
+# Find the location of the pkg-config executable.
+oIFS=$IFS dir=
+IFS=:
+for d in $PATH; do
+ IFS=$oIFS
+ if test -f $d/pkg-config || test -f $d/pkg-config.exe; then
+ dir=$d
+ break
+ fi
+done
+IFS=$oIFS
+
+# Now try to use the location of the pkg-config executable to guess
+# where the corresponding pkg.m4 might be installed.
+if test -n "$dir"; then
+ # Only support standard installation layouts.
+ XT_ACLOCAL_PATH=${dir%/bin}/share/aclocal:$XT_ACLOCAL_PATH
+fi
+
+XT_ACLOCAL_PATH=$XT_ACLOCAL_PATH${ACLOCAL_PATH+":$ACLOCAL_PATH"}
+
+# Try once again to fetch the pkg-config macros.
+mkdir m4
+ACLOCAL_PATH=$XT_ACLOCAL_PATH $ACLOCAL -Wno-syntax --install -I m4
+if test -f m4/pkg.m4 && have_pkg_config_macros; then
+ echo "ACLOCAL_PATH='$(pwd)/m4':\$ACLOCAL_PATH" >> get.sh
+ echo "export ACLOCAL_PATH" >> get.sh
+ echo "sed 20q '$(pwd)/m4/pkg.m4' # For debugging." >> get.sh
+else
+ echo "skip_all_ \"pkg-config m4 macros not found\"" >> get.sh
+fi
+
+unset ACLOCAL_PATH
+. ./get.sh
+
+$ACLOCAL --force -I m4 || cat >> get.sh <<'END'
+# We need to use '-Wno-syntax', since we do not want our test suite
+# to fail merely because some third-party '.m4' file is underquoted.
+ACLOCAL="$ACLOCAL -Wno-syntax"
+END
+
+# The pkg-config m4 file(s) we might fetched will be copied in the
+# 'm4' subdirectory of the test directory are going to be needed by
+# other tests, so we must not remove the test directory.
+keep_testdirs=yes
+
+:
diff --git a/t/pluseq.sh b/t/pluseq.sh
new file mode 100644
index 000000000..f769305dc
--- /dev/null
+++ b/t/pluseq.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test '+=' functionality.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+data_DATA = zar
+data_DATA += doz
+END
+
+$ACLOCAL
+$AUTOMAKE
+$FGREP 'zar doz' Makefile.in
+
+:
diff --git a/t/pluseq10.sh b/t/pluseq10.sh
new file mode 100644
index 000000000..9af0591e5
--- /dev/null
+++ b/t/pluseq10.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for += and backslashes.
+# Reported by Ralf Corsepius.
+
+. test-init.sh
+
+cat >>configure.ac << 'END'
+AM_CONDITIONAL([A], [true])
+AM_CONDITIONAL([B], [false])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+foo = 0.h
+if A
+foo += a0.h \
+ a1.h
+foo += a2.h \
+ a3.h
+endif
+if B
+foo += b0.h \
+ b1.h
+endif
+
+test:
+ is $(foo) == 0.h a0.h a1.h a2.h a3.h
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+:
diff --git a/t/pluseq11.sh b/t/pluseq11.sh
new file mode 100644
index 000000000..f65c5bf50
--- /dev/null
+++ b/t/pluseq11.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for bug in variable concatenation with '+=': an extra backslash
+# is erroneously retained in the final value.
+# See also sister test 'pluseq11b.sh'.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+## Use more line continuation to ensure we are robust and can (hopefully)
+## cope any number of them, and not just one
+FOO = \
+\
+\
+bar
+## Both these two variable additions are required to trigger the bug.
+FOO +=
+FOO += baz
+
+.PHONY: test
+test:
+ case '$(FOO)' in *\\*) exit 1;; *) exit 0;; esac
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^ *FOO *=.*\\.' Makefile.in && exit 1
+
+$AUTOCONF
+./configure
+$MAKE test
+
+:
diff --git a/t/pluseq2.sh b/t/pluseq2.sh
new file mode 100644
index 000000000..b4f850d0a
--- /dev/null
+++ b/t/pluseq2.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test '+=' with conditionals.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([CHECK], [true])
+END
+
+cat > Makefile.am << 'END'
+
+if CHECK
+data_DATA = zar
+else
+data_DATA =
+endif
+
+if CHECK
+data_DATA += doz
+else
+data_DATA += dog
+endif
+
+END
+
+$ACLOCAL
+$AUTOMAKE
+grep 'CHECK_TRUE.*zar doz' Makefile.in
+grep 'CHECK_FALSE.*dog' Makefile.in
+
+:
diff --git a/t/pluseq3.sh b/t/pluseq3.sh
new file mode 100644
index 000000000..7c8a8816c
--- /dev/null
+++ b/t/pluseq3.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another '+=' test with conditionals.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([CHECK], [true])
+END
+
+cat > Makefile.am << 'END'
+
+if CHECK
+data_DATA = zarrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
+else
+data_DATA =
+endif
+
+if CHECK
+data_DATA += \
+ doz
+else
+data_DATA += dog
+endif
+
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^@CHECK_TRUE@data_DATA = zarrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \\$' Makefile.in
+grep "^@CHECK_TRUE@${tab}doz$" Makefile.in
+
+grep '^@CHECK_FALSE@data_DATA = dog$' Makefile.in
+
+:
diff --git a/t/pluseq4.sh b/t/pluseq4.sh
new file mode 100644
index 000000000..df1294518
--- /dev/null
+++ b/t/pluseq4.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Yet another '+=' test.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+CC += -Dwhatever
+END
+
+$ACLOCAL
+$AUTOMAKE
+$FGREP '@CC@ -Dwhatever' Makefile.in
+
+:
diff --git a/t/pluseq5.sh b/t/pluseq5.sh
new file mode 100644
index 000000000..8c4d7ceac
--- /dev/null
+++ b/t/pluseq5.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for another '+=' problem. Report from Brian Jones.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([CHECK], [true])
+END
+
+cat > Makefile.am << 'END'
+if CHECK
+INCLUDES = abc
+endif
+INCLUDES += def
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+
+# We expect the following diagnostic:
+#
+# Makefile.am:4: cannot apply '+=' because 'INCLUDES' is not defined in
+# Makefile.am:4: the following conditions:
+# Makefile.am:4: !CHECK
+# Makefile.am:4: either define 'INCLUDES' in these conditions, or use
+# Makefile.am:4: '+=' in the same conditions as the definitions.
+
+# Is !CHECK mentioned?
+grep ':.*!CHECK$' stderr
+# Is there only one missing condition?
+test $(grep -c ': ' stderr) -eq 1
+
+# By the way, Automake should suggest using AM_CPPFLAGS,
+# because INCLUDES is an obsolete name.
+grep AM_CPPFLAGS stderr
+
+# A way to suppress the obsolete warning is to use
+# -Wno-obsolete:
+echo 'AUTOMAKE_OPTIONS = -Wno-obsolete' >> Makefile.am
+AUTOMAKE_fails
+grep AM_CPPFLAGS stderr && exit 1
+# !CHECK should still be mentioned.
+grep ':.*!CHECK$' stderr
+
+:
diff --git a/t/pluseq6.sh b/t/pluseq6.sh
new file mode 100644
index 000000000..891454ab5
--- /dev/null
+++ b/t/pluseq6.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that '+=' works with standard header-vars.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([ZZZ])
+END
+
+# If you do this in a real Makefile.am, I will kill you.
+cat > Makefile.am << 'END'
+mandir += foo
+zq = zzz
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP 'mandir' Makefile.in # For debugging.
+$FGREP '@mandir@ foo' Makefile.in
+test $(grep -c '^mandir =' Makefile.in) -eq 1
+
+:
diff --git a/t/pluseq7.sh b/t/pluseq7.sh
new file mode 100644
index 000000000..c457453c7
--- /dev/null
+++ b/t/pluseq7.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that '+=' fails when required.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+END
+
+# If you do this in a real Makefile.am, I will kill you.
+cat > Makefile.am << 'END'
+lib_LIBRARIES = libq.a
+libq_a_SOURCES = q.c
+AR += qq
+END
+
+$ACLOCAL
+AUTOMAKE_fails -Wno-portability
+grep "^Makefile\.am:3:.* AR .* with '=' before .*'+='" stderr
+
+:
diff --git a/t/pluseq8.sh b/t/pluseq8.sh
new file mode 100644
index 000000000..40ceb17c3
--- /dev/null
+++ b/t/pluseq8.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another '+=' test. From Paul Berrevoets.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+VAR = \
+ one \
+ two
+VAR += three
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+sed -n -e '/^VAR =/ {
+ :loop
+ p
+ n
+ t clear
+ :clear
+ s/\\$/\\/
+ t loop
+ p
+ n
+ }' Makefile.in | grep three
+
+:
diff --git a/t/pluseq9.sh b/t/pluseq9.sh
new file mode 100644
index 000000000..b6b46a2af
--- /dev/null
+++ b/t/pluseq9.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test the += diagnostics.
+
+. test-init.sh
+
+cat >>configure.ac << 'END'
+AM_CONDITIONAL([COND1], [true])
+AM_CONDITIONAL([COND2], [true])
+AM_CONDITIONAL([COND3], [true])
+END
+
+cat > Makefile.am << 'END'
+if COND1
+ C = c
+if COND2
+ A = a
+ B = aa
+ C += cc
+else
+ A = b
+ B = bb
+endif
+ A += c
+else
+ A = d
+endif
+A += e
+
+if COND3
+ A += f
+ B = cc
+endif
+B += dd
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+
+# We expect the following diagnostic:
+#
+# Makefile.am:19: cannot apply '+=' because 'B' is not defined in
+# Makefile.am:19: the following conditions:
+# Makefile.am:19: !COND1 and !COND3
+# Makefile.am:19: either define 'B' in these conditions, or use
+# Makefile.am:19: '+=' in the same conditions as the definitions.
+#
+# It would be nice if Automake could print only COND3_FALSE and
+# COND1_FALSE (merging the last two conditions), so we'll support
+# this case in the check too.
+
+grep '[cC]annot apply.*+=' stderr
+grep ': !COND1 and !COND3$' stderr
+# Make sure there is exactly one missing condition.
+test $(grep -c ': ' stderr) -eq 1
+
+:
diff --git a/t/pm/Cond2.pl b/t/pm/Cond2.pl
new file mode 100644
index 000000000..702ed9109
--- /dev/null
+++ b/t/pm/Cond2.pl
@@ -0,0 +1,22 @@
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Catch common programming error:
+# A Condition passed as a string to 'new'.
+
+use Automake::Condition;
+
+my $cond = new Automake::Condition ('TRUE');
+new Automake::Condition ($cond);
diff --git a/t/pm/Cond3.pl b/t/pm/Cond3.pl
new file mode 100644
index 000000000..0ffe9553b
--- /dev/null
+++ b/t/pm/Cond3.pl
@@ -0,0 +1,22 @@
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Catch common programming error:
+# A Condition passed as a string to 'new'.
+
+use Automake::Condition;
+
+my $cond = new Automake::Condition ("COND1_TRUE");
+new Automake::Condition ("$cond");
diff --git a/t/pm/Condition-t.pl b/t/pm/Condition-t.pl
new file mode 100644
index 000000000..fcd971a57
--- /dev/null
+++ b/t/pm/Condition-t.pl
@@ -0,0 +1,327 @@
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+BEGIN {
+ use Config;
+ if (eval { require 5.007_002; } # for CLONE support
+ && $Config{useithreads}
+ && !$ENV{WANT_NO_THREADS})
+ {
+ require threads;
+ import threads;
+ }
+ else
+ {
+ exit 77;
+ }
+}
+use Automake::Condition qw/TRUE FALSE/;
+
+sub test_basics ()
+{
+ my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string, human]
+ [[], 1, 0, 'TRUE', '', 'TRUE'],
+ [['TRUE'], 1, 0, 'TRUE', '', 'TRUE'],
+ [['FALSE'], 0, 1, 'FALSE', '#', 'FALSE'],
+ [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@', 'A'],
+ [['A_TRUE', 'B_FALSE'],
+ 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@', 'A and !B'],
+ [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#', 'FALSE'],
+ [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#', 'FALSE']);
+
+ for (@tests)
+ {
+ my $a = new Automake::Condition @{$_->[0]};
+ return 1
+ if threads->new(sub {
+ return 1 if $_->[1] != $a->true;
+ return 1 if $_->[1] != ($a == TRUE);
+ return 1 if $_->[2] != $a->false;
+ return 1 if $_->[2] != ($a == FALSE);
+ return 1 if $_->[3] ne $a->string;
+ return 1 if $_->[4] ne $a->subst_string;
+ return 1 if $_->[5] ne $a->human;
+ })->join;
+ }
+ return 0;
+}
+
+sub test_true_when ()
+{
+ my $failed = 0;
+
+ my @tests = (# [When,
+ # [Implied-Conditions],
+ # [Not-Implied-Conditions]]
+ [['TRUE'],
+ [['TRUE']],
+ [['A_TRUE'], ['A_TRUE', 'B_FALSE'], ['FALSE']]],
+ [['A_TRUE'],
+ [['TRUE'], ['A_TRUE']],
+ [['A_TRUE', 'B_FALSE'], ['FALSE']]],
+ [['A_TRUE', 'B_FALSE'],
+ [['TRUE'], ['A_TRUE'], ['B_FALSE'], ['A_TRUE', 'B_FALSE']],
+ [['FALSE'], ['C_FALSE'], ['C_FALSE', 'A_TRUE']]]);
+
+ for my $t (@tests)
+ {
+ my $a = new Automake::Condition @{$t->[0]};
+ return 1
+ if threads->new(sub {
+ for my $u (@{$t->[1]})
+ {
+ my $b = new Automake::Condition @$u;
+ return threads->new(sub {
+ if (! $b->true_when ($a))
+ {
+ print "`" . $b->string .
+ "' not implied by `" . $a->string . "'?\n";
+ $failed = 1;
+ }
+ })->join;
+ }
+ for my $u (@{$t->[2]})
+ {
+ my $b = new Automake::Condition @$u;
+ return threads->new(sub {
+ if ($b->true_when ($a))
+ {
+ print "`" . $b->string .
+ "' implied by `" . $a->string . "'?\n";
+ $failed = 1;
+ }
+
+ return threads->new(sub {
+ return 1 if $b->true_when ($a);
+ })->join;
+ })->join;
+ }
+ })->join;
+ }
+ return $failed;
+}
+
+sub test_reduce_and ()
+{
+ my @tests = (# If no conditions are given, TRUE should be returned
+ [[], ["TRUE"]],
+ # An empty condition is TRUE
+ [[""], ["TRUE"]],
+ # A single condition should be passed through unchanged
+ [["FOO"], ["FOO"]],
+ [["FALSE"], ["FALSE"]],
+ [["TRUE"], ["TRUE"]],
+ # TRUE and false should be discarded and overwhelm
+ # the result, respectively
+ [["FOO", "TRUE"], ["FOO"]],
+ [["FOO", "FALSE"], ["FALSE"]],
+ # Repetitions should be removed
+ [["FOO", "FOO"], ["FOO"]],
+ [["TRUE", "FOO", "FOO"], ["FOO"]],
+ [["FOO", "TRUE", "FOO"], ["FOO"]],
+ [["FOO", "FOO", "TRUE"], ["FOO"]],
+ # Two different conditions should be preserved,
+ # but TRUEs should be removed
+ [["FOO", "BAR"], ["BAR,FOO"]],
+ [["TRUE", "FOO", "BAR"], ["BAR,FOO"]],
+ [["FOO", "TRUE", "BAR"], ["BAR,FOO"]],
+ [["FOO", "BAR", "TRUE"], ["BAR,FOO"]],
+ # A condition implied by another condition should be removed.
+ [["FOO BAR", "BAR"], ["FOO BAR"]],
+ [["BAR", "FOO BAR"], ["FOO BAR"]],
+ [["TRUE", "FOO BAR", "BAR"], ["FOO BAR"]],
+ [["FOO BAR", "TRUE", "BAR"], ["FOO BAR"]],
+ [["FOO BAR", "BAR", "TRUE"], ["FOO BAR"]],
+
+ [["BAR FOO", "BAR"], ["BAR FOO"]],
+ [["BAR", "BAR FOO"], ["BAR FOO"]],
+ [["TRUE", "BAR FOO", "BAR"], ["BAR FOO"]],
+ [["BAR FOO", "TRUE", "BAR"], ["BAR FOO"]],
+ [["BAR FOO", "BAR", "TRUE"], ["BAR FOO"]],
+
+ # Check that reduction happens even when there are
+ # two conditions to remove.
+ [["FOO", "FOO BAR", "BAR"], ["FOO BAR"]],
+ [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["FOO BAR", "FOO BAZ"]],
+ [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
+ ["FOO BAZ BAR"]],
+
+ # Duplicated conditionals should be removed.
+ [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
+
+ # Equivalent conditions in different forms should be
+ # reduced: which one is left is unfortunately order
+ # dependent.
+ [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
+ [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
+
+ my $failed = 0;
+ foreach (@tests)
+ {
+ my ($inref, $outref) = @$_;
+ my @inconds = map { new Automake::Condition $_ } @$inref;
+ return 1
+ if threads->new(sub {
+ my @outconds = map { (new Automake::Condition $_)->string } @$outref;
+ return threads->new(sub {
+ my @res =
+ map { $_->string } (Automake::Condition::reduce_and (@inconds));
+ return threads->new(sub {
+ my $result = join (",", sort @res);
+ my $exresult = join (",", @outconds);
+
+ if ($result ne $exresult)
+ {
+ print '"' . join(",", @$inref) . '" => "' .
+ $result . '" expected "' .
+ $exresult . '"' . "\n";
+ $failed = 1;
+ }
+ return $failed;
+ })->join;
+ })->join;
+ })->join;
+ }
+ return $failed;
+}
+
+sub test_reduce_or ()
+{
+ my @tests = (# If no conditions are given, FALSE should be returned
+ [[], ["FALSE"]],
+ # An empty condition is TRUE
+ [[""], ["TRUE"]],
+ # A single condition should be passed through unchanged
+ [["FOO"], ["FOO"]],
+ [["FALSE"], ["FALSE"]],
+ [["TRUE"], ["TRUE"]],
+ # FALSE and TRUE should be discarded and overwhelm
+ # the result, respectively
+ [["FOO", "TRUE"], ["TRUE"]],
+ [["FOO", "FALSE"], ["FOO"]],
+ # Repetitions should be removed
+ [["FOO", "FOO"], ["FOO"]],
+ [["FALSE", "FOO", "FOO"], ["FOO"]],
+ [["FOO", "FALSE", "FOO"], ["FOO"]],
+ [["FOO", "FOO", "FALSE"], ["FOO"]],
+ # Two different conditions should be preserved,
+ # but FALSEs should be removed
+ [["FOO", "BAR"], ["BAR,FOO"]],
+ [["FALSE", "FOO", "BAR"], ["BAR,FOO"]],
+ [["FOO", "FALSE", "BAR"], ["BAR,FOO"]],
+ [["FOO", "BAR", "FALSE"], ["BAR,FOO"]],
+ # A condition implying another condition should be removed.
+ [["FOO BAR", "BAR"], ["BAR"]],
+ [["BAR", "FOO BAR"], ["BAR"]],
+ [["FALSE", "FOO BAR", "BAR"], ["BAR"]],
+ [["FOO BAR", "FALSE", "BAR"], ["BAR"]],
+ [["FOO BAR", "BAR", "FALSE"], ["BAR"]],
+
+ [["BAR FOO", "BAR"], ["BAR"]],
+ [["BAR", "BAR FOO"], ["BAR"]],
+ [["FALSE", "BAR FOO", "BAR"], ["BAR"]],
+ [["BAR FOO", "FALSE", "BAR"], ["BAR"]],
+ [["BAR FOO", "BAR", "FALSE"], ["BAR"]],
+
+ # Check that reduction happens even when there are
+ # two conditions to remove.
+ [["FOO", "FOO BAR", "BAR"], ["BAR,FOO"]],
+ [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["BAZ,FOO"]],
+ [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
+ ["BAZ,FOO"]],
+
+ # Duplicated conditionals should be removed.
+ [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
+
+ # Equivalent conditions in different forms should be
+ # reduced: which one is left is unfortunately order
+ # dependent.
+ [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
+ [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
+
+ my $failed = 0;
+ foreach (@tests)
+ {
+ my ($inref, $outref) = @$_;
+ my @inconds = map { new Automake::Condition $_ } @$inref;
+ return 1
+ if threads->new(sub {
+ my @outconds = map { (new Automake::Condition $_)->string } @$outref;
+ return threads->new(sub {
+ my @res =
+ map { $_->string } (Automake::Condition::reduce_or (@inconds));
+ return threads->new(sub {
+ my $result = join (",", sort @res);
+ my $exresult = join (",", @outconds);
+
+ if ($result ne $exresult)
+ {
+ print '"' . join(",", @$inref) . '" => "' .
+ $result . '" expected "' .
+ $exresult . '"' . "\n";
+ $failed = 1;
+ }
+ return $failed;
+ })->join;
+ })->join;
+ })->join;
+ }
+ return $failed;
+}
+
+sub test_merge ()
+{
+ my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE";
+ return threads->new(sub {
+ my $other = new Automake::Condition "COND3_FALSE";
+ return threads->new(sub {
+ my $both = $cond->merge ($other);
+ return threads->new(sub {
+ my $both2 = $cond->merge_conds ("COND3_FALSE");
+ return threads->new(sub {
+ $cond = $both->strip ($other);
+ my @conds = $cond->conds;
+ return 1 if $both->string ne "COND1_TRUE COND2_FALSE COND3_FALSE";
+ return 1 if $cond->string ne "COND1_TRUE COND2_FALSE";
+ return 1 if $both != $both2;
+ })->join;
+ })->join;
+ })->join;
+ })->join;
+ return 0;
+}
+
+exit (test_basics
+ || test_true_when
+ || test_reduce_and
+ || test_reduce_or
+ || test_merge);
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
diff --git a/t/pm/Condition.pl b/t/pm/Condition.pl
new file mode 100644
index 000000000..8ebb7c7e2
--- /dev/null
+++ b/t/pm/Condition.pl
@@ -0,0 +1,277 @@
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use Automake::Condition qw/TRUE FALSE/;
+
+sub test_basics ()
+{
+ my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string, human]
+ [[], 1, 0, 'TRUE', '', 'TRUE'],
+ [['TRUE'], 1, 0, 'TRUE', '', 'TRUE'],
+ [['FALSE'], 0, 1, 'FALSE', '#', 'FALSE'],
+ [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@', 'A'],
+ [['A_TRUE', 'B_FALSE'],
+ 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@', 'A and !B'],
+ [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#', 'FALSE'],
+ [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#', 'FALSE']);
+
+ for (@tests)
+ {
+ my $a = new Automake::Condition @{$_->[0]};
+ return 1 if $_->[1] != $a->true;
+ return 1 if $_->[1] != ($a == TRUE);
+ return 1 if $_->[2] != $a->false;
+ return 1 if $_->[2] != ($a == FALSE);
+ return 1 if $_->[3] ne $a->string;
+ return 1 if $_->[4] ne $a->subst_string;
+ return 1 if $_->[5] ne $a->human;
+ }
+ return 0;
+}
+
+sub test_true_when ()
+{
+ my $failed = 0;
+
+ my @tests = (# [When,
+ # [Implied-Conditions],
+ # [Not-Implied-Conditions]]
+ [['TRUE'],
+ [['TRUE']],
+ [['A_TRUE'], ['A_TRUE', 'B_FALSE'], ['FALSE']]],
+ [['A_TRUE'],
+ [['TRUE'], ['A_TRUE']],
+ [['A_TRUE', 'B_FALSE'], ['FALSE']]],
+ [['A_TRUE', 'B_FALSE'],
+ [['TRUE'], ['A_TRUE'], ['B_FALSE'], ['A_TRUE', 'B_FALSE']],
+ [['FALSE'], ['C_FALSE'], ['C_FALSE', 'A_TRUE']]]);
+
+ for my $t (@tests)
+ {
+ my $a = new Automake::Condition @{$t->[0]};
+ for my $u (@{$t->[1]})
+ {
+ my $b = new Automake::Condition @$u;
+ if (! $b->true_when ($a))
+ {
+ print "`" . $b->string .
+ "' not implied by `" . $a->string . "'?\n";
+ $failed = 1;
+ }
+ }
+ for my $u (@{$t->[2]})
+ {
+ my $b = new Automake::Condition @$u;
+ if ($b->true_when ($a))
+ {
+ print "`" . $b->string .
+ "' implied by `" . $a->string . "'?\n";
+ $failed = 1;
+ }
+
+ return 1 if $b->true_when ($a);
+ }
+ }
+ return $failed;
+}
+
+sub test_reduce_and ()
+{
+ my @tests = (# If no conditions are given, TRUE should be returned
+ [[], ["TRUE"]],
+ # An empty condition is TRUE
+ [[""], ["TRUE"]],
+ # A single condition should be passed through unchanged
+ [["FOO"], ["FOO"]],
+ [["FALSE"], ["FALSE"]],
+ [["TRUE"], ["TRUE"]],
+ # TRUE and false should be discarded and overwhelm
+ # the result, respectively
+ [["FOO", "TRUE"], ["FOO"]],
+ [["FOO", "FALSE"], ["FALSE"]],
+ # Repetitions should be removed
+ [["FOO", "FOO"], ["FOO"]],
+ [["TRUE", "FOO", "FOO"], ["FOO"]],
+ [["FOO", "TRUE", "FOO"], ["FOO"]],
+ [["FOO", "FOO", "TRUE"], ["FOO"]],
+ # Two different conditions should be preserved,
+ # but TRUEs should be removed
+ [["FOO", "BAR"], ["BAR,FOO"]],
+ [["TRUE", "FOO", "BAR"], ["BAR,FOO"]],
+ [["FOO", "TRUE", "BAR"], ["BAR,FOO"]],
+ [["FOO", "BAR", "TRUE"], ["BAR,FOO"]],
+ # A condition implied by another condition should be removed.
+ [["FOO BAR", "BAR"], ["FOO BAR"]],
+ [["BAR", "FOO BAR"], ["FOO BAR"]],
+ [["TRUE", "FOO BAR", "BAR"], ["FOO BAR"]],
+ [["FOO BAR", "TRUE", "BAR"], ["FOO BAR"]],
+ [["FOO BAR", "BAR", "TRUE"], ["FOO BAR"]],
+
+ [["BAR FOO", "BAR"], ["BAR FOO"]],
+ [["BAR", "BAR FOO"], ["BAR FOO"]],
+ [["TRUE", "BAR FOO", "BAR"], ["BAR FOO"]],
+ [["BAR FOO", "TRUE", "BAR"], ["BAR FOO"]],
+ [["BAR FOO", "BAR", "TRUE"], ["BAR FOO"]],
+
+ # Check that reduction happens even when there are
+ # two conditions to remove.
+ [["FOO", "FOO BAR", "BAR"], ["FOO BAR"]],
+ [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["FOO BAR", "FOO BAZ"]],
+ [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
+ ["FOO BAZ BAR"]],
+
+ # Duplicated conditionals should be removed.
+ [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
+
+ # Equivalent conditions in different forms should be
+ # reduced: which one is left is unfortunately order
+ # dependent.
+ [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
+ [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
+
+ my $failed = 0;
+ foreach (@tests)
+ {
+ my ($inref, $outref) = @$_;
+ my @inconds = map { new Automake::Condition $_ } @$inref;
+ my @outconds = map { (new Automake::Condition $_)->string } @$outref;
+ my @res =
+ map { $_->string } (Automake::Condition::reduce_and (@inconds));
+ my $result = join (",", sort @res);
+ my $exresult = join (",", @outconds);
+
+ if ($result ne $exresult)
+ {
+ print '"' . join(",", @$inref) . '" => "' .
+ $result . '" expected "' .
+ $exresult . '"' . "\n";
+ $failed = 1;
+ }
+ }
+ return $failed;
+}
+
+sub test_reduce_or ()
+{
+ my @tests = (# If no conditions are given, FALSE should be returned
+ [[], ["FALSE"]],
+ # An empty condition is TRUE
+ [[""], ["TRUE"]],
+ # A single condition should be passed through unchanged
+ [["FOO"], ["FOO"]],
+ [["FALSE"], ["FALSE"]],
+ [["TRUE"], ["TRUE"]],
+ # FALSE and TRUE should be discarded and overwhelm
+ # the result, respectively
+ [["FOO", "TRUE"], ["TRUE"]],
+ [["FOO", "FALSE"], ["FOO"]],
+ # Repetitions should be removed
+ [["FOO", "FOO"], ["FOO"]],
+ [["FALSE", "FOO", "FOO"], ["FOO"]],
+ [["FOO", "FALSE", "FOO"], ["FOO"]],
+ [["FOO", "FOO", "FALSE"], ["FOO"]],
+ # Two different conditions should be preserved,
+ # but FALSEs should be removed
+ [["FOO", "BAR"], ["BAR,FOO"]],
+ [["FALSE", "FOO", "BAR"], ["BAR,FOO"]],
+ [["FOO", "FALSE", "BAR"], ["BAR,FOO"]],
+ [["FOO", "BAR", "FALSE"], ["BAR,FOO"]],
+ # A condition implying another condition should be removed.
+ [["FOO BAR", "BAR"], ["BAR"]],
+ [["BAR", "FOO BAR"], ["BAR"]],
+ [["FALSE", "FOO BAR", "BAR"], ["BAR"]],
+ [["FOO BAR", "FALSE", "BAR"], ["BAR"]],
+ [["FOO BAR", "BAR", "FALSE"], ["BAR"]],
+
+ [["BAR FOO", "BAR"], ["BAR"]],
+ [["BAR", "BAR FOO"], ["BAR"]],
+ [["FALSE", "BAR FOO", "BAR"], ["BAR"]],
+ [["BAR FOO", "FALSE", "BAR"], ["BAR"]],
+ [["BAR FOO", "BAR", "FALSE"], ["BAR"]],
+
+ # Check that reduction happens even when there are
+ # two conditions to remove.
+ [["FOO", "FOO BAR", "BAR"], ["BAR,FOO"]],
+ [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["BAZ,FOO"]],
+ [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
+ ["BAZ,FOO"]],
+
+ # Duplicated conditionals should be removed.
+ [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
+
+ # Equivalent conditions in different forms should be
+ # reduced: which one is left is unfortunately order
+ # dependent.
+ [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
+ [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
+
+ my $failed = 0;
+ foreach (@tests)
+ {
+ my ($inref, $outref) = @$_;
+ my @inconds = map { new Automake::Condition $_ } @$inref;
+ my @outconds = map { (new Automake::Condition $_)->string } @$outref;
+ my @res =
+ map { $_->string } (Automake::Condition::reduce_or (@inconds));
+ my $result = join (",", sort @res);
+ my $exresult = join (",", @outconds);
+
+ if ($result ne $exresult)
+ {
+ print '"' . join(",", @$inref) . '" => "' .
+ $result . '" expected "' .
+ $exresult . '"' . "\n";
+ $failed = 1;
+ }
+ }
+ return $failed;
+}
+
+sub test_merge ()
+{
+ my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE";
+ my $other = new Automake::Condition "COND3_FALSE";
+ my $both = $cond->merge ($other);
+ my $both2 = $cond->merge_conds ("COND3_FALSE");
+ $cond = $both->strip ($other);
+ my @conds = $cond->conds;
+ return 1 if $both->string ne "COND1_TRUE COND2_FALSE COND3_FALSE";
+ return 1 if $cond->string ne "COND1_TRUE COND2_FALSE";
+ return 1 if $both != $both2;
+ return 0;
+}
+
+exit (test_basics
+ || test_true_when
+ || test_reduce_and
+ || test_reduce_or
+ || test_merge);
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
diff --git a/t/pm/DisjCon2.pl b/t/pm/DisjCon2.pl
new file mode 100644
index 000000000..26619a2a2
--- /dev/null
+++ b/t/pm/DisjCon2.pl
@@ -0,0 +1,24 @@
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Catch common programming error:
+# A non-Condition reference passed to new.
+
+use Automake::Condition;
+use Automake::DisjConditions;
+
+my $cond = new Automake::Condition ('TRUE');
+my $cond2 = new Automake::DisjConditions ($cond);
+new Automake::DisjConditions ($cond2);
diff --git a/t/pm/DisjCon3.pl b/t/pm/DisjCon3.pl
new file mode 100644
index 000000000..82abb7423
--- /dev/null
+++ b/t/pm/DisjCon3.pl
@@ -0,0 +1,23 @@
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Catch common programming error:
+# A non-reference passed to new.
+
+use Automake::Condition qw/TRUE FALSE/;
+use Automake::DisjConditions;
+
+my $cond = new Automake::Condition ("COND1_TRUE");
+new Automake::DisjConditions ("$cond");
diff --git a/t/pm/DisjConditions-t.pl b/t/pm/DisjConditions-t.pl
new file mode 100644
index 000000000..adcc4201f
--- /dev/null
+++ b/t/pm/DisjConditions-t.pl
@@ -0,0 +1,461 @@
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+BEGIN {
+ use Config;
+ if (eval { require 5.007_002; } # for CLONE support
+ && $Config{useithreads}
+ && !$ENV{WANT_NO_THREADS})
+ {
+ require threads;
+ import threads;
+ }
+ else
+ {
+ exit 77;
+ }
+}
+use Automake::Condition qw/TRUE FALSE/;
+use Automake::DisjConditions;
+
+sub test_basics ()
+{
+ my $true = new Automake::DisjConditions TRUE;
+ my $false = new Automake::DisjConditions FALSE;
+ my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE";
+ return threads->new (sub {
+ my $other = new Automake::Condition "COND3_FALSE";
+ my $another = new Automake::Condition "COND3_TRUE", "COND4_FALSE";
+ return threads->new (sub {
+ my $set1 = new Automake::DisjConditions $cond, $other;
+ return threads->new (sub {
+ my $set2 = new Automake::DisjConditions $other, $cond;
+ my $set3 = new Automake::DisjConditions FALSE, $another;
+ return 1 unless $set1 == $set2;
+ return 1 if $set1->false;
+ return 1 if $set1->true;
+ return 1 unless (new Automake::DisjConditions)->false;
+ return 1 if (new Automake::DisjConditions)->true;
+ return 1 unless $true->human eq 'TRUE';
+ return 1 unless $false->human eq 'FALSE';
+ return 1 unless $set1->human eq "(COND1 and !COND2) or (!COND3)";
+ return 1 unless $set2->human eq "(COND1 and !COND2) or (!COND3)";
+ my $one_cond_human = $set1->one_cond->human;
+ return 1 unless $one_cond_human eq "!COND3"
+ || $one_cond_human eq "COND1 and !COND2";
+ return 1 unless $set1->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
+
+ my $merged1 = $set1->merge ($set2);
+ my $merged2 = $set1->merge ($cond);
+ my $mult1 = $set1->multiply ($set3);
+ return threads->new (sub {
+ my $mult2 = $set1->multiply ($another);
+ return threads->new (sub {
+ return 1 unless $merged1->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
+ return 1 unless $merged2->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
+ return 1 unless $mult1->string eq "COND1_TRUE COND2_FALSE COND3_TRUE COND4_FALSE";
+ return 1 unless $mult1 == $mult2;
+ return 0;
+ })->join;
+ })->join;
+ })->join;
+ })->join;
+ })->join;
+}
+
+sub build_set (@)
+{
+ my @conds = @_;
+ my @set = ();
+ for my $cond (@conds)
+ {
+ push @set, new Automake::Condition @$cond;
+ }
+ return new Automake::DisjConditions @set;
+}
+
+sub test_invert ()
+{
+ my @tests = ([[["FALSE"]],
+ [["TRUE"]]],
+
+ [[["TRUE"]],
+ [["FALSE"]]],
+
+ [[["COND1_TRUE", "COND2_TRUE"],
+ ["COND3_FALSE", "COND2_TRUE"]],
+ [["COND2_FALSE"],
+ ["COND1_FALSE", "COND3_TRUE"]]],
+
+ [[["COND1_TRUE", "COND2_TRUE"],
+ ["TRUE"]],
+ [["FALSE"]]],
+
+ [[["COND1_TRUE", "COND2_TRUE"],
+ ["FALSE"]],
+ [["COND1_FALSE"],
+ ["COND2_FALSE"]]],
+
+ [[["COND1_TRUE"],
+ ["COND2_FALSE"]],
+ [["COND1_FALSE", "COND2_TRUE"]]]
+ );
+
+ for my $t (@tests)
+ {
+ my $set = build_set @{$t->[0]};
+ return 1
+ if threads->new(sub {
+ my $res = build_set @{$t->[1]};
+ my $inv = $set->invert;
+ if ($inv != $res)
+ {
+ print " (I) " . $set->string . "\n\t"
+ . $inv->string . ' != ' . $res->string . "\n";
+ return 1;
+ }
+ return 0
+ })-> join;
+ }
+ return 0;
+}
+
+sub test_simplify ()
+{
+ my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"]],
+ [["FOO_TRUE", "BAR_FALSE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_TRUE", "BAR_TRUE"]],
+ [["FOO_TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_TRUE", "BAR_TRUE"],
+ ["FOO_FALSE"]],
+ [["TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["BAR_TRUE", "BAZ_TRUE"],
+ ["BAR_FALSE", "BAZ_TRUE"]],
+ [["BAZ_TRUE"], ["FOO_TRUE", "BAR_FALSE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["BAR_TRUE", "BAZ_TRUE"],
+ ["BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
+
+ [[["B_TRUE"],
+ ["A_FALSE", "B_TRUE"]],
+ [["B_TRUE"]]],
+
+ [[["B_TRUE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE"],
+ ["A_FALSE", "B_FALSE", "C_FALSE"]],
+ [["A_FALSE"], ["B_TRUE"]]],
+
+ [[["B_TRUE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE"],
+ ["A_FALSE", "B_FALSE", "C_FALSE"],
+ ["A_TRUE", "B_FALSE"]],
+ [["TRUE"]]],
+
+ [[["A_TRUE", "B_TRUE"],
+ ["A_TRUE", "B_FALSE"],
+ ["A_TRUE", "C_FALSE", "D_FALSE"]],
+ [["A_TRUE"]]],
+
+ [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"]],
+ [ ["B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"]]],
+
+ [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_FALSE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"]],
+ [["C_FALSE", "E_FALSE"],
+ ["C_TRUE", "E_TRUE"]]],
+
+ [[["A_FALSE"],
+ ["A_TRUE", "B_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE", "F_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"]],
+ [["TRUE"]]],
+
+ # Simplify should work with up to 31 variables.
+ [[["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
+ "V31_TRUE"],
+ ["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
+ "V31_FALSE"],
+ ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
+ "V31_TRUE"],
+ ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
+ "V31_FALSE"]],
+ [[ "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE"
+ ]]]);
+
+ for my $t (@tests)
+ {
+ my $set = build_set @{$t->[0]};
+ return 1
+ if threads->new(sub {
+ my $res = build_set @{$t->[1]};
+ return threads->new(sub {
+
+ # Make sure simplify() yields the expected result.
+ my $sim = $set->simplify;
+ return threads->new(sub {
+ if ($sim != $res)
+ {
+ print " (S1) " . $set->string . "\n\t"
+ . $sim->string . ' != ' . $res->string . "\n";
+ return 1;
+ }
+
+ # Make sure simplify() is idempotent.
+ my $sim2 = $sim->simplify;
+ return threads->new(sub {
+ if ($sim2 != $sim)
+ {
+ print " (S2) " . $sim->string . "\n\t"
+ . $sim2->string . ' != ' . $sim->string . "\n";
+ return 1;
+ }
+
+ # Also exercise invert() while we are at it.
+
+ my $inv1 = $set->invert->simplify;
+ return threads->new(sub {
+ my $inv2 = $sim->invert->simplify;
+ return threads->new(sub {
+ if ($inv1 != $inv2)
+ {
+ print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
+ . $inv1->string . ' -= ' . $inv2->string . "\n";
+ return 1;
+ }
+ })->join;
+ })->join;
+ })->join;
+ })->join;
+ })->join;
+ })->join;
+ }
+
+ return 0;
+}
+
+sub test_sub_conditions ()
+{
+ my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ ["FOO_TRUE"],
+ [["BAR_FALSE", "BAZ_FALSE"],
+ ["BAR_FALSE", "BAZ_TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ ["FOO_TRUE", "BAR_FALSE"],
+ [["BAZ_FALSE"],
+ ["BAZ_TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ ["FOO_TRUE", "BAR_TRUE"],
+ [["FALSE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ ["FOO_TRUE", "BAR_TRUE"],
+ [["BAZ_TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE"],
+ ["FOO_TRUE", "BAR_TRUE"]],
+ ["FOO_TRUE", "BAR_TRUE"],
+ [["TRUE"]]],
+
+ [[["TRUE"]],
+ ["TRUE"],
+ [["TRUE"]]],
+
+ [[["FALSE"]],
+ ["TRUE"],
+ [["FALSE"]]],
+
+ [[["FALSE"]],
+ ["FALSE"],
+ [["FALSE"]]]);
+
+ for my $t (@tests)
+ {
+ my $t1 = build_set @{$t->[0]};
+ return 1
+ if threads->new(sub {
+ my $t2 = new Automake::Condition @{$t->[1]};
+ return threads->new(sub {
+ my $t3 = build_set @{$t->[2]};
+ return threads->new(sub {
+
+ # Make sure sub_conditions() yields the expected result.
+ my $s = $t1->sub_conditions ($t2);
+ threads->new(sub {
+ if ($s != $t3)
+ {
+ print " (SC) " . $t1->string . "\n\t"
+ . $s->string . ' != ' . $t3->string . "\n";
+ return 1;
+ }
+ })->join;
+ })->join;
+ })->join;
+ })->join;
+ }
+}
+
+sub test_ambig ()
+{
+ my @tests = ([[["TRUE"]],
+ ["TRUE"],
+ "multiply defined"],
+ [[["C1_TRUE"]],
+ ["C1_TRUE"],
+ "multiply defined"],
+ [[["TRUE"]],
+ ["C1_FALSE"],
+ "which includes"],
+ [[["C1_TRUE"]],
+ ["C1_TRUE", "C2_TRUE"],
+ "which includes"],
+ [[["C1_TRUE", "C2_TRUE"]],
+ ["C2_TRUE"],
+ "which is included in"],
+ [[["C1_TRUE"]],
+ ["C2_TRUE"],
+ ''],
+ [[["C1_TRUE"],
+ ["C2_FALSE"]],
+ ["C1_FALSE", "C2_TRUE"],
+ '']);
+
+ my $failed = 0;
+ for my $t (@tests)
+ {
+ my $t1 = build_set @{$t->[0]};
+ $failed = 1
+ if threads->new(sub {
+ my $t2 = new Automake::Condition @{$t->[1]};
+ my $t3 = $t->[2];
+ return threads->new(sub {
+ my ($ans, $cond) = $t1->ambiguous_p ("FOO", $t2);
+ return threads->new(sub {
+ if ($t3 && $ans !~ /FOO.*$t3/)
+ {
+ print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t"
+ . "Error message '$ans' does not match '$t3'\n";
+ return 1;
+ }
+ if (!$t3 && $ans ne '')
+ {
+ print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
+ . "Unexpected error message: $ans\n";
+ return 1;
+ }
+ })->join;
+ })->join;
+ })->join;
+ }
+ return $failed;
+}
+
+exit (test_basics
+ || test_invert
+ || test_simplify
+ || test_sub_conditions
+ || test_ambig);
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
diff --git a/t/pm/DisjConditions.pl b/t/pm/DisjConditions.pl
new file mode 100644
index 000000000..07952f43f
--- /dev/null
+++ b/t/pm/DisjConditions.pl
@@ -0,0 +1,404 @@
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use Automake::Condition qw/TRUE FALSE/;
+use Automake::DisjConditions;
+
+sub test_basics ()
+{
+ my $true = new Automake::DisjConditions TRUE;
+ my $false = new Automake::DisjConditions FALSE;
+ my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE";
+ my $other = new Automake::Condition "COND3_FALSE";
+ my $another = new Automake::Condition "COND3_TRUE", "COND4_FALSE";
+ my $set1 = new Automake::DisjConditions $cond, $other;
+ my $set2 = new Automake::DisjConditions $other, $cond;
+ my $set3 = new Automake::DisjConditions FALSE, $another;
+ return 1 unless $set1 == $set2;
+ return 1 if $set1->false;
+ return 1 if $set1->true;
+ return 1 unless (new Automake::DisjConditions)->false;
+ return 1 if (new Automake::DisjConditions)->true;
+ return 1 unless $true->human eq 'TRUE';
+ return 1 unless $false->human eq 'FALSE';
+ return 1 unless $set1->human eq "(COND1 and !COND2) or (!COND3)";
+ return 1 unless $set2->human eq "(COND1 and !COND2) or (!COND3)";
+ my $one_cond_human = $set1->one_cond->human;
+ return 1 unless $one_cond_human eq "!COND3"
+ || $one_cond_human eq "COND1 and !COND2";
+ return 1 unless $set1->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
+
+ my $merged1 = $set1->merge ($set2);
+ my $merged2 = $set1->merge ($cond);
+ my $mult1 = $set1->multiply ($set3);
+ my $mult2 = $set1->multiply ($another);
+ return 1 unless $merged1->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
+ return 1 unless $merged2->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
+ return 1 unless $mult1->string eq "COND1_TRUE COND2_FALSE COND3_TRUE COND4_FALSE";
+ return 1 unless $mult1 == $mult2;
+
+ return 0;
+}
+
+sub build_set (@)
+{
+ my @conds = @_;
+ my @set = ();
+ for my $cond (@conds)
+ {
+ push @set, new Automake::Condition @$cond;
+ }
+ return new Automake::DisjConditions @set;
+}
+
+sub test_invert ()
+{
+ my @tests = ([[["FALSE"]],
+ [["TRUE"]]],
+
+ [[["TRUE"]],
+ [["FALSE"]]],
+
+ [[["COND1_TRUE", "COND2_TRUE"],
+ ["COND3_FALSE", "COND2_TRUE"]],
+ [["COND2_FALSE"],
+ ["COND1_FALSE", "COND3_TRUE"]]],
+
+ [[["COND1_TRUE", "COND2_TRUE"],
+ ["TRUE"]],
+ [["FALSE"]]],
+
+ [[["COND1_TRUE", "COND2_TRUE"],
+ ["FALSE"]],
+ [["COND1_FALSE"],
+ ["COND2_FALSE"]]],
+
+ [[["COND1_TRUE"],
+ ["COND2_FALSE"]],
+ [["COND1_FALSE", "COND2_TRUE"]]]
+ );
+
+ for my $t (@tests)
+ {
+ my $set = build_set @{$t->[0]};
+ my $res = build_set @{$t->[1]};
+ my $inv = $set->invert;
+ if ($inv != $res)
+ {
+ print " (I) " . $set->string . "\n\t"
+ . $inv->string . ' != ' . $res->string . "\n";
+ return 1;
+ }
+ }
+ return 0;
+}
+
+sub test_simplify ()
+{
+ my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"]],
+ [["FOO_TRUE", "BAR_FALSE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_TRUE", "BAR_TRUE"]],
+ [["FOO_TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_TRUE", "BAR_TRUE"],
+ ["FOO_FALSE"]],
+ [["TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["BAR_TRUE", "BAZ_TRUE"],
+ ["BAR_FALSE", "BAZ_TRUE"]],
+ [["BAZ_TRUE"], ["FOO_TRUE", "BAR_FALSE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["BAR_TRUE", "BAZ_TRUE"],
+ ["BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
+
+ [[["B_TRUE"],
+ ["A_FALSE", "B_TRUE"]],
+ [["B_TRUE"]]],
+
+ [[["B_TRUE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE"],
+ ["A_FALSE", "B_FALSE", "C_FALSE"]],
+ [["A_FALSE"], ["B_TRUE"]]],
+
+ [[["B_TRUE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE"],
+ ["A_FALSE", "B_FALSE", "C_FALSE"],
+ ["A_TRUE", "B_FALSE"]],
+ [["TRUE"]]],
+
+ [[["A_TRUE", "B_TRUE"],
+ ["A_TRUE", "B_FALSE"],
+ ["A_TRUE", "C_FALSE", "D_FALSE"]],
+ [["A_TRUE"]]],
+
+ [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"]],
+ [ ["B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"]]],
+
+ [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_FALSE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"],
+ ["A_FALSE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_FALSE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
+ ["A_TRUE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"]],
+ [["C_FALSE", "E_FALSE"],
+ ["C_TRUE", "E_TRUE"]]],
+
+ [[["A_FALSE"],
+ ["A_TRUE", "B_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE", "F_FALSE"],
+ ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"]],
+ [["TRUE"]]],
+
+ # Simplify should work with up to 31 variables.
+ [[["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
+ "V31_TRUE"],
+ ["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
+ "V31_FALSE"],
+ ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
+ "V31_TRUE"],
+ ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
+ "V31_FALSE"]],
+ [[ "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
+ "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
+ "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
+ "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
+ "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
+ "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE"
+ ]]]);
+
+ for my $t (@tests)
+ {
+ my $set = build_set @{$t->[0]};
+ my $res = build_set @{$t->[1]};
+
+ # Make sure simplify() yields the expected result.
+ my $sim = $set->simplify;
+ if ($sim != $res)
+ {
+ print " (S1) " . $set->string . "\n\t"
+ . $sim->string . ' != ' . $res->string . "\n";
+ return 1;
+ }
+
+ # Make sure simplify() is idempotent.
+ my $sim2 = $sim->simplify;
+ if ($sim2 != $sim)
+ {
+ print " (S2) " . $sim->string . "\n\t"
+ . $sim2->string . ' != ' . $sim->string . "\n";
+ return 1;
+ }
+
+ # Also exercise invert() while we are at it.
+
+ my $inv1 = $set->invert->simplify;
+ my $inv2 = $sim->invert->simplify;
+ if ($inv1 != $inv2)
+ {
+ print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
+ . $inv1->string . ' != ' . $inv2->string . "\n";
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+sub test_sub_conditions ()
+{
+ my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ ["FOO_TRUE"],
+ [["BAR_FALSE", "BAZ_FALSE"],
+ ["BAR_FALSE", "BAZ_TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ ["FOO_TRUE", "BAR_FALSE"],
+ [["BAZ_FALSE"],
+ ["BAZ_TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ ["FOO_TRUE", "BAR_TRUE"],
+ [["FALSE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
+ ["FOO_TRUE", "BAZ_TRUE"],
+ ["FOO_FALSE"]],
+ ["FOO_TRUE", "BAR_TRUE"],
+ [["BAZ_TRUE"]]],
+
+ [[["FOO_TRUE", "BAR_FALSE"],
+ ["FOO_TRUE", "BAR_TRUE"]],
+ ["FOO_TRUE", "BAR_TRUE"],
+ [["TRUE"]]],
+
+ [[["TRUE"]],
+ ["TRUE"],
+ [["TRUE"]]],
+
+ [[["FALSE"]],
+ ["TRUE"],
+ [["FALSE"]]],
+
+ [[["FALSE"]],
+ ["FALSE"],
+ [["FALSE"]]]);
+
+ for my $t (@tests)
+ {
+ my $t1 = build_set @{$t->[0]};
+ my $t2 = new Automake::Condition @{$t->[1]};
+ my $t3 = build_set @{$t->[2]};
+
+ # Make sure sub_conditions() yields the expected result.
+ my $s = $t1->sub_conditions ($t2);
+ if ($s != $t3)
+ {
+ print " (SC) " . $t1->string . "\n\t"
+ . $s->string . ' != ' . $t3->string . "\n";
+ return 1;
+ }
+ }
+}
+
+sub test_ambig ()
+{
+ my @tests = ([[["TRUE"]],
+ ["TRUE"],
+ "multiply defined"],
+ [[["C1_TRUE"]],
+ ["C1_TRUE"],
+ "multiply defined"],
+ [[["TRUE"]],
+ ["C1_FALSE"],
+ "which includes"],
+ [[["C1_TRUE"]],
+ ["C1_TRUE", "C2_TRUE"],
+ "which includes"],
+ [[["C1_TRUE", "C2_TRUE"]],
+ ["C2_TRUE"],
+ "which is included in"],
+ [[["C1_TRUE"]],
+ ["C2_TRUE"],
+ ''],
+ [[["C1_TRUE"],
+ ["C2_FALSE"]],
+ ["C1_FALSE", "C2_TRUE"],
+ '']);
+
+ for my $t (@tests)
+ {
+ my $t1 = build_set @{$t->[0]};
+ my $t2 = new Automake::Condition @{$t->[1]};
+ my $t3 = $t->[2];
+ my ($ans, $cond) = $t1->ambiguous_p ("FOO", $t2);
+ if ($t3 && $ans !~ /FOO.*$t3/)
+ {
+ print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t"
+ . "Error message '$ans' does not match '$t3'\n";
+ return 1;
+ }
+ if (!$t3 && $ans ne '')
+ {
+ print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
+ . "Unexpected error message: $ans\n";
+ return 1;
+ }
+ }
+ return 0;
+}
+
+exit (test_basics
+ || test_invert
+ || test_simplify
+ || test_sub_conditions
+ || test_ambig);
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
diff --git a/t/pm/Version.pl b/t/pm/Version.pl
new file mode 100644
index 000000000..764478a2f
--- /dev/null
+++ b/t/pm/Version.pl
@@ -0,0 +1,129 @@
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use Automake::Version;
+
+my $failed = 0;
+
+sub test_version_compare
+{
+ my ($left, $right, $result) = @_;
+ my @leftver = Automake::Version::split ($left);
+ my @rightver = Automake::Version::split ($right);
+ if ($#leftver == -1)
+ {
+ print "can't grok \"$left\"\n";
+ $failed = 1;
+ return;
+ }
+ if ($#rightver == -1)
+ {
+ print "can't grok \"$right\"\n";
+ $failed = 1;
+ return;
+ }
+ my $res = Automake::Version::compare (@leftver, @rightver);
+ if ($res != $result)
+ {
+ print "compare (\"$left\", \"$right\") = $res! (not $result?)\n";
+ $failed = 1;
+ }
+
+ my $check_expected = ($result == 0 || $result == 1) ? 0 : 1;
+ # Exception for 'foo' fork.
+ $check_expected = 1
+ if ($right =~ /foo/ && !($left =~ /foo/));
+
+ my $check = Automake::Version::check ($left, $right);
+ if ($check != $check_expected)
+ {
+ print "check (\"$left\", \"$right\") = $check! (not $check_expected?)\n";
+ $failed = 1;
+ }
+}
+
+sub test_bad_versions
+{
+ my ($ver) = @_;
+ my @version = Automake::Version::split ($ver);
+ if ($#version != -1)
+ {
+ print "shouldn't grok \"$ver\"\n";
+ $failed = 1;
+ }
+}
+
+my @tests = (
+# basics
+ ['1.0', '2.0', -1],
+ ['2.0', '1.0', 1],
+ ['1.2', '1.2', 0],
+ ['1.1', '1.2', -1],
+ ['1.2', '1.1', 1],
+# alphas
+ ['1.4', '1.4g', -1],
+ ['1.4g', '1.5', -1],
+ ['1.4g', '1.4', 1],
+ ['1.5', '1.4g', 1],
+ ['1.4a', '1.4g', -1],
+ ['1.5a', '1.3g', 1],
+ ['1.6a', '1.6a', 0],
+# micros
+ ['1.5.1', '1.5', 1],
+ ['1.5.0', '1.5', 0],
+ ['1.5.4', '1.6.1', -1],
+# micros and alphas
+ ['1.5a', '1.5.1', 1],
+ ['1.5a', '1.5.1a', 1],
+ ['1.5a', '1.5.1f', 1],
+ ['1.5', '1.5.1a', -1],
+ ['1.5.1a', '1.5.1f', -1],
+ ['1.5.1f', '1.5.1a', 1],
+ ['1.5.1f', '1.5.1f', 0],
+# special exceptions
+ ['1.6-p5a', '1.6.5a', 0],
+ ['1.6', '1.6-p5a', -1],
+ ['1.6-p4b', '1.6-p5a', -1],
+ ['1.6-p4b', '1.6-foo', 1],
+ ['1.6-p4b', '1.6a-foo', -1],
+ ['1.6-p5', '1.6.5', 0],
+ ['1.6a-foo', '1.6a-foo', 0],
+);
+
+my @bad_versions = (
+ '', 'a', '1', '1a', '1.2.3.4', '-1.2'
+);
+
+test_version_compare (@{$_}) foreach @tests;
+test_bad_versions ($_) foreach @bad_versions;
+
+exit $failed;
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
diff --git a/t/pm/Version2.pl b/t/pm/Version2.pl
new file mode 100644
index 000000000..4d9bfaa45
--- /dev/null
+++ b/t/pm/Version2.pl
@@ -0,0 +1,20 @@
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# prog_error due to invalid $VERSION.
+
+use Automake::Version;
+
+Automake::Version::check ('', '1.2.3');
diff --git a/t/pm/Version3.pl b/t/pm/Version3.pl
new file mode 100644
index 000000000..aa559b2ee
--- /dev/null
+++ b/t/pm/Version3.pl
@@ -0,0 +1,20 @@
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# prog_error due to invalid $REQUIRED.
+
+use Automake::Version;
+
+Automake::Version::check ('1.2.3', '');
diff --git a/t/pm/Wrap.pl b/t/pm/Wrap.pl
new file mode 100644
index 000000000..4da251128
--- /dev/null
+++ b/t/pm/Wrap.pl
@@ -0,0 +1,112 @@
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use Automake::Wrap qw/wrap makefile_wrap/;
+
+my $failed = 0;
+
+sub test_wrap
+{
+ my ($in, $exp_out) = @_;
+
+ my $out = &wrap (@$in);
+ if ($out ne $exp_out)
+ {
+ print STDERR "For: @$in\nGot:\n$out\nInstead of:\n$exp_out\n---\n";
+ ++$failed;
+ }
+}
+
+sub test_makefile_wrap
+{
+ my ($in, $exp_out) = @_;
+
+ my $out = &makefile_wrap (@$in);
+ if ($out ne $exp_out)
+ {
+ print STDERR "For: @$in\nGot:\n$out\nInstead of:\n$exp_out\n---\n";
+ ++$failed;
+ }
+}
+
+my @tests = (
+ [["HEAD:", "NEXT:", "CONT", 13, "v" ,"a", "l", "ue", "s", "values"],
+"HEAD:v aCONT
+NEXT:l ueCONT
+NEXT:sCONT
+NEXT:values
+"],
+ [["rule: ", "\t", " \\", 20, "dep1" ,"dep2", "dep3", "dep4", "dep5",
+ "dep06", "dep07", "dep08"],
+"rule: dep1 dep2 \\
+\tdep3 dep4 \\
+\tdep5 dep06 \\
+\tdep07 \\
+\tdep08
+"],
+ [["big header:", "big continuation:", " END", 5, "diag1", "diag2", "diag3"],
+"big header:diag1 END
+big continuation:diag2 END
+big continuation:diag3
+"],
+ [["big header:", "cont: ", " END", 16, "word1", "word2"],
+"big header: END
+cont: word1 END
+cont: word2
+"],
+ [["big header:", "", " END", 16, "w1", "w2 ", "w3"],
+"big header: END
+w1 w2 w3
+"]);
+
+my @makefile_tests = (
+ [["target:"],
+"target:
+"],
+ [["target:", "\t"],
+"target:
+"],
+ [["target:", "\t", "prereq1", "prereq2"],
+"target: prereq1 prereq2
+"],
+ [["target: ", "\t", "this is a long list of prerequisites ending in space",
+ "so that there is no need for another space before the backslash",
+ "unlike in the second line"],
+"target: this is a long list of prerequisites ending in space \\
+\tso that there is no need for another space before the backslash \\
+\tunlike in the second line
+"]);
+
+test_wrap (@{$_}) foreach @tests;
+test_makefile_wrap (@{$_}) foreach @makefile_tests;
+
+exit $failed;
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
diff --git a/t/posixsubst-data.sh b/t/posixsubst-data.sh
new file mode 100644
index 000000000..2dc46237e
--- /dev/null
+++ b/t/posixsubst-data.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that POSIX variable expansion '$(var:str=rpl)' works
+# in when used with the DATA primary.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+foodir = $(prefix)
+
+t1 = foo1 foo2
+t2 = barx
+t3 = baz.y
+
+bar.data bazzardoz:
+ : > $@
+CLEANFILES = bar.data bazzardoz
+
+# Also try an empty match suffix, to ensure that the ':=' in there is
+# not confused by the parser with an unportable assignment operator.
+dist_foo_DATA = $(t1:=.txt)
+foo_DATA = $(t2:x=.data)
+nodist_foo_DATA = $(t3:.y=zardoz)
+
+check-local: test
+.PHONY: test
+test: distdir
+ ls -l $(distdir)
+ test ! -r $(distdir)/foo.data
+ test ! -r $(distdir)/bazzardoz
+
+installcheck-local:
+ ls -l $(prefix)
+ test -f $(prefix)/foo1.txt
+ test -f $(prefix)/foo2.txt
+ test -f $(prefix)/bar.data
+ test -f $(prefix)/bazzardoz
+END
+
+: > foo1.txt
+: > foo2.txt
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+./configure --prefix="$cwd/_inst"
+$MAKE install
+test -f bar.data
+test -f bazzardoz
+$MAKE test
+$MAKE installcheck
+$MAKE distcheck
+
+:
diff --git a/t/posixsubst-extradist.sh b/t/posixsubst-extradist.sh
new file mode 100644
index 000000000..d821ebf5a
--- /dev/null
+++ b/t/posixsubst-extradist.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that POSIX variable expansion '$(var:str=rpl)' works when used
+# in EXTRA_DIST.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+t1 = foo1 foo2
+t2 = bar.x
+t3 = baz-y
+# Also try an empty match suffix, to ensure that the ':=' in there is
+# not confused by the parser with an unportable assignment operator.
+EXTRA_DIST = $(t1:=.c) $(t2:.x=.f) $(t3:-y=ar)
+bazar bar.f:
+ : > $@
+.PHONY: test
+test: distdir
+ ls -l $(distdir)
+ test -f $(distdir)/foo1.c
+ test -f $(distdir)/foo2.c
+ test -f $(distdir)/bar.f
+ test -f $(distdir)/bazar
+END
+
+: > foo1.c
+: > foo2.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+:
diff --git a/t/posixsubst-ldadd.sh b/t/posixsubst-ldadd.sh
new file mode 100644
index 000000000..555360b16
--- /dev/null
+++ b/t/posixsubst-ldadd.sh
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that POSIX variable expansion '$(var:str=rpl)' works
+# when used in LDADD.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AM_PROG_AR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+u = libquux1.lib libquux2.lib
+v = libquux1
+w = none
+
+zardozdir = $(prefix)/zardoz
+zardoz_PROGRAMS = foo bar
+
+noinst_LIBRARIES = libquux1.a libquux2.a libquux3.a
+
+# Also try an empty match suffix, to ensure that the ':=' in there is
+# not confused by the parser with an unportable assignment operator.
+LDADD = $(u:.lib=.a)
+bar_LDADD = $(v:=.a) libquux2.a $(w:none=libquux3.a)
+
+libquux1.c:
+ echo 'int quux1(void) { return 0; }' > $@
+CLEANFILES = libquux1.c # For FreeBSD make.
+END
+
+cat > foo.c <<'END'
+int main(void)
+{
+ int quux1(void), quux2(void);
+ return quux1() + quux2();
+}
+END
+
+cat > bar.c <<'END'
+int main(void)
+{
+ int quux1(void), quux2(void), quux3(void);
+ return quux1() + quux2() + quux3();
+}
+END
+
+echo 'int quux2(void) { return 0; }' > libquux2.c
+echo 'int quux3(void) { return 0; }' > libquux3.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+test -f libquux1.c
+$MAKE distcheck
+
+:
diff --git a/t/posixsubst-libraries.sh b/t/posixsubst-libraries.sh
new file mode 100644
index 000000000..b65b756d6
--- /dev/null
+++ b/t/posixsubst-libraries.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that POSIX variable expansion '$(var:str=rpl)' works when used
+# with the LIBRARIES primary in a "simple" way.
+# Keep this in sync with sister test 'posixsubst-ltlibraries.sh'.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AM_PROG_AR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+foolibs = libfoo1 libfoo2
+barlibs = libbaz
+
+# Also try an empty match suffix, to ensure that the ':=' in there is
+# not confused by the parser with an unportable assignment operator.
+lib_LIBRARIES = $(foolibs:=.a) $(barlibs:z=r.a)
+
+libbar.c:
+ echo 'int bar(void) { return 0; }' > $@
+CLEANFILES = libbar.c # For FreeBSD make.
+
+installcheck-local:
+ ls -l $(libdir)
+ test -f $(libdir)/libfoo1.a
+ test -f $(libdir)/libfoo2.a
+ test -f $(libdir)/libbar.a
+END
+
+echo 'int bar1(void) { return 0; }' > libfoo1.c
+echo 'int bar2(void) { return 0; }' > libfoo2.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+./configure --prefix="$cwd/_inst"
+$MAKE
+test -f libfoo2.c
+$MAKE install
+$MAKE installcheck
+$MAKE distcheck
+
+:
diff --git a/t/posixsubst-ltlibraries.sh b/t/posixsubst-ltlibraries.sh
new file mode 100644
index 000000000..37848114f
--- /dev/null
+++ b/t/posixsubst-ltlibraries.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that POSIX variable expansion '$(var:str=rpl)' works when used
+# with the LTLIBRARIES primary in a "simple" way.
+# Keep this in sync with sister test 'posixsubst-libraries.sh'.
+
+required='cc libtool libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+foolibs = libfoo1 libfoo2
+barlibs = libbaz
+
+# Also try an empty match suffix, to ensure that the ':=' in there is
+# not confused by the parser with an unportable assignment operator.
+lib_LTLIBRARIES = $(foolibs:=.la) $(barlibs:z=r.la)
+
+libbar.c:
+ echo 'int bar(void) { return 0; }' > $@
+CLEANFILES = libbar.c # For FreeBSD make.
+
+installcheck-local:
+ ls -l $(libdir)
+ test -f $(libdir)/libfoo1.la
+ test -f $(libdir)/libfoo2.la
+ test -f $(libdir)/libbar.la
+END
+
+echo 'int bar1(void) { return 0; }' > libfoo1.c
+echo 'int bar2(void) { return 0; }' > libfoo2.c
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+./configure --prefix="$cwd/_inst"
+$MAKE
+test -f libfoo2.c
+$MAKE install
+$MAKE installcheck
+$MAKE distcheck
+
+:
diff --git a/t/posixsubst-programs.sh b/t/posixsubst-programs.sh
new file mode 100644
index 000000000..2a41f049b
--- /dev/null
+++ b/t/posixsubst-programs.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that POSIX variable expansion '$(var:str=rpl)' works when used
+# with the PROGRAMS primary.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+t1 = foo1 foo2
+t2 = barx bar2
+
+# Also try an empty match suffix, to ensure that the ':=' in there is
+# not confused by the parser with an unportable assignment operator.
+bin_PROGRAMS = $(t1:=-p) $(t2:2=y)
+
+installcheck-local:
+ ls -l $(prefix)/bin
+ test -f $(prefix)/bin/foo1-p$(EXEEXT)
+ test -x $(prefix)/bin/foo1-p$(EXEEXT)
+ test -f $(prefix)/bin/foo2-p$(EXEEXT)
+ test -x $(prefix)/bin/foo2-p$(EXEEXT)
+ test -f $(prefix)/bin/barx$(EXEEXT)
+ test -x $(prefix)/bin/barx$(EXEEXT)
+ test -f $(prefix)/bin/bary$(EXEEXT)
+ test -x $(prefix)/bin/bary$(EXEEXT)
+END
+
+for f in foo1-p.c foo2-p.c barx.c bary.c; do
+ echo 'int main(void) { return 0; }' > $f
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+./configure --prefix="$cwd/_inst"
+$MAKE
+$MAKE install
+$MAKE installcheck
+$MAKE distcheck
+
+:
diff --git a/t/posixsubst-scripts.sh b/t/posixsubst-scripts.sh
new file mode 100644
index 000000000..e3e7257e8
--- /dev/null
+++ b/t/posixsubst-scripts.sh
@@ -0,0 +1,99 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that POSIX variable expansion '$(var:str=rpl)' works when used
+# with the SCRIPTS primary.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+# We have to be careful with 'test -x' commands on MinGW/MSYS, because
+# the file system does not actually have execute permission information.
+# Instead, that is emulated by looking at the file content, and returning
+# 0 if the file starts with, e.g., a COFF header or with '#!'.
+# So we need to create actual scripts in the make rules and in the file
+# creation below.
+
+cat > Makefile.am << 'END'
+t1 = foo1 foo2
+t2 = bar1x bar2
+t3 = quu-baz
+
+bar1 bar2:
+ (echo '#!/bin/sh' && echo 'exit 0') > $@
+quux.pl:
+ (echo '#!/bin/perl' && echo '1;') > $@
+CLEANFILES = bar1 bar2 quux.pl
+
+# Also try an empty match suffix, to ensure that the ':=' in there is
+# not confused by the parser with an unportable assignment operator.
+dist_sbin_SCRIPTS = $(t1:=.sh)
+libexec_SCRIPTS = $(t2:x=)
+nodist_bin_SCRIPTS = $(t3:-baz=x.pl)
+
+check-local: test1 test2
+.PHONY: test1 test2
+test1:
+ ls -l
+ test -f bar1
+ test -f bar2
+ test -f quux.pl
+test2: distdir
+ ls -l $(distdir)
+## The scripts foo1.sh and foo2.sh should be distributed.
+ test -f $(distdir)/foo1.sh
+ test -f $(distdir)/foo2.sh
+## The scripts bar1, bar2 and quux.pl shouldn't be distributed.
+ test ! -r $(distdir)/bar1
+ test ! -r $(distdir)/bar2
+ test ! -r $(distdir)/quux.pl
+
+installcheck-local:
+ ls -l $(libexecdir) $(bindir) $(sbindir)
+ test -f $(sbindir)/foo1.sh
+ test -x $(sbindir)/foo1.sh
+ test -f $(sbindir)/foo2.sh
+ test -x $(sbindir)/foo2.sh
+ test -f $(libexecdir)/bar1
+ test -x $(libexecdir)/bar1
+ test -f $(libexecdir)/bar2
+ test -x $(libexecdir)/bar2
+ test -f $(bindir)/quux.pl
+ test -x $(bindir)/quux.pl
+END
+
+cat > foo1.sh <<'END'
+#!/bin/sh
+exit 0
+END
+cp foo1.sh foo2.sh
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+./configure --prefix="$cwd/_inst"
+$MAKE
+$MAKE test1 test2
+$MAKE install
+$MAKE installcheck
+$MAKE distcheck
+
+:
diff --git a/t/posixsubst-sources.sh b/t/posixsubst-sources.sh
new file mode 100644
index 000000000..0efbf6f1d
--- /dev/null
+++ b/t/posixsubst-sources.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that POSIX variable expansion '$(var:str=rpl)' works when used
+# with the SOURCES primary.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+
+FOO = foo.cxx
+BAR = bar__
+BAZ = baz.
+
+# Also try an empty match suffix, to ensure that the ':=' in there is
+# not confused by the parser with an unportable assignment operator.
+foo_SOURCES = main.c $(FOO:.cxx=.c)
+dist_foo_SOURCES = $(BAR:__=.c)
+nodist_foo_SOURCES = $(BAZ:=c)
+
+bar.c baz.c:
+ echo 'int $@ (void) { return 0; }' | sed 's/\.c //' > $@
+CLEANFILES = baz.c
+CLEANFILES += bar.c # For FreeBSD make.
+
+.PHONY: test test2
+check-local: test1 test2
+test1:
+ ls -l . $(srcdir)
+ test -f $(srcdir)/bar.c
+ test -f baz.c
+test2: distdir
+ ls -l $(distdir)
+## These sources should be distributed ...
+ test -f $(distdir)/bar.c
+ test -f $(distdir)/foo.c
+ test -f $(distdir)/main.c
+## ... and this shouldn't.
+ test ! -r $(distdir)/baz.c
+END
+
+cat > main.c <<'END'
+int main(void)
+{
+ int foo(void), bar(void), baz(void);
+ return foo() + bar() + baz();
+}
+END
+
+echo 'int foo(void) { return 0; }' > foo.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+$MAKE test1 test2
+$MAKE distcheck
+
+:
diff --git a/t/posixsubst-tests.sh b/t/posixsubst-tests.sh
new file mode 100644
index 000000000..77e6c446b
--- /dev/null
+++ b/t/posixsubst-tests.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that POSIX variable expansion '$(var:str=rpl)' works when used
+# with the TESTS special variable.
+
+# For gen-testsuite-part: ==> try-with-serial-tests <==
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+t1 = foo1 foo2
+t2 = barx
+t3 = bar2
+
+foo2.test barz:
+ (echo '#!/bin/sh' && echo 'exit 0') > $@ && chmod a+x $@
+CLEANFILES = foo2.test barz # For FreeBSD make.
+
+# Also try an empty match suffix, to ensure that the ':=' in there is
+# not confused by the parser with an unportable assignment operator.
+TESTS = $(t1:=.test) $(t2:x=y) $(t3:2=z)
+
+EXTRA_DIST = $(TESTS)
+MOSTLYCLEANFILES = *.out
+END
+
+cat > foo1.test <<'END'
+#!/bin/sh
+touch foo1.out
+test x"${TESTSUITE_OK-no}" = x"yes"
+END
+sed 's/foo1/bary/g' foo1.test > bary
+chmod +x foo1.test bary
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+run_make -M -e FAIL check
+ls -l
+grep '^FAIL: foo1\.test *$' output
+grep '^PASS: foo2\.test *$' output
+grep '^FAIL: bary *$' output
+grep '^PASS: barz *$' output
+test -f foo1.out
+test -f bary.out
+
+TESTSUITE_OK=yes $MAKE distcheck
+
+:
diff --git a/t/ppf77.sh b/t/ppf77.sh
new file mode 100644
index 000000000..dcc177331
--- /dev/null
+++ b/t/ppf77.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure preprocessed F77 works.
+# Report from Jochen Kuepper.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_F77
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = ppf
+ppf_SOURCES = foo.F q.r
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/pr2.sh b/t/pr2.sh
new file mode 100644
index 000000000..0a7a90daa
--- /dev/null
+++ b/t/pr2.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug reported in PR 2.
+# "make dist" fails for AC_OUTPUT(README.foo:templ/README.foo.in).
+#
+# == Report ==
+# When my AC_OUTPUT macro in configure.ac contains something
+# like the following (among the Makefiles)
+# README.foo:templ/README.foo.in
+# the generated dist target in the Makefile.in fails,
+# because DIST_COMMON will contain templ/README.foo.in
+# and the dist target will try to copy templ/README.foo.in
+# to the distribution directory before it creates a templ
+# subdirectory in the distribution directory.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT([README.foo:templ/README.foo.in])
+END
+
+: > Makefile.am
+
+mkdir templ
+: > templ/README.foo.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distdir
+test -f $distdir/templ/README.foo.in
+
+:
diff --git a/t/pr211.sh b/t/pr211.sh
new file mode 100644
index 000000000..367fef3f9
--- /dev/null
+++ b/t/pr211.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 211.
+#
+# == Description ==
+# Suppose you have a library and an ltlibrary in the same
+# directory which use the same source:
+#
+# libfoo_la_SOURCES = foo.c
+# libbar_a_SOURCES = foo.c
+#
+# In this case foo.c will be compiled twice but using different
+# compilers. This is a conflict. In this case the user should
+# rename one of the 'foo.o' files.
+
+required=libtoolize
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = helldl
+lib_LTLIBRARIES = libfoo.la
+helldl_SOURCES = foo.c
+libfoo_la_SOURCES = foo.c
+END
+
+libtoolize
+$ACLOCAL
+AUTOMAKE_fails -Wnone -a
+$FGREP 'foo.$(OBJEXT)' stderr
+
+:
diff --git a/t/pr220.sh b/t/pr220.sh
new file mode 100644
index 000000000..a80eb2c7b
--- /dev/null
+++ b/t/pr220.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR automake/220.
+# Test for problems when conditionals are not actually defined.
+# Check that the problems is diagnosed by configure.
+# This isn't perfect (ideally we'd like an error from autoconf),
+# but it is the best we can do. It certainly makes it easier
+# to debug the problem.
+# Note that this should be also in the documentation.
+
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+if NEVER_TRUE
+NEVER_DEFINED = foo.txt
+endif
+data_DATA = $(NEVER_DEFINED)
+EOF
+
+cat >> configure.ac << 'EOF'
+AC_ARG_ENABLE([foo],
+[ --enable-foo Enable foo],
+[ if test "foo" = "bar" ; then
+ AM_CONDITIONAL([NEVER_TRUE], [true])
+ else
+ AM_CONDITIONAL([NEVER_TRUE], [false])
+ fi
+])
+AC_OUTPUT
+EOF
+
+mkdir build
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cd build
+# configure should fail since we've done something invalid.
+../configure 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'conditional.*NEVER_TRUE' stderr
+
+:
diff --git a/t/pr224.sh b/t/pr224.sh
new file mode 100644
index 000000000..32fa67b3e
--- /dev/null
+++ b/t/pr224.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR automake/224: $(top_srcdir) w.r.t. dependencies.
+#
+# == Description ==
+# Dependency tracking data should be stored in in the relative path
+# of the source file, as opposed the object file.
+# I.e., for 'foo.c' in '$(top_srcdir)/bar', being built in
+# '$(top_srcdir)/build', the location of the '.deps' directory
+# should be '$(top_builddir)/bar/.deps'.
+
+required=cc
+. test-init.sh
+
+mkdir foo
+
+cat >foo/main.c <<'EOF'
+int main (void)
+{
+ return 0;
+}
+EOF
+
+cat >Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = bar
+bar_SOURCES = foo/main.c
+EOF
+
+cat >>configure.ac <<'EOF'
+AC_PROG_CC
+AC_OUTPUT
+EOF
+
+mkdir build
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cd build
+../configure
+
+$MAKE
+test -f foo/.deps/main.Po
+$MAKE distclean
+test ! -e foo/.deps/main.Po
+
+:
diff --git a/t/pr229.sh b/t/pr229.sh
new file mode 100644
index 000000000..bed6d819a
--- /dev/null
+++ b/t/pr229.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR automake/229.
+# Make sure AC_CYGWIN requires config.{sub,guess}.
+# Reported by James Youngman.
+
+. test-init.sh
+
+cat >> configure.ac <<EOF
+AC_CYGWIN
+EOF
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE -a
+
+test -f config.sub
+test -f config.guess
+
+:
diff --git a/t/pr243.sh b/t/pr243.sh
new file mode 100644
index 000000000..9f5b52d9e
--- /dev/null
+++ b/t/pr243.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 243.
+# AM_OUTPUT_DEPENDENCY_COMMANDS doesn't handle
+# 'Makefile:Makefile.in:tail.mk' in AC_OUTPUT.
+#
+# == Report ==
+# If configure.ac has something like:
+# AC_OUTPUT(Makefile:Makefile.in:tail.mk)
+# then config.status cannot parse the Makefile to build the
+# dependency files in the .deps directory. This is because
+# the AM_OUTPUT_DEPENDENCY_COMMANDS macro cannot cope with
+# the colon in the CONFIG_FILES variable.
+
+required=cc
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AC_CONFIG_FILES([Makefile:Makefile.in:tail.mk])
+AC_OUTPUT
+END
+
+: > tail.mk
+
+cat > Makefile.am << 'END'
+include_HEADERS = 3dfx.h linutil.h
+noinst_HEADERS = fx64.h fxdll.h fximg.h fxglob.h \
+ fxos.h fxver.h glob.h
+noinst_PROGRAMS = fxmisc
+fxmisc_SOURCES = fx64.c fximg.c fxos.c linutil.c
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure
+
+test -f .deps/fx64.Po
+
+:
diff --git a/t/pr266.sh b/t/pr266.sh
new file mode 100644
index 000000000..cabfd6504
--- /dev/null
+++ b/t/pr266.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 266.
+# Dependency tracking -vs- nonstandard Makefile names
+
+required=cc
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AC_CONFIG_FILES([Maudefile])
+AC_OUTPUT
+END
+
+cat > Maudefile.am << 'END'
+include_HEADERS = 3dfx.h linutil.h
+noinst_HEADERS = fx64.h fxdll.h fximg.h fxglob.h \
+ fxos.h fxver.h glob.h
+noinst_PROGRAMS = fxmisc
+fxmisc_SOURCES = fx64.c fximg.c fxos.c linutil.c
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure --enable-dependency-tracking
+
+test -f .deps/fx64.Po
+
+:
diff --git a/t/pr279-2.sh b/t/pr279-2.sh
new file mode 100644
index 000000000..21e8c4c1d
--- /dev/null
+++ b/t/pr279-2.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another test related to PR 279.
+# Multiple DEPENDENCIES on conditionals.
+# Please keep this in sync with sister test 'pr279.sh'.
+#
+# == Report ==
+# When defining xxx_LDADD and xxx_DEPENDENCIES variables where the
+# xxx_LDADD one contains values set in conditionals, automake will
+# fail with messages like:
+# foo_DEPENDENCIES was already defined in condition TRUE, ...
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([FOOTEST], [false])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if FOOTEST
+foo_LDADD = zardoz
+else
+foo_LDADD = maude
+endif
+
+bin_PROGRAMS = foo
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^@FOOTEST_TRUE@foo_DEPENDENCIES *= *zardoz$' Makefile.in
+grep '^@FOOTEST_FALSE@foo_DEPENDENCIES *= *maude$' Makefile.in
+
+:
diff --git a/t/pr279.sh b/t/pr279.sh
new file mode 100644
index 000000000..0d209b2c2
--- /dev/null
+++ b/t/pr279.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 279.
+# Multiple DEPENDENCIES on conditionals.
+# Please keep this in sync with sister test 'pr279-2.sh'.
+#
+# == Report ==
+# When defining xxx_LDADD and xxx_DEPENDENCIES variables where the
+# xxx_LDADD one contains values set in conditionals, automake will
+# fail with messages like:
+# foo_DEPENDENCIES was already defined in condition TRUE, ...
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([FOOTEST], [false])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+if FOOTEST
+xtralib =
+else
+xtralib =
+endif
+
+bin_PROGRAMS = foo
+foo_LDADD = ${xtralib}
+foo_DEPENDENCIES =
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/pr287.sh b/t/pr287.sh
new file mode 100644
index 000000000..5ad8b0caf
--- /dev/null
+++ b/t/pr287.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 287: empty SUBDIRS.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS =
+bin_SCRIPTS = foo
+END
+
+cat > foo << 'END'
+#! /bin/sh
+echo Maude
+END
+chmod +x foo
+
+mkdir install
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure "--prefix=$(cd install && pwd)"
+
+$MAKE
+$MAKE distdir
+
+:
diff --git a/t/pr300-lib.sh b/t/pr300-lib.sh
new file mode 100644
index 000000000..06768058c
--- /dev/null
+++ b/t/pr300-lib.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that installing subdirectory libraries works.
+# PR/300
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_RANLIB
+AC_PROG_CC
+AM_PROG_AR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LIBRARIES = subdir/liba.a
+subdir_liba_a_SOURCES = a.c
+
+nobase_lib_LIBRARIES = subdir/libb.a
+subdir_libb_a_SOURCES = a.c
+END
+
+cat > a.c << 'END'
+int i = 3;
+END
+
+## A rule in the Makefile should create subdir
+# mkdir subdir
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+# We pass '--libdir' explicitly, to avoid spurious failures due to users
+# or distributions possibly overriding '${libdir}' in their $CONFIG_SITE
+# file (for example, defining it to '${prefix}/lib64' on 64-bit systems,
+# as is the case with openSUSE 12.1). See automake bug#10426.
+cwd=$(pwd) || fatal_ "getting current working directory"
+./configure --prefix "$cwd/inst" --libdir "$cwd/inst/lib"
+
+$MAKE
+
+test -f subdir/liba.a
+test -f subdir/libb.a
+
+$MAKE install
+
+test -f inst/lib/liba.a
+test -f inst/lib/subdir/libb.a
+
+$MAKE uninstall
+
+test -f inst/lib/liba.a && exit 1
+test -f inst/lib/subdir/libb.a && exit 1
+
+$MAKE install-strip
+
+test -f inst/lib/liba.a
+test -f inst/lib/subdir/libb.a
+
+:
diff --git a/t/pr300-ltlib.sh b/t/pr300-ltlib.sh
new file mode 100644
index 000000000..7a249bbf5
--- /dev/null
+++ b/t/pr300-ltlib.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that installing subdirectory libtool libraries works.
+# PR/300
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = subdir/liba.la
+subdir_liba_la_SOURCES = a.c
+
+nobase_lib_LTLIBRARIES = subdir/libb.la
+subdir_libb_la_SOURCES = a.c
+END
+
+cat > a.c << 'END'
+int i = 3;
+END
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+# We pass '--libdir' explicitly, to avoid spurious failures due to users
+# or distributions possibly overriding '${libdir}' in their $CONFIG_SITE
+# file (for example, defining it to '${prefix}/lib64' on 64-bit systems,
+# as is the case with openSUSE 12.1). See automake bug#10426.
+cwd=$(pwd) || fatal_ "getting current working directory"
+./configure --prefix "$cwd/inst" --libdir "$cwd/inst/lib"
+
+# A rule in the Makefile should create subdir.
+test ! -e subdir
+run_make -O
+test -d subdir
+
+grep 'liba.la .*-rpath .*lib' stdout
+grep 'liba.la .*-rpath .*lib/subdir' stdout && exit 1
+grep 'libb.la .*-rpath .*lib/subdir' stdout
+
+test -f subdir/liba.la
+test -f subdir/libb.la
+
+run_make -E install
+grep 'remember.*--finish' stderr && exit 1
+
+test -f inst/lib/liba.la
+test -f inst/lib/subdir/libb.la
+
+$MAKE uninstall
+
+test -f inst/lib/liba.la && exit 1
+test -f inst/lib/subdir/libb.la && exit 1
+
+$MAKE install-strip
+
+test -f inst/lib/liba.la
+test -f inst/lib/subdir/libb.la
+
+:
diff --git a/t/pr300-prog.sh b/t/pr300-prog.sh
new file mode 100644
index 000000000..a50d519c8
--- /dev/null
+++ b/t/pr300-prog.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that installing subdirectory programs works.
+# PR/300
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = subdir/wish
+subdir_wish_SOURCES = a.c
+
+nobase_bin_PROGRAMS = subdir/want
+subdir_want_SOURCES = a.c
+
+test-all: all
+ test -f subdir/wish$(EXEEXT)
+ test -f subdir/want$(EXEEXT)
+test-install: install
+ test -f inst/bin/wish$(EXEEXT)
+ test -f inst/bin/subdir/want$(EXEEXT)
+test-uninstall: uninstall
+ test ! -f inst/bin/wish$(EXEEXT)
+ test ! -f inst/bin/subdir/want$(EXEEXT)
+test-install-strip: install-strip
+ test -f inst/bin/wish$(EXEEXT)
+ test -f inst/bin/subdir/want$(EXEEXT)
+END
+
+cat > a.c << 'END'
+#include <stdio.h>
+int main ()
+{
+ printf ("hi liver!\n");
+ return 0;
+}
+END
+
+## A rule in the Makefile should create subdir
+# mkdir subdir
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+./configure --prefix "$(pwd)/inst"
+
+$MAKE test-all
+$MAKE test-install
+$MAKE test-uninstall
+$MAKE test-install-strip
+
+:
diff --git a/t/pr307.sh b/t/pr307.sh
new file mode 100644
index 000000000..3380d07b0
--- /dev/null
+++ b/t/pr307.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 307: depcomp with depmode=dashmstdout libtool race condition
+# Report from Laurent Morichetti.
+# (Also exercises check_LTLIBRARIES.)
+#
+# == Report ==
+# The dashmstdout depmode calls libtool in parallel to generate the
+# dependencies (with -M flag) and to build the objfile (both have
+# --mode=compile and -o).
+# The process with 'libtool --mode=compile .* -M' can corrupt the objfile
+# as none is generated by the compiler. Since --mode=compile and -o are
+# set libtool assumes that a objfile should be generated and will execute
+# invalid $mv & $LN_S.
+#
+# == Fix ==
+# Now 'depcomp' never compute dependencies in the background, as this can
+# cause races with libtool. Compute the dependencies after the actual
+# compilation.
+
+required='libtoolize gcc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+check_LTLIBRARIES = librace.la
+librace_la_SOURCES = a.c b.c c.c d.c e.c f.c g.c h.c
+
+# Make sure the dependencies are updated.
+check-local:
+ for i in $(librace_la_SOURCES:.c=.Plo); do \
+ echo "checking ./$(DEPDIR)/$$i"; \
+ grep 'foo\.h' ./$(DEPDIR)/$$i >tst || exit 1; \
+ test `wc -l <tst` -eq 2 || exit 1; \
+ done
+END
+
+: >foo.h
+
+for i in a b c d e f g h; do
+ unindent >$i.c <<EOF
+ #include "foo.h"
+ int $i () { return 0; }
+EOF
+done
+
+libtoolize --force
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# Sanity check: make sure the variable we are attempting to force
+# is indeed used by configure.
+grep am_cv_CC_dependencies_compiler_type configure
+
+./configure am_cv_CC_dependencies_compiler_type=dashmstdout
+
+$MAKE
+test -f librace.la && exit 1
+$MAKE check
+
+# The failure we check usually occurs during the above build,
+# with an output such as:
+#
+# mv -f .libs/f.lo f.lo
+# mv: cannot stat '.libs/f.lo': No such file or directory
+#
+# (This may happen on 'f' or on some other files.)
+
+test -f librace.la
+test -f tst # A proof that check-local was run.
+
+:
diff --git a/t/pr401.sh b/t/pr401.sh
new file mode 100644
index 000000000..b0c45cad8
--- /dev/null
+++ b/t/pr401.sh
@@ -0,0 +1,187 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for AC_CONFIG_LIBOBJ_DIR vs LIBOBJS.
+# (pr401b.sh and pr401c.sh do the same for LTLIBOBJS and ALLOCA)
+
+required=cc
+. test-init.sh
+
+mkdir lib src
+
+cat >lib/feep.c <<'EOF'
+const char *feep (void)
+{
+ return "feep";
+}
+EOF
+
+cat >src/main.c <<'EOF'
+#include <stdio.h>
+
+extern const char *feep (void);
+
+int main (void)
+{
+ puts (feep ());
+ return 0;
+}
+EOF
+
+cat >>configure.ac << 'EOF'
+## These lines are activated for later tests
+#: AC_CONFIG_LIBOBJ_DIR([lib])
+AC_PROG_CC
+AC_LIBOBJ([feep])
+AC_LIBSOURCE([feep.c])
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_CONFIG_FILES([lib/Makefile src/Makefile])
+AM_CONDITIONAL([CROSS_COMPILING], [test $cross_compiling = yes])
+AC_OUTPUT
+EOF
+
+## ------------------------------------------ ##
+## First a test of traditional LIBOBJS usage. ##
+## ------------------------------------------ ##
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = lib src
+EOF
+
+cat >lib/Makefile.am <<'EOF'
+noinst_LIBRARIES = libfeep.a
+libfeep_a_SOURCES =
+libfeep_a_LIBADD = $(LIBOBJS)
+EOF
+
+cat >src/Makefile.am <<'EOF'
+check_PROGRAMS = main
+main_LDADD = ../lib/libfeep.a
+
+if !CROSS_COMPILING
+TESTS = main
+endif
+EOF
+
+cp "$am_scriptdir/ar-lib" . || fatal_ "fetching auxiliary script 'ar-lib'"
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE distcheck
+
+## ------------------------------------------ ##
+## Traditional LIBOBJS with LIBOBJDIR set. ##
+## ------------------------------------------ ##
+
+# Invocation of AC_CONFIG_LIBOBJ_DIR may be necessary for reasons
+# unrelated to Automake or Makefile.am layout.
+
+sed 's/#: //' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+test ! -e lib/lib
+$MAKE distcheck
+
+## -------------------------------------------- ##
+## Error message with usage in wrong directory. ##
+## -------------------------------------------- ##
+
+mv -f src/Makefile.am src/t
+sed 's/LDADD = .*/LDADD = @LIBOBJS@/' src/t > src/Makefile.am
+AUTOMAKE_fails
+grep 'cannot be used outside.*lib' stderr
+mv -f src/t src/Makefile.am
+
+
+## -------------------------------------------- ##
+## Test using LIBOBJS from a sibling directory. ##
+## -------------------------------------------- ##
+
+sed 's/lib\/Makefile //' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = src
+EOF
+
+cat > src/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+
+noinst_LIBRARIES = libfeep.a
+libfeep_a_SOURCES =
+libfeep_a_LIBADD = $(LIBOBJS)
+
+check_PROGRAMS = main
+main_LDADD = libfeep.a
+
+if !CROSS_COMPILING
+TESTS = main
+endif
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+test ! -e src/lib
+test ! -e 'src/$(top_builddir)'
+$MAKE
+$MAKE check
+$MAKE distclean
+
+
+## ----------------------------------------- ##
+## Test using LIBOBJS from parent directory. ##
+## ----------------------------------------- ##
+
+sed 's/^.*src\/Makefile.*$//' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+cat >Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+
+noinst_LIBRARIES = lib/libfeep.a
+lib_libfeep_a_SOURCES =
+lib_libfeep_a_LIBADD = $(LIBOBJS)
+
+check_PROGRAMS = src/main
+src_main_SOURCES = src/main.c
+src_main_LDADD = lib/libfeep.a
+
+if !CROSS_COMPILING
+TESTS = src/main
+endif
+
+check-local:
+ test -f src/main.$(OBJEXT)
+ test -f lib/feep.$(OBJEXT)
+ test ! -f src/$(DEPDIR)/feep.Po
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
+
+:
diff --git a/t/pr401b.sh b/t/pr401b.sh
new file mode 100644
index 000000000..f6a7fa2b2
--- /dev/null
+++ b/t/pr401b.sh
@@ -0,0 +1,187 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for AC_CONFIG_LIBOBJ_DIR vs LTLIBOBJS.
+# (pr401.sh and pr401c.sh do the same for LIBOBJS and ALLOCA)
+
+required='cc libtoolize'
+. test-init.sh
+
+mkdir lib src
+
+cat >lib/feep.c <<'EOF'
+const char *feep (void)
+{
+ return "feep";
+}
+EOF
+
+cat >src/main.c <<'EOF'
+#include <stdio.h>
+
+extern const char *feep (void);
+
+int main (void)
+{
+ puts (feep ());
+ return 0;
+}
+EOF
+
+cat >>configure.ac << 'EOF'
+## These lines are activated for later tests
+#: AC_CONFIG_LIBOBJ_DIR([lib])
+AC_PROG_CC
+AC_LIBOBJ([feep])
+AC_LIBSOURCE([feep.c])
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_CONFIG_FILES([lib/Makefile src/Makefile])
+AM_CONDITIONAL([CROSS_COMPILING], [test $cross_compiling = yes])
+AC_OUTPUT
+EOF
+
+## -------------------------------------------- ##
+## First a test of traditional LTLIBOBJS usage. ##
+## -------------------------------------------- ##
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = lib src
+EOF
+
+cat >lib/Makefile.am <<'EOF'
+noinst_LTLIBRARIES = libfeep.la
+libfeep_la_SOURCES =
+libfeep_la_LIBADD = $(LTLIBOBJS)
+EOF
+
+cat >src/Makefile.am <<'EOF'
+check_PROGRAMS = main
+main_LDADD = ../lib/libfeep.la
+
+if !CROSS_COMPILING
+TESTS = main
+endif
+EOF
+
+cp "$am_scriptdir/ar-lib" . || fatal_ "fetching auxiliary script 'ar-lib'"
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE distcheck
+
+## ----------------------------------------- ##
+## Traditional LTLIBOBJS with LIBOBJDIR set. ##
+## ----------------------------------------- ##
+
+# Invocation of AC_CONFIG_LIBOBJ_DIR may be necessary for reasons
+# unrelated to Automake or Makefile.am layout.
+
+sed 's/#: //' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+test ! -e lib/lib
+$MAKE distcheck
+
+## -------------------------------------------- ##
+## Error message with usage in wrong directory. ##
+## -------------------------------------------- ##
+
+mv -f src/Makefile.am src/t
+sed 's/LDADD = .*/LDADD = @LTLIBOBJS@/' src/t > src/Makefile.am
+AUTOMAKE_fails
+grep 'cannot be used outside.*lib' stderr
+mv -f src/t src/Makefile.am
+
+## ---------------------------------------------- ##
+## Test using LTLIBOBJS from a sibling directory. ##
+## ---------------------------------------------- ##
+
+sed 's/lib\/Makefile //' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = src
+EOF
+
+cat > src/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+
+noinst_LTLIBRARIES = libfeep.la
+libfeep_la_SOURCES =
+libfeep_la_LIBADD = $(LTLIBOBJS)
+
+check_PROGRAMS = main
+main_LDADD = libfeep.la
+
+if !CROSS_COMPILING
+TESTS = main
+endif
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+test ! -e src/lib
+test ! -e 'src/$(top_builddir)'
+$MAKE
+$MAKE check
+$MAKE distclean
+
+
+## ------------------------------------------- ##
+## Test using LTLIBOBJS from parent directory. ##
+## ------------------------------------------- ##
+
+sed 's/^.*src\/Makefile.*$//' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+cat >Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+
+noinst_LTLIBRARIES = lib/libfeep.la
+lib_libfeep_la_SOURCES =
+lib_libfeep_la_LIBADD = $(LTLIBOBJS)
+
+check_PROGRAMS = src/main
+src_main_SOURCES = src/main.c
+src_main_LDADD = lib/libfeep.la
+
+if !CROSS_COMPILING
+TESTS = src/main
+endif
+
+check-local:
+ test -f src/main.$(OBJEXT)
+ test -f lib/feep.lo
+ test ! -f src/$(DEPDIR)/feep.Po
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
+
+:
diff --git a/t/pr401c.sh b/t/pr401c.sh
new file mode 100644
index 000000000..e1cea4ee6
--- /dev/null
+++ b/t/pr401c.sh
@@ -0,0 +1,189 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check support for AC_CONFIG_LIBOBJ_DIR vs ALLOCA.
+# (pr401.sh and pr401b.sh do the same for LIBOBJS and LTLIBOBJS)
+
+required=cc
+. test-init.sh
+
+mkdir lib src
+
+ac_cv_func_alloca_works=no; export ac_cv_func_alloca_works
+
+cat >lib/alloca.c <<'EOF'
+const char *feep (void)
+{
+ return "feep";
+}
+EOF
+
+cat >src/main.c <<'EOF'
+#include <stdio.h>
+
+extern const char *feep (void);
+
+int main (void)
+{
+ puts (feep ());
+ return 0;
+}
+EOF
+
+cat >>configure.ac << 'EOF'
+## These lines are activated for later tests.
+#: AC_CONFIG_LIBOBJ_DIR([lib])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_FUNC_ALLOCA
+AC_CONFIG_FILES([lib/Makefile src/Makefile])
+AM_CONDITIONAL([CROSS_COMPILING], [test $cross_compiling = yes])
+AC_OUTPUT
+EOF
+
+## ----------------------------------------- ##
+## First a test of traditional ALLOCA usage. ##
+## ----------------------------------------- ##
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = lib src
+EOF
+
+cat >lib/Makefile.am <<'EOF'
+noinst_LIBRARIES = libfeep.a
+libfeep_a_SOURCES =
+libfeep_a_LIBADD = $(ALLOCA)
+EOF
+
+cat >src/Makefile.am <<'EOF'
+check_PROGRAMS = main
+main_LDADD = ../lib/libfeep.a
+
+if !CROSS_COMPILING
+TESTS = main
+endif
+EOF
+
+cp "$am_scriptdir/ar-lib" . || fatal_ "fetching auxiliary script 'ar-lib'"
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE distcheck
+
+
+## --------------------------------------- ##
+## Traditional ALLOCA with LIBOBJDIR set. ##
+## --------------------------------------- ##
+
+# Invocation of AC_CONFIG_LIBOBJ_DIR may be necessary for reasons
+# unrelated to Automake or Makefile.am layout.
+
+sed 's/#: //' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+test ! -e lib/lib
+$MAKE distcheck
+
+## -------------------------------------------- ##
+## Error message with usage in wrong directory. ##
+## -------------------------------------------- ##
+
+mv -f src/Makefile.am src/t
+sed 's/LDADD = .*/LDADD = @ALLOCA@/' src/t > src/Makefile.am
+AUTOMAKE_fails
+grep 'cannot be used outside.*lib' stderr
+mv -f src/t src/Makefile.am
+
+
+## ------------------------------------------- ##
+## Test using ALLOCA from a sibling directory. ##
+## ------------------------------------------- ##
+
+sed 's/lib\/Makefile //' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = src
+EOF
+
+cat > src/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+
+noinst_LIBRARIES = libfeep.a
+libfeep_a_SOURCES =
+libfeep_a_LIBADD = $(ALLOCA) $(LIBOBJS) # Add LIBOBJS for fun.
+
+check_PROGRAMS = main
+main_LDADD = libfeep.a
+
+if !CROSS_COMPILING
+TESTS = main
+endif
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE
+test ! -e src/lib
+test ! -e 'src/$(top_builddir)'
+$MAKE check
+$MAKE distclean
+
+
+## ---------------------------------------- ##
+## Test using ALLOCA from parent directory. ##
+## ---------------------------------------- ##
+
+sed 's/^.*src\/Makefile.*$//' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+cat >Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+
+noinst_LIBRARIES = lib/libfeep.a
+lib_libfeep_a_SOURCES =
+lib_libfeep_a_LIBADD = $(ALLOCA)
+
+check_PROGRAMS = src/main
+src_main_SOURCES = src/main.c
+src_main_LDADD = lib/libfeep.a
+
+if !CROSS_COMPILING
+TESTS = src/main
+endif
+
+check-local:
+ test -f src/main.$(OBJEXT)
+ test -f lib/alloca.$(OBJEXT)
+ test ! -f src/$(DEPDIR)/alloca.Po
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
+
+:
diff --git a/t/pr72.sh b/t/pr72.sh
new file mode 100644
index 000000000..d853a6c78
--- /dev/null
+++ b/t/pr72.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 72
+# Empty _SOURCES results in $(LINK) undefined.
+
+required=libtool
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libviewer.la
+libviewer_la_SOURCES =
+libviewer_la_LIBADD = libphony.la
+END
+
+: > ltconfig
+: > ltmain.sh
+: > config.guess
+: > config.sub
+
+$ACLOCAL
+$AUTOMAKE -Wno-extra-portability
+
+grep '^LINK =' Makefile.in
+
+:
diff --git a/t/pr87.sh b/t/pr87.sh
new file mode 100644
index 000000000..35bd217ba
--- /dev/null
+++ b/t/pr87.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR automake/87.
+# "make distcheck" fails when two source dirs exist.
+
+required=cc
+. test-init.sh
+
+subdirs="foo bar"
+
+for i in $subdirs; do
+ mkdir $i
+ unindent >$i/$i.c <<EOF
+ int main (void)
+ {
+ return 0;
+ }
+EOF
+ unindent >$i/Makefile.am <<EOF
+ bin_PROGRAMS = $i
+ ${i}_SOURCES = $i.c
+EOF
+done
+
+echo "SUBDIRS = $subdirs" > Makefile.am
+
+cat > configure.ac <<EOF
+AC_INIT([$me], [1.0])
+AC_CONFIG_SRCDIR([foo/foo.c])
+AC_CONFIG_AUX_DIR([.])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([$(echo $subdirs | sed 's|\([a-z][a-z]*\)|\1/Makefile|g')])
+AC_OUTPUT
+EOF
+
+mkdir build
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# Regression test for bug where '.c.o:' is followed by blank line.
+(while read line; do
+ if test "$line" = ".c.o:"; then
+ read next
+ if test -z "$next"; then
+ exit 1
+ else
+ : # For shells with broken 'set -e'.
+ fi
+ break
+ fi
+ done) < foo/Makefile.in || exit 1
+
+cd build
+../configure
+$MAKE distcheck
+
+:
diff --git a/t/pr9.sh b/t/pr9.sh
new file mode 100644
index 000000000..956ed0d53
--- /dev/null
+++ b/t/pr9.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in PR 9.
+# "make dist" incorrect when AC_CONFIG_AUX_DIR is present.
+#
+# == Report ==
+# When AC_CONFIG_AUX_DIR is set (in my case to 'support'), make dist
+# no longer automatically includes config.guess, config.sub, install-sh,
+# ltconfig, ltmain.sh, mdate-sh, missing, and mkinstalldirs. In fact,
+# the entire 'support/' directory is omitted.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([support])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+mkdir support
+
+$ACLOCAL
+
+$AUTOCONF
+$AUTOMAKE -a -c
+./configure
+$MAKE
+$MAKE distcheck
+
+gzip -d $distdir.tar.gz
+
+tar tf $distdir.tar | $FGREP support
+
+tar xf $distdir.tar
+ls -l . $distdir # For debugging.
+test -d $distdir/support
+ls -l $distdir/support # For debugging.
+test -f $distdir/support/install-sh
+
+:
diff --git a/t/precious.sh b/t/precious.sh
new file mode 100644
index 000000000..54065e14d
--- /dev/null
+++ b/t/precious.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure .PRECIOUS can be extended by the user, and can be given
+# dependencies several times.
+
+. test-init.sh
+
+cat >Makefile.am << 'EOF'
+.PRECIOUS: foo
+.PRECIOUS: bar
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+$FGREP '.PRECIOUS:' Makefile.in # For debugging.
+test $($FGREP -c '.PRECIOUS:' Makefile.in) -eq 3
+
+:
diff --git a/t/prefix.sh b/t/prefix.sh
new file mode 100644
index 000000000..2409a2d5b
--- /dev/null
+++ b/t/prefix.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure range of prefixes can be extended
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'EOF'
+bnidir = $(prefix)/bni
+bni_PROGRAMS = zardoz
+EOF
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/preproc-basics.sh b/t/preproc-basics.sh
new file mode 100644
index 000000000..4e37daa87
--- /dev/null
+++ b/t/preproc-basics.sh
@@ -0,0 +1,106 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic tests for '%...%' preprocessing in included Makefile fragments:
+# %reldir% a.k.a. %D%
+# %canon_reldir% a.k.a. %C%
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([zot/Makefile])
+AC_OUTPUT
+END
+
+mkdir foo foo/bar foo/foobar zot
+
+cat > Makefile.am << 'END'
+include $(top_srcdir)/foo/local.mk
+include $(srcdir)/foo/foobar/local.mk
+include local.mk
+END
+
+cat > zot/Makefile.am << 'END'
+include $(top_srcdir)/zot/local.mk
+
+## Check that '%canon_reldir%' doesn't remain overridden
+## by the previous include.
+%canon_reldir%_zot_whoami:
+ echo "I am %reldir%/Makefile.am" >$@
+
+include $(top_srcdir)/top.mk
+include ../reltop.mk
+END
+
+cat > local.mk << 'END'
+%canon_reldir%_whoami:
+ echo "I am %reldir%/local.mk" >$@
+END
+
+cat > top.mk << 'END'
+%canon_reldir%_top_whoami:
+ echo "I am %reldir%/top.mk" >$@
+END
+
+cat > reltop.mk << 'END'
+%C%_reltop_whoami:
+ echo "I am %D%/reltop.mk" >$@
+END
+
+cp local.mk foo
+cp local.mk foo/bar
+cp local.mk foo/foobar
+cp local.mk zot
+
+cat >> foo/local.mk << 'END'
+include %reldir%/bar/local.mk
+## Check that '%canon_reldir%' doesn't remain overridden by the
+## previous include. The duplicated checks are done to ensure that
+## Automake substitutes all pre-processing occurrences on a line,
+## not just the first one.
+test-%reldir%:
+ test '%reldir%' = foo && test '%reldir%' = foo
+ test '%D%' = foo && test '%D%' = foo
+ test '%canon_reldir%' = foo && test '%C%' = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+check ()
+{
+ test $# -eq 2 || fatal_ "made_into(): bad usage"
+ target=$1 contents=$2
+ rm -f "$target" \
+ && $MAKE "$target" \
+ && test x"$(cat "$target")" = x"$contents"
+}
+
+check whoami "I am local.mk"
+check foo_whoami "I am foo/local.mk"
+check foo_bar_whoami "I am foo/bar/local.mk"
+check foo_foobar_whoami "I am foo/foobar/local.mk"
+$MAKE test-foo
+
+cd zot
+check whoami "I am local.mk"
+check ___top_whoami "I am ../top.mk"
+check ___reltop_whoami "I am ../reltop.mk"
+check zot_whoami "I am Makefile.am"
+
+:
diff --git a/t/preproc-c-compile.sh b/t/preproc-c-compile.sh
new file mode 100644
index 000000000..5f659346b
--- /dev/null
+++ b/t/preproc-c-compile.sh
@@ -0,0 +1,118 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test pre-processing substitutions '%reldir%' and '%canon_reldir%'
+# with C compilation and subdir objects.
+
+require=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_CONFIG_FILES([zot/Makefile])
+AC_OUTPUT
+END
+
+mkdir foo
+mkdir foo/bar
+mkdir foo/foobar
+mkdir zot
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+SUBDIRS = zot
+bin_PROGRAMS =
+
+include $(top_srcdir)/foo/local.mk
+include $(srcdir)/foo/foobar/local.mk
+include local.mk
+
+check-local:
+ is $(bin_PROGRAMS) == \
+ foo/mumble2$(EXEEXT) \
+ foo/bar/mumble$(EXEEXT) \
+ foo/foobar/mumble$(EXEEXT) \
+ mumble$(EXEEXT)
+ test '$(mumble_SOURCES)' = one.c
+ test '$(foo_mumble2_SOURCES)' = foo/one.c
+ test '$(foo_bar_mumble_SOURCES)' = foo/bar/one.c
+ test '$(foo_foobar_mumble_SOURCES)' = foo/foobar/one.c
+ test -f mumble$(EXEEXT)
+ test -f foo/mumble2$(EXEEXT)
+ test -f foo/bar/mumble$(EXEEXT)
+ test -f foo/foobar/mumble$(EXEEXT)
+ test -f zot/mumble$(EXEEXT)
+ : Test some of the object files too.
+ test -f one.$(OBJEXT)
+ test -f foo/foobar/one.$(OBJEXT)
+ test -f zot/one.$(OBJEXT)
+END
+
+cat > zot/Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS =
+include $(top_srcdir)/zot/local.mk
+
+test:
+ test '$(bin_PROGRAMS)' = mumble$(EXEEXT)
+ test '$(mumble_SOURCES)' = one.c
+check-local: test
+END
+
+cat > local.mk << 'END'
+bin_PROGRAMS += %reldir%/mumble
+%canon_reldir%_mumble_SOURCES = %reldir%/one.c
+END
+
+echo 'int main (void) { return 0; }' > one.c
+
+sed 's/mumble/mumble2/' local.mk > foo/local.mk
+cp local.mk foo/bar
+cp local.mk foo/foobar
+cp local.mk zot
+echo "include %reldir%/bar/local.mk" >> foo/local.mk
+
+cp one.c foo
+cp one.c foo/bar
+cp one.c foo/foobar
+cp one.c zot
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+$MAKE
+$MAKE check-local
+if ! cross_compiling; then
+ ./mumble
+ ./foo/mumble2
+ ./foo/bar/mumble
+ ./foo/foobar/mumble
+ ./zot/mumble
+fi
+
+(cd zot && $MAKE test)
+
+# GNU install refuses to override a just-installed file; since we
+# have plenty of 'mumble' dummy programs to install in the same
+# location, such "overridden installations" are not a problem for
+# us; so just force the use the 'install-sh' script.
+ac_cv_path_install=$(pwd)/install-sh; export ac_cv_path_install
+$MAKE distcheck
+
+:
diff --git a/t/preproc-demo.sh b/t/preproc-demo.sh
new file mode 100644
index 000000000..a86f51c4a
--- /dev/null
+++ b/t/preproc-demo.sh
@@ -0,0 +1,230 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Demo of a package using pre-processing substitutions '%reldir%' and
+# '%canon_reldir%', and their respective shorthands '%D%' and '%C%'.
+
+am_create_testdir=empty
+required=cc
+. test-init.sh
+
+if cross_compiling; then
+ WE_ARE_CROSS_COMPILING=yes
+else
+ WE_ARE_CROSS_COMPILING=no
+fi
+export WE_ARE_CROSS_COMPILING
+
+SAFE_PRINT_FAIL=; unset SAFE_PRINT_FAIL
+
+cat > configure.ac << 'END'
+AC_INIT([GNU Demo], [0.7], [bug-automake@gnu.org])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE([1.12.6 foreign subdir-objects -Wall])
+AM_CONDITIONAL([NATIVE_BUILD], [test $WE_ARE_CROSS_COMPILING != yes])
+AC_CONFIG_FILES([Makefile])
+AC_PROG_CC
+AM_PROG_CC_C_O
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+mkdir build-aux lib lib/tests src tests
+
+## Top level.
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS =
+check_PROGRAMS =
+noinst_LIBRARIES =
+AM_CPPFLAGS =
+AM_TESTS_ENVIRONMENT =
+CLEANFILES =
+EXTRA_DIST =
+LDADD =
+TESTS =
+
+include $(srcdir)/src/progs.am
+include $(srcdir)/lib/gnulib.am
+include $(srcdir)/tests/check.am
+END
+
+## Src subdir.
+
+cat > src/progs.am <<'END'
+bin_PROGRAMS += %reldir%/hello
+
+bin_PROGRAMS += %D%/goodbye
+%canon_reldir%_goodbye_SOURCES = %D%/hello.c
+%C%_goodbye_CPPFLAGS = $(AM_CPPFLAGS) -DGREETINGS='"Goodbye"'
+
+# The testsuite should have access to our built programs.
+AM_TESTS_ENVIRONMENT += \
+ PROGDIR='$(top_builddir)/%reldir%'; \
+ export PROGDIR; \
+ PATH='$(abs_builddir)/%reldir%'$(PATH_SEPARATOR)$$PATH; \
+ export PATH;
+END
+
+cat > src/hello.c <<'END'
+#include "safe-print.h"
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifndef GREETINGS
+# define GREETINGS "Hello"
+#endif
+
+int
+main (void)
+{
+ safe_print (stdout, GREETINGS ", World!\n");
+ exit (EXIT_SUCCESS);
+}
+END
+
+## Lib subdir.
+
+cat > lib/gnulib.am << 'END'
+noinst_LIBRARIES += %D%/libgnu.a
+
+AM_CPPFLAGS += -I%D% -I$(top_srcdir)/%D%
+LDADD += $(noinst_LIBRARIES)
+
+%C%_libgnu_a_SOURCES = \
+ %D%/safe-print.c \
+ %D%/safe-print.h
+
+if NATIVE_BUILD
+include %D%/tests/gnulib-check.am
+endif
+END
+
+cat > lib/safe-print.c <<'END'
+#include "safe-print.h"
+#include <string.h>
+#include <stdlib.h>
+
+void
+safe_print (FILE *fp, const char * str)
+{
+ if (fprintf (fp, "%s", str) != strlen (str)
+ || fflush (fp) != 0 || ferror (fp))
+ {
+ fprintf (stderr, "I/O error\n");
+ exit (EXIT_FAILURE);
+ }
+}
+
+END
+
+cat > lib/safe-print.h <<'END'
+#include <stdio.h>
+void safe_print (FILE *, const char *);
+END
+
+## Lib/Tests (sub)subdir.
+
+cat > lib/tests/gnulib-check.am <<'END'
+check_PROGRAMS += %D%/safe-print-test
+TESTS += $(check_PROGRAMS)
+END
+
+cat > lib/tests/safe-print-test.c <<'END'
+#include "safe-print.h"
+int
+main (void)
+{
+ safe_print (stdout, "dummy\n");
+ return 0;
+}
+END
+
+## Tests subdir.
+
+cat > tests/check.am <<'END'
+TEST_EXTENSIONS = .sh
+SH_LOG_COMPILER = $(SHELL)
+
+AM_TESTS_ENVIRONMENT += EXEEXT='$(EXEEXT)'; export EXEEXT;
+
+handwritten_TESTS = \
+ %D%/hello.sh \
+ %D%/built.sh
+TESTS += $(handwritten_TESTS)
+EXTRA_DIST += $(handwritten_TESTS)
+
+TESTS += %D%/goodbye.sh
+CLEANFILES += %D%/goodbye.sh
+%D%/goodbye.sh: %D%/hello.sh
+ $(MKDIR_P) %D%
+ rm -f $@ $@-t
+ sed -e 's/hello/goodbye/' \
+ -e 's/Hello/Goodbye/' \
+ < $(srcdir)/%D%/hello.sh >$@-t
+ chmod a-w,a+x $@-t && mv -f $@-t $@
+END
+
+cat > tests/hello.sh <<'END'
+#!/bin/sh
+set -x -e
+if test "$WE_ARE_CROSS_COMPILING" = yes; then
+ echo Skipping: cannot run in cross-compilation mode
+ exit 77
+else
+ hello || exit 1
+ test "`hello`" = 'Hello, World!' || exit 1
+fi
+END
+
+cat > tests/built.sh <<'END'
+#!/bin/sh
+set -x
+test -n "$PROGDIR" || exit 99
+test -f "$PROGDIR/hello$EXEEXT" || exit 1
+test -x "$PROGDIR/hello$EXEEXT" || exit 1
+test -f "$PROGDIR/goodbye$EXEEXT" || exit 1
+test -x "$PROGDIR/goodbye$EXEEXT" || exit 1
+END
+
+
+## Go.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing --copy
+test ! -e compile
+test -f build-aux/compile
+
+./configure
+
+$MAKE
+
+run_make -O check VERBOSE=x
+cat tests/built.log
+cat tests/hello.log
+cat tests/goodbye.log
+if cross_compiling; then
+ test ! -e lib/tests/safe-print-test.log
+ count_test_results total=3 pass=1 fail=0 xpass=0 xfail=0 skip=2 error=0
+else
+ count_test_results total=4 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=0
+fi
+
+$MAKE distcheck
+
+:
diff --git a/t/preproc-errmsg.sh b/t/preproc-errmsg.sh
new file mode 100644
index 000000000..47cbd3c9a
--- /dev/null
+++ b/t/preproc-errmsg.sh
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Tests error messages when '%reldir%' and '%canon_reldir%' substitutions
+# (and their shorthands '%D%' and '%C%') are involved.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AM_PROG_AR
+END
+
+: > ar-lib
+
+mkdir sub sub/sub2
+
+cat > Makefile.am <<'END'
+%canon_reldir%_x1_SOURCES = bar.c
+include sub/local.mk
+END
+
+cat > sub/local.mk <<'END'
+AUTOMAKE_OPTIONS = -Wno-extra-portability
+include %D%/sub2/more.mk
+noinst_LIBRARIES = %reldir%-one.a %D%-two.a
+%C%_x2_SOURCES = foo.c
+END
+
+cat > sub/sub2/more.mk <<'END'
+%C%_UNDEFINED +=
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+
+cat > expected << 'END'
+sub/sub2/more.mk:1: sub_sub2_UNDEFINED must be set with '=' before using '+='
+Makefile.am:2: 'sub/local.mk' included from here
+sub/local.mk:2: 'sub/sub2/more.mk' included from here
+sub/local.mk:3: 'sub-one.a' is not a standard library name
+sub/local.mk:3: did you mean 'libsub-one.a'?
+Makefile.am:2: 'sub/local.mk' included from here
+sub/local.mk:3: 'sub-two.a' is not a standard library name
+sub/local.mk:3: did you mean 'libsub-two.a'?
+Makefile.am:2: 'sub/local.mk' included from here
+sub/local.mk:4: variable 'sub_x2_SOURCES' is defined but no program or
+sub/local.mk:4: library has 'sub_x2' as canonical name (possible typo)
+Makefile.am:2: 'sub/local.mk' included from here
+Makefile.am:1: variable 'x1_SOURCES' is defined but no program or
+Makefile.am:1: library has 'x1' as canonical name (possible typo)
+END
+
+# We need to break these substitutions into multiple sed invocations
+# to avoid spuriously triggering the 'sc_tests_logs_duplicate_prefixes'
+# maintainer check.
+sed -e '/warnings are treated as errors/d' stderr > t1
+sed -e 's/: warning:/:/' t1 > t2
+sed -e 's/: error:/:/' t2 > t3
+sed -e 's/ */ /g' t3 > obtained
+
+diff expected obtained
+
+:
diff --git a/t/primary-prefix-couples-documented-valid.sh b/t/primary-prefix-couples-documented-valid.sh
new file mode 100644
index 000000000..6cef44f2c
--- /dev/null
+++ b/t/primary-prefix-couples-documented-valid.sh
@@ -0,0 +1,87 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the "uncommon" prefix/primary combinations used in
+# examples in the Automake manual do not cause obvious errors.
+# Please keep this test in sync with the automake manual.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_PROG_LIBTOOL
+AM_PROG_GCJ
+AM_PATH_PYTHON
+END
+
+# Fake libtool availability.
+: > ltmain.sh
+cat > acinclude.m4 <<'END'
+AC_DEFUN([AC_PROG_LIBTOOL],
+ [AC_SUBST([LIBTOOL], [:])])
+END
+
+cat > Makefile.am <<'END'
+xmldir = $(datadir)/xml
+xml_DATA = file.xml
+
+data_DATA = file1 file2 file3
+data2dir = $(datadir)
+data2_DATA = file4 file5 file6
+
+aclocaldir = $(datadir)/aclocal
+aclocal_DATA = mymacro.m4 myothermacro.m4
+
+imagesdir = $(pkgdatadir)/images
+soundsdir = $(pkgdatadir)/sounds
+dist_images_DATA = images/vortex.pgm
+dist_sounds_DATA = sounds/whirl.ogg
+
+lisp_DATA = file1.el file2.el
+
+javadir = $(datadir)/java
+dist_java_JAVA = a.java b.java c.java
+
+pkgpython_PYTHON = foo.py
+
+pyexec_LTLIBRARIES = quaternion.la
+quaternion_la_SOURCES = quaternion.c support.c support.h
+quaternion_la_LDFLAGS = -avoid-version -module
+
+myexecbindir = /exec
+myexecbin_PROGRAMS = zardoz
+
+foodir = $(prefix)/foo
+barexecdir = $(prefix)/bar/binaries
+foo_SCRIPTS = foo.sh
+barexec_SCRIPTS = quux.pl
+
+my_execbindir = $(pkglibdir)
+my_doclibdir = $(docdir)
+my_execbin_PROGRAMS = foo
+my_doclib_LIBRARIES = libquux.a
+END
+
+$ACLOCAL
+
+# Both these two invocations are meant.
+# They exercise both code paths concerning auxiliary files.
+$AUTOMAKE -a
+$AUTOMAKE
+
+:
diff --git a/t/primary-prefix-couples-force-valid.sh b/t/primary-prefix-couples-force-valid.sh
new file mode 100644
index 000000000..f7ba8b7b5
--- /dev/null
+++ b/t/primary-prefix-couples-force-valid.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that a user who wants to use an invalid prefix/primary
+# combination can do so with a proper workaround.
+# For example, this:
+# lib_PROGRAMS = foo
+# is expected to cause an automake error, but this:
+# bardir = $(libdir)
+# bar_PROGRAMS = foo
+# should work.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+my_libdir = $(libdir)
+my_lib_PROGRAMS = foo
+
+foodir = $(bindir)
+foo_LIBRARIES = libquux.a
+
+xdir = $(libexecdir)
+x_HEADERS = bar.h
+
+installcheck-local: test
+.PHONY: test
+test:
+ (cd '$(prefix)' && find .);: For debugging.
+ ls -l '$(libdir)/foo$(EXEEXT)'
+ test -f '$(libdir)/foo$(EXEEXT)'
+ test -x '$(libdir)/foo$(EXEEXT)'
+ ls -l '$(bindir)/libquux.a'
+ test -f '$(bindir)/libquux.a'
+ ls -l '$(libexecdir)/bar.h'
+ test -f '$(libexecdir)/bar.h'
+## If this test is run as root, "test -x" could succeed also for
+## non-executable files, so we need to protect the next check.
+## See automake bug#12041.
+ if test -x Makefile; then echo SKIP THIS; else \
+ test ! -x '$(libexecdir)/bar.h'; \
+ fi;
+END
+
+cat > foo.c <<'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+cat > libquux.c <<'END'
+int quux(void)
+{
+ return 1;
+}
+END
+
+: > bar.h
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+./configure --prefix="$cwd/_inst"
+
+$MAKE install
+$MAKE installcheck
+$MAKE distcheck
+
+:
diff --git a/t/primary-prefix-invalid-couples.tap b/t/primary-prefix-invalid-couples.tap
new file mode 100644
index 000000000..1058ff5c0
--- /dev/null
+++ b/t/primary-prefix-invalid-couples.tap
@@ -0,0 +1,193 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Not all primaries/directories combinations are valid.
+# Automake should flag them as errors.
+# Originated from PR/294, extended later (following bug #7647) to
+# cover more cases.
+# See also test 'primary-prefix-valid-couples.test'.
+
+. test-init.sh
+
+plan_ "later"
+
+oIFS=$IFS # Saved for later.
+
+: > ar-lib
+: > ltmain.sh
+: > texinfo.tex
+: > py-compile
+: > config.guess
+: > config.sub
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_SUBST([LIBTOOL], [:]) dnl So that we don't have to require Libtool.
+AM_PROG_GCJ
+AM_PATH_PYTHON
+AM_PATH_LISPDIR
+END
+
+$ACLOCAL || fatal_ "aclocal failure"
+
+# Please keep this list in sync with the list of "Directory Variables"
+# in the GNU Coding Standards and with the list additional directory
+# variables provided by autoconf and/or automake (pkgdatadir, pkglibdir,
+# ...). See also the hash '%standard_prefix' in the automake script.
+prefixes='bin data dataroot doc dvi exec html include info lib libexec
+ lisp locale localstate man man1 man2 man3 man4 man5 man6 man7
+ man8 man9 oldinclude pdf pkgdata pkginclude pkglib pkglibexec
+ ps sbin sharedstate sysconf'
+# Please keep this list in sync with the list of primaries documented in
+# the Automake manual (see the "The Uniform Naming Scheme" section).
+primaries='PROGRAMS LIBRARIES LTLIBRARIES LISP PYTHON JAVA SCRIPTS DATA
+ HEADERS MANS TEXINFOS'
+
+# Use files, not variables, to hold the list of all the possible
+# prefix_PRIMARY couples and the list of those couples valid for
+# automake, to avoid having unreadable very verbose traces.
+
+set +x # Don't be overly verbose.
+
+for prefix in $prefixes; do
+ for primary in $primaries; do
+ echo ${prefix} ${primary}
+ done
+done >all.list
+
+for primary in $primaries; do
+ prefixes_ok=''
+ case $primary in
+ LIBRARIES|LTLIBRARIES)
+ prefixes_ok='lib pkglib'
+ ;;
+ PROGRAMS)
+ prefixes_ok='bin sbin libexec pkglibexec'
+ ;;
+ SCRIPTS)
+ prefixes_ok='bin sbin libexec pkglibexec pkgdata'
+ ;;
+ DATA)
+ prefixes_ok='data dataroot pkgdata doc html dvi pdf ps
+ sysconf sharedstate localstate lisp'
+ ;;
+ HEADERS)
+ prefixes_ok='include oldinclude pkginclude'
+ ;;
+ LISP)
+ prefixes_ok='lisp'
+ ;;
+ PYTHON)
+ prefixes_ok='python'
+ ;;
+ JAVA)
+ prefixes_ok='java'
+ ;;
+ MANS)
+ # FIXME: Here we'd like to have:
+ # prefixes_ok='man man1 man2 man3 man4 man5 man6 man7 man8 man9'
+ # but Automake currently fails on that, as it allows the MANS
+ # primary to be coupled to any prefix.
+ # See also Automake bug#7656.
+ # We should dig out how automake had come to behave this way, and
+ # if such a behaviour can be safely changed.
+ prefixes_ok=$prefixes
+ ;;
+ TEXINFOS)
+ # FIXME: Here we'd like to have:
+ # prefixes_ok='info'
+ # but Automake currently fails on that, as it allows the use of
+ # 'foo_TEXINFOS' to declare extra Texinfo sources for the 'foo'
+ # Texinfo manual, as in e.g.:
+ # info_TEXINFOS = foo.texi
+ # foo_TEXINFOS = gpl.texi
+ # See also Automake bug#7657.
+ prefixes_ok=$prefixes
+ ;;
+ *)
+ fatal_ "unrecognized primary '$primary'"
+ ;;
+ esac
+ for prefix in $prefixes_ok; do
+ echo ${prefix}_${primary}
+ done
+done >allow.list
+
+# 'html_TEXINFOS' is not yet supported, and might never be.
+grep -v '^html TEXINFOS$' all.list | awk '{print NR, $0}' > t
+mv -f t all.list
+
+# For debugging.
+echo '=== all.list ==='
+cat all.list
+echo '=== allow.list ==='
+cat allow.list
+
+# Create the Makefile.am.
+while read lineno prefix primary; do
+ test -n "$prefix" && test -n "$primary" && test 0 -lt $lineno \
+ || fatal_ "internal error in 'all.list'"
+ pfx='' ext=''
+ case $primary in
+ LTLIBRARIES) pfx=lib ext=la;;
+ LIBRARIES) pfx=lib ext=a;;
+ MANS) ext=man;;
+ HEADERS) ext=h;;
+ JAVA) ext=java;;
+ PYTHON) ext=py;;
+ LISP) ext=el;;
+ TEXINFOS) ext=texi;;
+ esac
+ test -z "$ext" || ext=.$ext
+ if test $primary = TEXINFOS; then
+ echo @setfilename foo$lineno.info > foo$lineno.texi
+ fi
+ echo ${prefix}_${primary} = ${pfx}foo${lineno}${ext}
+done <all.list >Makefile.am
+
+# For debugging.
+echo '=== Makefile.am ==='
+cat Makefile.am
+
+set -x # Restore shell xtraces from now on.
+
+AUTOMAKE_fails \
+ -d "'automake -a' error out on mismatched prefix/primary couples" \
+ -- --add-missing
+
+while read lineno prefix primary; do
+ test -n "$prefix" && test -n "$primary" && test 0 -lt $lineno \
+ || fatal_ "internal error in 'all.list'"
+ grep "^${prefix}_${primary}$" allow.list >/dev/null && continue
+ errmsg_rx=".*${prefix}dir.* not a legitimate directory .*$primary"
+ command_ok_ \
+ "mismatched prefix/primary in ${prefix}_${primary}" \
+ grep "^Makefile\\.am:$lineno: $errmsg_rx" stderr
+done <all.list
+
+# Check that automake really failed only for the expected reason(s).
+grep -v 'dir.* not a legitimate directory' stderr && exit 1
+
+# Check that the same failures are present without the '--add-missing'
+# option.
+mv stderr stderr.old
+AUTOMAKE_fails -d "automake error out on mismatched prefix/primary couples"
+command_ok_ "... and with the same diagnostic of 'automake -a'" \
+ diff stderr.old stderr
+
+:
diff --git a/t/primary-prefix-valid-couples.sh b/t/primary-prefix-valid-couples.sh
new file mode 100644
index 000000000..b7c64e2b9
--- /dev/null
+++ b/t/primary-prefix-valid-couples.sh
@@ -0,0 +1,87 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for valid prefix/primary combinations.
+# See also test 'primary-prefix-invalid-couples.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_PROG_LIBTOOL
+AM_PATH_PYTHON
+AM_PATH_LISPDIR
+END
+
+# Fake libtool availability.
+: > ltmain.sh
+: > config.sub
+: > config.guess
+cat > acinclude.m4 <<'END'
+AC_DEFUN([AC_PROG_LIBTOOL],
+ [AC_SUBST([LIBTOOL], [:])])
+END
+
+# Other required files.
+echo '@setfilename foo.info' > foo.texi
+: > texinfo.tex
+: > py-compile
+: > ar-lib
+
+# Setup Makefile.am.
+
+: > Makefile.am
+
+for p in bin sbin libexec pkglibexec; do
+ echo "${p}_PROGRAMS = prog-$p" >> Makefile.am
+done
+
+for p in lib pkglib; do
+ echo "${p}_LIBRARIES = libs-$p.a" >> Makefile.am
+ echo "${p}_LTLIBRARIES = libd-$p.la" >> Makefile.am
+done
+
+for p in bin sbin libexec pkglibexec pkgdata; do
+ echo "${p}_SCRIPTS = $p.sh" >> Makefile.am
+done
+
+for p in data dataroot pkgdata doc html dvi pdf ps sysconf \
+ sharedstate localstate lisp; do
+ echo "${p}_DATA = $p.dat" >> Makefile.am
+done
+
+for p in include oldinclude pkginclude; do
+ echo "${p}_HEADERS = $p.h" >> Makefile.am
+done
+
+for p in man man1 man2 man3 man4 man5 man6 man7 man8 man9; do
+ echo "${p}_MANS = bar.$p"
+done
+
+echo "info_TEXINFOS = foo.texi" >> Makefile.am
+echo "lisp_LISP = foo.el" >> Makefile.am
+echo "python_PYTHON = foo.py" >> Makefile.am
+
+awk '{print NR ":" $0}' Makefile.am # For debugging.
+
+# Go with the tests.
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/primary.sh b/t/primary.sh
new file mode 100644
index 000000000..24ce9bf84
--- /dev/null
+++ b/t/primary.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure errors in am_install_var work.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = @programs@
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'bin_PROGRAMS.*configure substitution' stderr
+grep 'EXTRA_PROGRAMS.*not defined' stderr
+
+:
diff --git a/t/primary2.sh b/t/primary2.sh
new file mode 100644
index 000000000..951709b14
--- /dev/null
+++ b/t/primary2.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure errors in am_install_var work.
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = @programs@
+EXTRA_PROGRAMS = joe @more@
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'EXTRA_PROGRAMS.*configure substitution' stderr
+
+:
diff --git a/t/primary3.sh b/t/primary3.sh
new file mode 100644
index 000000000..0307f25c5
--- /dev/null
+++ b/t/primary3.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we can build programs ending in '.la'
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_PROG_CC
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo.la
+foo_la_SOURCES = foo.c
+.PHONY: test
+test: all
+ test -f foo.la$(EXEEXT)
+END
+
+echo 'int main () { return 0; }' > foo.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE test
+
+:
diff --git a/t/print-libdir.sh b/t/print-libdir.sh
new file mode 100644
index 000000000..a19db0feb
--- /dev/null
+++ b/t/print-libdir.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test on automake options '--print-data-dir' and '--print-script-dir'.
+
+am_create_testdir=empty
+. test-init.sh
+
+libdir=$($AUTOMAKE --print-libdir) || exit 1
+case $libdir in /*);; *) exit 1;; esac
+test -d "$libdir"
+test "$libdir" = "$am_pkgvdatadir"
+test "$libdir" = "$am_scriptdir"
+
+: > Makefile.am
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([.])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+touch ChangeLog README NEWS AUTHORS COPYING
+
+$ACLOCAL
+$AUTOMAKE --gnu --add-missing
+ls -l
+
+diff missing "$libdir"/missing
+diff INSTALL "$libdir"/INSTALL
+
+:
diff --git a/t/proginst.sh b/t/proginst.sh
new file mode 100644
index 000000000..98ce4f81d
--- /dev/null
+++ b/t/proginst.sh
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug where when multiple scripts are installed,
+# the check for AC_PROG_INSTALL fails.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+bin_SCRIPTS = zardoz qbert brownie
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/programs-primary-rewritten.sh b/t/programs-primary-rewritten.sh
new file mode 100644
index 000000000..1b2cd3db7
--- /dev/null
+++ b/t/programs-primary-rewritten.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure xxx_PROGRAMS gets properly rewritten where needed. These
+# checks have been introduced in commit 'Release-1-9-254-g9d0eaef' into
+# the former test 'subst2.test'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([FOO], [c])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+AUTOMAKE_OPTIONS = no-dependencies
+CC = false
+EXEEXT = .bin
+
+check_PROGRAMS = a
+bin_PROGRAMS = b @FOO@
+noinst_PROGRAMS = $(bar) $(baz:=de)
+EXTRA_PROGRAMS =
+
+bar = zardoz
+baz = mau
+
+.PHONY: test
+test:
+ is $(check_PROGRAMS) == a.bin
+ is $(bin_PROGRAMS) == b.bin c
+ is $(noinst_PROGRAMS) == zardoz.bin maude.bin
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep PROGRAMS Makefile.in # For debugging.
+
+# Check that no useless indirections are used.
+grep '^check_PROGRAMS = a$(EXEEXT)$' Makefile.in
+grep '^bin_PROGRAMS = b$(EXEEXT) @FOO@$' Makefile.in
+
+$AUTOCONF
+./configure
+$MAKE test
+
+:
diff --git a/t/py-compile-basedir.sh b/t/py-compile-basedir.sh
new file mode 100644
index 000000000..bc1af61e6
--- /dev/null
+++ b/t/py-compile-basedir.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test the '--basedir' option of the 'py-compile' script,
+
+required=python
+. test-init.sh
+
+# We'll need to create files in '..', so we need one more subdirectory
+# level in order not to clutter up the top-level tests directory.
+mkdir sandbox
+cd sandbox
+
+cp "$am_scriptdir/py-compile" . \
+ || fatal_ "failed to fetch auxiliary script py-compile"
+
+f=__init__
+for d in foo foo/bar "$(pwd)/foo" . .. ../foo ''; do
+ if test -z "$d"; then
+ d2=.
+ else
+ d2=$d
+ fi
+ ../install-sh -d "$d2" "$d2/sub" || exit 99
+ : > "$d2/$f.py"
+ : > "$d2/sub/$f.py"
+ ./py-compile --basedir "$d" "$f.py" "sub/$f.py"
+ find "$d2" # For debugging.
+ py_installed "$d2/$f.pyc"
+ py_installed "$d2/$f.pyo"
+ py_installed "$d2/sub/$f.pyc"
+ py_installed "$d2/sub/$f.pyo"
+ files=$(find "$d2" | grep '\.py[co]$')
+ test $(echo "$files" | wc -l) -eq 4
+ case $d2 in
+ .|..) rm -f $files;;
+ *) rm -rf "$d2";;
+ esac
+done
+
+:
diff --git a/t/py-compile-basic.sh b/t/py-compile-basic.sh
new file mode 100644
index 000000000..ab12f272b
--- /dev/null
+++ b/t/py-compile-basic.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test more basic functionalities of the 'py-compile' script,
+# with "believable" python sources. See also related test
+# 'py-compile-basic2.sh'.
+
+required=python
+. test-init.sh
+
+cp "$am_scriptdir/py-compile" . \
+ || fatal_ "failed to fetch auxiliary script py-compile"
+
+cat > foo.py <<'END'
+# Try out some non-trivial syntax in here.
+
+'''Module docstring'''
+
+def foo (*args, **kwargs):
+ """Function docstring
+ with embedded newline"""
+ return 1
+
+class Foo:
+ r"""Class docstring"""
+ def __init__(self):
+ r'''Method docstring
+ with
+ embedded
+ newlines'''
+ pass
+
+bar = baz = (1, (2,), [3, 4]); zardoz = 0;
+END
+
+mkdir sub
+cat > sub/bar.py <<'END'
+# Import of non-existent modules, or assertion of false conditions,
+# shouldn't cause problems, as it should be enough for the code to
+# be syntactically correct.
+import Automake.No.Such.Module
+assert False
+END
+
+# An empty file in a more deeply-nested directory should be ok as well.
+mkdir -p 1/_/2/_/3/_
+: > 1/_/2/_/3/_/0.py
+
+./py-compile foo.py sub/bar.py 1/_/2/_/3/_/0.py
+py_installed foo.pyc
+py_installed foo.pyo
+py_installed sub/bar.pyc
+py_installed sub/bar.pyo
+py_installed 1/_/2/_/3/_/0.pyc
+py_installed 1/_/2/_/3/_/0.pyo
+
+:
diff --git a/t/py-compile-destdir.sh b/t/py-compile-destdir.sh
new file mode 100644
index 000000000..c524ecec1
--- /dev/null
+++ b/t/py-compile-destdir.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test the '--destdir' option of the 'py-compile' script,
+
+required=python
+. test-init.sh
+
+cp "$am_scriptdir/py-compile" . \
+ || fatal_ "failed to fetch auxiliary script py-compile"
+
+# Should not give false positives when grepping for it, so use
+# an "uncommon" string (with ugly CamelCase).
+destdir=TheDestDir
+
+mkdir sub $destdir $destdir/sub
+echo 'def foo (): return "foo"' > $destdir/foo.py
+echo 'def bar (): return "bar"' > $destdir/sub/bar.py
+
+./py-compile --destdir $destdir foo.py sub/bar.py
+
+find $destdir # For debugging.
+st=0
+for x in c o; do
+ for b in foo sub/bar; do
+ f=$(pyc_location -p "$destdir/$b.py$x")
+ test -f "$f"
+ strings "$f" || : # For debugging.
+ $FGREP $destdir $f && { echo BAD: $f; st=1; }
+ done
+done
+exit $st
+
+:
diff --git a/t/py-compile-env.sh b/t/py-compile-env.sh
new file mode 100644
index 000000000..d25d67da3
--- /dev/null
+++ b/t/py-compile-env.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'py-compile' honours the PYTHON environment variable.
+
+. test-init.sh
+
+cp "$am_scriptdir/py-compile" . \
+ || fatal_ "failed to fetch auxiliary script py-compile"
+
+cat > my-py <<'END'
+#!/bin/sh
+: > my-py.run
+END
+chmod a+x my-py
+
+mkdir sub1
+cd sub1
+
+PYTHON=: ../py-compile foo.py
+ls | grep . && exit 1
+
+PYTHON=false ../py-compile foo.py && exit 1
+ls | grep . && exit 1
+
+PYTHON='echo GrEpMe AndMeToo' ../py-compile foo.py
+PYTHON='echo GrEpMe AndMeToo' ../py-compile foo.py | grep 'GrEpMe AndMeToo'
+ls | grep . && exit 1
+
+cd ..
+mkdir sub2
+cd sub2
+
+PYTHON=../my-py ../py-compile foo.py
+test -f my-py.run
+ls | grep -v '^my-py\.run$' | grep . && exit 1
+
+cd ..
+mkdir sub3
+cd sub3
+PATH=..$PATH_SEPARATOR$PATH; export PATH
+PYTHON=my-py py-compile foo.py
+test -f my-py.run
+ls | grep -v '^my-py\.run$' | grep . && exit 1
+
+:
diff --git a/t/py-compile-option-terminate.sh b/t/py-compile-option-terminate.sh
new file mode 100644
index 000000000..a2c2d2095
--- /dev/null
+++ b/t/py-compile-option-terminate.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that a non-option argument and the '--' special argument
+# explicitly terminate the option list for 'py-compile'.
+
+required=python
+. test-init.sh
+
+cp "$am_scriptdir/py-compile" . \
+ || fatal_ "failed to fetch auxiliary script py-compile"
+
+: > ./-o.py
+: > ./--foo.py
+./py-compile -- -o.py --foo.py
+py_installed ./-o.pyc
+py_installed ./-o.pyo
+py_installed ./--foo.pyc
+py_installed ./--foo.pyo
+rm -f ./-*.py[co]
+: > x.py
+./py-compile x.py -o.py --foo.py
+py_installed ./x.pyc
+py_installed ./x.pyo
+py_installed ./-o.pyc
+py_installed ./-o.pyo
+py_installed ./--foo.pyc
+py_installed ./--foo.pyo
+
+:
diff --git a/t/py-compile-usage.sh b/t/py-compile-usage.sh
new file mode 100644
index 000000000..57574a4c0
--- /dev/null
+++ b/t/py-compile-usage.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test 'py-compile --help', 'py-compile --version', and that 'py-compile'
+# correctly complains on wrong usage.
+
+. test-init.sh
+
+cp "$am_scriptdir/py-compile" . \
+ || fatal_ "failed to fetch auxiliary script py-compile"
+
+# --help
+
+./py-compile --help >stdout 2>stderr \
+ || { cat stdout; cat stderr >&2; exit 1; }
+cat stdout
+test -s stderr && { cat stderr >&2; exit 1; }
+grep '^Usage: py-compile .' stdout
+$FGREP ' [--basedir DIR]' stdout
+$FGREP ' [--destdir DIR]' stdout
+
+# --version
+
+./py-compile --version >stdout 2>stderr \
+ || { cat stdout; cat stderr >&2; exit 1; }
+cat stdout
+test -s stderr && { cat stderr >&2; exit 1; }
+year='20[0-9][0-9]' # Hopefully automake will be obsolete in 80 years ;-)
+month='(0[0-9]|1[012])'
+day='([012][0-9]|3[01])'
+hour='([01][0-9]|2[0123])'
+LC_ALL=C $EGREP "^py-compile $year-$month-$day\.$hour" stdout
+test $(wc -l <stdout) -eq 1
+
+# Unknown option.
+
+for opt in -b -d --foo; do
+ ./py-compile $opt 2>stderr && { cat stderr >&2; exit 1; }
+ cat stderr >&2
+ grep "^py-compile: unrecognized option '$opt'" stderr
+ grep "^Try 'py-compile --help' for more information" stderr
+done
+
+# Missing option argument.
+
+for opt in --basedir --destdir; do
+ ./py-compile $opt 2>stderr && { cat stderr >&2; exit 1; }
+ cat stderr >&2
+ grep "^py-compile: option '$opt' requires an argument" stderr
+ grep "^Try 'py-compile --help' for more information" stderr
+done
+
+# Missing files.
+
+for args in '' '--basedir dir' '--destdir dir'; do
+ ./py-compile $args 2>stderr && { cat stderr >&2; exit 1; }
+ cat stderr >&2
+ grep '^py-compile: no files given' stderr
+ grep "^Try 'py-compile --help' for more information" stderr
+done
+
+:
diff --git a/t/python-am-path-iftrue.sh b/t/python-am-path-iftrue.sh
new file mode 100644
index 000000000..be837ed9c
--- /dev/null
+++ b/t/python-am-path-iftrue.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test ACTION-IF-TRUE in AM_PATH_PYTHON.
+
+am_create_testdir=empty
+required=python
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+m4_include([mypy.m4])
+AC_OUTPUT
+END
+
+# $PYTHON is supposed to be properly set in ACTION-IF-TRUE.
+cat > mypy.m4 << 'END'
+AM_PATH_PYTHON(, [$PYTHON -V >py-version 2>&1])
+END
+
+$ACLOCAL
+$AUTOCONF
+./configure
+grep '^Python [0-9]\.[0-9][0-9]*\.[0-9]' py-version
+
+# The same, but requiring a version.
+
+rm -rf autom4te*.cache
+
+# $PYTHON is supposed to be properly set in ACTION-IF-TRUE.
+cat > mypy.m4 << 'END'
+AM_PATH_PYTHON([0.0], [$PYTHON -c 'print("%u:%u" % (1-1, 2**0))' > py.out])
+END
+
+# The "--force" option here is truly needed to avoid potential timestamp
+# races. See automake bug#12210.
+$ACLOCAL --force
+$AUTOCONF --force
+./configure
+test x"$(cat py.out)" = x0:1
+
+:
diff --git a/t/python-dist.sh b/t/python-dist.sh
new file mode 100644
index 000000000..6233746b1
--- /dev/null
+++ b/t/python-dist.sh
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test distribution of *_PYTHON files.
+
+# This test does not require python.
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PATH_PYTHON([], [:], [:])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+python_PYTHON = python.py
+dist_python_PYTHON = python-dist.py
+nodist_python_PYTHON = python-nodist.py
+
+pkgpython_PYTHON = pkgpython.py
+dist_pkgpython_PYTHON = pkgpython-dist.py
+nodist_pkgpython_PYTHON = pkgpython-nodist.py
+
+mydir = $(prefix)/my
+my_PYTHON = my.py
+dist_my_PYTHON = my-dist.py
+nodist_my_PYTHON = my-nodist.py
+
+my.py my-dist.py my-nodist.py:
+ : > $@
+
+.PHONY: disttest
+disttest: distdir
+ ls -l $(distdir)
+ test -f $(distdir)/python.py
+ test -f $(distdir)/python-dist.py
+ test ! -f $(distdir)/python-nodist.py
+ test -f $(distdir)/pkgpython.py
+ test -f $(distdir)/pkgpython-dist.py
+ test ! -f $(distdir)/pkgpython-nodist.py
+ test -f $(distdir)/my.py
+ test -f $(distdir)/my-dist.py
+ test ! -f $(distdir)/my-nodist.py
+END
+
+: > python.py
+: > python-dist.py
+: > python-nodist.py
+
+: > pkgpython.py
+: > pkgpython-dist.py
+: > pkgpython-nodist.py
+
+: > py-compile
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE disttest
+# It's not distributed, hence it shouldn't be needlessly generated.
+test ! -e my-nodist.py
+
+:
diff --git a/t/python-missing.sh b/t/python-missing.sh
new file mode 100644
index 000000000..608d92360
--- /dev/null
+++ b/t/python-missing.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test detection of missing Python.
+# See also related test t/python-am-path-missing-2.sh (which requires
+# an actual python program).
+
+am_create_testdir=empty
+# An actual python is *not* required in this test.
+. test-init.sh
+
+unset PYTHON
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+m4_include([mypy.m4])
+AC_OUTPUT
+END
+
+echo AM_PATH_PYTHON > mypy.m4
+
+$ACLOCAL
+$AUTOCONF
+
+# Simulate no Python.
+./configure PYTHON=: 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'no suitable Python interpreter found' stderr
+
+# Again, but from the environment this time.
+env PYTHON=: ./configure 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'no suitable Python interpreter found' stderr
+
+# Now try using a custom ACTION-IF-NOT-FOUND.
+
+echo 'AM_PATH_PYTHON(,, [echo "$PYTHON" > py])' > mypy.m4
+$AUTOCONF --force
+./configure PYTHON=:
+test x"$(cat py)" = x:
+
+# Now try requiring a version.
+
+rm -rf autom4te*.cache # Will have to re-run aclocal.
+
+# Hopefully the Python team will never release such a version :-)
+echo 'AM_PATH_PYTHON([9999.9], [])' > mypy.m4
+# The "--force" options (here and below) are truly needed to avoid
+# potential timestamp races. See automake bug#12210.
+$ACLOCAL --force
+$AUTOCONF --force
+./configure >stdout 2>stderr && {
+ cat stdout
+ cat stderr >&2
+ exit 1
+}
+cat stdout
+cat stderr >&2
+$EGREP 'checking for a Python interpreter with version >= 9999\.9\.\.\. no(ne)? *$' stdout
+grep 'no suitable Python interpreter found' stderr
+
+# Now try requiring a version and using a custom ACTION-IF-NOT-FOUND.
+
+echo 'AM_PATH_PYTHON([9999.9], [], [echo "$PYTHON" > py])' > mypy.m4
+$AUTOCONF --force
+./configure
+test x"$(cat py)" = x:
+
+:
diff --git a/t/python-pr10995.sh b/t/python-pr10995.sh
new file mode 100644
index 000000000..de751903e
--- /dev/null
+++ b/t/python-pr10995.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test automake bug#10995: am__py_compile doesn't get correctly defined
+# when there a 'noinst_PYTHON' declaration precedes a 'foo_PYTHON'
+# declaration.
+
+required=python
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AM_PATH_PYTHON
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'END'
+yesinstdir = $(prefix)/py
+noinst_PYTHON = no.py
+yesinst_PYTHON = yes.py
+disttest: distdir
+ test -f $(distdir)/no.py
+ test -f $(distdir)/yes.py
+END
+
+echo 'def foo(): return 1' > yes.py
+# no.py shouldn't be byte-compiled, so lets make it syntactically invalid.
+echo 'if' > no.py
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+test -f py-compile
+
+./configure --prefix="$(pwd)/inst"
+$MAKE install
+test -f inst/py/yes.py
+test ! -e inst/py/no.py
+py_installed inst/py/yes.pyc
+py_installed --not inst/py/no.pyc
+
+$MAKE disttest
+
+:
diff --git a/t/python-too-old.sh b/t/python-too-old.sh
new file mode 100644
index 000000000..f74f26050
--- /dev/null
+++ b/t/python-too-old.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test detection of too old Python, also forcing the python to use.
+# See also related test 't/python-am-path-missing.sh'.
+
+am_create_testdir=empty
+required=python
+. test-init.sh
+
+py_too_old ()
+{
+ ./configure ${1+"PYTHON=$1"} >stdout 2>stderr && {
+ cat stdout
+ cat stderr >&2
+ exit 1
+ }
+ cat stdout
+ cat stderr >&2
+ grep "whether $1 version is >= 9999\\.9\\.\\.\\. no *$" stdout
+ grep '[Pp]ython interpreter is too old' stderr
+}
+
+saved_PYTHON=$PYTHON; export saved_PYTHON
+unset PYTHON
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+# Hopefully the Python team will never release such a version.
+AM_PATH_PYTHON([9999.9])
+END
+
+$ACLOCAL
+$AUTOCONF
+
+py_too_old python
+
+mkdir bin
+cat > bin/my-python << 'END'
+#! /bin/sh
+exec $saved_PYTHON ${1+"$@"}
+END
+chmod a+x bin/my-python
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH
+
+py_too_old my-python
+
+:
diff --git a/t/python-vars.sh b/t/python-vars.sh
new file mode 100644
index 000000000..e436915b2
--- /dev/null
+++ b/t/python-vars.sh
@@ -0,0 +1,105 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that AM_PATH_PYTHON correctly sets all the output variables
+# advertised in the manual.
+
+required=python
+. test-init.sh
+
+# In case the user's config.site defines pythondir or pyexecdir.
+CONFIG_SITE=/dev/null; export CONFIG_SITE
+
+# Update the definition below if the documentation changes.
+# Note that the value of the 'pythondir' and 'pyexecdir' variables can
+# vary among different python installations, so we need more relaxed
+# and ad-hoc checks for them. Also, more proper "functional" checks
+# on them should be done in the 'python-virtualenv.sh' test.
+PYTHON_VERSION=$($PYTHON -c 'import sys; print(sys.version[:3])') || exit 1
+PYTHON_PLATFORM=$($PYTHON -c 'import sys; print(sys.platform)') || exit 1
+PYTHON_EXEC_PREFIX='${exec_prefix}'
+PYTHON_PREFIX='${prefix}'
+pkgpythondir="\${pythondir}/$me"
+pkgpyexecdir="\${pyexecdir}/$me"
+
+pyvars='PYTHON_VERSION PYTHON_PLATFORM PYTHON_PREFIX PYTHON_EXEC_PREFIX
+ pkgpythondir pkgpyexecdir'
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([vars-got pythondir pyexecdir])
+AM_PATH_PYTHON
+AC_OUTPUT
+END
+
+cat > my.py << 'END'
+def my():
+ return 1
+END
+
+cat > Makefile.am << 'END'
+
+python_PYTHON = my.py
+
+EXTRA_DIST = vars-exp
+
+check-local: test-in test-am
+.PHONY: test-in test-am
+
+test-in:
+ cat pythondir
+ case `cat pythondir` in '$${prefix}'/*);; *) exit 1;; esac
+ cat pyexecdir
+ case `cat pyexecdir` in '$${exec_prefix}'/*);; *) exit 1;; esac
+ cat $(srcdir)/vars-exp
+ cat $(builddir)/vars-got
+ diff $(srcdir)/vars-exp $(builddir)/vars-got
+
+## Note: this target's rules will be extended in the "for" loop below.
+test-am:
+ case '$(pythondir)' in '$(prefix)'/*);; *) exit 1;; esac
+ case '$(pyexecdir)' in '$(exec_prefix)'/*);; *) exit 1;; esac
+END
+
+echo @pythondir@ > pythondir.in
+echo @pyexecdir@ > pyexecdir.in
+
+: > vars-exp
+: > vars-got.in
+
+for var in $pyvars; do
+ eval val=\$$var
+ echo "var=$val" >> vars-exp
+ echo "var=@$var@" >> vars-got.in
+ echo "${tab}test x'\$($var)' = x'$val'" >> Makefile.am
+done
+
+cat Makefile.am
+cat vars-got.in
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+for var in pythondir pyexecdir $pyvars; do
+ grep "^$var *=" Makefile.in
+done
+
+$AUTOCONF
+./configure PYTHON="$PYTHON"
+
+$MAKE test-in test-am
+$MAKE distcheck
+
+:
diff --git a/t/python-virtualenv.sh b/t/python-virtualenv.sh
new file mode 100644
index 000000000..5ec32f553
--- /dev/null
+++ b/t/python-virtualenv.sh
@@ -0,0 +1,201 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that python support can work well with virtualenvs.
+# This test also works as a mild stress-test on the python support.
+
+required='cc python virtualenv'
+. test-init.sh
+
+# In case the user's config.site defines pythondir or pyexecdir.
+CONFIG_SITE=/dev/null; export CONFIG_SITE
+
+py_version_pre=$($PYTHON -V)
+
+# Skip the test if a proper virtualenv cannot be created.
+virtualenv -p"$PYTHON" --verbose virtenv && py_installed virtenv/bin/activate \
+ || skip_ "couldn't create python virtual environment"
+
+# Activate the virtualenv.
+. ./virtenv/bin/activate
+# Sanity check.
+if test -z "$VIRTUAL_ENV"; then
+ framework_failure_ "can't activate python virtual environment"
+fi
+
+py_version_post=$(python -V)
+
+# Sanity check.
+test "$py_version_pre" = "$py_version_post"
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+py_version=$(python -c 'import sys; print("%u.%u" % tuple(sys.version_info[:2]))')
+py_site=$VIRTUAL_ENV/lib/python$py_version/site-packages
+
+# We need to do do this early, just to set some cache variables properly,
+# since because we're going to unset $PYTHON next.
+if python_has_pep3147; then
+ : PEP 3147 will be used in installation of ".pyc" files
+fi
+# We don't want our original python to be picked up by configure
+# invocations.
+unset PYTHON
+
+# We need control over the package name.
+cat > configure.ac << END
+AC_INIT([am_virtenv], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AM_PATH_PYTHON
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+python_PYTHON = am_foo.py
+pkgpython_PYTHON = __init__.py
+pyexec_LIBRARIES = libquux.a
+libquux_a_SOURCES = foo.c
+pkgpyexec_LIBRARIES = libzardoz.a
+libzardoz_a_SOURCES = foo.c
+
+.PYTHON: debug test-run
+debug:
+ @echo PYTHON: $(PYTHON)
+ @echo PYTHON_VERSION: $(PYTHON_VERSION)
+ @echo prefix: $(prefix)
+ @echo pythondir: $(pythondir)
+ @echo pkgpythondir: $(pkgpythondir)
+ @echo pyexecdir: $(pyexecdir)
+ @echo pkgpyexecdir: $(pkgpyexecdir)
+test-run:
+ ## In a virtualenv, the default python must be the custom
+ ## virtualenv python.
+ @: \
+ && py1=`python -c 'import sys; print(sys.executable)'` \
+ && py2=`$(PYTHON) -c 'import sys; print(sys.executable)'` \
+ && echo "py1: $$py1" \
+ && echo "py2: $$py2" \
+ && test -n "$$py1" \
+ && test -n "$$py2" \
+ && test x"$$py1" = x"$$py2"
+ ## Check that modules installed in the virtualenv are readily
+ ## available.
+ python -c 'from am_foo import foo_func; assert (foo_func () == 12345)'
+ python -c 'from am_virtenv import old_am; assert (old_am () == "AutoMake")'
+all-local: debug
+END
+
+cat > am_foo.py << 'END'
+def foo_func ():
+ return 12345
+END
+
+cat > __init__.py << 'END'
+def old_am ():
+ return 'AutoMake'
+END
+
+cat > foo.c << 'END'
+int foo (void)
+{
+ return 0;
+}
+END
+
+check_install ()
+{
+ $MAKE install ${1+"$@"}
+
+ test -f "$py_site"/am_foo.py
+ py_installed "$py_site"/am_foo.pyc
+ py_installed "$py_site"/am_foo.pyo
+ py_installed "$py_site"/am_virtenv/__init__.py
+ py_installed "$py_site"/am_virtenv/__init__.pyc
+ py_installed "$py_site"/am_virtenv/__init__.pyo
+ test -f "$py_site"/libquux.a
+ test -f "$py_site"/am_virtenv/libzardoz.a
+}
+
+check_uninstall ()
+{
+ $MAKE uninstall ${1+"$@"}
+
+ test ! -e "$py_site"/am_foo.py
+ py_installed --not "$py_site"/am_foo.pyc
+ py_installed --not "$py_site"/am_foo.pyo
+ test ! -e "$py_site"/am_virtenv/__init__.py
+ py_installed --not "$py_site"/am_virtenv/__init__.pyc
+ py_installed --not "$py_site"/am_virtenv/__init__.pyo
+ test ! -e "$py_site"/libquux.a
+ test ! -e "$py_site"/am_virtenv/libzardoz.a
+}
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+# Try a VPATH build.
+mkdir build
+cd build
+../configure --prefix="$VIRTUAL_ENV"
+check_install
+$MAKE test-run
+check_uninstall
+cd ..
+
+# Try an in-tree build.
+./configure --prefix="$VIRTUAL_ENV"
+check_install
+$MAKE test-run
+check_uninstall
+
+$MAKE distclean
+
+# Overriding pythondir and pyexecdir with cache variables should work.
+./configure am_cv_python_pythondir="$py_site" \
+ am_cv_python_pyexecdir="$py_site"
+check_install
+$MAKE test-run
+check_uninstall
+
+$MAKE distclean
+
+# Overriding pythondir and pyexecdir at make time should be enough.
+./configure --prefix="$cwd/bad-prefix"
+check_install pythondir="$py_site" pyexecdir="$py_site" \
+ AM_MAKEFLAGS="pythondir='$py_site' pyexecdir='$py_site'"
+test ! -e bad-prefix
+$MAKE test-run
+check_uninstall pythondir="$py_site" pyexecdir="$py_site" \
+ AM_MAKEFLAGS="pythondir='$py_site' pyexecdir='$py_site'"
+
+# Also check that the distribution is self-contained, for completeness.
+$MAKE distcheck
+
+# Finally, check that if we disable the virtualenv, we shouldn't be
+# able to access to the installed modules anymore.
+cd build
+$MAKE install
+python -c 'import am_foo; print(am_foo.__file__)'
+python -c 'import am_virtenv; print(am_virtenv.__file__)'
+deactivate "nondestructive"
+python -c 'import am_foo' && exit 1
+python -c 'import am_virtenv' && exit 1
+
+:
diff --git a/t/python.sh b/t/python.sh
new file mode 100644
index 000000000..a5c709d6a
--- /dev/null
+++ b/t/python.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure py_compile and am__py_compile are correctly defined.
+
+. test-init.sh
+
+echo 'AM_PATH_PYTHON' >> configure.ac
+
+cat > Makefile.am << 'END'
+python_PYTHON = foo.py
+END
+
+cat > Makefile2.am << 'END'
+python_PYTHON = a.py
+nodist_python_PYTHON = b.py
+nobase_python_PYTHON = x/c.py
+mydir = ${prefix}
+my_PYTHON = d.py
+END
+
+# For automake bug#10995.
+cat > Makefile3.am << 'END'
+noinst_PYTHON = un.py
+python_PYTHON = in.py
+END
+
+$ACLOCAL
+
+AUTOMAKE_fails
+grep '^Makefile\.am:1:.* required file.*py-compile' stderr
+
+$AUTOMAKE -a
+grep '^py_compile *=' Makefile.in
+test -f py-compile
+
+$AUTOMAKE Makefile2
+$AUTOMAKE Makefile3
+
+grep "py" Makefile.in Makefile2.in Makefile3.in # For debugging.
+
+for f in Makefile.in Makefile2.in Makefile3.in; do
+ test $(grep -c '^py_compile =' $f) -eq 1
+ test $(grep -c '^am__py_compile =' $f) -eq 1
+done
+
+:
diff --git a/t/python10.sh b/t/python10.sh
new file mode 100644
index 000000000..863c2cee8
--- /dev/null
+++ b/t/python10.sh
@@ -0,0 +1,87 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test _PYTHON with conditionals.
+
+required=python
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_PATH_PYTHON
+AM_CONDITIONAL([ONE], [test "x$one" = x1])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'END'
+if ONE
+mydir=$(prefix)/my
+my_PYTHON = one.py
+else
+yourdir=$(prefix)/your
+your_PYTHON = two.py
+endif
+
+one.py:
+ echo 'def one(): return 1' >$@
+two.py:
+ echo 'def two(): return 1' >$@
+
+.PHONY: disttest
+disttest: distdir
+ ls -l $(distdir)
+ test -f $(distdir)/one.py
+ test -f $(distdir)/two.py
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+inst=inst_
+mkdir inst_ build_
+cd build_
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+../configure --prefix="$cwd/$inst" one=0
+$MAKE install
+test -f "$inst/your/two.py"
+py_installed "$inst/your/two.pyc"
+py_installed "$inst/your/two.pyo"
+py_installed --not "$inst/my/one.py"
+py_installed --not "$inst/my/one.pyc"
+py_installed --not "$inst/my/one.pyo"
+$MAKE uninstall
+py_installed --not "$inst/your/two.py"
+py_installed --not "$inst/your/two.pyc"
+py_installed --not "$inst/your/two.pyo"
+
+../configure --prefix=$cwd/"$inst" one=1
+$MAKE install
+py_installed --not "$inst/your/two.py"
+py_installed --not "$inst/your/two.pyc"
+py_installed --not "$inst/your/two.pyo"
+test -f "$inst/my/one.py"
+py_installed "$inst/my/one.pyc"
+py_installed "$inst/my/one.pyo"
+$MAKE uninstall
+py_installed --not "$inst/my/one.py"
+py_installed --not "$inst/my/one.pyc"
+py_installed --not "$inst/my/one.pyo"
+
+$MAKE disttest
+
+:
diff --git a/t/python11.sh b/t/python11.sh
new file mode 100644
index 000000000..305538478
--- /dev/null
+++ b/t/python11.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test missing python.
+
+# Python is not required for this test.
+. test-init.sh
+
+# We don't want to allow user overrides in this test.
+unset PYTHON
+
+cat >>configure.ac <<'EOF'
+m4_define([_AM_PYTHON_INTERPRETER_LIST], [IShouldNotExist1 IShouldNotExist2])
+AM_PATH_PYTHON
+# The following be executed only after the first run, once a
+# third argument has been added to the previous macro.
+echo PYTHON = $PYTHON
+test "$PYTHON" = : || exit 1
+EOF
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+
+./configure >stdout 2>stderr && { cat stdout; cat stderr >&2; exit 1; }
+cat stdout
+cat stderr >&2
+grep 'checking for IShouldNotExist1' stdout
+grep 'checking for IShouldNotExist2' stdout
+grep 'no suitable Python interpreter found' stderr
+
+sed 's/AM_PATH_PYTHON/AM_PATH_PYTHON(,,:)/' configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+$ACLOCAL --force
+$AUTOCONF --force
+# This one should define PYTHON as ":" and exit successfully.
+./configure
+
+# Any user setting should be used.
+./configure PYTHON=foo >stdout && { cat stdout; exit 1; }
+cat stdout
+grep 'PYTHON = foo' stdout
+
+:
diff --git a/t/python12.sh b/t/python12.sh
new file mode 100644
index 000000000..f804d84c1
--- /dev/null
+++ b/t/python12.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure DESTDIR is not included in byte-compiled files.
+
+required=python
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_PATH_PYTHON
+AC_OUTPUT
+EOF
+
+cat >Makefile.am <<'END'
+mydir = $(datadir)/my
+my_PYTHON = my.py
+
+my.py:
+ echo 'def my(): return 1' >$@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+destdir=$(pwd)/inst
+mkdir inst build
+cd build
+../configure --prefix="/usr"
+$MAKE install DESTDIR=$destdir
+
+# Perfunctory test that the files were created.
+test -f "$destdir/usr/share/my/my.py"
+pyo=$(pyc_location -p "$destdir/usr/share/my/my.pyo")
+pyc=$(pyc_location -p "$destdir/usr/share/my/my.pyc")
+
+# If DESTDIR has made it into the byte compiled files, fail the test.
+st=0; $FGREP "$destdir" "$pyc" "$pyo" || st=$?
+test $st -eq 1
+
+:
diff --git a/t/python2.sh b/t/python2.sh
new file mode 100644
index 000000000..d97fe2910
--- /dev/null
+++ b/t/python2.sh
@@ -0,0 +1,106 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that Automake suggests using AM_PATH_PYTHON.
+
+. test-init.sh
+
+$ACLOCAL
+
+echo 1. pythondir not defined
+
+cat > Makefile.am <<'END'
+PYTHON = x
+python_PYTHON = foo.py
+END
+
+AUTOMAKE_fails -a
+grep 'pythondir.*undefined' stderr
+grep AM_PATH_PYTHON stderr
+
+
+echo 2. pkgpythondir not defined
+
+cat > Makefile.am <<'END'
+PYTHON = x
+pkgpython_PYTHON = foo.py
+END
+
+AUTOMAKE_fails -a
+grep 'pkgpythondir.*undefined' stderr
+grep AM_PATH_PYTHON stderr
+
+
+echo 3. pyexecdir not defined
+
+cat > Makefile.am <<'END'
+PYTHON = x
+pyexec_PYTHON = foo.py
+END
+
+AUTOMAKE_fails -a
+grep 'pyexecdir.*undefined' stderr
+grep AM_PATH_PYTHON stderr
+
+
+echo 4. pkgpyexecdir not defined
+
+cat > Makefile.am <<'END'
+PYTHON = x
+pkgpyexec_PYTHON = foo.py
+END
+
+AUTOMAKE_fails -a
+grep 'pkgpyexecdir.*undefined' stderr
+grep AM_PATH_PYTHON stderr
+
+
+echo 5. PYTHON not defined.
+
+cat > Makefile.am <<'END'
+pkgpyexecdir = /here/we/go
+pkgpyexec_PYTHON = foo.py
+END
+
+AUTOMAKE_fails -a
+grep 'PYTHON.*undefined' stderr
+grep AM_PATH_PYTHON stderr
+
+
+echo 6. Ok.
+
+cat > Makefile.am <<'END'
+PYTHON = x
+pkgpyexecdir = /here/we/go
+pkgpyexec_PYTHON = foo.py
+END
+
+rm -f py-compile
+$AUTOMAKE -a
+test -f py-compile
+
+
+echo 7. Ok again.
+
+cat > Makefile.am <<'END'
+PYTHON = x
+fubardir = /here/we/go
+fubar_PYTHON = foo.py
+END
+
+$AUTOMAKE -a
+
+:
diff --git a/t/python3.sh b/t/python3.sh
new file mode 100644
index 000000000..2ddd4007f
--- /dev/null
+++ b/t/python3.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we install built python files.
+
+required=python
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AM_PATH_PYTHON
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'END'
+mydir=$(prefix)/my
+my_PYTHON = one.py
+
+one.py:
+ echo 'def one(): return 1' >$@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+mkdir build
+cd build
+../configure --prefix="$(pwd)/inst"
+$MAKE install
+py_installed inst/my/one.py
+py_installed inst/my/one.pyc
+py_installed inst/my/one.pyo
+
+:
diff --git a/t/recurs-user-deeply-nested.sh b/t/recurs-user-deeply-nested.sh
new file mode 100644
index 000000000..8d2e32fb2
--- /dev/null
+++ b/t/recurs-user-deeply-nested.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that recursion on user-defined targets can be made to work
+# with "deeply" nested uses of $(SUBDIRS).
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([
+ sub1/Makefile
+ sub1/sub2/Makefile
+ sub1/sub2/sub3/Makefile
+ sub1/sub2/sub3/sub4/Makefile
+])
+AM_EXTRA_RECURSIVE_TARGETS([foo])
+AC_OUTPUT
+END
+
+dirs='sub1 sub1/sub2 sub1/sub2/sub3 sub1/sub2/sub3/sub4'
+
+mkdir $dirs
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1
+
+foo-local:
+ cp sub1/foo foo
+MOSTLYCLEANFILES = foo
+
+.PHONY: test
+test:
+ echo 'It works!' > exp
+ diff exp foo
+ diff exp sub1/foo
+ test ! -f sub1/sub2/foo
+ test ! -f sub1/sub2/sub3/foo
+ diff exp sub1/sub2/sub3/sub4/foo
+ rm -f exp
+
+all-local: foo
+check-local: test
+END
+
+cat > sub1/Makefile.am <<'END'
+SUBDIRS = sub2
+foo-local:
+ test ! -f sub2/sub3/foo
+ cp sub2/sub3/sub4/foo foo
+MOSTLYCLEANFILES = foo
+END
+
+# Here we deliberately lack an explicit definition the 'foo-local'
+# target; that shouldn't stop 'foo' recursion into subdirectory
+# 'sub3/sub4'.
+echo SUBDIRS = sub3 > sub1/sub2/Makefile.am
+echo SUBDIRS = sub4 > sub1/sub2/sub3/Makefile.am
+
+cat > sub1/sub2/sub3/sub4/Makefile.am <<'END'
+foo-local:
+ echo 'It works!' > foo
+MOSTLYCLEANFILES = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for d in $dirs; do
+ $FGREP foo-am $d/Makefile.in || exit 1
+ case $d in
+ */sub4);;
+ *) $FGREP foo-recursive $d/Makefile.in || exit 1;;
+ esac
+done
+
+./configure
+
+$MAKE foo
+$MAKE test
+
+$MAKE distcheck
+
+:
diff --git a/t/recurs-user-indir.sh b/t/recurs-user-indir.sh
new file mode 100644
index 000000000..858daf691
--- /dev/null
+++ b/t/recurs-user-indir.sh
@@ -0,0 +1,99 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that user recursion works with various types of indirections
+# *involved in the definition of the '*-local' targets*: make macros,
+# AC_SUBST'd strings, automake-time file inclusions, automake
+# conditionals...
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([
+ sub1/Makefile
+ sub1/subsub/Makefile
+ sub2/Makefile
+ sub2/subsub/Makefile
+])
+AM_EXTRA_RECURSIVE_TARGETS([foo])
+AC_SUBST([FOO_LOCAL], [foo-local])
+AM_CONDITIONAL([COND], [:])
+AC_OUTPUT
+END
+
+mkdir sub1 sub1/subsub sub2 sub2/subsub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1 sub2
+AM_FOO_LOCAL = foo-local
+
+$(AM_FOO_LOCAL):
+ pwd && : > foo
+CLEANFILES = foo
+
+all-local: foo
+check-local:
+ test -f foo
+ test -f sub1/foo
+ test -f sub1/subsub/foo
+ test -f sub2/foo
+ test -f sub2/subsub/foo
+ test ! -r sub2/subsub/bar
+END
+
+cat > sub1/Makefile.am <<'END'
+SUBDIRS = subsub
+@FOO_LOCAL@:
+ pwd && : > foo
+CLEANFILES = foo
+END
+
+cat > sub1/subsub/Makefile.am <<'END'
+$(FOO_LOCAL):
+ pwd && : > foo
+CLEANFILES = foo
+END
+
+cat > sub2/Makefile.am <<'END'
+include $(srcdir)/bar.am
+include $(srcdir)/baz.am
+CLEANFILES = foo
+END
+
+echo 'SUBDIRS = subsub' > sub2/bar.am
+echo 'foo-local: ; pwd && : > foo' > sub2/baz.am
+
+cat > sub2/subsub/Makefile.am <<'END'
+if COND
+foo-local:
+ pwd && : > foo
+CLEANFILES = foo
+else !COND
+foo-local:
+ pwd && : > bar
+endif !COND
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/recurs-user-keep-going.sh b/t/recurs-user-keep-going.sh
new file mode 100644
index 000000000..ee2f47f5d
--- /dev/null
+++ b/t/recurs-user-keep-going.sh
@@ -0,0 +1,95 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that user recursion works with "make -k".
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AM_EXTRA_RECURSIVE_TARGETS([foo])
+AC_CONFIG_FILES([
+ sub1/Makefile
+ sub1/subsub1/Makefile
+ sub2/Makefile
+ sub2/subsub2/Makefile
+ sub3/Makefile
+])
+FAIL='@echo "FAIL $@ in `pwd`"; exit 1'
+PASS='@echo "PASS $@ in `pwd`"; : > foo'
+AC_SUBST([FAIL])
+AC_SUBST([PASS])
+AC_OUTPUT
+END
+
+mkdir sub1 sub1/subsub1 sub2 sub2/subsub2 sub3
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1 . sub2 sub3
+foo-local:; @FAIL@
+END
+
+cat > sub1/Makefile.am <<'END'
+SUBDIRS = subsub1
+foo-local:; @PASS@
+END
+
+cat > sub2/Makefile.am <<'END'
+SUBDIRS = subsub2
+foo-local:; @FAIL@
+END
+
+echo 'foo-local:; @FAIL@' > sub1/subsub1/Makefile.am
+echo 'foo-local:; @PASS@' > sub2/subsub2/Makefile.am
+echo 'foo-local:; @PASS@' > sub3/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+cat > exp <<END
+./sub1/foo
+./sub2/subsub2/foo
+./sub3/foo
+END
+
+as_expected ()
+{
+ find . -name foo > t || { cat t; exit 1; }
+ LC_ALL=C sort t > got
+ cat exp
+ cat got
+ diff exp got
+}
+
+# Without "-k", we fail in 'sub1/subsub1', and do nothing else.
+# So, no 'foo' file gets created.
+$MAKE foo && exit 1
+find . -name foo | grep . && exit 1
+
+if using_gmake; then
+ $MAKE -k foo && exit 1
+ as_expected
+ $MAKE --keep-going foo && exit 1
+ as_expected
+else
+ # Don't trust the exit status of 'make -k' for non-GNU makes.
+ $MAKE -k foo || :
+ as_expected
+fi
+
+:
diff --git a/t/recurs-user-many.sh b/t/recurs-user-many.sh
new file mode 100644
index 000000000..c4a0f6481
--- /dev/null
+++ b/t/recurs-user-many.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that many user-defined recursive targets can be supported
+# at once, and that calls to 'AM_EXTRA_RECURSIVE_TARGETS' are
+# cumulative.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+## NOTE: extra white spaces, tabs, newlines and backslashes in the
+## lines below: on purpose.
+AM_EXTRA_RECURSIVE_TARGETS([ foo \
+ bar ])
+AC_SUBST([CLEANFILES], ['foo bar baz'])
+AC_OUTPUT
+# Yes, this appears after AC_OUTPUT. So what?
+AM_EXTRA_RECURSIVE_TARGETS([baz])
+END
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+foo-local:
+ : > foo
+bar-local:
+ echo x > bar
+baz-local: ; touch baz
+check-local: foo bar baz
+ ls -l . sub ;: For debugging.
+ test -f foo
+ test -f bar
+ test -f baz
+ test -f sub/foo
+ test -f sub/bar
+ test -f sub/baz
+END
+
+cat > sub/Makefile.am <<'END'
+foo-local bar-local baz-local:
+ touch `echo $@ | sed 's/-local$$//'`
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for t in foo bar baz; do
+ $FGREP "$t-am" Makefile.in
+ $FGREP "$t-am" sub/Makefile.in
+done
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/recurs-user-no-subdirs.sh b/t/recurs-user-no-subdirs.sh
new file mode 100644
index 000000000..9c29d31ae
--- /dev/null
+++ b/t/recurs-user-no-subdirs.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that user recursion can be made to work even when $(SUBDIRS)
+# is empty or undefined.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AM_EXTRA_RECURSIVE_TARGETS([foo])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+
+# First try with undefined $(SUBDIRS).
+cat > Makefile.am <<'END'
+all-local: foo
+foo-local:
+ : > bar
+MOSTLYCLEANFILES = bar
+END
+$AUTOMAKE
+./configure
+$MAKE foo
+test -f bar
+
+$MAKE distclean
+test ! -r bar # Sanity check.
+
+# Now try with empty but defined $(SUBDIRS).
+echo SUBDIRS = >> Makefile.am
+$AUTOMAKE
+./configure
+$MAKE foo
+test -f bar
+
+:
diff --git a/t/recurs-user-no-top-level.sh b/t/recurs-user-no-top-level.sh
new file mode 100644
index 000000000..6f06e2c09
--- /dev/null
+++ b/t/recurs-user-no-top-level.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that user recursion works even for targets that don't exist
+# in the top-level Makefile.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AM_EXTRA_RECURSIVE_TARGETS([foo-bar])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+all-local: foo-bar
+END
+
+cat > sub/Makefile.am <<'END'
+foo-bar-local:
+ : > foo-bar
+MOSTLYCLEANFILES = foo-bar
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE foo-bar
+test -f sub/foo-bar
+
+:
diff --git a/t/recurs-user-override.sh b/t/recurs-user-override.sh
new file mode 100644
index 000000000..67a963de8
--- /dev/null
+++ b/t/recurs-user-override.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that override of user-defined recursive targets work as
+# expected.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AM_EXTRA_RECURSIVE_TARGETS([foobar zardoz])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+all-local: foobar zardoz
+foobar:
+ : > foobar.out
+MOSTLYCLEANFILES = foobar.out
+check-local:
+ test -f foobar.out
+ test ! -r sub/foobar.out
+ test -f sub/zardoz.out
+ test ! -r sub/baz.out
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+foobar foobar-local:
+ : > foobar.out
+zardoz-local:
+ : > baz.out
+zardoz:
+ : > zardoz.out
+MOSTLYCLEANFILES = zardoz.out
+END
+
+$ACLOCAL
+$AUTOCONF
+
+AUTOMAKE_fails
+grep '^Makefile\.am:3:.*user target.*foobar' stderr
+grep '^Makefile\.am:.*foobar-local.*instead of foobar$' stderr
+grep '^sub/Makefile\.am:5:.*user target.*zardoz' stderr
+grep '^sub/Makefile\.am:.*zardoz-local.*instead of zardoz$' stderr
+
+$AUTOMAKE -Wno-override
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/recurs-user-phony.sh b/t/recurs-user-phony.sh
new file mode 100644
index 000000000..39b0f4893
--- /dev/null
+++ b/t/recurs-user-phony.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that user-defined recursive targets and their associate
+# '-local', '-am' and '-recursive' targets are declared as phony.
+
+# Require GNU make, because some vendo makes (e.g., Solaris) doesn't
+# truly respect .PHONY.
+required=GNUmake
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AM_EXTRA_RECURSIVE_TARGETS([foo])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+foo-local:
+ echo 'GOOD!' > foo
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+foo-local:
+ echo 'GOOD!' > foo
+END
+
+dummy_files='
+ foo
+ foo-local
+ foo-am
+ foo-recursive
+ sub/foo
+ sub/foo-local
+ sub/foo-am
+'
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+touch $dummy_files
+
+$MAKE foo
+grep 'GOOD!' foo
+grep 'GOOD!' sub/foo
+
+:
diff --git a/t/recurs-user-wrap.sh b/t/recurs-user-wrap.sh
new file mode 100644
index 000000000..a7f0c270b
--- /dev/null
+++ b/t/recurs-user-wrap.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that rules generated by user recursion are apt to be wrapped
+# by other makefiles.
+
+required=GNUmake
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_EXTRA_RECURSIVE_TARGETS([extra])
+AC_CONFIG_FILES([src/Makefile])
+AC_OUTPUT
+END
+
+mkdir src
+echo SUBDIRS = src > Makefile.am
+echo 'bar: ; : > $@ ' > src/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE extra
+test ! -f extra-local
+test ! -f src/bar
+
+cat > GNUmakefile << 'END'
+.DEFAULT_GOAL = all
+extra-local:
+ : > $@
+include ./Makefile
+END
+
+cat > src/GNUmakefile << 'END'
+include ./Makefile
+extra-local: bar
+END
+
+$MAKE extra
+test -f extra-local
+test -f src/bar
+
+:
diff --git a/t/recurs-user.sh b/t/recurs-user.sh
new file mode 100644
index 000000000..a3f95ff45
--- /dev/null
+++ b/t/recurs-user.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic checks on user-defined recursive rules.
+# Check that user recursion respect $(SUBDIRS) order,
+# and proceeds in a depth-first fashion.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AM_EXTRA_RECURSIVE_TARGETS([foo])
+AC_CONFIG_FILES([
+ sub1/Makefile
+ sub2/Makefile
+ sub3/Makefile
+ sub3/deeper/Makefile
+])
+AC_OUTPUT
+END
+
+mkdir sub1 sub2 sub3 sub3/deeper
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1 . sub3 sub2
+foo-local:
+ echo '.' >> $(top_builddir)/got
+.PHONY: test
+test: foo
+ cat $(srcdir)/exp
+ cat ./got
+ diff $(srcdir)/exp ./got
+check-local: test
+MOSTLYCLEANFILES = got
+EXTRA_DIST = exp
+END
+
+for i in 1 2 3; do
+ cat > sub$i/Makefile.am <<END
+foo-local:
+ echo 'sub$i' >> \$(top_builddir)/got
+END
+done
+
+echo SUBDIRS = deeper >> sub3/Makefile.am
+
+cat >> sub3/deeper/Makefile.am <<'END'
+foo-local:
+ echo sub3/deeper >> $(top_builddir)/got
+END
+
+cat >> exp <<'END'
+sub1
+.
+sub3/deeper
+sub3
+sub2
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/recurs-user2.sh b/t/recurs-user2.sh
new file mode 100644
index 000000000..882a0d395
--- /dev/null
+++ b/t/recurs-user2.sh
@@ -0,0 +1,103 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that user recursion can be made to work when $(SUBDIRS) are
+# not "strictly" nested, as in e.g.:
+# SUBDIRS = src external/lib external/tests
+# with no Makefile in 'external'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES(
+ sub1/Makefile
+ sub2/Makefile
+dnl There's deliberately no 'sub3/Makefile'.
+ sub3/subsub/Makefile
+ sub4/Makefile
+ sub4/subsub/Makefile
+)
+AM_EXTRA_RECURSIVE_TARGETS([foo])
+AC_OUTPUT
+END
+
+mkdir sub1 sub2 sub3 sub4 sub3/subsub sub4/subsub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1 sub2 sub3/subsub sub4 sub4/subsub
+
+foo-local:
+ echo _rootdir_ >foo
+MOSTLYCLEANFILES = foo
+
+.PHONY: test
+test: foo
+ grep _rootdir_ foo
+ grep ':sub1:' sub1/foo
+ grep ',sub1,' sub1/bar
+ test ! -r sub2/foo
+ test ! -r sub3/foo
+ grep '%sub3/subsub%' sub3/subsub/quux
+ test ! -r sub3/subsub/foo
+ test ! -r sub4/foo
+ grep '=sub4/subsub=' sub4/subsub/foo
+
+check-local: test
+END
+
+# A 'foo-local' target with dependencies shouldn't cause problems.
+cat > sub1/Makefile.am <<'END'
+foo-local: bar
+ sed 's/,/:/g' bar >foo
+bar:
+ echo ',sub1,' >$@
+MOSTLYCLEANFILES = foo bar
+END
+
+# The lack of a 'foo' target here shouldn't cause any error in
+# automake nor in make.
+: > sub2/Makefile.am
+
+# The lack of file 'sub3/Makefile.am' shouldn't cause any problem either.
+rm -f sub3/Makefile.am
+
+# A 'foo-local' creating a file != 'foo' shouldn't cause any problem.
+cat > sub3/subsub/Makefile.am <<'END'
+foo-local:
+ echo '%sub3/subsub%' >quux
+MOSTLYCLEANFILES = quux
+END
+
+# No 'foo-local' nor 'foo' target here ...
+: > sub4/Makefile.am
+# ... should not cause errors, nor cause the 'foo-local' target
+# here not to be executed.
+cat > sub4/subsub/Makefile.am <<'END'
+foo-local:
+ echo '=sub4/subsub=' >foo
+MOSTLYCLEANFILES = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/relativize.tap b/t/relativize.tap
new file mode 100644
index 000000000..ad4ddf87e
--- /dev/null
+++ b/t/relativize.tap
@@ -0,0 +1,96 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test Automake-provided internal make macro $(am__relativize).
+
+am_create_testdir=empty
+. test-init.sh
+
+plan_ later
+
+mkdir uber uber/top
+cd uber/top
+
+: > install-sh
+: > missing
+
+cat >> configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# The 'am__relitivize' definition is only brought in when
+# SUBDIRS are defined.
+SUBDIRS = .
+
+.PHONY: test
+test:
+ @$(am__relativize); echo "result: '$$reldir'"; set -x; \
+ case $${reldir:-.} in "$$exp"|"$$exp/.") ;; *) exit 1;; esac
+END
+
+$ACLOCAL && $AUTOMAKE && $AUTOCONF && ./configure || fatal_ "setup failure"
+
+rel_ ()
+{
+ case $1 in -x) directive=TODO; shift;; *) directive=;; esac
+ test $# -eq 4 && test x"$3" = x"=" || fatal_ "rel_: incorrect usage"
+ command_ok_ "$1/{$4} = $2" -D "$directive" \
+ env dir1=$1 dir2=$2 exp=$4 $MAKE test
+}
+
+# am__relativize
+# ~~~~~~~~~~~~~~
+# Computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
+# Input:
+# - DIR1 relative pathname, relative to the current directory
+# - DIR2 relative pathname, relative to the current directory
+# Output:
+# - reldir relative pathname of DIR2, relative to DIR1
+
+rel_ . . = .
+rel_ . .. = ..
+rel_ .. . = top
+
+for d in x long-longer a/b 1/2/3/4/5; do
+ rel_ $d $d = .
+ for d2 in . .. x r/s/t; do
+ rel_ $d $d/$d2 = $d2
+ done
+done
+
+rel_ one two = ../two
+rel_ a b/c = ../b/c
+rel_ a/b . = ../..
+rel_ a/b foo = ../../foo
+rel_ a/b foo/bar = ../../foo/bar
+rel_ a/b a/c = ../c
+rel_ a/b a/c/d = ../c/d
+
+rel_ foo/bar/baz foo/bar/qux/zap = ../qux/zap
+
+rel_ ../foo . = ../top
+rel_ ../.. . = uber/top
+rel_ ../../foo . = ../uber/top
+rel_ ../../x ok = ../uber/top/ok
+rel_ ../../x bo/ba = ../uber/top/bo/ba
+rel_ ../../x ../ok2 = ../uber/top/../ok2
+rel_ ../a/b/c/d/e . = ../../../../../top
+
+:
diff --git a/t/remake-aclocal-version-mismatch.sh b/t/remake-aclocal-version-mismatch.sh
new file mode 100644
index 000000000..7af5ef5b9
--- /dev/null
+++ b/t/remake-aclocal-version-mismatch.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# See how well the rebuild rule handles an aclocal.m4 that was
+# generated for another version of autoconf.
+
+. test-init.sh
+
+echo AC_OUTPUT >>configure.ac
+
+touch Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
+
+sed '1,20 s/m4_defn(\[AC_AUTOCONF_VERSION\]),/9999,/' < aclocal.m4 > aclocal.tmp
+cmp aclocal.m4 aclocal.tmp && exit 1
+
+mv aclocal.tmp aclocal.m4
+
+run_make -E
+grep 'You have another version of autoconf' stderr
+grep 'aclocal.m4:.*this file was generated for' stderr
+
+run_make -E
+grep 'You have another version of autoconf' stderr && exit 1
+grep 'aclocal.m4:.*this file was generated for' stderr && exit 1
+
+:
diff --git a/t/remake-after-acinclude-m4.sh b/t/remake-after-acinclude-m4.sh
new file mode 100644
index 000000000..182476d2e
--- /dev/null
+++ b/t/remake-after-acinclude-m4.sh
@@ -0,0 +1,112 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when acinclude.m4 or its prerequisites change.
+# Keep in sync with the other sister tests 'remake-after-*.sh'.
+
+. test-init.sh
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+
+if using_gmake; then
+ remake_() { $MAKE nil; }
+else
+ remake_() { $MAKE Makefile && $MAKE foo.sh; }
+fi
+
+cat >> configure.ac <<END
+FINGERPRINT='my_fingerprint'
+AC_SUBST([FINGERPRINT])
+AC_CONFIG_FILES([foo.sh:foo.in], [chmod a+x foo.sh])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+nil:
+.PHONY: nil
+
+# The right way to extend an autogenerated aclocal.m4 is to provide
+# an acinclude.m4 file.
+$(srcdir)/acinclude.m4: $(srcdir)/tweak-acinclude-m4
+ $(SHELL) $(srcdir)/tweak-acinclude-m4 <$@ >$@-t
+ mv -f $@-t $@
+ touch $@
+EXTRA_DIST = $(srcdir)/tweak-acinclude-m4
+
+# Used by "make distcheck" later.
+check-local:
+ test x'$(FINGERPRINT)' = x'DummyValue'
+ test x"`./foo.sh`" = x"DummyValue"
+END
+
+cat > foo.in <<END
+#!/bin/sh
+echo '@FINGERPRINT@'
+END
+
+echo "AC_DEFUN([my_fingerprint], [BadBadBad])" > acinclude.m4
+
+echo : > tweak-acinclude-m4 # It is a no-op by default.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for vpath in : false; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+ $MAKE # Should be a no-op.
+
+ $sleep
+ echo "AC_DEFUN([my_fingerprint], [$magic1])" > $srcdir/acinclude.m4
+ remake_
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile
+ test x"$(./foo.sh)" = x"$magic1"
+
+ $sleep
+ echo "echo 'AC_DEFUN([my_fingerprint], [$magic2])'" \
+ > $srcdir/tweak-acinclude-m4
+ remake_
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile
+ test x"$(./foo.sh)" = x"$magic2"
+
+ $sleep
+ echo : > $srcdir/tweak-acinclude-m4 # Make it a no-op again.
+ echo "AC_DEFUN([my_fingerprint], [DummyValue])" > $srcdir/acinclude.m4
+ using_gmake || remake_
+ $MAKE distcheck
+ $FGREP $magic1 Makefile && exit 1 # Sanity check.
+ $FGREP $magic2 Makefile && exit 1 # Likewise.
+
+ $MAKE distclean
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/remake-after-aclocal-m4.sh b/t/remake-after-aclocal-m4.sh
new file mode 100644
index 000000000..11f10a4b5
--- /dev/null
+++ b/t/remake-after-aclocal-m4.sh
@@ -0,0 +1,112 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when aclocal.m4 or its prerequisites change.
+# Keep in sync with the other sister tests 'remake-after-*.sh'.
+
+. test-init.sh
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+
+if using_gmake; then
+ remake_() { $MAKE nil; }
+else
+ remake_() { $MAKE Makefile && $MAKE foo.sh; }
+fi
+
+cat >> configure.ac <<END
+FINGERPRINT='my_fingerprint'
+AC_SUBST([FINGERPRINT])
+AC_CONFIG_FILES([foo.sh:foo.in], [chmod a+x foo.sh])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+nil:
+.PHONY: nil
+
+# A non-autogenerated aclocal.m4 can be extended by hand.
+$(srcdir)/aclocal.m4: $(srcdir)/tweak-aclocal-m4
+ $(SHELL) $(srcdir)/tweak-aclocal-m4 <$@ >$@-t
+ mv -f $@-t $@
+ touch $@
+EXTRA_DIST = $(srcdir)/tweak-aclocal-m4
+
+# Used by "make distcheck" later.
+check-local:
+ test x'$(FINGERPRINT)' = x'DummyValue'
+ test x"`./foo.sh`" = x"DummyValue"
+END
+
+cat > foo.in <<END
+#!/bin/sh
+echo '@FINGERPRINT@'
+END
+
+echo cat > tweak-aclocal-m4 # It is a no-op by default.
+
+$ACLOCAL
+# Cheatingly mark aclocal.m4 as non auto-generated.
+sed '/^ *#.*generated automatically/d' aclocal.m4 > t
+mv -f t aclocal.m4
+$AUTOCONF
+$AUTOMAKE
+
+for vpath in : false; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+ $MAKE # Should be a no-op.
+
+ $sleep
+ echo "AC_DEFUN([my_fingerprint], [$magic1])dnl %%%" >> $srcdir/aclocal.m4
+ remake_
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile
+ test x"$(./foo.sh)" = x"$magic1"
+
+ $sleep
+ echo "sed 's/.*dnl *%%%.*/AC_DEFUN([my_fingerprint], [$magic2])/'" \
+ > $srcdir/tweak-aclocal-m4
+ remake_
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile
+ test x"$(./foo.sh)" = x"$magic2"
+
+ $sleep
+ echo cat > $srcdir/tweak-aclocal-m4 # Make it a no-op again.
+ echo 'AC_DEFUN([my_fingerprint], [DummyValue])' >> $srcdir/aclocal.m4
+ using_gmake || remake_
+ $MAKE distcheck
+ $FGREP $magic1 Makefile && exit 1 # Sanity check.
+ $FGREP $magic2 Makefile && exit 1 # Likewise.
+
+ $MAKE distclean
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/remake-after-configure-ac.sh b/t/remake-after-configure-ac.sh
new file mode 100644
index 000000000..0479c3952
--- /dev/null
+++ b/t/remake-after-configure-ac.sh
@@ -0,0 +1,109 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when configure.ac or its prerequisites change.
+# Keep in sync with the other sister tests 'remake-after-*.sh'.
+
+. test-init.sh
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+
+if using_gmake; then
+ remake_() { $MAKE nil; }
+else
+ remake_() { $MAKE Makefile && $MAKE foo.sh; }
+fi
+
+cat >> configure.ac <<END
+FINGERPRINT=BadBadBad
+AC_SUBST([FINGERPRINT])
+AC_CONFIG_FILES([foo.sh:foo.in], [chmod a+x foo.sh])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+nil:
+.PHONY: nil
+
+$(srcdir)/configure.ac: $(srcdir)/tweak-configure-in
+ $(SHELL) $(srcdir)/tweak-configure-in <$@ >$@-t
+ mv -f $@-t $@
+EXTRA_DIST = $(srcdir)/tweak-configure-in
+
+# Used by "make distcheck" later.
+check-local:
+ test x'$(FINGERPRINT)' = x'DummyValue'
+ test x"`./foo.sh`" = x"DummyValue"
+END
+
+cat > foo.in <<END
+#!/bin/sh
+echo '@FINGERPRINT@'
+END
+
+echo cat > tweak-configure-in # It is a no-op by default.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for vpath in : false; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+ $MAKE # Should be a no-op.
+
+ $sleep
+ sed "s/^\\(FINGERPRINT\\)=.*/\\1=$magic1/" $srcdir/configure.ac >t
+ mv -f t $srcdir/configure.ac
+ remake_
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile
+ test x"$(./foo.sh)" = x"$magic1"
+
+ $sleep
+ echo 'sed "s/^\\(FINGERPRINT\\)=.*/\\1='$magic2'/"' \
+ > $srcdir/tweak-configure-in
+ remake_
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile
+ test x"$(./foo.sh)" = x"$magic2"
+
+ $sleep
+ echo cat > $srcdir/tweak-configure-in # Make it a no-op again.
+ sed "s/^\\(FINGERPRINT\\)=.*/\\1=DummyValue/" $srcdir/configure.ac >t
+ mv -f t $srcdir/configure.ac
+ using_gmake || remake_
+ $MAKE distcheck
+ $FGREP $magic1 Makefile && exit 1 # Sanity check.
+ $FGREP $magic2 Makefile && exit 1 # Likewise.
+
+ $MAKE distclean
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/remake-after-makefile-am.sh b/t/remake-after-makefile-am.sh
new file mode 100644
index 000000000..4585df0e3
--- /dev/null
+++ b/t/remake-after-makefile-am.sh
@@ -0,0 +1,111 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when Makefile.am or its prerequisites change.
+# Keep in sync with the other sister tests 'remake-after-*.sh'.
+
+. test-init.sh
+
+if using_gmake; then
+ remake_() { $MAKE nil; }
+else
+ remake_() { $MAKE Makefile && $MAKE foo.sh; }
+fi
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+FINGERPRINT = BadBadBad
+
+all-local: nil
+nil: foo.sh
+.PHONY: nil
+
+$(srcdir)/Makefile.am: $(srcdir)/tweak-makefile-am
+ $(SHELL) $(srcdir)/tweak-makefile-am <$@ >$@-t
+ mv -f $@-t $@
+EXTRA_DIST = $(srcdir)/tweak-makefile-am
+
+foo.sh: Makefile
+ rm -f $@ $@-t
+ echo '#!/bin/sh' > $@-t
+ echo "echo '$(FINGERPRINT)'" >> $@-t
+ chmod a+x $@-t && mv -f $@-t $@
+CLEANFILES = foo.sh
+
+# Used by "make distcheck" later.
+check-local:
+ test x'$(FINGERPRINT)' = x'DummyValue'
+ test x"`./foo.sh`" = x"DummyValue"
+END
+
+echo cat > tweak-makefile-am # It is a no-op by default.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for vpath in : false; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+ $MAKE # Should be a no-op.
+
+ $sleep
+ sed "s/^\\(FINGERPRINT\\) *=.*/\\1 = $magic1/" $srcdir/Makefile.am >t
+ mv -f t $srcdir/Makefile.am
+ remake_
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile
+ test x"$(./foo.sh)" = x"$magic1"
+
+ $sleep
+ echo 'sed "s/^\\(FINGERPRINT\\) *=.*/\\1 = '$magic2'/"' \
+ > $srcdir/tweak-makefile-am
+ remake_
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile
+ test x"$(./foo.sh)" = x"$magic2"
+
+ $sleep
+ echo cat > $srcdir/tweak-makefile-am # Make it a no-op again.
+ sed "s/^\\(FINGERPRINT\\) *=.*/\\1 = DummyValue/" $srcdir/Makefile.am >t
+ mv -f t $srcdir/Makefile.am
+ using_gmake || remake_
+ $MAKE distcheck
+ $FGREP $magic1 Makefile && exit 1 # Sanity check.
+ $FGREP $magic2 Makefile && exit 1 # Likewise.
+
+ $MAKE distclean
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/remake-all-1.sh b/t/remake-all-1.sh
new file mode 100644
index 000000000..804e4807b
--- /dev/null
+++ b/t/remake-all-1.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the "all" target triggers rebuilt of outdated Makefiles.
+# See also sister test 'remake-all-2.sh'.
+
+. test-init.sh
+
+mkfile=Makefile
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+magic3=%%MagicStringThree%%
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([$mkfile sub/$mkfile])
+FOO='$magic1'
+AC_OUTPUT
+END
+
+mkdir sub
+echo SUBDIRS = sub > $mkfile.am
+: > sub/$mkfile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+$EGREP "^all-am:.* $mkfile( |$)" $mkfile.in sub/$mkfile.in
+
+$AUTOCONF
+./configure
+
+$FGREP "$magic1" mkfile.in && exit 1 # Sanity check.
+
+# Two code paths in configure.am:
+
+# - either a file in $(am__configure_deps) has been updated ...
+$sleep
+echo "AC_SUBST([FOO])" >> configure.ac
+$MAKE
+$FGREP FOO $mkfile # For debugging.
+$FGREP $magic1 $mkfile
+
+# - ... or not; i.e., Makefile.am or an included file has.
+$sleep
+echo "# $magic2" >> $mkfile.am
+echo "# $magic3" >> sub/$mkfile.am
+$MAKE
+$FGREP $magic2 $mkfile
+$FGREP $magic3 sub/$mkfile
+
+:
diff --git a/t/remake-all-2.sh b/t/remake-all-2.sh
new file mode 100644
index 000000000..649aaa584
--- /dev/null
+++ b/t/remake-all-2.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the "all" target triggers rebuilt of outdated makefiles.
+# This handle the case in which the makefiles are not called 'Makefile'.
+# See also sister test 'remake-all-1.sh'.
+
+. test-init.sh
+
+mkfile=foobar
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+magic3=%%MagicStringThree%%
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([$mkfile sub/$mkfile])
+FOO='$magic1'
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > $mkfile.am <<END
+SUBDIRS = sub
+AM_MAKEFLAGS = -f $mkfile
+END
+
+cat > sub/$mkfile.am <<END
+AM_MAKEFLAGS = -f $mkfile
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$EGREP "^all-am:.* $mkfile( |$)" $mkfile.in sub/$mkfile.in
+
+$AUTOCONF
+./configure
+
+$FGREP "$magic1" mkfile.in && exit 1 # Sanity check.
+
+# Two code paths in configure.am:
+
+# - either a file in $(am__configure_deps) has been updated ...
+$sleep
+echo "AC_SUBST([FOO])" >> configure.ac
+$MAKE -f $mkfile
+$FGREP FOO $mkfile # For debugging.
+$FGREP $magic1 $mkfile
+
+# - ... or not; i.e., Makefile.am or an included file has.
+$sleep
+echo "# $magic2" >> $mkfile.am
+echo "# $magic3" >> sub/$mkfile.am
+$MAKE -f $mkfile
+$FGREP $magic2 $mkfile
+$FGREP $magic3 sub/$mkfile
+
+:
diff --git a/t/remake-am-pr10111.sh b/t/remake-am-pr10111.sh
new file mode 100644
index 000000000..1f05c781d
--- /dev/null
+++ b/t/remake-am-pr10111.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that our remake rules doesn't give spurious successes in
+# some corner case situations where they should actually fail.
+# See automake bug#10111.
+# To be clear, we are speaking about *very* corner-case situations here,
+# and the fact that the remake rules might get confused in them is not a
+# big deal in practice (in fact, this test *currently fails*). Still,
+# keeping the limitation exposed is a good idea anyway.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+: > foobar.am
+
+cat > Makefile.am <<'END'
+include $(srcdir)/foobar.am
+$(srcdir)/foobar.am:
+## Creative quoting is to avoid spurious matches in the grepping
+## of Makefile.in, later.
+ echo "mu =" foobar "was here =" > $@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# OK, so the developer wants to interactively try out how the
+# "distributed form" of his package behaves.
+$MAKE distdir
+cd $distdir
+# He's interested in trying out a VPATH build.
+mkdir build
+cd build
+../configure
+# He wants to verify that the rules he's written to rebuild a file
+# included by configure.ac works also in VPATH builds.
+rm -f ../foobar.am
+$MAKE
+grep '= foobar was here =' ../Makefile.in
+$MAKE distcheck
+
+:
diff --git a/t/remake-config-status-dependencies.sh b/t/remake-config-status-dependencies.sh
new file mode 100644
index 000000000..6802b48dd
--- /dev/null
+++ b/t/remake-config-status-dependencies.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test CONFIG_STATUS_DEPENDENCIES.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+. ${srcdir}/version.sh
+AC_SUBST([EXTRA_VERSION])
+AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
+AC_OUTPUT
+END
+
+echo EXTRA_VERSION=1.0 > version.sh
+
+cat > Makefile.am <<'END'
+.PHONY: test-1 test-2 test-3
+check-local: test-3
+test-1:
+ test $(EXTRA_VERSION) = 1.0
+test-2:
+ test $(EXTRA_VERSION) = 2.1
+test-3:
+ test $(EXTRA_VERSION) = 3.14
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test-1
+
+$sleep
+echo EXTRA_VERSION=2.1 > version.sh
+using_gmake || $MAKE Makefile
+$MAKE test-2
+
+$MAKE distclean
+mkdir build
+cd build
+../configure
+$MAKE test-2
+$sleep
+echo EXTRA_VERSION=3.14 > ../version.sh
+using_gmake || $MAKE Makefile
+$MAKE test-3
+
+# Contents of $(CONFIG_STATUS_DEPENDENCIES) are *not* to be
+# automatically distributed; there is no generic good reason
+# for that.
+$MAKE distdir
+test ! -e $distdir/version.sh
+test -f $distdir/configure || exit 99 # Sanity check.
+
+:
diff --git a/t/remake-configure-dependencies.sh b/t/remake-configure-dependencies.sh
new file mode 100644
index 000000000..a27e68d4a
--- /dev/null
+++ b/t/remake-configure-dependencies.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test CONFIGURE_DEPENDENCIES.
+
+. test-init.sh
+
+cat > configure.ac <<'END'
+AC_INIT([confdeps], m4_esyscmd([./print-version]))
+AM_INIT_AUTOMAKE([foreign])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+# Needless to say, the autom4te cache happily break this test.
+cat > .autom4te.cfg <<'END'
+begin-language: "Autoconf-without-aclocal-m4"
+args: --no-cache
+end-language: "Autoconf-without-aclocal-m4"
+END
+
+cat > Makefile.am <<'END'
+EXTRA_DIST = .autom4te.cfg
+CONFIGURE_DEPENDENCIES = $(top_srcdir)/print-version
+
+test-1:
+ test $(VERSION) = 1.0
+test-2:
+ test $(VERSION) = 2.1
+test-3:
+ test $(VERSION) = 3.14
+
+.PHONY: test-1 test-2 test-3
+
+# Contents of $(CONFIGURE_DEPENDENCIES) are to be automatically
+# distributed.
+local-check: test-3 distdir
+ test -f $(distdir)/print-version
+END
+
+(echo '#!/bin/sh' && echo 'printf %s 1.0') > print-version
+chmod a+x print-version
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test-1
+
+$sleep
+(echo '#!/bin/sh' && echo 'printf %s 2.1') > print-version
+using_gmake || $MAKE Makefile
+$MAKE test-2
+
+$MAKE distclean
+mkdir build
+cd build
+../configure
+$MAKE test-2
+
+$sleep
+(echo '#!/bin/sh' && echo 'printf %s 3.14') > ../print-version
+using_gmake || $MAKE Makefile
+$MAKE test-3
+
+# Check that $(CONFIGURE_DEPENDENCIES) are automatically distributed.
+$MAKE distcheck
+
+:
diff --git a/t/remake-deeply-nested.sh b/t/remake-deeply-nested.sh
new file mode 100644
index 000000000..170b3831e
--- /dev/null
+++ b/t/remake-deeply-nested.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules in deeply nested subdirectories, and with a lot
+# of files. This is basically a mild stress test, ensuring that rebuild
+# rules don't break in obvious ways in a slightly "heavier than usual"
+# setup.
+
+. test-init.sh
+
+ocwd=$(pwd) || fatal_ "getting current working directory"
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+
+echo "AC_SUBST([FOO], [$magic1])" >> configure.ac
+
+echo "@FOO@" > bar.in
+echo "AC_CONFIG_FILES([bar])" >> configure.ac
+unset d # Avoid unduly interferences from the environment.
+for i in 0 1 2 3 4 5 6 7 8 9; do
+ d=${d+"$d/"}sub$i
+ echo "SUBDIRS = sub$i" > Makefile.am
+ echo "AC_CONFIG_FILES([$d/Makefile])" >> "$ocwd"/configure.ac
+ echo "AC_CONFIG_FILES([$d/bar])" >> "$ocwd"/configure.ac
+ mkdir sub$i
+ cd sub$i
+ echo "$d: @FOO@" > bar.in
+done
+echo AC_OUTPUT >> "$ocwd"/configure.ac
+: > Makefile.am
+unset d i
+
+bottom=$(pwd) || fatal_ "getting current working directory"
+
+cd "$ocwd"
+
+makefiles_am_list=$(find . -name Makefile.am | LC_ALL=C sort)
+makefiles_list=$(echo "$makefiles_am_list" | sed 's/\.am$//')
+bar_in_list=$(find . -name bar.in | LC_ALL=C sort)
+bar_list=$(echo "$bar_in_list" | sed 's/\.in$//')
+
+cat configure.ac # For debugging.
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+
+for f in configure config.status $makefiles_list $bar_list; do
+ $FGREP "$magic1" $f
+done
+
+$sleep
+sed "s/$magic1/$magic2/" configure.ac >configure.tmp
+mv -f configure.tmp configure.ac
+
+cd "$bottom"
+$MAKE
+cd "$ocwd"
+
+for f in configure config.status $makefiles_list $bar_list; do
+ $FGREP "$magic2" $f
+done
+$FGREP "$magic1" configure config.status $makefiles_list $bar_list && exit 1
+
+$MAKE distcheck
+
+:
diff --git a/t/remake-deleted-am-2.sh b/t/remake-deleted-am-2.sh
new file mode 100644
index 000000000..768feb623
--- /dev/null
+++ b/t/remake-deleted-am-2.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that inclusion of '.am' fragments by automake does not suffer
+# of the "deleted header problem". This test checks deeper inclusion
+# stacks, and use VPATH builds.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+$ACLOCAL
+$AUTOCONF
+
+cat > Makefile.am <<'END'
+include $(srcdir)/foo.am
+END
+
+cat > foo.am <<'END'
+# this is foo
+include sub/bar.am
+include baz.am
+END
+
+mkdir sub
+echo 'include $(top_srcdir)/sub/zardoz.am' > sub/bar.am
+echo '# this is zardoz' > sub/zardoz.am
+
+echo 'include fnord.am' > baz.am
+echo '# you are not seeing this' > fnord.am
+
+$AUTOMAKE
+# Sanity checks.
+$FGREP 'this is zardoz' Makefile.in
+$FGREP 'you are not seeing this' Makefile.in
+
+mkdir build
+cd build
+
+srcdir=..
+
+$srcdir/configure
+$MAKE
+
+$sleep
+echo '# this is baz' > $srcdir/baz.am
+rm -f $srcdir/fnord.am
+$MAKE
+# Sanity checks.
+$FGREP 'you are not seeing this' $srcdir/Makefile.in Makefile && exit 1
+$FGREP 'this is baz' $srcdir/Makefile.in
+$FGREP 'this is baz' Makefile
+
+$sleep
+rm -rf $srcdir/sub $srcdir/foo.am $srcdir/baz.am
+echo '# no more inclusions' > $srcdir/Makefile.am
+$MAKE
+# Sanity checks.
+$EGREP 'this is (foo|bar|baz)' Makefile $srcdir/Makefile.in && exit 1
+$FGREP 'no more inclusions' Makefile
+
+:
diff --git a/t/remake-deleted-am-subdir.sh b/t/remake-deleted-am-subdir.sh
new file mode 100644
index 000000000..c7888ea66
--- /dev/null
+++ b/t/remake-deleted-am-subdir.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that inclusion of '.am' fragments by automake does not suffer
+# of the "deleted header problem". This test does the check when the
+# SUBDIRS variable is involved.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+
+cat > Makefile.am <<'END'
+include foo.am
+SUBDIRS = sub1 sub2
+END
+
+echo '# this is foo.am' > foo.am
+
+mkdir sub1 sub2
+
+echo 'include $(srcdir)/bar.am' > sub1/Makefile.am
+echo '# this is bar.am' > sub1/bar.am
+
+echo 'include $(top_srcdir)/foo.am' > sub2/Makefile.am
+
+$AUTOMAKE
+# Sanity checks.
+$FGREP 'this is foo.am' Makefile.in
+$FGREP 'this is bar.am' sub1/Makefile.in
+$FGREP 'this is foo.am' sub2/Makefile.in
+
+./configure
+$MAKE # Should be no-op.
+
+$sleep
+echo '# this is sub1/Makefile.am' > sub1/Makefile.am
+rm -f sub1/bar.am
+$MAKE all
+# Sanity checks.
+$FGREP 'this is bar' sub1/Makefile.in sub1/Makefile && exit 1
+$FGREP 'this is sub1/Makefile.am' sub1/Makefile.in
+$FGREP 'this is sub1/Makefile.am' sub1/Makefile
+
+$sleep
+for d in . sub2; do
+ sed "s|.*include.*foo\.am.*|# this is $d/Makefile.am|" $d/Makefile.am > t
+ mv -f t $d/Makefile.am
+done
+rm -f foo.am
+$MAKE all
+# Sanity checks.
+$FGREP 'this is foo' sub*/Makefile* Makefile* && exit 1
+for d in . sub1 sub2; do
+ $FGREP "this is $d/Makefile.am" $d/Makefile.in
+ $FGREP "this is $d/Makefile.am" $d/Makefile
+done
+
+:
diff --git a/t/remake-deleted-am.sh b/t/remake-deleted-am.sh
new file mode 100644
index 000000000..2204ed898
--- /dev/null
+++ b/t/remake-deleted-am.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that inclusion of '.am' fragments by automake does not suffer
+# of the "deleted header problem". Basic checks are done here.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+$ACLOCAL
+$AUTOCONF
+
+cat > Makefile.am <<'END'
+include foo.am
+include $(srcdir)/bar.am
+include $(top_srcdir)/baz.am
+END
+
+echo '# this is foo' > foo.am
+echo '# this is bar' > bar.am
+echo '# this is baz' > baz.am
+
+$AUTOMAKE
+# Sanity checks.
+$FGREP 'this is foo' Makefile.in
+$FGREP 'this is bar' Makefile.in
+$FGREP 'this is baz' Makefile.in
+
+./configure
+$MAKE # Should be no-op.
+
+$sleep
+sed '/^include foo\.am$/d' Makefile.am > t
+mv -f t Makefile.am
+rm -f foo.am
+$MAKE Makefile
+# Sanity checks.
+$FGREP 'this is foo' Makefile.in Makefile && exit 1
+$FGREP 'this is bar' Makefile.in
+$FGREP 'this is bar' Makefile
+$FGREP 'this is baz' Makefile.in
+$FGREP 'this is baz' Makefile
+
+$sleep
+echo '# empty empty' > Makefile.am
+rm -f bar.am baz.am
+$MAKE Makefile
+# Sanity checks.
+$FGREP 'empty empty' Makefile.in
+$FGREP 'empty empty' Makefile
+grep 'this is ba[rz]' Makefile Makefile.in && exit 1
+
+:
diff --git a/t/remake-deleted-m4-file.sh b/t/remake-deleted-m4-file.sh
new file mode 100644
index 000000000..ad9750f9b
--- /dev/null
+++ b/t/remake-deleted-m4-file.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when an m4 file gets removed and the macros it
+# defined get inlined into the caller. Try with both an indirect
+# call and a direct one. This can be seen as testing the "deleted
+# header file" issue w.r.t. aclocal.m4 dependencies. See also
+# related test 'aclocal-deleted-header.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+FOO_MACRO
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I m4
+.PHONY: test
+test:
+ test '$(the_answer)' -eq 42
+END
+
+macro_value='the_answer=42; AC_SUBST([the_answer])'
+
+mkdir m4
+
+cat > m4/foo.m4 <<'END'
+AC_DEFUN([FOO_MACRO], [BAR_MACRO])
+END
+
+cat > m4/bar.m4 <<END
+AC_DEFUN([BAR_MACRO], [$macro_value])
+END
+
+$ACLOCAL -I m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+$sleep
+
+sed -e "s|BAR_MACRO|$macro_value|" m4/foo.m4 > t
+mv -f t m4/foo.m4
+rm -f m4/bar.m4
+
+using_gmake || $MAKE Makefile
+$MAKE test
+
+$sleep
+
+sed -e "s|FOO_MACRO|$macro_value|" configure.ac > t
+mv -f t configure.ac
+rm -f m4/foo.m4
+
+using_gmake || $MAKE Makefile
+$MAKE test
+
+:
diff --git a/t/remake-fail.sh b/t/remake-fail.sh
new file mode 100644
index 000000000..c83b4240c
--- /dev/null
+++ b/t/remake-fail.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure remaking rules fail when they should.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+END
+mkdir sub
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure
+$MAKE
+
+$sleep
+
+# Fail for broken input files.
+
+echo "if FOO" > sub/Makefile.am
+$MAKE && exit 1
+
+: >sub/Makefile.am
+$MAKE
+
+mv Makefile.am backup
+echo "if FOO" > Makefile.am
+$MAKE && exit 1
+
+# Fail for missing input files, with or without missing
+# Makefile.in files.
+
+cp backup Makefile.am
+mv sub/Makefile.am sub/backup
+$MAKE && exit 1
+
+rm -f sub/Makefile.in
+$MAKE && exit 1
+
+mv sub/backup sub/Makefile.am
+rm -f Makefile.am
+$MAKE && exit 1
+
+rm -f Makefile.in
+$MAKE && exit 1
+
+:
diff --git a/t/remake-gnulib-add-acsubst.sh b/t/remake-gnulib-add-acsubst.sh
new file mode 100644
index 000000000..3f37f06f8
--- /dev/null
+++ b/t/remake-gnulib-add-acsubst.sh
@@ -0,0 +1,133 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when a new AC_SUBST'd variable is added, and C header
+# files are involved.
+# This test overlaps with others, and is not strictly necessary per se,
+# but it exercises a real use case (from gnulib, see:
+# <https://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00005.html>
+# for more info).
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+MY_MACROS
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I m4
+noinst_PROGRAMS = foo
+foo_SOURCES = foo.c
+BUILT_SOURCES = foo.h
+edit_h = sed -e 's|[@]foovar@|@foovar@|g'
+foo.h: foo.in.h
+ $(edit_h) < $(srcdir)/foo.in.h > $@-t
+ cat $@-t;: For debugging.
+ mv -f $@-t $@
+EXTRA_DIST = foo.in.h
+MOSTLYCLEANFILES = foo.h foo.h-t
+END
+
+mkdir m4
+
+cat > m4/foo.m4 <<'END'
+AC_DEFUN([MY_MACROS], [
+ FOO_MACRO
+dnl: ZAP_MACRO
+])
+END
+
+cat > m4/bar.m4 <<'END'
+AC_DEFUN([FOO_MACRO], [
+ foovar=42; AC_SUBST([foovar])
+dnl: barvar=47; AC_SUBST([barvar])
+])
+END
+
+cat > foo.in.h <<'END'
+#define foo @foovar@
+END
+
+cat > foo.c <<'END'
+#include "foo.h"
+int main (void) { return 0; }
+typedef int checkfoo[1 - 2 * (foo != 42)];
+END
+
+$ACLOCAL -I m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+
+: AC_SUBST @barvar@ and add it to foo.h.
+
+$sleep
+
+sed -e 's/^dnl:/ /' m4/bar.m4 > t
+mv -f t m4/bar.m4
+cat m4/bar.m4
+
+cat >> foo.in.h <<'END'
+#define bar @barvar@
+END
+
+cat >> foo.c <<'END'
+typedef int checkbar[1 - 2 * (bar != 47)];
+END
+
+cat >> Makefile.am <<'END'
+edit_h += -e 's|[@]barvar@|@barvar@|g'
+END
+
+using_gmake || $MAKE Makefile
+$MAKE
+
+: AC_SUBST @zapvar@ and add it to foo.h.
+# Do it in a slightly different way from how it was done for @barvar@.
+
+$sleep
+
+cat >> Makefile.am <<'END'
+edit_h += -e 's|[@]zapvar@|$(zapvar)|g'
+END
+
+cat >> foo.c <<'END'
+typedef int checkzap[1 - 2 * (zap != 163)];
+END
+
+sed -e 's/^dnl://' m4/foo.m4 > t
+mv -f t m4/foo.m4
+cat m4/foo.m4
+
+cat >> foo.in.h <<'END'
+#define zap @zapvar@
+END
+
+cat >> m4/bar.m4 <<'END'
+AC_DEFUN([ZAP_MACRO], [zapvar=163; AC_SUBST([zapvar])])
+END
+
+using_gmake || $MAKE Makefile
+$MAKE
+
+$MAKE distcheck
+
+:
diff --git a/t/remake-gnulib-add-header.sh b/t/remake-gnulib-add-header.sh
new file mode 100644
index 000000000..8f00063fb
--- /dev/null
+++ b/t/remake-gnulib-add-header.sh
@@ -0,0 +1,109 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when a new C header "guarded" by AC_SUBST'd
+# variables is added.
+# This test overlaps with others, and is not strictly necessary per se,
+# but it exercises a real use case (from gnulib, see:
+# <https://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00005.html>
+# for more info).
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_HEADERS([config.h])
+AC_PROG_CC
+MY_MACROS
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I .
+noinst_PROGRAMS = foo
+foo_SOURCES = foo.c
+BUILT_SOURCES = $(STDIO_H)
+stdio.h: stdio.in.h
+ cp $(srcdir)/stdio.in.h $@
+MOSTLYCLEANFILES = stdio.h
+EXTRA_DIST = stdio.in.h
+check-local:
+ ls -l . $(srcdir)
+ if test -n '$(STDIO_H)'; then \
+ test -f stdio.h || exit 1; \
+ else \
+ test ! -f stdio.h || exit 1; \
+ fi
+END
+
+cat > macros.m4 <<'END'
+AC_DEFUN([MY_MACROS], [
+ override_stdio=false
+ if $override_stdio; then
+ STDIO_H=stdio.h
+ use_dummies=1
+ else
+ STDIO_H=
+ use_dummies=0
+ fi
+ AC_SUBST([STDIO_H])
+ AC_DEFINE_UNQUOTED([USE_DUMMIES], [$use_dummies],
+ [Whether to use dummy types.])
+])
+END
+
+cat > stdio.in.h <<'END'
+typedef struct dummyfile { void *p; } DUMMYFILE;
+END
+
+cat > foo.c <<'END'
+#include <config.h>
+#include <stdio.h>
+#if USE_DUMMIES
+DUMMYFILE *f;
+#else
+FILE *f;
+#endif
+int main () { return 0; }
+END
+
+$ACLOCAL -I .
+$AUTOHEADER
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+
+$MAKE
+ls -l
+test ! -e stdio.h
+# Also try our build rules in a VPATH build.
+$MAKE distcheck
+
+# No need to sleep here: "./configure" and "make distcheck" above
+# have already slept enough.
+
+sed -e 's/^\( *override_stdio\)=.*$/\1=:/' macros.m4 > t
+mv -f t macros.m4
+
+using_gmake || $MAKE Makefile
+$MAKE
+ls -l
+test -f stdio.h
+# Also try our build rules in a VPATH build.
+$MAKE distcheck
+
+:
diff --git a/t/remake-gnulib-remove-header.sh b/t/remake-gnulib-remove-header.sh
new file mode 100644
index 000000000..ba1ade78f
--- /dev/null
+++ b/t/remake-gnulib-remove-header.sh
@@ -0,0 +1,136 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when a C header "guarded" by AC_SUBST'd variables
+# is not needed anymore, or when it's needed again.
+# This test requires some user-level machinery, overlaps with other tests,
+# and is not strictly necessary per se, but it exercises a real, important
+# use case (from gnulib, see:
+# <https://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00005.html>
+# for more info).
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_HEADERS([config.h])
+AC_PROG_CC
+MY_MACROS
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I .
+noinst_PROGRAMS = foo
+foo_SOURCES = foo.c
+BUILT_SOURCES = $(STDIO_H)
+if REPLACE_STDIO_H
+stdio.h: stdio.in.h $(top_builddir)/config.status
+ cp $(srcdir)/stdio.in.h $@
+else
+stdio.h: $(top_builddir)/config.status
+ rm -f $@
+endif
+MOSTLYCLEANFILES = stdio.h
+END
+
+cat > macros.m4 <<'END'
+AC_DEFUN([MY_MACROS], [
+ override_stdio=:
+ if $override_stdio; then
+ STDIO_H=stdio.h
+ use_dummies=1
+ else
+ STDIO_H=
+ use_dummies=0
+ fi
+ AC_SUBST([STDIO_H])
+ AC_DEFINE_UNQUOTED([USE_DUMMIES], [$use_dummies],
+ [Whether to use dummy types.])
+ AM_CONDITIONAL([REPLACE_STDIO_H], [test -n "$STDIO_H"])
+])
+END
+
+cat > stdio.in.h <<'END'
+typedef struct dummyfile { void *p; } DUMMYFILE;
+END
+
+cat > foo.c <<'END'
+#include <config.h>
+#include <stdio.h>
+#if USE_DUMMIES
+DUMMYFILE *f;
+#else
+FILE *f;
+#endif
+int main () { return 0; }
+END
+
+$ACLOCAL -I .
+$AUTOHEADER
+$AUTOMAKE
+$AUTOCONF
+
+for vpath in : false; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ # Do not reject slow dependency extractors: we need dependency tracking.
+ $srcdir/configure --enable-dependency-tracking
+ if $FGREP 'depmode=none' Makefile; then
+ skip_ "automatic dependency tracking couldn't be activated"
+ fi
+
+ $MAKE
+ ls -l
+ test -f stdio.h
+
+ # Simulate that we don't need our custom stdio.h anymore.
+
+ $sleep
+ sed -e 's/^\( *override_stdio\)=.*$/\1=false/' $srcdir/macros.m4 > t
+ diff $srcdir/macros.m4 t && fatal_ "failed to edit macros.m4"
+ mv -f t $srcdir/macros.m4
+
+ using_gmake || $MAKE Makefile
+ $MAKE
+ ls -l
+ test ! -e stdio.h
+
+ # And now simulate that we want our custom stdio.h back.
+
+ $sleep
+ sed -e 's/^\( *override_stdio\)=.*$/\1=:/' $srcdir/macros.m4 > t
+ diff $srcdir/macros.m4 t && fatal_ "failed to edit macros.m4"
+ mv -f t $srcdir/macros.m4
+
+ using_gmake || $MAKE Makefile
+ $MAKE
+ ls -l
+ test -f stdio.h
+
+ $MAKE distclean
+ cd $srcdir
+
+done
+
+:
diff --git a/t/remake-include-aclocal.sh b/t/remake-include-aclocal.sh
new file mode 100644
index 000000000..f20456518
--- /dev/null
+++ b/t/remake-include-aclocal.sh
@@ -0,0 +1,115 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules for m4 files included (also recursively) by
+# aclocal.m4. Keep in sync with sister tests:
+# - remake-include-configure.sh
+# - remake-include-makefile.sh
+
+. test-init.sh
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+magic3=%%MagicStringThree%%
+
+if using_gmake; then
+ remake="$MAKE nil"
+else
+ remake="$MAKE Makefile"
+fi
+
+cat >> configure.ac <<END
+AC_CONFIG_MACRO_DIR([m4])
+FINGERPRINT='my_fingerprint'
+AC_SUBST([FINGERPRINT])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+.PHONY: nil
+nil:
+## Used by "make distcheck" later.
+check-local:
+ test -f $(top_srcdir)/m4/foo.m4
+ test ! -r $(top_srcdir)/m4/bar.m4
+ test x'$(FINGERPRINT)' = x'DummyValue'
+END
+
+mkdir m4
+echo 'AC_DEFUN([my_fingerprint], [BadBadBad])' > m4/foo.m4
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for vpath in : false; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ top_srcdir=..
+ else
+ top_srcdir=.
+ fi
+
+ $top_srcdir/configure
+ $MAKE # Should be a no-op.
+
+ $sleep
+ echo "AC_DEFUN([my_fingerprint], [$magic1])" > $top_srcdir/m4/foo.m4
+ $remake
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile
+
+ $sleep
+ echo "AC_DEFUN([my_fingerprint], [$magic2])" > $top_srcdir/m4/foo.m4
+ $remake
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile
+
+ $sleep
+ echo "m4_include([m4/bar.m4])" > $top_srcdir/m4/foo.m4
+ echo "AC_DEFUN([my_fingerprint], [$magic3])" > $top_srcdir/m4/bar.m4
+ $remake
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile && exit 1
+ $FGREP $magic3 Makefile
+
+ $sleep
+ echo "AC_DEFUN([my_fingerprint], [$magic1])" > $top_srcdir/m4/bar.m4
+ $remake
+ $FGREP $magic2 Makefile && exit 1
+ $FGREP $magic3 Makefile && exit 1
+ $FGREP $magic1 Makefile
+
+ $sleep
+ echo "AC_DEFUN([my_fingerprint], [DummyValue])" > $top_srcdir/m4/foo.m4
+ echo "AC_DEFUN([AM_UNUSED], [NoSuchMacro])" > $top_srcdir/m4/bar.m4
+ using_gmake || $remake
+ $MAKE distcheck
+ $FGREP $magic1 Makefile && exit 1 # Sanity check.
+ $FGREP $magic2 Makefile && exit 1 # Likewise.
+ $FGREP $magic3 Makefile && exit 1 # Likewise.
+
+ $MAKE distclean
+
+ cd $top_srcdir
+
+done
+
+:
diff --git a/t/remake-include-configure.sh b/t/remake-include-configure.sh
new file mode 100644
index 000000000..2227f3a53
--- /dev/null
+++ b/t/remake-include-configure.sh
@@ -0,0 +1,112 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules for m4 files included (also recursively) by
+# configure.ac. Keep in sync with sister tests:
+# - remake-include-aclocal.sh
+# - remake-include-makefile.sh
+
+. test-init.sh
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+magic3=%%MagicStringThree%%
+
+if using_gmake; then
+ remake="$MAKE nil"
+else
+ remake="$MAKE Makefile"
+fi
+
+cat >> configure.ac <<END
+m4_include([foo.m4])
+AC_SUBST([FINGERPRINT], [my_fingerprint])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+.PHONY: nil
+nil:
+## Used by "make distcheck" later.
+check-local:
+ test -f $(top_srcdir)/foo.m4
+ test ! -r $(top_srcdir)/bar.m4
+ test x'$(FINGERPRINT)' = x'DummyValue'
+END
+
+echo 'm4_define([my_fingerprint], [BadBadBad])' > foo.m4
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for vpath in : false; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ top_srcdir=..
+ else
+ top_srcdir=.
+ fi
+
+ $top_srcdir/configure
+ $MAKE # Should be a no-op.
+
+ $sleep
+ echo "m4_define([my_fingerprint], [$magic1])" > $top_srcdir/foo.m4
+ $remake
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile
+
+ $sleep
+ echo "m4_define([my_fingerprint], [$magic2])" > $top_srcdir/foo.m4
+ $remake
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile
+
+ $sleep
+ echo "m4_include([bar.m4])" > $top_srcdir/foo.m4
+ echo "m4_define([my_fingerprint], [$magic3])" > $top_srcdir/bar.m4
+ $remake
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile && exit 1
+ $FGREP $magic3 Makefile
+
+ $sleep
+ echo "m4_define([my_fingerprint], [$magic1])" > $top_srcdir/bar.m4
+ $remake
+ $FGREP $magic2 Makefile && exit 1
+ $FGREP $magic3 Makefile && exit 1
+ $FGREP $magic1 Makefile
+
+ $sleep
+ echo "m4_define([my_fingerprint], [DummyValue])" > $top_srcdir/foo.m4
+ using_gmake || $remake
+ $MAKE distcheck
+ $FGREP $magic1 Makefile && exit 1 # Sanity check.
+ $FGREP $magic2 Makefile && exit 1 # Likewise.
+ $FGREP $magic3 Makefile && exit 1 # Likewise.
+
+ $MAKE distclean
+
+ cd $top_srcdir
+
+done
+
+:
diff --git a/t/remake-include-makefile.sh b/t/remake-include-makefile.sh
new file mode 100644
index 000000000..d3b3da0ee
--- /dev/null
+++ b/t/remake-include-makefile.sh
@@ -0,0 +1,112 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules for am files included (also recursively) by
+# Makefile.am. Keep in sync with sister tests:
+# - remake-include-aclocal.sh
+# - remake-include-configure.sh
+
+
+. test-init.sh
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+magic3=%%MagicStringThree%%
+
+if using_gmake; then
+ remake="$MAKE nil"
+else
+ remake="$MAKE Makefile"
+fi
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+.PHONY: nil
+nil:
+include foo.am
+## Used by "make distcheck" later.
+check-local:
+ test -f $(top_srcdir)/foo.am
+ test ! -r $(top_srcdir)/bar.am
+ test x'$(FINGERPRINT)' = x'DummyValue'
+END
+
+echo 'FINGERPRINT = BadBadBad' > foo.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for vpath in : false; do
+
+ if $vpath; then
+ mkdir build
+ cd build
+ top_srcdir=..
+ else
+ top_srcdir=.
+ fi
+
+ $top_srcdir/configure
+ $MAKE # Should be a no-op.
+
+ $sleep
+ echo "FINGERPRINT = $magic1" > $top_srcdir/foo.am
+ $remake
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile
+
+ $sleep
+ echo "FINGERPRINT = $magic2" > $top_srcdir/foo.am
+ $remake
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile
+
+ $sleep
+ echo 'include $(top_srcdir)/bar.am' > $top_srcdir/foo.am
+ echo "FINGERPRINT = $magic3" > $top_srcdir/bar.am
+ $remake
+ $FGREP FINGERPRINT Makefile # For debugging.
+ $FGREP $magic1 Makefile && exit 1
+ $FGREP $magic2 Makefile && exit 1
+ $FGREP $magic3 Makefile
+
+ $sleep
+ echo "FINGERPRINT = $magic1" > $top_srcdir/bar.am
+ $remake
+ $FGREP $magic2 Makefile && exit 1
+ $FGREP $magic3 Makefile && exit 1
+ $FGREP $magic1 Makefile
+
+ $sleep
+ echo "FINGERPRINT = DummyValue" > $top_srcdir/foo.am
+ using_gmake || $remake
+ $MAKE distcheck
+ $FGREP $magic1 Makefile && exit 1 # Sanity check.
+ $FGREP $magic2 Makefile && exit 1 # Likewise.
+ $FGREP $magic3 Makefile && exit 1 # Likewise.
+
+ $MAKE distclean
+
+ cd $top_srcdir
+
+done
+
+:
diff --git a/t/remake-m4-pr10111.sh b/t/remake-m4-pr10111.sh
new file mode 100644
index 000000000..b257b10a9
--- /dev/null
+++ b/t/remake-m4-pr10111.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that our remake rules doesn't give spurious successes in
+# some corner case situations where they should actually fail.
+# See automake bug#10111.
+# To be clear, we are speaking about *very* corner-case situations here,
+# and the fact that the remake rules might get confused in them is not a
+# big deal in practice (in fact, this test *currently fails*). Still,
+# keeping the limitation exposed is a good idea anyway.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+m4_include([foobar.m4])
+AC_OUTPUT
+END
+
+: > foobar.m4
+
+cat > Makefile.am <<'END'
+$(srcdir)/foobar.m4:
+ echo ': foobar was here :' > $@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# OK, so the developer wants to interactively try out how the
+# "distributed form" of his package behaves.
+$MAKE distdir
+cd $distdir
+# He's interested in trying out a VPATH build.
+mkdir build
+cd build
+../configure
+# He wants to verify that the rules he's written to rebuild a file
+# included by configure.ac works also in VPATH builds.
+rm -f ../foobar.m4
+$MAKE
+grep ': foobar was here :' ../configure
+$MAKE distcheck
+
+:
diff --git a/t/remake-macrodir.sh b/t/remake-macrodir.sh
new file mode 100644
index 000000000..aa85e0a90
--- /dev/null
+++ b/t/remake-macrodir.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the aclocal honouring of AC_CONFIG_MACRO_DIR interacts
+# nicely with automatic rebuild rules.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([macro-dir])
+my__FOO || AS_EXIT([1])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+mkdir macro-dir
+cat > macro-dir/foo.m4 <<'END'
+AC_DEFUN([my__FOO], [: > bar])
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+$FGREP my__FOO configure && exit 1
+
+./configure
+test -f bar
+rm -f bar
+
+$sleep
+
+cat > macro-dir/foo.m4 <<'END'
+AC_DEFUN([my__FOO], [: > baz])
+END
+
+$MAKE Makefile
+test -f baz
+test ! -r bar
+rm -f baz
+
+$sleep
+
+rm -f macro-dir/foo.m4
+cat > macro-dir/quux.m4 <<'END'
+AC_DEFUN([my__FOO], [: > quux])
+END
+
+$MAKE Makefile
+test -f quux
+test ! -r baz
+rm -f quux
+
+$sleep
+
+sed 's/^AC_CONFIG_MACRO_DIR/&([newdir])/' configure.ac > t
+mv -f t configure.ac
+
+mkdir newdir
+cat > newdir/mu.m4 <<'END'
+AC_DEFUN([my__FOO], [[: my__FOO do nothing]])
+END
+
+$MAKE Makefile
+$FGREP ': my__FOO do nothing' configure
+
+$MAKE distcheck
+
+:
diff --git a/t/remake-maintainer-mode.sh b/t/remake-maintainer-mode.sh
new file mode 100644
index 000000000..2c7012e5b
--- /dev/null
+++ b/t/remake-maintainer-mode.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that AM_MAINTAINER_MODE disable some rebuild rules,
+# but not all.
+# Report from Ralf Corsepius.
+
+. test-init.sh
+
+if using_gmake; then
+ remake="$MAKE"
+else
+ remake="$MAKE Makefile"
+fi
+
+cat >>configure.ac <<'EOF'
+AM_MAINTAINER_MODE
+m4_include([foo.m4])
+if test ! -f rebuild_ok; then
+ ACLOCAL=false
+ AUTOMAKE=false
+ AUTOCONF=false
+fi
+AC_OUTPUT
+EOF
+
+: > foo.m4
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE
+
+# Make sure the rules to rebuild configure/Makefile.in are not
+# triggered by default. ($MAKE will fail if they are, because the
+# tools are set to false.)
+$sleep
+touch aclocal.m4 Makefile.am configure.ac foo.m4
+$remake
+
+# Make sure the rebuild rule for Makefile is triggered.
+$sleep
+echo '# GrEpMe' >>Makefile.in
+$remake
+grep GrEpMe Makefile
+
+# Make sure the rebuild rule for config.status is triggered.
+$sleep
+grep 'AUTOCONF.*=.*false' Makefile
+: > rebuild_ok
+./configure --no-create
+$remake
+grep 'AUTOCONF.*=.*false' Makefile && exit 1
+
+# Make sure rebuild rules do work if --enable-maintainer-mode is given.
+./configure --enable-maintainer-mode
+$sleep
+echo 'AC_SUBST([YIPPY_YIPPY_YEAH])' >foo.m4
+$remake
+grep YIPPY_YIPPY_YEAH Makefile
+
+# Try the distribution, for completeness.
+$MAKE distcheck
+
+:
diff --git a/t/remake-makefile-intree.sh b/t/remake-makefile-intree.sh
new file mode 100644
index 000000000..d6bb3167f
--- /dev/null
+++ b/t/remake-makefile-intree.sh
@@ -0,0 +1,190 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test basic remake rules for Makefiles, for an *in-tree build*.
+# This testcase checks dependency of generated Makefile from Makefile.am,
+# configure.ac, acinclude.m4, aclocal.m4, and extra m4 files considered
+# by aclocal.
+# Keep this in sync with sister test 'remake-makefile-vpath.sh', which
+# performs the same checks for a VPATH build.
+
+. test-init.sh
+
+mv -f configure.ac configure.stub
+
+cat > Makefile.am <<'END'
+all-local: foo
+foo:
+ echo '!Foo!' >$@
+check-local:
+ cat foo
+ grep '!Foo!' foo
+CLEANFILES = foo
+END
+
+cat configure.stub - > configure.ac <<'END'
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+srcdir='.' # To make syncing with remake-makefile-vpath.sh easier.
+
+$srcdir/configure
+
+$MAKE
+cat foo
+grep '!Foo!' foo
+$MAKE distcheck
+
+rm -f foo
+
+# Modify just Makefile.am.
+
+$sleep
+
+cat > $srcdir/Makefile.am <<'END'
+all-local: bar
+bar:
+ echo '!Baz!' >$@
+check-local:
+ cat bar
+ grep '!Baz!' bar
+ test ! -r $(srcdir)/foo
+ test ! -r foo
+CLEANFILES = bar
+END
+
+using_gmake || $MAKE Makefile
+$MAKE
+cat bar
+grep '!Baz!' bar
+test ! -e foo
+$MAKE distcheck
+
+rm -f bar
+
+# Modify Makefile.am and configure.ac.
+
+$sleep
+
+cat > $srcdir/Makefile.am <<'END'
+check-local:
+ cat quux
+ grep '!Zardoz!' quux
+ test ! -r $(srcdir)/bar
+ test ! -r bar
+END
+
+cat $srcdir/configure.stub - > $srcdir/configure.ac <<'END'
+AC_CONFIG_FILES([quux])
+AC_SUBST([QUUX], [Zardoz])
+AC_OUTPUT
+END
+
+cat > $srcdir/quux.in <<'END'
+!@QUUX@!
+END
+
+using_gmake || $MAKE Makefile
+$MAKE
+cat quux
+grep '!Zardoz!' quux
+test ! -e bar
+$MAKE distcheck
+
+rm -f quux
+
+# Modify configure.ac and aclocal.m4 to add a directory of extra m4
+# files considered by aclocal. Also update checks in Makefile.am.
+# Note that we won't use this new directory of extra m4 files in the
+# first rebuild below (but we will in the second).
+
+$sleep
+
+mkdir $srcdir/m4
+
+cat > $srcdir/Makefile.am <<'END'
+all-local: quux
+check-local:
+ cat quux
+ grep '%Foo%' quux
+ test x'$(QUUX)' = x'%Foo%'
+END
+
+# Modify configure.ac and aclocal.m4.
+
+$sleep
+
+cat $srcdir/configure.stub - > $srcdir/configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_FILES([quux])
+MY_CUSTOM_MACRO
+AC_OUTPUT
+END
+
+cat >> $srcdir/aclocal.m4 <<'END'
+AC_DEFUN([MY_CUSTOM_MACRO], [AC_SUBST([QUUX], [%Foo%])])
+END
+
+$MAKE
+cat quux
+grep '%Foo%' quux
+$MAKE distcheck
+
+# Modify Makefile.am, remove aclocal.m4, and add a new m4 file to
+# the directory of extra m4 files considered by aclocal. This new
+# file should now provide a macro required by configure.ac and that
+# was previously provided by aclocal.m4.
+
+$sleep
+
+sed 's/%Foo%/%Bar%/g' $srcdir/Makefile.am > t
+mv -f t $srcdir/Makefile.am
+cat $srcdir/Makefile.am
+rm -f $srcdir/aclocal.m4
+cat > $srcdir/m4/blah.m4 <<'END'
+AC_DEFUN([MY_CUSTOM_MACRO], [AC_SUBST([QUUX], [%Bar%])])
+END
+
+$MAKE
+cat quux
+grep '%Bar%' quux
+$MAKE distcheck
+
+# Modify Makefile.am, remove all the extra m4 files to considered
+# by aclocal, and add an acinclude.m4 file. This last file should
+# now provide a macro required by configure.ac, and that was
+# previously provided by the extra m4 files considered by aclocal.
+
+$sleep
+
+rm -f $srcdir/m4/*.m4
+sed 's/%Bar%/%Quux%/g' $srcdir/Makefile.am > t
+mv -f t $srcdir/Makefile.am
+cat $srcdir/Makefile.am
+cat > $srcdir/acinclude.m4 <<'END'
+AC_DEFUN([MY_CUSTOM_MACRO], [AC_SUBST([QUUX], [%Quux%])])
+END
+
+$MAKE
+cat quux
+grep '%Quux%' quux
+$MAKE distcheck
+
+:
diff --git a/t/remake-makefile-vpath.sh b/t/remake-makefile-vpath.sh
new file mode 100644
index 000000000..6ec167187
--- /dev/null
+++ b/t/remake-makefile-vpath.sh
@@ -0,0 +1,192 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test basic remake rules for Makefiles, for a *VPATH build*.
+# This testcase checks dependency of generated Makefile from Makefile.am,
+# configure.ac, acinclude.m4, aclocal.m4, and extra m4 files considered
+# by aclocal.
+# Keep this in sync with sister test 'remake-makefile-instree.sh', which
+# performs the same checks for a in-tree build.
+
+. test-init.sh
+
+mv -f configure.ac configure.stub
+
+cat > Makefile.am <<'END'
+all-local: foo
+foo:
+ echo '!Foo!' >$@
+check-local:
+ cat foo
+ grep '!Foo!' foo
+CLEANFILES = foo
+END
+
+cat configure.stub - > configure.ac <<'END'
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+mkdir build
+cd build
+srcdir='..' # To make syncing with remake-makefile-intree.sh easier.
+
+$srcdir/configure
+
+$MAKE
+cat foo
+grep '!Foo!' foo
+$MAKE distcheck
+
+rm -f foo
+
+# Modify just Makefile.am.
+
+$sleep
+
+cat > $srcdir/Makefile.am <<'END'
+all-local: bar
+bar:
+ echo '!Baz!' >$@
+check-local:
+ cat bar
+ grep '!Baz!' bar
+ test ! -r $(srcdir)/foo
+ test ! -r foo
+CLEANFILES = bar
+END
+
+using_gmake || $MAKE Makefile
+$MAKE
+cat bar
+grep '!Baz!' bar
+test ! -e foo
+$MAKE distcheck
+
+rm -f bar
+
+# Modify Makefile.am and configure.ac.
+
+$sleep
+
+cat > $srcdir/Makefile.am <<'END'
+check-local:
+ cat quux
+ grep '!Zardoz!' quux
+ test ! -r $(srcdir)/bar
+ test ! -r bar
+END
+
+cat $srcdir/configure.stub - > $srcdir/configure.ac <<'END'
+AC_CONFIG_FILES([quux])
+AC_SUBST([QUUX], [Zardoz])
+AC_OUTPUT
+END
+
+cat > $srcdir/quux.in <<'END'
+!@QUUX@!
+END
+
+using_gmake || $MAKE Makefile
+$MAKE
+cat quux
+grep '!Zardoz!' quux
+test ! -e bar
+$MAKE distcheck
+
+rm -f quux
+
+# Modify configure.ac and aclocal.m4 to add a directory of extra m4
+# files considered by aclocal. Also update checks in Makefile.am.
+# Note that we won't use this new directory of extra m4 files in the
+# first rebuild below (but we will in the second).
+
+$sleep
+
+mkdir $srcdir/m4
+
+cat > $srcdir/Makefile.am <<'END'
+all-local: quux
+check-local:
+ cat quux
+ grep '%Foo%' quux
+ test x'$(QUUX)' = x'%Foo%'
+END
+
+# Modify configure.ac and aclocal.m4.
+
+$sleep
+
+cat $srcdir/configure.stub - > $srcdir/configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_FILES([quux])
+MY_CUSTOM_MACRO
+AC_OUTPUT
+END
+
+cat >> $srcdir/aclocal.m4 <<'END'
+AC_DEFUN([MY_CUSTOM_MACRO], [AC_SUBST([QUUX], [%Foo%])])
+END
+
+$MAKE
+cat quux
+grep '%Foo%' quux
+$MAKE distcheck
+
+# Modify Makefile.am, remove aclocal.m4, and add a new m4 file to
+# the directory of extra m4 files considered by aclocal. This new
+# file should now provide a macro required by configure.ac and that
+# was previously provided by aclocal.m4.
+
+$sleep
+
+sed 's/%Foo%/%Bar%/g' $srcdir/Makefile.am > t
+mv -f t $srcdir/Makefile.am
+cat $srcdir/Makefile.am
+rm -f $srcdir/aclocal.m4
+cat > $srcdir/m4/blah.m4 <<'END'
+AC_DEFUN([MY_CUSTOM_MACRO], [AC_SUBST([QUUX], [%Bar%])])
+END
+
+$MAKE
+cat quux
+grep '%Bar%' quux
+$MAKE distcheck
+
+# Modify Makefile.am, remove all the extra m4 files to considered
+# by aclocal, and add an acinclude.m4 file. This last file should
+# now provide a macro required by configure.ac, and that was
+# previously provided by the extra m4 files considered by aclocal.
+
+$sleep
+
+rm -f $srcdir/m4/*.m4
+sed 's/%Bar%/%Quux%/g' $srcdir/Makefile.am > t
+mv -f t $srcdir/Makefile.am
+cat $srcdir/Makefile.am
+cat > $srcdir/acinclude.m4 <<'END'
+AC_DEFUN([MY_CUSTOM_MACRO], [AC_SUBST([QUUX], [%Quux%])])
+END
+
+$MAKE
+cat quux
+grep '%Quux%' quux
+$MAKE distcheck
+
+:
diff --git a/t/remake-mild-stress.sh b/t/remake-mild-stress.sh
new file mode 100644
index 000000000..ecbe3c60f
--- /dev/null
+++ b/t/remake-mild-stress.sh
@@ -0,0 +1,146 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test basic remake rules for Makefiles with non-default names
+# and/or with multiple sources.
+
+. test-init.sh
+
+magic1=::MagicStringOne::
+magic2=__MagicStringTwo__
+magic3=%%MagicStringThree%%
+
+# See if the user's make implementation support an include directive.
+# We need it in this test.
+echo 'all:; @echo include is supported' > incl.mk
+echo 'include incl.mk' > gnu-style.mk
+echo '.include "incl.mk"' > bsd-style.mk
+if $MAKE -f gnu-style.mk | grep 'include is supported'; then
+ echo "$me: GNU make include style supported"
+ include_zardoz='include zardoz'
+elif $MAKE -f bsd-style.mk | grep 'include is supported'; then
+ echo "$me: BSD make include style supported"
+ include_zardoz='.include "zardoz"'
+else
+ skip_ "make doesn't support any \"include\" directive"
+fi
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([zardoz])
+AC_CONFIG_LINKS([Makefile:Makefile])
+AC_OUTPUT
+END
+
+cat > zardoz.am <<END
+EXTRA_DIST = Makefile
+#H: $magic1
+END
+
+cat > Makefile <<END
+$include_zardoz
+nil:
+.PHONY: nil
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+if using_gmake; then
+ $MAKE nil
+else
+ $MAKE Makefile
+fi
+grep '^#H:' zardoz.in # For debugging.
+$FGREP $magic1 zardoz
+$FGREP $magic1 zardoz.in
+$MAKE distcheck
+$MAKE distclean # This shouldn't remove Makefile.
+ls -l
+test -f Makefile
+
+./configure
+
+$sleep
+sed "s/%MAGIC3%/$magic3/" >> Makefile <<'END'
+my-check:
+ ls -l . $(srcdir) ;: For debugging.
+ test -f $(srcdir)/quux.am
+ test -f $(srcdir)/quux.in
+ test -f $(srcdir)/bot.in
+ test -f $(srcdir)/top.in
+ test ! -r $(srcdir)/zardoz.am
+ test ! -r $(srcdir)/zardoz.in
+ grep FOO zardoz ;: For debugging.
+ test x'$(FOO)' = x'%MAGIC3%'
+test:
+ ls -l ;: For debugging.
+ test x'$(FOO)' = x'dummy'
+.PHONY: test my-check
+END
+sed "s/^#H:.*/#H: $magic2/" zardoz.am > t
+cat >> t <<'END'
+# Used by "make distcheck" below.
+check-local: my-check
+END
+mv -f t zardoz.am
+cat zardoz.am # For debugging.
+if using_gmake; then
+ $MAKE nil
+else
+ $MAKE zardoz
+fi
+$FGREP my-check zardoz # Sanity check.
+$FGREP $magic1 zardoz zardoz.in && exit 1
+$FGREP $magic2 zardoz
+$FGREP $magic2 zardoz.in
+
+./configure
+
+$sleep
+sed 's/^\(AC_CONFIG_FILES\)(.*/\1([zardoz:top.in:quux.in:bot.in])/' \
+ <configure.ac >t
+mv -f t configure.ac
+cat configure.ac # For debugging.
+sed '/^#H:/d' zardoz.am > quux.am
+echo 'FOO = dummy' >> quux.am
+echo 'BAR = $(BAZ)' > top.in
+echo "BAZ = $magic3" > bot.in
+is_gmake || $MAKE zardoz
+$MAKE test
+$FGREP my-check zardoz # Sanity check.
+$FGREP $magic3 quux.in && exit 1
+$FGREP $magic3 zardoz
+$FGREP $magic1 zardoz && exit 1
+$FGREP $magic2 zardoz && exit 1
+# After the remake above, the files 'zardoz.am' and 'zardoz.in'
+# should be no more needed.
+echo 'endif' > zardoz.am # Put in a syntax error.
+is_gmake || $MAKE zardoz
+$MAKE test
+rm -f zardoz.in zardoz.am # Get rid of them.
+is_gmake || $MAKE zardoz
+$MAKE test
+
+echo 'FOO = $(BAR)' >> quux.am
+is_gmake || $MAKE zardoz
+$MAKE distcheck
+
+:
diff --git a/t/remake-moved-m4-file.sh b/t/remake-moved-m4-file.sh
new file mode 100644
index 000000000..98e17d5eb
--- /dev/null
+++ b/t/remake-moved-m4-file.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when m4 files get moved among different "include
+# dirs" (i.e. those passed to aclocal with '-I' option).
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+MY_MACRO
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I d1 -I d2 -I d3
+.PHONY: test
+test:
+ test '$(the_answer)' -eq 42
+END
+
+mkdir d1 d2 d3
+
+cat > d1/macros.m4 <<'END'
+AC_DEFUN([MY_MACRO], [FOO])
+END
+
+cat > d1/foo.m4 <<'END'
+AC_DEFUN([FOO], [the_answer=42; AC_SUBST([the_answer])])
+END
+
+$ACLOCAL -I d1
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+# Move one file.
+mv d1/foo.m4 d2/foo.m4
+using_gmake || $MAKE Makefile
+$MAKE test
+$MAKE distdir
+ls -l $distdir $distdir/*
+test -f $distdir/d2/foo.m4
+test ! -e $distdir/d1/foo.m4
+test -f $distdir/d1/macros.m4
+test ! -e $distdir/d2/macros.m4
+
+# Move both files at once.
+mv d1/macros.m4 d3/macros.m4
+mv d2/foo.m4 d3/foo.m4
+using_gmake || $MAKE Makefile
+$MAKE test
+$MAKE distdir
+ls -l $distdir $distdir/*
+test -f $distdir/d3/foo.m4
+test -f $distdir/d3/macros.m4
+test ! -e $distdir/d1/foo.m4
+test ! -e $distdir/d2/foo.m4
+test ! -e $distdir/d1/macros.m4
+test ! -e $distdir/d2/macros.m4
+
+:
diff --git a/t/remake-not-after-make-dist.sh b/t/remake-not-after-make-dist.sh
new file mode 100644
index 000000000..5f41c8d1b
--- /dev/null
+++ b/t/remake-not-after-make-dist.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Makefile.in are up to date after make dist.
+# This is expected to work even without GNU Make (the GNU Make
+# feature that isn't supported elsewhere is the rebuild of
+# Makefile dependencies during ordinary builds).
+#
+# If this fails, this is likely to be due to a dependency being
+# given two different name. For instance BSD Make does not know
+# that 'Makefile' is the same as './Makefile'
+#
+# Report from Akim Demaille.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+# Rebuild rule are ok until make dist, but not afterwards.
+if test ! -f rebuild_ok; then
+ ACLOCAL=false
+ AUTOMAKE=false
+ AUTOCONF=false
+fi
+AC_OUTPUT
+EOF
+
+: > rebuild_ok
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE
+$sleep
+touch aclocal.m4
+$MAKE distdir
+cd $me-1.0
+test ! -f rebuild_ok
+./configure
+$MAKE
+
+:
diff --git a/t/remake-recurs-user.sh b/t/remake-recurs-user.sh
new file mode 100644
index 000000000..665dc3d16
--- /dev/null
+++ b/t/remake-recurs-user.sh
@@ -0,0 +1,89 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Remake rules and user-defined recursive rules.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+m4_include([extra-targets.m4])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+echo 'AM_EXTRA_RECURSIVE_TARGETS([foo])' > extra-targets.m4
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+all-local: foo
+foo-local:
+ : > foo
+bar-local:
+ : > bar
+MOSTLYCLEANFILES = foo
+END
+
+mkdir sub
+cat > sub/Makefile.am << 'END'
+foo-local:
+ : > foo2
+MOSTLYCLEANFILES = foo2
+bar-local: later-target
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE
+test -f foo
+test -f sub/foo2
+test ! -f bar
+test ! -f sub/zardoz
+$MAKE distcheck
+
+$sleep
+
+echo 'AM_EXTRA_RECURSIVE_TARGETS([bar])' >> extra-targets.m4
+
+cat >> Makefile.am <<'END'
+MOSTLYCLEANFILES += bar oof
+all-local: bar
+foo-local: oof
+oof:
+ : > $@
+END
+
+echo 'include $(srcdir)/more.am' >> sub/Makefile.am
+
+cat > sub/more.am << 'END'
+later-target:
+ : > zardoz
+DISTCLEANFILES = zardoz
+END
+
+using_gmake || $MAKE Makefile
+$MAKE
+test -f foo
+test -f oof
+test -f sub/foo2
+test -f bar
+test -f sub/zardoz
+$MAKE distcheck
+
+:
diff --git a/t/remake-renamed-am.sh b/t/remake-renamed-am.sh
new file mode 100644
index 000000000..2aa26c424
--- /dev/null
+++ b/t/remake-renamed-am.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that inclusion of '.am' fragments by automake does not suffer
+# of the "deleted header problem". This test checks that we can rename
+# an included .am file without confusing the remake rules.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+include foo.am
+END
+
+cat > foo.am <<'END'
+all-local:
+ echo ok > has-run-1
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE
+test -f has-run-1
+
+$sleep
+rm -f has-run-1
+mv -f foo.am bar.am
+echo include bar.am > Makefile.am
+$MAKE Makefile
+$FGREP 'foo.am' Makefile Makefile.in && exit 1
+
+$sleep
+rm -f has-run-1 bar.am
+echo 'all-local:; echo ok > has-run-2' > zardoz.am
+echo 'include $(srcdir)/zardoz.am' > Makefile.am
+using_gmake || $MAKE Makefile
+$MAKE
+test ! -e has-run-1
+test -f has-run-2
+
+:
diff --git a/t/remake-renamed-m4-file.sh b/t/remake-renamed-m4-file.sh
new file mode 100644
index 000000000..57e199488
--- /dev/null
+++ b/t/remake-renamed-m4-file.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when m4 files get renamed.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+MY_MACRO
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I m4
+.PHONY: test
+test:
+ test '$(the_answer)' -eq 42
+END
+
+mkdir m4
+
+cat > m4/macros.m4 <<'END'
+AC_DEFUN([MY_MACRO], [FOO])
+END
+
+cat > m4/foo.m4 <<'END'
+AC_DEFUN([FOO], [the_answer=42; AC_SUBST([the_answer])])
+END
+
+$ACLOCAL -I m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+# Rename one file at the time.
+
+mv m4/foo.m4 m4/bar.m4
+using_gmake || $MAKE Makefile
+$MAKE test
+$MAKE distdir
+ls -l $distdir $distdir/*
+test -f $distdir/m4/bar.m4
+test ! -e $distdir/m4/foo.m4
+
+mv m4/macros.m4 m4/defs.m4
+using_gmake || $MAKE Makefile
+$MAKE test
+$MAKE distdir
+ls -l $distdir $distdir/*
+test -f $distdir/m4/defs.m4
+test ! -e $distdir/m4/macros.m4
+
+# Rename both files at once.
+
+mv m4/bar.m4 m4/quux.m4
+mv m4/defs.m4 acinclude.m4
+using_gmake || $MAKE Makefile
+$MAKE test
+$MAKE distdir
+ls -l $distdir $distdir/*
+test -f $distdir/m4/quux.m4
+test -f $distdir/acinclude.m4
+test ! -e $distdir/m4/foo.m4
+test ! -e $distdir/m4/bar.m4
+test ! -e $distdir/m4/macros.m4
+test ! -e $distdir/m4/defs.m4
+
+:
diff --git a/t/remake-renamed-m4-macro-and-file.sh b/t/remake-renamed-m4-macro-and-file.sh
new file mode 100644
index 000000000..72adcc640
--- /dev/null
+++ b/t/remake-renamed-m4-macro-and-file.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when an m4 file gets renamed and *simultaneously*
+# an m4 macro in it gets renamed. Kudos to Bruno Haible for thinking
+# about this situation. See also related test 'aclocal-deleted-header.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+MY_MACRO
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I m4
+.PHONY: test
+test:
+ test '$(the_answer)' -eq 42
+END
+
+mkdir m4
+
+cat > m4/macros.m4 <<'END'
+AC_DEFUN([MY_MACRO], [FOO_MACRO])
+END
+
+cat > m4/foo.m4 <<'END'
+AC_DEFUN([FOO_MACRO], [the_answer=42; AC_SUBST([the_answer])])
+END
+
+$ACLOCAL -I m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+# Rename only one file and one macro.
+
+$sleep
+sed -e 's/FOO_MACRO/BAR_MACRO/' m4/foo.m4 > m4/bar.m4
+rm -f m4/foo.m4
+sed -e 's/FOO_MACRO/BAR_MACRO/' m4/macros.m4 > t
+mv -f t m4/macros.m4
+using_gmake || $MAKE Makefile
+$MAKE test
+$MAKE distdir
+ls -l $distdir $distdir/*
+test -f $distdir/m4/bar.m4
+test -f $distdir/m4/macros.m4
+test ! -e $distdir/m4/foo.m4
+
+# Rename both at once.
+
+$sleep
+sed -e 's/BAR_MACRO/QUUX_MACRO/' \
+ m4/bar.m4 > m4/quux.m4
+sed -e 's/BAR_MACRO/QUUX_MACRO/' -e 's/MY_MACRO/A_MACRO/' \
+ m4/macros.m4 > m4/defs.m4
+rm -f m4/macros.m4 m4/bar.m4
+sed -e 's/BAR_MACRO/QUUX_MACRO/' -e 's/MY_MACRO/A_MACRO/' configure.ac > t
+mv -f t configure.ac
+using_gmake || $MAKE Makefile
+$MAKE test
+$MAKE distdir
+ls -l $distdir $distdir/*
+test -f $distdir/m4/quux.m4
+test -f $distdir/m4/defs.m4
+test ! -e $distdir/m4/bar.m4
+test ! -e $distdir/m4/macros.m4
+
+:
diff --git a/t/remake-renamed-m4-macro.sh b/t/remake-renamed-m4-macro.sh
new file mode 100644
index 000000000..4bd9edb5d
--- /dev/null
+++ b/t/remake-renamed-m4-macro.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test remake rules when the name of an m4 macro change. Try both with
+# and without indirection.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+MY_MACRO
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I m4
+.PHONY: test
+test:
+ test '$(the_answer)' -eq 42
+END
+
+mkdir m4
+
+cat > m4/macros.m4 <<'END'
+AC_DEFUN([MY_MACRO], [FOO_1])
+END
+
+cat > m4/foo.m4 <<'END'
+AC_DEFUN([FOO_1], [the_answer=42
+ AC_SUBST([the_answer])])
+END
+
+$ACLOCAL -I m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+$sleep
+
+for x in macros foo; do
+ sed -e 's/FOO_1/FOO_2/' m4/$x.m4 > t
+ mv -f t m4/$x.m4
+done
+
+using_gmake || $MAKE Makefile
+$MAKE test
+
+$sleep
+
+for f in m4/macros.m4 configure.ac; do
+ sed -e 's/MY_MACRO/YOUR_MACRO/' $f > t
+ mv -f t $f
+done
+
+using_gmake || $MAKE Makefile
+$MAKE test
+
+:
diff --git a/t/remake-subdir-from-subdir.sh b/t/remake-subdir-from-subdir.sh
new file mode 100644
index 000000000..c63de118c
--- /dev/null
+++ b/t/remake-subdir-from-subdir.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that remake rules works for adding a new subdirectory from a
+# pre-existing subdirectory.
+# See also the other similar tests 'remake-subdir*.sh', and the
+# related test 'aclocal5.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+m4_include([subdirs.m4])
+AC_SUBST([MAGIC], [magic])
+AC_OUTPUT
+END
+
+echo 'AC_CONFIG_FILES([sub/Makefile])' > subdirs.m4
+echo 'SUBDIRS = sub' > Makefile.am
+
+mkdir sub
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+
+cd sub
+$sleep
+echo 'AC_CONFIG_FILES([sub/subsub/Makefile])' >> ../subdirs.m4
+echo 'SUBDIRS = subsub' >> Makefile.am
+mkdir subsub
+cat > subsub/Makefile.am <<'END'
+all-local:
+ : > ok-it-works
+END
+using_gmake || $MAKE Makefile
+$MAKE
+test -f subsub/ok-it-works
+
+:
diff --git a/t/remake-subdir-gnu.sh b/t/remake-subdir-gnu.sh
new file mode 100644
index 000000000..cbc4aae55
--- /dev/null
+++ b/t/remake-subdir-gnu.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that remake rules works from subdirectories, even using
+# 'GNUmakefile' as makefiles name. This obviously requires GNU
+# make.
+# See also the other similar tests 'remake-subdir*.sh', and the
+# related test 'aclocal5.sh'
+
+required=GNUmake
+. test-init.sh
+
+magic1='::MagicString::One::'
+magic2='__MagicString__Two__'
+
+debug_info ()
+{
+ grep -i magic configure GNUmakefile.in GNUmakefile \
+ sub/GNUmakefile.in sub/GNUmakefile
+}
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([GNUmakefile sub/GNUmakefile])
+AC_SUBST([MAGIC], [magic])
+AC_OUTPUT
+END
+
+cat > GNUmakefile.am <<'END'
+SUBDIRS = sub
+END
+
+mkdir sub
+: > sub/GNUmakefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+debug_info
+
+$sleep
+sed "s|magic|$magic1|" configure.ac > t
+mv -f t configure.ac
+cd sub
+$MAKE
+cd ..
+debug_info
+$FGREP $magic1 configure
+$FGREP $magic1 GNUmakefile
+$FGREP $magic1 sub/GNUmakefile
+
+$sleep
+cd sub
+echo MAGIC = $magic2 >> GNUmakefile.am
+$MAKE
+cd ..
+debug_info
+$FGREP $magic2 sub/GNUmakefile
+$FGREP $magic2 sub/GNUmakefile.in
+$FGREP $magic1 sub/GNUmakefile sub/GNUmakefile.in && exit 1
+$FGREP $magic2 GNUmakefile GNUmakefile.in && exit 1
+
+:
diff --git a/t/remake-subdir-grepping.sh b/t/remake-subdir-grepping.sh
new file mode 100644
index 000000000..8c005e79c
--- /dev/null
+++ b/t/remake-subdir-grepping.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Weak "grepping" test trying to ensure that remaking rules in a subdir
+# are correctly generated.
+# See also sister functional test 'remake-subdir-only.sh'.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^Makefile' sub/Makefile.in
+grep '\$(AUTOMAKE).* sub/Makefile' sub/Makefile.in
+
+:
diff --git a/t/remake-subdir-long-time.sh b/t/remake-subdir-long-time.sh
new file mode 100644
index 000000000..e07dfa7a7
--- /dev/null
+++ b/t/remake-subdir-long-time.sh
@@ -0,0 +1,114 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that remake rules from subdirectories do not hang or cycle
+# endlessly, even with build systems that takes several seconds to
+# rebuild the Makefiles.
+# This test tries to ensure a long-enough rebuild time by introducing
+# an explicit delay in the build process.
+# Suggestion by Ralf Wildenhues.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([foreign -Wall -Werror])
+AC_CONFIG_FILES([Makefile sub/Makefile])
+AC_SUBST([MAGIC], [magic])
+AC_OUTPUT
+END
+
+echo SUBDIRS = sub > Makefile.am
+mkdir sub
+: > sub/Makefile.am
+
+# Both aclocal and automake are expected to run one and just one time.
+# Create and use wrappers that will verify that.
+
+ocwd=$(pwd) || fatal_ "cannot get current working directory"
+
+mkdir bin
+
+cat > bin/automake <<END
+#!/bin/sh
+set -e
+PATH='$PATH'; export PATH
+sentinel='$ocwd/automake-has-run'
+if test -f "\$sentinel"; then
+ echo "Automake has been run more than one time" >&2
+ exit 1
+else
+ echo automake has run > "\$sentinel"
+fi
+$sleep; $sleep;
+exec $AUTOMAKE \${1+"\$@"}
+END
+chmod a+x bin/automake
+
+cat > bin/aclocal <<END
+#!/bin/sh
+set -e
+PATH='$PATH'; export PATH
+sentinel='$ocwd/aclocal-has-run'
+if test -f "\$sentinel"; then
+ echo "Aclocal has been run more than one time" >&2
+ exit 1
+else
+ echo aclocal has run > "\$sentinel"
+fi
+$sleep; $sleep;
+exec $ACLOCAL \${1+"\$@"}
+END
+chmod a+x bin/aclocal
+
+# Just to be sure.
+cp bin/automake bin/automake-$APIVERSION
+cp bin/aclocal bin/aclocal-$APIVERSION
+
+PATH=$ocwd/bin$PATH_SEPARATOR$PATH; export PATH
+
+AUTOMAKE=automake ACLOCAL=aclocal; export AUTOMAKE ACLOCAL
+
+$ACLOCAL # Should use or just-defined wrapper.
+$AUTOMAKE # Likewise.
+$AUTOCONF
+
+# Sanity check: the wrappers have been used.
+test -f automake-has-run
+test -f aclocal-has-run
+rm -f automake-has-run aclocal-has-run
+
+./configure
+# Sanity check: Makefile doesn't get updated uselessly.
+run_make ACLOCAL=false AUTOMAKE=false AUTOCONF=false
+
+$sleep
+sed "s|magic|magic2|" configure.ac > t
+mv -f t configure.ac
+
+cd sub
+run_make Makefile AUTOMAKE="$AUTOMAKE" ACLOCAL="$ACLOCAL"
+cd ..
+
+# For debugging.
+ls -l . sub
+grep -i magic configure Makefile.in Makefile sub/Makefile.in sub/Makefile
+# Sanity checks.
+$FGREP magic2 configure
+$FGREP magic2 Makefile
+$FGREP magic2 sub/Makefile
+
+:
diff --git a/t/remake-subdir-no-makefile.sh b/t/remake-subdir-no-makefile.sh
new file mode 100644
index 000000000..bfe2705dc
--- /dev/null
+++ b/t/remake-subdir-no-makefile.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure that remake rules work for files in a subdirectory even when
+# there is no Makefile for that subdirectory.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/foo])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+all-local: sub/foo
+END
+
+mkdir sub
+: > sub/foo.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+# First a VPATH build.
+mkdir build
+cd build
+../configure
+$sleep
+test -f sub/foo
+test ! -s sub/foo
+echo '#GrepMe#' > ../sub/foo.in
+$MAKE
+grep '#GrepMe#' sub/foo
+
+cd ..
+
+# Now try an in-tree build.
+: > sub/foo.in # Restore its original (empty) content.
+./configure
+$sleep
+test -f sub/foo
+test ! -s sub/foo
+echo '#GrepMe#' > sub/foo.in
+$MAKE
+grep '#GrepMe#' sub/foo
+
+# Finally try to check the distribution.
+$sleep
+echo '%GrepMe%' > sub/foo.in
+cat >>Makefile.am <<END
+check-local:
+ grep '%GrepMe%' sub/foo
+END
+$MAKE
+grep "grep '%GrepMe%' sub/foo" Makefile.in # Sanity check.
+$MAKE distcheck
+
+:
diff --git a/t/remake-subdir-only.sh b/t/remake-subdir-only.sh
new file mode 100644
index 000000000..8a4bfaffd
--- /dev/null
+++ b/t/remake-subdir-only.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure remaking rules in subdir are correctly generated.
+# See also sister "grepping" test 'remake-subdir-grepping.sh'.
+
+. test-init.sh
+
+fingerprint='=/FiNgErPrInT/='
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# Rebuild rules should work even if there is no top-level
+# makefiles, if we are careful enough to trigger them only
+# in proper subdirs.
+$sleep
+echo "# $fingerprint" > sub/Makefile.am
+cd sub
+$MAKE Makefile
+cd ..
+# Check that no spurious Makefile has been created in the
+# top-level directory.
+test ! -e Makefile
+# Check that the Makefile in the subdirectory has been properly
+# updated.
+$FGREP "$fingerprint" sub/Makefile
+
+:
diff --git a/t/remake-subdir.sh b/t/remake-subdir.sh
new file mode 100644
index 000000000..7a5d0825a
--- /dev/null
+++ b/t/remake-subdir.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that remake rules works from subdirectories, even with non-GNU
+# make implementations.
+# See also the other similar tests 'remake-subdir*.sh', and the
+# related test 'aclocal5.sh'.
+
+. test-init.sh
+
+if using_gmake; then
+ remake=$MAKE
+else
+ remake="$MAKE Makefile"
+fi
+
+magic1='::MagicString::One::'
+magic2='__MagicString__Two__'
+
+debug_info ()
+{
+ grep -i magic configure Makefile.in Makefile sub/Makefile.in sub/Makefile
+}
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_SUBST([MAGIC], [magic])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+END
+
+mkdir sub
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+debug_info
+
+$sleep
+sed "s|magic|$magic1|" configure.ac > t
+mv -f t configure.ac
+cd sub
+$remake
+cd ..
+debug_info
+$FGREP $magic1 configure
+$FGREP $magic1 Makefile
+$FGREP $magic1 sub/Makefile
+
+$sleep
+cd sub
+echo MAGIC = $magic2 >> Makefile.am
+$remake
+cd ..
+debug_info
+$FGREP $magic2 sub/Makefile
+$FGREP $magic2 sub/Makefile.in
+$FGREP $magic1 sub/Makefile sub/Makefile.in && exit 1
+$FGREP $magic2 Makefile Makefile.in && exit 1
+
+:
diff --git a/t/remake-subdir2.sh b/t/remake-subdir2.sh
new file mode 100644
index 000000000..6ec23a49c
--- /dev/null
+++ b/t/remake-subdir2.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that remake rules works from subdirectories, even when makefiles
+# are not named "Makefile".
+# See also the other similar tests 'remake-subdir*.sh', and the
+# related test 'aclocal5.sh'.
+
+. test-init.sh
+
+magic1='::MagicString::One::'
+magic2='__MagicString__Two__'
+
+debug_info ()
+{
+ grep -i magic configure build.in build.mk sub/build.in sub/build.mk
+}
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([build.mk:build.in])
+AC_CONFIG_FILES([sub/build.mk:sub/build.in])
+AC_SUBST([MAGIC], [magic])
+AC_OUTPUT
+END
+
+cat > build.am <<'END'
+AM_MAKEFLAGS = -f build.mk
+SUBDIRS = sub
+END
+
+mkdir sub
+cat > sub/build.am <<'END'
+AM_MAKEFLAGS = -f build.mk
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+ls -l # For debugging.
+
+$MAKE -f build.mk
+debug_info
+
+$sleep
+sed "s|magic|$magic1|" configure.ac > t
+mv -f t configure.ac
+cd sub
+$MAKE -f build.mk build.mk
+cd ..
+debug_info
+$FGREP $magic1 configure
+$FGREP $magic1 build.mk
+$FGREP $magic1 sub/build.mk
+
+$sleep
+cd sub
+echo MAGIC = $magic2 >> build.am
+$MAKE -f build.mk build.mk
+cd ..
+debug_info
+$FGREP $magic2 sub/build.mk
+$FGREP $magic2 sub/build.in
+$FGREP $magic1 sub/build.in sub/build.mk && exit 1
+$FGREP $magic2 build.in build.mk && exit 1
+
+:
diff --git a/t/remake-subdir3.sh b/t/remake-subdir3.sh
new file mode 100644
index 000000000..0dbd673fb
--- /dev/null
+++ b/t/remake-subdir3.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure remaking rules work when subdir Makefile.in has been removed.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+END
+mkdir sub
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure
+$MAKE
+
+do_check ()
+{
+ run_make -O
+ test $(grep -c "/missing " stdout) -eq 1
+}
+
+# Now, we are set up. Ensure that, for either missing Makefile.in,
+# or updated Makefile.am, rebuild rules are run, and run exactly once
+# only.
+
+rm -f Makefile.in
+do_check
+
+rm -f sub/Makefile.in
+do_check
+
+$sleep # Let touched files appear newer.
+
+touch Makefile.am
+do_check
+
+touch sub/Makefile.am
+do_check
+
+:
diff --git a/t/remake-timing-bug-pr8365.sh b/t/remake-timing-bug-pr8365.sh
new file mode 100644
index 000000000..c94971e3c
--- /dev/null
+++ b/t/remake-timing-bug-pr8365.sh
@@ -0,0 +1,106 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for automake bug#8365, related to Makefile remake rules.
+# The bug is due to subtle timestamp issues and limitations in
+# make's behaviour, and is very unlikely to be triggered (we have
+# to resort to timestamp edit hacks to consistently expose it); in
+# any account, it is nigh to impossible to trigger it by running
+# make by hand. Thus, fixing it would not be worth the hassle, but
+# we prefer to keep it exposed anyway.
+
+. test-init.sh
+
+# We'll use calls to stat to get debugging information.
+if stat /dev/null; then stat=stat; else stat=:; fi
+
+cat >> configure.ac << 'END'
+FOOBAR=zardoz
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+$ACLOCAL
+# Run automake *before* autoconf, because we want to ensure that
+# Makefile.in is not newer than configure.
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE Makefile
+# Sanity check.
+$EGREP 'FOOBAR|zardoz' Makefile && fatal_ 'unexpected AC_SUBST in Makefile'
+
+echo 'AC_SUBST([FOOBAR])' >> configure.ac
+
+# Modified configure dependencies must have the same timestamp of
+# config.status and Makefile in order to trigger the bug.
+# We also re-touch config.status, because "touch -r" can truncate
+# timestamps on file systems with sub-second resolutions (see the
+# autoconf manual). Finally, we also sleep before touching, to ensure
+# that the (possibly truncated) timestamps of config.status etc. are
+# strictly newer than the non-truncated configure timestamp.
+$stat config.status Makefile configure.ac
+$sleep
+touch config.status
+touch -r config.status config.status Makefile configure.ac
+$stat config.status Makefile configure.ac
+
+# Also, the race condition is triggered only when aclocal, automake
+# and aclocal run fast enough to keep the timestamp of the generated
+# aclocal.m4, Makefile.in and configure equal to the timestamp of
+# Makefile & config.status. To reproduce this race consistently, we
+# need the following hackish wrappers.
+
+cat > aclocal-wrap <<END
+#!/bin/sh
+set -ex
+# aclocal shouldn't use our autoconf wrapper when extracting
+# the races from configure.ac.
+AUTOCONF='$AUTOCONF'; export AUTOCONF
+$ACLOCAL "\$@"
+touch -r config.status aclocal.m4
+$stat aclocal.m4
+END
+
+cat > automake-wrap <<END
+#!/bin/sh
+set -ex
+# automake shouldn't use our autoconf wrapper when extracting
+# the races from configure.ac.
+AUTOCONF='$AUTOCONF'; export AUTOCONF
+$AUTOMAKE "\$@"
+touch -r config.status Makefile.in
+$stat Makefile.in
+END
+
+cat > autoconf-wrap <<END
+#!/bin/sh
+set -ex
+$AUTOCONF "\$@"
+touch -r config.status configure
+$stat configure
+END
+
+chmod a+x aclocal-wrap automake-wrap autoconf-wrap
+
+run_make Makefile \
+ ACLOCAL=./aclocal-wrap AUTOMAKE=./automake-wrap AUTOCONF=./autoconf-wrap
+grep '^FOOBAR =' Makefile.in
+grep '^FOOBAR *= *zardoz *$' Makefile
+
+:
diff --git a/t/repeated-options.sh b/t/repeated-options.sh
new file mode 100644
index 000000000..d4c25bc7c
--- /dev/null
+++ b/t/repeated-options.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake does not complain on repeated options, nor
+# generate broken or incorrect makefiles.
+
+required='cc bzip2'
+. test-init.sh
+
+cat >configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip no-dist-gzip dist-bzip2])
+AC_PROG_CC
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = parallel-tests subdir-objects subdir-objects
+AUTOMAKE_OPTIONS += dist-bzip2 parallel-tests
+TESTS = foo.test
+EXTRA_DIST = $(TESTS)
+TESTS_ENVIRONMENT = EXEEXT='$(EXEEXT)'
+bin_PROGRAMS = sub/foo
+.PHONY: test-build
+test-build:
+ ls -l . sub
+ test -f sub/foo.$(OBJEXT)
+ test -f sub/foo$(EXEEXT)
+END
+
+mkdir sub
+
+cat > foo.test <<'END'
+#!/bin/sh
+test -f sub/foo$EXEEXT && test -x sub/foo$EXEEXT
+END
+chmod a+x foo.test
+
+cat > sub/foo.c <<'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+cp "$am_scriptdir"/test-driver .
+
+$ACLOCAL
+$AUTOMAKE --foreign --foreign -Wall 2>stderr || { cat stderr >&2; exit 1; }
+test -s stderr && { cat stderr >&2; exit 1; }
+rm -f stderr
+$AUTOCONF
+
+./configure
+$MAKE
+$MAKE test-build
+$MAKE check
+ls -l
+test -f foo.log
+test -f test-suite.log
+$MAKE clean
+$MAKE distcheck
+ls -l
+test -f $me-1.0.tar.bz2
+test ! -e $me-1.0.tar.gz
+
+:
diff --git a/t/reqd2.sh b/t/reqd2.sh
new file mode 100644
index 000000000..42d575374
--- /dev/null
+++ b/t/reqd2.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for a bug reported by Andrew Suffield.
+# (Automake goes wild and try to rerun itself more than two time
+# to fix the Makefiles.)
+
+required='libtoolize'
+. test-init.sh
+
+cat > configure.ac << 'END'
+AC_INIT([req2], [1.0])
+AC_CONFIG_AUX_DIR([autoconf])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_PROG_CC
+AM_PROG_AR
+AM_PROG_LIBTOOL
+AC_CONFIG_FILES([autoconf/Makefile main/Makefile])
+AC_OUTPUT
+END
+
+mkdir autoconf
+mkdir main
+
+: > autoconf/Makefile.am
+echo 'SUBDIRS = autoconf main' >Makefile.am
+
+cat >main/Makefile.am <<'END'
+lib_LTLIBRARIES = lib0.la
+lib0_la_SOURCES = 0.c
+END
+
+: > ar-lib
+libtoolize --force --copy
+$ACLOCAL
+$AUTOCONF
+
+test -f autoconf/ltmain.sh # Sanity check.
+rm -f autoconf/ltmain.sh
+AUTOMAKE_fails --add-missing --copy
+grep '^configure\.ac:7:.* required file.*autoconf/ltmain\.sh' stderr
+
+:
diff --git a/t/rm-f-probe.sh b/t/rm-f-probe.sh
new file mode 100644
index 000000000..d8389ce46
--- /dev/null
+++ b/t/rm-f-probe.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Verify our probe that checks that "rm -f" doesn't complain if called
+# without file operands works as expected. See automake bug#10828.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+mkdir bin
+cat > bin/rm <<'END'
+#!/bin/sh
+set -e; set -u;
+PATH=$original_PATH; export PATH
+rm_opts=
+while test $# -gt 0; do
+ case $1 in
+ -*) rm_opts="$rm_opts $1";;
+ *) break;;
+ esac
+ shift
+done
+if test $# -eq 0; then
+ echo "Oops, fake rm called without arguments" >&2
+ exit 1
+else
+ exec rm $rm_opts "$@"
+fi
+END
+chmod a+x bin/rm
+
+original_PATH=$PATH
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH
+export PATH original_PATH
+
+rm -f && exit 99 # Sanity check.
+
+./configure 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+
+grep "'rm' program.* unable to run without file operands" stderr
+$FGREP "tell bug-automake@gnu.org about your system" stderr
+$FGREP "install GNU coreutils" stderr
+$EGREP "(^| |')ACCEPT_INFERIOR_RM_PROGRAM($| |')" stderr
+
+ACCEPT_INFERIOR_RM_PROGRAM=yes; export ACCEPT_INFERIOR_RM_PROGRAM
+
+./configure
+$MAKE
+$MAKE distcheck
+
+# For the sake of our exit trap.
+PATH=$original_PATH; export PATH
+
+:
diff --git a/t/rulepat.sh b/t/rulepat.sh
new file mode 100644
index 000000000..394520af9
--- /dev/null
+++ b/t/rulepat.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure RULE_PATTERN catches strange targets.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+$(srcdir)/Makefile.am:
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^$(srcdir)/Makefile\.am' Makefile.in
+
+:
diff --git a/t/sanity.sh b/t/sanity.sh
new file mode 100644
index 000000000..dee123aea
--- /dev/null
+++ b/t/sanity.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Unsafe absolute directory names should be diagnosed.
+
+. test-init.sh
+
+mkdir 'unsafe$'
+cd 'unsafe$'
+
+mv ../configure.ac .
+mv ../install-sh ../missing .
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'unsafe absolute working directory' stderr
+
+cd ..
+mkdir build
+cd build
+../unsafe$/configure 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'unsafe srcdir' stderr
+
+:
diff --git a/t/seenc.sh b/t/seenc.sh
new file mode 100644
index 000000000..5cea239c4
--- /dev/null
+++ b/t/seenc.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure C-but-not-CC error works.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+dnl AC_PROG_CC and AC_PROG_CXX missing on purpose
+AC_LIBOBJ([fsusage])
+AC_LIBOBJ([mountlist])
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = x.C
+foo_LDADD = @LIBOBJS@
+END
+
+: > fsusage.c
+: > mountlist.c
+
+$ACLOCAL
+AUTOMAKE_fails
+grep ' C source.*CC.* undefined' stderr
+grep 'define .*CC.* add .*AC_PROG_CC' stderr
+grep ' C++ source.*CXX.* undefined' stderr
+grep 'define .*CXX.* add .*AC_PROG_CXX' stderr
+
+:
diff --git a/t/self-check-cc-no-c-o.sh b/t/self-check-cc-no-c-o.sh
new file mode 100644
index 000000000..115661465
--- /dev/null
+++ b/t/self-check-cc-no-c-o.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that our fake "C compiler" that doesn't grasp the '-c' and
+# '-o' command-line options passed together, used to enhance testsuite
+# coverage.
+
+required=gcc # Our fake compiler uses gcc.
+am_create_testdir=empty
+. test-init.sh
+
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+echo 'int main (void) { return 0; }' > foo.c
+$CC -c foo.c
+test -f foo.o || test -f foo.obj
+$CC -c -o bar.o foo.c 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep "both '-o' and '-c' seen on the command line" stderr
+test ! -e bar.o && test ! -e bar.obj
+
+:
diff --git a/t/self-check-configure-help.sh b/t/self-check-configure-help.sh
new file mode 100644
index 000000000..1a72198ed
--- /dev/null
+++ b/t/self-check-configure-help.sh
@@ -0,0 +1,274 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check on the function used by the automake testsuite to
+# analyze output of "configure --help".
+
+. test-init.sh
+
+# FIXME: this test is a good candidate for a conversion to TAP.
+
+# Prefer real-world data. This is from the help screen of the
+# configure script from GNU coreutils, with small adaptations.
+cat > help <<'END'
+'configure' configures GNU coreutils 8.14a to adapt to many kinds of systems.
+
+Usage: ./configure [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE. See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+ -h, --help display this help and exit
+ --help=short display options specific to this package
+ --help=recursive display the short help of all the included packages
+ -V, --version display version information and exit
+ -q, --quiet, --silent do not print 'checking ...' messages
+ --cache-file=FILE cache test results in FILE [disabled]
+ -C, --config-cache alias for '--cache-file=config.cache'
+ -n, --no-create do not create output files
+ --srcdir=DIR find the sources in DIR [configure dir or '..']
+
+Installation directories:
+ --prefix=PREFIX install architecture-independent files in PREFIX
+ [/usr/local]
+ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
+ [PREFIX]
+
+By default, 'make install' will install all the files in
+'/usr/local/bin', '/usr/local/lib' etc. You can specify
+an installation prefix other than '/usr/local' using '--prefix',
+for instance '--prefix=$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+ --bindir=DIR user executables [EPREFIX/bin]
+ --sbindir=DIR system admin executables [EPREFIX/sbin]
+ --libexecdir=DIR program executables [EPREFIX/libexec]
+ --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
+ --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
+ --localstatedir=DIR modifiable single-machine data [PREFIX/var]
+ --libdir=DIR object code libraries [EPREFIX/lib]
+ --includedir=DIR C header files [PREFIX/include]
+ --oldincludedir=DIR C header files for non-gcc [/usr/include]
+ --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
+ --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
+ --infodir=DIR info documentation [DATAROOTDIR/info]
+ --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
+ --mandir=DIR man documentation [DATAROOTDIR/man]
+ --docdir=DIR documentation root [DATAROOTDIR/doc/coreutils]
+ --htmldir=DIR html documentation [DOCDIR]
+ --dvidir=DIR dvi documentation [DOCDIR]
+ --pdfdir=DIR pdf documentation [DOCDIR]
+ --psdir=DIR ps documentation [DOCDIR]
+
+Program names:
+ --program-prefix=PREFIX prepend PREFIX to installed program names
+ --program-suffix=SUFFIX append SUFFIX to installed program names
+ --program-transform-name=PROGRAM run sed PROGRAM on installed program names
+
+System types:
+ --build=BUILD configure for building on BUILD [guessed]
+ --host=HOST cross-compile to build programs to run on HOST [BUILD]
+
+Optional Features:
+ --disable-option-checking ignore unrecognized --enable/--with options
+ --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
+ --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
+ --enable-silent-rules less verbose build output (undo: 'make V=1')
+ --disable-silent-rules verbose build output (undo: 'make V=0')
+ --disable-dependency-tracking speeds up one-time build
+ --enable-dependency-tracking do not reject slow dependency extractors
+ --disable-largefile omit support for large files
+ --enable-threads={posix|solaris|pth|win32}
+ specify multithreading API
+ --disable-threads build without multithread safety
+ --disable-acl do not support ACLs
+ --disable-assert turn off assertions
+ --disable-rpath do not hardcode runtime library paths
+ --disable-xattr do not support extended attributes
+ --disable-libcap disable libcap support
+ --enable-gcc-warnings turn on lots of GCC warnings (for developers)
+ --enable-install-program=PROG_LIST
+ install the programs in PROG_LIST (comma-separated,
+ default: none)
+ --enable-no-install-program=PROG_LIST
+ do NOT install the programs in PROG_LIST
+ (comma-separated, default: arch,hostname,su)
+ --disable-nls do not use Native Language Support
+
+Optional Packages:
+ --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
+ --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
+ --with-gnu-ld assume the C compiler uses GNU ld default=no
+ --with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib
+ --without-libiconv-prefix don't search for libiconv in includedir and libdir
+ --with-libpth-prefix[=DIR] search for libpth in DIR/include and DIR/lib
+ --without-libpth-prefix don't search for libpth in includedir and libdir
+ --without-included-regex
+ don't compile regex; this is the default on systems
+ with recent-enough versions of the GNU C Library
+ (use with caution on other systems).
+ --without-selinux do not use SELinux, even on systems with SELinux
+ --with-packager String identifying the packager of this software
+ --with-packager-version Packager-specific version information
+ --with-packager-bug-reports
+ Packager info for bug reports (URL/e-mail/...)
+ --with-tty-group[=NAME]
+ group used by system for TTYs, "tty" when not
+ specified (default: do not rely on any group used
+ for TTYs)
+ --without-gmp do not use the GNU MP library for arbitrary
+ precision calculation (default: use it if available)
+ --with-libintl-prefix[=DIR] search for libintl in DIR/include and DIR/lib
+ --without-libintl-prefix don't search for libintl in includedir and libdir
+
+Some influential environment variables:
+ CC C compiler command
+ CFLAGS C compiler flags
+ LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
+ nonstandard directory <lib dir>
+ LIBS libraries to pass to the linker, e.g. -l<library>
+ CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
+ you have headers in a nonstandard directory <include dir>
+ CPP C preprocessor
+ YACC The "Yet Another C Compiler" implementation to use. Defaults to
+ 'bison -y'. Values other than 'bison -y' will most likely break
+ on most systems.
+ YFLAGS YFLAGS contains the list arguments that will be passed by
+ default to Bison. This script will default YFLAGS to the empty
+ string to avoid a default value of '-d' given by some make
+ applications.
+ DEFAULT_POSIX2_VERSION
+ POSIX version to default to; see 'config.hin'.
+
+Use these variables to override the choices made by 'configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to <bug-automake@gnu.org>.
+General help using GNU software: <https://www.gnu.org/gethelp/>.
+END
+
+compare_extracted_help ()
+{
+ cat > exp || exit 99
+ extract_configure_help "$1" help > got || exit 1
+ cat exp
+ cat got
+ diff exp got || exit 1
+}
+
+compare_extracted_help --disable-libcap <<'END'
+ --disable-libcap disable libcap support
+END
+
+compare_extracted_help --disable-nls <<'END'
+ --disable-nls do not use Native Language Support
+END
+
+compare_extracted_help --disable-option-checking <<'END'
+ --disable-option-checking ignore unrecognized --enable/--with options
+END
+
+compare_extracted_help --build= <<'END'
+ --build=BUILD configure for building on BUILD [guessed]
+END
+
+compare_extracted_help --host= <<'END'
+ --host=HOST cross-compile to build programs to run on HOST [BUILD]
+END
+
+compare_extracted_help '--with-libintl-prefix[=]' <<'END'
+ --with-libintl-prefix[=DIR] search for libintl in DIR/include and DIR/lib
+END
+
+compare_extracted_help --without-included-regex <<'END'
+ --without-included-regex
+ don't compile regex; this is the default on systems
+ with recent-enough versions of the GNU C Library
+ (use with caution on other systems).
+END
+
+compare_extracted_help --enable-threads= <<'END'
+ --enable-threads={posix|solaris|pth|win32}
+ specify multithreading API
+END
+
+compare_extracted_help '--with-tty-group[=]' <<'END'
+ --with-tty-group[=NAME]
+ group used by system for TTYs, "tty" when not
+ specified (default: do not rely on any group used
+ for TTYs)
+END
+
+compare_extracted_help '--prefix=' <<'END'
+ --prefix=PREFIX install architecture-independent files in PREFIX
+ [/usr/local]
+END
+
+compare_extracted_help '--exec-prefix=' <<'END'
+ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
+ [PREFIX]
+END
+
+compare_extracted_help CC <<'END'
+ CC C compiler command
+END
+
+compare_extracted_help CPP <<'END'
+ CPP C preprocessor
+END
+
+compare_extracted_help CPPFLAGS <<'END'
+ CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
+ you have headers in a nonstandard directory <include dir>
+END
+
+compare_extracted_help YACC <<'END'
+ YACC The "Yet Another C Compiler" implementation to use. Defaults to
+ 'bison -y'. Values other than 'bison -y' will most likely break
+ on most systems.
+END
+
+compare_extracted_help DEFAULT_POSIX2_VERSION <<'END'
+ DEFAULT_POSIX2_VERSION
+ POSIX version to default to; see 'config.hin'.
+END
+
+for o in \
+ '--nonesuch' \
+ '--nonesuch=' \
+ '--nonesuch[=]' \
+ '--disable-nls=' \
+ '--disable-nls[=]' \
+ '--without-included-regex=' \
+ '--without-included-regex[=]' \
+ '--prefix' \
+ '--prefix[=]' \
+ '--build' \
+ '--build[=]' \
+ '--with-tty-group' \
+ '--with-tty-group=' \
+ 'NO_SUCH_VAR' \
+ 'NOSUCHVAR' \
+; do
+ compare_extracted_help "$o" </dev/null
+done
+
+:
diff --git a/t/self-check-dir.tap b/t/self-check-dir.tap
new file mode 100644
index 000000000..a74921958
--- /dev/null
+++ b/t/self-check-dir.tap
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite.
+# Check that tests using 'test-init.sh' create a proper temporary
+# directory, and run in it. Also check that we can prevent the
+# pre-population and the creation of such directory if we want.
+
+am_create_testdir=no
+. test-init.sh
+
+plan_ 5
+
+unset keep_testdirs
+
+# This needs to be consistent with what $AM_TEST_RUNNER_SHELL
+# deems to be the current working directory.
+cwd=$($AM_TEST_RUNNER_SHELL -c 'pwd') \
+ || fatal_ "can't get current working directory"
+echo "$cwd"
+
+do_check ()
+{
+ rm -rf _self.dir || framework_failure_ "cleaning up _self.dir"
+ command_ok_ "$1 [$2]" $AM_TEST_RUNNER_SHELL -c "
+ $2
+ . test-init.sh
+ # Don't fail if 'ls -l' fails; avoids possible racy spurious failures.
+ pwd; ls -l || : # For debugging.
+ $3
+ " t/_self.sh
+}
+
+do_check 'testdir has the expected path' \
+ 'unset am_create_testdir' \
+ 'case $(pwd) in '"$cwd"'/t/_self.dir);; *) exit 1;; esac'
+
+do_check 'fully pre-populated testdir' \
+ 'unset am_create_testdir' \
+ 'test -f install-sh || exit 1
+ test -f configure.ac || exit 1
+ case $(pwd) in '"$cwd"'/t/_self.dir) : ;; *) exit 1;; esac'
+
+do_check 'testdir has the expected path' \
+ 'am_create_testdir=empty' \
+ 'case $(pwd) in '"$cwd"'/t/_self.dir) : ;; *) exit 1;; esac'
+
+do_check 'do not pre-populate testdir' \
+ 'am_create_testdir=empty' \
+ 'ls -a | grep -v "^\\.\\{1,2\\}$" | grep . && exit 1; :'
+
+do_check 'do not create nor chdir in testdir' \
+ 'am_create_testdir=no' \
+ 'test ! -e t/_self.dir || exit 1
+ grep "self-check-dir\.tap" Makefile || exit 1
+ case $(pwd) in '"$cwd"') : ;; *) exit 1;; esac'
+
+:
diff --git a/t/self-check-exit.tap b/t/self-check-exit.tap
new file mode 100644
index 000000000..ca2ee7801
--- /dev/null
+++ b/t/self-check-exit.tap
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite.
+# Check that, in case of failing commands, the correct exit status is
+# passed to the exit trap installed by the 'test-init.sh' script.
+# Also check that the 'errexit' shell flag is active.
+
+am_create_testdir=no
+. test-init.sh
+
+plan_ 32
+
+# This test becomes more cumbersome if we keep the 'errexit' shell flag
+# set. And removing it is no big deal, as this test is a TAP-based one,
+# so that false positives remain very unlikely.
+set +e
+
+# It's especially important that the 'unset' is done before sourcing
+# test-init.sh, i.e., when 'set -e' is not active yet, for the benefit
+# of shells (like Bash 2.05 and Solaris 10 /bin/ksh) that returns a
+# non-zero status when unsetting an already-unset variable.
+# Add an extra newline at the end so that the aliases defined by
+# test-init.sh can take effect. Yes, this is truly required.
+init="stderr_fileno_=2; unset am_explicit_skips;. test-init.sh${nl}"
+
+# Required so that the code in test-init.sh doesn't go crazy trying to creating a
+# temporary directory in the absolute dir of $AM_TEST_RUNNER_SHELL.
+dummy_test_script=t/$me.sh
+
+for st in 1 2 3 4 5 77 99 126 127 128 129 130 255; do
+ for exit_cmd in "exit $st" "sh -c 'exit $st'"; do
+ $AM_TEST_RUNNER_SHELL -c "$init $exit_cmd; :" "$dummy_test_script"
+ command_ok_ "$exit_cmd" test $? -eq $st
+ done
+done
+
+for sig in 1 2 13 15; do
+ if is_blocked_signal $sig; then
+ skip_ -r "signal $sig seems blocked"
+ continue
+ fi
+ if test $sig -eq 2; then
+ # Some Korn shells might otherwise get a spurious SIGINT when one is
+ # sent to the child $AM_TEST_RUNNER_SHELL. For more details, see:
+ # <https://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
+ trap : 2
+ fi
+ $AM_TEST_RUNNER_SHELL -c "$init kill -$sig \$\$; :" "$dummy_test_script"
+ rc=$?
+ if test $sig -eq 2; then
+ # Reset default SIGINT handler as portably as possible.
+ trap 2 || trap - 2
+ fi
+ command_ok_ "kill -$sig" test $rc -eq 99
+ unset rc
+done
+
+: Non-existent program.
+$AM_TEST_RUNNER_SHELL -c "$init non-existent-prog; :" "$dummy_test_script"
+command_ok_ "command not found" -- test $? -gt 0
+
+: Non-executable command.
+test -f Makefile && test ! -x Makefile || \
+ framowork_failure_ "no proper Makefile in the current directory"
+$AM_TEST_RUNNER_SHELL -c "$init ./Makefile; :" "$dummy_test_script"
+command_ok_ "permission denied" test $? -gt 0
+
+:
diff --git a/t/self-check-explicit-skips.sh b/t/self-check-explicit-skips.sh
new file mode 100644
index 000000000..37d941dde
--- /dev/null
+++ b/t/self-check-explicit-skips.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite.
+# Check that our testsuite framework can be instructed not to consider
+# an early exit due to some command exiting unexpectedly with status 77.
+
+am_create_testdir=no
+. test-init.sh
+
+set +e
+
+unset am_explicit_skips stderr_fileno_
+
+# FIXME: this can be simplified when we improve our runtime checks on the
+# testsuite shell to ensure it supports "VAR=val shell_func" correctly.
+run_dummy_test ()
+{
+ env $2 $AM_TEST_RUNNER_SHELL -c "
+ am_create_testdir=no
+ . test-init.sh
+ $1
+ " dummy.sh
+}
+
+run_dummy_test 'exit 77'
+test $? -eq 77 || exit 1
+
+run_dummy_test 'sh -c "exit 77"' am_explicit_skips=no
+test $? -eq 77 || exit 1
+
+run_dummy_test '$PERL -e "exit 77"; true' am_explicit_skips=yes
+test $? -eq 78 || exit 1
+
+run_dummy_test 'sh -c "exit 77"; exit 0' am_explicit_skips=y
+test $? -eq 78 || exit 1
+
+run_dummy_test 'skip_ "foo"; :' am_explicit_skips=y
+test $? -eq 77 || exit 1
+
+:
diff --git a/t/self-check-is-blocked-signal.tap b/t/self-check-is-blocked-signal.tap
new file mode 100644
index 000000000..34160c976
--- /dev/null
+++ b/t/self-check-is-blocked-signal.tap
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite: the 'signal_is_blocked'
+# shell function.
+
+am_create_testdir=no
+. test-init.sh
+
+plan_ 2
+
+command_ok_ "unblockable signal 9" not is_blocked_signal 9
+trap "" 13
+command_ok_ "blocked signal 13" is_blocked_signal 13
+
+:
diff --git a/t/self-check-is_newest.tap b/t/self-check-is_newest.tap
new file mode 100644
index 000000000..4b50dc329
--- /dev/null
+++ b/t/self-check-is_newest.tap
@@ -0,0 +1,90 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite: the 'is_newest' subroutine.
+
+. test-init.sh
+
+plan_ 21
+
+# I'm a lazy typist.
+Y () { command_ok_ "is_newest $*" is_newest "$@"; }
+N () { command_ok_ "not is_newest $*" not is_newest "$@"; }
+
+# A simple "touch -r" might not work, since on some file systems, and/or
+# with some 'touch' versions, it might truncate the timestamp (or even
+# rounded it upwards maybe). So the first (apparently redundant) 'touch'
+# invocation below ensures that the timestamp gets "normalized" in a way
+# that allows it to be correctly copied by the second 'touch' invocation.
+copy_timestamp ()
+{
+ touch -r "$1" "$1" && touch -r "$1" "$2"
+}
+
+: > a
+$sleep
+: > b
+: > c
+
+stat a b c || : # For debugging.
+
+Y c a
+Y b a
+N a b
+Y c b
+Y c c
+Y c a b c
+
+copy_timestamp c d
+
+stat c d || : # For debugging.
+
+Y c d
+
+# Should work on directories too, both empty and not-empty. An older
+# implementation of 'is_newest' failed if the first argument was a
+# directory containing files newer than itself (see automake bug#9147).
+mkdir u x
+touch x/foo
+$sleep
+touch x/foo
+$sleep
+mkdir v y
+touch y/foo
+$sleep
+touch y/foo
+
+stat u v x y x/foo y/foo || : # For debugging.
+
+for older in u x; do
+ for newer in v y; do
+ Y $newer $older
+ N $older $newer
+ done
+done
+
+Y x/foo x
+N x x/foo
+
+copy_timestamp x u
+Y x u
+Y u x
+
+# A couple of mild "stress" tests.
+Y y x u v
+Y y u x/foo a b c
+
+:
diff --git a/t/self-check-me.tap b/t/self-check-me.tap
new file mode 100644
index 000000000..c09d83b21
--- /dev/null
+++ b/t/self-check-me.tap
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite.
+# Make sure that $me gets automatically defined by 'test-init.sh'.
+
+am_create_testdir=no
+. test-init.sh
+
+plan_ 12
+
+# This test becomes cumbersome if we keep the 'errexit' shell flag set.
+# And removing it is no big deal, as this test is a TAP-based one, so
+# that false positives remain very unlikely.
+set +e
+
+do_check ()
+{
+ $AM_TEST_RUNNER_SHELL -c '
+ am_create_testdir=no # Do not pollute the top-level directory.
+ . test-init.sh
+ echo me=$me
+ ' "$1" | grep "^me=$2$"
+ command_ok_ "me=$1" test $? -eq 0
+}
+
+for e in sh tap; do
+ do_check foo-bar-.$e 'foo-bar-'
+ do_check _foo__bar.$e '_foo__bar'
+ do_check 012.$e '012'
+ do_check a.b.c.$e 'a\.b\.c'
+done
+
+do_check foo.bar 'foo\.bar'
+do_check abc. 'abc\.'
+
+# A definition of $me in the environment should be ignored.
+
+s=$(me=bad $AM_TEST_RUNNER_SHELL -c '
+ # Do not pollute the top-level directory.
+ am_create_testdir=no
+ . test-init.sh
+ echo me=$me
+' foo.sh)
+command_ok_ "override of \$me before test-init.sh causes no error" \
+ test $? -eq 0
+
+r='ok'
+printf '%s\n' "$s" | grep '^me=foo$' || r='not ok'
+printf '%s\n' "$s" | grep 'me=bad' && r='not ok'
+result_ "$r" "\$me from the environment is ignored"
+unset r
+
+:
diff --git a/t/self-check-report.sh b/t/self-check-report.sh
new file mode 100644
index 000000000..f110efe51
--- /dev/null
+++ b/t/self-check-report.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite.
+# Test subroutines to report warnings, and to signal failures, skips
+# and hard errors.
+
+unset stderr_fileno_
+
+am_create_testdir=empty
+. test-init.sh
+
+set +e
+
+exec 5>&1
+
+(warn_ foobar) 2>&1 1>&5 | grep '^foobar$' || exit 1
+(fail_ foo); test $? -eq 1 || exit 1
+(fail_ foo) 2>&1 1>&5 | grep "^$me: failed test: foo" || exit 1
+(skip_ foo); test $? -eq 77 || exit 1
+(skip_ foo) 2>&1 1>&5 | grep "^$me: skipped test: foo" || exit 1
+(fatal_ foo); test $? -eq 99 || exit 1
+(fatal_ foo) 2>&1 1>&5 | grep "^$me: hard error: foo" || exit 1
+(framework_failure_ foo); test $? -eq 99 || exit 1
+(framework_failure_ foo) 2>&1 1>&5 \
+ | grep "^$me: set-up failure: foo" || exit 1
+
+stderr_fileno_=6
+
+(warn_ foobar) 6>&1 1>&5 | grep '^foobar$' || exit 1
+(fail_ foo); test $? -eq 1 || exit 1
+(fail_ foo) 6>&1 1>&5 | grep "^$me: failed test: foo" || exit 1
+(skip_ foo); test $? -eq 77 || exit 1
+(skip_ foo) 6>&1 1>&5 | grep "^$me: skipped test: foo" || exit 1
+(fatal_ foo); test $? -eq 99 || exit 1
+(fatal_ foo) 6>&1 1>&5 | grep "^$me: hard error: foo" || exit 1
+(framework_failure_ foo); test $? -eq 99 || exit 1
+(framework_failure_ foo) 6>&1 1>&5 \
+ | grep "^$me: set-up failure: foo" || exit 1
+
+:
diff --git a/t/self-check-seq.tap b/t/self-check-seq.tap
new file mode 100644
index 000000000..078d49129
--- /dev/null
+++ b/t/self-check-seq.tap
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite.
+# Check the 'seq_' subroutine.
+
+. test-init.sh
+
+plan_ 14
+
+unset stderr_fileno_
+
+check_work ()
+{
+ desc=$1 args=$2 exp=$3
+ st=0; got=$(seq_ $args) || st=$?
+ command_ok_ "$desc [exit status = 0]" test $st -eq 0
+ command_ok_ "$desc [output]" test x"$exp" = x"$got"
+}
+
+check_work 'one-argument form' '5' "\
+1
+2
+3
+4
+5"
+
+check_work 'two-arguments form' '7 11' "\
+7
+8
+9
+10
+11"
+
+check_work 'three-arguments form (1)' '120 5 135' "\
+120
+125
+130
+135"
+
+check_work 'three-arguments form (1)' '13 4 23' "\
+13
+17
+21"
+
+check_err ()
+{
+ desc=$1 args=$2 err=$3
+ (seq_ $args) >output || st=$?
+ # Protect content emitted on stdout/stderr, to avoid sending to the
+ # TAP driver possible "Bail out!" directives generated by 'seq_'.
+ # Use 'grep -c' below for the same reason.
+ sed 's/^/: /' output
+ command_ok_ "$desc [exit status = 99]" test $st -eq 99
+ command_ok_ "$desc [error message]" grep -c "seq_: $err" output
+}
+
+check_err 'no argument is an error' '' 'missing argument'
+check_err 'four arguments is an error' '1 1 2 1' 'too many arguments'
+check_err 'six arguments is an error' '1 1 1 1 1 1' 'too many arguments'
+
+:
diff --git a/t/self-check-shell-no-trail-bslash.sh b/t/self-check-shell-no-trail-bslash.sh
new file mode 100644
index 000000000..a0ef5b6f3
--- /dev/null
+++ b/t/self-check-shell-no-trail-bslash.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that our fake "shell" used to guard against use of trailing
+# backslashes in recipes actually complains when those are used.
+
+# Our hack doesn't work with some make implementations (see comments
+# in 't/ax/shell-no-trail-bslash.in' for more details).
+required=GNUmake
+am_create_testdir=empty
+. test-init.sh
+
+cat >> Makefile <<'END'
+am__backslash = \\ # foo
+.PHONY: good bad
+good:
+ @printf '%s\n' OK
+.PHONY: bad
+bad:
+ @echo $(am__backslash)
+END
+
+SHELL=$am_testaux_builddir/shell-no-trail-bslash
+
+$SHELL -c 'exit 0'
+test "$($SHELL -c 'echo is o\k')" = "is ok"
+
+echo 'echo is ok\"' > ok.sh
+$SHELL ./ok.sh
+test "$($SHELL ./ok.sh)" = "is ok\""
+
+tab=' '
+nl='
+'
+for sfx in \
+ '\' \
+ '\\' \
+ '\\\\\' \
+ '\ ' \
+ "\\$tab" \
+ "\\ $tab$tab " \
+ "\\$nl" \
+ "\\ $nl " \
+ "\\$nl$nl$nl" \
+; do
+ for pfx in "" "echo bad" ": a${nl}# multine${nl}: text"; do
+ cmd=${pfx}${sfx}
+ printf '%s' "$cmd" > bad.sh
+ for args in '-c "$cmd"' './bad.sh'; do
+ eval "\$SHELL $args 2>stderr && { cat stderr >&2; exit 1; }; :"
+ cat stderr >&2
+ $FGREP "recipe/script ends with backslash character" stderr
+ cmd="$cmd" $PERL -w -e '
+ undef $/;
+ $_ = <>;
+ index($_, $ENV{cmd}) >= 0 or exit 1;
+ ' <stderr
+ $FGREP "$cmd" stderr
+ done
+ done
+done
+
+$MAKE good
+
+run_make -E -e FAIL bad SHELL="$SHELL"
+$FGREP "recipe/script ends with backslash character" stderr
+
+:
diff --git a/t/self-check-unindent.tap b/t/self-check-unindent.tap
new file mode 100644
index 000000000..109e2d49d
--- /dev/null
+++ b/t/self-check-unindent.tap
@@ -0,0 +1,255 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite.
+# Check the 'unindent' subroutine.
+
+. test-init.sh
+
+plan_ 22
+
+#------------------------------------------------------------------
+
+will_test () { tst=$*; }
+
+do_check ()
+{
+ command_ok_ "$tst [simple, exit status]" \
+ eval 'unindent input > got'
+ command_ok_ "$tst [simple, output]" \
+ diff exp got
+ command_ok_ "$tst [parallel, exit status]" \
+ eval 'unindent input | unindent > got'
+ command_ok_ "$tst [parallel, output]" \
+ diff exp got
+}
+
+#------------------------------------------------------------------
+
+will_test 'leading spaces'
+
+cat > input <<END
+ 1
+ 2
+3
+ 4
+${tab}5
+${tab} 6
+ 6${sp}
+7${sp}
+ 8${sp}${sp}
+9${sp}${sp}
+ 10${tab}
+11${tab}
+ 12${sp}${tab}
+13${sp}${tab}
+ 14 this${tab}with${tab}multiple fields${sp}
+15 and ${tab}${tab}this too${tab}
+ 16 and also this
+${sp}${sp}
+${sp}
+${tab}
+
+last line
+END
+
+cat > exp <<END
+1
+ 2
+3
+ 4
+${tab}5
+${tab} 6
+6${sp}
+7${sp}
+8${sp}${sp}
+9${sp}${sp}
+10${tab}
+11${tab}
+12${sp}${tab}
+13${sp}${tab}
+14 this${tab}with${tab}multiple fields${sp}
+15 and ${tab}${tab}this too${tab}
+ 16 and also this
+
+${sp}
+${tab}
+
+last line
+END
+
+do_check
+
+#------------------------------------------------------------------
+
+will_test 'leading tab'
+
+cat > input <<END
+${tab}1
+${tab} 2
+3
+ 4
+ 5
+ 6
+ 7
+ ${tab}8
+${tab}${tab}9
+${tab}10${tab}
+${tab}11${sp}
+12${tab}
+13${sp}
+${tab}14 this with${tab}multiple fields${sp}
+15 and ${tab}${tab}this too${tab}
+ 16 and also this
+${tab}
+${sp}
+${sp}${tab}
+
+last line
+END
+
+cat > exp <<END
+1
+ 2
+3
+ 4
+ 5
+ 6
+ 7
+ ${tab}8
+${tab}9
+10${tab}
+11${sp}
+12${tab}
+13${sp}
+14 this with${tab}multiple fields${sp}
+15 and ${tab}${tab}this too${tab}
+ 16 and also this
+
+${sp}
+${sp}${tab}
+
+last line
+END
+
+do_check "leading tab"
+
+#------------------------------------------------------------------
+
+will_test 'no leading whitespace'
+
+cat > input <<END
+1
+ 2
+ 3
+ 4
+${tab}5
+${tab} 6
+ ${tab}7
+${tab}${tab}8
+9${sp}
+ 10${tab}
+${tab}10${sp}${sp}
+14 this with${tab}multiple fields${sp}
+ 15 and this too${tab}
+${tab}16 and also this
+${tab}
+${sp}
+
+last line
+END
+
+cp input exp
+
+do_check
+
+#------------------------------------------------------------------
+
+will_test 'leading empty lines ignored (1)'
+
+cat > input <<END
+
+
+ foo
+ bar
+ quux
+END
+
+cat > exp <<END
+
+
+foo
+bar
+ quux
+END
+
+do_check
+
+#------------------------------------------------------------------
+
+will_test 'leading empty lines ignored (2)'
+
+cat > input <<END
+
+
+foo
+bar
+ quux
+END
+
+cat > exp <<END
+
+
+foo
+bar
+ quux
+END
+
+do_check
+
+#------------------------------------------------------------------
+
+will_test 'more elaborated parallel use'
+
+cat > input <<END
+ x
+ ${tab}y
+ z
+ ${tab}a
+ ${tab} b
+${tab}c
+ ${tab}d
+ ${tab}e
+ ${tab}${tab}f
+END
+
+cat > exp <<END
+y
+z
+a
+ b
+c
+ ${tab}d
+ ${tab}e
+${tab}f
+END
+
+command_ok_ "$tst [exit status]" \
+ eval 'unindent input | sed 1d | unindent > got'
+
+command_ok_ "$tst [output]" diff exp got
+
+:
diff --git a/t/serial-tests.sh b/t/serial-tests.sh
new file mode 100644
index 000000000..8a86638df
--- /dev/null
+++ b/t/serial-tests.sh
@@ -0,0 +1,84 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Option 'serial-tests'.
+
+am_create_testdir=empty
+. test-init.sh
+
+hasnt_parallel_tests ()
+{
+ $EGREP 'TEST_SUITE_LOG|TEST_LOGS|\.log.*:' $1 && exit 1
+ grep 'recheck.*:' $1 && exit 1
+ grep '^check-TESTS: \$(TESTS)$' $1
+}
+
+has_parallel_tests ()
+{
+ $EGREP '(^| )check-TESTS.*:' $1
+ $EGREP '(^| )recheck.*:' $1
+ grep '^\$(TEST_SUITE_LOG): \$(TEST_LOGS)$' $1
+ grep '^\.test\.log:$' $1
+}
+
+mkdir one two
+
+cat > one/configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([serial-tests])
+AC_CONFIG_FILES([Makefile])
+END
+
+echo 'TESTS = foo.test bar.test' > one/Makefile.am
+
+cat > two/configure.ac <<END
+AC_INIT([$me], [2.0])
+AC_CONFIG_AUX_DIR([config])
+AM_INIT_AUTOMAKE([parallel-tests])
+AC_CONFIG_FILES([aMakefile bMakefile])
+END
+
+cp one/Makefile.am two/aMakefile.am
+cat - one/Makefile.am > two/bMakefile.am <<END
+AUTOMAKE_OPTIONS = serial-tests
+END
+
+cd one
+touch missing install-sh
+$ACLOCAL
+$AUTOMAKE
+grep TEST Makefile.in # For debugging.
+hasnt_parallel_tests Makefile.in
+test ! -e test-driver
+cd ..
+
+cd two
+mkdir config
+$ACLOCAL
+$AUTOMAKE --add-missing
+grep TEST [ab]Makefile.in # For debugging.
+has_parallel_tests aMakefile.in
+hasnt_parallel_tests bMakefile.in
+mv aMakefile.in aMakefile.sav
+mv bMakefile.in bMakefile.sav
+test ! -e test-driver
+test -f config/test-driver
+$AUTOMAKE
+diff aMakefile.sav aMakefile.in
+diff bMakefile.sav bMakefile.in
+cd ..
+
+:
diff --git a/t/silent-c.sh b/t/silent-c.sh
new file mode 100644
index 000000000..00e691dd8
--- /dev/null
+++ b/t/silent-c.sh
@@ -0,0 +1,88 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode for C, without libtool, both with and without
+# automatic dependency tracking.
+
+required=cc
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'EOF'
+AC_CONFIG_FILES([sub/Makefile])
+AC_PROG_CC
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+bin_PROGRAMS = foo bar
+bar_CFLAGS = $(AM_CFLAGS)
+SUBDIRS = sub
+EOF
+
+cat > sub/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+# Need generic and non-generic rules.
+bin_PROGRAMS = baz bla
+bla_CFLAGS = $(AM_CFLAGS)
+EOF
+
+cat > foo.c <<'EOF'
+int main ()
+{
+ return 0;
+}
+EOF
+cp foo.c bar.c
+cp foo.c sub/baz.c
+cp foo.c sub/bla.c
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+for config_args in \
+ '--enable-dependency-tracking' \
+ '--disable-dependency-tracking' \
+; do
+
+ ./configure --enable-silent-rules $config_args
+
+ run_make -O
+ $EGREP ' (-c|-o)' stdout && exit 1
+ grep 'mv ' stdout && exit 1
+ grep 'CC .*foo\.' stdout
+ grep 'CC .*bar\.' stdout
+ grep 'CC .*baz\.' stdout
+ grep 'CC .*bla\.' stdout
+ grep 'CCLD .*foo' stdout
+ grep 'CCLD .*bar' stdout
+ grep 'CCLD .*baz' stdout
+ grep 'CCLD .*bla' stdout
+
+ $MAKE clean
+ run_make -O V=1
+ grep ' -c' stdout
+ grep ' -o foo' stdout
+ $EGREP '(CC|LD) ' stdout && exit 1
+
+ $MAKE distclean
+
+done
+
+:
diff --git a/t/silent-configsite.sh b/t/silent-configsite.sh
new file mode 100644
index 000000000..4a514ae4b
--- /dev/null
+++ b/t/silent-configsite.sh
@@ -0,0 +1,86 @@
+#!/bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the user can control default mode of silent-rules
+# from config.site, and that this default can be overridden from
+# either the ./configure or make command line.
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+# This line will be edited later to force silent-rules default.
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+.PHONY: test-silent test-nosilent
+test-silent:
+ test x'$(AM_DEFAULT_VERBOSITY)' = x'0'
+test-nosilent:
+ test x'$(AM_DEFAULT_VERBOSITY)' = x'1'
+EOF
+
+unset enable_silent_rules
+
+: 'No explicit default in configure.ac, enable by default in config.site'
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+echo "enable_silent_rules=\${enable_silent_rules-yes}" > config.site
+CONFIG_SITE=./config.site ./configure
+$MAKE test-silent
+$MAKE distclean
+# Command line should win over default values in config.site.
+CONFIG_SITE=./config.site ./configure --disable-silent-rules
+$MAKE test-nosilent
+$MAKE distclean
+
+: 'Disable by default in configure.ac, enable by default in config.site'
+
+sed 's/.*silent-rules default.*/AM_SILENT_RULES([no])/' configure.ac > t
+diff t configure.ac && fatal_ "editing configure.ac"
+mv -f t configure.ac
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+echo "enable_silent_rules=\${enable_silent_rules-yes}" > config.site
+CONFIG_SITE=./config.site ./configure
+$MAKE test-silent
+# Command line should win over default values in config.site.
+$MAKE distclean
+CONFIG_SITE=./config.site ./configure --disable-silent-rules
+$MAKE test-nosilent
+$MAKE distclean
+
+: 'Enable by default in configure.ac, disable by default in config.site'
+
+sed 's/.*AM_SILENT_RULES.*/AM_SILENT_RULES([yes])/' configure.ac > t
+diff t configure.ac && fatal_ "editing configure.ac"
+mv -f t configure.ac
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+echo "enable_silent_rules=\${enable_silent_rules-no}" > config.site
+CONFIG_SITE=./config.site ./configure
+$MAKE test-nosilent
+$MAKE distclean
+# Command line should win over default values in config.site.
+CONFIG_SITE=./config.site ./configure --enable-silent-rules
+$MAKE test-silent
+$MAKE distclean
+
+:
diff --git a/t/silent-custom.sh b/t/silent-custom.sh
new file mode 100644
index 000000000..6f214183b
--- /dev/null
+++ b/t/silent-custom.sh
@@ -0,0 +1,110 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check user extensibility of silent-rules mode.
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+EOF
+
+# We delegate all the work to the subdir makefile. This is done
+# to ensure any command-line setting of $(V) gets correctly passed
+# down to recursive make invocations.
+echo SUBDIRS = sub > Makefile.am
+
+mkdir sub
+cat > sub/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = -Wno-portability-recursive
+my_verbose = $(my_verbose_$(V))
+my_verbose_ = $(my_verbose_$(AM_DEFAULT_VERBOSITY))
+my_verbose_0 = @echo " XGEN $@";
+
+all-local: foo gen-headers
+
+list = 0 1 2
+.PHONY: gen-headers
+gen-headers:
+ @headers=`for i in $(list); do echo sub/$$i.h; done`; \
+ if $(AM_V_P); then set -x; else \
+ echo " GEN [headers]"; \
+ fi; \
+ rm -f $$headers || exit 1; \
+## Only fake header generation.
+ : generate-header --flags $$headers
+
+foo: foo.in
+ $(my_verbose)cp $(srcdir)/foo.in $@
+EXTRA_DIST = foo.in
+CLEANFILES = foo
+EOF
+
+: > sub/foo.in
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+do_check ()
+{
+ case ${1-} in
+ --silent) silent=:;;
+ --verbose) silent=false;;
+ *) fatal_ "do_check(): incorrect usage";;
+ esac
+ shift
+ $MAKE clean
+ run_make -M -- ${1+"$@"}
+ if $silent; then
+ $FGREP 'cp ' output && exit 1
+ $FGREP 'generate-header' output && exit 1
+ $FGREP 'rm -f' output && exit 1
+ grep '[012]\.h' output && exit 1
+ grep '^ XGEN foo$' output
+ grep '^ GEN \[headers\]$' output
+ else
+ $FGREP 'GEN ' output && exit 1
+ $FGREP 'cp ./foo.in foo' output
+ # Be prepared to handle "creative quoting" in the shell traces.
+ # See automake bug#14760.
+ ok=false
+ for q in '' \' \"; do
+ files="${q}sub/0.h${q} ${q}sub/1.h${q} ${q}sub/2.h${q}"
+ $FGREP "rm -f $files" output || continue
+ $FGREP "generate-header --flags $files" output || continue
+ ok=:
+ break
+ done
+ $ok || exit 1
+ unset ok
+ fi
+}
+
+./configure --enable-silent-rules
+do_check --silent
+do_check --verbose V=1
+
+$MAKE distclean
+
+./configure --disable-silent-rules
+do_check --verbose
+do_check --silent V=0
+
+$MAKE distclean
+
+:
diff --git a/t/silent-cxx.sh b/t/silent-cxx.sh
new file mode 100644
index 000000000..462f2265b
--- /dev/null
+++ b/t/silent-cxx.sh
@@ -0,0 +1,107 @@
+#!/bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode for C++, both with and without automatic
+# dependency tracking.
+
+required=c++
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'EOF'
+AC_PROG_CXX
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+bin_PROGRAMS = foo1 foo2
+foo1_SOURCES = foo.cpp baz.cxx quux.cc
+foo2_SOURCES = $(foo1_SOURCES)
+foo2_CXXFLAGS = $(AM_CXXFLAGS)
+SUBDIRS = sub
+EOF
+
+cat > sub/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+# Need generic and non-generic rules.
+bin_PROGRAMS = bar1 bar2
+bar1_SOURCES = bar.cpp
+bar2_SOURCES = $(bar1_SOURCES)
+bar2_CXXFLAGS = $(AM_CXXFLAGS)
+EOF
+
+cat > foo.cpp <<'EOF'
+using namespace std; /* C compilers fail on this. */
+int main (void) { return 0; }
+EOF
+
+# Let's try out other extensions too.
+echo 'class Baz { public: int i; };' > baz.cxx
+echo 'class Quux { public: bool b; };' > quux.cc
+
+cp foo.cpp sub/bar.cpp
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+# Sanity check: make sure the cache variable we force is really used
+# by configure.
+$FGREP am_cv_CXX_dependencies_compiler_type configure
+
+# Force dependency tracking explicitly, so that slow dependency
+# extractors are not rejected. Try also with dependency tracking
+# explicitly disabled.
+for config_args in \
+ --enable-dependency-tracking --disable-dependency-tracking
+do
+
+ ./configure $config_args --enable-silent-rules
+
+ run_make -O
+
+ $EGREP ' (-c|-o)' stdout && exit 1
+ grep 'mv ' stdout && exit 1
+
+ grep 'CXX .*foo\.' stdout
+ grep 'CXX .*baz\.' stdout
+ grep 'CXX .*quux\.' stdout
+ grep 'CXX .*bar\.' stdout
+ grep 'CXXLD .*foo1' stdout
+ grep 'CXXLD .*bar1' stdout
+ grep 'CXXLD .*foo2' stdout
+ grep 'CXXLD .*bar2' stdout
+
+ # Ensure a clean rebuild.
+ $MAKE clean
+
+ run_make -O V=1
+
+ grep ' -c ' stdout
+ grep ' -o ' stdout
+
+ $EGREP '(CXX|LD) ' stdout && exit 1
+
+ # Ensure a clean reconfiguration/rebuild.
+ $MAKE clean
+ $MAKE maintainer-clean
+
+done
+
+:
diff --git a/t/silent-f77.sh b/t/silent-f77.sh
new file mode 100644
index 000000000..37a3cb638
--- /dev/null
+++ b/t/silent-f77.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode for Fortran 77.
+# Keep this ins sync with the sister test 'silent-f90.sh'.
+
+required=fortran77
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'EOF'
+AC_PROG_F77
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+bin_PROGRAMS = foo1 foo2
+foo1_SOURCES = foo.f
+foo2_SOURCES = $(foo1_SOURCES)
+foo2_FFLAGS = $(AM_FFLAGS)
+SUBDIRS = sub
+EOF
+
+cat > sub/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+# Need generic and non-generic rules.
+bin_PROGRAMS = bar1 bar2
+bar1_SOURCES = bar.f
+bar2_SOURCES = $(bar1_SOURCES)
+bar2_FFLAGS = $(AM_FFLAGS)
+EOF
+
+cat > foo.f <<'EOF'
+ program foo
+ stop
+ end
+EOF
+cp foo.f sub/bar.f
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure --enable-silent-rules
+run_make -O
+# Avoid spurious failures with SunStudio Fortran compilers.
+sed '/^NOTICE:/d' stdout > t
+mv -f t stdout
+cat stdout
+
+$EGREP ' (-c|-o)' stdout && exit 1
+grep 'mv ' stdout && exit 1
+
+grep 'F77 .*foo\.' stdout
+grep 'F77 .*bar\.' stdout
+grep 'F77LD .*foo1' stdout
+grep 'F77LD .*bar1' stdout
+grep 'F77LD .*foo2' stdout
+grep 'F77LD .*bar2' stdout
+
+$EGREP '(FC|FCLD) ' stdout && exit 1
+
+# Ensure a clean rebuild.
+$MAKE clean
+
+run_make -O V=1
+
+grep ' -c ' stdout
+grep ' -o ' stdout
+
+$EGREP '(F77|FC|LD) ' stdout && exit 1
+
+:
diff --git a/t/silent-f90.sh b/t/silent-f90.sh
new file mode 100644
index 000000000..6ace2a5c5
--- /dev/null
+++ b/t/silent-f90.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode for Fortran 90.
+# Keep this ins sync with the sister test 'silent-f77.sh'.
+
+required=fortran
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'EOF'
+AC_PROG_FC
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+bin_PROGRAMS = foo1 foo2
+foo1_SOURCES = foo.f90
+foo2_SOURCES = $(foo1_SOURCES)
+foo2_FCFLAGS = $(AM_FCLAGS)
+SUBDIRS = sub
+EOF
+
+cat > sub/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+# Need generic and non-generic rules.
+bin_PROGRAMS = bar1 bar2
+bar1_SOURCES = bar.f90
+bar2_SOURCES = $(bar1_SOURCES)
+bar2_FCFLAGS = $(AM_FCLAGS)
+EOF
+
+cat > foo.f90 <<'EOF'
+ program foo
+ stop
+ end
+EOF
+cp foo.f90 sub/bar.f90
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure --enable-silent-rules
+run_make -O
+# Avoid spurious failures with SunStudio Fortran compilers.
+sed '/^NOTICE:/d' stdout > t
+mv -f t stdout
+cat stdout
+
+$EGREP ' (-c|-o)' stdout && exit 1
+grep 'mv ' stdout && exit 1
+
+grep 'FC .*foo\.' stdout
+grep 'FC .*bar\.' stdout
+grep 'FCLD .*foo1' stdout
+grep 'FCLD .*bar1' stdout
+grep 'FCLD .*foo2' stdout
+grep 'FCLD .*bar2' stdout
+
+$EGREP '(F77|F77LD) ' stdout && exit 1
+
+# Ensure a clean rebuild.
+$MAKE clean
+
+run_make -O V=1
+
+grep ' -c ' stdout
+grep ' -o ' stdout
+
+$EGREP '(F77|FC|LD) ' stdout && exit 1
+
+:
diff --git a/t/silent-gen.sh b/t/silent-gen.sh
new file mode 100644
index 000000000..ff306db22
--- /dev/null
+++ b/t/silent-gen.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Silent rules: use of pre-defined variables $(AM_V_GEN) and $(AM_V_at).
+# Incidentally, also check that silent rules are disabled by default.
+
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'EOF'
+all-local: foo
+
+## And here's how you should do it in your own code:
+foo: foo.in
+ $(AM_V_GEN)cp $(srcdir)/foo.in $@
+ $(AM_V_at)echo more >> $@
+
+EXTRA_DIST = foo.in
+CLEANFILES = foo
+EOF
+
+: >foo.in
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+# Silent rules are disabled by default, since we haven't called
+# "AM_SILENT_RULES([yes])" explicitly.
+./configure
+run_make -O
+grep 'GEN ' stdout && exit 1
+grep 'cp ' stdout
+grep 'echo ' stdout
+
+$MAKE clean
+run_make -O V=1
+grep 'GEN ' stdout && exit 1
+grep 'cp ' stdout
+grep 'echo ' stdout
+
+$MAKE clean
+run_make -O V=0
+grep 'GEN .*foo' stdout
+grep 'cp ' stdout && exit 1
+grep 'echo ' stdout && exit 1
+
+$MAKE distclean
+
+./configure --enable-silent-rules
+run_make -O
+grep 'GEN .*foo' stdout
+grep 'cp ' stdout && exit 1
+grep 'echo ' stdout && exit 1
+
+$MAKE clean
+run_make -O V=0
+grep 'GEN .*foo' stdout
+grep 'cp ' stdout && exit 1
+grep 'echo ' stdout && exit 1
+
+$MAKE clean
+run_make -O V=1
+grep 'GEN ' stdout && exit 1
+grep 'cp ' stdout
+grep 'echo ' stdout
+
+:
diff --git a/t/silent-lex.sh b/t/silent-lex.sh
new file mode 100644
index 000000000..14ec086be
--- /dev/null
+++ b/t/silent-lex.sh
@@ -0,0 +1,133 @@
+#!/bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode for Lex.
+
+required='cc lex'
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'EOF'
+AC_PROG_LEX
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+bin_PROGRAMS = foo1 foo2
+foo1_SOURCES = foo.l
+foo2_SOURCES = $(foo1_SOURCES)
+foo2_LFLAGS = -n
+foo2_CFLAGS = $(AM_CFLAGS)
+SUBDIRS = sub
+LDADD = $(LEXLIB)
+EOF
+
+cat > sub/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+# Need generic and non-generic rules.
+bin_PROGRAMS = bar1 bar2
+bar1_SOURCES = bar.l
+bar2_SOURCES = $(bar1_SOURCES)
+bar2_LFLAGS = -n
+bar2_CFLAGS = $(AM_CFLAGS)
+LDADD = $(LEXLIB)
+EOF
+
+cat > foo.l <<'EOF'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+/* Avoid possible link errors. */
+int yywrap (void) { return 1; }
+int main (void) { return 0; }
+EOF
+cp foo.l sub/bar.l
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+# Ensure per-target rules are used, to ensure their coverage below.
+$FGREP 'foo2-foo.c' Makefile.in || exit 99
+$FGREP 'bar2-bar.c' sub/Makefile.in || exit 99
+
+./configure --enable-silent-rules
+
+run_make -O
+
+$EGREP ' (-c|-o)' stdout && exit 1
+$EGREP '(mv|ylwrap) ' stdout && exit 1
+
+grep 'LEX .*foo\.' stdout
+grep 'LEX .*bar\.' stdout
+grep ' CC .*foo\.' stdout
+grep ' CC .*bar\.' stdout
+grep 'CCLD .*foo1' stdout
+grep 'CCLD .*bar1' stdout
+grep 'CCLD .*foo2' stdout
+grep 'CCLD .*bar2' stdout
+
+# Cleaning and then rebuilding with the same V flag (and without
+# removing the generated sources in between) shouldn't trigger a
+# different set of rules.
+$MAKE clean
+
+run_make -O
+
+$EGREP ' (-c|-o)' stdout && exit 1
+$EGREP '(mv|ylwrap) ' stdout && exit 1
+
+# Don't look for LEX, as probably lex hasn't been re-run.
+grep ' CC .*foo\.' stdout
+grep ' CC .*bar\.' stdout
+grep 'CCLD .*foo1' stdout
+grep 'CCLD .*bar1' stdout
+grep 'CCLD .*foo2' stdout
+grep 'CCLD .*bar2' stdout
+
+# Ensure a truly clean rebuild.
+$MAKE clean
+rm -f *foo.c sub/*bar.c
+
+run_make -O V=1
+
+grep ' -c ' stdout
+grep ' -o ' stdout
+grep 'ylwrap ' stdout
+
+$EGREP '(LEX|CC|CCLD) ' stdout && exit 1
+
+# Cleaning and then rebuilding with the same V flag (and without
+# removing the generated sources in between) shouldn't trigger a
+# different set of rules.
+$MAKE clean
+
+run_make -O V=1
+
+# Don't look for ylwrap, as probably lex hasn't been re-run.
+grep ' -c ' stdout
+grep ' -o ' stdout
+
+$EGREP '(LEX|CC|CCLD) ' stdout && exit 1
+
+:
diff --git a/t/silent-lt.sh b/t/silent-lt.sh
new file mode 100644
index 000000000..a5dbb00fe
--- /dev/null
+++ b/t/silent-lt.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode for C, with libtool, both with and without
+# automatic dependency tracking.
+
+required='cc libtoolize'
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'EOF'
+AC_CONFIG_FILES([sub/Makefile])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+lib_LTLIBRARIES = libfoo.la libbar.la
+libbar_la_CFLAGS = $(AM_CFLAGS)
+SUBDIRS = sub
+EOF
+
+cat > sub/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+# Need generic and non-generic rules.
+lib_LTLIBRARIES = libbaz.la libbla.la
+libbla_la_CFLAGS = $(AM_CFLAGS)
+EOF
+
+cat > libfoo.c <<'EOF'
+int main ()
+{
+ return 0;
+}
+EOF
+cp libfoo.c libbar.c
+cp libfoo.c sub/libbaz.c
+cp libfoo.c sub/libbla.c
+
+libtoolize
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+for config_args in \
+ '--enable-dependency-tracking' \
+ '--disable-dependency-tracking' \
+; do
+
+ ./configure --enable-silent-rules $config_args
+
+ run_make -O
+
+ $EGREP ' (-c|-o)' stdout && exit 1
+ grep 'mv ' stdout && exit 1
+ grep ' CC .*foo\.' stdout
+ grep ' CC .*bar\.' stdout
+ grep ' CC .*baz\.' stdout
+ grep ' CC .*bla\.' stdout
+ grep ' CCLD .*foo' stdout
+ grep ' CCLD .*bar' stdout
+ grep ' CCLD .*baz' stdout
+ grep ' CCLD .*bla' stdout
+
+ $MAKE clean
+ run_make -O V=1
+ grep ' -c' stdout
+ grep ' -o libfoo' stdout
+ # The libtool command line can contain e.g. a '--tag=CC' option.
+ sed 's/--tag=[^ ]*/--tag=x/g' stdout | $EGREP '(CC|LD) ' && exit 1
+
+ $MAKE distclean
+
+done
+
+:
diff --git a/t/silent-many-languages.sh b/t/silent-many-languages.sh
new file mode 100644
index 000000000..d955aed22
--- /dev/null
+++ b/t/silent-many-languages.sh
@@ -0,0 +1,253 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode, with many languages at once.
+# This test partly overlaps with other 'silent*.sh', but it serves as
+# a stress test by using many different languages at once -- so don't
+# remove this test script.
+
+required='cc c++ fortran fortran77 lex yacc'
+. test-init.sh
+
+# Avoids too much code duplication.
+do_and_check_silent_build ()
+{
+ case $1 in
+ --rebuild) rebuild=true;;
+ *) rebuild=false;;
+ esac
+
+ run_make -O
+ # Avoid spurious failures with SunStudio Fortran compilers.
+ sed '/^NOTICE:/d' stdout > t
+ mv -f t stdout
+ cat stdout
+
+ $EGREP ' (-c|-o)' stdout && exit 1
+ $EGREP '(mv|ylwrap) ' stdout && exit 1
+
+ grep 'CXX .*foo1\.' stdout
+ grep 'CXX .*baz1\.' stdout
+ grep 'FC .*foo2\.' stdout
+ grep 'FC .*baz2\.' stdout
+ grep 'F77 .*foo3\.' stdout
+ grep 'F77 .*baz3\.' stdout
+ grep ' CC .*foo5\.' stdout
+ grep ' CC .*baz5\.' stdout
+ grep ' CC .*foo6\.' stdout
+ grep ' CC .*baz6\.' stdout
+
+ grep 'CXXLD .*foo' stdout
+ grep 'CCLD .*bar' stdout
+ grep 'CXXLD .*baz' stdout
+ grep 'CCLD .*bla' stdout
+
+ if ! $rebuild; then
+ grep 'YACC .*foo6\.' stdout
+ grep 'YACC .*baz6\.' stdout
+ grep 'LEX .*foo5\.' stdout
+ grep 'LEX .*baz5\.' stdout
+ fi
+
+ unset rebuild
+}
+
+# Avoids too much code duplication.
+do_and_check_verbose_build ()
+{
+ case $1 in
+ --rebuild) rebuild=true;;
+ *) rebuild=false;;
+ esac
+
+ run_make -O V=1
+
+ grep ' -c ' stdout
+ grep ' -o ' stdout
+
+ $EGREP '(CC|CXX|FC|F77|LD) ' stdout && exit 1
+
+ if ! $rebuild; then
+ grep 'ylwrap ' stdout
+ $EGREP '(LEX|YACC) ' stdout && exit 1
+ fi
+
+ unset rebuild
+}
+
+mkdir sub
+
+cat >>configure.ac <<'EOF'
+AC_PROG_F77
+AC_PROG_FC
+AC_PROG_LEX
+AC_PROG_YACC
+AC_PROG_CXX
+
+# The SunStudio C++ compiler is unfortunately named 'sunCC' (or even just
+# 'CC', yuck!); similarly and the Portland group C++ compiler is named
+# 'pgCC'. This can cause problems with our grepping checks on the output
+# from make. Avoid these problems by invoking a wrapper script, as
+# filtering the make output proved too fragile.
+case " $CXX " in
+ *'CC '*)
+ AC_MSG_WARN([the C++ compiler '$CXX' name ends with 'CC'])
+ AC_MSG_WARN([it will be wrapped with the custom script 'am--cxx'])
+ echo '#!/bin/sh' > bin/am--cxx
+ echo 'PATH=$saved_PATH; export PATH' >> bin/am--cxx
+ echo "case \$# in" >> bin/am--cxx
+ echo " 0) exec $CXX ;;" >> bin/am--cxx
+ echo " *) exec $CXX \"\$@\" ;;" >> bin/am--cxx
+ echo "esac" >> bin/am--cxx
+ chmod a+x bin/am--cxx
+ CXX=am--cxx
+esac
+
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+bin_PROGRAMS = foo bar fo2
+bar_CFLAGS = $(AM_CFLAGS)
+foo_SOURCES = foo1.cpp foo2.f90 foo3.f foo5.l foo6.y
+fo2_SOURCES = $(foo_SOURCES)
+fo2_CPPFLAGS = $(AM_CPPFLAGS)
+fo2_FFLAGS = $(AM_FFLAGS)
+fo2_FCFLAGS = $(AM_FCFLAGS)
+fo2_YFLAGS = -v
+fo2_LFLAGS = -n
+SUBDIRS = sub
+AM_YFLAGS = -d
+LDADD = $(LEXLIB)
+BUILT_SOURCES = foo6.h
+EOF
+
+cat > sub/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+# Need generic and non-generic rules.
+bin_PROGRAMS = baz bla ba2
+bla_CFLAGS = $(AM_CFLAGS)
+baz_SOURCES = baz1.cpp baz2.f90 baz3.f baz5.l baz6.y
+ba2_SOURCES = $(baz_SOURCES)
+ba2_CPPFLAGS = $(AM_CPPFLAGS)
+ba2_FFLAGS = $(AM_FFLAGS)
+ba2_FCFLAGS = $(AM_FCFLAGS)
+ba2_YFLAGS = -v
+ba2_LFLAGS = -n
+AM_YFLAGS = -d
+LDADD = $(LEXLIB)
+BUILT_SOURCES = baz6.h
+EOF
+
+cat > foo1.cpp <<'EOF'
+int main ()
+{
+ return 0;
+}
+EOF
+cat > foo2.f90 <<'EOF'
+ subroutine foo2
+ return
+ end
+EOF
+cat > foo3.f <<'EOF'
+ subroutine foo3
+ return
+ end
+EOF
+cat > foo5.l <<'EOF'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"END" return EOF;
+.
+%%
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+ return 1;
+}
+EOF
+cat > foo6.y <<'EOF'
+%{
+void yyerror (char *s) {}
+%}
+%token EOF
+%%
+fubar : 'f' 'o' 'o' 'b' 'a' 'r' EOF {};
+EOF
+cp foo1.cpp bar.c
+cp foo1.cpp sub/baz.c
+cp foo1.cpp sub/bla.c
+cp foo1.cpp sub/baz1.cpp
+cp foo2.f90 sub/baz2.f90
+cp foo3.f sub/baz3.f
+cp foo5.l sub/baz5.l
+cp foo6.y sub/baz6.y
+
+mkdir bin
+saved_PATH=$PATH; export saved_PATH
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+# Ensure per-target rules are used, to ensure their coverage below.
+# (We do not do an exhaustive check, that wouldn't be practical).
+$FGREP 'bar-bar.o' Makefile.in
+$FGREP 'fo2-foo5.c' Makefile.in
+$FGREP 'fo2-foo6.c' Makefile.in
+
+# Force dependency tracking explicitly, so that slow dependency
+# extractors are not rejected. Try also with dependency tracking
+# explicitly disabled.
+for config_args in \
+ --enable-dependency-tracking --disable-dependency-tracking
+do
+
+ ./configure $config_args --enable-silent-rules
+
+ do_and_check_silent_build
+ # Cleaning and then rebuilding with the same V flag (and without
+ # removing the generated sources in between) shouldn't trigger a
+ # different set of rules.
+ $MAKE clean
+ do_and_check_silent_build --rebuild
+
+ # Ensure a clean rebuild.
+ $MAKE clean
+ # This is required, since these files are not removed by 'make clean'
+ # (as dictated by the GNU Coding Standards).
+ rm -f *foo5.c *foo6.[ch] sub/*baz5.c sub/*baz6.[ch]
+
+ do_and_check_verbose_build
+ # Cleaning and then rebuilding with the same V flag (and without
+ # removing the generated sources in between) shouldn't trigger a
+ # different set of rules.
+ $MAKE clean
+ do_and_check_verbose_build --rebuild
+
+ # Ensure a clean reconfiguration/rebuild.
+ $MAKE clean
+ $MAKE maintainer-clean
+
+done
+
+:
diff --git a/t/silent-nested-vars.sh b/t/silent-nested-vars.sh
new file mode 100644
index 000000000..c62a15c41
--- /dev/null
+++ b/t/silent-nested-vars.sh
@@ -0,0 +1,144 @@
+#!/bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode, on 'make' implementations that do not
+# support nested variables (Bug#9928, Bug#10237).
+
+. test-init.sh
+
+cat >>configure.ac <<'EOF'
+AM_SILENT_RULES
+AC_PROG_CC
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+bin_PROGRAMS = foo bar
+bar_CFLAGS = $(AM_CFLAGS)
+
+# Check that AM_V and AM_DEFAULT_V work as advertised.
+pkg_verbose = $(pkg_verbose_@AM_V@)
+pkg_verbose_ = $(pkg_verbose_@AM_DEFAULT_V@)
+pkg_verbose_0 = @echo PKG-GEN $@;
+
+bin_SCRIPTS = oop
+oop:
+ $(pkg_verbose)echo $@ >$@
+
+mostlyclean-local:
+ rm -f oop
+EOF
+
+cat > foo.c <<'EOF'
+int main ()
+{
+ return 0;
+}
+EOF
+cp foo.c bar.c
+
+cat >mymake <<'EOF'
+#! /bin/sh
+makerules=
+
+case $1 in
+ -f)
+ makefile=$2
+ case $2 in
+ -) makerules=`cat` || exit ;;
+ esac ;;
+ *)
+ for makefile in makefile Makefile; do
+ test -f $makefile && break
+ done ;;
+esac
+
+nested_var_pat='^[^#].*\$([^)]*\$'
+if
+ case $makefile in
+ -) printf '%s\n' "$makerules" | grep "$nested_var_pat";;
+ *) grep "$nested_var_pat" $makefile;;
+ esac
+then
+ echo >&2 "mymake: $makefile contains nested variables"
+ exit 1
+fi
+
+case $makefile in
+ -) printf '%s\n' "$makerules" | $mymake_MAKE "$@";;
+ *) exec $mymake_MAKE "$@";;
+esac
+EOF
+chmod a+x mymake
+mymake_MAKE=${MAKE-make}
+MAKE=./mymake
+export MAKE mymake_MAKE
+
+# As a sanity check, verify that 'mymake' rejects Makefiles that
+# use nested variables.
+cat > Makefile <<'END'
+a = $(b$(c))
+all:
+ touch bar
+END
+$MAKE && exit 99
+mv -f Makefile foo.mk
+$MAKE -f foo.mk && exit 99
+cat foo.mk | $MAKE -f - && exit 99
+test -f bar && exit 99
+sed '/a =/d' foo.mk > Makefile
+$MAKE && test -f bar || exit 99
+rm -f bar Makefile foo.mk
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure --enable-silent-rules >stdout || { cat stdout; exit 1; }
+cat stdout
+grep '^checking whether \./mymake supports nested variables\.\.\. no *$' \
+ stdout
+$EGREP 'CC|AM_V|GEN' Makefile # For debugging.
+grep '^AM_V_CC = *\$(am__v_CC_0) *$' Makefile
+grep '^AM_V_GEN = *\$(am__v_GEN_0) *$' Makefile
+run_make -O
+$EGREP ' (-c|-o)' stdout && exit 1
+grep 'mv ' stdout && exit 1
+grep 'echo .*oop' stdout && exit 1
+grep 'CC .*foo\.' stdout
+grep 'CC .*bar\.' stdout
+grep 'CCLD .*foo' stdout
+grep 'CCLD .*bar' stdout
+grep 'PKG-GEN .*oop' stdout
+$MAKE distclean
+
+./configure --disable-silent-rules > stdout || { cat stdout; exit 1; }
+cat stdout
+grep '^checking whether \./mymake supports nested variables\.\.\. no *$' \
+ stdout
+$EGREP 'CC|AM_V|GEN' Makefile # For debugging.
+grep '^AM_V_CC = *\$(am__v_CC_1) *$' Makefile
+grep '^AM_V_GEN = *\$(am__v_GEN_1) *$' Makefile
+
+run_make -O
+grep ' -c' stdout
+grep ' -o foo' stdout
+grep ' -o bar' stdout
+grep 'echo .*>oop' stdout
+$EGREP '(CC|LD) ' stdout && exit 1
+
+:
diff --git a/t/silent-texi.sh b/t/silent-texi.sh
new file mode 100644
index 000000000..dc694f798
--- /dev/null
+++ b/t/silent-texi.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check texinfo rules in silent-rules mode.
+
+required='makeinfo tex texi2dvi dvips'
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'EOF'
+info_TEXINFOS = foo.texi sub/zardoz.texi
+EOF
+
+cat > foo.texi <<'EOF'
+\input texinfo
+@setfilename foo.info
+@settitle foo manual
+@bye
+EOF
+
+mkdir sub
+cat > sub/zardoz.texi <<'EOF'
+\input texinfo
+@setfilename zardoz.info
+@settitle zardoz manual
+@bye
+EOF
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure --disable-silent-rules
+
+# Silent mode output.
+run_make -O -E -- V=0 dvi html info ps pdf
+grep '^ DVIPS foo\.ps$' stdout
+grep '^ MAKEINFO foo\.html$' stdout
+# NetBSD make will print './foo.info' instead of 'foo.info'.
+$EGREP '^ MAKEINFO (\./)?foo\.info$' stdout
+grep '^ TEXI2DVI foo\.dvi$' stdout
+grep '^ TEXI2PDF foo\.pdf$' stdout
+grep '^ DVIPS sub/zardoz.ps$' stdout
+grep '^ MAKEINFO sub/zardoz.html$' stdout
+# NetBSD make will print './sub/zardoz.info' instead of 'zardoz.info'.
+$EGREP '^ MAKEINFO (\./)?sub/zardoz.info$' stdout
+grep '^ TEXI2DVI sub/zardoz.dvi$' stdout
+grep '^ TEXI2PDF sub/zardoz.pdf$' stdout
+# No make recipe is displayed before being executed.
+$EGREP 'texi2(dvi|pdf)|dvips|makeinfo|(rm|mv) ' \
+ stdout stderr && exit 1
+# No verbose output from TeX nor dvips.
+$EGREP '(zardoz|foo)\.log|3\.14|Copyright|This is|[Oo]utput ' \
+ stdout stderr && exit 1
+
+# Verbose mode output.
+$MAKE clean || exit 1
+run_make -M V=1 dvi html info ps pdf
+$EGREP '(DVIPS|MAKEINFO|TEXI2(PDF|DVI)) ' output && exit 1
+# Verbose output from TeX.
+grep '[Oo]utput .*foo\.pdf' output
+grep '[Oo]utput .*zardoz\.pdf' output
+$FGREP 'foo.log' output
+$FGREP 'zardoz.log' output
+# Verbose output from dvips.
+$FGREP ' dvips' output
+
+:
diff --git a/t/silent-yacc-headers.sh b/t/silent-yacc-headers.sh
new file mode 100644
index 000000000..d0d5f5b74
--- /dev/null
+++ b/t/silent-yacc-headers.sh
@@ -0,0 +1,164 @@
+#!/bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode for Yacc, when yacc-generated headers are
+# involved (i.e., the '-d' option is in *YFLAGS).
+
+required='cc yacc'
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'EOF'
+AC_PROG_YACC
+AC_PROG_CC
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+AM_YFLAGS = -d
+bin_PROGRAMS = foo bar
+foo_SOURCES = parse.y
+bar_SOURCES = $(foo_SOURCES)
+bar_YFLAGS = $(AM_YFLAGS)
+EOF
+
+cat > parse.y <<'EOF'
+%{
+void yyerror (char *s) { return; }
+int yylex (void) { return 0; }
+int main (void) { return 0; }
+%}
+%token EOF
+%%
+fubar : 'f' 'o' 'o' 'b' 'a' 'r' EOF {};
+EOF
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+# Check that the expected non-generic rules has been truly generated.
+# Otherwise, the coverage offered by this test will be weaker then
+# expected and planned.
+$FGREP 'bar-parse.c' Makefile.in
+$FGREP '$(bar_YFLAGS)' Makefile.in
+
+./configure --enable-silent-rules
+
+run_make -O
+
+$EGREP ' (-c|-d|-o)' stdout && exit 1
+$EGREP '(mv|ylwrap) ' stdout && exit 1
+
+grep 'YACC *parse\.c' stdout
+grep 'updating *parse\.h' stdout
+grep 'YACC *bar-parse\.c' stdout
+grep 'updating *bar-parse\.h' stdout
+
+grep ' CC *parse\.' stdout
+grep ' CC *bar-parse\.' stdout
+grep 'CCLD *foo' stdout
+grep 'CCLD *bar' stdout
+
+# Check recovering from header removal.
+rm -f parse.h bar-parse.h
+run_make -O parse.h bar-parse.h
+
+$EGREP ' (-c|-d|-o)' stdout && exit 1
+$EGREP '(mv|ylwrap) ' stdout && exit 1
+
+grep 'YACC *parse\.c' stdout
+grep 'updating *parse\.h' stdout
+grep 'YACC *bar-parse\.c' stdout
+grep 'updating *bar-parse\.h' stdout
+
+# Cleaning and then rebuilding with the same V flag (and without
+# removing the generated sources in between) shouldn't trigger a
+# different set of rules.
+$MAKE clean
+
+run_make -O
+
+$EGREP ' (-c|-d|-o)' stdout && exit 1
+$EGREP '(mv|ylwrap) ' stdout && exit 1
+
+# Don't look for "YACC *.c" and "updating *.h", as yacc shouldn't
+# have been re-run.
+grep ' CC *parse\.' stdout
+grep ' CC *bar-parse\.' stdout
+grep 'CCLD *foo' stdout
+grep 'CCLD *bar' stdout
+
+# Check recovering from header removal.
+rm -f parse.h bar-parse.h
+run_make -O parse.h bar-parse.h
+
+$EGREP ' (-c|-d|-o)' stdout && exit 1
+$EGREP '(mv|ylwrap) ' stdout && exit 1
+
+grep 'YACC *parse\.c' stdout
+grep 'updating *parse\.h' stdout
+grep 'YACC *bar-parse\.c' stdout
+grep 'updating *bar-parse\.h' stdout
+
+# Ensure a truly clean rebuild.
+$MAKE maintainer-clean
+
+./configure --enable-silent-rules
+
+run_make -O V=1
+
+grep ' -c ' stdout
+grep ' -o ' stdout
+grep ' -d ' stdout
+grep 'ylwrap ' stdout
+
+$EGREP '(YACC|CC|CCLD) ' stdout && exit 1
+
+# Check recovering from header removal.
+rm -f parse.h bar-parse.h
+run_make -O V=1 parse.h bar-parse.h
+
+grep ' -d ' stdout
+grep 'ylwrap ' stdout
+
+grep 'YACC' stdout && exit 1
+
+# Cleaning and then rebuilding with the same V flag (and without
+# removing the generated sources in between) shouldn't trigger a
+# different set of rules.
+$MAKE clean
+
+run_make -O V=1
+
+# Don't look for ylwrap, as probably lex hasn't been re-run.
+grep ' -c ' stdout
+grep ' -o ' stdout
+
+$EGREP '(YACC|CC|CCLD) ' stdout && exit 1
+
+# Check recovering from header removal.
+rm -f parse.h bar-parse.h
+run_make -O V=1 parse.h bar-parse.h
+
+grep ' -d ' stdout
+grep 'ylwrap ' stdout
+
+grep 'YACC' stdout && exit 1
+
+:
diff --git a/t/silent-yacc.sh b/t/silent-yacc.sh
new file mode 100644
index 000000000..32b777212
--- /dev/null
+++ b/t/silent-yacc.sh
@@ -0,0 +1,130 @@
+#!/bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check silent-rules mode for Yacc.
+
+required='cc yacc'
+. test-init.sh
+
+mkdir sub
+
+cat >>configure.ac <<'EOF'
+AC_PROG_CC
+AC_PROG_YACC
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+# Need generic and non-generic rules.
+bin_PROGRAMS = foo1 foo2
+foo1_SOURCES = foo.y
+foo2_SOURCES = $(foo1_SOURCES)
+foo2_YFLAGS = -v
+foo2_CFLAGS = $(AM_CPPFLAGS)
+SUBDIRS = sub
+EOF
+
+cat > sub/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+# Need generic and non-generic rules.
+bin_PROGRAMS = bar1 bar2
+bar1_SOURCES = bar.y
+bar2_SOURCES = $(bar1_SOURCES)
+bar2_YFLAGS = -v
+bar2_CFLAGS = $(AM_CPPFLAGS)
+EOF
+
+cat > foo.y <<'EOF'
+%{
+void yyerror (char *s) { return; }
+int yylex (void) { return 0; }
+int main (void) { return 0; }
+%}
+%token EOF
+%%
+fubar : 'f' 'o' 'o' 'b' 'a' 'r' EOF {};
+EOF
+cp foo.y sub/bar.y
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+# Ensure per-target rules are used, to ensure their coverage below.
+$FGREP 'foo2-foo.c' Makefile.in || exit 99
+$FGREP 'bar2-bar.c' sub/Makefile.in || exit 99
+
+./configure --enable-silent-rules
+
+run_make -O
+
+$EGREP ' (-c|-o)' stdout && exit 1
+$EGREP '(mv|ylwrap) ' stdout && exit 1
+
+grep 'YACC .*foo\.' stdout
+grep 'YACC .*bar\.' stdout
+grep ' CC .*foo\.' stdout
+grep ' CC .*bar\.' stdout
+grep 'CCLD .*foo1' stdout
+grep 'CCLD .*bar1' stdout
+grep 'CCLD .*foo2' stdout
+grep 'CCLD .*bar2' stdout
+
+# Cleaning and then rebuilding with the same V flag (and without
+# removing the generated sources in between) shouldn't trigger a
+# different set of rules.
+$MAKE clean
+
+run_make -O
+
+$EGREP ' (-c|-o)' stdout && exit 1
+$EGREP '(mv|ylwrap) ' stdout && exit 1
+
+# Don't look for YACC, as probably yacc hasn't been re-run.
+grep ' CC .*foo\.' stdout
+grep ' CC .*bar\.' stdout
+grep 'CCLD .*foo1' stdout
+grep 'CCLD .*bar1' stdout
+grep 'CCLD .*foo2' stdout
+grep 'CCLD .*bar2' stdout
+
+# Ensure a truly clean rebuild.
+$MAKE clean
+rm -f *foo.[ch] sub/*bar.[ch]
+
+run_make -O V=1
+
+grep ' -c ' stdout
+grep ' -o ' stdout
+grep 'ylwrap ' stdout
+
+$EGREP '(YACC|CC|CCLD) ' stdout && exit 1
+
+# Cleaning and then rebuilding with the same V flag (and without
+# removing the generated sources in between) shouldn't trigger a
+# different set of rules.
+$MAKE clean
+
+run_make -O V=1
+
+# Don't look for ylwrap, as probably lex hasn't been re-run.
+grep ' -c ' stdout
+grep ' -o ' stdout
+
+$EGREP '(YACC|CC|CCLD) ' stdout && exit 1
+
+:
diff --git a/t/sourcefile-in-subdir.sh b/t/sourcefile-in-subdir.sh
new file mode 100644
index 000000000..8a478e00a
--- /dev/null
+++ b/t/sourcefile-in-subdir.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure subdir source file generates explicit dependency.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz widdershins
+zardoz_SOURCES = y.c x/z.c
+widdershins_SOURCES = x/z.c
+END
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+$ACLOCAL
+$AUTOMAKE -Wno-unsupported
+
+grep '^z\.o: x/z\.c$' Makefile.in
+
+:
diff --git a/t/space.sh b/t/space.sh
new file mode 100644
index 000000000..d20fc1b9f
--- /dev/null
+++ b/t/space.sh
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test leading space on macro assignment.
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am << 'END'
+ bin_PROGRAMS = foo
+foo_SOURCES = foo.c
+END
+
+$ACLOCAL
+$AUTOMAKE
diff --git a/t/specflg-dummy.sh b/t/specflg-dummy.sh
new file mode 100644
index 000000000..52344486c
--- /dev/null
+++ b/t/specflg-dummy.sh
@@ -0,0 +1,246 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that even "dummy" per-target flags triggers the use of renamed
+# objects. I.e., a definition like 'foo_CFLAGS = $(AM_CFLAGS)' should
+# always cause Automake to trigger the semantics for per-target CFLAGS,
+# even if AM_CFLAGS is undefined. Similarly for other *FLAGS variables
+# (CXXFLAGS, YFLAGS, LDFLAGS, ...)
+
+. test-init.sh
+
+# Disable shell globbing if possible.
+(set +f) >/dev/null 2>&1 && set +f
+
+oIFS=$IFS
+nl='
+'
+
+matches=
+add_match ()
+{
+ matches="$matches$nl$1"
+}
+
+do_check ()
+{
+ IFS=$nl
+ for string in $matches; do
+ IFS=$oIFS
+ $FGREP "$string" Makefile.in
+ done
+ IFS=$oIFS
+}
+
+# Fake libtool presence, so that we won't have to require it.
+cat > acinclude.m4 <<END
+AC_DEFUN([AC_PROG_LIBTOOL], [AC_SUBST([LIBTOOL], [dummy])])
+END
+: > ltmain.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_YACC
+AC_PROG_LEX
+AC_PROG_F77
+AC_PROG_FC
+AM_PROG_GCJ
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_PROG_LIBTOOL
+AM_PROG_UPC
+AC_PROG_OBJC
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS =
+lib_LIBRARIES =
+lib_LTLIBRARIES =
+END
+
+$ACLOCAL
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog1
+prog1_SOURCES = source1.c
+prog1_CFLAGS = $(AM_CFLAGS)
+END
+
+add_match 'prog1-source1.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog2
+prog2_SOURCES = source2.c
+prog2_CPPFLAGS = $(AM_CPPFLAGS)
+END
+
+add_match 'prog2-source2.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog3
+prog3_SOURCES = source3.cxx
+prog3_CXXFLAGS = $(AM_CXXFLAGS)
+END
+
+add_match 'prog3-source3.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog4
+prog4_SOURCES = source4.c++
+prog4_CPPFLAGS = $(AM_CPPFLAGS)
+END
+
+add_match 'prog4-source4.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog5
+prog5_SOURCES = source5.f
+prog5_FFLAGS = $(AM_FFLAGS)
+END
+
+add_match 'prog5-source5.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog6
+prog6_SOURCES = source6.f90
+prog6_FCFLAGS = $(AM_FCFLAGS)
+END
+
+add_match 'prog6-source6.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog7
+prog7_SOURCES = source7.r
+prog7_RFLAGS = $(AM_RFLAGS)
+END
+
+add_match 'prog7-source7.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog8
+prog8_SOURCES = source8.java
+prog8_GCJFLAGS = $(AM_GCJFLAGS)
+END
+
+add_match 'prog8-source8.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog9
+prog9_SOURCES = source9.upc
+prog9_UPCFLAGS = $(AM_UPCFLAGS)
+END
+
+add_match 'prog9-source9.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += prog10
+prog10_SOURCES = source10.m
+prog10_OBJCFLAGS = $(AM_OBJCFLAGS)
+END
+
+add_match 'prog10-source10.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += linkprog
+linkprog_SOURCES = linkprog.c
+linkprog_LDFLAGS = $(AM_LDFLAGS)
+END
+
+add_match 'linkprog_LINK ='
+
+cat >> Makefile.am <<'END'
+lib_LIBRARIES += libstatic.a
+libstatic_a_SOURCES = static123.c
+libstatic_a_CFLAGS = $(AM_CFLAGS)
+END
+
+add_match 'libstatic_a-static123.$(OBJEXT)'
+
+cat >> Makefile.am <<'END'
+lib_LTLIBRARIES += libshared1.la
+libshared1_la_SOURCES = shared1.c
+libshared1_la_LIBTOOLFLAGS = $(AM_LIBTOOLFLAGS)
+END
+
+add_match 'libshared1_la-shared1.lo'
+
+cat >> Makefile.am <<'END'
+lib_LTLIBRARIES += libshared2.la
+libshared2_la_SOURCES = shared2.cc
+libshared2_la_CXXFLAGS = $(AM_CXXFLAGS)
+END
+
+add_match 'libshared2_la-shared2.lo'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += parse1
+parse1_SOURCES = parse.y
+parse1_YFLAGS = $(AM_YFLAGS)
+END
+
+add_match 'parse1-parse.c'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += parse2
+parse2_SOURCES = parse.ypp
+parse2_YFLAGS = $(AM_YFLAGS)
+END
+
+add_match 'parse2-parse.cpp'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += lexer1
+lexer1_SOURCES = lex.l
+lexer1_LFLAGS = $(AM_YFLAGS)
+END
+
+add_match 'lexer1-lex.c'
+
+cat >> Makefile.am <<'END'
+bin_PROGRAMS += lexer2
+lexer2_SOURCES = lexer.ll
+lexer2_LFLAGS = $(AM_YFLAGS)
+END
+
+add_match 'lexer2-lexer.cc'
+
+# For debugging.
+cat Makefile.am
+
+$AUTOMAKE -a
+do_check
+
+sed '
+ s|^\(.*\)_SOURCES *= *|sub_\1_SOURCES = srcsub/|
+ s|^\(.*\)PROGRAMS *+= *|\1PROGRAMS += sub/|
+ s|^\(.*\)LIBRARIES *+= *|\1LIBRARIES += sub/|
+ s|^\(.*\)FLAGS *=|sub_\1FLAGS =|
+' Makefile.am > t
+
+cat - t > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+END
+
+rm -f t
+
+# For debugging.
+cat Makefile.am
+
+$AUTOMAKE
+do_check
+
+:
diff --git a/t/specflg6.sh b/t/specflg6.sh
new file mode 100644
index 000000000..5c13f6bd5
--- /dev/null
+++ b/t/specflg6.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Regression test for multiple rules being generated for each target when
+# conditionals are present.
+# From Richard Boulton.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([BAR], [true])
+END
+
+cat > Makefile.am << 'END'
+if BAR
+BAR_SRCS = bar.c
+endif
+
+bin_PROGRAMS = foo
+foo_CFLAGS = -DFOO
+foo_SOURCES = foo.c
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+uncondval=$($FGREP 'foo-foo.o: foo.c' Makefile.in)
+
+cat >> Makefile.am << 'END'
+foo_SOURCES += $(BAR_SRCS)
+END
+
+$AUTOMAKE
+
+condval=$($FGREP 'foo-foo.o: foo.c' Makefile.in)
+
+test "x$uncondval" = "x$condval"
+
+:
diff --git a/t/specflg7.sh b/t/specflg7.sh
new file mode 100644
index 000000000..78210a75f
--- /dev/null
+++ b/t/specflg7.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The true/false example from the manual, plus a check for _SHORTNAME.
+
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = false true
+true_SOURCES = false.c
+true_CFLAGS = -DAM_TRUE
+true_SHORTNAME = t
+# No false_SOURCES definition. Use the default source.
+false_CFLAGS = -DAM_FALSE
+false_SHORTNAME = f
+END
+
+cat > false.c << 'END'
+#include <stdio.h>
+int
+main (int argc, char *argv[])
+{
+#ifdef AM_TRUE
+ puts ("true");
+#else
+ puts ("false");
+#endif
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+./true | grep true
+./false | grep false
+
+objext=$(sed -n -e 's/^OBJEXT = //p' < Makefile)
+test -f ./t-false.$objext
+test -f ./f-false.$objext
+
+:
diff --git a/t/specflg8.sh b/t/specflg8.sh
new file mode 100644
index 000000000..cf4cb8056
--- /dev/null
+++ b/t/specflg8.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Like the true/false example from the manual,
+# with one extra indirection in the sources (PR/315), and
+# use of _CPPFLAGS (PR/337).
+
+required='cc native'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+# Using a separate variable to hold all the sources for a program is
+# common when building many flavors of this program, each with
+# different flags.
+
+cat > Makefile.am << 'END'
+TRUESOURCE = true.c
+bin_PROGRAMS = false true
+true_SOURCES = $(TRUESOURCE)
+true_CPPFLAGS = -DEXIT_CODE=0
+false_SOURCES = $(TRUESOURCE)
+false_CPPFLAGS = -DEXIT_CODE=1
+END
+
+cat > true.c << 'END'
+int main (void)
+{
+ return EXIT_CODE;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+
+./true
+./false && exit 1
+
+objext=$(sed -n -e 's/^OBJEXT = //p' < Makefile)
+test -f ./true-true.$objext
+test -f ./false-true.$objext
+
+:
diff --git a/t/specflg9.sh b/t/specflg9.sh
new file mode 100644
index 000000000..4c10340e8
--- /dev/null
+++ b/t/specflg9.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Another check for per-target flag substitutions.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = zzfoo zzbar
+zzfoo_SOURCES = sub/foo.c
+zzbar_SOURCES = bar.c
+zzbar_CPPFLAGS = -Dfoo
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+$FGREP '$(AM_CFLAGS)' Makefile.in
+
+$FGREP '$(zzfoo_CFLAGS)' Makefile.in && exit 1
+$FGREP '$(zzfoo_CPPFLAGS)' Makefile.in && exit 1
+
+$FGREP '$(zzbar_CFLAGS)' Makefile.in && exit 1
+$FGREP '$(zzbar_CPPFLAGS)' Makefile.in
+
+:
diff --git a/t/spell.sh b/t/spell.sh
new file mode 100644
index 000000000..cd9243e32
--- /dev/null
+++ b/t/spell.sh
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure misspellings in _SOURCES variables cause failure.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz foo
+zardoz_SOURCES = x.c
+boo_SOURCES = y.c
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'Makefile.am:3:.*boo' stderr
diff --git a/t/spell2.sh b/t/spell2.sh
new file mode 100644
index 000000000..88fd6775e
--- /dev/null
+++ b/t/spell2.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure misspellings in _SOURCES variables cause failure.
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = x.c
+qardoz_LDADD = -ljoe
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'Makefile.am:3:.*qardoz' stderr
diff --git a/t/spell3.sh b/t/spell3.sh
new file mode 100644
index 000000000..ddd10fc54
--- /dev/null
+++ b/t/spell3.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure some internal _DEPENDENCIES variables don't cause
+# errors.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+TAGS_DEPENDENCIES = joe
+## Required to avoid error.
+ETAGS_ARGS = joe
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/spelling.sh b/t/spelling.sh
new file mode 100644
index 000000000..d56bc6966
--- /dev/null
+++ b/t/spelling.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that misspelled prefixes actually cause error.
+
+. test-init.sh
+
+cat > Makefile.am << 'EOF'
+bni_PROGRAMS = zot
+EOF
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'bni_PROGRAMS' stderr
+grep 'bnidir.*undefined' stderr
+
+:
diff --git a/t/spy-double-colon.sh b/t/spy-double-colon.sh
new file mode 100644
index 000000000..4dc89d49b
--- /dev/null
+++ b/t/spy-double-colon.sh
@@ -0,0 +1,106 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check whether double colon rules work. The Unix V7 make manual
+# mentions double-colon rules, but POSIX does not. They seem to be
+# supported by all Make implementation as far as we can tell. This test
+# case is a spy: we want to detect if there exist implementations where
+# these do not work. We might use these rules to simplify the rebuild
+# rules (instead of the $? hack).
+
+# Tom Tromey write:
+# | In the distant past we used :: rules extensively.
+# | Fran?ois convinced me to get rid of them:
+# |
+# | Thu Nov 23 18:02:38 1995 Tom Tromey <tromey@cambric>
+# | [ ... ]
+# | * subdirs.am: Removed "::" rules
+# | * header.am, libraries.am, mans.am, texinfos.am, footer.am:
+# | Removed "::" rules
+# | * scripts.am, programs.am, libprograms.am: Removed "::" rules
+# |
+# |
+# | I no longer remember the rationale for this. It may have only been a
+# | belief that they were unportable.
+
+# On a related topic, the Autoconf manual has the following text:
+# | 'VPATH' and double-colon rules
+# | Any assignment to 'VPATH' causes Sun 'make' to only execute
+# | the first set of double-colon rules. (This comment has been
+# | here since 1994 and the context has been lost. It's probably
+# | about SunOS 4. If you can reproduce this, please send us a
+# | test case for illustration.)
+
+# We already know that overlapping ::-rule like
+#
+# a :: b
+# echo rule1 >> $@
+# a :: c
+# echo rule2 >> $@
+# a :: b c
+# echo rule3 >> $@
+#
+# do not work equally on all platforms. It seems that in all cases
+# Make attempts to run all matching rules. However at least GNU Make,
+# NetBSD Make, and FreeBSD Make will detect that $@ was updated by the
+# first matching rule and skip remaining matches (with the above
+# example that means that unless 'a' was declared PHONY, only "rule1"
+# will be appended to 'a' if both b and c have changed). Other
+# implementations like OSF1 Make and HP-UX Make do not perform such a
+# check and execute all matching rules whatever they do ("rule1",
+# "rule2", abd "rule3" will all be appended to 'a' if b and c have
+# changed).
+
+# So it seems only non-overlapping ::-rule may be portable. This is
+# what we check now.
+
+. test-init.sh
+
+cat >Makefile <<\EOF
+a :: b
+ echo rule1 >> $@
+a :: c
+ echo rule2 >> $@
+EOF
+
+touch b c
+$sleep
+: > a
+$MAKE
+test x"$(cat a)" = x
+$sleep
+touch b
+$MAKE
+test "$(cat a)" = "rule1"
+# Ensure a is strictly newer than b, so HP-UX make does not execute rule2.
+$sleep
+: > a
+$sleep
+touch c
+$MAKE
+test "$(cat a)" = "rule2"
+
+# Unfortunately, the following is not portable to FreeBSD/NetBSD/OpenBSD
+# make, see explanation above.
+
+#: > a
+#$sleep
+#touch b c
+#$MAKE
+#grep rule1 a
+#grep rule2 a
+
+:
diff --git a/t/spy-rm.tap b/t/spy-rm.tap
new file mode 100644
index 000000000..0f754cef2
--- /dev/null
+++ b/t/spy-rm.tap
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check whether "rm -f" do not complain if called without file
+# operands. We'd like to depend on this behaviour (which seems
+# to hold on all non-museum systems, and will soon be mandated
+# by POSIX as well) in future version of automake, to simplify
+# automake-provided cleanup rules.
+# See automake bug#10828.
+# Other references:
+# <https://lists.gnu.org/archive/html/bug-autoconf/2012-02/msg00002.html>
+# <http://austingroupbugs.net/view.php?id=542>
+
+am_create_testdir=empty
+. test-init.sh
+
+plan_ 10
+
+chk ()
+{
+ if test -f /bin/rm; then
+ command_ok_ "/bin/rm $*" /bin/rm "$@"
+ else
+ skip_ -r "/bin/rm not found"
+ fi
+ command_ok_ "rm $*" rm "$@"
+}
+
+chk -f
+chk -rf
+chk -fr
+chk -f -r
+chk -r -f
+
+:
diff --git a/t/src-acsubst.sh b/t/src-acsubst.sh
new file mode 100644
index 000000000..cf5722e93
--- /dev/null
+++ b/t/src-acsubst.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure config substitution in _SOURCES fails.
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = x y
+x_SOURCES = x.c @FOO@
+bar = @FOO@
+foo = $(bar)
+EXTRA_y_SOURCES = $(foo) y.c
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+
+cat > exp-err << 'END'
+Makefile.am:2: error: 'x_SOURCES' includes configure substitution '@FOO@';
+Makefile.am:2: configure substitutions are not allowed in _SOURCES variables
+Makefile.am:3: error: 'bar' includes configure substitution '@FOO@'
+Makefile.am:3: and is referred to from 'EXTRA_y_SOURCES';
+Makefile.am:3: configure substitutions are not allowed in _SOURCES variables
+END
+
+diff exp-err stderr
+
+:
diff --git a/t/stamph2.sh b/t/stamph2.sh
new file mode 100644
index 000000000..72afbd721
--- /dev/null
+++ b/t/stamph2.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure stamp-h* files are created where we expect
+. test-init.sh
+
+cat >> configure.ac << END
+AC_CONFIG_HEADERS([1.h
+ 2.h:config.hin
+ 3.h:sdir1/config1.hin])
+AC_CONFIG_HEADERS([sdir1/4.h
+ sdir1/5.h:config.hin
+ sdir1/6.h:sdir1/config1.hin
+ sdir1/7.h:sdir2/config2.hin])
+AC_OUTPUT
+END
+
+: > Makefile.am
+mkdir sdir1
+mkdir sdir2
+: > config.hin
+: > 1.h.in
+: > sdir1/4.h.in
+: > sdir1/config1.hin
+: > sdir2/config2.hin
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+test -f stamp-h1
+test -f stamp-h2
+test -f stamp-h3
+test -f sdir1/stamp-h4
+test -f sdir1/stamp-h5
+test -f sdir1/stamp-h6
+test -f sdir1/stamp-h7
+
+# Make sure './config.status foo' creates the right stamp file.
+# Report from Sander Niemeijer.
+
+rm -f stamp-h*
+rm -f sdir1/stamp-h*
+
+./config.status sdir1/7.h 2.h sdir1/4.h
+test ! -e stamp-h1
+test -f stamp-h2
+test ! -e stamp-h3
+test -f sdir1/stamp-h4
+test ! -e sdir1/stamp-h5
+test ! -e sdir1/stamp-h6
+test -f sdir1/stamp-h7
+
+:
diff --git a/t/stdinc.sh b/t/stdinc.sh
new file mode 100644
index 000000000..c4b5c21fb
--- /dev/null
+++ b/t/stdinc.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2007-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure the standard include order is stable.
+# Report by Kent Boortz.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_CONFIG_HEADERS([sub/config.h])
+AC_CONFIG_FILES([sub/bar.h])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c
+BUILT_SOURCES = bar.h
+END
+
+mkdir sub
+
+cat >foo.c <<'END'
+#include <config.h>
+#include <bar.h>
+int main() { return bar (); }
+END
+cat >bar.h <<'END'
+int bar () { return 0; }
+END
+cat >sub/bar.h.in <<'END'
+choke me
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE
+
+mkdir build
+cd build
+../configure -C
+$MAKE
+
+cd ..
+./configure -C
+$MAKE
diff --git a/t/stdlib.sh b/t/stdlib.sh
new file mode 100644
index 000000000..dbbac7671
--- /dev/null
+++ b/t/stdlib.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test "not a standard library" error.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = sub/foo
+include $(srcdir)/foo.mk
+END
+
+cat > foo.mk << 'END'
+## A dummy automake comment.
+a = x \
+ y
+# A dummy make comment.
+lib_LIBRARIES = zardoz.a
+END
+
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+badname='not a standard library name'
+# We're specifically testing for line-number information.
+grep "^Makefile\\.am:1:.*'sub/foo'.*$badname" stderr
+grep "^Makefile\\.am:1:.*sub/libfoo\\.a" stderr
+grep "^foo\\.mk:5:.*'zardoz\\.a'.*$badname" stderr
+grep "^foo\\.mk:5:.*libzardoz\\.a" stderr
+
+:
diff --git a/t/stdlib2.sh b/t/stdlib2.sh
new file mode 100644
index 000000000..7ca5d7218
--- /dev/null
+++ b/t/stdlib2.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for AM_LDFLAGS = -module
+# Report from Kevin P. Fleming.
+required=libtool
+. test-init.sh
+
+: > README
+: > NEWS
+: > AUTHORS
+: > ChangeLog
+: > ltconfig
+: > ltmain.sh
+: > config.guess
+: > config.sub
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+: > Makefile.inc
+
+cat > Makefile.am << 'END'
+include Makefile.inc
+lib_LTLIBRARIES = nonstandard.la
+nonstandard_la_SOURCES = foo.c
+FOO = -module
+END
+
+$ACLOCAL
+AUTOMAKE_fails --add-missing --gnu
+grep 'Makefile.am:2:.*nonstandard.la.*standard libtool library name' stderr
+grep 'Makefile.am:2:.*libnonstandard.la' stderr
+
+# We will use -Wno-gnu to disable the warning about setting LDFLAGS (below)
+# Make sure nonstandard names are diagnosed anyway.
+AUTOMAKE_fails --add-missing --gnu -Wno-gnu
+grep 'Makefile.am:2:.*nonstandard.la.*standard libtool library name' stderr
+grep 'Makefile.am:2:.*libnonstandard.la' stderr
+
+# Make sure nonstandard_la_LDFLAGS is read even if LDFLAGS is used.
+cat >Makefile.inc <<'EOF'
+LDFLAGS = -lfoo
+nonstandard_la_LDFLAGS = $(FOO)
+EOF
+$AUTOMAKE -Wno-gnu
+
+# Make sure LDFLAGS is read even if nonstandard_la_LDFLAGS is used.
+cat >Makefile.inc <<'EOF'
+LDFLAGS = $(FOO)
+nonstandard_la_LDFLAGS = -lfoo
+EOF
+$AUTOMAKE -Wno-gnu
+
+# Make sure AM_LDFLAGS is not read if foo_LDFLAGS is used.
+cat >Makefile.inc <<'EOF'
+nonstandard_la_LDFLAGS = -lfoo
+AM_LDFLAGS = -module
+EOF
+AUTOMAKE_fails
+grep 'Makefile.am:2:.*nonstandard.la.*standard libtool library name' stderr
+grep 'Makefile.am:2:.*libnonstandard.la' stderr
+
+echo 'AM_LDFLAGS = -module' > Makefile.inc
+$AUTOMAKE
+
+# For module, Automake should not suggest the lib prefix.
+cat > Makefile.am << 'END'
+include Makefile.inc
+lib_LTLIBRARIES = nonstandard
+nonstandard_SOURCES = foo.c
+FOO = -module
+END
+
+AUTOMAKE_fails
+grep "Makefile.am:2:.*'nonstandard'.*standard libtool module name" stderr
+grep 'Makefile.am:2:.*nonstandard.la' stderr
diff --git a/t/strictness-override.sh b/t/strictness-override.sh
new file mode 100644
index 000000000..6a775b36e
--- /dev/null
+++ b/t/strictness-override.sh
@@ -0,0 +1,123 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The strictness specified in Makefile.am:AUTOMAKE_OPTIONS should
+# override that specified in configure.ac:AM_INIT_AUTOMAKE, and both
+# should override the strictness specified on the command line.
+# NOTE: the current semantics might not be the best one (even if it has
+# been in place for quite a long time); see also Automake bug #7673.
+# Update this test if the semantics are changed.
+
+. test-init.sh
+
+# We want complete control over automake options.
+AUTOMAKE=$am_original_AUTOMAKE
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS =
+END
+
+set_strictness ()
+{
+ set +x
+ sed <$2 >$2-t -e "s|^\\(AUTOMAKE_OPTIONS\\) *=.*|\\1 = $1|" \
+ -e "s|^\\(AM_INIT_AUTOMAKE\\).*|\\1([$1])|"
+ mv -f $2-t $2
+ set -x
+ cat $2
+}
+
+ok ()
+{
+ $AUTOMAKE -Werror $*
+}
+
+ko ()
+{
+ AUTOMAKE_fails $*
+ grep 'required file.*README' stderr
+}
+
+$ACLOCAL
+
+# Leave out only one of the required files, to avoid too much
+# repetition in the error messages.
+touch INSTALL NEWS AUTHORS ChangeLog COPYING
+
+rm -rf autom4te*.cache
+set_strictness '' Makefile.am
+set_strictness '' configure.ac
+ko --gnu
+ko
+ok --foreign
+
+rm -rf autom4te*.cache
+set_strictness 'gnu' Makefile.am
+set_strictness '' configure.ac
+ko --gnu
+ko
+ko --foreign
+
+rm -rf autom4te*.cache
+set_strictness '' Makefile.am
+set_strictness 'gnu' configure.ac
+ko --gnu
+ko
+ko --foreign
+
+rm -rf autom4te*.cache
+set_strictness 'foreign' Makefile.am
+set_strictness '' configure.ac
+ok --gnu
+ok
+ok --foreign
+
+rm -rf autom4te*.cache
+set_strictness '' Makefile.am
+set_strictness 'foreign' configure.ac
+ok --gnu
+ok
+ok --foreign
+
+rm -rf autom4te*.cache
+set_strictness 'gnu' Makefile.am
+set_strictness 'gnu' configure.ac
+ko --gnu
+ko
+ko --foreign
+
+rm -rf autom4te*.cache
+set_strictness 'foreign' Makefile.am
+set_strictness 'foreign' configure.ac
+ok --gnu
+ok
+ok --foreign
+
+rm -rf autom4te*.cache
+set_strictness 'foreign' Makefile.am
+set_strictness 'gnu' configure.ac
+ok --gnu
+ok
+ok --foreign
+
+rm -rf autom4te*.cache
+set_strictness 'gnu' Makefile.am
+set_strictness 'foreign' configure.ac
+ko --gnu
+ko
+ko --foreign
+
+:
diff --git a/t/strictness-precedence.sh b/t/strictness-precedence.sh
new file mode 100644
index 000000000..d27370d0d
--- /dev/null
+++ b/t/strictness-precedence.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# On the command line, in AM_INIT_AUTOMAKE, and in AUTOMAKE_OPTIONS,
+# strictness specified later should take precedence over strictness
+# specified earlier.
+
+. test-init.sh
+
+# We want complete control over automake options.
+AUTOMAKE=$am_original_AUTOMAKE
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS =
+END
+
+set_strictness ()
+{
+ set +x
+ sed <$2 >$2-t -e "s|^\\(AUTOMAKE_OPTIONS\\) *=.*|\\1 = $1|" \
+ -e "s|^\\(AM_INIT_AUTOMAKE\\).*|\\1([$1])|"
+ mv -f $2-t $2
+ set -x
+ cat $2
+}
+
+ok ()
+{
+ $AUTOMAKE -Werror $*
+}
+
+ko ()
+{
+ AUTOMAKE_fails $*
+ grep 'required file.*README' stderr
+}
+
+# Leave out only one of the required files, to avoid too much
+# repetition in the error messages.
+touch INSTALL NEWS AUTHORS ChangeLog COPYING
+
+$ACLOCAL
+ko --foreign --gnu
+ok --gnu --foreign
+
+set_strictness '' Makefile.am
+set_strictness 'gnu foreign' configure.ac
+rm -rf autom4te*.cache
+$ACLOCAL
+ok
+set_strictness 'foreign gnu' configure.ac
+rm -rf autom4te*.cache
+$ACLOCAL
+ko
+
+set_strictness '' configure.ac
+rm -rf autom4te*.cache
+$ACLOCAL
+set_strictness 'gnu foreign' Makefile.am
+ok
+set_strictness 'foreign gnu' Makefile.am
+ko
+
+:
diff --git a/t/strip.sh b/t/strip.sh
new file mode 100644
index 000000000..96c326a32
--- /dev/null
+++ b/t/strip.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for install-strip.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_SCRIPTS = foo
+END
+
+cat > foo << 'END'
+#! /bin/sh
+echo Maude
+END
+
+chmod +x foo
+
+mkdir install
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+prefix=$(cd install && pwd) || exit 99
+./configure --prefix="$prefix"
+$MAKE
+$MAKE install-strip
+diff foo "$prefix"/bin/foo
+
+:
diff --git a/t/strip2.sh b/t/strip2.sh
new file mode 100644
index 000000000..6c9045d76
--- /dev/null
+++ b/t/strip2.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure install-strip works when STRIP consists of more than one word.
+# This test needs GNU binutils strip. See sister test 'strip3.sh'.
+
+required='cc strip'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+lib_LIBRARIES = libfoo.a
+END
+
+echo 'int main (void) { return 0; }' > foo.c
+echo 'int foo (void) { return 0; }' > libfoo.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure --prefix="$(pwd)/inst" STRIP='strip --verbose'
+$MAKE
+$MAKE install-strip
+
+:
diff --git a/t/strip3.sh b/t/strip3.sh
new file mode 100644
index 000000000..e9c845902
--- /dev/null
+++ b/t/strip3.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Ensure install-strip works when STRIP consists of more than one word.
+# This test needs GNU binutils strip. Libtool variant. See sister
+# test 'strip2.sh'.
+
+required='cc libtoolize strip'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+lib_LTLIBRARIES = libfoo.la
+END
+
+echo 'int main (void) { return 0; }' > foo.c
+echo 'int foo (void) { return 0; }' > libfoo.c
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure --prefix="$(pwd)/inst" STRIP='strip --verbose'
+$MAKE
+$MAKE install-strip
+
+:
diff --git a/t/subdir-ac-subst.sh b/t/subdir-ac-subst.sh
new file mode 100644
index 000000000..594891319
--- /dev/null
+++ b/t/subdir-ac-subst.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The for conditional SUBDIRS.
+# SUBDIRS + AC_SUBST setup from the manual.
+# Lots of lines here are duplicated in 'subcond-am-cond.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+if test "$want_opt" = yes; then
+ MAYBE_OPT=opt
+else
+ MAYBE_OPT=
+fi
+AC_SUBST([MAYBE_OPT])
+AC_CONFIG_FILES([src/Makefile opt/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = src $(MAYBE_OPT)
+DIST_SUBDIRS = src opt
+
+# Testing targets.
+#
+# We want to ensure that
+# - src/source and opt/source are always distributed.
+# - src/result is always built
+# - opt/result is built conditionally
+#
+# We rely on 'distcheck' to run 'check-local' and use
+# 'sanity1' and 'sanity2' as evidences that test-build was run.
+
+test_rootdir = $(top_builddir)/../../..
+
+test-build: all
+ test -f src/result
+ if test -n "$(MAYBE_OPT)"; then \
+ test -f opt/result || exit 1; \
+ : > $(test_rootdir)/sanity2 || exit 1; \
+ else \
+ test ! -f opt/result || exit 1; \
+ : > $(test_rootdir)/sanity1 || exit 1; \
+ fi
+
+test-dist: distdir
+ test -f $(distdir)/src/source
+ test -f $(distdir)/opt/source
+
+check-local: test-build test-dist
+END
+
+mkdir src opt
+: > src/source
+: > opt/source
+
+cat > src/Makefile.am <<'END'
+EXTRA_DIST = source
+all-local: result
+CLEANFILES = result
+
+result: source
+ cp $(srcdir)/source result
+END
+
+# We want in opt/ the same Makefile as in src/. Let's exercise 'include'.
+cat > opt/Makefile.am <<'END'
+include ../src/Makefile.am
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE distcheck
+test -f sanity1
+DISTCHECK_CONFIGURE_FLAGS=want_opt=yes $MAKE distcheck
+test -f sanity2
+
+:
diff --git a/t/subdir-add-pr46.sh b/t/subdir-add-pr46.sh
new file mode 100644
index 000000000..339645c5e
--- /dev/null
+++ b/t/subdir-add-pr46.sh
@@ -0,0 +1,96 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that adding a new directory works.
+# This test runs 'make' from the top-level directory, the sister
+# test 'subdir-add2-pr46.sh' do it from a subdirectory.
+# PR automake/46
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
+
+# Now add new directories.
+
+# First we add a new directory by modifying configure.ac directly.
+# We update configure.ac *before* updating sub/Makefile.am; the sister
+# test 'subdir-add2-pr46.sh' does it in the other way: it updates
+# confiles.m4 (which is m4_included by configure.ac there) after
+# Makefile.am.
+
+# Modified configure dependencies must be newer than config.status.
+$sleep
+sed <configure.ac >configure.tmp -e '/^AC_OUTPUT$/i\
+AC_CONFIG_FILES([maude/Makefile])\
+m4_include([confile.m4])\
+' # Last newline required by older OpenBSD sed.
+mv -f configure.tmp configure.ac
+
+cat configure.ac # For debugging.
+
+: > confile.m4
+
+mkdir maude
+
+cat > maude/Makefile.am << 'END'
+include_HEADERS = foo.h
+END
+
+: > maude/foo.h
+
+echo 'SUBDIRS = maude' >> Makefile.am
+
+# We want a simple rebuild to create maude/Makefile automatically.
+$MAKE
+grep '^SUBDIRS = *maude *$' Makefile.in
+grep '^SUBDIRS = *maude *$' Makefile
+test -f maude/Makefile
+
+# Then we add a new directory by modifying a file included (through
+# 'm4_include') by configure.ac.
+mkdir maude2
+# Modified configure dependencies must be newer than config.status.
+$sleep
+cat >> confile.m4 << 'END'
+AC_CONFIG_FILES([maude2/Makefile])
+AC_SUBST([GREPME])
+END
+: > maude2/Makefile.am
+echo 'SUBDIRS += maude2' >> Makefile.am
+
+# We want a simple rebuild to create maude2/Makefile and update
+# all other Makefiles automatically.
+$MAKE
+grep '^SUBDIRS =.* maude2' Makefile.in
+grep '^SUBDIRS =.* maude2' Makefile
+
+for ext in '.in' ''; do
+ for d in . maude maude2; do
+ grep '^GREPME =' $d/Makefile$ext
+ done
+done
+
+:
diff --git a/t/subdir-add2-pr46.sh b/t/subdir-add2-pr46.sh
new file mode 100644
index 000000000..2a4d5c00a
--- /dev/null
+++ b/t/subdir-add2-pr46.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that adding a new directory works, even from
+# subdirectories. The sister test 'subdir-add-pr46.sh' makes sure
+# it works when make is run from the top-level directory.
+# PR automake/46
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_MACRO_DIR([m4])
+m4_include([confiles.m4])
+MORE_DEFS
+AC_OUTPUT
+END
+
+echo 'AC_CONFIG_FILES([sub/Makefile])' > confiles.m4
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+END
+
+mkdir sub
+
+: > sub/Makefile.am
+
+mkdir m4
+echo 'AC_DEFUN([MORE_DEFS], [])' > m4/moredefs.m4
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
+
+# Now add new directories.
+
+# The first step users typically do when adding a new subdir is editing
+# configure.ac. That is already tested by 'subdir-add-pr46.sh' though,
+# so here we try to just edit a file that is included by configure.ac,
+# without touching configure.ac itself.
+
+mkdir sub/maude
+cat > sub/maude/Makefile.am << 'END'
+include_HEADERS = foo.h
+END
+
+: > sub/maude/foo.h
+
+echo 'SUBDIRS = maude' >> sub/Makefile.am
+
+mkdir maude
+: > maude/Makefile.am
+
+# Update confiles.m4 *after* updating sub/Makefile.am; the sister test
+# 'subdir-add-pr46.sh' does it the in other way: it updates configure.ac
+# before Makefile.am. We sleep here because modified configure
+# dependencies must be newer than config.status.
+$sleep
+echo 'AC_CONFIG_FILES([maude/Makefile sub/maude/Makefile])' >> confiles.m4
+
+# We want a simple rebuild from sub/ to create sub/maude/Makefile
+# and maude/Makefile automatically.
+cd sub
+$MAKE
+cd ..
+grep '^SUBDIRS = *maude *$' sub/Makefile.in
+grep '^SUBDIRS = *maude *$' sub/Makefile
+test -f maude/Makefile
+test -f sub/maude/Makefile
+
+# Make sure the dependencies of aclocal.m4 or honored at least from
+# the top-level directory.
+echo 'AC_DEFUN([MORE_DEFS], [AC_SUBST([GREPME])])' > m4/moredefs.m4
+$MAKE
+
+for ext in '.in' ''; do
+ for d in . maude sub sub/maude; do
+ grep '^GREPME =' $d/Makefile$ext
+ done
+done
+
+:
diff --git a/t/subdir-am-cond.sh b/t/subdir-am-cond.sh
new file mode 100644
index 000000000..042bb3fa5
--- /dev/null
+++ b/t/subdir-am-cond.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The for conditional SUBDIRS.
+# SUBDIRS + AM_CONDITIONAL setup from the manual.
+# Lots of lines here are duplicated in 'subdir-ac-subst.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
+AC_CONFIG_FILES([src/Makefile opt/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+if COND_OPT
+ MAYBE_OPT = opt
+endif
+SUBDIRS = src $(MAYBE_OPT)
+
+# Testing targets.
+#
+# We want to ensure that
+# - src/source and opt/source are always distributed.
+# - src/result is always built
+# - opt/result is built conditionally
+#
+# We rely on 'distcheck' to run 'check-local' and use
+# 'sanity1' and 'sanity2' as evidences that test-build was run.
+
+test_rootdir = $(top_builddir)/../../..
+
+if COND_OPT
+test-build: all
+ test -f src/result
+ test -f opt/result
+ : > $(test_rootdir)/sanity2
+else
+test-build: all
+ test -f src/result
+ test ! -f opt/result
+ : > $(test_rootdir)/sanity1
+endif
+
+test-dist: distdir
+ test -f $(distdir)/src/source
+ test -f $(distdir)/opt/source
+
+check-local: test-build test-dist
+END
+
+mkdir src opt
+: > src/source
+: > opt/source
+
+cat > src/Makefile.am <<'END'
+EXTRA_DIST = source
+all-local: result
+CLEANFILES = result
+
+result: source
+ cp $(srcdir)/source result
+END
+
+# We want in opt/ the same Makefile as in src/. Let's exercise 'include'.
+cat > opt/Makefile.am <<'END'
+include ../src/Makefile.am
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE distcheck
+test -f sanity1
+DISTCHECK_CONFIGURE_FLAGS=want_opt=yes $MAKE distcheck
+test -f sanity2
+
+:
diff --git a/t/subdir-cond-err.sh b/t/subdir-cond-err.sh
new file mode 100644
index 000000000..2263fbc09
--- /dev/null
+++ b/t/subdir-cond-err.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check SUBDIRS set based on conditionals.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([TEST], [true])
+END
+
+cat > Makefile.am << 'END'
+if TEST
+DIR = dir1
+else
+DIR = dir2
+endif
+SUBDIRS = $(DIR)
+END
+
+mkdir dir1
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile\.am:4:.*dir2.*does not exist' stderr
+
+:
diff --git a/t/subdir-cond-gettext.sh b/t/subdir-cond-gettext.sh
new file mode 100644
index 000000000..5b524b119
--- /dev/null
+++ b/t/subdir-cond-gettext.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# It is ok to have a conditional SUBDIRS when using gettext.
+
+required=gettext
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_GNU_GETTEXT
+AM_CONDITIONAL([MAUDE], [true])
+ALL_LINGUAS=
+AC_SUBST([ALL_LINGUAS])
+END
+
+mkdir po intl
+: >config.rpath
+
+cat > Makefile.am << 'END'
+if MAUDE
+SUBDIRS = po intl
+else
+SUBDIRS =
+endif
+END
+
+$ACLOCAL
+# Gettext wants config.guess etc.
+$AUTOMAKE --add-missing
+
+:
diff --git a/t/subdir-distclean.sh b/t/subdir-distclean.sh
new file mode 100644
index 000000000..3dd11e56c
--- /dev/null
+++ b/t/subdir-distclean.sh
@@ -0,0 +1,103 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that "./configure && make && make distclean" is actually a
+# no-op, even when conditional SUBDIRS are involved.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile sub1/subsub/Makefile])
+AM_CONDITIONAL([COND], [false])
+AC_SUBST([extra_subdirs], [''])
+AC_OUTPUT
+END
+
+mkdir sub1 sub2 sub1/subsub
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub1
+if COND
+SUBDIRS += sub2
+endif
+END
+
+cat > sub1/Makefile.am << 'END'
+all-local:
+ : > run
+CLEANFILES = run
+SUBDIRS = @extra_subdirs@
+DIST_SUBDIRS = subsub
+END
+
+cat > sub2/Makefile.am << 'END'
+all-local:
+ @echo "Should not run in `pwd`!"
+ exit 1
+DISTCLEANFILES = oops
+END
+cp sub2/Makefile.am sub1/subsub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -c --add-missing
+
+./configure
+
+test -f sub1/Makefile
+test -f sub2/Makefile
+test -f sub1/subsub/Makefile
+
+$MAKE
+test -f sub1/run
+touch sub2/oops sub1/subsub/oops
+
+$MAKE distclean
+test ! -e sub1/run
+test ! -e sub2/oops
+test ! -e sub1/subsub/oops
+test ! -e sub1/Makefile
+test ! -e sub2/Makefile
+test ! -e sub1/subsub/Makefile
+
+mkdir build
+cd build
+
+../configure
+
+$MAKE
+
+test -f sub1/Makefile
+test -f sub2/Makefile
+test -f sub1/subsub/Makefile
+
+test -f sub1/run
+touch sub2/oops sub1/subsub/oops
+
+$MAKE maintainer-clean
+test ! -e sub1/run
+test ! -e sub2/oops
+test ! -e sub1/subsub/oops
+test ! -e sub1/Makefile
+test ! -e sub2/Makefile
+test ! -e sub1/subsub/Makefile
+
+cd ..
+
+./configure
+$MAKE distclean
+
+:
diff --git a/t/subdir-env-interference.sh b/t/subdir-env-interference.sh
new file mode 100644
index 000000000..50456b3d2
--- /dev/null
+++ b/t/subdir-env-interference.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# SUDBIRS with $fail set in the environment.
+
+. test-init.sh
+
+mkdir sub
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+echo SUBDIRS = sub >Makefile.am
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+env fail=1 $MAKE all clean
+
+:
diff --git a/t/subdir-keep-going-pr12554.sh b/t/subdir-keep-going-pr12554.sh
new file mode 100644
index 000000000..643e7886a
--- /dev/null
+++ b/t/subdir-keep-going-pr12554.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the Automake-generated recursive rules are resilient against
+# false positives in deciding whether make is running with the '-k'
+# option, and thus whether a failure into one of the $(SUBDIRS) should
+# still prevent recursion in the following $(SUBDIRS) entries. See
+# automake bug#12544.
+
+. test-init.sh
+
+echo nil: | $MAKE -I . -f - || skip_ "$MAKE doesn't support the -I option"
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
+AC_OUTPUT
+END
+
+mkdir k ./--keep-going sub1 sub2
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1 sub2
+END
+
+cat > sub1/Makefile.am <<'END'
+all-local:
+ touch ko
+ false
+END
+cat > sub2/Makefile.am <<'END'
+all-local:
+ test -f ../sub1/ko
+ touch ok
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+st=0
+$MAKE -I k -I --keep-going \
+ TESTS='k --keep-going -k' AM_MAKEFLAGS="TESTS='k --keep-going -k'" \
+ || st=$?
+# Don't trust the exit status of "make -k" for non-GNU make.
+if using_gmake; then
+ test $st -gt 0 || exit 1
+fi
+test ! -r sub2/ok
+
+# Sanity check.
+st=0; $MAKE -k || st=$?
+if { using_gmake && test $st -eq 0; } || test ! -f sub2/ok; then
+ fatal_ '"make -k" not working as expected'
+fi
+
+:
diff --git a/t/subdir-order.sh b/t/subdir-order.sh
new file mode 100644
index 000000000..b06c62f65
--- /dev/null
+++ b/t/subdir-order.sh
@@ -0,0 +1,159 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The $(SUDBIRS) entries are processed in the order they are specified.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([
+ sub0/Makefile
+ sub1/Makefile
+ sub2/Makefile
+ sub3/Makefile
+ sub3/a/Makefile
+ sub3/b/Makefile
+])
+AC_OUTPUT
+END
+
+mkdir sub0 sub1 sub2 sub3 sub3/a sub3/b
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub2 sub1 sub3 sub0
+all-local:
+ test -f sub0/run
+ test -f sub1/run
+ test -f sub2/run
+ test -f sub3/run
+ test -f sub3/a/run
+ test -f sub3/b/run
+ test ! -f run
+ : > run
+
+CLEANFILES = \
+ run \
+ sub0/run \
+ sub1/run \
+ sub2/run \
+ sub3/run \
+ sub3/a/run \
+ sub3/b/run
+END
+
+cat > sub0/Makefile.am << 'END'
+all-local:
+ test ! -f $(top_builddir)/run
+ test -f $(top_builddir)/sub1/run
+ test -f $(top_builddir)/sub3/run
+ test -f $(top_builddir)/sub3/a/run
+ test -f $(top_builddir)/sub3/b/run
+ test ! -f run
+ : > run
+END
+
+cat > sub1/Makefile.am << 'END'
+all-local:
+ test ! -f $(top_builddir)/run
+ test ! -f $(top_builddir)/sub0/run
+ test -f $(top_builddir)/sub2/run
+ test ! -f $(top_builddir)/sub3/run
+ test ! -f $(top_builddir)/sub3/a/run
+ test ! -f $(top_builddir)/sub3/b/run
+ test ! -f run
+ : > run
+END
+
+
+cat > sub2/Makefile.am << 'END'
+all-local:
+ test ! -f $(top_builddir)/run
+ test ! -f $(top_builddir)/sub0/run
+ test ! -f $(top_builddir)/sub1/run
+ test ! -f $(top_builddir)/sub3/run
+ test ! -f $(top_builddir)/sub3/a/run
+ test ! -f $(top_builddir)/sub3/b/run
+ test ! -f run
+ : > run
+END
+
+cat > sub3/Makefile.am << 'END'
+SUBDIRS = b . a
+all-local:
+ test ! -f $(top_builddir)/run
+ test ! -f $(top_builddir)/sub0/run
+ test -f $(top_builddir)/sub1/run
+ test ! -f $(top_builddir)/sub3/a/run
+ test -f $(top_builddir)/sub3/b/run
+ test ! -f run
+ : > run
+END
+
+cat > sub3/a/Makefile.am << 'END'
+all-local:
+ test ! -f $(top_builddir)/run
+ test ! -f $(top_builddir)/sub0/run
+ test -f $(top_builddir)/sub1/run
+ test -f $(top_builddir)/sub3/b/run
+ test -f $(top_builddir)/sub3/run
+ test ! -f run
+ : > run
+END
+
+cat > sub3/b/Makefile.am << 'END'
+all-local:
+ test ! -f $(top_builddir)/run
+ test ! -f $(top_builddir)/sub0/run
+ test -f $(top_builddir)/sub1/run
+ test ! -f $(top_builddir)/sub3/b/run
+ test ! -f $(top_builddir)/sub3/run
+ test ! -f run
+ : > run
+END
+
+echo dummy: > Makefile
+if using_gmake; then
+ jobs=-j12
+elif $MAKE -j12; then
+ jobs=-j12
+elif $MAKE -j 12; then
+ jobs="-j 12"
+else
+ jobs=none
+fi
+rm -f Makefile
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -c --add-missing
+
+./configure
+
+for j in '' "$jobs"; do
+ test x"$j" = x"none" && continue
+ $MAKE $j
+ test -f run
+ test -f sub0/run
+ test -f sub1/run
+ test -f sub3/run
+ test -f sub3/a/run
+ test -f sub3/b/run
+ $MAKE clean
+ find . | grep 'run$' && exit 1
+ : # For shells with busted 'set -e'
+done
+
+:
diff --git a/t/subdir-subsub.sh b/t/subdir-subsub.sh
new file mode 100644
index 000000000..e65fa785d
--- /dev/null
+++ b/t/subdir-subsub.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure sub-sub-dirs work correctly.
+
+. test-init.sh
+
+mkdir one
+mkdir one/two
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([one/Makefile one/two/Makefile])
+AC_OUTPUT
+END
+
+# Files required because we are using '--gnu'.
+: > INSTALL
+: > NEWS
+: > README
+: > COPYING
+: > AUTHORS
+: > ChangeLog
+
+cat > Makefile.am << 'END'
+SUBDIRS = one
+END
+
+cat > one/Makefile.am << 'END'
+SUBDIRS = two
+END
+
+cat > one/two/Makefile.am << 'END'
+pkgdata_DATA = data.txt
+data.txt:
+ echo dummy >$@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --gnu
+
+./configure
+$MAKE
+test -f one/two/data.txt
+
+:
diff --git a/t/subdir-with-slash.sh b/t/subdir-with-slash.sh
new file mode 100644
index 000000000..ee77e7ca6
--- /dev/null
+++ b/t/subdir-with-slash.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test SUDBIRS with '/' in them.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([src/subdir/Makefile src/subdir2/Makefile])
+AC_OUTPUT
+END
+
+echo SUBDIRS = src/subdir >Makefile.am
+
+mkdir src
+mkdir src/subdir
+mkdir src/subdir2
+
+: >src/subdir/foo
+: >src/subdir2/foo
+
+cat >src/subdir/Makefile.am <<'EOF'
+EXTRA_DIST = foo
+SUBDIRS = ../subdir2
+EOF
+
+cat >src/subdir2/Makefile.am <<'EOF'
+EXTRA_DIST = foo
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+./configure
+$MAKE distdir
+test -f $distdir/src/subdir/foo
+test -f $distdir/src/subdir2/foo
+$MAKE clean
+$MAKE distclean
+test ! -e src/subdir2/Makefile
+
+:
diff --git a/t/subdir.sh b/t/subdir.sh
new file mode 100644
index 000000000..bdce47755
--- /dev/null
+++ b/t/subdir.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure install-sh and mkinstalldirs correctly found in
+# subdirs.
+
+. test-init.sh
+
+mkdir zot
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([zot/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = zot
+END
+
+cat > zot/Makefile.am << 'END'
+pkgdata_DATA =
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/subobj-clean-lt-pr10697.sh b/t/subobj-clean-lt-pr10697.sh
new file mode 100644
index 000000000..60d83ec03
--- /dev/null
+++ b/t/subobj-clean-lt-pr10697.sh
@@ -0,0 +1,168 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Removing subdir objects does not cause too much 'rm' invocations.
+# Also, if we rename a source file in a subdirectory, the stale
+# compiled object corresponding to the old name still gets removed
+# by "make mostlyclean". See automake bug#10697.
+# This is the libtool case. Keep this test in sync with sister test
+# 'subobj-clean-pr10697.sh', which deals with the non-libtool case.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_PROG_CC
+AC_OUTPUT
+END
+
+oPATH=$PATH
+ocwd=$(pwd) || fatal_ "getting current working directory"
+
+# An rm(1) wrapper that fails when invoked too many times.
+mkdir rm-wrap
+max_rm_invocations=6
+count_file=$ocwd/rm-wrap/count
+cat > rm-wrap/rm <<END
+#!$AM_TEST_RUNNER_SHELL -e
+count=\$((\$(cat '$count_file') + 1))
+if ! test \$count -le $max_rm_invocations; then
+ echo "rm invoked more than $max_rm_invocations times" >&2
+ exit 1
+fi
+echo "\$count" > '$count_file'
+PATH='$oPATH'; export PATH
+exec rm "\$@"
+END
+chmod a+x rm-wrap/rm
+echo "0" > rm-wrap/count
+
+cat > Makefile.am <<'END'
+.PHONY: sanity-check-rm
+sanity-check-rm:
+ rm -f 1
+ rm -f 2
+ rm -f 3
+ rm -f 4
+ rm -f 5
+ rm -f 6
+ rm -f x && exit 1; :
+ echo "0" > rm-wrap/count
+
+AUTOMAKE_OPTIONS = subdir-objects
+lib_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = \
+ sub1/a.c \
+ sub1/b.c \
+ sub1/c.c \
+ sub1/d.c \
+ sub1/e.c \
+ sub1/f.c \
+ sub2/a.c \
+ sub2/b.c \
+ sub2/c.c \
+ sub2/d.c \
+ sub2/e.c \
+ sub2/f.c \
+ main.c
+END
+
+mkdir sub1 sub2
+echo 'int libmain (void)' > main.c
+echo '{' >> main.c
+for i in 1 2; do
+ for j in a b c d e f; do
+ echo "void $j$i (void) { }" > sub$i/$j.c
+ echo " $j$i ();" >> main.c
+ done
+done
+echo ' return 0;' >> main.c
+echo '}' >> main.c
+cat main.c # For debugging.
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+# The use of this variable is only meant to keep us better in sync
+# with the sister test 'subobj-clean-pr10697.sh'.
+OBJEXT=lo
+
+$MAKE
+
+# This must go after configure, since that will invoke rm many times.
+PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
+$MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
+
+$MAKE mostlyclean
+ls -l . sub1 sub2
+for i in 1 2; do
+ for j in a b c d e f; do
+ test ! -e sub$i/$j.o
+ test ! -e sub$i/$j.obj
+ test ! -e sub$i/$j.lo
+ test -f sub$i/$j.c || exit 99 # Sanity check
+ done
+done
+
+PATH=$oPATH; export PATH
+rm -rf rm-wrap
+
+$MAKE clean
+$MAKE
+test -f sub1/a.$OBJEXT
+test -f sub2/d.$OBJEXT
+
+$sleep
+
+mv -f sub2/d.c sub2/x.c
+rm -f sub1/a.c
+
+sed -e '/ a1 ()/d' main.c > t
+mv -f t main.c
+
+sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
+mv -f t Makefile.am
+
+using_gmake || $MAKE Makefile
+$MAKE
+test -f sub2/x.$OBJEXT
+
+# The stale objects are still there after a mere "make all" ...
+test -f sub1/a.$OBJEXT
+test -f sub2/a.$OBJEXT
+
+# ... but they get removed by "make mostlyclean" ...
+$MAKE mostlyclean
+test ! -e sub1/a.$OBJEXT
+test ! -e sub2/d.$OBJEXT
+
+# ... and do not get rebuilt ...
+$MAKE clean
+$MAKE all
+test ! -e sub1/a.$OBJEXT
+test ! -e sub2/d.$OBJEXT
+
+# ... while the non-stale files do.
+test -f sub1/b.$OBJEXT
+test -f sub2/x.$OBJEXT
+
+:
diff --git a/t/subobj-clean-pr10697.sh b/t/subobj-clean-pr10697.sh
new file mode 100644
index 000000000..f3a60f537
--- /dev/null
+++ b/t/subobj-clean-pr10697.sh
@@ -0,0 +1,163 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Removing subdir objects does not cause too much 'rm' invocations.
+# Also, if we rename a source file in a subdirectory, the stale
+# compiled object corresponding to the old name still gets removed by
+# "make mostlyclean". See automake bug#10697.
+# This is the non-libtool case. Keep this test in sync with sister test
+# 'subobj-clean-lt-pr10697.sh', which deals with the libtool case.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_CONFIG_FILES([get-objext.sh:get-objext.in])
+AC_OUTPUT
+END
+
+echo "OBJEXT='@OBJEXT@'" > get-objext.in
+
+oPATH=$PATH
+ocwd=$(pwd) || fatal_ "getting current working directory"
+
+# An rm(1) wrapper that fails when invoked too many times.
+mkdir rm-wrap
+max_rm_invocations=3
+count_file=$ocwd/rm-wrap/count
+cat > rm-wrap/rm <<END
+#!$AM_TEST_RUNNER_SHELL -e
+count=\$((\$(cat '$count_file') + 1))
+test \$count -le $max_rm_invocations || {
+ echo "rm invoked more than $max_rm_invocations times" >&2
+ exit 1
+}
+echo "\$count" > '$count_file'
+PATH='$oPATH'; export PATH
+exec rm "\$@"
+END
+chmod a+x rm-wrap/rm
+echo "0" > rm-wrap/count
+
+cat > Makefile.am <<'END'
+.PHONY: sanity-check-rm
+sanity-check-rm:
+ rm -f 1
+ rm -f 2
+ rm -f 3
+ rm -f x && exit 1; :
+ echo "0" > rm-wrap/count
+
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = foo
+foo_SOURCES = \
+ sub1/a.c \
+ sub1/b.c \
+ sub1/c.c \
+ sub1/d.c \
+ sub1/e.c \
+ sub1/f.c \
+ sub2/a.c \
+ sub2/b.c \
+ sub2/c.c \
+ sub2/d.c \
+ sub2/e.c \
+ sub2/f.c \
+ main.c
+END
+
+mkdir sub1 sub2
+echo 'int main (void)' > main.c
+echo '{' >> main.c
+for i in 1 2; do
+ for j in a b c d e f; do
+ echo "void $j$i (void) { }" > sub$i/$j.c
+ echo " $j$i ();" >> main.c
+ done
+done
+echo ' return 0;' >> main.c
+echo '}' >> main.c
+cat main.c # For debugging.
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+test -f get-objext.sh
+. ./get-objext.sh
+
+$MAKE
+
+# This must go after configure, since that will invoke rm many times.
+PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
+$MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
+
+$MAKE mostlyclean
+ls -l . sub1 sub2
+for i in 1 2; do
+ for j in a b c d e f; do
+ test ! -e sub$i/$j.o
+ test ! -e sub$i/$j.obj
+ test -f sub$i/$j.c || exit 99 # Sanity check
+ done
+done
+
+PATH=$oPATH; export PATH
+rm -rf rm-wrap
+
+$MAKE clean
+$MAKE
+test -f sub1/a.$OBJEXT
+test -f sub2/d.$OBJEXT
+
+$sleep
+
+mv -f sub2/d.c sub2/x.c
+rm -f sub1/a.c
+
+sed -e '/ a1 ()/d' main.c > t
+mv -f t main.c
+
+sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
+mv -f t Makefile.am
+
+using_gmake || $MAKE Makefile
+$MAKE
+test -f sub2/x.$OBJEXT
+
+# The stale objects are still there after a mere "make all" ...
+test -f sub1/a.$OBJEXT
+test -f sub2/a.$OBJEXT
+
+# ... but they get removed by "make mostlyclean" ...
+$MAKE mostlyclean
+test ! -e sub1/a.$OBJEXT
+test ! -e sub2/d.$OBJEXT
+
+# ... and do not get rebuilt ...
+$MAKE clean
+$MAKE all
+test ! -e sub1/a.$OBJEXT
+test ! -e sub2/d.$OBJEXT
+
+# ... while the non-stale files do.
+test -f sub1/b.$OBJEXT
+test -f sub2/x.$OBJEXT
+
+:
diff --git a/t/subobj-indir-pr13928.sh b/t/subobj-indir-pr13928.sh
new file mode 100644
index 000000000..739083755
--- /dev/null
+++ b/t/subobj-indir-pr13928.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Expose part of Automake bug#13928: config.status generates broken
+# makefiles if the subdir-objects option is used and a _SOURCES
+# variable lists sources whose directory part is specified as a
+# make variable ("foo_SOURCES = $(src)/foo.c").
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+src = s
+bin_PROGRAMS = foo
+foo_SOURCES = $(src)/foo.c
+END
+
+mkdir s
+echo 'int main(void) { return 0; }' > s/foo.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+test -f s/.deps/foo.Po
+find . | $FGREP '$(src)' && exit 1
+$MAKE distcheck
+
+:
diff --git a/t/subobj-objname-clash.sh b/t/subobj-objname-clash.sh
new file mode 100644
index 000000000..7da9868c8
--- /dev/null
+++ b/t/subobj-objname-clash.sh
@@ -0,0 +1,104 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that object names don't clash when using subdir-objects.
+# The check is done for clashing programs, clashing libraries and
+# a program that clashes with a library
+
+. test-init.sh
+
+mkdir src
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects foreign
+noinst_PROGRAMS =
+noinst_LIBRARIES =
+
+# CLASHING PROGRAMS
+noinst_PROGRAMS += foo src/foo
+foo_SOURCES = src/foo.c src/main.c
+foo_CPPFLAGS = -DVAL=0
+src_foo_CPPFLAGS = -DVAL=1
+src_foo_SOURCES = src/foo.c src/main.c
+
+# CLASHING LIBS
+noinst_PROGRAMS += bar src/bar
+noinst_LIBRARIES += libbar.a src/libbar.a
+bar_SOURCES = src/main.c
+bar_LDADD = libbar.a
+src_bar_SOURCES = src/main.c
+src_bar_LDADD = src/libbar.a
+libbar_a_SOURCES = src/foo.c
+libbar_a_CPPFLAGS = -DVAL=0
+src_libbar_a_SOURCES = src/foo.c
+src_libbar_a_CPPFLAGS = -DVAL=1
+
+# CLASHING PROGRAM + LIB
+noinst_PROGRAMS += libzap_a src/zap
+noinst_LIBRARIES += src/libzap.a
+libzap_a_SOURCES = src/main.c src/foo.c
+libzap_a_CPPFLAGS = -DVAL=2
+src_zap_SOURCES = src/main.c
+src_zap_LDADD = src/libzap.a
+src_libzap_a_SOURCES = src/foo.c
+src_libzap_a_CPPFLAGS = -DVAL=3
+
+# NON-CLASHING
+noinst_PROGRAMS += src/foo-uniq
+src_foo_uniq_SOURCES = src/main.c src/foo.c
+src_foo_uniq_CPPFLAGS = -DVAL=4
+END
+
+cat > src/foo.c << 'END'
+int
+foo ()
+{
+ return VAL;
+}
+END
+
+cat > src/main.c << 'END'
+int foo (void);
+
+int
+main ()
+{
+ return foo ();
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+$MAKE
+set +e
+./foo || fail_ "./foo should return 0"
+./src/foo; test $? = 1 || fail_ "./src/foo should return 1"
+./bar || fail_ "./bar should return 0"
+./src/bar; test $? = 1 || fail_ "./src/bar should return 1"
+./libzap_a; test $? = 2 || fail_ "./libfoo_a should return 2"
+./src/zap; test $? = 3 || fail_ "./src/prog_libfoo should return 3"
+./src/foo-uniq; test $? = 4 || fail_ "./foo_uniq should return 4"
+set -e
+$MAKE clean
diff --git a/t/subobj-pr13928-more-langs.sh b/t/subobj-pr13928-more-langs.sh
new file mode 100644
index 000000000..15bdd4ebe
--- /dev/null
+++ b/t/subobj-pr13928-more-langs.sh
@@ -0,0 +1,138 @@
+#! /bin/sh
+# Copyright (C) 2015 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Expose part of automake bug#13928, also for non-C languages: if the
+# subdir-objects option is in use and a source file is listed in a
+# _SOURCES variable with a leading $(srcdir) component, Automake will
+# generate a Makefile that tries to create the corresponding object
+# file in $(srcdir) as well.
+
+required='cc c++ fortran77 fortran'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_F77
+AC_PROG_FC
+AM_CONDITIONAL([OBVIOUS], [:])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+SUBDIRS = sub
+
+LESS = m/o/r/e
+
+noinst_PROGRAMS = test test2
+test_SOURCES = $(srcdir)/test.f90
+
+test2_SOURCES = $(indir)
+
+indir = ${indir2} $(empty)
+indir2 =
+if OBVIOUS
+indir2 += ${srcdir}/$(LESS)///test.f
+else
+endif
+
+test-objs:
+ ls -la @srcdir@ .
+ :
+ test ! -f @srcdir@/test.$(OBJEXT)
+ test -f test.$(OBJEXT)
+ test ! -f @srcdir@/m/o/r/e/test.$(OBJEXT)
+ test -f m/o/r/e/test.$(OBJEXT)
+ :
+ test ! -f @srcdir@/bar.$(OBJEXT)
+ test -f bar.$(OBJEXT)
+ test ! -f @srcdir@/baz.$(OBJEXT)
+ test -f baz.$(OBJEXT)
+ :
+ test ! -d @srcdir@/$(DEPDIR)
+ test ! -d @srcdir@/m/o/r/e/$(DEPDIR)
+ test -d $(DEPDIR)
+ test -d m/o/r/e/$(DEPDIR)
+
+check-local: test-objs
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = foo
+foo = baz
+foo_SOURCES = foo.h \
+ $(top_srcdir)/bar.cc \
+ ${top_srcdir}/$(foo).c
+END
+
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkfiles='Makefile.in sub/Makefile.in'
+$EGREP '(test|ba[rz])\.|DEPDIR|dirstamp|srcdir' $mkfiles # For debugging.
+$EGREP '\$.(top_)?srcdir./(test|ba[rz]|\$.foo.)\.[o$]' $mkfiles && exit 1
+$FGREP '\$.(top_)?srcdir./.*$(am__dirstamp)' $mkfiles && exit 1
+$FGREP '\$.(top_)?srcdir./.*$(DEPDIR)' $mkfiles && exit 1
+
+cat > test.f90 <<'EOF'
+ program foo
+ stop
+ end
+EOF
+
+mkdir -p m/o/r/e
+cp test.f90 m/o/r/e/test.f
+
+cat > sub/foo.h <<'END'
+#ifdef __cplusplus
+extern "C"
+#endif
+int foo (void);
+END
+
+cat > bar.cc <<'END'
+#include "foo.h"
+#include <iostream>
+int main (void)
+{
+ std::cout << "OK!" << "\n";
+ return foo ();
+}
+END
+
+cat > baz.c <<'END'
+#include "foo.h"
+int foo (void)
+{
+ return 0;
+}
+END
+
+mkdir build
+cd build
+../configure
+
+$MAKE
+$MAKE test-objs
+$MAKE distcheck
+
+:
diff --git a/t/subobj-vpath-pr13928.sh b/t/subobj-vpath-pr13928.sh
new file mode 100644
index 000000000..5f09515d3
--- /dev/null
+++ b/t/subobj-vpath-pr13928.sh
@@ -0,0 +1,127 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Expose part of automake bug#13928: if the subdir-objects option is
+# in use and a source file is listed in a _SOURCES variable with a
+# leading $(srcdir) component, Automake will generate a Makefile that
+# tries to create the corresponding object file in $(srcdir) as well.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_CC_C_O
+AM_CONDITIONAL([OBVIOUS], [:])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+SUBDIRS = sub
+
+LESS = more
+
+noinst_PROGRAMS = test test2
+test_SOURCES = $(srcdir)/test.c
+
+test2_SOURCES = $(indir)
+
+indir =
+if OBVIOUS
+indir += ${srcdir}/$(LESS)/test.c
+else
+endif
+
+test-objs:
+ ls -la @srcdir@ .
+ :
+ test ! -f @srcdir@/test.$(OBJEXT)
+ test -f test.$(OBJEXT)
+ test ! -f @srcdir@/more/test.$(OBJEXT)
+ test -f more/test.$(OBJEXT)
+ :
+ test ! -f @srcdir@/bar.$(OBJEXT)
+ test -f bar.$(OBJEXT)
+ test ! -f @srcdir@/baz.$(OBJEXT)
+ test -f baz.$(OBJEXT)
+ :
+ test ! -d @srcdir@/$(DEPDIR)
+ test ! -d @srcdir@/more/$(DEPDIR)
+ test -d $(DEPDIR)
+ test -d more/$(DEPDIR)
+
+check-local: test-objs
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = foo
+foo_SOURCES = foo.h \
+ $(top_srcdir)/bar.c \
+ ${top_srcdir}/baz.c
+END
+
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkfiles='Makefile.in sub/Makefile.in'
+$EGREP '(test|ba[rz])\.|DEPDIR|dirstamp|srcdir' $mkfiles # For debugging.
+$EGREP '\$.(top_)?srcdir./(test|ba[rz])\.[o$]' $mkfiles && exit 1
+$FGREP '\$.(top_)?srcdir./.*$(am__dirstamp)' $mkfiles && exit 1
+$FGREP '\$.(top_)?srcdir./.*$(DEPDIR)' $mkfiles && exit 1
+
+cat > test.c <<'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+mkdir more
+cp test.c more/test.c
+
+echo 'int foo (void);' > sub/foo.h
+
+cat > bar.c <<'END'
+#include "foo.h"
+int main (void)
+{
+ return foo ();
+}
+END
+
+cat > baz.c <<'END'
+#include "foo.h"
+int foo (void)
+{
+ return 0;
+}
+END
+
+mkdir build
+cd build
+../configure
+
+$MAKE
+$MAKE test-objs
+$MAKE distcheck
+
+:
diff --git a/t/subobj.sh b/t/subobj.sh
new file mode 100644
index 000000000..c5bc546ee
--- /dev/null
+++ b/t/subobj.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of subdir objects with C and C++.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_YACC
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+$ACLOCAL
+: > ylwrap
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+bin_PROGRAMS = wish
+wish_SOURCES = generic/a.c
+wish_SOURCES += another/z.cxx
+END
+
+mkdir sub
+cat > sub/Makefile.am << 'END'
+dream_SOURCES = generic/b.c more/r.y
+bin_PROGRAMS = dream
+END
+
+AUTOMAKE_fails
+grep "^Makefile\.am:3:.*'generic/a\.c'.* in a subdirectory" stderr
+grep "^Makefile\.am:[34]:.*'another/z\.cxx'.* in a subdirectory" stderr
+grep "^sub/Makefile\.am:1:.*'generic/b\.c'.* in a subdirectory" stderr
+grep "option 'subdir-objects' is disabled" stderr
+# Verbose tips should be given, but not too many times.
+for msg in \
+ "possible forward-incompatibility" \
+ "advi[sc]e.* 'subdir-objects' option throughout" \
+ "unconditionally.* object file.* same subdirectory" \
+; do
+ test $(grep -c "$msg" stderr) -eq 1
+done
+
+# Guard against stupid typos.
+grep 'subdir-object([^s]|$)' stderr && exit 1
+
+$AUTOMAKE -Wno-unsupported
+
+echo AUTOMAKE_OPTIONS = subdir-objects >> Makefile.am
+AUTOMAKE_fails
+grep "^Makefile\.am" stderr && exit 1
+grep "^sub/Makefile\.am:.*'generic/b\.c'.* in a subdirectory" stderr
+grep "option 'subdir-objects' is disabled" stderr
+
+sed 's/^AM_INIT_AUTOMAKE/&([subdir-objects])/' configure.ac > configure.tmp
+mv -f configure.tmp configure.ac
+$ACLOCAL --force
+$AUTOMAKE
+
+rm -f compile
+$AUTOMAKE --add-missing 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+# Make sure compile is installed, and that Automake says so.
+grep '^configure\.ac:[48]:.*install.*compile' stderr
+test -f compile
+
+grep '^generic/a\.\$(OBJEXT):' Makefile.in
+grep '^generic/b\.\$(OBJEXT):' sub/Makefile.in
+grep '^another/z\.\$(OBJEXT):' Makefile.in
+$EGREP '(^|[^/])[abz]\.\$(OBJEXT)' Makefile.in sub/Makefile.in && exit 1
+
+# Opportunistically test for a different bug.
+grep '^another/z\.\$(OBJEXT):.*dirstamp' Makefile.in
+grep '^generic/b\.\$(OBJEXT):.*dirstamp' sub/Makefile.in
+
+:
diff --git a/t/subobj10.sh b/t/subobj10.sh
new file mode 100644
index 000000000..2202a8b1f
--- /dev/null
+++ b/t/subobj10.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# PR 492: Test asm subdir-objects.
+
+required='gcc -c-o'
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([subdir-objects])
+
+AM_PROG_AS
+AM_PROG_AR
+AC_PROG_RANLIB
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libfoo.a libbar.a
+libfoo_a_SOURCES = src/a.s b.s
+libbar_a_SOURCES = src/c.s d.s
+libbar_a_CCASFLAGS =
+END
+
+mkdir src
+: >src/a.s
+: >b.s
+: >src/c.s
+: >d.s
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+$MAKE distcheck
+
+:
diff --git a/t/subobj11a.sh b/t/subobj11a.sh
new file mode 100644
index 000000000..6b8f2d983
--- /dev/null
+++ b/t/subobj11a.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that automake works around a bug of Solaris Make. The bug is the
+# following. If we have a Makefile containg a file inclusion like this:
+# include .//foo.mk
+# Solaris make fails with a message like:
+# make: ... can't find '/foo.mk': No such file or directory
+# make: fatal error ... read of include file '/foo.mk' failed
+# (even if the file 'foo.mk' exists). The error disappear by collapsing
+# the repeated slash '/' characters into a single one.
+#
+# See also sister "grepping" test 'subobj11b.sh', and related test
+# 'subobj11c.sh'.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = foo
+## The './/' below is meant.
+foo_SOURCES = .//src/foo.c
+END
+
+mkdir src
+
+cat > src/foo.c << 'END'
+int main(void)
+{
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure --enable-dependency-tracking
+
+depdir=$(sed -n 's/^ *DEPDIR *= *//p' Makefile)
+if test x"$depdir" != x; then
+ depdir=src/$depdir
+else
+ echo "$me: cannot extract value of DEPDIR from Makefile" >&2
+ exit 1
+fi
+
+ls -l "$depdir"
+test -f "$depdir"/foo.Po
+
+echo 'quux:; echo "z@rd@z" >$@' >> "$depdir"/foo.Po
+
+$MAKE quux
+$FGREP "z@rd@z" quux
+
+$MAKE
+
+DISTCHECK_CONFIGURE_FLAGS='--enable-dependency-tracking' $MAKE distcheck
+DISTCHECK_CONFIGURE_FLAGS='--disable-dependency-tracking' $MAKE distcheck
+
+:
diff --git a/t/subobj11b.sh b/t/subobj11b.sh
new file mode 100644
index 000000000..b340f3c74
--- /dev/null
+++ b/t/subobj11b.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that automake works around a bug of Solaris Make. The bug is the
+# following. If we have a Makefile containg a file inclusion like this:
+# include .//foo.mk
+# Solaris make fails with a message like:
+# make: ... can't find '/foo.mk': No such file or directory
+# make: fatal error ... read of include file '/foo.mk' failed
+# (even if the file 'foo.mk' exists). The error disappear by collapsing
+# the repeated slash '/' characters into a single one.
+#
+# See also "semantic" sister test 'subobj11a.sh', and related test
+# 'subobj11c.sh'.
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = foo
+## The 'zardoz' sources should activate a code paths in Automake that
+## cannot be sensibly tested by sister test 'subobj11a.test'. The other
+## sources provide some sort of stress testing.
+foo_SOURCES = \
+ //server/zardoz0.c \
+ //server//zardoz1.c \
+ //server/path/to/zardoz2.c \
+ //server/another//path///to////zardoz3.c \
+ /foobar0.c \
+ ///foobar1.c \
+ ////foobar2.c \
+ /sub///foobar3.c \
+ ///sub/foobar4.c \
+ .//foobar5.c \
+ .//sub/foobar6.c \
+ ./sub//foobar7.c \
+ .//sub//foobar8.c \
+ sub/sub//sub///sub////foobar9.c
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+grep '\.P' Makefile.in # For debugging.
+
+grep '//.*foobar\.P' Makefile.in && exit 1
+
+# These checks depend on automake internals, but presently this is
+# the only way to test the code path we are interested in.
+# Please update these checks when (and if) the relevant automake
+# internals are changed.
+for x in zardoz0 zardoz1 path/to/zardoz2 another/path/to/zardoz3; do
+ case $x in
+ */*) d=$(echo $x | sed 's,[^/]*$,,'); b=$(echo $x | sed 's,^.*/,,');;
+ *) d=''; b=$x;;
+ esac
+ # Be a little lax in the regexp, to account for automake conditionals,
+ # quoting, and similar stuff.
+ grep "[ ]//server/$d\\\$(DEPDIR)/$b\\.Po" Makefile.in
+done
+
+# Sanity checks.
+for i in 0 1 2 3 4 5 6 7 8 9; do
+ grep "\$(DEPDIR)/foobar$i\\.Po" Makefile.in
+done
+
+:
diff --git a/t/subobj11c.sh b/t/subobj11c.sh
new file mode 100644
index 000000000..b3e78b459
--- /dev/null
+++ b/t/subobj11c.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automatic dependency tracking with subdir-objects option active:
+# check for a pathological case of slash-collapsing in the name of
+# included makefile fragments (containing dependency info).
+# See also related tests 'subobj11a.sh' and 'subobj11b.sh'.
+
+. test-init.sh
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = foo
+foo_SOURCES = //zardoz.c
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+#
+# This check depends on automake internals, but presently this is
+# the only way to test the code path we are interested in.
+# Please update these checks when (and if) the relevant automake
+# internals are changed.
+#
+# Be a little lax in the regexp, to account for automake conditionals,
+# quoting, and similar stuff.
+#
+# FIXME: Are we sure this is the most sensible output in our situation?
+#
+grep 'am__depfiles_remade =.* //\$(DEPDIR)/zardoz\.Po' Makefile.in
+
+:
diff --git a/t/subobj2.sh b/t/subobj2.sh
new file mode 100644
index 000000000..6cee18f7b
--- /dev/null
+++ b/t/subobj2.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of subdir objects with C++.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = wish
+wish_SOURCES = generic/a.cc generic/b.cxx
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP 'generic/a.$(OBJEXT)' Makefile.in
+grep '[^/]a\.\$(OBJEXT)' Makefile.in && exit 1
+grep '.*-c -o' Makefile.in
+
+:
diff --git a/t/subobj4.sh b/t/subobj4.sh
new file mode 100644
index 000000000..dd464d934
--- /dev/null
+++ b/t/subobj4.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure '../foo/foo.cpp' generates a rule.
+# Report from Dave Brolley.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_CONFIG_FILES([d1/Makefile d2/Makefile])
+AC_OUTPUT
+END
+
+mkdir d1 d2
+
+cat > Makefile.am << 'END'
+SUBDIRS = d1 d2
+END
+
+cat > d1/Makefile.am << 'END'
+bin_PROGRAMS = z
+z_SOURCES = ../d2/z.c
+END
+
+cat > d2/Makefile.am << 'END'
+END
+
+: > d2/z.c
+
+$ACLOCAL
+$AUTOMAKE -Wno-unsupported
+
+grep '\$(CC) .*\.\./d2/z\.c' d1/Makefile.in
+
+:
diff --git a/t/subobj5.sh b/t/subobj5.sh
new file mode 100644
index 000000000..0b046baef
--- /dev/null
+++ b/t/subobj5.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of subdir make dist rules.
+# From Robert Collins.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([generic/Makefile])
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = wish
+wish_SOURCES = generic/a.c
+
+.PHONY: test-distdir test-build
+test-distdir: distdir
+ ls -l $(distdir) $(distdir)/* ;: For debugging.
+ test ! -r $(distdir)/a.c
+ test -f $(distdir)/generic/a.c
+test-build: all
+ ls -l . generic ;: For debugging.
+ test -f generic/a.$(OBJEXT)
+ test -f wish$(EXEEXT)
+ test ! -r a.$(OBJEXT)
+ test ! -r a$(EXEEXT)
+ test ! -r generic/wish$(EXEEXT)
+ test ! -r generic/a$(EXEEXT)
+END
+
+mkdir generic
+: > generic/Makefile.am
+
+cat > generic/a.c << 'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --include-deps --copy --add-missing
+
+./configure
+
+$MAKE test-distdir
+$MAKE dist
+$MAKE test-build
+
+:
diff --git a/t/subobj6.sh b/t/subobj6.sh
new file mode 100644
index 000000000..f598c7f65
--- /dev/null
+++ b/t/subobj6.sh
@@ -0,0 +1,85 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of subdir make distclean rules.
+# From Robert Collins.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = wish
+wish_SOURCES = generic/a.c
+
+test-all: all
+ test -f generic/$(am__dirstamp)
+test-mostlyclean: mostlyclean
+ test ! -f generic/a.o
+test-distclean: distclean
+ test ! -f generic/$(am__dirstamp)
+END
+
+mkdir generic
+cat > generic/a.c << 'END'
+#include <stdio.h>
+int main ()
+{
+ printf ("maude!\n");
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --include-deps --copy --add-missing
+
+mkdir build
+cd build
+
+../configure
+$MAKE test-all
+$MAKE test-mostlyclean
+$MAKE test-distclean
+
+cd ..
+
+# Now test without the subdir.
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = wish
+wish_SOURCES = a.c
+END
+
+mv generic/a.c a.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --include-deps --copy --add-missing
+
+mkdir build2
+cd build2
+
+../configure
+$MAKE
+$MAKE mostlyclean
+
+:
diff --git a/t/subobj7.sh b/t/subobj7.sh
new file mode 100644
index 000000000..313260684
--- /dev/null
+++ b/t/subobj7.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure AM_CFLAGS appears in subdir compilation rule.
+# Report from Steve M. Robbins.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = wish
+wish_SOURCES = foo.c generic/a.c
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+grep wish_CFLAGS Makefile.in && exit 1
+
+:
diff --git a/t/subobj8.sh b/t/subobj8.sh
new file mode 100644
index 000000000..d9d7d5fb5
--- /dev/null
+++ b/t/subobj8.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure 'compile' is included when subdir-objects is used in a subdir.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([tools])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AC_CONFIG_FILES([Makefile foo/Makefile])
+AC_OUTPUT
+END
+
+mkdir tools foo foo/bar
+
+cat > Makefile.am << 'END'
+SUBDIRS = foo
+END
+
+cat > foo/Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = mumble
+mumble_SOURCES = bar/a.c
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+test -f tools/compile
+
+:
diff --git a/t/subobj9.sh b/t/subobj9.sh
new file mode 100644
index 000000000..01d3b3497
--- /dev/null
+++ b/t/subobj9.sh
@@ -0,0 +1,87 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for PR 312.
+#
+# == Report ==
+# When using non-recursive make to build a libtoolize-library from
+# sources in a subdirectory, 'make distcheck' fails because of incomplete
+# cleanup. "make clean" tries to remove '*.o' and '.../<file>.lo' but
+# forgets '.../<file>.o'.
+
+required='c++ libtoolize'
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([subdir-objects])
+AC_PROG_CXX
+AM_PROG_AR
+AM_PROG_LIBTOOL
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = src/foo.cc .//src/bar.cc # The './/' is meant.
+.PHONY: print
+print:
+ @echo BEG1: "$(LTCXXCOMPILE)" :1END
+ @echo BEG2: "$(CXXLINK)" :2END
+END
+
+mkdir src
+cat > src/foo.cc << 'END'
+int doit2 (void);
+int doit (void)
+{
+ return doit2();
+}
+END
+
+cat > src/bar.cc << 'END'
+int doit2 (void)
+{
+ return 23;
+}
+END
+
+
+libtoolize --force
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+# Ensure './libtool --help' will use the right tool versions.
+export AUTOCONF AUTOMAKE
+
+# Opportunistically check that --tag=CXX is used when supported.
+if ./libtool --help | grep tag=TAG; then
+ run_make -O print
+ grep 'BEG1: .*--tag=CXX.*--mode=compile.* :1END' stdout
+ grep 'BEG2: .*--tag=CXX.*--mode=link.* :2END' stdout
+fi
+
+$MAKE
+run_make -M distcheck
+# GNU Make used to complain that the Makefile contained two rules
+# for 'src/.dirstamp' and './/src/.dirstamp'.
+grep 'overriding commands' output && exit 1
+
+:
diff --git a/t/subobjname.sh b/t/subobjname.sh
new file mode 100644
index 000000000..f3aa28d55
--- /dev/null
+++ b/t/subobjname.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we reuse variables whenever possible, to limit
+# combinational explosion. (This test is named after the &subobjname
+# sub in Automake).
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_CONDITIONAL([FOO1], [some test])
+AM_CONDITIONAL([FOO2], [some test])
+AM_CONDITIONAL([FOO3], [some test])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = c d
+
+if FOO1
+A1=a1.c
+endif
+
+if FOO2
+A2=a2.c
+endif
+
+if FOO3
+A3=a3.c
+endif
+
+B=$(A1) $(A2) $(A3)
+
+c_SOURCES=$(B)
+d_SOURCES=$(B)
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+# Sanity check: make sure am_c_OBJECTS and am_d_OBJECTS are used
+# in the Makefile. (This is an internal detail, so better make
+# sure we update this test if the naming changes in the future.)
+grep '^am_c_OBJECTS = ' Makefile.in
+grep '^am_d_OBJECTS = ' Makefile.in
+
+# Now the actual test. Are both values equal?
+cobj=$(sed -n '/^am_c_OBJECTS = / {
+ s/.* = \(.*\)$/\1/
+ p
+ }' Makefile.in)
+dobj=$(sed -n '/^am_d_OBJECTS = / {
+ s/^.* = \(.*\)$/\1/
+ p
+ }' Makefile.in)
+test "$cobj" = "$dobj"
+
+:
diff --git a/t/subpkg-macrodir.sh b/t/subpkg-macrodir.sh
new file mode 100644
index 000000000..7053570aa
--- /dev/null
+++ b/t/subpkg-macrodir.sh
@@ -0,0 +1,85 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Subpackages that want to use m4 macros from their superpackages,
+# with AC_CONFIG_MACRO_DIRS.
+
+. test-init.sh
+
+cat > configure.ac <<'END'
+AC_INIT([super], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SUBDIRS([pkg])
+AX_BAR
+AX_FOO
+END
+
+mkdir m4
+
+cat > m4/foo.m4 <<'EOF'
+AC_DEFUN([AX_FOO], [
+ AC_CONFIG_FILES([Makefile])
+ AC_OUTPUT
+])
+EOF
+
+cat > m4/bar.m4 <<'EOF'
+AC_DEFUN([AX_BAR], [AC_SUBST([WHOAMI], [SuperPkg])])
+EOF
+
+cat > Makefile.am << 'END'
+test-whoami:
+ test '$(WHOAMI)' = SuperPkg
+check-local: test-whoami
+END
+
+mkdir pkg
+
+cat > pkg/configure.ac <<'END'
+AC_INIT([super], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIRS([macros ../m4])
+AX_BAR
+AX_FOO
+END
+
+mkdir pkg/macros
+cat > pkg/macros/zardoz.m4 << 'END'
+AC_DEFUN([AX_BAR], [AC_SUBST([WHOAMI], [sub-pkg])])
+END
+
+cat > pkg/Makefile.am << 'END'
+test-whoami:
+ test '$(WHOAMI)' = sub-pkg
+check-local: test-whomai
+END
+
+AUTOMAKE=$AUTOMAKE ACLOCAL=$ACLOCAL AUTOCONF=$AUTOCONF $AUTORECONF -vi
+
+$FGREP 'm4_include([m4/foo.m4])' aclocal.m4
+$FGREP 'm4_include([m4/bar.m4])' aclocal.m4
+$FGREP 'm4_include([../m4/foo.m4])' pkg/aclocal.m4
+$FGREP 'm4_include([macros/zardoz.m4])' pkg/aclocal.m4
+
+./configure
+
+$MAKE test-whoami
+(cd pkg && $MAKE test-whoami) || exit 1
+
+$MAKE distcheck
+
+:
diff --git a/t/subpkg-yacc.sh b/t/subpkg-yacc.sh
new file mode 100644
index 000000000..485337264
--- /dev/null
+++ b/t/subpkg-yacc.sh
@@ -0,0 +1,129 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that ylwrap is installed properly, and $(YLWRAP) us defined
+# properly, when a subpackage is involved.
+
+required='cc yacc'
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AC_CONFIG_SUBDIRS([lib])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = lib
+bin_PROGRAMS = MU
+MU_LDADD = lib/liblib.a
+# It's ok to override distdir.
+distdir = subpack-1
+# Remove a file created by rules in subdir lib.
+CLEANFILES = lib-dist-hook-has-run
+EOF
+
+cat >MU.c <<'EOF'
+int lib (void);
+int main (void)
+{
+ return lib ();
+}
+EOF
+
+mkdir lib
+mkdir lib/src
+
+cat >lib/configure.ac <<'EOF'
+AC_INIT([lib], [2.3])
+AM_INIT_AUTOMAKE([subdir-objects])
+AC_PROG_RANLIB
+AC_PROG_YACC
+dnl This comes after YACC and RANLIB checks, deliberately.
+AC_PROG_CC
+AM_PROG_AR
+AC_CONFIG_HEADERS([config.h:config.hin])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+EOF
+
+cat >lib/Makefile.am <<'EOF'
+noinst_LIBRARIES = liblib.a
+liblib_a_SOURCES = src/x.c foo.y
+EXTRA_liblib_a_SOURCES = bar.y
+
+dist-hook:
+ test -d $(top_distdir)
+ test -d $(distdir)
+ find $(top_distdir) $(distdir) ;: For debugging.
+ test -f $(top_distdir)/MU.c
+ test ! -f $(distdir)/MU.c
+ for suf in y c; do \
+ for name in foo bar; do \
+ test -f $(distdir)/$$name.$$suf || exit 1; \
+ test ! -f $(top_distdir)/$$name.$$suf || exit 1; \
+ done; \
+ done
+ test -f $(distdir)/foo.y
+ test ! -f $(top_distdir)/foo.y
+ test -f $(distdir)/src/x.c
+ test ! -f $(top_distdir)/src/x.c
+ test -f $(YLWRAP)
+ : > $(top_builddir)/../lib-dist-hook-has-run
+EOF
+
+cat > lib/foo.y << 'END'
+%{
+int yylex (void) { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+cp lib/foo.y lib/bar.y
+
+cat >lib/src/x.c <<'EOF'
+#include <config.h>
+int lib (void)
+{
+ return 0;
+}
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -Wno-override
+
+cd lib
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE -Wno-override --add-missing
+cd ..
+
+./configure
+
+$MAKE dist
+test -f lib-dist-hook-has-run
+test -f subpack-1.tar.gz
+test ! -e subpack-1 # Make sure "dist" cleans up after itself.
+
+rm -f lib-dist-hook-has-run subpack-1.tar.gz
+
+yl_distcheck
+
+:
diff --git a/t/subpkg.sh b/t/subpkg.sh
new file mode 100644
index 000000000..d6351b100
--- /dev/null
+++ b/t/subpkg.sh
@@ -0,0 +1,111 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check subpackage handling.
+
+required=cc
+. test-init.sh
+
+mkdir m4
+
+cat >m4/foo.m4 <<'EOF'
+AC_DEFUN([FOO],[
+ AC_PROG_CC
+ AC_OUTPUT
+])
+EOF
+
+cat >>configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SUBDIRS([lib])
+FOO
+END
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = lib
+# Yes, This program is named LDADD. So what?
+bin_PROGRAMS = LDADD
+LDADD_LDADD = lib/liblib.a
+
+# It's ok to override distdir.
+distdir = subpack-1
+
+# Make sure $(distdir) and $(top_distdir) work as expected.
+dist-hook:
+ test -f $(distdir)/LDADD.c
+ test -f $(top_distdir)/LDADD.c
+EOF
+
+cat >LDADD.c <<'EOF'
+int lib (void);
+int main (void)
+{
+ return lib ();
+}
+EOF
+
+mkdir lib
+mkdir lib/src
+
+cat >lib/configure.ac <<'EOF'
+AC_INIT([lib], [2.3])
+AM_INIT_AUTOMAKE([subdir-objects])
+AC_CONFIG_MACRO_DIR([../m4])
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_CONFIG_HEADERS([config.h:config.hin])
+AC_CONFIG_FILES([Makefile])
+FOO
+EOF
+
+cat >lib/Makefile.am <<'EOF'
+noinst_LIBRARIES = liblib.a
+liblib_a_SOURCES = src/x.c
+
+dist-hook:
+ test ! -f $(distdir)/LDADD.c
+ test -f $(top_distdir)/LDADD.c
+ test -f $(distdir)/src/x.c
+ test ! -f $(top_distdir)/src/x.c
+EOF
+
+cat >lib/src/x.c <<'EOF'
+#include <config.h>
+int lib (void)
+{
+ return 0;
+}
+EOF
+
+$ACLOCAL
+$AUTOCONF -Werror -Wall
+$AUTOMAKE -Wno-override
+
+cd lib
+$ACLOCAL
+$FGREP 'm4_include([../m4/foo.m4])' aclocal.m4
+$AUTOCONF
+$AUTOHEADER
+$AUTOMAKE -Wno-override --add-missing
+cd ..
+
+./configure
+$MAKE
+$MAKE distcheck
+test ! -e subpack-1 # Make sure distcheck cleans up after itself.
+test -f subpack-1.tar.gz
+
+:
diff --git a/t/subpkg2.sh b/t/subpkg2.sh
new file mode 100644
index 000000000..1145c6242
--- /dev/null
+++ b/t/subpkg2.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Try a DIST_SUBDIRS subpackage with no SUBDIRS.
+# Report from Gary V. Vaughan.
+
+. test-init.sh
+
+mkdir m4
+
+cat >m4/foo.m4 <<'EOF'
+AC_DEFUN([FOO],[
+ AC_OUTPUT
+])
+EOF
+
+cat >>configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SUBDIRS([sub])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'EOF'
+DIST_SUBDIRS = sub
+dist-hook:
+ test -f $(distdir)/sub/script.in
+EOF
+
+mkdir sub
+
+cat >sub/configure.ac <<'EOF'
+AC_INIT([sub], [2.3])
+AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIR([../m4])
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([script])
+FOO
+EOF
+
+: >sub/script.in
+: >sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cd sub
+$ACLOCAL
+$FGREP 'm4_include([../m4/foo.m4])' aclocal.m4
+$AUTOCONF
+$AUTOMAKE -Wno-override
+cd ..
+
+./configure
+$MAKE distcheck
+
+:
diff --git a/t/subpkg3.sh b/t/subpkg3.sh
new file mode 100644
index 000000000..dacd862b8
--- /dev/null
+++ b/t/subpkg3.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure different subpackages may share files and directories.
+
+. test-init.sh
+
+cat >Makefile.am <<'END'
+SUBDIRS = subpkg
+EXTRA_DIST = subpkg/foobar
+END
+
+cat >>configure.ac <<'END'
+AC_CONFIG_SUBDIRS([subpkg])
+AC_OUTPUT
+END
+
+mkdir subpkg
+
+echo foobar >subpkg/foobar
+
+echo SUBDIRS = >subpkg/Makefile.am
+
+cat >subpkg/configure.ac <<'END'
+AC_INIT([subpkg], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+cd subpkg
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+cd ..
+
+./configure
+$MAKE distcheck
diff --git a/t/subpkg4.sh b/t/subpkg4.sh
new file mode 100644
index 000000000..cb76e5281
--- /dev/null
+++ b/t/subpkg4.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to ensure 'distdir' fixes the mode of files and directories
+# copied into '$(distdir)', even with sub-packages.
+
+. test-init.sh
+
+cat >Makefile.am <<'END'
+SUBDIRS = subpkg
+test-distdir-is-readable:
+ bad_dirs=`find $(distdir) -type d ! -perm -755 -print`; \
+ if test -n "$$bad_dirs"; then \
+ echo "directories not permissive: $$bad_dirs" >&2; \
+ exit 1; \
+ fi
+ bad_files=`find $(distdir) ! -type d ! -perm -444 -print`; \
+ if test -n "$$bad_files"; then \
+ echo "file not permissive: $$bad_files" >&2; \
+ exit 1; \
+ fi
+END
+
+cat >>configure.ac <<'END'
+AC_CONFIG_SUBDIRS([subpkg])
+AC_OUTPUT
+END
+
+mkdir subpkg subpkg/dir
+echo foobar >subpkg/foobar
+echo baz > subpkg/dir/baz
+
+chmod go-rwx subpkg/foobar subpkg/dir/baz subpkg/dir
+
+cat >subpkg/Makefile.am <<'END'
+EXTRA_DIST = foobar dir
+END
+
+cat >subpkg/configure.ac <<'END'
+AC_INIT([subpkg], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+cd subpkg
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+cd ..
+
+./configure
+$MAKE distdir
+$MAKE test-distdir-is-readable
diff --git a/t/subst-no-trailing-empty-line.sh b/t/subst-no-trailing-empty-line.sh
new file mode 100644
index 000000000..35f980676
--- /dev/null
+++ b/t/subst-no-trailing-empty-line.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# If the last line of a automake-rewritten definition is made only of
+# @substitutions@, automake should take care of appending an empty
+# variable to make sure that line cannot end up substituted as a blank
+# line (that would confuse HP-UX Make).
+# These checks have been introduced in commit 'Release-1-9-254-g9d0eaef'
+# into the former test 'subst2.test'.
+
+. test-init.sh
+
+# These are deliberately quite long, so that the xxx_PROGRAMS definition
+# in Makefile.am below will be split on multiple lines, with the last
+# line containing only @substituted@ stuff that expands to empty (this is
+# required to expose the bug we are testing).
+v1=ABCDEFGHIJKLMNOPQRSTUVWX
+v2=ABCDEFGHIJKLMNOPQRSTUVWXY
+v3=ABCDEFGHIJKLMNOPQRSTUVWXYZ
+
+# Literal backslash for use by grep.
+bs='\\'
+
+cat >> configure.ac <<END
+AC_SUBST([A], [''])
+AC_SUBST([$v1], [''])
+AC_SUBST([$v2], [''])
+AC_SUBST([$v3], [''])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<END
+AUTOMAKE_OPTIONS = no-dependencies
+CC = false
+EXEEXT =
+
+## The "x" and "zardoz" strings and the use of '+=' are there to ensure
+## that these variables get rewritten by Automake.
+noinst_PROGRAMS = x @$v1@ @$v2@ @$v3@
+bin_PROGRAMS = @A@
+bin_PROGRAMS += @$v1@ @$v2@ @$v3@
+check_PROGRAMS = zardoz \$(noinst_PROGRAMS)
+
+## Required whenever there are @substituted@ values in the
+## PROGRAMS primary, otherwise automake will complain.
+EXTRA_PROGRAMS =
+
+test-real-empty:
+ is \$(noinst_PROGRAMS) == x
+ is \$(bin_PROGRAMS) ==
+ is \$(check_PROGRAMS) == zardoz x
+
+test-fake-empty:
+ is \$(noinst_PROGRAMS) == x X
+ is \$(bin_PROGRAMS) == X
+ is \$(check_PROGRAMS) == zardoz x X
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+# For debugging.
+$EGREP -n 'ABCD|am__empty' Makefile.in
+# Sanity check.
+test $($EGREP -c "^[ $tab]*@$v2@ @$v3@[ $tab]*$bs?$" Makefile.in) -eq 3
+
+./configure
+{
+ sed -n '/^noinst_PROGRAMS *=/,/[^\\]$/p' Makefile
+ sed -n '/^bin_PROGRAMS *=/,/[^\\]$/p' Makefile
+ sed -n '/^check_PROGRAMS *=/,/[^\\]$/p' Makefile
+ sed -n '/^am__EXEEXT.*=/,/[^\\]$/p' Makefile
+} >t-programs
+cat t-programs
+grep '^ *$' t-programs && exit 1
+
+run_make test-real-empty
+run_make test-fake-empty am__empty=X
+
+:
diff --git a/t/subst.sh b/t/subst.sh
new file mode 100644
index 000000000..b1d5c6e0d
--- /dev/null
+++ b/t/subst.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that AC_SUBST($1) does something sensible. From Ulrich
+# Drepper.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+dnl This test used to have the following lines, which cannot have
+dnl worked sensibly with Autoconf for years, however:
+dnl AC_SUBST($1)
+dnl AC_SUBST([$]$1) dnl this is the actual invocation that was used
+dnl
+AC_DEFUN([FOO],
+[AC_SUBST([$1])])
+FOO([BAR])
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+grep '^\$1' Makefile.in && exit 1
+
+:
diff --git a/t/subst3.sh b/t/subst3.sh
new file mode 100644
index 000000000..06ebee850
--- /dev/null
+++ b/t/subst3.sh
@@ -0,0 +1,178 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test installation with substitutions. This test is based on
+# 'nobase.sh'.
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+if test x"$doit" = x"yes"; then
+ AC_SUBST([basehdr], [sub/base.h])
+ AC_SUBST([nobasehdr], [sub/nobase.h])
+ AC_SUBST([basedata], [sub/base.dat])
+ AC_SUBST([nobasedata], [sub/nobase.dat])
+ AC_SUBST([basescript], [sub/base.sh])
+ AC_SUBST([nobasescript], [sub/nobase.sh])
+ AC_SUBST([baseprog], ['sub/base$(EXEEXT)'])
+ AC_SUBST([nobaseprog], ['sub/nobase$(EXEEXT)'])
+ AC_SUBST([baselib], [sub/libbase.a])
+ AC_SUBST([nobaselib], [sub/libnobase.a])
+fi
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'EOF'
+foodir = $(prefix)/foo
+fooexecdir = $(prefix)/foo
+
+foo_HEADERS = @basehdr@
+nobase_foo_HEADERS = @nobasehdr@
+EXTRA_HEADERS = sub/base.h sub/nobase.h
+
+dist_foo_DATA = @basedata@
+nobase_dist_foo_DATA = @nobasedata@
+
+dist_fooexec_SCRIPTS = @basescript@
+nobase_dist_fooexec_SCRIPTS = @nobasescript@
+EXTRA_SCRIPTS = sub/base.sh sub/nobase.sh
+
+fooexec_PROGRAMS = @baseprog@
+nobase_fooexec_PROGRAMS = @nobaseprog@
+EXTRA_PROGRAMS = sub/base sub/nobase
+sub_base_SOURCES = source.c
+sub_nobase_SOURCES = source.c
+
+fooexec_LIBRARIES = @baselib@
+nobase_fooexec_LIBRARIES = @nobaselib@
+EXTRA_LIBRARIES = sub/libbase.a sub/libnobase.a
+sub_libbase_a_SOURCES = source.c
+sub_libnobase_a_SOURCES = source.c
+
+test-install-data: install-data
+ test -f inst/foo/sub/nobase.h
+ test ! -f inst/foo/nobase.h
+ test -f inst/foo/base.h
+ test -f inst/foo/sub/nobase.dat
+ test ! -f inst/foo/nobase.dat
+ test -f inst/foo/base.dat
+ test ! -f inst/foo/sub/pnobase.sh
+ test ! -f inst/foo/pbase.sh
+ test ! -f inst/foo/sub/pnobase$(EXEEXT)
+ test ! -f inst/foo/pbase$(EXEEXT)
+ test ! -f inst/foo/sub/libnobase.a
+ test ! -f inst/foo/libbase.a
+
+test-install-exec: install-exec
+ test -f inst/foo/sub/pnobase.sh
+ test ! -f inst/foo/pnobase.sh
+ test -f inst/foo/pbase.sh
+ test -f inst/foo/sub/pnobase$(EXEEXT)
+ test ! -f inst/foo/pnobase$(EXEEXT)
+ test -f inst/foo/pbase$(EXEEXT)
+ test -f inst/foo/sub/libnobase.a
+ test ! -f inst/foo/libnobase.a
+ test -f inst/foo/libbase.a
+
+test-install-nothing-data: install-data
+ test ! -f inst/foo/sub/nobase.h
+ test ! -f inst/foo/nobase.h
+ test ! -f inst/foo/base.h
+ test ! -f inst/foo/sub/nobase.dat
+ test ! -f inst/foo/nobase.dat
+ test ! -f inst/foo/base.dat
+ test ! -f inst/foo/sub/pnobase.sh
+ test ! -f inst/foo/pbase.sh
+ test ! -f inst/foo/sub/pnobase$(EXEEXT)
+ test ! -f inst/foo/pbase$(EXEEXT)
+ test ! -f inst/foo/sub/libnobase.a
+ test ! -f inst/foo/libbase.a
+
+test-install-nothing-exec: install-exec
+ test ! -f inst/foo/sub/pnobase.sh
+ test ! -f inst/foo/pnobase.sh
+ test ! -f inst/foo/pbase.sh
+ test ! -f inst/foo/sub/pnobase$(EXEEXT)
+ test ! -f inst/foo/pnobase$(EXEEXT)
+ test ! -f inst/foo/pbase$(EXEEXT)
+ test ! -f inst/foo/sub/libnobase.a
+ test ! -f inst/foo/libnobase.a
+ test ! -f inst/foo/libbase.a
+EOF
+
+mkdir sub
+
+: > sub/base.h
+: > sub/nobase.h
+: > sub/base.dat
+: > sub/nobase.dat
+: > sub/base.sh
+: > sub/nobase.sh
+
+cat >source.c <<'EOF'
+int
+main (int argc, char *argv[])
+{
+ return 0;
+}
+EOF
+cp source.c source2.c
+
+rm -f install-sh
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a --copy
+./configure --prefix "$(pwd)/inst" --program-prefix=p doit=yes
+
+$MAKE
+$MAKE test-install-data
+$MAKE test-install-exec
+$MAKE uninstall
+$MAKE clean
+
+test $(find inst/foo -type f -print | wc -l) -eq 0
+
+./configure --prefix "$(pwd)/inst" --program-prefix=p doit=no
+
+$MAKE
+$MAKE test-install-nothing-data
+$MAKE test-install-nothing-exec
+$MAKE uninstall
+
+
+# Likewise, in a VPATH build.
+
+$MAKE distclean
+mkdir build
+cd build
+../configure --prefix "$(pwd)/inst" --program-prefix=p doit=yes
+$MAKE
+$MAKE test-install-data
+$MAKE test-install-exec
+$MAKE uninstall
+test $(find inst/foo -type f -print | wc -l) -eq 0
+
+../configure --prefix "$(pwd)/inst" --program-prefix=p doit=no
+$MAKE
+$MAKE test-install-nothing-data
+$MAKE test-install-nothing-exec
+
+:
diff --git a/t/subst4.sh b/t/subst4.sh
new file mode 100644
index 000000000..161aaca13
--- /dev/null
+++ b/t/subst4.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test AM_SUBST_NOTMAKE.
+
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+myrule="\
+foo: bar
+ echo making \$@ from bar
+ echo \$@ > \$@
+"
+AC_SUBST([myrule])
+AM_SUBST_NOTMAKE([myrule])
+AC_OUTPUT
+EOF
+
+cat > Makefile.am <<'EOF'
+@myrule@
+EOF
+: > bar
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE foo
+test -f foo
+
+:
diff --git a/t/subst5.sh b/t/subst5.sh
new file mode 100644
index 000000000..d502792f6
--- /dev/null
+++ b/t/subst5.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Complain about configure substitutions in EXTRA_PRIMARY variables.
+# Rationale: we need to know the literal values of, say, PROGRAMS.
+# Thus, we allow substitutions in bin_PROGRAMS, but then EXTRA_PROGRAMS
+# needs to list possible values of that substitution, literally.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AC_SUBST([substed1])
+AC_SUBST([substed2])
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = @substed1@
+EXTRA_PROGRAMS = @substed2@
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'bin_PROGRAMS.*contains configure substitution' stderr && exit 1
+grep 'EXTRA_PROGRAMS.*contains configure substitution' stderr
+
+exit 0
diff --git a/t/substre2.sh b/t/substre2.sh
new file mode 100644
index 000000000..76aee664d
--- /dev/null
+++ b/t/substre2.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in variable substitution references, where
+# undefined variables break later substitutions.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([CC], [whocares])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+
+foo = foo.a foo.b $(doesnt_exist)
+bar = bar.a bar.b
+var1 = $(foo:.a=1.c) $(doesnt_exist:.b=2.c) $(bar:.a=3.c)
+var2 = $(var1:.b=4.c)
+
+bin_PROGRAMS = foo
+foo_SOURCES = $(var2)
+
+OBJEXT = obj
+.PHONY: test
+test:
+ is $(foo_OBJECTS) == foo1.obj foo4.obj bar3.obj bar4.obj
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE test
+
+:
diff --git a/t/substref.sh b/t/substref.sh
new file mode 100644
index 000000000..bf6153209
--- /dev/null
+++ b/t/substref.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug in variable substitution references when left hand
+# pattern is null.
+# Report from Richard Boulton.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([CC], [whocares])
+AC_OUTPUT
+END
+
+: > hello.c
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+var1 = dlmain
+var2 = $(var1:=.)
+helldl_SOURCES = $(var2:=c)
+bin_PROGRAMS = helldl
+.PHONY: test
+test:
+ is $(helldl_SOURCES) $(helldl_OBJECTS) == dlmain.c dlmain.$(OBJEXT)
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE test
+
+# This is unrelated to the rest of this test. But while we are
+# at it, make sure we don't use am__helldl_SOURCES_DIST here, since
+# it's not needed. DIST_SOURCES should contain $(helldl_SOURCES).
+grep am__helldl_SOURCES_DIST Makefile && exit 1
+grep 'DIST_SOURCES.*\$(helldl_SOURCES)' Makefile
+
+:
diff --git a/t/substtarg.sh b/t/substtarg.sh
new file mode 100644
index 000000000..b117a9c39
--- /dev/null
+++ b/t/substtarg.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that substitutions in variables work.
+# From Lars J. Aas.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_SOURCE([fakelib.c])
+AC_PROG_CC
+AM_PROG_AR
+RANLIB=:
+AC_SUBST([RANLIB])
+SUBST=hei
+AC_SUBST([SUBST])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libfake@SUBST@.a
+
+libfake@SUBST@_a_SOURCES = abra.c kadabra.c
+
+# Then we override the target rule:
+libfake@SUBST@.a: Makefile $(libfake@SUBST@_a_OBJECTS) $(libfake@SUBST@_a_DEPENDENCIES)
+ @echo here we do some custom stuff, instead of invoking the linker
+END
+
+: > ar-lib
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'overrid.*libfake@SUBST@.a' stderr
+$AUTOMAKE -Wno-override
+test $(grep -c '^libfake@SUBST@.a:' Makefile.in) -eq 1
+
+:
diff --git a/t/suffix-chain.tap b/t/suffix-chain.tap
new file mode 100644
index 000000000..504fefef7
--- /dev/null
+++ b/t/suffix-chain.tap
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that Automake can emit code that work round the inability of
+# some make implementations to automatically chain suffix rules.
+# See automake bug#7824 and bug#7670.
+
+required=cc
+. test-init.sh
+
+plan_ 8
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c1
+.c1.c0:
+ (echo 'int main (void)' && echo '{' && cat $<) > $@
+.c0.c:
+ (cat $< && echo '}') > $@
+CLEANFILES = foo.c0 foo.c
+END
+
+echo 'return 0;' > foo.c1
+
+command_ok_ "aclocal" $ACLOCAL
+command_ok_ "automake" $AUTOMAKE
+command_ok_ "autoconf" $AUTOCONF
+command_ok_ "configure" ./configure
+
+directive=''; make_can_chain_suffix_rules || directive=TODO
+
+for target in all distcheck; do
+ command_ok_ "make $target" \
+ -D "$directive" -r "suffix rules not chained" \
+ $MAKE $target
+done
+
+command_ok_ "clean" $MAKE clean
+# Sanity check.
+cat >> Makefile <<'END'
+foo.c: foo.c0
+foo.c0: foo.c1
+END
+command_ok_ "make with explicit dependencies" $MAKE
+
+:
diff --git a/t/suffix-custom-pr14441.sh b/t/suffix-custom-pr14441.sh
new file mode 100644
index 000000000..0af16790e
--- /dev/null
+++ b/t/suffix-custom-pr14441.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug#14441: the same user-defined suffix being transformed into
+# different automake-known suffixes in different Makefiles was confusing
+# Automake.
+
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_PROG_CC
+AC_PROG_CXX
+AC_CONFIG_FILES([sub/Makefile])
+EOF
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+bin_PROGRAMS = one
+one_SOURCES = one.ext
+.ext.cc:
+ whatever
+END
+
+cat > sub/Makefile.am <<'END'
+bin_PROGRAMS = two
+two_SOURCES = two.ext
+.ext.c:
+ do something
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+$FGREP '.c' Makefile.in sub/Makefile.in # For debugging.
+
+grep '^\.cc\.o:' Makefile.in
+LC_ALL=C $EGREP '\.c[^a-z]' Makefile.in && exit 1
+grep '^\.c\.o:' sub/Makefile.in
+$FGREP '.cc' sub/Makefile.in && exit 1
+
+:
diff --git a/t/suffix-custom-subobj-and-specflg.sh b/t/suffix-custom-subobj-and-specflg.sh
new file mode 100644
index 000000000..43b30a89c
--- /dev/null
+++ b/t/suffix-custom-subobj-and-specflg.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Tests that Automake understands suffix rules with renamed objects
+# and subdir objects.
+# Reported by Florian Briegel.
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_PROG_CC
+AC_OUTPUT
+EOF
+
+cat >Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+SUFFIXES = .baz .c
+.baz.c:
+ case $@ in sub/*) $(MKDIR_P) sub;; *) :;; esac
+## Account for VPATH issues on weaker make implementations (e.g. IRIX 6.5).
+ cp `test -f '$<' || echo $(srcdir)/`$< $@
+
+DISTCLEANFILES = sub/bar.c
+
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c sub/bar.baz
+foo_CFLAGS =
+END
+
+mkdir sub
+cat > sub/bar.baz <<'END'
+extern int foo ();
+int main () { return foo (); }
+END
+cat > foo.c <<'END'
+int foo () { return 0; }
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE
+$MAKE distcheck
+
+:
diff --git a/t/suffix-custom-subobj.sh b/t/suffix-custom-subobj.sh
new file mode 100644
index 000000000..ae3659014
--- /dev/null
+++ b/t/suffix-custom-subobj.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Tests that Automake understands suffix rules with subdir objects.
+# Reported by John Ratliff.
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac <<EOF
+AC_PROG_CC
+AC_OUTPUT
+EOF
+
+cat >Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+SUFFIXES = .baz .o
+# We fake here:
+.baz.o:
+## Account for VPATH issues on weaker make implementations.
+ cp `test -f '$<' || echo $(srcdir)/`$< $@
+
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c sub/bar.baz
+
+.PHONY: test-fake test-real
+test-fake:
+ echo $(foo_OBJECTS) | grep '^foo\.quux sub/bar\.quux$$'
+test-real:
+ echo $(foo_OBJECTS) | grep '^foo\.$(OBJEXT) sub/bar\.$(OBJEXT)$$'
+END
+
+mkdir sub
+: > sub/bar.baz
+: > foo.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+run_make OBJEXT=quux test-fake
+$MAKE test-real
+
+:
diff --git a/t/suffix-extra-c-stuff-pr14560.sh b/t/suffix-extra-c-stuff-pr14560.sh
new file mode 100644
index 000000000..9eb38ccd7
--- /dev/null
+++ b/t/suffix-extra-c-stuff-pr14560.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Automake bug#14560: if multiple user-specified suffix rules were
+# present, Automake could generate useless definitions and rules
+# related to C compilation.
+
+. test-init.sh
+
+cat > Makefile.am <<'END'
+.foo.bar:
+ foo2bar -o $@ $<
+.baz.qux:
+ baz2qux -o $@ $<
+bin_SCRIPTS = a.bar b.qux
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+$EGREP '\$\(CC\)|COMPILE|AM_V_CC|-compile|INCLUDES' Makefile.in && exit 1
+
+:
diff --git a/t/suffix.sh b/t/suffix.sh
new file mode 100644
index 000000000..2ded3db5b
--- /dev/null
+++ b/t/suffix.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure proper suffix rules for C compilation are produced, and
+# only once.
+# See also related test 'suffix2.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = foo
+noinst_LIBRARIES = libbar.a
+END
+
+for use_arlib in false :; do
+
+ rm -rf autom4te*.cache
+
+ if $use_arlib; then
+ am_warns=
+ echo AM_PROG_AR >> configure.ac
+ : > ar-lib
+ else
+ am_warns=-Wno-extra-portability
+ fi
+
+ $ACLOCAL
+
+ $AUTOMAKE $am_warns -i
+ grep '^ *\.c' Makefile.in # For debugging.
+ test $(grep -c '^\.c\.o:' Makefile.in) -eq 1
+ test $(grep -c '^\.c\.obj:' Makefile.in) -eq 1
+
+ $AUTOMAKE $am_warns
+ grep '^ *\.c' Makefile.in # For debugging.
+ test $(grep -c '^\.c\.o:' Makefile.in) -eq 1
+ test $(grep -c '^\.c\.obj:' Makefile.in) -eq 1
+
+done
+
+:
diff --git a/t/suffix10.tap b/t/suffix10.tap
new file mode 100644
index 000000000..ea89a7b40
--- /dev/null
+++ b/t/suffix10.tap
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that derivations work with .lo too.
+# (related to PR/37)
+
+required='cc libtoolize yacc'
+. test-init.sh
+
+plan_ 7
+
+cat >>configure.ac <<EOF
+AC_PROG_CC
+AC_PROG_YACC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+EOF
+
+cat >Makefile.am << 'END'
+lib_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = foo.x_
+.x_.y:
+ rm -f $@ $@-t
+## The leading ':;' works around a bug in bash <= 3.2.
+ :; { echo '/* autogenerated */' \
+ && echo '%{' \
+ && echo 'int yylex () {return 0;}' \
+ && echo 'void yyerror (char *s) {}' \
+ && echo '%}' \
+ && echo '%%' \
+ && echo "foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};" \
+ && echo '%%' \
+## Account for VPATH issues on weaker make implementations.
+ && cat `test -f '$<' || echo $(srcdir)/`$<; \
+ } > $@-t
+ mv -f $@-t $@
+.PHONY: test
+test:
+ echo $(libfoo_la_OBJECTS) | grep '^foo\.lo$$'
+END
+
+cat > foo.x_ << 'END'
+int foo (void) { return yyparse(); }
+END
+
+# We must protect the TAP driver from the output of configure, since
+# that might output a stray "ok" on a line of its own (due to a
+# libtool bug on Mac OS X), thus causing a spurious test result to
+# be seen. See automake bug#11897.
+run_configure ()
+{
+ st=0; ./configure >output 2>&1 || st=1
+ sed 's/^/ /' output
+ test $st -eq 0
+}
+
+command_ok_ "libtoolize" libtoolize --force
+command_ok_ "aclocal" $ACLOCAL
+command_ok_ "autoconf" $AUTOCONF
+command_ok_ "automake" $AUTOMAKE --add-missing
+command_ok_ "configure" run_configure
+command_ok_ "make test" $MAKE test
+
+directive=''; make_can_chain_suffix_rules || directive=TODO
+command_ok_ "make all" -D "$directive" -r "suffix rules not chained" \
+ $MAKE all
+
+:
diff --git a/t/suffix11.tap b/t/suffix11.tap
new file mode 100644
index 000000000..1811ad71a
--- /dev/null
+++ b/t/suffix11.tap
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Tests that Automake understands multiple suffix rules on the same line.
+# PR/371 and PR/372: Reported by Duncan Gibson.
+# We also check for suffixes containing '-'.
+
+required=cc
+. test-init.sh
+
+plan_ 10
+
+cat >>configure.ac <<EOF
+AC_PROG_CC
+AC_OUTPUT
+EOF
+
+cat >Makefile.am << 'END'
+bin_PROGRAMS = foo bar baz
+foo_SOURCES = foo.x_
+bar_SOURCES = bar.y-z
+baz_SOURCES = baz1.x_ baz2.y-z
+
+.y-z.c .x_.c:
+## Account for VPATH issues on weaker make implementations (e.g. IRIX 6.5).
+ sed 's/INTEGER/int/g' `test -f '$<' || echo $(srcdir)/`$< >$@
+
+CLEANFILES = foo.c bar.c baz1.c baz2.c
+
+.PHONY: test-real test-fake
+test-fake:
+ echo $(foo_OBJECTS) | grep '^foo\.foo$$'
+ echo $(bar_OBJECTS) | grep '^bar\.foo$$'
+ echo $(baz_OBJECTS) | grep '^baz1\.foo baz2\.foo$$'
+test-real:
+ echo $(foo_OBJECTS) | grep '^foo\.$(OBJEXT)$$'
+ echo $(bar_OBJECTS) | grep '^bar\.$(OBJEXT)$$'
+ echo $(baz_OBJECTS) | grep '^baz1\.$(OBJEXT) baz2\.$(OBJEXT)$$'
+check-local: test-real
+END
+
+echo 'INTEGER main(void) { return 0; }' > foo.x_
+echo 'INTEGER main(void) { return 0; }' > bar.y-z
+echo 'INTEGER main(void) { INTEGER baz(void); return baz(); }' > baz1.x_
+echo 'INTEGER baz(void) { return 0; }' > baz2.y-z
+
+command_ok_ "aclocal" $ACLOCAL
+command_ok_ "autoconf" $AUTOCONF
+
+# What we do is not portable. Automake should warn.
+AUTOMAKE_fails -a
+command_ok_ "warn about unportable make usage" \
+ grep '[iI]nference rules can have only one target before the colon' stderr
+# But this should work anyway.
+command_ok_ "automake" $AUTOMAKE -a -Wno-portability
+
+command_ok_ "configure" ./configure
+command_ok_ "make test-fake" run_make OBJEXT=foo test-fake
+command_ok_ "make test-real" $MAKE test-real
+
+directive=''; make_can_chain_suffix_rules || directive=TODO
+
+for target in '' distcheck; do
+ command_ok_ "make $target" \
+ -D "$directive" -r "suffix rules not chained" \
+ $MAKE $target
+done
+
+:
diff --git a/t/suffix2.sh b/t/suffix2.sh
new file mode 100644
index 000000000..445617a52
--- /dev/null
+++ b/t/suffix2.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure proper suffix rules for C compilation are produced,
+# and only once, even for libtool libraries.
+# See also related test 'suffix.sh'.
+required=libtoolize
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_LIBTOOL
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libltdl.la
+libltdl_la_SOURCES = ltdl.c ltdl.h
+END
+
+# Create all the files created libtoolize so we don't run libtoolize.
+# We don't want the user to need libtool to run this test.
+: > ltconfig
+: > ltmain.sh
+: > config.guess
+: > config.sub
+
+$ACLOCAL
+
+$AUTOMAKE -a
+grep '^ *\.c' Makefile.in # For debugging.
+test $(grep -c '^\.c\.o:' Makefile.in) -eq 1
+test $(grep -c '^\.c\.obj:' Makefile.in) -eq 1
+
+$AUTOMAKE -i
+grep '^ *\.c' Makefile.in # For debugging.
+test $(grep -c '^\.c\.o:' Makefile.in) -eq 1
+test $(grep -c '^\.c\.obj:' Makefile.in) -eq 1
+
+:
diff --git a/t/suffix3.tap b/t/suffix3.tap
new file mode 100644
index 000000000..81b832aef
--- /dev/null
+++ b/t/suffix3.tap
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that suffix rules chain.
+
+required=c++
+. test-init.sh
+
+plan_ 10
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUFFIXES = .zoo
+.zoo.cc:
+ sed 's/INTEGER/int/g' `test -f '$<' || echo $(srcdir)/`$< >$@
+bin_PROGRAMS = foo
+foo_SOURCES = foo.zoo
+# This is required by "make distcheck". The useless indirection is
+# reequired to avoid false positives by the grepping checks below.
+FOO = foo
+CLEANFILES = $(FOO).cc
+END
+
+command_ok_ "aclocal" $ACLOCAL
+command_ok_ "automake" $AUTOMAKE
+
+# The foo.cc intermediate step is implicit, it's a mistake if
+# Automake requires this file somewhere. Also, Automake should
+# not require the file 'foo.c' anywhere.
+command_ok_ "intermediate files not mentioned" \
+ not $FGREP foo.c Makefile.in
+# However Automake must figure that foo.zoo is eventually
+# transformed into foo.o, and use this latter file (to link foo).
+command_ok_ "final object file figured out" \
+ $FGREP 'foo.$(OBJEXT)' Makefile.in
+
+command_ok_ "autoconf" $AUTOCONF
+command_ok_ "configure" ./configure
+
+# This is deliberately valid C++, but invalid C.
+cat > foo.zoo <<'END'
+using namespace std;
+INTEGER main (void)
+{
+ return 0;
+}
+END
+
+directive=''; make_can_chain_suffix_rules || directive=TODO
+
+for target in all distcheck; do
+ command_ok_ "make $target" \
+ -D "$directive" -r "suffix rules not chained" \
+ $MAKE $target
+done
+
+# FIXME: should we check that intermediate file 'foo.cc' has
+# been removed? Or is this requiring too much from the make
+# implementation?
+
+# Intermediate files should not be distributed.
+command_ok_ "make distdir" $MAKE distdir
+command_ok_ "intermediate file not distributed" test ! -e $me-1.0/foo.cc
+
+:
diff --git a/t/suffix4.sh b/t/suffix4.sh
new file mode 100644
index 000000000..b7f77f6e7
--- /dev/null
+++ b/t/suffix4.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure Automake doesn't abort on user-defined extensions.
+# Based on a report from Dmitry Mikhin <dmitrym@acres.com.au>.
+
+# Also make sure that .SUFFIXES is automatically adjusted with
+# extensions from implicit rules.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+.k.o:
+ echo $< > $@
+
+bin_PROGRAMS = foo
+foo_SOURCES = foo.k
+END
+
+$ACLOCAL
+$AUTOMAKE
+grep '^\.SUFFIXES:' Makefile.in | sed -e 's/$/ /' > suffixes
+cat suffixes
+$FGREP ' .k ' suffixes
+
+:
diff --git a/t/suffix5.sh b/t/suffix5.sh
new file mode 100644
index 000000000..b7cd650ad
--- /dev/null
+++ b/t/suffix5.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure Automake include libtool objects resulting
+# from user-defined implicit rules.
+# Based on a report from Arkadiusz Miskiewicz <misiek@pld.ORG.PL>.
+
+required='cc libtool'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_SUBST([LINK], [:])
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+.k.lo:
+## Account for VPATH issues on weaker make implementations.
+ (echo $< && cat `test -f '$<' || echo $(srcdir)/`$<) > $@
+
+noinst_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = foo.k
+
+.PHONY: test
+test: all
+ grep '^=GREP=ME=$$' foo.lo
+## Weaker regex to account for VPATH issues.
+ grep 'foo\.k$$' foo.lo
+check-local: test
+END
+
+: > ltmain.sh
+
+for auxscript in ar-lib config.guess config.sub; do
+ cp "$am_scriptdir/$auxscript" . \
+ || fatal_ "fetching auxiliary script '$auxscript'"
+done
+
+$ACLOCAL
+$AUTOMAKE
+grep '_OBJECTS.*foo\.lo' Makefile.in
+
+$AUTOCONF
+./configure
+
+echo '=GREP=ME=' > foo.k
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/suffix6.sh b/t/suffix6.sh
new file mode 100644
index 000000000..1c8df185e
--- /dev/null
+++ b/t/suffix6.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure Automake supports implicit rules with dot-less
+# extensions. Also make sure that '.o' and '.obj' are handled like
+# '.$(OBJEXT)'. See also related "semantic" tests 'suffix6b.sh'
+# and 'suffix6c.sh'.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+SUFFIXES = a b .$(OBJEXT) c .o .obj
+bin_PROGRAMS = foo
+foo_SOURCES = fooa barc bazc
+ab:
+ dummy action 1
+b.$(OBJEXT):
+ dummy action 2
+c.o:
+ dummy action C
+c.obj:
+ dummy action C
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+sed -n -e '/foo_OBJECTS *=.*\\$/ {
+ :loop
+ p
+ n
+ t clear
+ :clear
+ s/\\$/\\/
+ t loop
+ p
+ n
+}' -e 's/$/ /' -e 's/^.*foo_OBJECTS *= */ /p' Makefile.in > foo-objects
+cat foo-objects
+
+# Automake must figure that fooa translates to foo.$(OBJEXT) and
+# foo.$(OBJEXT) using the following rules:
+# fooa --[ab]--> foob --[b.$(OBJEXT)]--> foo.$(OBJEXT)
+$FGREP ' foo.$(OBJEXT) ' foo-objects
+# barc --[c.o]--> bar.$(OBJEXT) ## This is really meant!
+$FGREP ' bar.$(OBJEXT) ' foo-objects
+# bazc --[c.obj]--> baz.$(OBJEXT) ## This is really meant!
+$FGREP ' baz.$(OBJEXT) ' foo-objects
+
+:
diff --git a/t/suffix6b.sh b/t/suffix6b.sh
new file mode 100644
index 000000000..f672fe453
--- /dev/null
+++ b/t/suffix6b.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure Automake supports implicit rules with dot-less
+# extensions. Se also related "grepping" test 'suffix6.sh'.
+
+required=GNUmake # Other makes might not grok dot-less suffix rules.
+. test-init.sh
+
+cat >> configure.ac << 'END'
+# $(LINK) is not defined automatically by Automake, since the *_SOURCES
+# variables don't contain any known extension (.c, .cc, .f, ...).
+# So we need this hack -- but since such an hack can also serve as a
+# mild stress test, that's ok.
+AC_SUBST([LINK], ['cat >$@'])
+AC_SUBST([OBJEXT], [oOo])
+AC_SUBST([EXEEXT], [.XxX])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUFFIXES = a b c .$(OBJEXT)
+bin_PROGRAMS = foo
+foo_SOURCES = fooa
+ab:
+ { echo '=ab=' && cat $<; } >$@
+bc:
+ { echo '=bc=' && cat $<; } >$@
+c.$(OBJEXT):
+ { echo '=b.obj=' && cat $<; } >$@
+test:
+ : For debugging.
+ ls -l
+ : Implicit intermediate files should be removed by GNU make ...
+ test ! -r foob
+ test ! -r fooc
+ : ... but object files should not.
+ cat foo.$(OBJEXT)
+ : For debugging.
+ cat foo.XxX
+ : Now check that the chain of implicit rules has been executed
+ : completely and in the correct order.
+ (echo =b.obj= && echo =bc= && echo =ab= && echo =src=) > exp
+ diff exp foo.XxX
+ rm -f exp
+.PHONY: test
+check-local: test
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+echo =src= > fooa
+
+$MAKE
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/t/suffix6c.sh b/t/suffix6c.sh
new file mode 100644
index 000000000..0a8b63d56
--- /dev/null
+++ b/t/suffix6c.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that '.o' and '.obj' are handled like '.$(OBJEXT)'.
+# See also related "grepping" test 'suffix6.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+# $(LINK) is not defined automatically by Automake, since the *_SOURCES
+# variables don't contain any known extension (.c, .cc, .f ...),
+# So we need this hack -- but since such an hack can also serve as a
+# mild stress test, that's ok.
+OBJEXT=${OBJEXT-oOo}
+AC_SUBST([LINK], ['cat >$@'])
+AC_SUBST([EXEEXT], [.XxX])
+AC_SUBST([OBJEXT])
+AC_OUTPUT
+END
+
+unset OBJEXT
+
+cat > Makefile.am << 'END'
+SUFFIXES = .zoo .o .obj .@OBJEXT@
+
+bin_PROGRAMS = foo
+foo_SOURCES = foo.zoo
+
+.zoo.o:
+ { echo '=.zoo.o=' && cat $<; } >$@
+.zoo.obj:
+ { echo '=.zoo.obj=' && cat $<; } >$@
+.zoo.@OBJEXT@:
+ { echo '=.zoo.@OBJEXT@=' && cat $<; } >$@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+cat > foo.exp <<'END'
+=.zoo.oOo=
+%ONE%
+END
+echo %ONE% > foo.zoo
+$MAKE
+cat foo.oOo
+cat foo.XxX
+diff foo.XxX foo.exp
+
+rm -f foo.* exp
+
+cat > foo.exp <<'END'
+=.zoo.o=
+%TWO%
+END
+echo %TWO% > foo.zoo
+run_make OBJEXT=o
+cat foo.o
+cat foo.XxX
+diff foo.XxX foo.exp
+
+rm -f foo.* exp
+
+cat > foo.exp <<'END'
+=.zoo.obj=
+%THREE%
+END
+echo %THREE% > foo.zoo
+run_make OBJEXT=obj
+cat foo.obj
+cat foo.XxX
+diff foo.XxX foo.exp
+
+rm -f foo.* exp
+
+:
diff --git a/t/suffix7.sh b/t/suffix7.sh
new file mode 100644
index 000000000..f6cb789c9
--- /dev/null
+++ b/t/suffix7.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure Automake supports implicit rules "confusing"
+# extensions. Inspired by a mail from Alex Hornby.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+SUFFIXES = .idl S.cpp C.h
+SUFFIXES += C.cpp S.h
+.idlC.cpp:
+ cp $< $@
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+# Make sure Automake has NOT recognized .cpp and .idlC as two new
+# extensions.
+grep 'SUFFIXES.* \.cpp' Makefile.in && exit 1
+grep 'SUFFIXES.* \.idlC' Makefile.in && exit 1
+
+:
diff --git a/t/suffix8.tap b/t/suffix8.tap
new file mode 100644
index 000000000..9db010bbc
--- /dev/null
+++ b/t/suffix8.tap
@@ -0,0 +1,105 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure Automake supports multiple derivations for the
+# same suffix.
+# From PR/37.
+
+required='cc libtoolize'
+. test-init.sh
+
+plan_ 10
+
+cat >>configure.ac <<'END'
+AM_PROG_AR
+AM_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am << 'END'
+# $(LINK) is not defined automatically by Automake, since the *_SOURCES
+# variables don't contain any known extension (.c, .cc, .f ...),
+# So we need this hack.
+LINK = :
+
+bin_PROGRAMS = foo
+lib_LTLIBRARIES = libfoo.la
+
+foo_SOURCES = foo.x_
+libfoo_la_SOURCES = bar.x_
+
+# The elaborate cp commands below account for VPATH issues on
+# weaker make implementations (e.g. IRIX 6.5).
+.x_.y_:
+ cp `test -f '$<' || echo $(srcdir)/`$< $@
+.y_.o:
+ cp `test -f '$<' || echo $(srcdir)/`$< $@
+.y_.obj:
+ cp `test -f '$<' || echo $(srcdir)/`$< $@
+.y_.z_:
+ cp `test -f '$<' || echo $(srcdir)/`$< $@
+.z_.lo:
+ cp `test -f '$<' || echo $(srcdir)/`$< $@
+
+# Some make implementations don't remove intermediate files
+# automatically, thus causing "make distcheck" to fail if
+# this is not added.
+MOSTLYCLEANFILES = *.y_ *.z_
+
+.PHONY: test0 test1 test2
+test0:
+ echo $(foo_OBJECTS) | grep '^foo\.foo$$'
+ echo $(libfoo_la_OBJECTS) | grep '^bar\.lo$$'
+test1:
+ echo $(foo_OBJECTS) | grep '^foo\.$(OBJEXT)$$'
+ echo $(libfoo_la_OBJECTS) | grep '^bar\.lo$$'
+test2: $(foo_OBJECTS) $(libfoo_la_OBJECTS)
+ test -f foo.$(OBJEXT)
+ test -f bar.lo
+check-local: test1 test2
+END
+
+echo 'int main (void) { return 0; }' > foo.x_
+echo 'int bar (void) { return 0; }' > bar.x_
+
+# We must protect the TAP driver from the output of configure, since
+# that might output a stray "ok" on a line of its own (due to a
+# libtool bug on Mac OS X), thus causing a spurious test result to
+# be seen. See automake bug#11897.
+protect_output ()
+{
+ st=0; "$@" >output 2>&1 || st=1
+ sed 's/^/ /' output
+ test $st -eq 0
+}
+
+command_ok_ "libtoolize" libtoolize
+command_ok_ "aclocal" $ACLOCAL
+command_ok_ "autoconf" $AUTOCONF
+command_ok_ "automake" $AUTOMAKE -a
+command_ok_ "configure" protect_output ./configure
+command_ok_ "make test0" run_make OBJEXT=foo test0
+command_ok_ "make test1" $MAKE test1
+
+directive=''; make_can_chain_suffix_rules || directive=TODO
+
+for target in test2 all distcheck; do
+ command_ok_ "make $target" \
+ -D "$directive" -r "suffix rules not chained" \
+ protect_output $MAKE $target
+done
+
+:
diff --git a/t/suffix9.sh b/t/suffix9.sh
new file mode 100644
index 000000000..4a997d67a
--- /dev/null
+++ b/t/suffix9.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that Automake choose the shorter route between suffixes
+# (related to PR/37)
+
+. test-init.sh
+
+cat >>configure.ac << 'END'
+AC_PROG_CC
+END
+
+$ACLOCAL
+
+# x_ -> y -> c -> o
+# \________/
+#
+# Automake should follow the bottom route: x_ -> c -> o because
+# it is shorter.
+#
+# It should not take the "-> y ->" route. We use 'y' here so that
+# then Automake will complains that YACC is not defined and the test will
+# fail when this happens.
+
+cat >Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.x_
+
+.x_.y:
+ cp $< $@
+.x_.c:
+ cp $< $@
+END
+
+$AUTOMAKE -a
+
+# Idem with the rules the another order.
+
+cat >Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.x_
+
+.x_.c:
+ cp $< $@
+.x_.y:
+ cp $< $@
+END
+
+$AUTOMAKE -a
+
+:
diff --git a/t/symlink.sh b/t/symlink.sh
new file mode 100644
index 000000000..78ad72218
--- /dev/null
+++ b/t/symlink.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we get an error if symlink creation fails.
+# Reported by Joerg-Martin Schwarz.
+
+am_create_testdir=empty
+. test-init.sh
+
+: > Makefile.am
+
+cat > configure.ac << 'END'
+AC_INIT([symlink], [1.0])
+AC_CONFIG_AUX_DIR([subdir])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+END
+
+$ACLOCAL
+AUTOMAKE_fails --add-missing
+
+grep '^configure\.ac:3: .*missing.*error while making link' stderr
+grep '^configure\.ac:3: .*install-sh.*error while making link' stderr
+
+test $(grep -c 'error while making link' stderr) -eq 2
+
+:
diff --git a/t/symlink2.sh b/t/symlink2.sh
new file mode 100644
index 000000000..863820167
--- /dev/null
+++ b/t/symlink2.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure that 'automake -a' redirects dangling symlinks.
+
+. test-init.sh
+
+rm -f install-sh
+ln -s Zardoz install-sh || skip_ "cannot create broken symlinks"
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+test -f install-sh
+test ! -e Zardoz
+
+:
diff --git a/t/syntax.sh b/t/syntax.sh
new file mode 100644
index 000000000..21d69afb2
--- /dev/null
+++ b/t/syntax.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for error for bad syntax.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+foo = q \
+
+bin_SCRIPTS = foo.sh
+END
+
+$ACLOCAL
+AUTOMAKE_fails -Wnone
+grep '^Makefile\.am:2:.*blank line following trailing backslash' stderr
+
+:
diff --git a/t/tags-pr12372.sh b/t/tags-pr12372.sh
new file mode 100644
index 000000000..14ae78c5b
--- /dev/null
+++ b/t/tags-pr12372.sh
@@ -0,0 +1,85 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure tags are processed also for files with non-standard
+# extensions. See automake bug#12372.
+
+required='cc etags'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_CONFIG_FILES([sub/Makefile])
+# Fake linking. Help avoid possible spurious errors from make
+# or from the linker; errors that are irrelevant to this test.
+AC_SUBST([LINK], ['echo $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@'])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+all-local: tags
+.pc.o:
+ sed -e 's/\[/{/' -e 's/\]/}/' $(srcdir)/$*.pc >$*.c
+ $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c $*.c
+ rm -f $*.c
+
+noinst_PROGRAMS = foo
+foo_SOURCES = foo-main.pc barbar.c
+SUBDIRS = sub
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+all-local: tags
+.pc.o:
+ sed -e 's/@/a/g' $(srcdir)/$*.pc >$*.c
+ $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c $*.c
+ rm -f $*.c
+
+noinst_PROGRAMS = zap
+zap_SOURCES = zardoz.pc
+END
+
+echo 'int main(void) [ return bar(1); ]' > foo-main.pc
+echo 'int bar(int x) { return !x; }' > barbar.c
+echo 'int m@in(void) { return 0; }' > sub/zardoz.pc
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# Exuberant Ctags (at least version 5.8) doesn't generate any tags
+# for file extensions it doesn't recognize. This can be fixed by
+# using the '--langmap' option. But we must be careful, because
+# etags from Emacs (at least version 23.4) doesn't recognize that
+# option.
+if etags --help | grep '.*--langmap'; then
+ run_make ETAGSFLAGS="--langmap=c:+.pc"
+else
+ $MAKE
+fi
+
+cat TAGS
+cat sub/TAGS
+$FGREP foo-main.pc TAGS
+$FGREP barbar.c TAGS
+$FGREP zardoz.pc sub/TAGS
+
+$MAKE distcheck
+
+:
diff --git a/t/tags.sh b/t/tags.sh
new file mode 100644
index 000000000..628f7d189
--- /dev/null
+++ b/t/tags.sh
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug reported by Harlan Stenn: the tags target doesn't work
+# when there are only headers in a directory.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+noinst_HEADERS = iguana.h
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^ID:' Makefile.in
diff --git a/t/tags2.sh b/t/tags2.sh
new file mode 100644
index 000000000..ea3f3e8d4
--- /dev/null
+++ b/t/tags2.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAGS_DEPENDENCIES only make sense if other tag-worthy things (such as
+# sources) exist.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat >Makefile.am << 'END'
+TAGS_DEPENDENCIES = foo
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'define.*TAGS_DEPENDENCIES.*without' stderr
+
+cat >>Makefile.am << 'END'
+bin_PROGRAMS = bar
+END
+
+AUTOMAKE_run
+grep 'define.*TAGS_DEPENDENCIES.*without' stderr && exit 1
+
+:
diff --git a/t/tagsub.sh b/t/tagsub.sh
new file mode 100644
index 000000000..177f790d1
--- /dev/null
+++ b/t/tagsub.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure tags and subdirs work correctly. Bug report by
+# François Pinard, and later by Akim Demaille.
+
+required=etags
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+echo 'SUBDIRS = sub' > Makefile.am
+mkdir sub
+echo 'noinst_HEADERS = iguana.h' > sub/Makefile.am
+: > sub/iguana.h
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE tags
+test -f sub/TAGS
+test -f TAGS
+$FGREP sub/TAGS TAGS
+$FGREP iguana.h sub/TAGS
+
+$MAKE distclean
+test ! -e sub/TAGS
+test ! -e TAGS
+
+:
diff --git a/t/tap-ambiguous-directive.sh b/t/tap-ambiguous-directive.sh
new file mode 100644
index 000000000..75ff7d4ef
--- /dev/null
+++ b/t/tap-ambiguous-directive.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - handling of "ambiguous" TODO and SKIP directives
+# See also related test 'tap-todo-skip-together.sh'.
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<END
+1..6
+ok 1 # foo SKIP
+not ok 2 # bar TODO
+ok 3 # :SKIP
+not ok 4 # :TODO
+ok 5 # SKIP SKIP
+not ok 6 # TODO TODO
+END
+
+run_make -O -e FAIL check
+count_test_results total=6 pass=2 fail=2 xpass=0 xfail=1 skip=1 error=0
+
+cat > exp << 'END'
+PASS: all.test 1 # foo SKIP
+FAIL: all.test 2 # bar TODO
+PASS: all.test 3 # :SKIP
+FAIL: all.test 4 # :TODO
+SKIP: all.test 5 # SKIP SKIP
+XFAIL: all.test 6 # TODO TODO
+END
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-autonumber.sh b/t/tap-autonumber.sh
new file mode 100644
index 000000000..ded621975
--- /dev/null
+++ b/t/tap-autonumber.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - unnumbered tests are OK, as long as their final total number
+# agrees with the plan
+# - test results without number get automatically numbered in the
+# console progress output
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<'END'
+1..14
+ok
+ok foo
+ok - foo2
+not ok
+not ok bar
+not ok - bar2
+; See that we can intermingle different kind of results without
+; messing up the autonumbering
+ok
+ok # TODO
+not ok # TODO who cares?
+ok
+not ok
+ok muuu # SKIP
+not ok
+ok
+END
+
+run_make -O -e FAIL TESTS=all.test check
+count_test_results total=14 pass=6 fail=5 xpass=1 xfail=1 skip=1 error=0
+
+cat > exp <<'END'
+PASS: all.test 1
+PASS: all.test 2 foo
+PASS: all.test 3 - foo2
+FAIL: all.test 4
+FAIL: all.test 5 bar
+FAIL: all.test 6 - bar2
+PASS: all.test 7
+XPASS: all.test 8 # TODO
+XFAIL: all.test 9 # TODO who cares?
+PASS: all.test 10
+FAIL: all.test 11
+SKIP: all.test 12 muuu # SKIP
+FAIL: all.test 13
+PASS: all.test 14
+END
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-bad-prog.tap b/t/tap-bad-prog.tap
new file mode 100644
index 000000000..5c5807759
--- /dev/null
+++ b/t/tap-bad-prog.tap
@@ -0,0 +1,85 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - missing, unreadable, or not-executable test scripts cause proper
+# error reports
+
+. test-init.sh
+
+fetch_tap_driver
+
+plan_ 6
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = $(srcdir)/tap-driver
+TESTS = none.test noread.test noexec.test
+none.test:
+END
+
+cat > noexec.test <<'END'
+#!/bin/sh
+echo 1..1
+echo ok 1
+END
+
+cp noexec.test noread.test
+chmod a-r noread.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+command_ok_ '"make check" returns non-zero exit status' \
+ run_make -O -e FAIL check
+
+# FIXME: maybe grep for stricter error messages in the next checks?
+
+command_ok_ "non-existent test is reported" \
+ grep '^ERROR: none\.test' stdout
+
+desc="non-executable test is reported"
+# Redirect output to avoid confusing automake's testsuite own TAP driver.
+if ./noexec.test >/dev/null; then
+ skip_ -r "any file is executable" "$desc"
+else
+ command_ok_ "$desc" -- grep '^ERROR: noexec\.test' stdout
+fi
+
+desc="non-readable test is reported"
+if test -r noread.test; then
+ skip_ -r "any file is readable" "$desc"
+else
+ command_ok_ "$desc" -- grep '^ERROR: noread\.test' stdout
+fi
+
+# Check that no spurious test result is reported. This is lower-priority
+# (and in fact the check currently fails).
+
+command_ok_ 'no spurious "missing plan" message' \
+ -D TODO -- not grep 'missing.* plan' stdout
+
+command_ok_ 'no spurious results' \
+ -D TODO -r 'still get "missing plan"' \
+ count_test_results total=3 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=3
+
+:
diff --git a/t/tap-bailout-and-logging.sh b/t/tap-bailout-and-logging.sh
new file mode 100644
index 000000000..6c4719755
--- /dev/null
+++ b/t/tap-bailout-and-logging.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - even after a "Bail out!" directive, all input is still copied in
+# the log file
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<END
+First line
+Bail out!
+non-TAP line after bailout
+# TAP diagnostic after bailout
+1..0 # SKIP TAP plan after bailout
+ok 1 - TAP result after bailout
+END
+
+$MAKE check && { cat all.log; exit 1; }
+cat all.log
+
+for rx in \
+ 'First line' \
+ 'Bail out!' \
+ 'non-TAP line after bailout' \
+ '# TAP diagnostic after bailout' \
+ '1\.\.0 # SKIP TAP plan after bailout' \
+ 'ok 1 - TAP result after bailout' \
+; do
+ grep "^$rx$" all.log
+done
+
+:
diff --git a/t/tap-bailout-leading-space.sh b/t/tap-bailout-leading-space.sh
new file mode 100644
index 000000000..53d965e73
--- /dev/null
+++ b/t/tap-bailout-leading-space.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# A "Bail out!" directive that is preceded by whitespace should still
+# be recognized.
+
+. test-init.sh
+. tap-setup.sh
+
+cat > a.test <<END
+1..1
+ok 1
+ Bail out!
+END
+
+cat > b.test <<END
+1..1
+ok 1 # SKIP
+${tab}Bail out!
+END
+
+cat > c.test <<END
+1..1
+ ${tab} ${tab}${tab}Bail out! FUBAR! $tab
+END
+
+cat >> exp <<END
+PASS: a.test 1
+ERROR: a.test - Bail out!
+SKIP: b.test 1
+ERROR: b.test - Bail out!
+ERROR: c.test - Bail out! FUBAR!
+END
+
+run_make -O -e FAIL TESTS='a.test b.test c.test' check
+count_test_results total=5 pass=1 fail=0 xpass=0 xfail=0 skip=1 error=3
+
+LC_ALL=C sort exp > t
+mv -f t exp
+
+# We need the sort below to account for parallel make usage.
+grep ': [abcde]\.test' stdout \
+ | sed "s/[ $tab]*#[ $tab]*SKIP.*//" \
+ | LC_ALL=C sort > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-bailout-suppress-badexit.sh b/t/tap-bailout-suppress-badexit.sh
new file mode 100644
index 000000000..0a65980c1
--- /dev/null
+++ b/t/tap-bailout-suppress-badexit.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic TAP test protocol support:
+# - A "Bail out!" directive causes the driver to ignore the exit
+# status of the test script.
+
+. test-init.sh
+
+tests='exit.test exit127.test sighup.test sigterm.test'
+
+cat > Makefile.am <<END
+TESTS = $tests
+END
+
+. tap-setup.sh
+
+cat > exit.test << 'END'
+#!/bin/sh
+echo 'Bail out!'
+exit 1
+END
+
+cat > exit127.test << 'END'
+#!/bin/sh
+echo 'Bail out!'
+exit 127
+END
+
+cat > sighup.test << 'END'
+#!/bin/sh
+echo 'Bail out!'
+kill -1 $$
+END
+
+cat > sigterm.test << 'END'
+#!/bin/sh
+echo 'Bail out!'
+kill -15 $$
+END
+
+chmod a+x $tests
+
+run_make -O -e FAIL check
+count_test_results total=4 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=4
+
+for tst in $tests; do grep "^ERROR: $tst - Bail out!" stdout; done
+$EGREP "ERROR: .*(exit.*status|terminat.*signal)" stdout && exit 1
+
+:
diff --git a/t/tap-bailout-suppress-later-diagnostic.sh b/t/tap-bailout-suppress-later-diagnostic.sh
new file mode 100644
index 000000000..08cee1405
--- /dev/null
+++ b/t/tap-bailout-suppress-later-diagnostic.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - A "Bail out!" directive causes the driver to ignore any TAP
+# diagnostic message in the rest of the following TAP stream.
+
+. test-init.sh
+
+. tap-setup.sh
+
+echo AM_TEST_LOG_DRIVER_FLAGS = --comments >> Makefile
+
+cat > all.test <<END
+1..1
+# sanity check
+ok 1
+Bail out!
+# not seen
+END
+
+run_make -O -e FAIL check
+count_test_results total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1
+grep '# all.test: sanity check' stdout
+grep 'not seen' stdout && exit 1
+
+:
diff --git a/t/tap-bailout-suppress-later-errors.sh b/t/tap-bailout-suppress-later-errors.sh
new file mode 100644
index 000000000..88bd7027d
--- /dev/null
+++ b/t/tap-bailout-suppress-later-errors.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - A "Bail out!" directive causes the driver to ignore any TAP
+# result or error in the rest of the following TAP stream.
+
+. test-init.sh
+
+. tap-setup.sh
+
+# Various errors that can all be squashed into a single test script.
+cat > foo.test << 'END'
+1..5
+Bail out!
+# All possible test results.
+# Test out-of-order.
+ok 4
+# Extra TAP plan.
+1..2
+# Another bailout directive.
+Bail out! Not seen.
+# Stop now, with too few tests run.
+END
+
+# Tests run after a "SKIP" plan.
+cat > bar.test << 'END'
+1..0 # SKIP
+Bail out!
+ok 1
+END
+
+# Too many tests run.
+cat > baz.test << 'END'
+1..1
+ok 1
+Bail out!
+ok 2
+ok 3
+END
+
+run_make -e FAIL -O TESTS='foo.test bar.test baz.test' check
+count_test_results total=5 pass=1 fail=0 xpass=0 xfail=0 skip=1 error=3
+
+grep '^ERROR: foo\.test - Bail out!$' stdout
+grep '^ERROR: bar\.test - Bail out!$' stdout
+grep '^SKIP: bar\.test' stdout
+grep '^ERROR: baz\.test - Bail out!$' stdout
+grep '^PASS: baz\.test 1$' stdout
+
+$FGREP 'Not seen' stdout && exit 1
+
+test $($FGREP -c ': foo.test' stdout) -eq 1
+test $($FGREP -c ': bar.test' stdout) -eq 2
+test $($FGREP -c ': baz.test' stdout) -eq 2
+
+:
diff --git a/t/tap-bailout.sh b/t/tap-bailout.sh
new file mode 100644
index 000000000..641e9c223
--- /dev/null
+++ b/t/tap-bailout.sh
@@ -0,0 +1,134 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic TAP test protocol support:
+# - "Bail out!" magic
+
+. test-init.sh
+
+. tap-setup.sh
+
+: > exp
+
+#------------------------------------------------------------------
+
+# Bailout without explanation.
+
+cat > a.test <<END
+1..4
+ok 1
+not ok 2
+Bail out!
+not ok 3
+ok 4 # SKIP
+END
+
+cat >> exp <<END
+PASS: a.test 1
+FAIL: a.test 2
+ERROR: a.test - Bail out!
+END
+
+# pass += 1, fail +=1, error += 1
+
+#------------------------------------------------------------------
+
+# Bailout with explanation.
+
+cat > b.test <<END
+1..7
+ok 1 # SKIP
+ok 2 # TODO
+not ok 3 # TODO
+Bail out! We're out of disk space.
+ok 4
+not ok 5
+not ok 6 # TODO
+ok 7 # TODO
+END
+
+cat >> exp <<END
+SKIP: b.test 1 # SKIP
+XPASS: b.test 2 # TODO
+XFAIL: b.test 3 # TODO
+ERROR: b.test - Bail out! We're out of disk space.
+END
+
+# skip += 1, xpass += 1, xfail += 1, error += 1
+
+#------------------------------------------------------------------
+
+# Bail out before the test plan.
+
+cat > c.test <<END
+ok 1
+ok 2
+Bail out! BOOOH!
+1..2
+END
+
+cat >> exp <<END
+PASS: c.test 1
+PASS: c.test 2
+ERROR: c.test - Bail out! BOOOH!
+END
+
+# pass += 2, error += 1
+
+#------------------------------------------------------------------
+
+# Bailout on the first line.
+
+cat > d.test <<END
+Bail out! mktemp -d: Permission denied
+ok 1
+END
+
+echo 'ERROR: d.test - Bail out! mktemp -d: Permission denied' >> exp
+
+# error += 1
+
+#------------------------------------------------------------------
+
+# TAP input comprised only of a bailout directive.
+
+cat > e.test <<END
+Bail out!
+END
+
+echo "ERROR: e.test - Bail out!" >> exp
+
+# error += 1
+
+#------------------------------------------------------------------
+
+# Doing the sums above, we have:
+test_counts='total=12 pass=3 fail=1 xpass=1 xfail=1 skip=1 error=5'
+
+run_make -O -e FAIL TESTS='a.test b.test c.test d.test e.test' check
+count_test_results $test_counts
+
+LC_ALL=C sort exp > t
+mv -f t exp
+
+# We need the sort below to account for parallel make usage.
+grep ': [abcde]\.test' stdout | LC_ALL=C sort > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-basic.sh b/t/tap-basic.sh
new file mode 100644
index 000000000..37c1afd42
--- /dev/null
+++ b/t/tap-basic.sh
@@ -0,0 +1,168 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic TAP support:
+# - LOG_COMPILER support;
+# - basic support for TODO and SKIP directives, and "Bail out!" magic;
+# - testsuite progress output on console;
+# - runtime overriding of TESTS and TEST_LOGS;
+# - correct counts of test results (both in summary and in progress
+# output on console).
+# Note that some of the features checked here are checked in other
+# test cases too, usually in a more thorough and detailed way.
+
+. test-init.sh
+
+fetch_tap_driver
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = $(srcdir)/tap-driver
+## Defining LOG_COMPILER should work and not intefere with the
+## tap-driver script.
+TEST_LOG_COMPILER = cat
+TESTS = success.test
+
+ok.test:
+ echo '1..3' > $@-t
+ echo 'ok 1' >> $@-t
+ echo 'not ok 2 # TODO' >>$@-t
+ echo 'ok 3 # SKIP' >>$@-t
+ cat $@-t ;: For debugging.
+ mv -f $@-t $@
+END
+
+cat > success.test << 'END'
+1..20
+ok 1
+ok 2 two
+ok 3 - three
+ok 4 four four
+not ok 5
+not ok 6 six
+not ok 7 - seven
+not ok 8 eight eight
+ok 9 # TODO
+ok 10 ten # TODO
+ok 11 - eleven # TODO
+ok 12 twelve twelve # TODO
+not ok 13 # TODO
+not ok 14 fourteen # TODO
+not ok 15 - fifteen # TODO
+not ok 16 sixteen sixteen # TODO
+ok 17 # SKIP
+ok 18 eighteen # SKIP
+ok 19 - nineteen # SKIP
+ok 20 twenty twenty # SKIP
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# Basilar usage and testsuite progress output.
+
+run_make -O -e FAIL check
+count_test_results total=20 pass=4 fail=4 xpass=4 xfail=4 skip=4 error=0
+
+test -f success.log
+test -f test-suite.log
+
+cat > exp << 'END'
+PASS: success.test 1
+PASS: success.test 2 two
+PASS: success.test 3 - three
+PASS: success.test 4 four four
+FAIL: success.test 5
+FAIL: success.test 6 six
+FAIL: success.test 7 - seven
+FAIL: success.test 8 eight eight
+XPASS: success.test 9 # TODO
+XPASS: success.test 10 ten # TODO
+XPASS: success.test 11 - eleven # TODO
+XPASS: success.test 12 twelve twelve # TODO
+XFAIL: success.test 13 # TODO
+XFAIL: success.test 14 fourteen # TODO
+XFAIL: success.test 15 - fifteen # TODO
+XFAIL: success.test 16 sixteen sixteen # TODO
+SKIP: success.test 17 # SKIP
+SKIP: success.test 18 eighteen # SKIP
+SKIP: success.test 19 - nineteen # SKIP
+SKIP: success.test 20 twenty twenty # SKIP
+END
+
+$FGREP ': success.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+# Override TESTS from the command line.
+
+rm -f *.log *.test
+
+cat > bail.test <<'END'
+1..1
+Bail out!
+ok 1
+END
+
+run_make -O -e FAIL check TESTS=bail.test
+count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=1
+
+test ! -e success.log
+test -f bail.log
+test -f test-suite.log
+
+grep '^ERROR: bail\.test - Bail out!' stdout
+grep '^PASS:' stdout && exit 1
+test $($FGREP -c ': bail.test' stdout) -eq 1
+$FGREP 'success.test' stdout && exit 1
+
+# Override TEST_LOGS from the command line, making it point to a test
+# (ok.test) that has to be generated at make time.
+
+rm -f *.log *.test
+
+run_make -O check TEST_LOGS=ok.log
+count_test_results total=3 pass=1 fail=0 xpass=0 xfail=1 skip=1 error=0
+
+test -f ok.test
+test -f ok.log
+test ! -e success.log
+test ! -e bail.log
+test -f test-suite.log
+
+$EGREP '(bail|success)\.test' stdout && exit 1
+
+cat > exp << 'END'
+PASS: ok.test 1
+XFAIL: ok.test 2 # TODO
+SKIP: ok.test 3 # SKIP
+END
+
+$FGREP ': ok.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-color.sh b/t/tap-color.sh
new file mode 100644
index 000000000..dadfb26b0
--- /dev/null
+++ b/t/tap-color.sh
@@ -0,0 +1,163 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - colorization of TAP results and diagnostic messages
+
+required='grep-nonprint'
+. test-init.sh
+
+# Escape '[' for grep, below.
+red="$esc\[0;31m"
+grn="$esc\[0;32m"
+lgn="$esc\[1;32m"
+blu="$esc\[1;34m"
+mgn="$esc\[0;35m"
+std="$esc\[m"
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = color-tests
+AM_TEST_LOG_DRIVER_FLAGS = --comments
+TEST_LOG_COMPILER = cat
+TESTS = all.test skip.test bail.test badplan.test noplan.test \
+ few.test many.test order.test afterlate.test
+END
+
+. tap-setup.sh
+
+cat > all.test << 'END'
+1..5
+ok 1 - foo
+# Hi! I shouldn't be colorized!
+not ok 2 - bar # TODO td
+ok 3 - baz # SKIP sk
+not ok 4 - quux
+ok 5 - zardoz # TODO
+END
+
+cat > skip.test << 'END'
+1..0 # SKIP whole script
+END
+
+cat > bail.test << 'END'
+1..1
+ok 1
+Bail out!
+END
+
+cat > badplan.test << 'END'
+1..2
+ok 1
+1..2
+ok 2
+END
+
+cat > noplan.test << 'END'
+ok 1
+END
+
+cat > few.test << 'END'
+1..2
+ok 1
+END
+
+cat > many.test << 'END'
+1..1
+ok 1
+ok 2
+END
+
+cat > order.test << 'END'
+1..1
+ok 5
+END
+
+cat > afterlate.test << 'END'
+ok 1
+1..2
+ok 2
+END
+
+test_color ()
+{
+ # Not a useless use of cat; see above comments "grep-nonprinting"
+ # requirement in 'test-init.sh'.
+ cat stdout | grep "^${grn}PASS${std}: all\.test 1 - foo$"
+ cat stdout | grep "^${lgn}XFAIL${std}: all\.test 2 - bar # TODO td$"
+ cat stdout | grep "^${blu}SKIP${std}: all\.test 3 - baz # SKIP sk$"
+ cat stdout | grep "^${red}FAIL${std}: all\.test 4 - quux$"
+ cat stdout | grep "^${red}XPASS${std}: all\.test 5 - zardoz # TODO$"
+ cat stdout | grep "^${blu}SKIP${std}: skip\.test - whole script$"
+ cat stdout | grep "^${grn}PASS${std}: bail\.test 1$"
+ cat stdout | grep "^${mgn}ERROR${std}: bail\.test - Bail out!$"
+ cat stdout | grep "^${mgn}ERROR${std}: badplan\.test - multiple test plans$"
+ cat stdout | grep "^${mgn}ERROR${std}: noplan\.test - missing test plan$"
+ cat stdout | grep "^${mgn}ERROR${std}: few.test - too few tests run (expected 2, got 1)$"
+ cat stdout | grep "^${mgn}ERROR${std}: many.test - too many tests run (expected 1, got 2)$"
+ cat stdout | grep "^${mgn}ERROR${std}: many.test 2 # UNPLANNED$"
+ cat stdout | grep "^${mgn}ERROR${std}: order.test 5 # OUT-OF-ORDER (expecting 1)$"
+ cat stdout | grep "^${mgn}ERROR${std}: afterlate\.test 2 # AFTER LATE PLAN$"
+ # Diagnostic messages shouldn't be colorized.
+ cat stdout | grep "^# all\.test: Hi! I shouldn't be colorized!$"
+ :
+}
+
+test_no_color ()
+{
+ # With make implementations that, like Solaris make, in case of errors
+ # print the whole failing recipe on standard output, we should content
+ # ourselves with a laxer check, to avoid false positives.
+ # Keep this in sync with lib/am/check.am:$(am__color_tests).
+ if $FGREP '= Xalways; then' stdout; then
+ # Extra verbose make, resort to laxer checks.
+ # But we also want to check that the testsuite summary is not unduly
+ # colorized.
+ (
+ set +e # In case some grepped regex below isn't matched.
+ # Not a useless use of cat; see above comments "grep-nonprinting"
+ # requirement in 'test-init.sh'.
+ cat stdout | grep "TOTAL.*:"
+ cat stdout | grep "PASS.*:"
+ cat stdout | grep "FAIL.*:"
+ cat stdout | grep "SKIP.*:"
+ cat stdout | grep "XFAIL.*:"
+ cat stdout | grep "XPASS.*:"
+ cat stdout | grep "ERROR.*:"
+ cat stdout | grep "^#"
+ cat stdout | grep 'test.*expected'
+ cat stdout | grep 'test.*not run'
+ cat stdout | grep '===='
+ cat stdout | grep '[Ss]ee .*test-suite\.log'
+ cat stdout | grep '[Tt]estsuite summary'
+ ) | grep "$esc" && exit 1
+ : For shells with broken 'set -e'
+ else
+ cat stdout | grep "$esc" && exit 1
+ : For shells with broken 'set -e'
+ fi
+}
+
+# Forced colorization should take place also with non-ANSI terminals;
+# hence the "TERM=dumb" definition.
+AM_COLOR_TESTS=always; export AM_COLOR_TESTS
+run_make -O -e FAIL TERM=dumb check
+test_color
+
+unset AM_COLOR_TESTS
+run_make -O -e FAIL TERM=ansi check
+test_no_color
+
+:
diff --git a/t/tap-common-setup.sh b/t/tap-common-setup.sh
new file mode 100644
index 000000000..91d212724
--- /dev/null
+++ b/t/tap-common-setup.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Auxiliary test to set up common data used by many tests on TAP support.
+
+. test-init.sh
+
+cat >> configure.ac << END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = $(srcdir)/tap-driver
+TEST_LOG_COMPILER = cat
+TESTS = all.test
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+rm -rf autom4te*.cache
+
+# So that the data files we've created won't be removed at exit.
+keep_testdirs=yes
+
+:
diff --git a/t/tap-deps.sh b/t/tap-deps.sh
new file mode 100644
index 000000000..173c93433
--- /dev/null
+++ b/t/tap-deps.sh
@@ -0,0 +1,84 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic TAP test protocol support:
+# - dependencies between test scripts
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+# The tests are *deliberately* listed in inversed order here.
+TESTS = c.test b.test a.test
+b.log: a.log
+c.log: b.log
+END
+
+. tap-setup.sh
+
+cat > a.test << 'END'
+#!/bin/sh
+echo 1..2
+echo ok 1
+# Creative quoting below to please maintainer-check.
+sleep '3'
+echo ok 2
+: > a.run
+END
+
+cat > b.test << 'END'
+#!/bin/sh
+echo 1..2
+if test -f a.run; then
+ echo ok 1
+else
+ echo not ok 1
+fi
+# Creative quoting below to please maintainer-check.
+sleep '3'
+echo ok 2
+: > b.run
+END
+
+cat > c.test << 'END'
+#!/bin/sh
+echo 1..1
+test -f b.run || { echo 'Bail out!'; exit 1; }
+echo ok 1
+rm -f a.run b.run
+END
+
+chmod a+x *.test
+
+run_make -O check
+count_test_results total=5 pass=5 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+cat > exp << 'END'
+PASS: a.test 1
+PASS: a.test 2
+PASS: b.test 1
+PASS: b.test 2
+PASS: c.test 1
+END
+
+grep ': [abc]\.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+# TODO: it would be nice to also redo the checks forcing parallel make...
+
+:
diff --git a/t/tap-diagnostic-custom.sh b/t/tap-diagnostic-custom.sh
new file mode 100644
index 000000000..df5807bc8
--- /dev/null
+++ b/t/tap-diagnostic-custom.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - option '--diagnostic-string' to customize the string introducing
+# TAP diagnostics
+
+. test-init.sh
+
+fetch_tap_driver
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+my_log_driver = $(srcdir)/tap-driver
+my_log_compiler = cat
+TEST_EXTENSIONS =
+TESTS =
+END
+
+: > later.mk
+
+# Quoting our comments below is an hack required to keep
+# comments near the things they refer to.
+i=0
+for string in \
+'## A letter' \
+ a \
+'## A number' \
+ 1023 \
+'## A non-alphabetic character' \
+ @ \
+'## Some metacharacters (we need to repeat the "$" for make)' \
+ '^>;&*"|$$' \
+'## A whitespace character' \
+ " " \
+'## A tab character' \
+ "$tab" \
+'## A string with more whitespace' \
+ " ${tab}a b${tab} c" \
+'## Note the we do not have the empty string here. We prefer to' \
+'## leave its behaviour in this context undefined for the moment.'
+do
+ case $string in '##'*) continue;; esac
+ i=$(($i + 1))
+ unindent >> Makefile.am << END
+ TEST_EXTENSIONS += .t$i
+ TESTS += foo$i.t$i
+ T${i}_LOG_COMPILER = \$(my_log_compiler)
+ T${i}_LOG_DRIVER = \$(my_log_driver)
+ AM_T${i}_LOG_DRIVER_FLAGS = \
+ --comments \
+ --diagnostic-string '$string'
+END
+ unindent > foo$i.t$i <<END
+ 1..1
+ ok 1
+ $string blah blah $i
+END
+ echo "AM_T${i}_LOG_DRIVER_FLAGS = --no-comments" >> later.mk
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+run_make -O check
+count_test_results total=$i pass=$i fail=0 xpass=0 xfail=0 skip=0 error=0
+
+cat later.mk >> Makefile
+run_make -O check
+$FGREP 'blah blah' stdout && exit 1
+
+:
diff --git a/t/tap-diagnostic.sh b/t/tap-diagnostic.sh
new file mode 100644
index 000000000..7f3993b97
--- /dev/null
+++ b/t/tap-diagnostic.sh
@@ -0,0 +1,117 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - diagnostic messages (TAP lines with leading "#")
+# - flags '--comments' and '--no-comments' of the TAP test driver
+
+. test-init.sh
+
+. tap-setup.sh
+
+metacharacters=\''"\$!&()[]<>#;^?*'
+
+cat > all.test <<END
+1..4
+# Hi! I'm a comment.
+# Tests begin.
+ok 1
+not ok 2 - foo # TODO
+ok 3 - bar # SKIP
+# Tests end.
+ok - zardoz
+# Shell metacharacters here: $metacharacters
+.# Leading characters before "#", not a TAP diagnostic line.
+x # Leading characters before "#", not a TAP diagnostic line.
+ # Leading whitespace before "#", not a TAP diagnostic line.
+${tab}# Leading whitespace before "#", not a TAP diagnostic line.
+ ${tab} # Leading whitespace before "#", not a TAP diagnostic line.
+END
+
+cat > exp <<END
+# all.test: Hi! I'm a comment.
+# all.test: Tests begin.
+PASS: all.test 1
+XFAIL: all.test 2 - foo # TODO
+SKIP: all.test 3 - bar # SKIP
+# all.test: Tests end.
+PASS: all.test 4 - zardoz
+# all.test: Shell metacharacters here: $metacharacters
+END
+
+run_make -O check
+$EGREP -i "#.*all\\.test|a comment|(Tests|Shell) " stdout && exit 1
+count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
+
+echo 'AM_TEST_LOG_DRIVER_FLAGS = --comments' >> Makefile
+run_make -O check
+$FGREP ' all.test' stdout > got
+cat exp
+cat got
+diff exp got
+count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
+
+run_make -O TEST_LOG_DRIVER_FLAGS="--no-comments" check
+$EGREP -i "#.*all\\.test|a comment|(Tests|Shell) " stdout && exit 1
+count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
+
+# The "#"-prepended lines here shouldn't be parsed as test results.
+cat > all.test <<END
+1..1
+ok
+# ok
+#ok
+# not ok
+#not ok
+# Bail out!
+#Bail out!
+# SKIP
+#SKIP
+# TODO
+#TODO
+END
+
+run_make -O check
+count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+# Diagnostic without leading whitespace, or with extra leading whitespace,
+# is ok. Be laxer in the grepping checks, to allow for whitespace
+# normalization by the TAP driver.
+
+ws="[ $tab]"
+ws0p="${ws}*"
+ws1p="${ws}${ws0p}"
+
+cat > all.test <<END
+1..1
+ok 1
+#foo
+#bar${tab}
+# zardoz ${tab}
+# ${tab} ${tab}${tab}foo bar${tab}baz ${tab}
+END
+
+run_make -O check
+count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+grep "^# all.test:${ws0p}foo$" stdout
+grep "^# all.test:${ws0p}bar${ws0p}$" stdout
+grep "^# all.test:${ws1p}zardoz${ws0p}$" stdout
+grep "^# all.test:${ws1p}foo bar${tab}baz${ws0p}$" stdout
+
+test $(grep -c '^# all\.test:' stdout) -eq 4
+
+:
diff --git a/t/tap-doc.sh b/t/tap-doc.sh
new file mode 100644
index 000000000..41bd47d12
--- /dev/null
+++ b/t/tap-doc.sh
@@ -0,0 +1,96 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that an example given in the documentation really works.
+# See section "Simple Tests" subsection "Script-based Testsuites".
+
+. test-init.sh
+
+fetch_tap_driver
+
+cat >> configure.ac <<END
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.sh zardoz.tap bar.sh mu.tap
+TEST_EXTENSIONS = .sh .tap
+TAP_LOG_DRIVER = $(srcdir)/tap-driver
+## Ensure the test scripts are run in the correct order.
+mu.log: bar.log
+bar.log: zardoz.log
+zardoz.log: foo.log
+END
+
+cat > foo.sh <<'END'
+#!/bin/sh
+exit 0
+END
+
+cat > bar.sh <<'END'
+#!/bin/sh
+exit 77
+END
+
+cat > zardoz.tap << 'END'
+#!/bin/sh
+echo 1..4
+echo 'ok 1 - Daemon started'
+echo 'ok 2 - Daemon responding'
+echo 'ok 3 - Daemon uses /proc # SKIP /proc is not mounted'
+echo 'ok 4 - Daemon stopped'
+END
+
+cat > mu.tap << 'END'
+#!/bin/sh
+echo 1..2
+echo 'ok'
+echo 'not ok # TODO frobnication not yet implemented'
+END
+
+chmod a+x *.sh *.tap
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+run_make -O check
+
+cat > exp <<'END'
+PASS: foo.sh
+PASS: zardoz.tap 1 - Daemon started
+PASS: zardoz.tap 2 - Daemon responding
+SKIP: zardoz.tap 3 - Daemon uses /proc # SKIP /proc is not mounted
+PASS: zardoz.tap 4 - Daemon stopped
+SKIP: bar.sh
+PASS: mu.tap 1
+XFAIL: mu.tap 2 # TODO frobnication not yet implemented
+END
+
+sed -n '/^PASS: foo\.sh/,/^XFAIL: mu\.tap/p' stdout > t
+cat t
+# Strip extra "informative" lines that could be printed by Solaris
+# Distributed Make.
+LC_ALL=C $EGREP -v ' --> ([0-9][0-9]* job|[Jj]ob output)' t > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-doc2.sh b/t/tap-doc2.sh
new file mode 100644
index 000000000..da2c20b17
--- /dev/null
+++ b/t/tap-doc2.sh
@@ -0,0 +1,138 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that an example given in the documentation really works.
+# See section "Using the TAP test protocol", subsection "Use TAP
+# with the Automake test harness".
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > Makefile.am <<'END'
+TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
+ $(top_srcdir)/build-aux/tap-driver.sh
+TESTS = foo.test bar.test baz.test
+EXTRA_DIST = $(TESTS)
+END
+
+cat > configure.ac <<'END'
+AC_INIT([GNU Try Tap], [1.0], [bug-automake@gnu.org])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE([foreign -Wall -Werror])
+AC_CONFIG_FILES([Makefile])
+AC_REQUIRE_AUX_FILE([tap-driver.sh])
+AC_OUTPUT
+END
+
+cat > foo.test <<'END'
+#!/bin/sh
+echo 1..4 # Number of tests to be executed.
+echo 'ok 1 - Swallows fly'
+echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
+echo 'ok 3 - Pigs fly # SKIP not enough acid'
+echo '# I just love word plays...'
+echo 'ok 4 - Flies fly too :-)'
+END
+
+cat > bar.test <<'END'
+#!/bin/sh
+echo 1..3
+echo 'not ok 1 - Bummer, this test has failed.'
+echo 'ok 2 - This passed though.'
+echo 'Bail out! Ennui kicking in, sorry...'
+echo 'ok 3 - This will not be seen.'
+END
+
+cat > baz.test <<'END'
+#!/bin/sh
+echo 1..1
+echo ok 1
+# Exit with error, even if all the tests have been successful.
+exit 7
+END
+
+chmod a+x *.test
+
+# Strip extra "informative" lines that could be printed by Solaris
+# Distributed Make.
+mkdir build-aux
+cp "$am_scriptdir"/tap-driver.sh build-aux \
+ || framework_failure_ "fetching the perl TAP driver"
+
+(export AUTOMAKE ACLOCAL AUTOCONF && $AUTORECONF -vi) || exit 1
+
+./configure --help # Sanity check.
+./configure || skip_ "configure failed"
+
+case $MAKE in *\ -j*) skip_ "can't work easily with concurrent make";; esac
+
+# Prevent Sun Distributed Make from trying to run in parallel.
+DMAKE_MODE=serial; export DMAKE_MODE
+
+run_make -O -e FAIL check
+
+cat > exp <<'END'
+PASS: foo.test 1 - Swallows fly
+XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
+SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
+PASS: foo.test 4 - Flies fly too :-)
+FAIL: bar.test 1 - Bummer, this test has failed.
+PASS: bar.test 2 - This passed though.
+ERROR: bar.test - Bail out! Ennui kicking in, sorry...
+PASS: baz.test 1
+ERROR: baz.test - exited with status 7
+END
+
+sed -n '/^PASS: foo\.test/,/^ERROR: baz\.test/p' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+grep '^Please report to bug-automake@gnu\.org$' stdout
+
+run_make -O check \
+ TESTS='foo.test baz.test' \
+ TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit'
+
+cat > exp <<'END'
+PASS: foo.test 1 - Swallows fly
+XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
+SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
+# foo.test: I just love word plays...
+PASS: foo.test 4 - Flies fly too :-)
+PASS: baz.test 1
+END
+
+sed -n '/^PASS: foo\.test/,/^PASS: baz\.test/p' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+# Sanity check the distribution.
+cat > bar.test <<'END'
+#!/bin/sh
+echo 1..1
+echo ok 1
+END
+echo AM_TEST_LOG_DRIVER_FLAGS = --ignore-exit >> Makefile.in
+./config.status Makefile
+$MAKE distcheck
+
+rm -f Makefile.in # To avoid a maintainer-check failure.
+
+:
diff --git a/t/tap-driver-stderr.sh b/t/tap-driver-stderr.sh
new file mode 100644
index 000000000..9f9a702fe
--- /dev/null
+++ b/t/tap-driver-stderr.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Unit test on TAP driver:
+# - error messages from awk/shell/perl goes to the console
+
+required=non-root
+am_create_testdir=empty
+. test-init.sh
+
+fetch_tap_driver
+
+tst=zardoz
+
+for suf in trs log; do
+
+ rm -f $tst.log $tst.trs
+ touch $tst.$suf
+ chmod a-w $tst.$suf
+
+ st=0
+ ./tap-driver --test-name $tst --log-file $tst.log --trs-file $tst.trs \
+ -- sh -c 'echo 1..1; echo ok 1; echo "Hello, World!"' \
+ >stdout 2>stderr && st=1
+ cat stdout
+ cat stderr >&2
+ cat $tst.log || :
+ cat $tst.trs || :
+ test $st -eq 0
+
+ $FGREP 'Hello, World!' stderr stdout && exit 1
+ $FGREP $tst.$suf stderr
+
+done
+
+:
diff --git a/t/tap-empty-diagnostic.sh b/t/tap-empty-diagnostic.sh
new file mode 100644
index 000000000..b1f49bba5
--- /dev/null
+++ b/t/tap-empty-diagnostic.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - empty diagnostic messages are discarder
+
+. test-init.sh
+
+. tap-setup.sh
+
+sed 's/\$$//' > all.test <<END
+1..1$
+ok 1$
+#$
+# $
+#${tab}$
+# ${tab} $tab${tab}$
+END
+
+run_make -O check
+
+grep '^PASS:.*all\.test' stdout # Sanity check.
+grep '#.*all\.test' stdout && exit 1
+grep "all\.test[ $tab]*:[ $tab]*$" stdout && exit 1
+
+:
diff --git a/t/tap-empty.sh b/t/tap-empty.sh
new file mode 100644
index 000000000..44eb2af76
--- /dev/null
+++ b/t/tap-empty.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support: the following situations should be flagged as errors:
+# - empty TAP input
+# - blank TAP input
+
+. test-init.sh
+
+. tap-setup.sh
+
+# Empty TAP input.
+: > empty.test
+
+# Blank TAP input (one empty line).
+echo > blank.test
+
+# Blank TAP input (one whitespace-only line).
+cat > white.test <<END
+ ${tab}
+END
+
+# Blank TAP input (few blank and whitespace-only lines).
+cat > white2.test <<END
+
+
+ ${tab} ${tab}${tab}
+
+${tab}
+
+END
+
+for input in empty blank white white2; do
+ cp $input.test all.test
+ run_make -O -e FAIL check
+ count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=1
+ grep '^ERROR: all\.test - missing test plan$' stdout
+done
+
+:
diff --git a/t/tap-escape-directive-2.sh b/t/tap-escape-directive-2.sh
new file mode 100644
index 000000000..3aba4e1fe
--- /dev/null
+++ b/t/tap-escape-directive-2.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - "escape" TODO and SKIP directives (by escaping the "#" character)
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<'END'
+1..8
+
+not ok \ # TODO
+ok \ # SKIP
+
+not ok \\# TODO
+ok \\# SKIP
+
+ok \\\# TODO
+ok \\\# SKIP
+
+not ok \\\\\\\\\\# TODO
+ok \\\\\\\\\\# SKIP
+END
+
+run_make -O check
+count_test_results total=8 pass=2 fail=0 xpass=0 xfail=3 skip=3 error=0
+
+grep '^XFAIL: all\.test 1 .*# TODO' stdout
+grep '^SKIP: all\.test 2 .*# SKIP' stdout
+grep '^XFAIL: all\.test 3 .*# TODO' stdout
+grep '^SKIP: all\.test 4 .*# SKIP' stdout
+grep '^PASS: all\.test 5 .*# TODO' stdout
+grep '^PASS: all\.test 6 .*# SKIP' stdout
+grep '^XFAIL: all\.test 7 .*# TODO' stdout
+grep '^SKIP: all\.test 8 .*# SKIP' stdout
+
+:
diff --git a/t/tap-escape-directive.sh b/t/tap-escape-directive.sh
new file mode 100644
index 000000000..603c949c1
--- /dev/null
+++ b/t/tap-escape-directive.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - "escape" TODO and SKIP directives (by escaping the "#" character)
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<'END'
+1..2
+ok \# TODO
+ok \# SKIP
+END
+
+run_make -O check
+count_test_results total=2 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+grep '^PASS: all\.test 1 .*# TODO' stdout
+grep '^PASS: all\.test 2 .*# SKIP' stdout
+
+:
diff --git a/t/tap-exit.sh b/t/tap-exit.sh
new file mode 100644
index 000000000..f09e7f411
--- /dev/null
+++ b/t/tap-exit.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - an exit status != 0 of a test script causes an hard error
+# - the '--ignore-exit' option causes the TAP test driver to ignore
+# exit statuses of the test scripts.
+
+. test-init.sh
+
+echo TESTS = > Makefile.am
+for st in 1 2 77 99; do
+ unindent > exit${st}.test <<END
+ #!/bin/sh
+ echo 1..1
+ echo ok 1
+ exit $st
+END
+ echo TESTS += exit${st}.test >> Makefile.am
+done
+
+chmod a+x *.test
+
+. tap-setup.sh
+
+run_make -O -e FAIL check
+count_test_results total=8 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=4
+
+grep '^ERROR: exit1\.test - exited with status 1$' stdout
+grep '^ERROR: exit2\.test - exited with status 2$' stdout
+grep '^ERROR: exit77\.test - exited with status 77$' stdout
+grep '^ERROR: exit99\.test - exited with status 99$' stdout
+
+echo TEST_LOG_DRIVER_FLAGS = --ignore-exit >> Makefile
+run_make -O check
+count_test_results total=4 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+:
diff --git a/t/tap-fancy.sh b/t/tap-fancy.sh
new file mode 100644
index 000000000..1296306f4
--- /dev/null
+++ b/t/tap-fancy.sh
@@ -0,0 +1,127 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support: some unusual forms for valid TAP input.
+# See also related test 'tap-fancy2.sh'.
+
+. test-init.sh
+
+. tap-setup.sh
+
+#
+# From manpage Test::Harness::TAP(3):
+#
+# Lines written to standard output matching /^(not )?ok\b/ must be
+# interpreted as test lines. All other lines must not be considered
+# test output.
+#
+# Unfortunately, the exact format of TODO and SKIP directives is not as
+# clearly described in that manpage; but a simple reverse-engineering of
+# the prove(1) utility shows that it is probably given by the perl regex
+# /#\s*(TODO|SKIP)\b/.
+#
+
+cat > all.test <<END
+1..21
+
+ok? a question
+not ok? a question
+
+ok+plus
+not ok+plus
+
+ok-minus
+not ok-minus
+
+ok#55
+not ok#55
+
+ok${tab} ${tab}9
+ok ${tab}${tab} 10
+
+not ok${tab} ${tab}11
+not ok ${tab}${tab} 12
+
+ok# SKIP
+ok${tab}#SKIP--who cares?
+ok?#SKIP!
+ok!#SKIP?
+
+not ok# TODO
+not ok${tab}#TODO--who cares?
+not ok?#TODO!
+not ok!#TODO?
+
+ok~#TODO
+END
+
+run_make -O -e FAIL check
+count_test_results total=21 pass=6 fail=6 xfail=4 xpass=1 skip=4 error=0
+
+#
+# "Weird" characters support.
+#
+
+# The "#" character might cause confusion w.r.t. TAP directives (TODO,
+# SKIP), so we don't attempt to use it.
+weirdchars=\''"$!&()[]<>;^?*/@%=,.:'
+
+cat > all.test <<END
+1..6
+ok $weirdchars
+not ok $weirdchars
+ok $weirdchars # TODO
+not ok $weirdchars # TODO
+ok $weirdchars # SKIP
+Bail out! $weirdchars
+END
+
+run_make -O -e FAIL check
+count_test_results total=6 pass=1 fail=1 xfail=1 xpass=1 skip=1 error=1
+$FGREP "PASS: all.test 1 $weirdchars" stdout
+$FGREP "FAIL: all.test 2 $weirdchars" stdout
+$FGREP "XPASS: all.test 3 $weirdchars" stdout
+$FGREP "XFAIL: all.test 4 $weirdchars" stdout
+$FGREP "SKIP: all.test 5 $weirdchars" stdout
+$FGREP "ERROR: all.test - Bail out! $weirdchars" stdout
+
+#
+# Trailing backslashes does not confuse the parser.
+#
+
+bs='\'
+
+cat > all.test <<END
+1..6
+ok $bs
+not ok $bs
+ok # TODO $bs
+not ok # TODO $bs
+ok # SKIP $bs
+Bail out! $bs
+END
+
+run_make -O -e FAIL check
+count_test_results total=6 pass=1 fail=1 xfail=1 xpass=1 skip=1 error=1
+
+grep '^PASS: all\.test 1 \\$' stdout
+grep '^FAIL: all\.test 2 \\$' stdout
+grep '^XPASS: all\.test 3 # TODO \\$' stdout
+grep '^XFAIL: all\.test 4 # TODO \\$' stdout
+grep '^SKIP: all\.test 5 # SKIP \\$' stdout
+grep '^ERROR: all\.test - Bail out! \\$' stdout
+
+:
diff --git a/t/tap-fancy2.sh b/t/tap-fancy2.sh
new file mode 100644
index 000000000..a4851cd04
--- /dev/null
+++ b/t/tap-fancy2.sh
@@ -0,0 +1,136 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support: more unusual forms for valid TAP input.
+# See also related test 'tap-fancy.sh'.
+
+. test-init.sh
+
+. tap-setup.sh
+
+#
+# From manpage Test::Harness::TAP(3):
+#
+# Lines written to standard output matching /^(not )?ok\b/ must be
+# interpreted as test lines. All other lines must not be considered
+# test output.
+#
+# Unfortunately, the exact format of TODO and SKIP directives is not as
+# clearly described in that manpage; but a simple reverse-engineering of
+# the prove(1) utility shows that it is probably given by the perl regex
+# /#\s*(TODO|SKIP)\b/.
+#
+
+# To avoid problems with backslashes in echo arguments.
+xecho () { printf '%s\n' "$*"; }
+
+# There are 34 values for $str ...
+for str in \
+ \' \
+ '"' \
+ '`' \
+ '#' \
+ '$' \
+ '!' \
+ '\' \
+ '/' \
+ '&' \
+ '%' \
+ '(' \
+ ')' \
+ '|' \
+ '^' \
+ '~' \
+ '?' \
+ '*' \
+ '+' \
+ '-' \
+ ',' \
+ ':' \
+ ';' \
+ '=' \
+ '<' \
+ '>' \
+ '@' \
+ '[' \
+ ']' \
+ '{' \
+ '}' \
+ '\\' \
+ '...' \
+ '?[a-zA-Z0-9]*' \
+ '*.*' \
+; do
+ # ... each of them add 1 pass, 1 fail, ...
+ xecho "ok${str}"
+ xecho "not ok${str}"
+ # ... and (generally) 4 skips, 4 xfails, and 4 xpasses ...
+ for settings in \
+ 'result="ok" directive=SKIP' \
+ 'result="not ok" directive=TODO' \
+ 'result="ok" directive=TODO' \
+ ; do
+ eval "$settings"
+ xecho "${result}# ${directive}${str}"
+ # ... but 6 skips, 6 xpasses and 6 xfails are to be removed, since
+ # they might not work with $str = '#' or $str = '\' ...
+ if test x"$str" != x'#' && test x"$str" != x'\'; then
+ xecho "${result}${str}#${directive}"
+ xecho "${result}${str}# ${tab}${tab} ${directive}"
+ xecho "${result}${str}#${directive}${str}"
+ fi
+ done
+done > all.test
+
+# Sanity check against a previous use of unportable usages of backslashes
+# with the "echo" builtin.
+if grep '[^\\]\\#' all.test; then
+ framework_failure_ "writing backslashes in all.test"
+fi
+
+# ... so that we finally have:
+pass=34
+fail=34
+xfail=130 # = 4 * 34 - 6
+xpass=130 # = 4 * 34 - 6
+skip=130 # = 4 * 34 - 6
+error=0
+total=$(($pass + $fail + $xfail + $xpass + $skip))
+
+# Even nastier! But accordingly to the specifics, it should still work.
+for result in 'ok' 'not ok'; do
+ echo "${result}{[(<#${tab}TODO>)]}" >> all.test
+done
+echo "ok{[(<#${tab}SKIP>)]}" >> all.test
+
+# We have to update some test counts.
+xfail=$(($xfail + 1))
+xpass=$(($xpass + 1))
+skip=$(($skip + 1))
+total=$(($total + 3))
+
+# And add the test plan!
+echo 1..$total >> all.test
+
+run_make -O -e FAIL check
+
+$EGREP '^(PASS|FAIL|SKIP).*#.*TODO' stdout && exit 1
+$EGREP '^X?(PASS|FAIL).*#.*SKIP' stdout && exit 1
+
+count_test_results total=$total pass=$pass fail=$fail skip=$skip \
+ xpass=$xpass xfail=$xfail error=$error
+
+:
diff --git a/t/tap-global-log.sh b/t/tap-global-log.sh
new file mode 100644
index 000000000..57f55e608
--- /dev/null
+++ b/t/tap-global-log.sh
@@ -0,0 +1,122 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - which log files get copied in the global log?
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > ok.test << 'END'
+1..5
+ok 1
+ok 2
+ok 3
+not seen in global log
+ok 4
+ok 5
+END
+
+cat > top << 'END'
+1..6
+ok 1
+ok 2
+ok 3
+END
+
+cat > bot << 'END'
+ok 5
+ok 6
+END
+
+cat top - bot > skip.test << 'END'
+ok # SKIP
+::skip::
+END
+
+cat top - bot > todo.test << 'END'
+not ok # TODO
+::todo::
+END
+
+cat top - bot > fail.test << 'END'
+not ok
+::fail::
+END
+
+cat top - bot > xpass.test << 'END'
+ok # TODO
+::xpass::
+END
+
+cat top - bot > bail.test << 'END'
+::bail::
+Bail out!
+END
+
+cat top - bot > error.test << 'END'
+::error::
+1..7
+END
+
+# Created with "dd if=/dev/urandom count=1 | base64-encode"
+cat > hodgepodge <<'END'
+1+0 records in
+1+0 records out
+512 bytes (512 B) copied, 0.000241092 s, 2.1 MB/s
+gdivnV4VhL4DOzhE3zULJuun3PwqqQqMdATVcZbIQkNgyRvNBoqqHMBQEs7QsjDbp2nK+Szz
+EcelGyvXmHrW7yImaom6Yrg95k31VCmp/pGDRnTDwDrcOPJiv9jDReEmTAQkPuqLO+mFNly+
+DDHM9fNbzGumstsQ3wq3DOXz1pCV3JXwhjeaHSboeEbmr55bX0XHLSKaecctA0rXDXEyZWZ/
+ODlawSrAXzw0H7a+xBwjnNXZ3zYiwk3x+WQrPqNjb+qXiLLTxAKzx2/KnaFhxkPlte5jPRNB
+FciDolL+H/10LsCdSzLOrGnY2zH6vL2JMZfxjnb73zWFcdWWE01LTD7wpN5O1MP3+N47lcVe
+lWbkD04cJvhwxLElYSO24B743GG5EyGYt9SeZRE6xbgwq3fVOS8KqjwGxwi4adSBTtw0CV8W
+S/6n8dck1vBvjA+qpk0zMSYSqc3+jzW9UiGTmTEIwfw80p/lGNsfjcNBJ86nFkWUnHmrsi8k
+Dv57sK70mTg239g08f5Uvdga/5UreMBSgB0hUj5sbq57r7B1fsVr0Kag468la8zKy3ZEZ0gX
+++sbaJ9WGHhnKvjooeH+4Y6HwAFsdINde++FlCmp4EuNKKEEuXbSKLaOTy3+6pJ2DYdvRCL+
+frZwxH4hcrw8qh+8IakB02viewZS/qT57v4=
+END
+
+exec 5>misc.test
+echo 'ok # SKIP' >&5
+cat hodgepodge >&5
+echo 'not ok # TODO' >&5
+echo 'ok' >&5
+exec 5>&-
+
+cat > skipall.test << 'END'
+1..0 # SKIP all
+END
+
+run_make -e IGNORE TESTS="$(echo *.test)" check
+cat test-suite.log
+
+grep ':.*ok|not seen' test-suite.log && exit 1
+
+for s in skip todo fail xpass bail error; do
+ $FGREP "::$s::" test-suite.log
+done
+
+grep '^1\.\.0 # SKIP all$' test-suite.log
+
+test_suite_contents=$(cat test-suite.log)
+hodgepodge_contents=$(cat hodgepodge)
+case $test_suite_contents in
+ *"$hodgepodge_contents"*) ;;
+ *) exit 1;;
+esac
+
+:
diff --git a/t/tap-global-result.sh b/t/tap-global-result.sh
new file mode 100644
index 000000000..e89348cc3
--- /dev/null
+++ b/t/tap-global-result.sh
@@ -0,0 +1,185 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - which global test result derives from different test results
+# mixed in a single script?
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > ok.test <<END
+1..3
+ok 1
+not ok 2 # TODO
+ok 3 # SKIP
+END
+
+cat > skip.test <<'END'
+1..3
+ok 1 # SKIP
+ok 2 # SKIP
+ok 3 # SKIP
+END
+
+cat > skipall.test <<'END'
+1..0 # SKIP
+foo
+# bar
+END
+
+cat > fail.test <<'END'
+1..1
+not ok 1
+END
+
+(sed '1s/.*/1..4/' ok.test && echo 'not ok 4') > fail2.test
+
+cat > xpass.test <<'END'
+1..1
+ok 1 # TODO
+END
+
+(sed '1s/.*/1..4/' ok.test && echo 'ok 4 # TODO') > xpass2.test
+
+echo 'Bail out!' > bail.test
+
+(cat ok.test && echo 'Bail out!') > bail2.test
+
+cat > bail3.test <<'END'
+1..0 # SKIP
+Bail out!
+END
+
+# Too many tests.
+cat > error.test <<'END'
+1..2
+ok 1
+ok 2 # SKIP
+not ok 3
+not ok 4 # TODO
+END
+
+# Too few tests.
+cat > error2.test <<'END'
+1..4
+ok 1
+not ok 2 # TODO
+ok 3 # SKIP
+END
+
+# Repeated plan.
+cat > error3.test <<'END'
+1..2
+1..2
+ok 1
+ok 2
+END
+
+# Too many tests, after a "SKIP" plan.
+cat > error4.test <<'END'
+1..0 # SKIP
+ok 1
+ok 2
+END
+
+# Tests out of order.
+cat > error5.test <<'END'
+1..4
+not ok 1 # TODO
+ok 3
+ok 2
+ok 4
+END
+
+# Wrong test number.
+cat > error6.test <<'END'
+1..2
+ok 1 # SKIP
+ok 7
+END
+
+# No plan.
+cat > error7.test <<'END'
+ok 1 # SKIP
+ok 2 # TODO
+not ok 3 # TODO
+ok 4
+END
+
+cat > hodgepodge.test <<'END'
+1..2
+not ok 1
+ok 2 # TODO
+Bail out!
+END
+
+cat > hodgepodge-all.test <<'END'
+1..4
+ok 1
+ok 2 # SKIP
+not ok 2 # TODO
+not ok 3
+ok 4 # TODO
+Bail out!
+END
+
+tests=$(echo *.test) # Also required later.
+
+run_make -O -e FAIL TESTS="$tests" check
+
+# Dirty trick required here.
+for tst in $(echo " $tests " | sed 's/\.test / /'); do
+ echo :copy-in-global-log: yes >> $tst.trs
+done
+
+rm -f test-suite.log
+run_make -e FAIL TESTS="$tests" test-suite.log
+cat test-suite.log
+
+have_rst_section ()
+{
+ eqeq=$(echo "$1" | sed 's/./=/g')
+ # Assume $1 contains no RE metacharacters.
+ sed -n "/^$1$/,/^$eqeq$/p" test-suite.log > got
+ (echo "$1" && echo "$eqeq") > exp
+ cat exp
+ cat got
+ diff exp got
+}
+
+have_rst_section 'PASS: ok'
+have_rst_section 'SKIP: skip'
+have_rst_section 'SKIP: skipall'
+have_rst_section 'FAIL: fail'
+have_rst_section 'FAIL: fail2'
+have_rst_section 'FAIL: xpass'
+have_rst_section 'FAIL: xpass2'
+have_rst_section 'ERROR: bail'
+have_rst_section 'ERROR: bail2'
+have_rst_section 'ERROR: bail3'
+have_rst_section 'ERROR: error'
+have_rst_section 'ERROR: error2'
+have_rst_section 'ERROR: error3'
+have_rst_section 'ERROR: error4'
+have_rst_section 'ERROR: error5'
+have_rst_section 'ERROR: error6'
+have_rst_section 'ERROR: error7'
+have_rst_section 'ERROR: hodgepodge'
+have_rst_section 'ERROR: hodgepodge-all'
+
+:
diff --git a/t/tap-log.sh b/t/tap-log.sh
new file mode 100644
index 000000000..fbfdcc1bf
--- /dev/null
+++ b/t/tap-log.sh
@@ -0,0 +1,162 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - log file creation
+# - log file removal
+# - stdout and stderr of a script go in its log file
+# - TEST_SUITE_LOG redefinition, at either automake or make time
+# - VERBOSE environment variable support
+# Keep in sync with 'test-log.sh'.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+TESTS = pass.test skip.test xfail.test fail.test xpass.test error.test
+TEST_SUITE_LOG = global.log
+END
+
+. tap-setup.sh
+
+# Custom markers, for use in grepping checks.
+cmarker=::: # comment marker
+pmarker=%%% # plain maker
+
+cat > pass.test <<END
+#! /bin/sh -e
+echo 1..1
+echo "$pmarker pass $pmarker" >&2
+echo "# $cmarker pass $cmarker" >&2
+echo "ok 1"
+END
+
+cat > skip.test <<END
+#! /bin/sh -e
+echo 1..1
+echo "$pmarker skip $pmarker"
+echo "# $cmarker skip $cmarker"
+echo "ok 1 # SKIP"
+END
+
+cat > xfail.test <<END
+#! /bin/sh -e
+echo 1..1
+echo "$pmarker xfail $pmarker" >&2
+echo "# $cmarker xfail $cmarker" >&2
+echo "not ok 1 # TODO"
+END
+
+cat > fail.test <<END
+#! /bin/sh -e
+echo 1..1
+echo "$pmarker fail $pmarker"
+echo "# $cmarker fail $cmarker"
+echo "not ok 1"
+END
+
+cat > xpass.test <<END
+#! /bin/sh -e
+echo 1..1
+echo "$pmarker xpass $pmarker" >&2
+echo "# $cmarker xpass $cmarker" >&2
+echo "ok 1 # TODO"
+END
+
+cat > error.test <<END
+#! /bin/sh -e
+echo 1..1
+echo "$pmarker error $pmarker"
+echo "# $cmarker error $cmarker"
+echo 'Bail out!'
+END
+
+chmod a+x *.test
+
+run_make -e FAIL TEST_SUITE_LOG=my.log check
+ls -l # For debugging.
+test ! -e test-suite.log
+test ! -e global.log
+test -f my.log
+st=0
+for result in pass fail xfail xpass skip error; do
+ cat $result.log # For debugging.
+ $FGREP "$pmarker $result $pmarker" $result.log || st=1
+ $FGREP "$cmarker $result $cmarker" $result.log || st=1
+done
+test $st -eq 0 || exit 1
+cat my.log # For debugging.
+for result in xfail fail xpass skip error; do
+ cat $result.log # For debugging.
+ $FGREP "$pmarker $result $pmarker" my.log || st=1
+ $FGREP "$cmarker $result $cmarker" my.log || st=1
+done
+test $($FGREP -c "$pmarker" my.log) -eq 5
+test $($FGREP -c "$cmarker" my.log) -eq 5
+
+# Passed test scripts shouldn't be mentioned in the global log.
+$EGREP '(^pass|[^x]pass)\.test' my.log && exit 1
+# But failing (expectedly or not) and skipped ones should.
+$FGREP 'xfail.test' my.log
+$FGREP 'skip.test' my.log
+$FGREP 'fail.test' my.log
+$FGREP 'xpass.test' my.log
+$FGREP 'error.test' my.log
+
+touch error2.log test-suite.log global.log
+run_make TEST_SUITE_LOG=my.log mostlyclean
+ls -l # For debugging.
+test ! -e my.log
+test ! -e pass.log
+test ! -e fail.log
+test ! -e xfail.log
+test ! -e xpass.log
+test ! -e skip.log
+test ! -e error.log
+# "make mostlyclean" shouldn't remove unrelated log files.
+test -f error2.log
+test -f test-suite.log
+test -f global.log
+
+rm -f *.log
+
+run_make -O -e FAIL check VERBOSE=yes
+cat global.log
+test ! -e my.log
+test ! -e test-suite.log
+# Check that VERBOSE causes the global testsuite log to be
+# emitted on stdout.
+out=$(cat stdout)
+log=$(cat global.log)
+case $out in *"$log"*) ;; *) exit 1;; esac
+
+touch error2.log test-suite.log my.log
+$MAKE clean
+ls -l # For debugging.
+test ! -e global.log
+test ! -e pass.log
+test ! -e fail.log
+test ! -e xfail.log
+test ! -e xpass.log
+test ! -e skip.log
+test ! -e error.log
+# "make clean" shouldn't remove unrelated log files.
+test -f error2.log
+test -f test-suite.log
+test -f my.log
+
+rm -f *.log
+
+:
diff --git a/t/tap-merge-stdout-stderr.sh b/t/tap-merge-stdout-stderr.sh
new file mode 100644
index 000000000..dc411cbc6
--- /dev/null
+++ b/t/tap-merge-stdout-stderr.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - The Automake TAP driver has an option that instruct it to read TAP
+# input also from the stderr of the test command, not only its stdout.
+
+. test-init.sh
+
+fetch_tap_driver
+
+cat > Makefile.am << 'END'
+AM_TEST_LOG_DRIVER_FLAGS = --comments --merge
+TESTS = all.test
+END
+
+. tap-setup.sh
+
+cat > all.test <<END
+#!/bin/sh
+echo 1..4
+echo ok 1 >&2
+echo ok 2
+echo "not ok 3 # TODO" >&2
+echo "ok 4 # SKIP"
+echo "# foo foo foo" >&2
+END
+chmod a+x all.test
+
+run_make -O check
+count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
+
+grep '^# all\.test: foo foo foo' stdout
+
+cat > all.test <<END
+#!/bin/sh
+echo 1..1
+echo ok 1
+echo 'Bail out!' >&2
+END
+
+run_make -O -e FAIL check
+count_test_results total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1
+
+# See that the option '--no-merge' can override the effect of '--merge'.
+
+run_make -O TEST_LOG_DRIVER_FLAGS=--no-merge check
+count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+:
diff --git a/t/tap-missing-plan-and-bad-exit.sh b/t/tap-missing-plan-and-bad-exit.sh
new file mode 100644
index 000000000..5a1d0f9e9
--- /dev/null
+++ b/t/tap-missing-plan-and-bad-exit.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - if a test script exits with non-zero status before printing the TAP
+# plan, then the driver reports both "missing plan" and "exited with
+# non-zero status" errors.
+
+. test-init.sh
+
+cat > foo.test <<END
+#!/bin/sh
+exit 123
+END
+
+echo TESTS = foo.test > Makefile.am
+
+chmod a+x foo.test
+
+. tap-setup.sh
+
+run_make -O -e FAIL check
+count_test_results total=2 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=2
+
+grep '^ERROR: foo\.test - exited with status 123$' stdout
+grep '^ERROR: foo\.test - missing test plan$' stdout
+
+:
diff --git a/t/tap-more.sh b/t/tap-more.sh
new file mode 100644
index 000000000..478868b5e
--- /dev/null
+++ b/t/tap-more.sh
@@ -0,0 +1,159 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# More on TAP support:
+# - more than one TAP-generating test script in $(TESTS)
+# - VPATH builds
+# - use with parallel make (if supported)
+# - basic use of diagnostic messages (lines beginning with "#")
+# - flags for TAP driver defined through AC_SUBST in configure.ac
+# - messages generated by the testsuite harness reference the
+# correct test script(s)
+# - "make distcheck" works
+
+. test-init.sh
+
+fetch_tap_driver
+
+cat >> configure.ac <<END
+AC_SUBST([AM_TEST_LOG_DRIVER_FLAGS], ['--comments'])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = $(srcdir)/tap-driver
+TESTS = 1.test 2.test 3.test
+EXTRA_DIST = $(TESTS) tap-driver
+END
+
+cat > 1.test <<'END'
+#! /bin/sh
+echo 1..2
+echo ok 1 - mu
+if test -f not-skip; then
+ echo "not ok 2 zardoz"
+else
+ echo "ok 2 zardoz # SKIP"
+fi
+END
+
+cat > 2.test <<'END'
+#! /bin/sh
+echo 1..3
+echo "ok"
+echo "not ok # TODO not implemented"
+echo "ok 3"
+END
+
+cat > 3.test <<END
+#! /bin/sh
+echo 1..1
+echo ok - blah blah blah
+echo '# Some diagnostic'
+if test -f bail-out; then
+ echo 'Bail out! Kernel Panic'
+else
+ :
+fi
+END
+
+chmod a+x [123].test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+# Try a VPATH and by default serial build first, and then an in-tree
+# and by default parallel build.
+for try in 0 1; do
+
+ if test $try -eq 0; then
+ # VPATH serial build.
+ mkdir build
+ cd build
+ srcdir=..
+ am_make=$MAKE
+ elif test $try -eq 1; then
+ # In-tree parallel build.
+ srcdir=.
+ case $MAKE in
+ *\ -j*)
+ # Degree of parallelism already specified by the user: do
+ # not override it.
+ :
+ ;;
+ *)
+ # Some make implementations (e.g., HP-UX) don't grok '-j',
+ # some require no space between '-j' and the number of jobs
+ # (e.g., older GNU make versions), and some *do* require a
+ # space between '-j' and the number of jobs (e.g., Solaris
+ # dmake). We need a runtime test to see what works.
+ echo 'all:' > Makefile
+ for am_make in "$MAKE -j3" "$MAKE -j 3" "$MAKE"; do
+ $am_make && break
+ done
+ rm -f Makefile
+ MAKE=$am_make
+ unset am_make
+ ;;
+ esac
+ else
+ fatal_ "internal error, invalid value of '$try' for \$try"
+ fi
+
+ $srcdir/configure
+ ls -l # For debugging.
+
+ # Success.
+
+ run_make -O check
+ count_test_results total=6 pass=4 fail=0 xpass=0 xfail=1 skip=1 error=0
+ grep '^PASS: 1\.test 1 - mu$' stdout
+ grep '^SKIP: 1\.test 2 zardoz # SKIP$' stdout
+ test $(grep -c '1\.test' stdout) -eq 2
+ grep '^PASS: 2\.test 1$' stdout
+ grep '^XFAIL: 2\.test 2 # TODO not implemented$' stdout
+ grep '^PASS: 2\.test 3$' stdout
+ test $(grep -c '2\.test' stdout) -eq 3
+ grep '^PASS: 3\.test 1 - blah blah blah$' stdout
+ grep '^# 3\.test: Some diagnostic$' stdout
+ test $(grep -c '3\.test' stdout) -eq 2
+
+ # Failure.
+
+ : > not-skip
+ : > bail-out
+ run_make -e FAIL -O check
+ count_test_results total=7 pass=4 fail=1 xpass=0 xfail=1 skip=0 error=1
+ grep '^PASS: 1\.test 1 - mu$' stdout
+ grep '^FAIL: 1\.test 2 zardoz$' stdout
+ test $(grep -c '1\.test' stdout) -eq 2
+ grep '^PASS: 2\.test 1$' stdout
+ grep '^XFAIL: 2\.test 2 # TODO not implemented$' stdout
+ grep '^PASS: 2\.test 3$' stdout
+ test $(grep -c '2\.test' stdout) -eq 3
+ grep '^PASS: 3\.test 1 - blah blah blah$' stdout
+ grep '^# 3\.test: Some diagnostic$' stdout
+ grep '^ERROR: 3\.test - Bail out! Kernel Panic$' stdout
+ test $(grep -c '3\.test' stdout) -eq 3
+
+ cd $srcdir
+
+done
+
+$MAKE distcheck
+
+:
diff --git a/t/tap-more2.sh b/t/tap-more2.sh
new file mode 100644
index 000000000..628545db6
--- /dev/null
+++ b/t/tap-more2.sh
@@ -0,0 +1,89 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# More on TAP support:
+# - more LOG_COMPILER at once for TAP tests
+# - binary programs in $(TESTS)
+# - interactions with 'check_*' variables
+
+required='cc native'
+. test-init.sh
+
+fetch_tap_driver
+
+cat >> configure.ac <<END
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_EXTENSIONS = .sh .tap
+
+tap_driver = $(srcdir)/tap-driver
+
+LOG_DRIVER = $(tap_driver)
+SH_LOG_DRIVER = $(tap_driver)
+TAP_LOG_DRIVER = $(tap_driver)
+
+TAP_LOG_COMPILER = cat
+SH_LOG_COMPILER = $(SHELL)
+LOG_COMPILER =
+
+EXTRA_DIST = baz.tap
+
+check_SCRIPTS = bar.sh
+bar.sh: Makefile
+ echo '#!/bin/sh' > $@-t
+ echo 'echo 1..1' >> $@-t
+ echo 'echo "not ok 1 # TODO"' >> $@-t
+ chmod a-w $@-t && mv -f $@-t $@
+CLEANFILES = bar.sh
+
+check_PROGRAMS = foo-test
+foo_test_SOURCES = foo.c
+
+TESTS = foo-test $(check_SCRIPTS) baz.tap
+
+EXTRA_DIST += tap-driver
+END
+
+cat > foo.c <<'END'
+#include <stdio.h>
+int main (void)
+{
+ printf ("1..1\n");
+ printf ("ok 1\n");
+ return 0;
+}
+END
+
+cat > baz.tap << 'END'
+1..1
+ok 1 # SKIP
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+for target in check distcheck; do
+ run_make -O $target
+ count_test_results total=3 pass=1 fail=0 xpass=0 xfail=1 skip=1 error=0
+done
+
+:
diff --git a/t/tap-msg0-bailout.sh b/t/tap-msg0-bailout.sh
new file mode 100644
index 000000000..ab661f7f1
--- /dev/null
+++ b/t/tap-msg0-bailout.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - literal strings "0" and "0.0" as a test description in the message
+# of a "plan with skip" TAP plan
+# generally true!
+
+. test-init.sh
+
+. tap-setup.sh
+
+echo 'Bail out! 0' > a.test
+echo 'Bail out! 0.0' > b.test
+
+run_make -O -e FAIL TESTS='a.test b.test' check
+count_test_results total=2 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=2
+
+grep '^ERROR: a.test - Bail out! 0$' stdout
+grep '^ERROR: b.test - Bail out! 0\.0$' stdout
+
+:
diff --git a/t/tap-msg0-directive.sh b/t/tap-msg0-directive.sh
new file mode 100644
index 000000000..8756c939e
--- /dev/null
+++ b/t/tap-msg0-directive.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - literal string "0" as a TODO or SKIP message
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test << 'END'
+1..3
+ok 1 # TODO 0
+not ok 2 # TODO 0
+ok 3 # SKIP 0
+END
+
+run_make -O -e FAIL check
+count_test_results total=3 pass=0 fail=0 xpass=1 xfail=1 skip=1 error=0
+
+grep '^XPASS: all\.test 1 # TODO 0$' stdout
+grep '^XFAIL: all\.test 2 # TODO 0$' stdout
+grep '^SKIP: all\.test 3 # SKIP 0$' stdout
+
+:
diff --git a/t/tap-msg0-misc.sh b/t/tap-msg0-misc.sh
new file mode 100644
index 000000000..76596b23b
--- /dev/null
+++ b/t/tap-msg0-misc.sh
@@ -0,0 +1,79 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - literal "0" and "0.0" in a test description and a TODO/SKIP message
+# at the same time
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test << 'END'
+1..14
+
+ok 1 0
+ok 2 0.0
+
+ok 3 0 # TODO 0
+ok 4 0.0 # TODO 0
+ok 5 0 # TODO 0.0
+ok 6 0.0 # TODO 0.0
+
+not ok 7 0 # TODO 0
+not ok 8 0.0 # TODO 0
+not ok 9 0 # TODO 0.0
+not ok 10 0.0 # TODO 0.0
+
+ok 11 0 # SKIP 0
+ok 12 0.0 # SKIP 0
+ok 13 0 # SKIP 0.0
+ok 14 0.0 # SKIP 0.0
+
+END
+
+run_make -O -e FAIL check
+count_test_results total=14 pass=2 fail=0 xpass=4 xfail=4 skip=4 error=0
+
+sed '/^ *$/d' > exp << 'END'
+
+PASS: all.test 1 0
+PASS: all.test 2 0.0
+
+XPASS: all.test 3 0 # TODO 0
+XPASS: all.test 4 0.0 # TODO 0
+XPASS: all.test 5 0 # TODO 0.0
+XPASS: all.test 6 0.0 # TODO 0.0
+
+XFAIL: all.test 7 0 # TODO 0
+XFAIL: all.test 8 0.0 # TODO 0
+XFAIL: all.test 9 0 # TODO 0.0
+XFAIL: all.test 10 0.0 # TODO 0.0
+
+SKIP: all.test 11 0 # SKIP 0
+SKIP: all.test 12 0.0 # SKIP 0
+SKIP: all.test 13 0 # SKIP 0.0
+SKIP: all.test 14 0.0 # SKIP 0.0
+
+END
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-msg0-planskip.sh b/t/tap-msg0-planskip.sh
new file mode 100644
index 000000000..aa5ebd28b
--- /dev/null
+++ b/t/tap-msg0-planskip.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - literal strings "0" and "0.0" as the reason of the skip in a "TAP
+# plan with skip" (i.e., "1..0 # SKIP ...").
+
+. test-init.sh
+
+. tap-setup.sh
+
+echo '1..0 # SKIP 0' > a.test
+echo '1..0 # SKIP 0.0' > b.test
+
+run_make -O TESTS='a.test b.test' check
+count_test_results total=2 pass=0 fail=0 xpass=0 xfail=0 skip=2 error=0
+
+grep '^SKIP: a.test - 0$' stdout
+grep '^SKIP: b.test - 0\.0$' stdout
+
+:
diff --git a/t/tap-msg0-result.sh b/t/tap-msg0-result.sh
new file mode 100644
index 000000000..317591c98
--- /dev/null
+++ b/t/tap-msg0-result.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - the string "0" as a test description
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test << 'END'
+1..10
+ok 1 0
+ok - 0
+not ok 3 0
+not ok - 0
+ok 5 0 # TODO
+ok - 0 # TODO
+not ok 7 0 # TODO
+not ok - 0 # TODO
+ok 9 0 # SKIP
+ok - 0 # SKIP
+END
+
+run_make -O -e FAIL check
+count_test_results total=10 pass=2 fail=2 xpass=2 xfail=2 skip=2 error=0
+
+cat > exp << 'END'
+PASS: all.test 1 0
+PASS: all.test 2 - 0
+FAIL: all.test 3 0
+FAIL: all.test 4 - 0
+XPASS: all.test 5 0 # TODO
+XPASS: all.test 6 - 0 # TODO
+XFAIL: all.test 7 0 # TODO
+XFAIL: all.test 8 - 0 # TODO
+SKIP: all.test 9 0 # SKIP
+SKIP: all.test 10 - 0 # SKIP
+END
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-negative-numbers.sh b/t/tap-negative-numbers.sh
new file mode 100644
index 000000000..b506c93cb
--- /dev/null
+++ b/t/tap-negative-numbers.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - don't spuriously recognize negative TAP result numbers, but correctly
+# interpret them as test descriptions instead
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<'END'
+1..7
+ok -1
+not ok -3
+ok -2 # SKIP
+not ok -5 # TODO
+ok -04 # TODO
+ok -121
+not ok -50000
+END
+
+run_make -O -e FAIL check
+count_test_results total=7 pass=2 fail=2 xpass=1 xfail=1 skip=1 error=0
+
+cat > exp <<'END'
+PASS: all.test 1 -1
+FAIL: all.test 2 -3
+SKIP: all.test 3 -2 # SKIP
+XFAIL: all.test 4 -5 # TODO
+XPASS: all.test 5 -04 # TODO
+PASS: all.test 6 -121
+FAIL: all.test 7 -50000
+END
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-no-disable-hard-error.sh b/t/tap-no-disable-hard-error.sh
new file mode 100644
index 000000000..1cd85561f
--- /dev/null
+++ b/t/tap-no-disable-hard-error.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - "Bail out!" magic and TAP parse errors are not disabled nor turned
+# into simple failures by the definition DISABLE_HARD_ERRORS.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+DISABLE_HARD_ERRORS = yes
+TEST_LOG_COMPILER = cat
+TESTS = bail.test few.test noplan.test
+END
+
+. tap-setup.sh
+
+cat > bail.test <<END
+1..1
+Bail out!
+END
+
+cat > few.test <<END
+1..1
+END
+
+cat > noplan.test <<END
+# nothing here
+END
+
+run_make -O -e FAIL check
+count_test_results total=3 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=3
+
+:
diff --git a/t/tap-no-merge-stdout-stderr.sh b/t/tap-no-merge-stdout-stderr.sh
new file mode 100644
index 000000000..cda4c3f7d
--- /dev/null
+++ b/t/tap-no-merge-stdout-stderr.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - By default, TAP input is only from the stdout (and not the stderr)
+# of the test command.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER_FLAGS = --comments
+TESTS = all.test
+END
+
+. tap-setup.sh
+
+cat > all.test <<END
+#!/bin/sh
+echo 1..2
+echo 'not ok' >&2
+echo 'not ok 1 # TODO' >&2
+echo 'ok 1'
+echo '# foo foo foo'
+echo '# bar bar bar' >&2
+echo 'ok 44 # TODO' >&2
+echo 'Bail out!' >&2
+echo 'ok 2 # SKIP'
+END
+
+chmod a+x all.test
+
+run_make -O check
+count_test_results total=2 pass=1 fail=0 xpass=0 xfail=0 skip=1 error=0
+
+$FGREP 'foo foo foo' stdout
+$FGREP 'bar bar bar' stdout && exit 1
+
+:
diff --git a/t/tap-no-spurious-numbers.sh b/t/tap-no-spurious-numbers.sh
new file mode 100644
index 000000000..9c6835e1b
--- /dev/null
+++ b/t/tap-no-spurious-numbers.sh
@@ -0,0 +1,98 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - we shouldn't spuriously recognize as TAP result numbers what it
+# not, even if it seems pretty close
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > prefixes <<'END'
+A
+a
+_
++
+-
+=
+/
+*
+.
+:
+,
+;
+$
+@
+%
+&
+#
+?
+!
+|
+\
+"
+`
+'
+(
+)
+[
+]
+{
+}
+<
+>
+END
+
+n=$(wc -l <prefixes)
+
+# See the loop below to understand this initialization.
+pass=$(($n * 3))
+fail=$pass
+skip=$(($pass - 3))
+xfail=$skip
+xpass=$xfail
+error=0
+total=$(($pass + $fail + $skip + $xfail + $xpass))
+
+echo 1..$total > all.test
+
+highno=1000
+
+for result in 'ok' 'not ok'; do
+ for spacing in "" " " "$tab"; do
+ subst="$result &$spacing$higno"
+ sed -e "s|.*|$subst|" prefixes
+ for directive in TODO SKIP; do
+ test "$result $directive" != "not ok SKIP" || continue
+ sed -e '/^#$/d' -e "s|.*|$subst # $directive|" prefixes
+ done
+ done
+done >> all.test
+
+cat all.test # For debugging.
+
+# Sanity checks.
+grep '#.*#' all.test \
+ && framework_failure_ "creating all.test"
+test $(wc -l <all.test) -lt $highno \
+ || framework_failure_ "creating all.test"
+
+run_make -O -e IGNORE check
+count_test_results total=$total pass=$pass fail=$fail skip=$skip \
+ xpass=$xpass xfail=$xfail error=$error
+
+:
diff --git a/t/tap-no-spurious-summary.sh b/t/tap-no-spurious-summary.sh
new file mode 100644
index 000000000..bdbdf808d
--- /dev/null
+++ b/t/tap-no-spurious-summary.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - ':test-results:' directives in test scripts' output doesn't
+# originate spurious results in the testsuite summary
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<'END'
+1..1
+:test-result: PASS
+:test-result: FAIL
+:test-result: XPASS
+:test-result: XFAIL
+:test-result: SKIP
+:test-result: ERROR
+:test-result: UNKNOWN
+ok 1
+END
+
+run_make -O check
+count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+for result in PASS FAIL XPASS XFAIL SKIP ERROR UNKNOWN; do
+ grep "^ *:test-result: $result$" all.log
+done
+
+:
diff --git a/t/tap-no-spurious.sh b/t/tap-no-spurious.sh
new file mode 100644
index 000000000..cb82022b5
--- /dev/null
+++ b/t/tap-no-spurious.sh
@@ -0,0 +1,111 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - don't spuriously recognize lines that are "almost" TAP lines as
+# real TAP lines
+
+. test-init.sh
+
+. tap-setup.sh
+
+echo 1..5 > all.test
+
+# The only recognized directives are "TODO" and "SKIP".
+# So the following should count as passed tests.
+cat >> all.test <<END
+ok 1 # XFAIL
+ok 2 # SKIPPED
+ok 3 # TO DO
+ok 4 # TODOALL
+ok 5 # FIXME
+END
+
+# According to documentation of Test::Harness::TAP(3):
+#
+# Lines written to standard output matching /^(not )?ok\b/
+# must be interpreted as test lines. All other lines must
+# not be considered test output.
+
+cat >> all.test <<END
+ ok
+ ok 1
+${tab}ok
+${tab}ok 1
+ not ok
+ not ok 1
+${tab}not ok
+${tab}not ok 1
+notok
+notok 1
+not${tab}ok
+not${tab}ok 1
+not ok
+not ok 1
+no ok
+no ok 1
+# ok
+# not ok
+# ok 1
+# not ok 1
+#ok
+#not ok
+#ok 1
+#not ok 1
+END
+
+set +x # Don't pollute logs too much.
+for r in 'ok' 'not ok'; do
+ for s1 in \
+ a b c d e f g h i j k l m n o p q r s t u v w x y z \
+ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
+ 0 1 2 3 4 5 6 7 8 9 _ ab 0a 23 a1B2c _o _x_y_
+ do
+ for s2 in '' @ % + - = / . : \; \* \? \& \! \# \$ \< \> \\; do
+ printf '%s\n' "$r$s1$s2"
+ done
+ done
+done >> all.test
+set -x # Reset shell xtraces.
+
+# The prove(1) utility doesn't bail out on these, so our driver
+# shouldn't either.
+# See comments in 'tap-bailout-leading-space.sh' for an explanation
+# of why we don't have a whitespace-prepended "Bail out!" line here.
+cat >> all.test <<'END'
+bailout
+bailout!
+bail out
+bail out!
+Bailout
+Bailout!
+Bail out
+ Bail out
+#Bail out!
+# Bail out!
+END
+
+
+# Debugging info and minor sanity check.
+cat all.test \
+ && test $(grep -c '^ok1$' all.test) -eq 1 \
+ && test $(grep -c '^not ok1$' all.test) -eq 1 \
+ || framework_failure_ "creating all.test"
+
+run_make -O check
+count_test_results total=5 pass=5 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+:
diff --git a/t/tap-not-ok-skip.sh b/t/tap-not-ok-skip.sh
new file mode 100644
index 000000000..535a546a2
--- /dev/null
+++ b/t/tap-not-ok-skip.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - a "not ok # SKIP" line should count as a failure, for consistency
+# with the prove(1) utility.
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<'END'
+1..4
+not ok # SKIP
+not ok 2 # SKIP
+not ok - foo # SKIP
+not ok 4 - bar # SKIP
+END
+
+run_make -O -e FAIL check
+count_test_results total=4 pass=0 fail=4 skip=0 xpass=0 xfail=0 error=0
+
+:
diff --git a/t/tap-number-wordboundary.sh b/t/tap-number-wordboundary.sh
new file mode 100644
index 000000000..3fc7940c4
--- /dev/null
+++ b/t/tap-number-wordboundary.sh
@@ -0,0 +1,105 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - TAP result numbers terminated by a non-whitespace "word boundary"
+# character are recognized
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<'END'
+1..5
+ok 1: foo1
+not ok 2- foo2
+ok 3@ foo3 # SKIP
+not ok 4?&%$ foo4 # TODO
+ok 5"`!! foo5 # TODO
+END
+
+run_make -O -e FAIL check
+count_test_results total=5 pass=1 fail=1 skip=1 xpass=1 xfail=1 error=0
+
+$EGREP '^PASS: all\.test 1 ?: foo1$' stdout
+$EGREP '^FAIL: all\.test 2 ?- foo2$' stdout
+$EGREP '^SKIP: all\.test 3 ?@ foo3 # SKIP$' stdout
+$EGREP '^XFAIL: all\.test 4 ?\?&%\$ foo4 # TODO$' stdout
+$EGREP '^XPASS: all\.test 5 ?"`!! foo5 # TODO$' stdout
+
+cat > all.test <<'END'
+1..3
+ok 2: quux
+not ok 1!
+ok 476$ # SKIP
+END
+
+run_make -O -e FAIL check
+count_test_results total=3 pass=0 fail=0 skip=0 xpass=0 xfail=0 error=3
+
+$EGREP '^ERROR: all\.test 2 ?: quux # OUT-OF-ORDER \(expecting 1\)$' stdout
+$EGREP '^ERROR: all\.test 1 ?! # OUT-OF-ORDER \(expecting 2\)$' stdout
+$EGREP '^ERROR: all\.test 476 ?\$ # OUT-OF-ORDER \(expecting 3\)$' stdout
+
+cat > punctuation <<'END'
+'
+"
+`
+#
+$
+!
+\
+/
+&
+%
+(
+)
+|
+^
+~
+?
+*
++
+-
+,
+:
+;
+=
+<
+>
+@
+[
+]
+{
+}
+\
+END
+
+# Strip any extra whitespace, for Solaris' wc.
+planned=$(wc -l <punctuation | tr -d " $tab")
+
+echo 1..$planned > all.test
+awk '{print "ok " NR $0 }' punctuation >> all.test
+# For debugging.
+cat all.test
+# Sanity check.
+grep "^ok 1'$" all.test || framework_failure_ "creating all.test"
+
+run_make -O check
+count_test_results total=$planned pass=$planned \
+ fail=0 skip=0 xpass=0 xfail=0 error=0
+
+:
diff --git a/t/tap-numbers-leading-zero.sh b/t/tap-numbers-leading-zero.sh
new file mode 100644
index 000000000..ffedd8788
--- /dev/null
+++ b/t/tap-numbers-leading-zero.sh
@@ -0,0 +1,107 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - how does TAP result numbers with leading zero fares?
+
+. test-init.sh
+
+. tap-setup.sh
+
+do_checks ()
+{
+ run_make -O -e FAIL check
+ count_test_results "$@"
+ # Allow some normalization of leading zeros, without forcing it.
+ LC_ALL=C sed -n 's/: all\.test 0*\([0-9]\)/: all.test \1/p' stdout > got
+ cat exp
+ cat got
+ diff exp got
+}
+
+cat > all.test <<END
+1..15
+
+ok 01
+ok 0002
+
+not ok 03
+not ok 0004
+
+ok 05 # SKIP
+ok 0006 # SKIP
+
+not ok 07 # TODO
+not ok 0008 # TODO
+
+ok 009
+ok 010
+
+ok 00000011
+not ok 0012
+ok 00000013 # SKIP
+not ok 0014 # TODO
+ok 00000015 # TODO
+END
+
+cat > exp <<END
+PASS: all.test 1
+PASS: all.test 2
+FAIL: all.test 3
+FAIL: all.test 4
+SKIP: all.test 5 # SKIP
+SKIP: all.test 6 # SKIP
+XFAIL: all.test 7 # TODO
+XFAIL: all.test 8 # TODO
+PASS: all.test 9
+PASS: all.test 10
+PASS: all.test 11
+FAIL: all.test 12
+SKIP: all.test 13 # SKIP
+XFAIL: all.test 14 # TODO
+XPASS: all.test 15 # TODO
+END
+
+do_checks total=15 pass=5 fail=3 xpass=1 xfail=3 skip=3 error=0
+
+cat > all.test <<END
+1..8
+
+ok 010
+not ok 003
+ok 0001 # SKIP
+not ok 010 # TODO
+ok 00100 # TODO
+
+ok 06
+ok 00007
+ok 8
+END
+
+cat > exp <<END
+ERROR: all.test 10 # OUT-OF-ORDER (expecting 1)
+ERROR: all.test 3 # OUT-OF-ORDER (expecting 2)
+ERROR: all.test 1 # OUT-OF-ORDER (expecting 3)
+ERROR: all.test 10 # OUT-OF-ORDER (expecting 4)
+ERROR: all.test 100 # OUT-OF-ORDER (expecting 5)
+PASS: all.test 6
+PASS: all.test 7
+PASS: all.test 8
+END
+
+do_checks total=8 pass=3 fail=0 xpass=0 xfail=0 skip=0 error=5
+
+:
diff --git a/t/tap-numeric-description.sh b/t/tap-numeric-description.sh
new file mode 100644
index 000000000..73f46b7c6
--- /dev/null
+++ b/t/tap-numeric-description.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP result lines whose description is a number.
+
+. test-init.sh
+
+. tap-setup.sh
+
+# Some random numbers to be used as test names. The definitions below are
+# selected so that $x<n> != <n> for every n >= 1. We can't use positional
+# parameters for this unfortunately, since Solaris 10 /bin/sh doesn't allow
+# the dereferencing of parameters from ${10} onwards.
+x1=5 x2=7 x3=45 x4=11 x5=7 x6=3 x7=6 x8=9 x9=1000 x10=1
+
+cat > all.test <<END
+1..10
+ok 1 ${x1}
+ok - ${x2}
+not ok 3 ${x3}
+not ok - ${x4}
+ok 5 ${x5} # SKIP
+ok - ${x6} # SKIP
+not ok 7 ${x7} # TODO
+not ok - ${x8} # TODO
+ok 9 ${x9} # TODO
+ok - ${x10} # TODO
+END
+
+cat > exp <<END
+PASS: all.test 1 ${x1}
+PASS: all.test 2 - ${x2}
+FAIL: all.test 3 ${x3}
+FAIL: all.test 4 - ${x4}
+SKIP: all.test 5 ${x5} # SKIP
+SKIP: all.test 6 - ${x6} # SKIP
+XFAIL: all.test 7 ${x7} # TODO
+XFAIL: all.test 8 - ${x8} # TODO
+XPASS: all.test 9 ${x9} # TODO
+XPASS: all.test 10 - ${x10} # TODO
+END
+
+run_make -O -e FAIL check
+count_test_results total=10 pass=2 fail=2 xpass=2 xfail=2 skip=2 error=0
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+
+:
diff --git a/t/tap-out-of-order.sh b/t/tap-out-of-order.sh
new file mode 100644
index 000000000..e44d4fd5e
--- /dev/null
+++ b/t/tap-out-of-order.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - out-of-order test results
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > a.test <<END
+1..3
+ok
+not ok 2 # TODO
+ok 71
+END
+
+cat > b.test <<END
+1..5
+ok 1
+ok 2
+ok 4 foo # SKIP mu
+not ok 2 bar # TODO um
+ok 5
+END
+
+cat > c.test <<END
+1..4
+ok 1
+ok foo
+ok 4 - zardoz
+not ok 3
+END
+
+# This is documented as an "test out of sequence" error in the
+# TAP::Parser documentation. Keep it in sync with the example
+# there.
+cat > d.test <<'END'
+1..5
+ok 1
+ok 2
+ok 15
+ok 16
+ok 17
+END
+
+run_make -O -e FAIL TESTS='a.test b.test c.test d.test' check
+count_test_results total=17 pass=8 fail=0 xpass=0 xfail=1 skip=0 error=8
+
+test $($FGREP -c ': a.test' stdout) -eq 3
+test $($FGREP -c ': b.test' stdout) -eq 5
+test $($FGREP -c ': c.test' stdout) -eq 4
+test $($FGREP -c ': d.test' stdout) -eq 5
+
+grep '^ERROR: a\.test 71 # OUT-OF-ORDER (expecting 3)$' stdout
+grep '^ERROR: b\.test 4 foo # OUT-OF-ORDER (expecting 3)$' stdout
+grep '^ERROR: b\.test 2 bar # OUT-OF-ORDER (expecting 4)$' stdout
+grep '^ERROR: c\.test 4 - zardoz # OUT-OF-ORDER (expecting 3)$' stdout
+grep '^ERROR: c\.test 3 # OUT-OF-ORDER (expecting 4)$' stdout
+grep '^ERROR: d\.test 15 # OUT-OF-ORDER (expecting 3)$' stdout
+grep '^ERROR: d\.test 16 # OUT-OF-ORDER (expecting 4)$' stdout
+grep '^ERROR: d\.test 17 # OUT-OF-ORDER (expecting 5)$' stdout
+
+:
diff --git a/t/tap-passthrough-exit.sh b/t/tap-passthrough-exit.sh
new file mode 100644
index 000000000..1a4dfdcf3
--- /dev/null
+++ b/t/tap-passthrough-exit.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - non-success exit status of a test script is reported in the
+# log file
+# See also related test 'tap-passthrough.sh'.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+TEST_LOG_COMPILER = $(SHELL)
+TESTS =
+END
+
+exit_statuses='1 2 77 99'
+
+for e in $exit_statuses; do
+ unindent > exit-$e.test <<END
+ #!/bin/sh
+ echo 1..1
+ echo ok 1
+ exit $e
+END
+ echo TESTS += exit-$e.test >> Makefile.am
+done
+
+. tap-setup.sh
+
+st=0
+$MAKE check || st=$?
+for e in $exit_statuses; do cat exit-$e.log; done
+cat test-suite.log
+test $st -gt 0 || exit 1
+
+for e in $exit_statuses; do
+ for log in exit-$e.log test-suite.log; do
+ grep "^ERROR: exit-$e\\.test - exited with status $e$" $log
+ done
+done
+
+run_make check TEST_LOG_DRIVER_FLAGS='--ignore-exit'
+$FGREP ".test - exited with status" *.log && exit 1
+
+:
diff --git a/t/tap-passthrough.sh b/t/tap-passthrough.sh
new file mode 100644
index 000000000..8daa45a5e
--- /dev/null
+++ b/t/tap-passthrough.sh
@@ -0,0 +1,165 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - all input (valid TAP lines, invalid TAP lines, non-TAP lines)
+# are passed through in the log file
+# - TAP errors are reported in the log file too
+# See also related test 'tap-passthrough-exit.sh'.
+
+. test-init.sh
+
+weirdchars=\''"\$@!&()[]<>#;,:.^?*/'
+
+. tap-setup.sh
+
+#
+# Only successful tests.
+#
+
+# The whitespace in this test might be normalized in the testsuite
+# progress output, but should be copied verbatim in the log files.
+cat > ok.test <<END
+1..6
+TAP plan in the previous line.
+ok${tab}
+ok 2
+ok - foo
+ok 4 - x
+ This is not a TAP line, but should still be copied in the log file!
+# some diagnostic${tab}
+not ok # TODO low priority
+ok # SKIP who cares?
+$weirdchars
+END
+
+run_make TESTS=ok.test check || { cat ok.log; exit 1; }
+cat ok.log
+
+for rx in \
+ '1\.\.6' \
+ 'TAP plan in the previous line\.' \
+ "ok${tab}" \
+ 'ok 2' \
+ 'ok - foo' \
+ 'ok 4 - x' \
+ ' This is not a TAP line, but should still be copied in the log file!' \
+ "# some diagnostic${tab}" \
+ 'not ok # TODO low priority' \
+ 'ok # SKIP who cares?' \
+; do
+ grep "^$rx$" ok.log
+done
+$FGREP "$weirdchars" ok.log
+
+#
+# Mixed failing/successful tests.
+#
+
+cat > tiny.test <<END
+1..1
+ok
+END
+
+cat > ok.test <<END
+1..1
+ok
+only one success here
+END
+
+cat > ko.test <<END
+1..5
+foo foo foo
+ok${tab}
+ok 2
+not ok - foo
+not ok 4 - x
+# diagnostic ko
+ bar${tab}bar${tab}bar
+ok # TODO dunno
+$weirdchars
+END
+
+cat > bail.test <<END
+Bail out! Test is taking too long!
+END
+
+cat > skip.test <<END
+1..0 # Skipped: WWW::Mechanize not installed
+END
+
+cat > err.test <<END
+1..3
+ok 1
+Invalid test count
+ok 23
+Misplaced plan
+1..13
+ok
+Extra test
+ok
+Last line
+END
+
+st=0
+run_make check \
+ TESTS='tiny.test ok.test ko.test bail.test skip.test err.test' || st=$?
+cat tiny.log
+cat ok.log
+cat ko.log
+cat bail.log
+cat skip.log
+cat err.log
+test $st -gt 0 || exit 1
+
+grep '^1\.\.1$' tiny.log
+grep '^ok$' tiny.log
+grep '^only one success here$' ok.log
+
+for rx in \
+ '1\.\.5' \
+ 'foo foo foo' \
+ "ok${tab}" \
+ 'ok 2' \
+ 'not ok - foo' \
+ 'not ok 4 - x' \
+ '# diagnostic ko' \
+ " bar${tab}bar${tab}bar" \
+ 'ok # TODO dunno' \
+; do
+ grep "^$rx$" ko.log
+done
+$FGREP "$weirdchars" ko.log
+
+grep '^Bail out! Test is taking too long!$' bail.log
+grep '^1\.\.0 # Skipped: WWW::Mechanize not installed$' skip.log
+
+for rx in \
+ '^1\.\.3$' \
+ '^Invalid test count$' \
+ '^ok 23$' \
+ '^Misplaced plan$' \
+ '^1\.\.13$' \
+ '^ERROR:.* multiple test plans' \
+ '^Extra test$' \
+ '^Last line$' \
+ '^ERROR:.* [tT]oo many tests run.*expected 3, got 4' \
+ '^ERROR:.* err\.test 23 .*OUT[ -]OF[ -]ORDER.*expecting 2' \
+; do
+ grep "$rx" err.log
+done
+
+:
diff --git a/t/tap-plan-corner.sh b/t/tap-plan-corner.sh
new file mode 100644
index 000000000..966f04d8c
--- /dev/null
+++ b/t/tap-plan-corner.sh
@@ -0,0 +1,189 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - some corner cases for TAP plan
+
+. test-init.sh
+
+. tap-setup.sh
+
+# -------------------------------------------------------------------------
+
+cat > leading-repeated.test <<END
+1..1
+1..1
+ok 1
+END
+
+cat > trailing-repeated.test <<END
+ok 1
+1..1
+1..1
+END
+
+for pos in leading trailing; do
+ run_make -O -e FAIL TESTS="$pos-repeated.test" check
+ count_test_results total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1
+ grep "^ERROR: $pos-repeated\\.test - multiple test plans$" stdout
+done
+
+# -------------------------------------------------------------------------
+
+cat > leading-repeated.test <<END
+1..2
+ok 1
+1..2
+ok 2
+END
+
+cat > trailing-repeated.test <<END
+ok 1
+1..2
+ok 2
+1..2
+END
+
+run_make -O -e FAIL check \
+ TESTS='leading-repeated.test trailing-repeated.test'
+count_test_results total=6 pass=3 fail=0 xpass=0 xfail=0 skip=0 error=3
+grep "^ERROR: leading-repeated\\.test - multiple test plans$" stdout
+grep "^ERROR: trailing-repeated\\.test - multiple test plans$" stdout
+grep "^ERROR: trailing-repeated\\.test 2 # AFTER LATE PLAN$" stdout
+grep "leading .*AFTER LATE PLAN" stdout && exit 1
+
+# -------------------------------------------------------------------------
+
+cat > 1.test <<END
+1..0
+1..0
+END
+
+cat > 2.test <<END
+1..0 # SKIP
+1..0
+END
+
+cat > 3.test <<END
+1..0
+1..0 # SKIP
+END
+
+cat > 4.test <<END
+1..0 # SKIP
+1..0 # SKIP
+END
+
+run_make -O -e FAIL check TESTS='1.test 2.test 3.test 4.test'
+count_test_results total=8 pass=0 fail=0 xpass=0 xfail=0 skip=4 error=4
+for i in 1 2 3 4; do
+ grep "^ERROR: $i\\.test - multiple test plans$" stdout
+done
+
+# -------------------------------------------------------------------------
+
+cat > all.test <<END
+1..5
+ok 1
+ok 2
+1..5
+ok 3
+1..5
+ok 4
+1..5
+ok 5
+END
+
+run_make -O -e FAIL check
+count_test_results total=8 pass=5 fail=0 xpass=0 xfail=0 skip=0 error=3
+
+cat > exp <<'END'
+PASS: all.test 1
+PASS: all.test 2
+ERROR: all.test - multiple test plans
+PASS: all.test 3
+ERROR: all.test - multiple test plans
+PASS: all.test 4
+ERROR: all.test - multiple test plans
+PASS: all.test 5
+END
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+# -------------------------------------------------------------------------
+
+cat > all.test <<END
+1..2
+ok 1
+ok 2
+1..3
+ok 3
+END
+
+run_make -O -e FAIL check
+count_test_results total=5 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=3
+
+cat > exp <<'END'
+PASS: all.test 1
+PASS: all.test 2
+ERROR: all.test - multiple test plans
+ERROR: all.test 3 # UNPLANNED
+ERROR: all.test - too many tests run (expected 2, got 3)
+END
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+# -------------------------------------------------------------------------
+
+cat > all.test <<END
+ok 1
+ok 2
+ok 3
+1..5
+1..5
+ok 4
+1..5
+ok 5
+END
+
+run_make -O -e FAIL check
+count_test_results total=7 pass=3 fail=0 xpass=0 xfail=0 skip=0 error=4
+
+cat > exp <<'END'
+PASS: all.test 1
+PASS: all.test 2
+PASS: all.test 3
+ERROR: all.test - multiple test plans
+ERROR: all.test 4 # AFTER LATE PLAN
+ERROR: all.test - multiple test plans
+ERROR: all.test 5 # AFTER LATE PLAN
+END
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-plan-errors.sh b/t/tap-plan-errors.sh
new file mode 100644
index 000000000..46ab17b1f
--- /dev/null
+++ b/t/tap-plan-errors.sh
@@ -0,0 +1,112 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support: the following situations should be flagged as errors:
+# - unmatched test plan (too few tests run)
+# - multiple test plans
+# - missing test plan
+# - misplaced test plan (tests run after a late plan)
+# Checks about unplanned tests are performed in 'tap-unplanned.sh'
+# and 'tap-skip-whole-badcount.sh'. More checks about corner-cases
+# in TAP plans are performed in 'tap-plan-corner.sh'.
+
+. test-init.sh
+
+. tap-setup.sh
+
+my_check ()
+{
+ cat > all.test
+ test -n "$err" || fatal_ "\$err not set before calling my_check"
+ cat all.test # For debugging.
+ run_make -O -e FAIL check
+ count_test_results "$@"
+ grep "^ERROR: all\\.test $err$" stdout
+ unset err
+}
+
+err='- too few tests run (expected 2, got 1)'
+my_check total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
+1..2
+ok 1
+END
+
+err='- too few tests run (expected 12, got 3)'
+my_check total=4 pass=2 fail=0 xpass=0 xfail=1 skip=0 error=1 <<END
+ok 1
+ok 2
+not ok 3 # TODO
+1..12
+END
+
+err='- too few tests run (expected 1, got 0)'
+my_check total=1 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
+1..1
+END
+
+err='2 # AFTER LATE PLAN'
+my_check total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
+ok 1
+1..2
+ok 2
+END
+
+err='5 # AFTER LATE PLAN'
+my_check total=5 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
+ok 1
+ok 2
+ok 3
+ok 4
+1..5
+ok 5
+END
+
+err='- missing test plan'
+my_check total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
+ok 1
+END
+
+
+# The two test plans here are deliberately equal.
+err='- multiple test plans'
+my_check total=3 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
+1..2
+ok 1
+ok 2
+1..2
+END
+
+# The second plan is diagnosed as extra, and only the first one is
+# relevant w.r.t. the number of the expected test.
+err='- multiple test plans'
+my_check total=4 pass=3 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
+1..3
+ok 1
+ok 2
+1..2
+ok 3
+END
+
+# As above, in a slightly different situation.
+err='- multiple test plans'
+my_check total=3 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
+1..2
+ok 1
+ok 2
+1..4
+END
+
+:
diff --git a/t/tap-plan-leading-zero.sh b/t/tap-plan-leading-zero.sh
new file mode 100644
index 000000000..c13e19ca5
--- /dev/null
+++ b/t/tap-plan-leading-zero.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - TAP plans with numbers having leading zeroes, as in "1..01"
+# - TAP "SKIP" plans with multiple zeroes, as in "1..00 # SKIP"
+# This is consistent with the behaviour of the 'prove' utility.
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > a.test <<END
+1..01
+ok 1
+END
+
+cat > b.test <<END
+1..0002
+ok 1
+ok 2
+END
+
+echo 1..010 > c.test
+for i in 1 2 3 4 5 6 7 8 9 10; do echo ok $i; done >> c.test
+
+echo 1..00100 > d.test
+for i in 1 2 3 4 5 6 7 8 9 10; do
+ for j in 1 2 3 4 5 6 7 8 9 10; do
+ echo ok
+ done
+done >> d.test
+
+echo 1..00 > e.test
+echo '1..000 # SKIP' > f.test
+
+run_make -O TESTS='a.test b.test c.test d.test e.test f.test' check
+count_test_results total=115 pass=113 xfail=0 skip=2 fail=0 xpass=0 error=0
+
+:
diff --git a/t/tap-plan-malformed.sh b/t/tap-plan-malformed.sh
new file mode 100644
index 000000000..efe53578e
--- /dev/null
+++ b/t/tap-plan-malformed.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support: a malformed TAP plan is not recognized. The checks in
+# here should be consistent with the behaviour of the 'prove' utility.
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > a.test <<END
+1..1 foo
+END
+
+cat > b.test <<END
+ 1..2
+ok 1
+ok 2
+END
+
+cat > c.test <<END
+1..1 # SKIP
+END
+
+cat > d.test <<END
+1..2 # foo bar
+not ok 1 # TODO
+not ok 2 # TODO
+END
+
+cat > e.test <<END
+0..0
+END
+
+tests_list=$(echo *.test)
+
+run_make -O -e FAIL TESTS="$tests_list" check
+count_test_results total=9 pass=2 fail=0 xpass=0 xfail=2 skip=0 error=5
+
+for tst in $tests_list; do
+ grep "^ERROR: $tst - missing test plan$" stdout
+done
+
+:
diff --git a/t/tap-plan-middle.sh b/t/tap-plan-middle.sh
new file mode 100644
index 000000000..97c95f34f
--- /dev/null
+++ b/t/tap-plan-middle.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - test plan preceding and/or following non-result TAP lines
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > top1.test <<END
+non-TAP line, ignored
+1..1
+ok 1
+END
+
+cat > top2.test <<END
+some
+non-TAP
+lines
+are
+ignored
+# and a TAP comment won't cause problems either
+1..2
+ok 1
+ok 2
+END
+
+# Try with a blank line too, just to be sure.
+cat > top3.test <<END
+
+1..1
+ok 1
+END
+
+cat > bot1.test <<END
+ok 1 # SKIP
+1..1
+bla blah blah ...
+END
+
+cat > bot2.test <<END
+ok 1
+ok 2
+not ok 3 # TODO
+1..3
+#@$%! (a cursing comment :-)
+END
+
+# Try with a blank line too, just to be sure.
+cat > bot3.test <<END
+ok 1
+not ok 2 # TODO
+ok 3 # SKIP
+ok 4 # SKIP
+1..4
+
+END
+
+tests=$(echo *.test)
+
+for tap_flags in "" "--comments"; do
+ run_make -O TEST_LOG_DRIVER_FLAGS="$tap_flags" TESTS="$tests" check
+ count_test_results total=12 pass=7 xfail=2 skip=3 fail=0 xpass=0 error=0
+done
+
+:
diff --git a/t/tap-plan-whitespace.sh b/t/tap-plan-whitespace.sh
new file mode 100644
index 000000000..d168d9420
--- /dev/null
+++ b/t/tap-plan-whitespace.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - plan line with trailing whitespace is recognized and handled correctly
+
+. test-init.sh
+
+. tap-setup.sh
+
+sed 's/\$$//' > foo.test <<END
+1..2 $
+ok 1$
+ok 2$
+END
+
+cat > bar.test <<END
+1..1$tab $tab$tab
+ok 1
+END
+
+run_make -O TESTS='foo.test bar.test' check
+count_test_results total=3 pass=3 fail=0 error=0 xpass=0 xfail=0 skip=0
+
+:
diff --git a/t/tap-plan.sh b/t/tap-plan.sh
new file mode 100644
index 000000000..c86ef6fa9
--- /dev/null
+++ b/t/tap-plan.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - test scripts with the test plan at the beginning
+# - test scripts with the test plan at the end
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > top.test <<END
+1..3
+ok 1
+ok 2 # SKIP
+ok 3
+# a trailing comment
+END
+
+cat > bot.test <<END
+ok 1
+# a comment
+ok 2
+not ok 3 # TODO
+# another comment
+ok
+1..4
+END
+
+for tap_flags in "" "--comments"; do
+ run_make -O check \
+ TESTS='top.test bot.test' \
+ TEST_LOG_DRIVER_FLAGS="$tap_flags"
+ count_test_results total=7 pass=5 xfail=1 skip=1 fail=0 xpass=0 error=0
+done
+
+
+:
diff --git a/t/tap-planskip-and-logging.sh b/t/tap-planskip-and-logging.sh
new file mode 100644
index 000000000..0db7bf0f1
--- /dev/null
+++ b/t/tap-planskip-and-logging.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - interactions between "TAP plan with SKIP" and logging of earlier or
+# later TAP or non-TAP text
+
+. test-init.sh
+
+. tap-setup.sh
+
+echo TEST_LOG_DRIVER_FLAGS = --comments >> Makefile
+
+cat > foo.test <<END
+1..0
+a non-TAP line
+# a comment
+END
+
+cat > foo2.test <<END
+a non-TAP line 2
+# a comment 2
+1..0
+END
+
+cat > bar.test <<END
+# an early comment
+an early non-TAP line
+ $tab
+1..0 # SKIP
+# a later comment
+a later non-TAP line
+END
+
+run_make -O TESTS='foo.test foo2.test bar.test' check
+count_test_results total=3 pass=0 fail=0 xpass=0 xfail=0 skip=3 error=0
+
+grep '^# foo\.test: a comment$' stdout
+grep '^# foo2\.test: a comment 2$' stdout
+grep '^# bar\.test: an early comment$' stdout
+grep '^# bar\.test: a later comment$' stdout
+
+cat foo.log
+cat foo2.log
+cat bar.log
+
+grep '^a non-TAP line$' foo.log
+grep '^# a comment$' foo.log
+grep '^a non-TAP line 2$' foo2.log
+grep '^# a comment 2$' foo2.log
+grep '^# an early comment' bar.log
+grep '^an early non-TAP line$' bar.log
+grep '^# a later comment' bar.log
+grep '^a later non-TAP line$' bar.log
+grep "^ $tab$" bar.log
+
+:
diff --git a/t/tap-planskip-badexit.sh b/t/tap-planskip-badexit.sh
new file mode 100644
index 000000000..f2cafeafd
--- /dev/null
+++ b/t/tap-planskip-badexit.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - an exit status != 0 of a test script causes an hard error, even if
+# the last line of output is a "SKIP plan" (e.g., "1..0 # SKIP").
+
+. test-init.sh
+
+echo TESTS = one.test two.test > Makefile.am
+
+. tap-setup.sh
+
+cat > one.test <<'END'
+#!/bin/sh
+echo '1..0 # SKIP'
+exit 1
+END
+
+cat > two.test <<'END'
+#!/bin/sh
+echo '1..0'
+exit 22
+END
+
+chmod a+x one.test two.test
+
+run_make -O -e FAIL check
+
+# The 'prove' utility reports both the skip and the non-zero exit status,
+# so we do the same.
+count_test_results total=4 pass=0 fail=0 xpass=0 xfail=0 skip=2 error=2
+
+grep '^ERROR: one\.test - exited with status 1$' stdout
+grep '^ERROR: two\.test - exited with status 22$' stdout
+
+:
diff --git a/t/tap-planskip-bailout.sh b/t/tap-planskip-bailout.sh
new file mode 100644
index 000000000..9cb1a6a33
--- /dev/null
+++ b/t/tap-planskip-bailout.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - a "Bail out!" directive causes an hard error, even if coming after
+# a "SKIP plan" (e.g., "1..0 # SKIP").
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<END
+1..0 # SKIP
+Bail out!
+END
+
+run_make -O -e FAIL check
+count_test_results total=2 pass=0 fail=0 xpass=0 xfail=0 skip=1 error=1
+grep '^ERROR: all\.test - Bail out!' stdout
+
+:
diff --git a/t/tap-planskip-case-insensitive.sh b/t/tap-planskip-case-insensitive.sh
new file mode 100644
index 000000000..b5b57d801
--- /dev/null
+++ b/t/tap-planskip-case-insensitive.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - "SKIP" keyword in a TAP plan is case-insensitive
+
+. test-init.sh
+
+. tap-setup.sh
+
+# These nested loops below are clearer without indentation.
+i=0
+for c1 in s S; do
+for c2 in k K; do
+for c3 in i I; do
+for c4 in p P; do
+ i=$(($i + 1))
+ case $i in ?) j=0$i;; *) j=$i;; esac
+ echo "1..0 # $c1$c2$c3$c4 foobar" > $j.test
+done; done; done; done
+
+run_make -O TESTS="$(echo *.test)" check
+count_test_results total=16 pass=0 fail=0 xpass=0 xfail=0 skip=16 error=0
+
+for tst in *.test; do
+ grep "^SKIP: $tst .* foobar$" stdout
+done
+
+:
diff --git a/t/tap-planskip-late.sh b/t/tap-planskip-late.sh
new file mode 100644
index 000000000..752f3c0ab
--- /dev/null
+++ b/t/tap-planskip-late.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - the special "plan with SKIP" can also be used "late" in the TAP
+# stream, i.e., preceded by non-TAP output or TAP diagnostic.
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > foo.test <<END
+some non-TAP text, will be copied in the global log
+1..0 # SKIP from the last line
+END
+
+cat > bar.test <<END
+# some TAP diagnostic, will go to console
+1..0
+END
+
+run_make -O TESTS='foo.test bar.test' check
+
+grep '^SKIP: foo\.test .* from the last line$' stdout
+grep '^SKIP: bar\.test$' stdout
+test $(grep -c ': .*\.test' stdout) -eq 2
+count_test_results total=2 pass=0 fail=0 xpass=0 xfail=0 skip=2 error=0
+
+:
diff --git a/t/tap-planskip-later-errors.sh b/t/tap-planskip-later-errors.sh
new file mode 100644
index 000000000..16454f6b4
--- /dev/null
+++ b/t/tap-planskip-later-errors.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - TAP errors following a "TAP plan with SKIP" are still diagnosed.
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<END
+1..0
+a non-TAP line
+1..3
+1..5
+# a comment
+1..1
+END
+
+run_make -O -e FAIL check
+count_test_results total=4 pass=0 fail=0 xpass=0 xfail=0 skip=1 error=3
+test $(grep -c '^ERROR: all\.test - multiple test plans' stdout) -eq 3
+
+:
diff --git a/t/tap-planskip-unplanned-corner.sh b/t/tap-planskip-unplanned-corner.sh
new file mode 100644
index 000000000..7cf03d4fe
--- /dev/null
+++ b/t/tap-planskip-unplanned-corner.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - test results seen in a TAP stream that has a "plan with SKIP" are
+# flagged as errors, even if all of them are "SKIP" results.
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > foo.test <<END
+1..0 # SKIP
+ok 1 # SKIP
+END
+
+cat > bar.test <<END
+ok 1 # SKIP
+1..0 # SKIP
+END
+
+run_make -O -e FAIL TESTS='foo.test bar.test' check
+count_test_results total=5 pass=0 fail=0 xpass=0 xfail=0 skip=2 error=3
+
+# Don't be too strict w.r.t. the format of the "skip whole test" message.
+grep '^SKIP: foo\.test$' stdout || grep '^SKIP: foo\.test [^0-9]' stdout
+grep '^ERROR: foo\.test 1 # UNPLANNED$' stdout
+grep '^ERROR: foo\.test - too many tests run (expected 0, got 1)$' stdout
+grep '^SKIP: bar\.test 1 # SKIP$' stdout
+grep '^ERROR: bar\.test - too many tests run (expected 0, got 1)$' stdout
+
+:
diff --git a/t/tap-planskip-unplanned.sh b/t/tap-planskip-unplanned.sh
new file mode 100644
index 000000000..a500dff4d
--- /dev/null
+++ b/t/tap-planskip-unplanned.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - a "plan with skip" given after one or more test result have already
+# been seen is an error
+# - any test result following a "plan with skip" is an error.
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<END
+ok 1
+1..0 # SKIP too late
+END
+run_make -O -e FAIL check
+count_test_results total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1
+grep '^ERROR: all\.test - too many tests run (expected 0, got 1)$' stdout
+
+cat > all.test <<END
+ok 1
+ok 2 # SKIP
+not ok 3 # TODO
+1..0 # SKIP too late
+END
+run_make -O -e FAIL check
+count_test_results total=4 pass=1 fail=0 xpass=0 xfail=1 skip=1 error=1
+grep '^ERROR: all\.test - too many tests run (expected 0, got 3)$' stdout
+
+cat > all.test <<END
+1..0 # SKIP falsified later
+ok 1
+END
+run_make -O -e FAIL check
+count_test_results total=3 pass=0 fail=0 xpass=0 xfail=0 skip=1 error=2
+grep '^ERROR: all\.test 1 # UNPLANNED$' stdout
+grep '^ERROR: all\.test - too many tests run (expected 0, got 1)$' stdout
+
+cat > all.test <<END
+1..0 # SKIP falsified later
+ok 1
+ok 2 # SKIP
+not ok 3
+not ok 4 # TODO
+END
+run_make -O -e FAIL check
+count_test_results total=6 pass=0 fail=0 xpass=0 xfail=0 skip=1 error=5
+grep '^ERROR: all\.test 1 # UNPLANNED$' stdout
+grep '^ERROR: all\.test 2 # UNPLANNED$' stdout
+grep '^ERROR: all\.test 3 # UNPLANNED$' stdout
+grep '^ERROR: all\.test 4 # UNPLANNED$' stdout
+grep '^ERROR: all\.test - too many tests run (expected 0, got 4)$' stdout
+
+:
diff --git a/t/tap-planskip-whitespace.sh b/t/tap-planskip-whitespace.sh
new file mode 100644
index 000000000..3a28c18a6
--- /dev/null
+++ b/t/tap-planskip-whitespace.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - normalization of whitespace in console testsuite progress associated
+# with a SKIP directive in the TAP plan
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > foo.test <<END
+1..0${tab}${tab} #${tab}SKIP ${tab}Strip leading & trailing ${tab}${tab}
+END
+
+cat > bar.test <<END
+1..0 #SKIP Preserve ${tab} middle${tab}${tab}space
+END
+
+cat > baz.test <<END
+1..0 # SKIP${tab} Strip${tab}external preserve ${tab}middle ${tab}${sp}
+END
+
+run_make -O TESTS='foo.test bar.test baz.test' check
+count_test_results total=3 pass=0 fail=0 error=0 xpass=0 xfail=0 skip=3
+
+grep "SKIP: foo\\.test - Strip leading & trailing$" stdout
+grep "SKIP: bar\\.test - Preserve ${tab} middle${tab}${tab}space" stdout
+grep "SKIP: baz\\.test - Strip${tab}external preserve ${tab}middle" stdout
+
+:
diff --git a/t/tap-planskip.sh b/t/tap-planskip.sh
new file mode 100644
index 000000000..1440c5310
--- /dev/null
+++ b/t/tap-planskip.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic TAP test protocol support:
+# - special plan format to skip all the tests in a script
+
+. test-init.sh
+
+. tap-setup.sh
+
+weirdchars=\''"$!&()[]<>#;^?*/@%=,.:'
+
+cat > foo.test <<END
+1..0
+END
+
+cat > bar.test <<END
+blah
+# blah
+1..0$tab $tab
+END
+
+# It is undefined whether the comment after the plan below should
+# count as an explanation; still, the test should be skipped.
+cat > baz.test <<END
+1..0 # WWW::Mechanize not installed
+other
+ junk
+ lines
+END
+
+cat > wget.test <<END
+1..0 # SKIP wget(1) not installed
+# See also curl.test
+END
+
+cat > curl.test <<END
+1..0 # SKIP: Can't connect to gnu.org!
+# See also wget.test
+END
+
+cat > mu.test <<END
+1..0 # SKIP $weirdchars
+END
+
+run_make -O check \
+ TESTS='foo.test bar.test baz.test wget.test curl.test mu.test'
+count_test_results total=6 pass=0 fail=0 xpass=0 xfail=0 skip=6 error=0
+
+# Look for a regression where the "1..0" wasn't being stripped from the
+# SKIP message.
+$FGREP '1..0' stdout && exit 1
+
+grep '^SKIP: foo\.test$' stdout
+grep '^SKIP: bar\.test$' stdout
+grep '^SKIP: baz\.test' stdout # Deliberately laxer, see above for why.
+grep '^SKIP: wget\.test .* wget(1) not installed$' stdout
+grep '^SKIP: curl\.test .* Can'\''t connect to gnu\.org!$' stdout
+grep '^SKIP: mu\.test' stdout | $FGREP "$weirdchars" stdout
+test $(grep -c ': .*\.test' stdout) -eq 6
+
+:
diff --git a/t/tap-recheck-logs.sh b/t/tap-recheck-logs.sh
new file mode 100644
index 000000000..c5039f435
--- /dev/null
+++ b/t/tap-recheck-logs.sh
@@ -0,0 +1,113 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - RECHECK_LOGS
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+TEST_LOG_COMPILER = cat
+TESTS = foo.test bar.test baz.test
+baz.log: zardoz
+END
+
+. tap-setup.sh
+
+: > zardoz
+
+cat > foo.test <<'END'
+1..2
+ok 1
+ok 2
+END
+
+cat > bar.test <<'END'
+1..1
+not ok 1
+END
+
+cat > baz.test <<'END'
+1..1
+Bail out!
+END
+
+# Even the tests that are not re-run should contribute to the testsuite
+# summary when obtained by "make check RECHECK_LOGS=".
+grep_summary ()
+{
+ grep '^# TOTAL: *4$' stdout
+ grep '^# PASS: *2$' stdout
+ grep '^# XPASS: *0$' stdout
+ grep '^# FAIL: *1$' stdout
+ grep '^# XFAIL: *0$' stdout
+ grep '^# SKIP: *0$' stdout
+ grep '^# ERROR: *1$' stdout
+}
+
+run_make -e FAIL check
+test -f foo.log
+test -f bar.log
+test -f baz.log
+
+rm -f foo.log bar.log
+
+run_make -O -e FAIL check RECHECK_LOGS=
+test -f foo.log
+test -f bar.log
+grep '^PASS: foo\.test 1$' stdout
+grep '^PASS: foo\.test 2$' stdout
+grep '^FAIL: bar\.test 1$' stdout
+grep 'baz\.test' stdout && exit 1
+grep_summary
+
+$sleep
+touch foo.test
+# We re-run only a successful test, but the tests that failed in the
+# previous run should still be taken into account, and cause an overall
+# failure.
+run_make -O -e FAIL check RECHECK_LOGS=
+grep '^PASS: foo\.test 1$' stdout
+grep '^PASS: foo\.test 2$' stdout
+grep 'ba[rz]\.test' stdout && exit 1
+is_newest foo.log foo.test
+grep_summary
+
+$sleep
+touch zardoz
+run_make -O -e FAIL check RECHECK_LOGS=
+grep '^ERROR: baz\.test' stdout
+$EGREP '(foo|bar)\.test' stdout && exit 1
+is_newest baz.log zardoz
+grep_summary
+
+# Now, explicitly retry with all test logs already updated, and ensure
+# that the summary is still displayed.
+run_make -O -e FAIL check RECHECK_LOGS=
+$EGREP '(foo|bar|baz)\.test' stdout && exit 1
+grep_summary
+
+# The following should re-run foo.test (and only foo.test), even if its
+# log file is up-to-date.
+: > older
+run_make -O -e FAIL check RECHECK_LOGS=foo.log
+grep '^PASS: foo\.test 1$' stdout
+grep '^PASS: foo\.test 2$' stdout
+grep 'ba[rz]\.test' stdout && exit 1
+is_newest foo.log older
+grep_summary
+
+:
diff --git a/t/tap-recheck.sh b/t/tap-recheck.sh
new file mode 100644
index 000000000..005b75d34
--- /dev/null
+++ b/t/tap-recheck.sh
@@ -0,0 +1,220 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test the 'recheck' target for TAP test protocol.
+# Keep in sync with 'test-driver-custom-multitest-recheck.sh'.
+
+. test-init.sh
+
+fetch_tap_driver
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = $(srcdir)/tap-driver
+TESTS = a.test b.test c.test d.test
+END
+
+cat > a.test << 'END'
+#! /bin/sh
+echo 1..2
+echo ok 1
+echo ok 2
+: > a.run
+END
+
+cat > b.test << 'END'
+#! /bin/sh
+: > b.run
+echo 1..2
+echo ok 1
+if test -f b.ok; then
+ echo ok 2
+else
+ echo 'Bail out!'
+fi
+END
+
+cat > c.test << 'END'
+#! /bin/sh
+echo 1..3
+if test -f c.pass; then
+ echo 'ok - c is ok :-)'
+else
+ echo 'not ok - c is ko :-('
+fi
+if test -f c.xfail; then
+ echo 'not ok 2 # TODO'
+else
+ echo 'ok 2 # TODO'
+fi
+echo 'not ok 3 - blah blah # TODO need better diagnostic'
+: > c.run
+END
+
+cat > d.test << 'END'
+#! /bin/sh
+test -f ./d.count && . ./d.count
+echo 1..${test_count-2}
+echo ok 1 '# SKIP: who cares ...'
+(. ./d.extra) || echo 'not ok 2 - d.extra failed'
+: > d.run
+END
+
+chmod a+x *.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+do_recheck ()
+{
+ case $* in
+ --fail) status=FAIL;;
+ --pass) status=0;;
+ *) fatal_ "invalid usage of function 'do_recheck'";;
+ esac
+ rm -f *.run
+ run_make -O -e $status recheck || { ls -l; exit 1; }
+ ls -l
+}
+
+for vpath in : false; do
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+
+ : A "make recheck" in a clean tree should run no tests.
+ do_recheck --pass
+ cat test-suite.log
+ test ! -e a.run
+ test ! -e a.log
+ test ! -e b.run
+ test ! -e b.log
+ test ! -e c.run
+ test ! -e c.log
+ test ! -e d.run
+ test ! -e d.log
+ count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+ : Run the tests for the first time.
+ run_make -O -e FAIL check
+ ls -l
+ # All the test scripts should have run.
+ test -f a.run
+ test -f b.run
+ test -f c.run
+ test -f d.run
+ count_test_results total=9 pass=3 fail=2 xpass=1 xfail=1 skip=1 error=1
+
+ : Let us make b.test pass.
+ using_gmake || $sleep # Required by BSD make.
+ echo OK > b.ok
+ do_recheck --fail
+ # a.test has been successful the first time, so no need to re-run it.
+ # Similar considerations apply to similar checks, below.
+ test ! -e a.run
+ test -f b.run
+ test -f c.run
+ test -f d.run
+ count_test_results total=7 pass=2 fail=2 xpass=1 xfail=1 skip=1 error=0
+
+ : Let us make the first part of c.test pass.
+ using_gmake || $sleep # Required by BSD make.
+ echo OK > c.pass
+ do_recheck --fail
+ test ! -e a.run
+ test ! -e b.run
+ test -f c.run
+ test -f d.run
+ count_test_results total=5 pass=1 fail=1 xpass=1 xfail=1 skip=1 error=0
+
+ : Let us make also the second part of c.test pass.
+ using_gmake || $sleep # Required by BSD make.
+ echo KO > c.xfail
+ do_recheck --fail
+ test ! -e a.run
+ test ! -e b.run
+ test -f c.run
+ test -f d.run
+ count_test_results total=5 pass=1 fail=1 xpass=0 xfail=2 skip=1 error=0
+
+ : Nothing changed, so only d.test should be run.
+ for i in 1 2; do
+ using_gmake || $sleep # Required by BSD make.
+ do_recheck --fail
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ test -f d.run
+ count_test_results total=2 pass=0 fail=1 xpass=0 xfail=0 skip=1 error=0
+ done
+
+ : Let us make d.test run more testcases, and experience _more_ failures.
+ using_gmake || $sleep # Required by BSD make.
+ echo 'test_count=9' > d.count
+ unindent > d.extra <<'END'
+ echo 'ok # SKIP s'
+ echo 'not ok - f 1'
+ echo 'ok - p 1'
+ echo 'not ok - f 2'
+ echo 'ok # TODO xp'
+ echo 'not ok - f 3'
+ echo 'not ok - f 4'
+ echo 'ok - p 2'
+ echo 'ok' # Extra test.
+ echo 'Bail out!'
+END
+ do_recheck --fail
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ test -f d.run
+ count_test_results total=11 pass=2 fail=4 xpass=1 xfail=0 skip=2 error=2
+
+ : Let us finally make d.test pass.
+ using_gmake || $sleep # Required by BSD make.
+ echo 'test_count=1' > d.count
+ echo : > d.extra
+ do_recheck --pass
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ test -f d.run
+ count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=1 error=0
+
+ : All tests have been successful or skipped, nothing should be re-run.
+ using_gmake || $sleep # Required by BSD make.
+ do_recheck --pass
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ test ! -e d.run
+ count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/tap-result-comment.sh b/t/tap-result-comment.sh
new file mode 100644
index 000000000..5455303a9
--- /dev/null
+++ b/t/tap-result-comment.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - non-directive comments in TAP results are kept verbatim
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<END
+1..5
+ok 1 # TDO
+not ok 2 # SKP
+ok #SIKP${tab}${sp}
+not ok # TOD${tab}
+ok 5 # ${tab}${tab}TOOD${tab}${sp}${sp}
+END
+
+run_make -O -e FAIL check
+count_test_results total=5 pass=3 fail=2 xpass=0 xfail=0 skip=0 error=0
+
+# Don't be too strict about trailing white space.
+$FGREP ': all.test' stdout | sed "s/[$sp$tab]*$//" > got
+
+cat > exp <<END
+PASS: all.test 1 # TDO
+FAIL: all.test 2 # SKP
+PASS: all.test 3 #SIKP
+FAIL: all.test 4 # TOD
+PASS: all.test 5 # ${tab}${tab}TOOD
+END
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-signal.tap b/t/tap-signal.tap
new file mode 100644
index 000000000..86d487377
--- /dev/null
+++ b/t/tap-signal.tap
@@ -0,0 +1,133 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - a test script terminated by a signal causes an hard error
+
+. test-init.sh
+
+fetch_tap_driver
+
+plan_ 10
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << END
+TEST_LOG_DRIVER = \$(srcdir)/tap-driver
+TEST_LOG_COMPILER = $PERL -w
+## Will be updated later.
+TESTS =
+END
+
+all_signals='1 2 3 9 13 15'
+blocked_signals=''
+for sig in $all_signals; do
+ # Ignore blocked signals
+ if is_blocked_signal $sig; then
+ blocked_signals="$blocked_signals $sig"
+ continue
+ fi
+ # Write the dummy test scripts in perl, not as shell scripts, to work
+ # around unportabilities in the handling of signals (in fact, even
+ # with bash, the older script were unable to properly deliver a SIGQUIT
+ # to themselves consistently). The shebang is dummy here, as we prefer
+ # to rely on the definition of TEST_LOG_COMPILER instead.
+ unindent > signal-$sig.test <<END
+ #! /usr/bin/env perl
+ # We need autoflush to avoid losing output, which could cause spurious
+ # "no test plan seen" in the TAP driver.
+ BEGIN { $| = 1 }
+ use warnings FATAL => "all";
+ print "1..1\\n";
+ print "ok 1\\n";
+ kill $sig, \$\$;
+ print "Bail out! \$0 not killed?\\n";
+END
+ echo TESTS += signal-$sig.test >> Makefile.am
+done
+results_count=$(ls *.test | wc -l | tr -d "$tab$sp")
+
+chmod a+x *.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+system=$(uname -s -r || echo unknown) # Needed later.
+
+signal_caught ()
+{
+ numeric=$1
+ case $numeric in
+ 1) symbolic=HUP;;
+ 2) symbolic=INT;;
+ 3) symbolic=QUIT;;
+ 9) symbolic=KILL;;
+ 13) symbolic=PIPE;;
+ 15) symbolic=TERM;;
+ *) fatal_ "unexpected signal number '$numeric'"
+ esac
+ # Sending a SIGQUIT on Cygwin 1.5 can cause a segmentation fault
+ # instead (sometimes). Don't let this older bug pollute the results
+ # of our testsuite.
+ case $numeric,$system in
+ 3,CYGWIN*\ 1.5.*) sig_re="((SIG)?($symbolic|SEGV)|$numeric|11)";;
+ *) sig_re="((SIG)?$symbolic|$numeric)";;
+ esac
+ wbound_re="($|[^a-zA-Z0-9_-])"
+ pfx_re="^ERROR: signal-$numeric\\.test"
+ rx="${pfx_re} .*terminated by signal ${sig_re}${wbound_re}"
+ desc="TAP driver catch test termination by signal SIG${symbolic}"
+ case " $blocked_signals " in
+ *" $numeric "*) skip_ -r "SIG$symbolic is blocked" "$desc" ;;
+ *) command_ok_ "$desc" env LC_ALL=C $EGREP "$rx" stdout ;;
+ esac
+}
+
+command_ok_ '"make check" fails' eval '
+ (
+ run_make -e IGNORE -O check
+ # Extra "echo" and silencing of xtraces required to avoid possible
+ # garbled output with NetBSD make, which would miss some final
+ # newlines in the expected places and thus mess up our TAP output.
+ set +x; echo
+ test $am_make_rc -gt 0
+ )
+'
+cat stdout # For debugging.
+
+command_ok_ "count of test results" count_test_results \
+ total=$(($results_count * 2)) \
+ pass=$results_count error=$results_count \
+ fail=0 xpass=0 xfail=0 skip=0
+
+for sig in $all_signals; do
+ signal_caught $sig
+done
+
+echo 'TEST_LOG_DRIVER_FLAGS = --ignore-exit' >> Makefile
+
+command_ok_ '"make check" passes [--ignore-exit]' run_make -O check
+
+command_ok_ "count of test results [--ignore-exit]" count_test_results \
+ total=$results_count pass=$results_count \
+ fail=0 xpass=0 xfail=0 skip=0 error=0
+
+:
diff --git a/t/tap-summary-color.sh b/t/tap-summary-color.sh
new file mode 100644
index 000000000..c6d74ce96
--- /dev/null
+++ b/t/tap-summary-color.sh
@@ -0,0 +1,23 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - colorized testsuite summary
+
+. test-lib.sh
+
+use_colors=yes
+. tap-summary-aux.sh
diff --git a/t/tap-summary.sh b/t/tap-summary.sh
new file mode 100644
index 000000000..87ece97a0
--- /dev/null
+++ b/t/tap-summary.sh
@@ -0,0 +1,23 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - colorized testsuite summary
+
+. test-lib.sh
+
+use_colors=no
+. tap-summary-aux.sh
diff --git a/t/tap-test-number-0.sh b/t/tap-test-number-0.sh
new file mode 100644
index 000000000..b82f0650d
--- /dev/null
+++ b/t/tap-test-number-0.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - a test result numbered as 0 is to be considered out-of-order
+# This is consistent with the behaviour of the 'prove' utility.
+
+. test-init.sh
+. tap-setup.sh
+
+cat > a.test <<END
+1..1
+ok 0
+END
+
+cat > b.test <<END
+1..1
+not ok 0
+END
+
+cat > c.test <<END
+1..1
+ok 0 foo # SKIP
+END
+
+cat > d.test <<END
+1..1
+not ok 0 bar # TODO
+END
+
+cat > e.test <<END
+1..1
+ok 0 # TODO
+END
+
+run_make -O -e FAIL TESTS='a.test b.test c.test d.test e.test' check
+count_test_results total=5 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=5
+
+grep '^ERROR: a\.test 0 # OUT-OF-ORDER (expecting 1)$' stdout
+grep '^ERROR: b\.test 0 # OUT-OF-ORDER (expecting 1)$' stdout
+grep '^ERROR: c\.test 0 foo # OUT-OF-ORDER (expecting 1)$' stdout
+grep '^ERROR: d\.test 0 bar # OUT-OF-ORDER (expecting 1)$' stdout
+grep '^ERROR: e\.test 0 # OUT-OF-ORDER (expecting 1)$' stdout
+
+:
diff --git a/t/tap-todo-skip-together.sh b/t/tap-todo-skip-together.sh
new file mode 100644
index 000000000..3abd23af8
--- /dev/null
+++ b/t/tap-todo-skip-together.sh
@@ -0,0 +1,37 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - TODO and SKIP directives on the same line: the first one wins
+# See also related test 'tap-ambiguous-directive.sh'.
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<END
+1..2
+ok 1 # SKIP TODO
+not ok 2 # TODO SKIP
+END
+
+run_make -O check
+count_test_results total=2 pass=0 fail=0 xpass=0 xfail=1 skip=1 error=0
+
+grep '^SKIP: all\.test 1 ' stdout
+grep '^XFAIL: all\.test 2 ' stdout
+
+:
diff --git a/t/tap-todo-skip-whitespace.sh b/t/tap-todo-skip-whitespace.sh
new file mode 100644
index 000000000..f45642883
--- /dev/null
+++ b/t/tap-todo-skip-whitespace.sh
@@ -0,0 +1,99 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - normalization of whitespace in console testsuite progress associated
+# with TODO and SKIP directives
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > stub.tap <<END
+1 # TODO
+2 # TODO foo?
+3 # TODO: bar!
+4 aa # TODO
+5 bb # TODO fnord 5
+6 cc # TODO:${tab}fnord 6
+7 - x # TODO
+8 - y # TODO fnord $tab 8
+9 - z # TODO: fnord 9 $tab
+10# TODO x0
+11$tab# TODO x1
+12 $tab$tab # TODO x2
+13 asd# TODO x3
+14 sad$tab# TODO x4
+15 das$tab$tab # TODO x5
+END
+
+cat > stub.exp <<END
+1 # TODO
+2 # TODO foo?
+3 # TODO: bar!
+4 aa # TODO
+5 bb # TODO fnord 5
+6 cc # TODO:${tab}fnord 6
+7 - x # TODO
+8 - y # TODO fnord $tab 8
+9 - z # TODO: fnord 9
+10 # TODO x0
+11 # TODO x1
+12 # TODO x2
+13 asd # TODO x3
+14 sad # TODO x4
+15 das # TODO x5
+END
+
+plan=1..15
+
+my_make_check ()
+{
+ xpass=0 xfail=0 skip=0
+ case $1 in
+ xpass|xfail|skip) eval $1=15;;
+ *) fatal_ "bad argument '$1' for my_make_check";;
+ esac
+ cat all.test
+ # We don't care about the exit status in this test.
+ run_make -O -e IGNORE check
+ count_test_results total=15 pass=0 fail=0 error=0 \
+ xpass=$xpass xfail=$xfail skip=$skip
+ # Don't be too strict w.r.t. possible normalization of "TODO: foo" into
+ # "TODO : foo" (as is done by, e.g., the 'TAP::Parser' perl module).
+ LC_ALL=C grep '^[A-Z][A-Z]*:' stdout \
+ | sed -e 's/# TODO *:/# TODO:/' -e 's/# SKIP *:/# SKIP:/' > got
+ cat exp
+ cat got
+ diff exp got
+}
+
+# For "TODO" directives leading to XPASS results.
+(echo $plan && sed -e 's/^/ok /' stub.tap) > all.test
+sed -e 's/^/XPASS: all.test /' stub.exp > exp
+my_make_check xpass
+
+# For "TODO" directives leading to XFAIL results.
+(echo $plan && sed -e 's/^/not ok /' stub.tap) > all.test
+sed -e 's/^/XFAIL: all.test /' stub.exp > exp
+my_make_check xfail
+
+# For "SKIP" directives.
+(echo $plan && sed -e 's/^/ok /' -e 's/TODO/SKIP/' stub.tap) > all.test
+sed -e 's/TODO/SKIP/' -e 's/^/SKIP: all.test /' stub.exp > exp
+my_make_check skip
+
+:
diff --git a/t/tap-todo-skip.sh b/t/tap-todo-skip.sh
new file mode 100644
index 000000000..5bafa451c
--- /dev/null
+++ b/t/tap-todo-skip.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - TODO and SKIP directives are case-insensitive
+# - TODO and SKIP directives can be followed optionally by a colon ":"
+# and by an optional explanation.
+# - our driver isn't fooled into recognizing TODO and SKIP directives
+# spuriously
+# - the reasons for TODO and SKIP, if present, are nicely printed in
+# the testsuite progress output
+
+. test-init.sh
+
+. tap-setup.sh
+
+# ----------------------------------------------------- #
+# Check all possible combinations of: #
+# - uppercase/lowercase #
+# - with/without colon character ":" #
+# - with/without explanatory message #
+# in TODO and SKIP directives. #
+# ----------------------------------------------------- #
+
+# There are 2 * 2^6 + 2 * 2^6 = 256 tests.
+echo 1..256 > all.test
+
+# These nested loops are clearer without indentation.
+
+for c1 in t T; do
+for c2 in o O; do
+for c3 in d D; do
+for c4 in o O; do
+for ex in '' ':' ' foo' ': foo'; do
+ echo "not ok # $c1$c2$c3$c4$ex"
+ echo "not ok# $c1$c2$c3$c4$ex"
+done; done; done; done; done >> all.test
+
+for c1 in s S; do
+for c2 in k K; do
+for c3 in i I; do
+for c4 in p P; do
+for ex in '' ':' ' foo' ': foo'; do
+ echo "ok # $c1$c2$c3$c4$ex"
+ echo "ok# $c1$c2$c3$c4$ex"
+done; done; done; done; done >> all.test
+
+cat all.test # For debugging.
+
+run_make -O check
+count_test_results total=256 pass=0 fail=0 xpass=0 xfail=128 skip=128 error=0
+
+# -------------------------------------------------------- #
+# TODO ans SKIP directives aren't recognized spuriously. #
+# -------------------------------------------------------- #
+
+cat > all.test <<'END'
+1..9
+ok TODO
+ok - TODO
+ok 3 TODO
+ok 4 - TODO
+ok SKIP
+ok - SKIP
+ok 7 SKIP
+ok 8 - SKIP
+ok 9
+END
+
+run_make -O check
+count_test_results total=9 pass=9 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+:
diff --git a/t/tap-unplanned.sh b/t/tap-unplanned.sh
new file mode 100644
index 000000000..95133795c
--- /dev/null
+++ b/t/tap-unplanned.sh
@@ -0,0 +1,153 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - unplanned tests are properly reported as errors
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<END
+1..1
+ok 1
+ok 2
+END
+run_make -O -e FAIL check
+count_test_results total=3 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=2
+grep '^ERROR: all\.test - too many tests run (expected 1, got 2)$' stdout
+grep '^ERROR: all\.test 2 # UNPLANNED$' stdout
+
+cat > all.test <<END
+1..2
+ok 1
+ok 2
+ok 3
+END
+run_make -O -e FAIL check
+count_test_results total=4 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=2
+grep '^ERROR: all\.test - too many tests run (expected 2, got 3)$' stdout
+grep '^ERROR: all\.test 3 # UNPLANNED$' stdout
+
+# Interaction with XFAIL_TESTS.
+cat > all.test <<END
+1..2
+not ok 1
+ok 2 # SKIP
+ok 3
+not ok 4
+ok 5 # SKIP
+END
+run_make -O -e FAIL XFAIL_TESTS=all.test check
+count_test_results total=6 pass=0 fail=0 xpass=0 xfail=1 skip=1 error=4
+grep '^ERROR: all\.test - too many tests run (expected 2, got 5)$' stdout
+grep '^ERROR: all\.test 3 # UNPLANNED$' stdout
+grep '^ERROR: all\.test 4 # UNPLANNED$' stdout
+grep '^ERROR: all\.test 5 # UNPLANNED$' stdout
+
+cat > all.test <<END
+1..1
+ok 1
+
+ok
+ok 3
+ok foo
+ok 5 - bar bar
+
+not ok
+not ok 7
+not ok foo
+not ok 9 - bar bar
+
+ok # TODO
+ok 11 # TODO
+ok foo # TODO
+ok 13 - bar bar # TODO
+
+not ok # TODO
+not ok 15 # TODO
+not ok foo # TODO
+not ok 17 - bar bar # TODO
+
+ok # SKIP
+ok 19 # SKIP
+ok foo # SKIP
+ok 21 - bar bar # SKIP
+END
+
+cat > t <<END
+
+2
+3
+4 foo
+5 - bar bar
+
+6
+7
+8 foo
+9 - bar bar
+
+10
+11
+12 foo
+13 - bar bar
+
+14
+15
+16 foo
+17 - bar bar
+
+18
+19
+20 foo
+21 - bar bar
+
+END
+
+run_make -O -e FAIL check
+count_test_results total=22 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=21
+
+echo 'PASS: all.test 1' > exp
+sed -e '/^$/d' -e 's/.*/ERROR: all.test & # UNPLANNED/' t >> exp
+echo 'ERROR: all.test - too many tests run (expected 1, got 21)' >> exp
+
+$FGREP ': all.test' stdout > got
+
+cat exp
+cat got
+diff exp got
+
+# Note that, if the TAP input has a trailing plan, it is not possible
+# to flag unplanned tests as such, since we do not know they're unplanned
+# until the plan is reached; still, we should give at least an error
+# message about the unmatched number of tests once we've got the plan.
+
+for x in 'ok' 'ok 3' 'not ok' 'not ok # TODO' 'ok # TODO' 'ok # SKIP'; do
+ unindent > all.test <<END
+ ok 1
+ ok 2 # SKIP
+ $x
+ 1..2
+END
+ run_make -O -e FAIL check
+ test $($FGREP -c ': all.test' stdout) -eq 4
+ $EGREP '^PASS: all\.test 1($| )' stdout
+ $EGREP '^SKIP: all\.test 2($| )' stdout
+ $EGREP ': all\.test 3($| )' stdout
+ grep '^ERROR: all\.test - too many tests run (expected 2, got 3)$' stdout
+done
+
+:
diff --git a/t/tap-whitespace-normalization.sh b/t/tap-whitespace-normalization.sh
new file mode 100644
index 000000000..4b767f5c1
--- /dev/null
+++ b/t/tap-whitespace-normalization.sh
@@ -0,0 +1,163 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support: whitespace normalization (or lack thereof) in the testsuite
+# progress output on console. We keep all of these checks here in a single
+# script so that a potential cosmetic change in the output format won't
+# force us to tweak dozens of other tests (hopefully).
+# See also related test 'tap-todo-skip-whitespace.sh'.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+TEST_LOG_COMPILER = cat
+TESTS =
+END
+
+: > exp
+
+spaces_a=${sp}${tab}${tab}${sp}${sp}${tab}
+spaces_b=${tab}${tab}${sp}${tab}${sp}${sp}${sp}
+
+#-----------------------------------------------------------------------
+
+echo TESTS += numbers.test >> Makefile.am
+
+cat > numbers.test <<END
+1..6
+ok${spaces_a}1
+ok 2${spaces_b}
+ok${spaces_a}3${spaces_b}
+not ok${spaces_b}4
+not ok 5${spaces_a}
+not ok${spaces_b}6${spaces_a}
+END
+
+cat >> exp <<END
+PASS: numbers.test 1
+PASS: numbers.test 2
+PASS: numbers.test 3
+FAIL: numbers.test 4
+FAIL: numbers.test 5
+FAIL: numbers.test 6
+END
+
+#-----------------------------------------------------------------------
+
+echo TESTS += description.test >> Makefile.am
+
+cat > description.test <<END
+1..8
+ok${spaces_a}+foo
+ok +bar${spaces_b}
+ok${spaces_a}+baz${spaces_b}
+not ok${spaces_b}-foo
+not ok -bar${spaces_a}
+not ok${spaces_b}-baz${spaces_a}
+ok u${spaces_b}v${spaces_a}w${sp}
+not ok${spaces_a}x${spaces_a}y${tab}z${tab}
+END
+
+cat >> exp <<END
+PASS: description.test 1 +foo
+PASS: description.test 2 +bar
+PASS: description.test 3 +baz
+FAIL: description.test 4 -foo
+FAIL: description.test 5 -bar
+FAIL: description.test 6 -baz
+PASS: description.test 7 u${spaces_b}v${spaces_a}w
+FAIL: description.test 8 x${spaces_a}y${tab}z
+END
+
+#-----------------------------------------------------------------------
+
+# "Bail out!" magic.
+
+echo TESTS += bailout.test >> Makefile.am
+
+cat > bailout.test <<END
+1..1
+Bail out!${tab}${sp}${sp}${tab}We're out of disk space.
+ok 1
+END
+
+cat >> exp <<END
+ERROR: bailout.test - Bail out! We're out of disk space.
+END
+
+echo TESTS += bailout2.test >> Makefile.am
+
+cat > bailout2.test <<END
+1..1
+Bail out!foo${tab}${sp}
+ok 1
+END
+
+cat >> exp <<END
+ERROR: bailout2.test - Bail out! foo
+END
+
+#-----------------------------------------------------------------------
+
+# Diagnostic lines.
+
+echo AM_TEST_LOG_DRIVER_FLAGS = --comments >> Makefile.am
+echo TESTS += cmnt.test >> Makefile.am
+
+cat > cmnt.test <<END
+1..1
+ok 1
+#Leading whitespace gets added
+# ${tab}${tab} ${tab}Extra leading whitespace is stripped
+# Trailing whitespace is stripped ${tab} ${tab}${tab}
+# Middle${tab}whitespace is${tab} ${tab}${tab} kept
+# ${tab} And only${tab}middle ${tab}whitespace ${tab}${tab} ${tab}
+END
+
+cat >> exp <<END
+PASS: cmnt.test 1
+# cmnt.test: Leading whitespace gets added
+# cmnt.test: Extra leading whitespace is stripped
+# cmnt.test: Trailing whitespace is stripped
+# cmnt.test: Middle${tab}whitespace is${tab} ${tab}${tab} kept
+# cmnt.test: And only${tab}middle ${tab}whitespace
+END
+
+#-----------------------------------------------------------------------
+
+# TODO: we should have more checks here ... (but let's not over-do FTM).
+
+#-----------------------------------------------------------------------
+
+chmod a+x *.test
+
+. tap-setup.sh
+
+# We don't care about exit status or number of test results, they
+# should be checked for in many other tests.
+run_make -O -e FAIL check
+
+LC_ALL=C sort exp > t
+mv -f t exp
+
+# We need the sort below to account for parallel make usage.
+LC_ALL=C grep '[a-z0-9][a-z0-9]*\.test' stdout | LC_ALL=C sort > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/t/tap-with-and-without-number.sh b/t/tap-with-and-without-number.sh
new file mode 100644
index 000000000..9ba708bb5
--- /dev/null
+++ b/t/tap-with-and-without-number.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP support:
+# - numbered and unnumbered test results can coexist
+# - tests without explicit number get automatically numbered in the
+# testsuite progress output on console
+
+. test-init.sh
+
+. tap-setup.sh
+
+cat > all.test <<'END'
+1..7
+ok 1 foo
+ok 2 - foo2
+ok - bar
+not ok baz # TODO
+not ok 5 - asd # TODO
+ok 6 # SKIP
+ok zardoz
+END
+
+run_make -O check
+count_test_results total=7 pass=4 fail=0 xpass=0 xfail=2 skip=1 error=0
+
+grep '^PASS: all\.test 1 foo$' stdout
+grep '^PASS: all\.test 2 - foo2$' stdout
+grep '^PASS: all\.test 3 - bar$' stdout
+grep '^XFAIL: all\.test 4 baz # TODO$' stdout
+grep '^XFAIL: all\.test 5 - asd # TODO$' stdout
+grep '^SKIP: all\.test 6 # SKIP$' stdout
+grep '^PASS: all\.test 7 zardoz$' stdout
+
+:
diff --git a/t/tap-xfail-tests.sh b/t/tap-xfail-tests.sh
new file mode 100644
index 000000000..7be985918
--- /dev/null
+++ b/t/tap-xfail-tests.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# TAP and $(XFAIL_TESTS): test results without directives are turned from
+# PASS to XPASS and from FAIL to XFAIL; other results are unchanged.
+
+. test-init.sh
+
+. tap-setup.sh
+
+echo 'XFAIL_TESTS = $(TESTS)' >> Makefile
+
+cat > all.test <<END
+1..6
+ok 1
+not ok 2
+ok 3 # TODO
+not ok 4 # TODO
+ok 5 # SKIP
+# The next should count as a failure (and thus will be
+# rendered into an expected failure by XFAIL_TESTS).
+not ok 6 # SKIP
+Bail out!
+END
+
+run_make -O -e FAIL check
+count_test_results total=7 pass=0 fail=0 xpass=2 xfail=3 skip=1 error=1
+
+grep '^XPASS: all\.test 1$' stdout
+grep '^XFAIL: all\.test 2$' stdout
+grep '^XPASS: all\.test 3 # TODO' stdout
+grep '^XFAIL: all\.test 4 # TODO' stdout
+grep '^SKIP: all\.test 5 # SKIP' stdout
+grep '^XFAIL: all\.test 6 # SKIP' stdout
+grep '^ERROR: all\.test - Bail out!' stdout
+
+# Check that the exit status of the testsuite is indeed 0 when we
+# would expect success.
+
+cat > all.test <<END
+1..3
+not ok 1
+ok 2 # SKIP
+not ok 3 # TODO
+END
+
+run_make -O check
+count_test_results total=3 pass=0 fail=0 xpass=0 xfail=2 skip=1 error=0
+
+:
diff --git a/t/tar-opts-errors.sh b/t/tar-opts-errors.sh
new file mode 100644
index 000000000..ff92ad05c
--- /dev/null
+++ b/t/tar-opts-errors.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check the tar options diagnostics.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([tar-pax tar-v7])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+grep "^configure\.ac:2:.*mutually exclusive" stderr > tar-err
+cat tar-err
+test 1 -eq $(wc -l < tar-err)
+grep "'tar-pax'" tar-err
+grep "'tar-v7'" tar-err
+
+rm -rf autom4te.cache
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+echo 'AUTOMAKE_OPTIONS = tar-pax' > Makefile.am
+
+AUTOMAKE_fails
+grep "^Makefile\.am:1:.*'tar-pax'.*AM_INIT_AUTOMAKE" stderr
+
+:
diff --git a/t/tar-override.sh b/t/tar-override.sh
new file mode 100644
index 000000000..116dd382c
--- /dev/null
+++ b/t/tar-override.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the user can override the tar program used by "make dist"
+# at runtime, by redefining the 'TAR' environment variable.
+# NOTE: currently this works only when the tar format used is 'v7'
+# (which is the default one).
+
+. test-init.sh
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+echo AC_OUTPUT >> configure.ac
+
+cat > am--tar <<'END'
+#!/bin/sh
+echo $1 > am--tar-has-run
+shift
+exec tar "$@"
+END
+chmod a+x am--tar
+
+cat > Makefile.am <<'END'
+check-local: dist
+ ls -l ;: For debugging.
+ test -f am--tar-has-run
+CLEANFILES = am--tar-has-run
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+clean_temp () { rm -f *.tar.* *has-run*; }
+
+$MAKE dist
+test -f $distdir.tar.gz
+ls | grep has-run && exit 1
+
+clean_temp
+
+TAR="$cwd/am--tar foo" $MAKE distcheck
+test -f $distdir.tar.gz
+test "$(cat am--tar-has-run)" = foo
+
+clean_temp
+
+unset TAR
+# Creative use of eval to pacify maintainer checks.
+eval \$'MAKE dist "TAR=./am--tar mu"'
+test -f $distdir.tar.gz
+test "$(cat am--tar-has-run)" = mu
+
+:
diff --git a/t/tar-pax.sh b/t/tar-pax.sh
new file mode 100644
index 000000000..eb1cbea1e
--- /dev/null
+++ b/t/tar-pax.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check the tar-pax option.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([tar-pax])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+grep 'am__tar' Makefile # For debugging.
+if grep '^am__tar = false' Makefile; then
+ skip_ "cannot find proper archiver program"
+fi
+
+$MAKE distcheck
+test -f "$distdir.tar.gz"
+
+:
diff --git a/t/tar-ustar-id-too-high.sh b/t/tar-ustar-id-too-high.sh
new file mode 100644
index 000000000..81802c3f9
--- /dev/null
+++ b/t/tar-ustar-id-too-high.sh
@@ -0,0 +1,88 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that UID or GID too high for the ustar format are correctly
+# rwcognized and diagnosed by configure. See bug#8343 and bug#13588.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([tar-ustar])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+run_configure()
+{
+ st=0; ./configure ${1+"$@"} >stdout || st=$?
+ cat stdout || exit 1
+ test $st -eq 0 || exit 1
+}
+
+checked ()
+{
+ grep "^checking $1\.\.\. $2$" stdout
+}
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+mkdir bin
+cat > bin/id <<'END'
+#!/bin/sh -e
+case "$*" in
+ -u) echo "${am_uid-1000}";;
+ -g) echo "${am_gid-1000}";;
+ *) echo "id: bad/unexpected usage" >&2; exit 1;;
+esac
+END
+chmod a+x bin/id
+
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH
+
+# Problematic ID reported in
+# <https://bugzilla.redhat.com/show_bug.cgi?id=843376>.
+am_uid=16777216; export am_uid
+am_gid=1000; export am_gid
+run_configure
+checked "whether UID '$am_uid' is supported by ustar format" "no"
+checked "whether GID '1000' is supported by ustar format" "yes"
+checked "how to create a ustar tar archive" "none"
+
+# Another problematic ID reported in
+# <https://bugzilla.redhat.com/show_bug.cgi?id=843376>.
+am_uid=1000; export am_uid
+am_gid=17000000; export am_gid
+run_configure
+checked "whether UID '1000' is supported by ustar format" "yes"
+checked "whether GID '$am_gid' is supported by ustar format" "no"
+checked "how to create a ustar tar archive" "none"
+
+# The minimal ID that is too big.
+two_to_twentyone=$((32 * 32 * 32 * 32 * 2))
+# <https://bugzilla.redhat.com/show_bug.cgi?id=843376>.
+am_uid=$two_to_twentyone; export am_uid
+am_gid=$two_to_twentyone; export am_gid
+run_configure
+checked "whether UID '$two_to_twentyone' is supported by ustar format" "no"
+checked "whether GID '$two_to_twentyone' is supported by ustar format" "no"
+checked "how to create a ustar tar archive" "none"
+
+:
diff --git a/t/tar-ustar.sh b/t/tar-ustar.sh
new file mode 100644
index 000000000..359e162c2
--- /dev/null
+++ b/t/tar-ustar.sh
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check the tar-ustar option.
+
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([tar-ustar])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+grep 'am__tar' Makefile # For debugging.
+if grep '^am__tar = false' Makefile; then
+ skip_ "cannot find proper archiver program"
+fi
+
+$MAKE distcheck
+test -f "$distdir.tar.gz"
+
+:
diff --git a/t/target-cflags.sh b/t/target-cflags.sh
new file mode 100644
index 000000000..2571e6197
--- /dev/null
+++ b/t/target-cflags.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure target specific CFLAGS work
+# Assar Westerlund <assar@sics.se>
+
+required=cc
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = no-dependencies
+
+bin_PROGRAMS = foo bar
+foo_CFLAGS = -DFOO
+END
+
+cat > foo.c << 'END'
+#include <stdio.h>
+#ifdef FOO
+int main(void)
+{
+ return 0;
+}
+#endif
+END
+
+cat > bar.c << 'END'
+#ifndef FOO
+int main(void)
+{
+ return 0;
+}
+#endif
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+mkdir build
+
+cd build
+../configure
+$MAKE
+if ! cross_compiling; then
+ ./foo
+ ./bar
+fi
+cd ..
+
+./configure
+$MAKE
+if ! cross_compiling; then
+ ./foo
+ ./bar
+fi
+
+:
diff --git a/t/targetclash.sh b/t/targetclash.sh
new file mode 100644
index 000000000..e9c91f316
--- /dev/null
+++ b/t/targetclash.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that target clashes are diagnosed.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = ctags
+END
+
+$ACLOCAL
+AUTOMAKE_fails -a
+grep 'redefinition.*ctags' stderr
+
+:
diff --git a/t/test-driver-acsubst.sh b/t/test-driver-acsubst.sh
new file mode 100644
index 000000000..e78290acc
--- /dev/null
+++ b/t/test-driver-acsubst.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests:
+# - LOG_DRIVER variables can be AC_SUBST'd
+
+. test-init.sh
+
+mkdir test-drivers
+
+cp "$am_testaux_srcdir"/trivial-test-driver test-drivers/triv \
+ || fatal_ "failed to fetch auxiliary script trivial-test-driver"
+cp "$am_scriptdir"/test-driver test-drivers/dflt \
+ || fatal_ "failed to fetch auxiliary script test-driver"
+
+cat >> configure.ac <<'END'
+AC_SUBST([LOG_DRIVER], ['${SHELL} test-drivers/triv'])
+AC_SUBST([TEST_LOG_DRIVER], ['${SHELL} test-drivers/dflt'])
+AC_SUBST([SH_LOG_DRIVER], ['${my_drv}'])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+TEST_EXTENSIONS = .test .sh
+my_drv = $(SHELL) test-drivers/dflt
+TESTS = foo bar.test baz.sh
+XFAIL_TESTS = baz.sh
+.PHONY: check-autodefs
+check-autodefs:
+### For debugging.
+ @echo LOG_DRIVER = $(LOG_DRIVER)
+ @echo TEST_LOG_DRIVER = $(TEST_LOG_DRIVER)
+ @echo SH_LOG_DRIVER = $(SH_LOG_DRIVER)
+### Checks here.
+ @echo ' ' $(LOG_DRIVER) ' ' | grep ' test-drivers/triv '
+ @echo ' ' $(TEST_LOG_DRIVER) ' ' | grep ' test-drivers/dflt '
+ @echo ' ' $(SH_LOG_DRIVER) ' ' | grep ' test-drivers/dflt '
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+
+cat > foo <<'END'
+#!/bin/sh
+echo "PASS: from $0"
+exit 1 # exit status should be ignored by the trivial-test-driver.
+END
+
+cat > bar.test <<'END'
+#!/bin/sh
+exit 77
+END
+
+cat > baz.sh <<'END'
+#!/bin/sh
+exit 1
+END
+
+chmod a+x foo bar.test baz.sh
+
+$MAKE check-autodefs
+run_make -O -e IGNORE check
+cat test-suite.log
+cat foo.log
+cat bar.log
+cat baz.log
+test $am_make_rc -eq 0
+count_test_results total=3 pass=1 fail=0 skip=1 xfail=1 xpass=0 error=0
+
+:
diff --git a/t/test-driver-cond.sh b/t/test-driver-cond.sh
new file mode 100644
index 000000000..cc6f2dc22
--- /dev/null
+++ b/t/test-driver-cond.sh
@@ -0,0 +1,116 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests:
+# - Automake can correctly handle conditionals contents for the
+# LOG_DRIVER variables.
+
+. test-init.sh
+
+cp "$am_testaux_srcdir"/trivial-test-driver . \
+ || fatal_ "failed to fetch auxiliary script trivial-test-driver"
+cp "$am_scriptdir"/tap-driver.sh . \
+ || fatal_ "failed to fetch auxiliary script tap-driver.sh"
+
+cat >> configure.ac << END
+AM_CONDITIONAL([COND1], [:])
+AM_CONDITIONAL([COND2], [false])
+AM_CONDITIONAL([COND3], [false])
+AC_SUBST([PERL], ['$PERL'])
+AC_SUBST([my_LOG_DRIVER], ['\${SHELL} \${top_srcdir}/trivial-test-driver'])
+AM_SUBST_NOTMAKE([my_LOG_DRIVER])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+
+cat > Makefile.am << 'END'
+TESTS = foo bar.test baz.sh
+EXTRA_DIST = $(TESTS) tap-driver.sh trivial-test-driver
+TEST_EXTENSIONS = .test .sh
+LOG_DRIVER =
+SH_LOG_DRIVER = $(tap_rulez)
+if COND1
+LOG_DRIVER += @my_LOG_DRIVER@
+if COND2
+tap_rulez = false
+else !COND2
+tap_rulez = $(PERL) $(srcdir)/tap-driver.sh
+endif !COND2
+endif COND1
+END
+
+cat > foo <<'END'
+#!/bin/sh
+echo "PASS: from $0"
+echo "SKIP: from $0"
+exit 1 # exit status should be ignored by the trivial-test-driver.
+END
+
+cat > bar.test <<'END'
+#!/bin/sh
+exit 0
+END
+
+cat > baz.sh <<'END'
+#!/bin/sh
+echo 1..3
+echo 'ok 1'
+echo 'not ok 2 # TODO'
+echo 'not ok 3 # TODO'
+END
+
+chmod a+x foo bar.test baz.sh
+
+$AUTOMAKE -a
+test -f test-driver
+
+grep DRIVER Makefile.in || exit 99 # For debugging.
+
+grep '^my_LOG_DRIVER *=' Makefile.in \
+ && fatal_ 'unexpected $(my_LOG_DRIVER) in Makefile.in'
+
+grep '^TEST_LOG_DRIVER =.*\$(SHELL).*/test-driver' Makefile.in
+
+$PERL -MTAP::Parser -e 1 \
+ || skip_ "cannot import TAP::Parser perl module"
+
+./configure
+
+do_count ()
+{
+ count_test_results total=6 pass=3 fail=0 skip=1 xfail=2 xpass=0 error=0
+ grep '^PASS: foo, testcase 1 *$' stdout
+ grep '^SKIP: foo, testcase 2 *$' stdout
+ grep '^PASS: bar\.test *$' stdout
+ $EGREP 'PASS: baz\.sh 1( |$)' stdout
+ $EGREP 'XFAIL: baz\.sh 2( |$)' stdout
+ $EGREP 'XFAIL: baz\.sh 3( |$)' stdout
+}
+
+run_make -O -e IGNORE check
+cat test-suite.log
+cat foo.log
+cat bar.log
+cat baz.log
+test $am_make_rc -eq 0 || exit 1
+do_count
+
+run_make -O distcheck
+do_count
+
+:
diff --git a/t/test-driver-create-log-dir.sh b/t/test-driver-create-log-dir.sh
new file mode 100644
index 000000000..aedebd580
--- /dev/null
+++ b/t/test-driver-create-log-dir.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Custom test drivers: if a log file has a directory component (as in
+# e.g., 'sub/foo.log'), the Automake test harness must ensure that
+# directory exists before calling any custom test driver.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# The extra '.' components below are meant.
+TESTS = sub/foo sub/subsub/bar.test ././sub1/./baz
+$(TESTS):
+LOG_DRIVER = $(srcdir)/checkdir-driver
+TEST_LOG_DRIVER = $(LOG_DRIVER)
+EXTRA_DIST = checkdir-driver
+
+check-local: $(TEST_SUITE_LOG)
+ test -d sub
+ test -d sub1
+ test -d sub/subsub
+ test -f sub/foo.log
+ test -f sub/subsub/bar.log
+ test -f sub1/baz.log
+ test -f sub/foo.trs
+ test -f sub/subsub/bar.trs
+ test -f sub1/baz.trs
+END
+
+echo "#!$AM_TEST_RUNNER_SHELL" > checkdir-driver
+cat >> checkdir-driver <<'END'
+set -e; set -u
+while test $# -gt 0; do
+ case $1 in
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ --test-name|--expect-failure|--color-tests|--enable-hard-errors) shift;;
+ --) shift; break;;
+ *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
+ esac
+ shift
+done
+echo "log: $log_file" # For debugging.
+echo "trs: $trs_file" # Ditto.
+case $log_file in */*);; *) exit 1;; esac
+dir_log=${log_file%/*}
+dir_trs=${trs_file%/*}
+echo "dir_log: $dir_log" # For debugging.
+echo "dir_trs: $dir_trs" # Likewise.
+test x"$dir_trs" = x"$dir_log" || exit 1
+test -d "$dir_log" || exit 1
+echo dummy1 > "$log_file"
+echo dummy2 > "$trs_file"
+END
+chmod a+x checkdir-driver
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/test-driver-custom-multitest-recheck.sh b/t/test-driver-custom-multitest-recheck.sh
new file mode 100644
index 000000000..68fdcfa5b
--- /dev/null
+++ b/t/test-driver-custom-multitest-recheck.sh
@@ -0,0 +1,220 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Custom test drivers: try the "recheck" functionality with test protocols
+# that allow multiple testcases in a single test script. This test not
+# only checks implementation details in Automake's custom test drivers
+# support, but also serves as a "usability test" for our APIs.
+# See also related tests 'test-driver-custom-multitest-recheck2.sh'
+# and 'parallel-tests-recheck-override.sh'.
+# Keep in sync with 'tap-recheck.sh'.
+
+. test-init.sh
+
+cp "$am_testaux_srcdir"/trivial-test-driver . \
+ || fatal_ "failed to fetch auxiliary script trivial-test-driver"
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = $(SHELL) $(srcdir)/trivial-test-driver
+TESTS = a.test b.test c.test d.test
+END
+
+cat > a.test << 'END'
+#! /bin/sh
+echo PASS: aa
+echo PASS: AA
+: > a.run
+END
+
+cat > b.test << 'END'
+#! /bin/sh
+echo PASS:
+if test -f b.ok; then
+ echo PASS:
+else
+ echo ERROR:
+fi
+: > b.run
+END
+
+cat > c.test << 'END'
+#! /bin/sh
+if test -f c.pass; then
+ echo PASS: c0
+else
+ echo FAIL: c0
+fi
+if test -f c.xfail; then
+ echo XFAIL: c1
+else
+ echo XPASS: c1
+fi
+echo XFAIL: c2
+: > c.run
+END
+
+cat > d.test << 'END'
+#! /bin/sh
+echo SKIP: who cares ...
+(. ./d.extra) || echo FAIL: d.extra failed
+: > d.run
+END
+
+chmod a+x *.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+do_recheck ()
+{
+ case $* in
+ --fail) status=FAIL;;
+ --pass) status=0;;
+ *) fatal_ "invalid usage of function 'do_recheck'";;
+ esac
+ rm -f *.run
+ run_make -O -e $status recheck || { ls -l; exit 1; }
+ ls -l
+}
+
+for vpath in : false; do
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+
+ : A "make recheck" in a clean tree should run no tests.
+ using_gmake || $sleep # Required by BSD make.
+ do_recheck --pass
+ cat test-suite.log
+ test ! -e a.run
+ test ! -e a.log
+ test ! -e b.run
+ test ! -e b.log
+ test ! -e c.run
+ test ! -e c.log
+ test ! -e d.run
+ test ! -e d.log
+ count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+ : Run the tests for the first time.
+ run_make -O -e FAIL check
+ ls -l
+ # All the test scripts should have run.
+ test -f a.run
+ test -f b.run
+ test -f c.run
+ test -f d.run
+ count_test_results total=9 pass=3 fail=2 xpass=1 xfail=1 skip=1 error=1
+
+ : Let us make b.test pass.
+ using_gmake || $sleep # Required by BSD make.
+ echo OK > b.ok
+ do_recheck --fail
+ # a.test has been successful the first time, so no need to re-run it.
+ # Similar considerations apply to similar checks, below.
+ test ! -e a.run
+ test -f b.run
+ test -f c.run
+ test -f d.run
+ count_test_results total=7 pass=2 fail=2 xpass=1 xfail=1 skip=1 error=0
+
+ : Let us make the first part of c.test pass.
+ using_gmake || $sleep # Required by BSD make.
+ echo OK > c.pass
+ do_recheck --fail
+ test ! -e a.run
+ test ! -e b.run
+ test -f c.run
+ test -f d.run
+ count_test_results total=5 pass=1 fail=1 xpass=1 xfail=1 skip=1 error=0
+
+ : Let us make also the second part of c.test pass.
+ using_gmake || $sleep # Required by BSD make.
+ echo KO > c.xfail
+ do_recheck --fail
+ test ! -e a.run
+ test ! -e b.run
+ test -f c.run
+ test -f d.run
+ count_test_results total=5 pass=1 fail=1 xpass=0 xfail=2 skip=1 error=0
+
+ : Nothing changed, so only d.test should be run.
+ for i in 1 2; do
+ using_gmake || $sleep # Required by BSD make.
+ do_recheck --fail
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ test -f d.run
+ count_test_results total=2 pass=0 fail=1 xpass=0 xfail=0 skip=1 error=0
+ done
+
+ : Let us make d.test run more testcases, and experience _more_ failures.
+ using_gmake || $sleep # Required by BSD make.
+ unindent > d.extra <<'END'
+ echo SKIP: s
+ echo FAIL: f 1
+ echo PASS: p 1
+ echo FAIL: f 2
+ echo XPASS: xp
+ echo FAIL: f 3
+ echo FAIL: f 4
+ echo ERROR: e 1
+ echo PASS: p 2
+ echo ERROR: e 2
+END
+ do_recheck --fail
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ test -f d.run
+ count_test_results total=11 pass=2 fail=4 xpass=1 xfail=0 skip=2 error=2
+
+ : Let us finally make d.test pass.
+ using_gmake || $sleep # Required by BSD make.
+ echo : > d.extra
+ do_recheck --pass
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ test -f d.run
+ count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=1 error=0
+
+ : All tests have been successful or skipped, nothing should be re-run.
+ using_gmake || $sleep # Required by BSD make.
+ do_recheck --pass
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ test ! -e d.run
+ count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/test-driver-custom-multitest-recheck2.sh b/t/test-driver-custom-multitest-recheck2.sh
new file mode 100644
index 000000000..a7c391049
--- /dev/null
+++ b/t/test-driver-custom-multitest-recheck2.sh
@@ -0,0 +1,176 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Custom test drivers: try the "recheck" functionality with test protocols
+# that allow multiple testcases in a single test script. In particular,
+# check that this still works when we override $(TESTS) and $(TEST_LOGS)
+# at make runtime.
+# See also related tests 'test-driver-custom-multitest-recheck.sh' and
+# 'parallel-tests-recheck-override.sh'.
+
+. test-init.sh
+
+cp "$am_testaux_srcdir"/trivial-test-driver . \
+ || fatal_ "failed to fetch auxiliary script trivial-test-driver"
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = $(SHELL) $(srcdir)/trivial-test-driver
+TESTS = a.test b.test c.test
+END
+
+cat > a.test << 'END'
+#! /bin/sh
+echo PASS: 1
+echo PASS: 2
+: > a.run
+END
+
+cat > b.test << 'END'
+#! /bin/sh
+echo SKIP: b0
+if test -f b.ok; then
+ echo XFAIL: b1
+else
+ echo FAIL: b2
+fi
+: > b.run
+END
+
+cat > c.test << 'END'
+#! /bin/sh
+if test -f c.err; then
+ echo ERROR: xxx
+elif test -f c.ok; then
+ echo PASS: ok
+else
+ echo XPASS: xp
+fi
+: > c.run
+END
+
+chmod a+x *.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for vpath in : false; do
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+
+ : Run the tests for the first time.
+ run_make -O -e FAIL check
+ # All the test scripts should have run.
+ test -f a.run
+ test -f b.run
+ test -f c.run
+ count_test_results total=5 pass=2 fail=1 xpass=1 xfail=0 skip=1 error=0
+
+ rm -f *.run
+
+ : An empty '$(TESTS)' or '$(TEST_LOGS)' means that no test should be run.
+ for var in TESTS TEST_LOGS; do
+ run_make -O "$var=" recheck
+ count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ done
+ unset var
+
+ : a.test was successful the first time, no need to re-run it.
+ using_gmake || $sleep # Required by BSD make.
+ run_make -O TESTS=a.test recheck
+ count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+
+ : b.test failed, it should be re-run. And make it pass this time.
+ using_gmake || $sleep # Required by BSD make.
+ echo OK > b.ok
+ run_make -O TEST_LOGS=b.log recheck
+ test ! -e a.run
+ test -f b.run
+ test ! -e c.run
+ count_test_results total=2 pass=0 fail=0 xpass=0 xfail=1 skip=1 error=0
+
+ rm -f *.run
+
+ : No need to re-run a.test or b.test anymore.
+ using_gmake || $sleep # Required by BSD make.
+ run_make -O TEST_LOGS=b.log recheck
+ count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+ using_gmake || $sleep # Required by BSD make.
+ run_make -O TESTS='a.test b.test' recheck
+ count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+
+ : No need to re-run a.test anymore, but c.test should be rerun,
+ : as it contained an XPASS. And this time, make it fail with
+ : an hard error.
+ echo dummy > c.err
+ run_make -e FAIL -O TEST_LOGS='a.log c.log' recheck
+ count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=1
+ test ! -e a.run
+ test ! -e b.run
+ test -f c.run
+
+ rm -f *.run *.err
+
+ : c.test contained and hard error the last time, so it should be re-run.
+ : This time, make it pass
+ # Use 'echo', not ':'; see comments above for why.
+ using_gmake || $sleep # Required by BSD make.
+ echo dummy > c.ok
+ run_make -O TESTS='c.test a.test' recheck
+ count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
+ test ! -e a.run
+ test ! -e b.run
+ test -f c.run
+
+ rm -f *.run *.err *.ok
+
+ : Nothing should be rerun anymore, as all tests have been eventually
+ : successful.
+ using_gmake || $sleep # Required by BSD make.
+ run_make -O recheck
+ count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+ test ! -e a.run
+ test ! -e b.run
+ test ! -e c.run
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/test-driver-custom-multitest.sh b/t/test-driver-custom-multitest.sh
new file mode 100644
index 000000000..1d8353314
--- /dev/null
+++ b/t/test-driver-custom-multitest.sh
@@ -0,0 +1,168 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Custom test drivers: check that we can easily support test protocols
+# that allow multiple testcases in a single test script. This test not
+# only checks implementation details in Automake's custom test drivers
+# support, but also serves as a "usability test" for our APIs.
+
+. test-init.sh
+
+cp "$am_testaux_srcdir"/trivial-test-driver . \
+ || fatal_ "failed to fetch auxiliary script trivial-test-driver"
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_EXTENSIONS = .t
+T_LOG_DRIVER = $(SHELL) $(srcdir)/trivial-test-driver
+
+TESTS = \
+ pass.t \
+ fail.t \
+ fail2.t \
+ pass-fail.t \
+ pass4-skip.t \
+ pass3-skip2-xfail.t \
+ pass-xpass-fail-xfail-skip-error.t
+END
+
+cat > pass.t << 'END'
+echo %% pass %%
+echo PASS: pass
+END
+
+cat > fail.t << 'END'
+echo %% fail %%
+echo FAIL: fail
+END
+
+cat > fail2.t << 'END'
+echo %% fail2 %%
+echo FAIL: stdout >&1
+echo FAIL: stderr >&2
+echo :PASS: this should be ignored
+END
+
+cat > pass-fail.t << 'END'
+echo %% pass-fail %%
+echo 'FAIL: this fails :-('
+echo 'some randome message'
+echo 'some randome warning' >&2
+echo 'PASS: this passes :-)'
+echo 'INFO: blah'
+echo 'WARNING: blah blah' >&2
+END
+
+cat > pass4-skip.t << 'END'
+echo %% pass4-skip %%
+echo PASS: on stdout >&1
+echo PASS: on stderr >&2
+echo PASS: 3
+echo PASS: 4
+echo SKIP: 1
+echo this FAIL: should be ignored
+echo FAIL as should this
+exit 99
+END
+
+cat > pass3-skip2-xfail.t << 'END'
+echo %% pass4-skip2-xfail %%
+echo 'PASS: -v'
+echo 'PASS: --verbose'
+echo 'SKIP: Oops, unsupported system.'
+echo 'PASS: -#-#-#-'
+cp || echo "SKIP: cp cannot read users' mind" >&2
+mv || echo "XFAIL: mv cannot read users' mind yet"
+exit 127
+END
+
+cat > pass-xpass-fail-xfail-skip-error.t << 'END'
+echo PASS:
+echo FAIL:
+echo XFAIL:
+echo XPASS:
+echo SKIP:
+echo ERROR:
+echo %% pass-xpass-fail-xfail-skip-error %%
+END
+
+chmod a+x *.t
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+for vpath in : false; do
+ if $vpath; then
+ mkdir build
+ cd build
+ srcdir=..
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+
+ run_make -O -e FAIL check || { cat test-suite.log; exit 1; }
+ cat test-suite.log
+ # Couple of sanity checks. These might need to be updated if the
+ # 'trivial-test-driver' script is changed.
+ $FGREP INVALID.NAME stdout test-suite.log && exit 1
+ test -f BAD.LOG && exit 1
+ test -f BAD.TRS && exit 1
+ # These log files must all have been created by the testsuite.
+ cat pass.log
+ cat fail.log
+ cat fail2.log
+ cat pass-fail.log
+ cat pass4-skip.log
+ cat pass3-skip2-xfail.log
+ cat pass-xpass-fail-xfail-skip-error.log
+
+ count_test_results total=23 pass=10 fail=5 skip=4 xfail=2 xpass=1 error=1
+
+ tst=pass-xpass-fail-xfail-skip-error
+ grep "^PASS: $tst\.t, testcase 1" stdout
+ grep "^FAIL: $tst\.t, testcase 2" stdout
+ grep "^XFAIL: $tst\.t, testcase 3" stdout
+ grep "^XPASS: $tst\.t, testcase 4" stdout
+ grep "^SKIP: $tst\.t, testcase 5" stdout
+ grep "^ERROR: $tst\.t, testcase 6" stdout
+
+ # Check that the content of, and only of, the test logs with at least
+ # one failing test case has been copied into 'test-suite.log'. Note
+ # that test logs containing skipped or xfailed test cases are *not*
+ # copied into 'test-suite.log' -- a behaviour that deliberately differs
+ # from the one of the built-in Automake test drivers.
+ grep '%%' test-suite.log # For debugging.
+ grep '%% fail %%' test-suite.log
+ grep '%% fail2 %%' test-suite.log
+ grep '%% pass-fail %%' test-suite.log
+ grep '%% pass-xpass-fail-xfail-skip-error %%' test-suite.log
+ test $(grep -c '%% ' test-suite.log) -eq 4
+
+ run_make -O TESTS='pass.t pass3-skip2-xfail.t' check
+ cat test-suite.log
+ count_test_results total=7 pass=4 fail=0 skip=2 xfail=1 xpass=0 error=0
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/test-driver-custom-no-extra-driver.sh b/t/test-driver-custom-no-extra-driver.sh
new file mode 100644
index 000000000..e67cdca77
--- /dev/null
+++ b/t/test-driver-custom-no-extra-driver.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that auxiliary script 'test-driver' doesn't get needlessly
+# installed or referenced if it's not used, i.e., if the user has
+# defined his own '*LOG_DRIVER' variables.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
+AC_SUBST([X_LOG_DRIVER], [none])
+AC_OUTPUT
+END
+
+mkdir sub1 sub2
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1 sub2
+LOG_DRIVER =
+TEST_LOG_DRIVER = :
+TESTS = foo bar.test
+END
+
+cat > sub1/Makefile.am <<'END'
+TEST_EXTENSIONS = .x .sh .pl
+SH_LOG_DRIVER = dummy1
+PL_LOG_DRIVER = dummy2
+TESTS = a.pl b.sh c.x
+END
+
+cat > sub2/Makefile.am <<'END'
+TEST_EXTENSIONS = .bar
+LOG_DRIVER = x
+BAR_LOG_DRIVER = y
+TESTS = 1 2.bar 3.test 4.t 5.tt $(check_PROGRAMS)
+check_PROGRAMS = p1 p2$(EXEEXT) p3.bar p4.suf
+END
+
+$ACLOCAL
+
+for opts in '' '--add-missing' '-a -c'; do
+ $AUTOMAKE $opts
+ $FGREP test-driver Makefile.in sub[12]/Makefile.in && exit 1
+ find . | $FGREP test-driver && exit 1
+ : For shells with busted 'set -e'.
+done
+
+:
diff --git a/t/test-driver-custom-xfail-tests.sh b/t/test-driver-custom-xfail-tests.sh
new file mode 100644
index 000000000..8feb879c5
--- /dev/null
+++ b/t/test-driver-custom-xfail-tests.sh
@@ -0,0 +1,163 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Custom test drivers: "abstract" XFAIL_TESTS support.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_SUBST([nihil], [])
+AC_SUBST([ac_xfail_tests], ['x5.test x6$(test_suffix)'])
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = . sub1 sub2
+TEST_LOG_DRIVER = $(srcdir)/td
+TESTS = pass.test xfail.test
+XFAIL_TESTS = xfail.test
+END
+
+mkdir sub1 sub2
+
+cat > sub1/Makefile.am <<END
+empty =
+
+TEST_LOG_DRIVER = \$(top_srcdir)/td
+
+# XFAIL_TESTS should gracefully handle TAB characters, and multiple
+# whitespaces.
+XFAIL_TESTS =\$(empty)${tab}x1.test x2.test${tab}x3.test${tab}\
+x4.test ${tab} x5.test x6.test${tab}\$(empty)
+
+TESTS = pass.test x1.test x2.test x3.test x4.test x5.test x6.test
+END
+
+cat > sub2/Makefile.am <<'END'
+AUTOMAKE_OPTIONS = -Wno-portability-recursive
+
+TEST_LOG_DRIVER = $(srcdir)/../td
+
+# XFAIL_TESTS should gracefully AC_SUBST @substitution@ and
+# make variables indirections.
+an_xfail_test = x1.test
+test_suffix = .test
+v0 = x3.test
+v1 = v
+v2 = 0
+XFAIL_TESTS = $(an_xfail_test) x2.test @nihil@ x3${test_suffix}
+XFAIL_TESTS += $($(v1)$(v2)) x4.test @ac_xfail_tests@
+
+TESTS = pass.test x1.test x2.test x3.test x4.test x5.test x6.test
+END
+
+cat > pass.test <<'END'
+#!/bin/sh
+exit 0
+END
+
+cat > xfail.test <<'END'
+#!/bin/sh
+exit 1
+END
+
+chmod a+x pass.test xfail.test
+
+cp pass.test sub1/pass.test
+cp pass.test sub2/pass.test
+
+for i in 1 2 3 4 5 6; do
+ cp xfail.test sub1/x$i.test
+ cp xfail.test sub2/x$i.test
+done
+
+cat > td <<'END'
+#! /bin/sh
+set -e; set -u
+test_name=INVALID
+log_file=/dev/null
+trs_file=/dev/null
+expect_failure=no
+while test $# -gt 0; do
+ case $1 in
+ --test-name) test_name=$2; shift;;
+ --expect-failure) expect_failure=$2; shift;;
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ # Ignored.
+ --color-tests) shift;;
+ --enable-hard-errors) shift;;
+ # Explicitly terminate option list.
+ --) shift; break;;
+ # Shouldn't happen
+ *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
+ esac
+ shift
+done
+st=0
+"$@" || st=$?
+case $st,$expect_failure in
+ 0,no)
+ echo "PASS: $test_name" | tee "$log_file"
+ echo ":test-result: PASS" > "$trs_file"
+ ;;
+ 1,no)
+ echo "FAIL: $test_name" | tee "$log_file"
+ echo ":test-result: FAIL" > "$trs_file"
+ ;;
+ 0,yes)
+ echo "XPASS: $test_name" | tee "$log_file"
+ echo ":test-result: XPASS" > "$trs_file"
+ ;;
+ 1,yes)
+ echo "XFAIL: $test_name" | tee "$log_file"
+ echo ":test-result: XFAIL" > "$trs_file"
+ ;;
+ *)
+ echo "INTERNAL ERROR" >&2
+ exit 99
+ ;;
+esac
+END
+chmod a+x td
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+run_make -O check
+test $(grep -c '^PASS:' stdout) -eq 3
+test $(grep -c '^XFAIL:' stdout) -eq 13
+
+for dir in sub1 sub2; do
+ cd $dir
+ cp pass.test x1.test
+ cp x2.test pass.test
+ run_make -O -e FAIL check
+ test "$(cat pass.trs)" = ":test-result: FAIL"
+ test "$(cat x1.trs)" = ":test-result: XPASS"
+ test "$(cat x2.trs)" = ":test-result: XFAIL"
+ grep '^FAIL: pass\.test$' stdout
+ grep '^XPASS: x1\.test$' stdout
+ grep '^XFAIL: x2\.test$' stdout
+ count_test_results total=7 pass=0 xpass=1 fail=1 xfail=5 skip=0 error=0
+ cd ..
+done
+
+:
diff --git a/t/test-driver-custom.sh b/t/test-driver-custom.sh
new file mode 100644
index 000000000..1978139f4
--- /dev/null
+++ b/t/test-driver-custom.sh
@@ -0,0 +1,143 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Custom test drivers: per-extension test drivers.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# Automake shouldn't match the '/test' in 'sub/test' as '.test' suffix.
+TESTS = 1.chk 2.test 3 4.c.chk 5.suf sub/test
+
+TEST_EXTENSIONS = .chk .test
+
+CHK_LOG_DRIVER = ./chk-wrapper
+TEST_LOG_DRIVER = $(SHELL) $(srcdir)/test-wrapper
+LOG_DRIVER = noext-wrapper
+
+AM_CHK_LOG_DRIVER_FLAGS = --am-chk
+CHK_LOG_DRIVER_FLAGS = --chk
+AM_TEST_LOG_DRIVER_FLAGS = -am-test
+TEST_LOG_DRIVER_FLAGS = -test
+AM_LOG_DRIVER_FLAGS = am
+LOG_DRIVER_FLAGS = _
+END
+
+mkdir sub bin
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
+
+cat > wrapper.skel <<'END'
+#! /bin/sh
+set -e
+
+me=`echo "$0" | sed 's,^.*/,,'`
+if test -z "$me"; then
+ echo "$0: cannot determine program name" >&2
+ exit 99
+fi
+
+am_log_wflags='@am_log_wflags@'
+log_wflags='@log_wflags@'
+
+test_name=INVALID
+log_file=BAD.log
+trs_file=BAD.trs
+extra_opts=
+while test $# -gt 0; do
+ case $1 in
+ --test-name) test_name=$2; shift;;
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ # Ignored.
+ --expect-failure) shift;;
+ --color-tests) shift;;
+ --enable-hard-errors) shift;;
+ # Remembered in the same order they're passed in.
+ $am_log_wflags|$log_wflags) extra_opts="$extra_opts $1";;
+ # Explicitly terminate option list.
+ --) shift; break;;
+ # Shouldn't happen
+ *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
+ esac
+ shift
+done
+
+echo "$me" "$test_name" $extra_opts > "$log_file"
+: > "$trs_file"
+
+exec "$@"
+exit 127
+END
+
+sed -e 's|@am_log_wflags@|--am-chk|' \
+ -e 's|@log_wflags@|--chk|' \
+ < wrapper.skel > chk-wrapper
+
+sed -e 's|@am_log_wflags@|-am-test|' \
+ -e 's|@log_wflags@|-test|' \
+ < wrapper.skel > test-wrapper
+
+sed -e 's|@am_log_wflags@|am|' \
+ -e 's|@log_wflags@|_|' \
+ < wrapper.skel > bin/noext-wrapper
+
+# 'test-wrapper' is deliberately not made executable.
+chmod a+x chk-wrapper bin/noext-wrapper
+
+# Not needed anymore.
+rm -f wrapper.skel
+
+cat > 1.chk << 'END'
+#! /bin/sh
+exit 0
+END
+chmod a+x 1.chk
+cp 1.chk 2.test
+cp 1.chk 3
+cp 1.chk 4.c.chk
+cp 1.chk 5.suf
+cp 1.chk sub/test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+VERBOSE=yes $MAKE check
+ls -l . sub
+
+test ! -e BAD.log
+test ! -e BAD.trs
+
+echo 'chk-wrapper 1.chk --am-chk --chk' > 1.exp
+echo 'test-wrapper 2.test -am-test -test' > 2.exp
+echo 'noext-wrapper 3 am _' > 3.exp
+echo 'chk-wrapper 4.c.chk --am-chk --chk' > 4.c.exp
+echo 'noext-wrapper 5.suf am _' > 5.suf.exp
+echo 'noext-wrapper sub/test am _' > sub/test.exp
+
+st=0
+for x in 1 2 3 4.c 5.suf sub/test; do
+ cat $x.log
+ diff $x.exp $x.log || st=1
+done
+
+exit $st
diff --git a/t/test-driver-fail.sh b/t/test-driver-fail.sh
new file mode 100644
index 000000000..bb4ba2ecc
--- /dev/null
+++ b/t/test-driver-fail.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Custom test drivers: what happens when a test driver fails? Well,
+# "make check" should at least fail too, and the test-suite.log
+# shouldn't be created. Unfortunately, we cannot truly control also
+# the (non-)creation of individual test logs, since those are expected
+# to be created by the drivers themselves, and an ill-behaved driver
+# (like our dummy one in this test) might leave around a test log even
+# in case of internal failures.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+TEST_LOG_DRIVER = ./oops
+TESTS = foo.test
+END
+
+cat > foo.test <<'END'
+#! /bin/sh
+exit 0
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# The testsuite driver does not exist.
+$MAKE check && exit 1
+test ! -e test-suite.log
+
+# The testsuite driver exists and create the test log files, but fails.
+
+cat > oops <<'END'
+#!/bin/sh
+: > foo.log
+echo 'Oops, I fail!' >&2
+exit 1
+END
+chmod a+x oops
+
+$MAKE check && exit 1
+test ! -e test-suite.log
+
+:
diff --git a/t/test-driver-is-distributed.sh b/t/test-driver-is-distributed.sh
new file mode 100644
index 000000000..c78ac2538
--- /dev/null
+++ b/t/test-driver-is-distributed.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check regression of parallel-tests:
+# - 'test-driver' script not correctly distributed when TESTS is
+# defined in a subdir Makefile
+
+am_create_testdir=empty
+. test-init.sh
+
+ocwd=$(pwd) || fatal_ "getting current working directory"
+
+for i in 1 2; do
+ mkdir D$i
+ cd D$i
+ if test $i -eq 1; then
+ auxdir=.
+ test_driver=test-driver
+ else
+ auxdir=build-aux
+ test_driver=$auxdir/test-driver
+ mkdir $auxdir
+ fi
+ mkdir tests
+ unindent > configure.ac << END
+ AC_INIT([$me], [1.0])
+ AC_CONFIG_AUX_DIR([$auxdir])
+ AM_INIT_AUTOMAKE
+ AC_CONFIG_FILES([Makefile tests/Makefile])
+ AC_OUTPUT
+END
+ unindent > Makefile.am << END
+ SUBDIRS = tests
+ check-local: test-top
+ test-top: distdir
+ ls -l \$(distdir) \$(distdir)/* ;: For debugging.
+ test -f \$(distdir)/$test_driver
+ .PHONY: test-top
+END
+ unindent > tests/Makefile.am << END
+ check-local: test-sub
+ test-sub:
+ echo ' ' \$(DIST_COMMON) ' ' | grep '[ /]$test_driver '
+ TESTS = foo.test
+ EXTRA_DIST = \$(TESTS)
+END
+ unindent > tests/foo.test << 'END'
+ #!/bin/sh
+ exit 0
+END
+ chmod a+x tests/foo.test
+ $ACLOCAL
+ $AUTOCONF
+ $AUTOMAKE -a
+ ./configure
+ $MAKE test-top
+ cd tests
+ $MAKE test-sub
+ cd ..
+ $MAKE distcheck
+ # Try code path without automatic installation of required files.
+ mv -f Makefile.in Makefile.sav
+ mv -f tests/Makefile.in tests/Makefile.sav
+ $AUTOMAKE
+ diff Makefile.in Makefile.sav
+ diff tests/Makefile.in tests/Makefile.sav
+ cd "$ocwd" || fatal_ "cannot chdir back to '$ocwd'"
+done
+
+:
diff --git a/t/test-driver-strip-vpath.sh b/t/test-driver-strip-vpath.sh
new file mode 100644
index 000000000..ec3a5632c
--- /dev/null
+++ b/t/test-driver-strip-vpath.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Custom test drivers: check that the test name passed to the test
+# driver has any VPATH prefix stripped.
+
+. test-init.sh
+
+ocwd=$(pwd) || fatal_ "cannot get current working directory"
+
+mkdir src build
+mv install-sh missing configure.ac src
+rm -f depcomp
+
+cd src
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# The directories of the 'bar.test' and 'baz.test' tests are deliberately
+# called as the source directory, to verify that the VPATH-stripping code
+# doesn't get too easily confused.
+# The $(empty) are for eliciting VPATH rewrites on make implementations
+# that support it (e.g., Solaris make), to improve coverage.
+empty =
+TESTS = $(empty) foo.test src/bar.test ./src/baz.test $(empty)
+$(TESTS):
+TEST_LOG_DRIVER = $(srcdir)/checkstrip-driver
+EXTRA_DIST = checkstrip-driver
+END
+
+cat > checkstrip-driver <<'END'
+#! /bin/sh
+set -e
+while test $# -gt 0; do
+ case $1 in
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ --test-name) test_name=$2; shift;;
+ --expect-failure|--color-tests|--enable-hard-errors) shift;;
+ --) shift; break;;
+ *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
+ esac
+ shift
+done
+echo "test name: $test_name" # For debugging.
+case $test_name in
+ foo.test|./foo.test|src/ba[rz].test|./src/ba[rz].test);;
+ *) exit 1;;
+esac
+echo dummy > "$log_file"
+echo dummy > "$trs_file"
+END
+chmod a+x checkstrip-driver
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cd ..
+
+mkdir build1
+cd build1
+../src/configure
+# "$MAKE -n" is for debugging, should highlight any VPATH rewrite.
+$MAKE -n check || :
+$MAKE check
+cd ..
+
+mkdir build2
+cd build2
+"$ocwd"/src/configure
+# "$MAKE -n" is for debugging, should highlight any VPATH rewrite.
+$MAKE -n check || :
+$MAKE check
+cd ..
+
+cd src
+./configure
+$MAKE distcheck
+
+:
diff --git a/t/test-driver-trs-suffix-registered.sh b/t/test-driver-trs-suffix-registered.sh
new file mode 100644
index 000000000..74c756b68
--- /dev/null
+++ b/t/test-driver-trs-suffix-registered.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests support: the following are registered with '.SUFFIXES':
+# - .log
+# - .trs (used by files that store test results and metadata)
+# - .test if $(TEST_EXTENSIONS) is not defined
+# - stuff in $(TEST_EXTENSIONS) otherwise
+
+. test-init.sh
+
+: > Makefile.am
+
+cat > 1.am << 'END'
+TESTS =
+END
+
+cat > 2.am << 'END'
+TEST_EXTENSIONS = .SH .abcdef
+TESTS =
+END
+
+: > test-driver
+
+$ACLOCAL
+
+$AUTOMAKE 1
+$AUTOMAKE 2
+
+sed -e 's/$/ /' 1.in > mk.1
+sed -e 's/$/ /' 2.in > mk.2
+
+grep '^\.SUFFIXES:' mk.1
+grep '^\.SUFFIXES:' mk.2
+
+for suf in test log trs; do
+ grep "^\\.SUFFIXES:.* \\.$suf " mk.1
+done
+
+for suf in SH abcdef log trs; do
+ grep "^\\.SUFFIXES:.* \\.$suf " mk.2
+done
+
+:
diff --git a/t/test-extensions-cond.sh b/t/test-extensions-cond.sh
new file mode 100644
index 000000000..a558b598e
--- /dev/null
+++ b/t/test-extensions-cond.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Expose bug in conditional definition of TEST_EXTENSIONS.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_CONDITIONAL([COND], [:])
+AM_CONDITIONAL([COND2], [:])
+END
+
+$ACLOCAL
+
+cat > 1.am << 'END'
+TESTS =
+if COND
+## lineno 4
+TEST_EXTENSIONS = .foo
+endif
+END
+
+cat > 2.am << 'END'
+TESTS =
+## lineno 3
+TEST_EXTENSIONS = .foo
+if COND
+# Do nothing.
+else
+TEST_EXTENSIONS += .bar
+endif
+END
+
+cat > 3.am << 'END'
+TESTS =
+if COND
+if !COND2
+TESTS = x
+else
+## lineno 7
+TEST_EXTENSIONS = .foo
+endif
+endif
+END
+
+: > test-driver
+
+for i in 1 2 3; do
+ AUTOMAKE_fails $i
+ lineno=$(sed -n 's/^## lineno //p' $i.am) \
+ && test 0 -lt "$lineno" \
+ || exit 99
+ grep "^$i\\.am:$lineno:.*TEST_EXTENSIONS.*conditional content" stderr
+done
+
+:
diff --git a/t/test-extensions.sh b/t/test-extensions.sh
new file mode 100644
index 000000000..64ea568b3
--- /dev/null
+++ b/t/test-extensions.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that Automake diagnose invalid entries in TEST_EXTENSIONS,
+# and do not diagnose valid (albeit more unusual) ones.
+# See automake bug#9400.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+
+valid_extensions='sh T t1 _foo BAR x_Y_z _'
+
+echo TESTS = > Makefile.am
+echo " $valid_extensions" \
+ | sed -e 's/ / ./g' -e 's/^/TEST_EXTENSIONS =/' >> Makefile.am
+cat Makefile.am # For debugging.
+
+$AUTOMAKE -a
+
+grep -i 'log' Makefile.in # For debugging.
+
+for lc in $valid_extensions; do
+ uc=$(echo $lc | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ)
+ $FGREP "\$(${uc}_LOG_COMPILER)" Makefile.in
+ grep "^${uc}_LOG_COMPILE =" Makefile.in
+ grep "^\.${lc}\.log:" Makefile.in
+done
+
+# The produced Makefile is not broken.
+./configure
+$MAKE all check
+
+cat > Makefile.am << 'END'
+TESTS = foo.test bar.sh
+TEST_EXTENSIONS = .test mu .x-y a-b .t.1 .sh .6c .0 .11 .= @suf@ .@ext@
+TEST_EXTENSIONS += .= .t33 .a@b _&_
+END
+
+AUTOMAKE_fails
+for suf in mu .x-y a-b .t.1 .6c .0 .11 @suf@ .@ext@ '.=' '_&_'; do
+ suf2=$(printf '%s\n' "$suf" | sed -e 's/\./\\./')
+ $EGREP "^Makefile\.am:2:.*invalid test extension.* $suf2( |$)" stderr
+done
+
+# Verify that we accept valid suffixes, even if intermixed with
+# invalid ones.
+$EGREP '\.(sh|test|t33)' stderr && exit 1
+
+# Verify that we don't try to handle invalid suffixes.
+$EGREP '(LOG_COMPILER|non-POSIX var|bad character)' stderr && exit 1
+
+:
diff --git a/t/test-harness-vpath-rewrite.sh b/t/test-harness-vpath-rewrite.sh
new file mode 100644
index 000000000..643e6f925
--- /dev/null
+++ b/t/test-harness-vpath-rewrite.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that our concurrent test harness is not subject to spurious VPATH
+# rewrites.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+LOG_COMPILER = true
+TESTS = x0 foo bar baz x1
+EXTRA_DIST = $(TESTS)
+END
+
+: > x0
+: > foo
+: > bar
+: > baz
+: > x1
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkdir build
+cd build
+../configure
+$MAKE check
+test -f test-suite.log
+test -f foo.log
+test -f foo.trs
+test -f bar.log
+test -f bar.trs
+test -f baz.log
+test -f baz.trs
+# We don't want VPATH rewrites, really.
+$MAKE check -n | $EGREP '\.\./(foo|bar|baz)( |$)' && exit 1
+$MAKE distcheck
+
+:
diff --git a/t/test-log.sh b/t/test-log.sh
new file mode 100644
index 000000000..e450cabec
--- /dev/null
+++ b/t/test-log.sh
@@ -0,0 +1,176 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - log file creation
+# - log file removal
+# - stdout and stderr of a test script go in its log file
+# - TEST_SUITE_LOG redefinition, at either automake or make time
+# - VERBOSE environment variable support
+# Keep in sync with 'tap-log.sh'.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = pass.test skip.test xfail.test fail.test xpass.test error.test
+XFAIL_TESTS = xpass.test xfail.test
+TEST_SUITE_LOG = global.log
+END
+
+# Custom markers, for use in grepping checks.
+cmarker=::: # comment marker
+pmarker=%%% # plain maker
+
+cat > pass.test <<END
+#! /bin/sh
+echo "$pmarker pass $pmarker" >&2
+echo "# $cmarker pass $cmarker" >&2
+exit 0
+END
+
+cat > skip.test <<END
+#! /bin/sh
+echo "$pmarker skip $pmarker"
+echo "# $cmarker skip $cmarker"
+exit 77
+END
+
+cat > xfail.test <<END
+#! /bin/sh
+echo "$pmarker xfail $pmarker" >&2
+echo "# $cmarker xfail $cmarker" >&2
+exit 1
+END
+
+cat > fail.test <<END
+#! /bin/sh
+echo "$pmarker fail $pmarker"
+echo "# $cmarker fail $cmarker"
+exit 1
+END
+
+cat > xpass.test <<END
+#! /bin/sh
+echo "$pmarker xpass $pmarker" >&2
+echo "# $cmarker xpass $cmarker" >&2
+exit 0
+END
+
+cat > error.test <<END
+#! /bin/sh
+echo "$pmarker error $pmarker"
+echo "# $cmarker error $cmarker"
+exit 99
+END
+
+chmod a+x *.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+run_make -e FAIL TEST_SUITE_LOG=my.log check
+ls -l # For debugging.
+test ! -e test-suite.log
+test ! -e global.log
+test -f my.log
+st=0
+for result in pass fail xfail xpass skip error; do
+ cat $result.log # For debugging.
+ $FGREP "$pmarker $result $pmarker" $result.log || st=1
+ $FGREP "$cmarker $result $cmarker" $result.log || st=1
+done
+test $st -eq 0 || exit 1
+cat my.log # For debugging.
+for result in xfail fail xpass skip error; do
+ cat $result.log # For debugging.
+ $FGREP "$pmarker $result $pmarker" my.log || st=1
+ $FGREP "$cmarker $result $cmarker" my.log || st=1
+done
+test $($FGREP -c "$pmarker" my.log) -eq 5
+test $($FGREP -c "$cmarker" my.log) -eq 5
+
+have_rst_section ()
+{
+ eqeq=$(echo "$1" | sed 's/./=/g')
+ # Assume $1 contains no RE metacharacters.
+ sed -n "/^$1$/,/^$eqeq$/p" $2 > got
+ (echo "$1" && echo "$eqeq") > exp
+ cat exp
+ cat got
+ diff exp got
+}
+
+# Passed test scripts shouldn't be mentioned in the global log.
+$EGREP ':.*[^x]pass' my.log && exit 1
+# But failing (expectedly or not) and skipped ones should.
+have_rst_section 'SKIP: skip' my.log
+have_rst_section 'FAIL: fail' my.log
+have_rst_section 'XFAIL: xfail' my.log
+have_rst_section 'XPASS: xpass' my.log
+have_rst_section 'ERROR: error' my.log
+
+touch error2.log test-suite.log global.log
+run_make TEST_SUITE_LOG=my.log mostlyclean
+ls -l # For debugging.
+test ! -e my.log
+test ! -e pass.log
+test ! -e fail.log
+test ! -e xfail.log
+test ! -e xpass.log
+test ! -e skip.log
+test ! -e error.log
+# "make mostlyclean" shouldn't remove unrelated log files.
+test -f error2.log
+test -f test-suite.log
+test -f global.log
+
+rm -f *.log
+
+run_make -O -e FAIL check VERBOSE=yes
+cat global.log
+test ! -e my.log
+test ! -e test-suite.log
+# Check that VERBOSE causes the global testsuite log to be
+# emitted on stdout.
+out=$(cat stdout)
+log=$(cat global.log)
+case $out in *"$log"*) ;; *) exit 1;; esac
+
+touch error2.log test-suite.log my.log
+$MAKE clean
+ls -l # For debugging.
+test ! -e global.log
+test ! -e pass.log
+test ! -e fail.log
+test ! -e xfail.log
+test ! -e xpass.log
+test ! -e skip.log
+test ! -e error.log
+# "make clean" shouldn't remove unrelated log files.
+test -f error2.log
+test -f test-suite.log
+test -f my.log
+
+rm -f *.log
+
+:
diff --git a/t/test-logs-repeated.sh b/t/test-logs-repeated.sh
new file mode 100644
index 000000000..efd587a12
--- /dev/null
+++ b/t/test-logs-repeated.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel-tests features:
+# - $(TESTS_LOGS) can end up holding duplicated entries
+# Such behaviour can be useful for projects that want to verify that
+# different test scripts don't end up sharing the same log file.
+# (Automake itself is such a project, BTW ;-)
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_EXTENSIONS = .sh .test .bar
+TESTS = foo.sh mu.test foo.test foo.bar
+.PHONY: verify
+verify:
+ is $(TEST_LOGS) == foo.log mu.log foo.log foo.log
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE verify
+
+:
diff --git a/t/test-metadata-global-log.sh b/t/test-metadata-global-log.sh
new file mode 100644
index 000000000..03459b11b
--- /dev/null
+++ b/t/test-metadata-global-log.sh
@@ -0,0 +1,146 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Custom test drivers and parallel test harness: check the documented
+# semantics for deciding when the content of a test log file should be
+# copied in the global test-suite.log file. Currently, this is done
+# with the use of the reStructuredText field ':copy-in-global-log:' in
+# the associated '.trs' files.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = ./passthrough-driver
+TEST_LOG_COMPILER = $(SHELL) -e
+END
+
+cat > passthrough-driver <<'END'
+#!/bin/sh
+set -e; set -u;
+while test $# -gt 0; do
+ case $1 in
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ --test-name) test_name=$2; shift;;
+ --expect-failure|--color-tests|--enable-hard-errors) shift;;
+ --) shift; break;;
+ *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
+ esac
+ shift
+done
+echo "$test_name: RUN"
+"$@" >$log_file 2>&1 5>$trs_file
+END
+chmod a+x passthrough-driver
+
+# The ':test-result:' and ':recheck:' fields and the first line of the
+# log file should be be irrelevant for the decision of whether a test
+# output is to be copied in the 'test-suite.log'.
+
+cat > no-1.test <<END
+echo :test-result: SKIP >&5
+echo :copy-in-global-log: no >&5
+echo :test-result: FAIL >&5
+echo :test-result: XPASS >&5
+echo not seen 1
+END
+
+# In the last line, with leading and trailing whitespace in the value.
+cat > no-2.test <<END
+echo ":test-result: FAIL" >&5
+echo "not seen 2"
+echo ":recheck: yes" >&5
+echo ":copy-in-global-log:$tab $tab no $tab" >&5
+END
+
+for RES in XPASS FAIL XFAIL SKIP ERROR UNKNOWN; do
+ unindent > $RES.test <<END
+ echo :test-result: $RES >&5
+ echo :copy-in-global-log: no >&5
+ echo not seen $RES
+END
+done
+
+# In the first line, with no whitespace.
+cat > no-3.test <<END
+echo :copy-in-global-log:no >&5
+echo ":test-result: FAIL" >&5
+echo "not seen 3"
+END
+
+# Leading whitespace before the field.
+cat > no-4.test <<END
+echo ":test-result: FAIL" >&5
+echo " $tab $tab$tab :copy-in-global-log: no" >&5
+echo "not seen 4"
+END
+
+cat > yes-1.test <<END
+echo :test-result: PASS >&5
+echo :copy-in-global-log: yes >&5
+echo seen yes 1
+END
+
+# A lacking ':copy-in-global-log:' implies that the content of
+# the log file should be copied.
+cat > yes-2.test <<END
+echo :test-result: PASS >&5
+echo seen yes 2
+END
+
+# Three corner cases.
+
+cat > corn-1.test <<END
+echo seen corn 1
+echo ':copy-in-global-log:' >&5
+END
+
+cat > corn-2.test <<END
+echo seen corn 2
+echo '$tab $tab$tab' >&5
+END
+
+cat > corn-3.test <<'END'
+echo seen corn 31
+echo ':copy-in-global-log:#@%!' >&5
+echo seen corn 32
+END
+
+echo TESTS = *.test >> Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# We don't care about the exit status of "make check" here, that
+# should be checked in other tests.
+$MAKE check || :
+cat test-suite.log
+grep '^seen yes 1$' test-suite.log
+grep '^seen yes 2$' test-suite.log
+grep '^seen corn 1$' test-suite.log
+grep '^seen corn 2$' test-suite.log
+grep '^seen corn 31$' test-suite.log
+grep '^seen corn 32$' test-suite.log
+$FGREP 'not seen' test-suite.log && exit 1
+
+:
diff --git a/t/test-metadata-global-result.sh b/t/test-metadata-global-result.sh
new file mode 100644
index 000000000..83235c5d5
--- /dev/null
+++ b/t/test-metadata-global-result.sh
@@ -0,0 +1,195 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Parallel testsuite harness: check APIs for the registering the
+# "global test result" in '*.trs' files, as documented in the automake
+# manual.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_EXTENSIONS = .test .x
+TEST_LOG_DRIVER = ./dummy-driver
+X_LOG_DRIVER = ./dummy-driver
+TESTS = foo.test zar-doz.test
+END
+
+cat > dummy-driver <<'END'
+#! /bin/sh
+set -e; set -u
+while test $# -gt 0; do
+ case $1 in
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ --test-name) test_name=$2; shift;;
+ --expect-failure|--color-tests|--enable-hard-errors) shift;;
+ --) shift; break;;
+ *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
+ esac
+ shift
+done
+echo logloglog > $log_file
+cp $1 $trs_file
+END
+chmod a+x dummy-driver
+
+# Do this in a subroutine to avoid quoting problem in the backticked
+# command substitution below.
+get_escaped_line()
+{
+ sed -e 's,[$^/\\\.],\\&,g' -e 1q "$@"
+}
+
+have_result ()
+{
+ cat > exp; echo >> exp; echo logloglog >> exp
+ eline=$(get_escaped_line exp)
+ sed -n -e "/^$eline$/,/^logloglog$/p" test-suite.log > got
+ cat exp; cat got
+ diff exp got
+}
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+: Basic checks.
+
+echo :global-test-result: PASS > foo.test
+echo :global-test-result: ERROR > zar-doz.x
+
+$MAKE check
+cat test-suite.log
+
+have_result <<END
+PASS: foo
+=========
+END
+
+have_result <<END
+ERROR: zar-doz
+==============
+END
+
+: Try usage documented in the manual.
+
+echo :global-test-result: PASS/SKIP > foo.test
+echo :global-test-result: ALMOST PASSED > zar-doz.x
+
+$MAKE check
+cat test-suite.log
+
+have_result <<END
+PASS/SKIP: foo
+==============
+END
+
+have_result <<END
+ALMOST PASSED: zar-doz
+======================
+END
+
+: Fields ':test-result:' does not interfere with the global test result.
+
+cat > foo.test << 'END'
+:test-result: FAIL
+:global-test-result: PASS
+:test-result: ERROR
+END
+
+cat > zar-doz.x << 'END'
+:global-test-result: FAIL
+:test-result: SKIP
+:test-result: XFAIL
+END
+
+$MAKE check && exit 1
+cat test-suite.log
+
+have_result <<END
+PASS: foo
+=========
+END
+
+have_result <<END
+FAIL: zar-doz
+=============
+END
+
+: What happens when ':global-test-result:' is absent.
+
+cat > foo.test << 'END'
+:test-result: PASS
+:test-result: ERROR
+END
+: > zar-doz.x
+
+$MAKE check && exit 1
+cat test-suite.log
+
+have_result <<END
+RUN: foo
+========
+END
+
+have_result <<END
+RUN: zar-doz
+============
+END
+
+# Leading and trailing whitespace gets eaten/normalized.
+
+echo ":global-test-result:SKIP${tab} ${tab}${tab}" > foo.test
+echo ":global-test-result:${tab} ${tab}XFAIL ${tab} " > zar-doz.x
+
+$MAKE check
+cat test-suite.log
+
+have_result <<END
+SKIP: foo
+=========
+END
+
+have_result <<END
+XFAIL: zar-doz
+==============
+END
+
+# Whitespaces before and after ':global-test-result:' are handled OK.
+
+echo " $tab:global-test-result:PASS" > foo.test
+echo "${tab}${tab}:global-test-result:${tab} ${tab}SKIP" > zar-doz.x
+
+$MAKE check
+cat test-suite.log
+
+have_result <<END
+PASS: foo
+=========
+END
+
+have_result <<END
+SKIP: zar-doz
+=============
+END
+
+:
diff --git a/t/test-metadata-recheck.sh b/t/test-metadata-recheck.sh
new file mode 100644
index 000000000..491d56c8b
--- /dev/null
+++ b/t/test-metadata-recheck.sh
@@ -0,0 +1,164 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test the "make recheck" semantics for custom test drivers, as documented
+# in the Automake manual.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+LOG_DRIVER = ./dummy-driver
+TEST_EXTENSIONS =
+TESTS =
+END
+
+#
+# Tests to be re-run by "make recheck"
+#
+
+: > y-1
+echo "foo bar" > y-2
+echo ":recheck:" > y-3
+echo ":recheck:yes" > y-4
+echo ":recheck: who cares" > y-5
+echo ":recheck: $tab y" > y-6
+echo ":recheck: yeah!$tab$tab " > y-7
+cat > y-10 <<END
+:foo:
+:recheck: ???
+END
+cat > y-11 <<END
+:recheck: YES
+:foo:
+END
+cat > y-12 <<END
+foo
+:recheck:yes
+
+bar
+zardoz
+END
+
+echo " $tab $tab$tab :recheck: yes" > y-8
+
+# The :test-result: fields and the fist line of the log should be
+# irrelevant for the decision of whether "make recheck" should or
+# should not re-run a test.
+
+echo ":test-result: PASS" > y-100
+
+echo "PASS: y-101"
+
+cat > y-102 <<END
+PASS: y-102
+===========
+
+:test-result: PASS
+END
+
+#
+# Tests *not* to be re-run by "make recheck"
+#
+
+echo ":recheck:no" > n-1
+echo ":recheck: no " > n-2
+echo ":recheck: $tab no" > n-3
+echo ":recheck: no $tab$tab " > n-4
+cat > n-5 <<END
+:foo:
+:recheck:no
+END
+cat > n-6 <<END
+:recheck: no
+:foo:
+END
+cat > n-7 <<END
+foo
+:recheck: no$tab$tab
+
+bar
+zardoz
+END
+
+echo " $tab $tab$tab :recheck: no" > n-8
+
+# The :test-result: fields should be irrelevant for the decision of
+# whether "make recheck" should or should not re-run a test.
+cat > n-100 <<END
+:test-result: FAIL
+:test-result: XPASS
+:test-result: ERROR
+:test-result: UNKNOWN
+:recheck: no
+END
+
+rechecked=$(echo y-[0-9]*)
+
+for t in [yn]-[0-9]*; do echo $t; done \
+ | sed 's/.*/TESTS += &/' >> Makefile.am
+
+cat Makefile.am # For debugging.
+
+cat > dummy-driver <<'END'
+#!/bin/sh
+set -e; set -u
+while test $# -gt 0; do
+ case $1 in
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ --test-name) test_name=$2; shift;;
+ --expect-failure|--color-tests|--enable-hard-errors) shift;;
+ --) shift; break;;
+ *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
+ esac
+ shift
+done
+: > $test_name.run
+: > $log_file
+cp $1 $trs_file
+END
+chmod a+x dummy-driver
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# The ':test-result:' fields should be ignored by "make recheck",
+# but should cause the testsuite report to detect errors.
+$MAKE check && exit 1
+ls -l
+for t in $tests; do test -f $t.run; done
+rm -f *.run
+
+# But now the tests that actually get re-run have only ':test-result:'
+# fields indicating success, so "make recheck" must pass. Still, the
+# next "make recheck" call should still re-run the same set of tests.
+for iteration in 1 2; do
+ using_gmake || $sleep # Required by BSD make.
+ $MAKE recheck
+ ls -l
+ for t in $rechecked; do test -f $t.run; done
+ find . -name 'n-*.run' | grep . && exit 1
+ : For shells with busted 'set -e'.
+done
+
+:
diff --git a/t/test-metadata-results.sh b/t/test-metadata-results.sh
new file mode 100644
index 000000000..edfe5f5d8
--- /dev/null
+++ b/t/test-metadata-results.sh
@@ -0,0 +1,177 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Parallel testsuite harness: check APIs for the registering of test
+# results in '*.trs' files, as documented in the automake manual.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = ./dummy-driver
+TESTS = foo.test bar.test
+END
+
+cat > dummy-driver <<'END'
+#! /bin/sh
+set -e; set -u
+while test $# -gt 0; do
+ case $1 in
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ --test-name) test_name=$2; shift;;
+ --expect-failure|--color-tests|--enable-hard-errors) shift;;
+ --) shift; break;;
+ *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
+ esac
+ shift
+done
+: > $log_file
+cp $1 $trs_file
+END
+chmod a+x dummy-driver
+
+mk_check ()
+{
+ stat=0
+ case $1 in
+ -e) stat=$2; shift 2;;
+ esac
+ run_make -O -e $stat -- check
+ # Our dummy driver make no testsuite progress report.
+ grep ': .*\.test' stdout && exit 1
+ # Nor it writes to the log files.
+ test -s foo.log && exit 1
+ test -s bar.log && exit 1
+ : For 'set -e'.
+}
+
+# This must be different from the one defined in 'test/defs', as that
+# assumes that the driver does proper testsuite progress reporting.
+count_test_results ()
+{
+ total=ERR pass=ERR fail=ERR xpass=ERR xfail=ERR skip=ERR error=ERR
+ eval "$@"
+ st=0
+ grep "^# TOTAL: *$total$" stdout || rc=1
+ grep "^# PASS: *$pass$" stdout || rc=1
+ grep "^# XFAIL: *$xfail$" stdout || rc=1
+ grep "^# SKIP: *$skip$" stdout || rc=1
+ grep "^# FAIL: *$fail$" stdout || rc=1
+ grep "^# XPASS: *$xpass$" stdout || rc=1
+ grep "^# ERROR: *$error$" stdout || rc=1
+ test $st -eq 0 || exit 1
+}
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+# Basic checks. Also that that ':global-test-result:' fields and
+# "old-style" directives with format "RESULT: test-name" are now ignored.
+
+: > foo.test
+echo blah blah blah > bar.test
+mk_check
+count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+cat > foo.test <<END
+:test-global-result: PASS
+:test-result: FAIL
+END
+cat > bar.test <<END
+:test-result: SKIP
+:test-global-result: ERROR
+END
+mk_check -e FAIL
+count_test_results total=2 pass=0 fail=1 xpass=0 xfail=0 skip=1 error=0
+
+cat > foo.test <<END
+FAIL: foo.test
+:test-result: PASS
+:test-global-result: XPASS
+END
+echo ERROR: bar.test > bar.test
+mk_check
+count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+cat > foo.test <<END
+:test-global-result: SKIP
+:test-result: FAIL
+END
+cat > bar.test <<END
+:test-global-result: PASS
+END
+mk_check -e FAIL
+count_test_results total=1 pass=0 fail=1 xpass=0 xfail=0 skip=0 error=0
+
+cat > foo.test <<END
+:test-result: XFAIL
+:test-result: PASS
+:test-result: SKIP
+END
+cat > bar.test <<END
+:test-result: SKIP
+:test-result: PASS
+:test-result: SKIP
+:test-result: PASS
+:test-result: PASS
+END
+mk_check
+count_test_results total=8 pass=4 fail=0 xpass=0 xfail=1 skip=3 error=0
+
+# Check that all results expected to be supported are *really* supported.
+
+cat > foo.test <<END
+:test-result: PASS
+:test-result: SKIP
+:test-result: XFAIL
+:test-result: FAIL
+:test-result: XPASS
+:test-result: ERROR
+END
+: > bar.test
+mk_check -e FAIL
+count_test_results total=6 pass=1 fail=1 xpass=1 xfail=1 skip=1 error=1
+
+cp foo.test bar.test
+mk_check -e FAIL
+count_test_results total=12 pass=2 fail=2 xpass=2 xfail=2 skip=2 error=2
+
+# Check that we are liberal w.r.t. whitespace use.
+
+: > foo.test
+: > bar.test
+for RESULT in PASS FAIL XPASS XFAIL SKIP ERROR; do
+ sed -e 's/^ *//' -e 's/|//g' >> foo.test <<END
+ |:test-result:$RESULT|
+ |:test-result: $tab $RESULT|
+ |:test-result:$RESULT $tab|
+ |:test-result:$tab$tab $RESULT$tab $tab |
+END
+ echo " $tab $tab$tab :test-result: $RESULT" >> bar.test
+done
+cat foo.test # For debugging.
+cat bar.test # Likewise.
+mk_check -e FAIL
+count_test_results total=30 pass=5 fail=5 xpass=5 xfail=5 skip=5 error=5
+
+:
diff --git a/t/test-missing.sh b/t/test-missing.sh
new file mode 100644
index 000000000..c828e5b4a
--- /dev/null
+++ b/t/test-missing.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests:
+# - non-existent scripts listed in TESTS get diagnosed
+# See also related test 'test-missing2.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = ok.test zardoz.test
+TEST_LOG_COMPILER = true
+END
+
+: > ok.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+run_make -e FAIL -M check
+test -f ok.log
+grep '^PASS: ok\.test' output
+$FGREP 'zardoz.log' output
+test ! -e test-suite.log
+
+run_make -M -e FAIL TESTS='zardoz2.test' check
+$FGREP 'zardoz2.log' output
+test ! -e test-suite.log
+
+run_make -M -e FAIL TEST_LOGS='zardoz3.log' check
+$FGREP 'zardoz3.log' output
+test ! -e test-suite.log
+
+# The errors should persist even after 'test-suite.log'
+# has been created.
+
+: > zardoz.test
+$MAKE check
+rm -f zardoz.test
+
+run_make -M -e FAIL check
+$FGREP 'zardoz.log' output
+test ! -e test-suite.log
+
+:
diff --git a/t/test-missing2.sh b/t/test-missing2.sh
new file mode 100644
index 000000000..efaff8d47
--- /dev/null
+++ b/t/test-missing2.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests:
+# - non-existent scripts listed in TESTS get diagnosed, even when
+# all the $(TEST_LOGS) have a dummy dependency.
+# See also related test 'test-missing.sh'.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foobar1.test foobar2.test
+$(TEST_LOGS):
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE foobar1.log foobar2.log || exit 99
+test ! -e foobar1.log || exit 99
+test ! -e foobar1.trs || exit 99
+test ! -e foobar2.log || exit 99
+test ! -e foobar2.trs || exit 99
+
+run_make -e FAIL -M check
+grep 'test-suite\.log.*foobar1\.log' output
+grep 'test-suite\.log.*foobar1\.trs' output
+grep 'test-suite\.log.*foobar2\.log' output
+grep 'test-suite\.log.*foobar2\.trs' output
+test ! -e test-suite.log
+
+:
diff --git a/t/test-trs-basic.sh b/t/test-trs-basic.sh
new file mode 100644
index 000000000..e734580ea
--- /dev/null
+++ b/t/test-trs-basic.sh
@@ -0,0 +1,157 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel harness features:
+# - creation and removal of '.trs' auxiliary files
+# - check some internals regarding the use of '.trs' files.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_EXTENSIONS = .sh .test
+TESTS = foo.test bar.sh sub/zardoz.test
+TEST_LOG_COMPILER = $(SHELL)
+SH_LOG_COMPILER = $(SHELL)
+
+## Used to check some internal details. And yes, the quotes around
+## '$bases' are deliberate: they check for whitespace normalization.
+tb:
+ $(am__set_TESTS_bases); echo "$$bases" > $@
+END
+
+cat > foo.test << 'END'
+#! /bin/sh
+exit $FOO_STATUS
+END
+: > bar.sh
+mkdir sub
+: > sub/zardoz.test
+
+FOO_STATUS=0; export FOO_STATUS
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+
+#
+# Check some internal details first.
+#
+
+for vpath in : false; do
+
+ if $vpath; then
+ srcdir=..
+ mkdir build
+ cd build
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+
+ $MAKE tb
+ test x"$(cat tb)" = x"foo bar sub/zardoz"
+ rm -f tb
+ # Please don't change the order of the stuff in TESTS, below.
+ run_make TESTS='foo.test foo2.sh foo-log foolog.test a.log.b.sh 0.exe' tb
+ test x"$(cat tb)" = x"foo foo2 foo-log foolog a.log.b 0.exe"
+ rm -f tb
+
+ cd $srcdir
+
+done
+
+#
+# The 'test-suite.stamp' file and the '.trs' files get created by
+# "make check" and removed by "make clean" and "make mostlyclean".
+#
+
+: > unrelated.trs
+: > sub/foo.trs
+
+$MAKE check
+test -f foo.trs
+test -f bar.trs
+test -f sub/zardoz.trs
+$MAKE clean
+test ! -e foo.trs
+test ! -e bar.trs
+test ! -e sub/zardoz.trs
+# Unrelated '.trs' files shouldn't be removed.
+test -f unrelated.trs
+test -f sub/foo.trs
+
+# The files should be properly created in case of testsuite failure too.
+FOO_STATUS=1 $MAKE check && exit 1
+test -f foo.trs
+test -f bar.trs
+test -f sub/zardoz.trs
+$MAKE mostlyclean
+test ! -e foo.trs
+test ! -e bar.trs
+test ! -e sub/zardoz.trs
+# Unrelated '.trs' files shouldn't be removed.
+test -f unrelated.trs
+test -f sub/foo.trs
+
+#
+# Try with a subset of TESTS.
+#
+
+run_make TESTS=foo.test check
+test -f foo.trs
+test ! -e bar.trs
+test ! -e sub/zardoz.trs
+$MAKE clean
+test ! -e foo.trs
+run_make TESTS='foo.test bar.sh' check
+test -f foo.trs
+test -f bar.trs
+test ! -e sub/zardoz.trs
+# "make clean" shouldn't remove '.trs' files for tests not in $(TESTS).
+run_make TESTS=bar.sh clean
+test -f foo.trs
+test ! -e bar.trs
+
+$MAKE clean
+
+#
+# Try with a subset of TEST_LOGS.
+#
+
+run_make TEST_LOGS=sub/zardoz.log check
+test ! -e foo.trs
+test ! -e bar.trs
+test -f sub/zardoz.trs
+$MAKE clean
+test ! -e sub/zardoz.trs
+run_make TEST_LOGS='foo.log bar.log' check
+test -f foo.trs
+test -f bar.trs
+test ! -e sub/zardoz.trs
+# "make clean" shouldn't remove '.trs' files for tests whose log
+# is not in $(TEST_LOGS).
+run_make TEST_LOGS=foo.log clean
+test ! -e foo.trs
+test -f bar.trs
+test ! -e sub/zardoz.trs
+
+:
diff --git a/t/test-trs-recover.sh b/t/test-trs-recover.sh
new file mode 100644
index 000000000..17169f266
--- /dev/null
+++ b/t/test-trs-recover.sh
@@ -0,0 +1,161 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel harness features:
+# - recovery from deleted '.trs' files, in various scenarios
+# This test is complex and tricky, but that's acceptable since we are
+# testing semantics that are potentially complex and tricky.
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test bar.test baz.test
+TEST_LOG_COMPILER = $(SHELL)
+END
+
+echo 'exit $TEST_STATUS' > foo.test
+echo 'exit $TEST_STATUS' > bar.test
+: > baz.test
+
+TEST_STATUS=0; export TEST_STATUS
+
+# Slower and possible overkill in some situations, but also clearer
+# and safer.
+update_stamp () { $sleep && touch stamp && $sleep; }
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+: Create the required log files.
+$MAKE check
+
+: Recreate by hand.
+rm -f foo.trs bar.trs baz.trs
+$MAKE foo.trs
+test -f foo.trs
+test ! -e bar.trs
+test ! -e baz.trs
+
+: Recreate by hand, several at the same time.
+rm -f foo.trs bar.trs baz.trs
+$MAKE foo.trs bar.trs
+test -f foo.trs
+test -f bar.trs
+test ! -e baz.trs
+
+: Recreate by hand, with a failing test.
+rm -f foo.trs bar.trs
+run_make -O TEST_STATUS=1 bar.trs baz.trs
+test ! -e foo.trs
+test -f bar.trs
+test -f baz.trs
+grep '^FAIL: bar\.test' stdout
+$EGREP '^(baz|foo)\.test' stdout && exit 1
+
+: Recreate with a sweeping "make check", and ensure that also up-to-date
+: '.trs' files are remade.
+update_stamp
+rm -f foo.trs bar.trs
+$MAKE check
+test -f foo.trs
+test -f bar.trs
+is_newest baz.trs stamp
+
+: Recreate with a sweeping "make check" with failing tests. Again,
+: ensure that also up-to-date '.trs' files are remade -- this time we
+: grep the "make check" output verify that.
+rm -f foo.trs bar.trs
+run_make -O -e FAIL TEST_STATUS=1 check
+test -f foo.trs
+test -f bar.trs
+grep '^FAIL: foo\.test' stdout
+grep '^FAIL: bar\.test' stdout
+grep '^PASS: baz\.test' stdout
+
+: Recreate with a "make check" with redefined TESTS.
+rm -f foo.trs bar.trs baz.trs
+run_make TESTS=foo.test check
+test -f foo.trs
+test ! -e bar.trs
+test ! -e baz.trs
+
+: Recreate with a "make check" with redefined TEST_LOGS.
+rm -f foo.trs bar.trs baz.trs
+run_make TEST_LOGS=bar.log check
+test ! -e foo.trs
+test -f bar.trs
+test ! -e baz.trs
+
+: Interactions with "make recheck" are OK.
+rm -f foo.trs bar.trs baz.log baz.trs
+run_make -O recheck
+test -f foo.trs
+test -f bar.trs
+test ! -e baz.trs
+test ! -e baz.log
+grep '^PASS: foo\.test' stdout
+grep '^PASS: bar\.test' stdout
+grep 'baz\.test' stdout && exit 1
+count_test_results total=2 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=0
+
+: Setup for the next check.
+$MAKE check
+test -f foo.trs
+test -f bar.trs
+test -f baz.trs
+
+: Recreate by remaking the global test log, and ensure that up-to-date
+: '.trs' files are *not* remade.
+update_stamp
+rm -f foo.trs bar.trs test-suite.log
+run_make -O test-suite.log
+grep '^PASS: foo\.test' stdout
+grep '^PASS: bar\.test' stdout
+grep 'baz\.test' stdout && exit 1
+stat *.trs *.log stamp || : # For debugging.
+# Check that make has updated what it needed to, but no more.
+test -f foo.trs
+test -f bar.trs
+is_newest stamp baz.trs
+is_newest test-suite.log foo.trs bar.trs
+
+: Setup for the next check.
+$MAKE check
+test -f foo.trs
+test -f bar.trs
+test -f baz.trs
+
+: Interactions with lazy test reruns are OK.
+rm -f foo.trs
+update_stamp
+touch bar.test
+run_make -O RECHECK_LOGS= check
+# Check that make has updated what it needed to, but no more.
+test -f foo.trs
+is_newest bar.trs bar.test
+is_newest stamp baz.trs
+grep '^PASS: foo\.test' stdout
+grep '^PASS: bar\.test' stdout
+grep 'baz\.test' stdout && exit 1
+
+:
diff --git a/t/test-trs-recover2.sh b/t/test-trs-recover2.sh
new file mode 100644
index 000000000..e72f314ca
--- /dev/null
+++ b/t/test-trs-recover2.sh
@@ -0,0 +1,118 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check parallel harness features:
+# - recovery from unreadable '.trs' files, in various scenarios
+
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test bar.test
+TEST_LOG_COMPILER = true
+END
+
+: > foo.test
+: > bar.test
+
+TEST_STATUS=0; export TEST_STATUS
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+: > t
+chmod a-r t && test ! -r t || skip_ "you can still read unreadable files"
+rm -f t
+
+: Create the required log files.
+$MAKE check
+test -f foo.trs
+test -f bar.trs
+
+: Recreate with a sweeping "make check".
+chmod a-r bar.trs
+$MAKE check
+test -f foo.trs
+test -r foo.trs
+test -f bar.trs
+test -r bar.trs
+
+: Again, this time with one .trs file missing and the other
+: one unreadable.
+rm -f foo.trs
+chmod a-r bar.trs
+$MAKE check
+test -f foo.trs
+test -r foo.trs
+test -f bar.trs
+test -r bar.trs
+
+: Again, but using "make recheck" this time.
+rm -f foo.trs
+chmod a-r bar.trs
+run_make -O recheck
+test -f foo.trs
+test -r foo.trs
+test -f bar.trs
+test -r bar.trs
+grep '^PASS: foo\.test' stdout
+grep '^PASS: bar\.test' stdout
+
+: Recreate by remaking the global test log.
+chmod a-r foo.trs
+rm -f test-suite.log
+run_make -O test-suite.log
+test -f foo.trs
+test -r foo.trs
+grep '^PASS: foo\.test' stdout
+grep 'bar\.test' stdout && exit 1
+# Also test that have only run before should be counted in the final
+# testsuite summary.
+grep '^# TOTAL: *2$' stdout
+
+: Setup for the next check.
+: > baz.test
+sed 's/^TESTS =.*/& baz.test/' Makefile > t
+diff t Makefile && exit 99
+mv -f t Makefile
+$MAKE check
+test -f foo.trs
+test -f bar.trs
+test -f baz.trs
+
+: Interactions with lazy test reruns are OK.
+chmod a-r foo.trs
+$sleep
+touch stamp
+$sleep
+touch bar.test
+run_make -O RECHECK_LOGS= check
+test -r foo.trs
+is_newest bar.trs bar.test
+grep '^PASS: foo\.test' stdout
+grep '^PASS: bar\.test' stdout
+grep 'baz\.test' stdout && exit 1
+# Also test that have only run before should be counted in the final
+# testsuite summary.
+grep '^# TOTAL: *3$' stdout
+
+:
diff --git a/t/tests-environment-and-log-compiler.sh b/t/tests-environment-and-log-compiler.sh
new file mode 100644
index 000000000..596b6a14f
--- /dev/null
+++ b/t/tests-environment-and-log-compiler.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# parallel-tests: check that we can use variables and functions set
+# by TESTS_ENVIRONMENT and AM_TESTS_ENVIRONMENT in LOG_COMPILER and
+# LOG_FLAGS (for tests both with and without registered extensions).
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+unset v0 v1 v2 v3 v4
+
+cat > Makefile.am << 'END'
+TESTS_ENVIRONMENT = am__f3 () { echo 3; }; v0='$(srcdir)' v1=1; :;
+AM_TESTS_ENVIRONMENT = v2=2; v4=4 && am__f5 () { echo 5; }; :;
+
+LOG_COMPILER = $$v0/log-compiler $$v1
+AM_LOG_FLAGS = $$v2 `am__f3`
+LOG_FLAGS = $$v4 `am__f5`
+
+TEST_LOG_COMPILER = $$v0/test-log-compiler $$v2
+AM_TEST_LOG_FLAGS = `am__f5` $$v1
+TEST_LOG_FLAGS = $$v4 `am__f3`
+
+EXTRA_DIST = log-compiler test-log-compiler
+
+TESTS = a b.test
+$(TESTS):
+END
+
+cat > log-compiler << 'END'
+#! /bin/sh
+echo "$0: $*"
+test x"$1$2$3$4$5" = x"12345"
+END
+
+cat > test-log-compiler << 'END'
+#! /bin/sh
+echo "$0: $*"
+test x"$1$2$3$4$5" = x"25143"
+END
+
+chmod a+x test-log-compiler log-compiler
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE -n check || : # For debugging.
+VERBOSE=yes $MAKE check
+cat a.log
+cat b.log
+
+VERBOSE=yes $MAKE distcheck
+
+:
diff --git a/t/tests-environment-backcompat.sh b/t/tests-environment-backcompat.sh
new file mode 100644
index 000000000..5ad3f1942
--- /dev/null
+++ b/t/tests-environment-backcompat.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# With old serial testsuite driver, TESTS_ENVIRONMENT can be used to
+# define the "test runner", i.e. the program that the test scripts must
+# be run by (with the parallel test harness one should use LOG_COMPILER
+# for this). The behaviour tested here is also documented in the manual.
+
+am_serial_tests=yes
+. test-init.sh
+
+cat >> configure.ac <<END
+AC_SUBST([PERL], ['$PERL'])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
+TESTS = foo.pl bar.pl baz.pl
+XFAIL_TESTS = baz.pl
+EXTRA_DIST = $(TESTS)
+END
+
+echo 'exit (0);' > foo.pl
+echo 'exit (0);' > bar.pl
+
+cat > baz.pl << 'END'
+# With "use strict" enacted, this will cause an error, since the
+# variable '$x' is not declared with 'my' nor specified with an
+# explicit package name.
+$x = 0;
+exit ($x);
+END
+
+chmod a+x *.pl
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/t/tests-environment-fd-redirect.sh b/t/tests-environment-fd-redirect.sh
new file mode 100644
index 000000000..8af35c789
--- /dev/null
+++ b/t/tests-environment-fd-redirect.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for a behaviour of 'TESTS_ENVIRONMENT' and 'AM_TESTS_ENVIRONMENT'
+# w.r.t. file descriptor redirections which, although undocumented,
+# is nonetheless required by Gnulib's 'tests/init.sh' and by coreutils'
+# testsuite.
+# The checked behaviour is that we can portably do file descriptor
+# redirections by placing them at the end of a {AM_,}TESTS_ENVIRONMENT
+# definition without a following semicolon. The need to support this
+# is detailedly motivated by coreutils bug#8846:
+# <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=8846>
+# and the following CC:ed thread on bug-autoconf list:
+# <https://lists.gnu.org/archive/html/bug-autoconf/2011-06/msg00002.html>
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+# Use both a shell script and a perl script as tests,
+# for better coverage.
+
+cat >foo.test <<'END'
+#! /bin/sh
+set -e
+echo " " $0: foofoofoo >&8
+echo " " $0: barbarbar >&9
+END
+
+echo "#! $PERL -w" > bar.test
+cat >>bar.test <<'END'
+use warnings FATAL => 'all';
+use strict;
+open(FD8, ">&=8") or die "$!";
+open(FD9, ">&=9") or die "$!";
+print FD8 " $0: 8888\n";
+print FD9 " $0: 9999\n";
+END
+
+chmod a+x foo.test bar.test
+
+$ACLOCAL
+$AUTOCONF
+
+# Korn Shells seem more vulnerable to the issue highlighted in coreutils
+# bug#8846 than other shells are. In particular, the default Korn Shell
+# on Debian GNU/Linux is affected by the issue. So let's try to run our
+# test with a system Korn Shell too, if that's available.
+bin_ksh=:
+case $SHELL in
+ ksh|*/ksh) ;;
+ *) for d in /bin /usr/bin; do
+ test -f $d/ksh && { bin_ksh=$d/ksh; break; }
+ done;;
+esac
+
+for sh in "$SHELL" "$bin_ksh"; do
+ test "$sh" = : && continue
+ for pfx in AM_ ''; do
+ unindent > Makefile.am <<END
+ TESTS = foo.test bar.test
+ ## No trailing semicolon here, *deliberately*.
+ ${pfx}TESTS_ENVIRONMENT = 8>&1 9>&8
+END
+ $AUTOMAKE -a
+ CONFIG_SHELL="$sh" $sh ./configure CONFIG_SHELL="$sh"
+ run_make -O VERBOSE=y check
+ grep '[ /]foo\.test: foofoofoo$' stdout
+ grep '[ /]foo\.test: barbarbar$' stdout
+ grep '[ /]bar\.test: 8888$' stdout
+ grep '[ /]bar\.test: 9999$' stdout
+ $EGREP '(foofoofoo|barbarbar|8888|9999)' foo.log && exit 1
+ : # For shells with buggy 'set -e'.
+ done
+done
+
+:
diff --git a/t/tests-environment.sh b/t/tests-environment.sh
new file mode 100644
index 000000000..74a061a3f
--- /dev/null
+++ b/t/tests-environment.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# "Simple Tests" testsuite driver: check TESTS_ENVIRONMENT support.
+
+am_serial_tests=yes
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TESTS = foo.test
+EXTRA_DIST = $(TESTS)
+END
+
+cat > foo.test << 'END'
+#! /bin/sh
+test x"$FOO" = x"ok"
+END
+chmod a+x foo.test
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+FOO=bad TESTS_ENVIRONMENT='FOO=ok' $MAKE check
+FOO=ok TESTS_ENVIRONMENT='FOO=bad' $MAKE check && exit 1
+
+:
diff --git a/t/testsuite-summary-color.sh b/t/testsuite-summary-color.sh
new file mode 100644
index 000000000..5ea69217e
--- /dev/null
+++ b/t/testsuite-summary-color.sh
@@ -0,0 +1,197 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check coloring of the testsuite summary.
+
+. test-lib.sh
+
+use_colors=yes; use_vpath=no
+. testsuite-summary-checks.sh
+
+./configure
+
+# ANSI colors.
+red=''
+grn=''
+lgn=''
+blu=''
+mgn=''
+brg='';
+std='';
+
+success_header="\
+${grn}${br}${std}
+${grn}Testsuite summary for GNU AutoFoo 7.1${std}
+${grn}${br}${std}"
+
+success_footer=${grn}${br}${std}
+
+failure_header="\
+${red}${br}${std}
+${red}Testsuite summary for GNU AutoFoo 7.1${std}
+${red}${br}${std}"
+
+failure_footer="\
+${red}${br}${std}
+${red}See ./test-suite.log${std}
+${red}Please report to bug-automake@gnu.org${std}
+${red}${br}${std}"
+
+do_check '' <<END
+$success_header
+# TOTAL: 0
+# PASS: 0
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+do_check pass.t <<END
+$success_header
+${brg}# TOTAL: 1${std}
+${grn}# PASS: 1${std}
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+do_check skip.t <<END
+$success_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+${blu}# SKIP: 1${std}
+# XFAIL: 0
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+do_check xfail.t <<END
+$success_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+# SKIP: 0
+${lgn}# XFAIL: 1${std}
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+do_check fail.t <<END
+$failure_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+# SKIP: 0
+# XFAIL: 0
+${red}# FAIL: 1${std}
+# XPASS: 0
+# ERROR: 0
+$failure_footer
+END
+
+do_check xpass.t <<END
+$failure_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 0
+${red}# XPASS: 1${std}
+# ERROR: 0
+$failure_footer
+END
+
+do_check error.t <<END
+$failure_header
+${brg}# TOTAL: 1${std}
+# PASS: 0
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 0
+# XPASS: 0
+${mgn}# ERROR: 1${std}
+$failure_footer
+END
+
+do_check pass.t xfail.t skip.t <<END
+$success_header
+${brg}# TOTAL: 3${std}
+${grn}# PASS: 1${std}
+${blu}# SKIP: 1${std}
+${lgn}# XFAIL: 1${std}
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+do_check pass.t fail.t skip.t <<END
+$failure_header
+${brg}# TOTAL: 3${std}
+${grn}# PASS: 1${std}
+${blu}# SKIP: 1${std}
+# XFAIL: 0
+${red}# FAIL: 1${std}
+# XPASS: 0
+# ERROR: 0
+$failure_footer
+END
+
+do_check pass.t xfail.t xpass.t <<END
+$failure_header
+${brg}# TOTAL: 3${std}
+${grn}# PASS: 1${std}
+# SKIP: 0
+${lgn}# XFAIL: 1${std}
+# FAIL: 0
+${red}# XPASS: 1${std}
+# ERROR: 0
+$failure_footer
+END
+
+do_check skip.t xfail.t error.t <<END
+$failure_header
+${brg}# TOTAL: 3${std}
+# PASS: 0
+${blu}# SKIP: 1${std}
+${lgn}# XFAIL: 1${std}
+# FAIL: 0
+# XPASS: 0
+${mgn}# ERROR: 1${std}
+$failure_footer
+END
+
+do_check pass.t skip.t xfail.t fail.t xpass.t error.t <<END
+$failure_header
+${brg}# TOTAL: 6${std}
+${grn}# PASS: 1${std}
+${blu}# SKIP: 1${std}
+${lgn}# XFAIL: 1${std}
+${red}# FAIL: 1${std}
+${red}# XPASS: 1${std}
+${mgn}# ERROR: 1${std}
+$failure_footer
+END
+
+:
diff --git a/t/testsuite-summary-count-many.sh b/t/testsuite-summary-count-many.sh
new file mode 100644
index 000000000..ed23a7a79
--- /dev/null
+++ b/t/testsuite-summary-count-many.sh
@@ -0,0 +1,102 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check test counts in the testsuite summary, with test drivers allowing
+# multiple test results per test script, and for a huge number of tests.
+# Incidentally, this test also checks that the testsuite summary doesn't
+# give any bug-report address if it's not defined.
+
+. test-init.sh
+
+for s in trivial-test-driver extract-testsuite-summary.pl; do
+ cp "$am_testaux_srcdir/$s" . || fatal_ "failed to fetch auxiliary script $s"
+done
+
+br='============================================================================'
+
+header="\
+${br}
+Testsuite summary for $me 1.0
+${br}"
+
+footer="\
+${br}
+See ./test-suite.log
+${br}"
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+TEST_LOG_DRIVER = $(SHELL) $(srcdir)/trivial-test-driver
+TESTS = all.test
+# Without this, the test driver will be horrendously slow.
+END
+
+cat > all.test <<'END'
+#!/bin/sh
+cat results.txt || { echo ERROR: weird; exit 99; }
+END
+chmod a+x all.test
+
+$PERL -w -e '
+ use warnings FATAL => "all";
+ use strict;
+
+ my $base = 1000;
+ my %count = (
+ TOTAL => $base * 1000,
+ PASS => $base * 700,
+ SKIP => $base * 200,
+ XFAIL => $base * 80,
+ FAIL => $base * 10,
+ XPASS => $base * 7,
+ ERROR => $base * 3,
+ );
+ my @results = qw/PASS SKIP XFAIL FAIL XPASS ERROR/;
+
+ open (RES, ">results.txt") or die "opening results.txt: $!\n";
+ open (CNT, ">count.txt") or die "opening count.txt: $!\n";
+
+ printf CNT "# %-6s %d\n", "TOTAL:", $count{TOTAL};
+ for my $res (@results)
+ {
+ my $uc_res = uc $res;
+ print STDERR "Generating list of $res ...\n";
+ for (1..$count{$res})
+ {
+ print RES "$uc_res: $_\n";
+ }
+ printf CNT "# %-6s %d\n", $res . ":", $count{$res};
+ }
+'
+
+(echo "$header" && cat count.txt && echo "$footer") > summary.exp
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+./configure
+
+($MAKE check || touch make.fail) | tee stdout
+test -f make.fail
+
+$PERL extract-testsuite-summary.pl stdout > summary.got
+cat summary.exp
+cat summary.got
+diff summary.exp summary.got || exit 1
+
+:
diff --git a/t/testsuite-summary-count.sh b/t/testsuite-summary-count.sh
new file mode 100644
index 000000000..bd2454506
--- /dev/null
+++ b/t/testsuite-summary-count.sh
@@ -0,0 +1,159 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check test counts in the testsuite summary.
+
+. test-lib.sh
+
+use_colors=no; use_vpath=no
+. testsuite-summary-checks.sh
+
+./configure
+
+header="\
+${br}
+Testsuite summary for GNU AutoFoo 7.1
+${br}"
+
+success_footer=${br}
+
+failure_footer="\
+${br}
+See ./test-suite.log
+Please report to bug-automake@gnu.org
+${br}"
+
+# Corner cases.
+
+do_check '' <<END
+$header
+# TOTAL: 0
+# PASS: 0
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+do_check pass.t <<END
+$header
+# TOTAL: 1
+# PASS: 1
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+do_check fail.t <<END
+$header
+# TOTAL: 1
+# PASS: 0
+# SKIP: 0
+# XFAIL: 0
+# FAIL: 1
+# XPASS: 0
+# ERROR: 0
+$failure_footer
+END
+
+# Some simpler checks, with low or moderate number of tests.
+
+do_check skip.t skip2.t skip3.t xfail.t xfail2.t <<END
+$header
+# TOTAL: 5
+# PASS: 0
+# SKIP: 3
+# XFAIL: 2
+# FAIL: 0
+# XPASS: 0
+# ERROR: 0
+$success_footer
+END
+
+do_check pass.t pass2.t xfail.t xpass.t error.t error2.t <<END
+$header
+# TOTAL: 6
+# PASS: 2
+# SKIP: 0
+# XFAIL: 1
+# FAIL: 0
+# XPASS: 1
+# ERROR: 2
+$failure_footer
+END
+
+pass_count=22
+skip_count=19
+xfail_count=21
+fail_count=18
+xpass_count=23
+error_count=17
+tests_count=120
+
+ pass=$(seq_ 1 $pass_count | sed 's/.*/pass-&.t/')
+ skip=$(seq_ 1 $skip_count | sed 's/.*/skip-&.t/')
+xfail=$(seq_ 1 $xfail_count | sed 's/.*/xfail-&.t/')
+ fail=$(seq_ 1 $fail_count | sed 's/.*/fail-&.t/')
+xpass=$(seq_ 1 $xpass_count | sed 's/.*/xpass-&.t/')
+error=$(seq_ 1 $error_count | sed 's/.*/error-&.t/')
+
+do_check $pass $skip $xfail $fail $xpass $error <<END
+$header
+# TOTAL: $tests_count
+# PASS: $pass_count
+# SKIP: $skip_count
+# XFAIL: $xfail_count
+# FAIL: $fail_count
+# XPASS: $xpass_count
+# ERROR: $error_count
+$failure_footer
+END
+
+# Mild stress test with a lot of test scripts.
+
+tests_count=1888
+pass_count=1403
+skip_count=292
+xfail_count=41
+fail_count=126
+xpass_count=17
+error_count=9
+
+ pass=$(seq_ 1 $pass_count | sed 's/.*/pass-&.t/')
+ skip=$(seq_ 1 $skip_count | sed 's/.*/skip-&.t/')
+xfail=$(seq_ 1 $xfail_count | sed 's/.*/xfail-&.t/')
+ fail=$(seq_ 1 $fail_count | sed 's/.*/fail-&.t/')
+xpass=$(seq_ 1 $xpass_count | sed 's/.*/xpass-&.t/')
+error=$(seq_ 1 $error_count | sed 's/.*/error-&.t/')
+
+do_check $pass $skip $xfail $fail $xpass $error <<END
+$header
+# TOTAL: $tests_count
+# PASS: $pass_count
+# SKIP: $skip_count
+# XFAIL: $xfail_count
+# FAIL: $fail_count
+# XPASS: $xpass_count
+# ERROR: $error_count
+$failure_footer
+END
+
+:
diff --git a/t/testsuite-summary-reference-log.sh b/t/testsuite-summary-reference-log.sh
new file mode 100644
index 000000000..92ab4d007
--- /dev/null
+++ b/t/testsuite-summary-reference-log.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the global testsuite log file referenced in the testsuite
+# summary and in the global testsuite log itself is correct.
+
+. test-init.sh
+
+mv configure.ac configure.stub
+
+cat > fail << 'END'
+#!/bin/sh
+exit 1
+END
+chmod a+x fail
+
+cat configure.stub - > configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_SUITE_LOG = my_test_suite.log
+TESTS = fail
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkdir build
+cd build
+
+../configure
+
+run_make -O -e FAIL check
+grep '^See \./my_test_suite\.log$' stdout
+
+mkdir bar
+run_make -O -e FAIL TEST_SUITE_LOG=bar/bar.log check
+grep '^See \./bar/bar\.log$' stdout
+
+cd ..
+
+echo SUBDIRS = sub > Makefile.am
+mkdir sub
+echo TESTS = fail > sub/Makefile.am
+mv fail sub
+
+cat configure.stub - > configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+$ACLOCAL --force
+$AUTOCONF --force
+$AUTOMAKE
+
+./configure
+run_make -O -e FAIL check
+grep '^See sub/test-suite\.log$' stdout
+cd sub
+run_make -O -e FAIL check
+grep '^See sub/test-suite\.log$' stdout
+cd ..
+
+run_make -O -e FAIL TEST_SUITE_LOG=foo.log check
+grep '^See sub/foo\.log$' stdout
+
+:
diff --git a/t/transform.sh b/t/transform.sh
new file mode 100644
index 000000000..94cc2a13f
--- /dev/null
+++ b/t/transform.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that --program-transform works.
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'EOF'
+bin_PROGRAMS = h
+bin_SCRIPTS = h.sh
+man_MANS = h.1
+
+.PHONY: test-install
+test-install: install
+ test -f inst/bin/gnu-h$(EXEEXT)
+ test -f inst/bin/gnu-h.sh
+ test -f inst/man/man1/gnu-h.1
+EOF
+
+cat >h.c <<'EOF'
+int main (void)
+{
+ return 0;
+}
+EOF
+
+: > h.sh
+: > h.1
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+./configure --program-prefix=gnu- --prefix "$cwd/inst" \
+ --mandir "$cwd/inst/man"
+$MAKE
+$MAKE test-install
+$MAKE uninstall
+test $(find inst -type f -print | wc -l) -eq 0
+
+# Opportunistically test for installdirs.
+rm -rf inst
+$MAKE installdirs
+test -d inst/bin
+test -d inst/man/man1
+
+:
diff --git a/t/transform2.sh b/t/transform2.sh
new file mode 100644
index 000000000..0e9730aeb
--- /dev/null
+++ b/t/transform2.sh
@@ -0,0 +1,99 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that --program-transform works even when multiple files are
+# collapsed.
+
+required=cc
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'EOF'
+bin_PROGRAMS = p1 p2
+bin_SCRIPTS = s1.sh s2.sh
+man_MANS = m1.1 m2.1
+
+test-install: install
+ test -f inst/bin/p$(EXEEXT)
+ test -f inst/bin/s.sh
+ test -f inst/man/man1/m.1
+
+test-install-foo: install
+ test -f inst/bin/foo$(EXEEXT)
+ test -f inst/bin/foo
+ test -f inst/man/man1/foo.1
+ test ! -f inst/bin/p1$(EXEEXT)
+ test ! -f inst/bin/p2$(EXEEXT)
+ test ! -f inst/bin/s1.sh
+ test ! -f inst/bin/s2.sh
+ test ! -f inst/man/man/m1.1
+ test ! -f inst/man/man/m2.1
+EOF
+
+cat >p1.c <<'EOF'
+int
+main ()
+{
+ return 0;
+}
+EOF
+
+cp p1.c p2.c
+
+: > s1.sh
+: > s2.sh
+: > m1.1
+: > m2.1
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cwd=$(pwd) || fatal_ "getting current working directory"
+
+./configure --program-transform-name='s/[12]//' --prefix "$cwd/inst" \
+ --mandir "$cwd/inst/man"
+$MAKE
+$MAKE test-install
+$MAKE uninstall
+test $(find inst -type f -print | wc -l) -eq 0
+
+# Also squash all file types in question.
+
+# On newer Cygwin versions, that won't work, likely due to overly
+# aggressive appending of '.exe' suffix when copying/renaming Windows
+# executables. So let's skip this part of the test if we detect the
+# faulty heuristic is present. See also:
+# <https://lists.gnu.org/archive/html/automake-patches/2010-08/msg00153.html>
+# <http://thread.gmane.org/gmane.os.cygwin/119380>
+echo Foo > foo
+echo Bar > bar.exe
+chmod a+x foo bar.exe
+cp foo bar && cmp foo bar \
+ || skip_ "your Cygwin is too aggressive in tweaking '.exe' suffixes"
+
+./configure --program-transform-name='s/.*/foo/' --prefix "$cwd/inst" \
+ --mandir "$cwd/inst/man"
+$MAKE
+$MAKE test-install-foo
+$MAKE uninstall
+test $(find inst -type f -print | wc -l) -eq 0
+
+:
diff --git a/t/transform3.sh b/t/transform3.sh
new file mode 100644
index 000000000..9d6e28ce3
--- /dev/null
+++ b/t/transform3.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that --program-transform does not transform too much
+# stuff (in particular, pgklibdir, pkgdatadir and pkglibexecdir).
+
+required=cc
+. test-init.sh
+
+cat > configure.ac <<'END'
+AC_INIT([foo], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_SCRIPTS = foo
+pkgdata_DATA = bar.txt
+pkglib_LIBRARIES = libzap.a
+pkglibexec_SCRIPTS = mu
+
+test-install: install
+ find $(prefix) ;: For debugging.
+ test -f $(bindir)/gnu-foo
+ test -x $(bindir)/gnu-foo
+ test -f $(datadir)/foo/bar.txt
+ test ! -d $(datadir)/gnu-foo
+ test -f $(libdir)/foo/libzap.a
+ test ! -d $(libdir)/gnu-foo
+ test -f $(libexecdir)/foo/gnu-mu
+ test -x $(libexecdir)/foo/gnu-mu
+ test ! -d $(libexecdir)/gnu-foo
+
+test-installdirs: installdirs
+ find $(prefix) ;: For debugging.
+ test -d $(datadir)/foo
+ test ! -d $(datadir)/gnu-foo
+ test -d $(libdir)/foo
+ test ! -d $(libdir)/gnu-foo
+ test -d $(libexecdir)/foo
+ test ! -d $(libexecdir)/gnu-foo
+END
+
+cat > libzap.c <<'END'
+int zap (void)
+{
+ return 0;
+}
+END
+
+echo 'To be or not to be ...' > bar.txt
+
+cat > foo <<'END'
+#!/bin/sh
+exit 0
+END
+cp foo mu
+chmod a+x foo mu
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure --program-prefix=gnu- --prefix "$(pwd)/inst"
+
+$MAKE test-install
+
+$MAKE uninstall
+test $(find inst -type f -print | wc -l) -eq 0
+
+# Opportunistically test for installdirs.
+rm -rf inst
+$MAKE test-installdirs
+
+:
diff --git a/t/txinfo-absolute-srcdir-pr408.sh b/t/txinfo-absolute-srcdir-pr408.sh
new file mode 100644
index 000000000..63c47eb41
--- /dev/null
+++ b/t/txinfo-absolute-srcdir-pr408.sh
@@ -0,0 +1,70 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Texinfo installation works when absolute --srcdir is used.
+# PR/408
+
+required='makeinfo'
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = main.texi
+END
+
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure
+$MAKE
+$MAKE distclean
+
+abscwd=$(pwd) || fatal_ "getting current working directory"
+
+mkdir build
+cd build
+../configure --srcdir="$abscwd" \
+ --prefix="$abscwd/build/_inst" \
+ --infodir="$abscwd/build/_inst/info"
+
+$MAKE install
+
+test -f ../main.info
+test ! -e ./main.info
+test -f _inst/info/main.info
+
+$MAKE uninstall
+test ! -e _inst/info/main.info
+test -f ../main.info
+
+# Multiple uninstall should not fail.
+$MAKE uninstall
+
+:
diff --git a/t/txinfo-add-missing-and-dist.sh b/t/txinfo-add-missing-and-dist.sh
new file mode 100644
index 000000000..62c8dbd7b
--- /dev/null
+++ b/t/txinfo-add-missing-and-dist.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure texinfo.tex is correctly installed and disted by
+# -a when we're using AC_CONFIG_AUX_DIR. Bug report by by Per
+# Cederqvist.
+
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([auxdir])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = textutils.texi
+.PHONY: test1 test2
+test1:
+ @echo DISTFILES = $(DISTFILES)
+ echo ' ' $(DISTFILES) ' ' | grep '[ /]auxdir/texinfo\.tex '
+test2: distdir
+ ls -l $(distdir)/*
+ test -f $(distdir)/auxdir/texinfo.tex
+END
+
+echo '@setfilename textutils.info' > textutils.texi
+
+mkdir auxdir
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+test -f auxdir/texinfo.tex
+
+./configure
+
+# Create textutils.info by hand, so that we don't have to require
+# makeinfo. Also ensure it's really newer than textutils.texi, so
+# that make won't try to re-create it.
+$sleep
+: > textutils.info
+
+$MAKE test1 test2
+
+:
diff --git a/t/txinfo-bsd-make-recurs.sh b/t/txinfo-bsd-make-recurs.sh
new file mode 100644
index 000000000..81c161aca
--- /dev/null
+++ b/t/txinfo-bsd-make-recurs.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the documentation targets work as required with BSD make,
+# even in the presence of subdirs (requires presence of default *-am rules).
+
+. test-init.sh
+
+mkdir sub
+cat >>configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+cat >Makefile.am <<'END'
+SUBDIRS = sub
+END
+: >sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure --prefix="$(pwd)/inst"
+$MAKE html dvi ps pdf info \
+ install-html install-dvi install-ps install-pdf install-info \
+ install-man install-data install-exec install uninstall
+
+:
diff --git a/t/txinfo-builddir.sh b/t/txinfo-builddir.sh
new file mode 100644
index 000000000..68dec81ff
--- /dev/null
+++ b/t/txinfo-builddir.sh
@@ -0,0 +1,131 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that info files are built in builddir when needed.
+# This test that this can be done through the so far undocumented
+# option 'info-in-builddir', as requested by at least GCC, GDB,
+# GNU binutils and the GNU bfd library. See automake bug#11034.
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+if useless_vpath_rebuild; then
+ skip_ "$MAKE has brittle VPATH support"
+fi
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = info-in-builddir
+info_TEXINFOS = foo.texi subdir/bar.texi mu.texi
+subdir_bar_TEXINFOS = subdir/inc.texi
+CLEANFILES = mu.info
+
+# mu.info should not be rebuilt in the current directory, since
+# it's up-to-date in $(srcdir).
+# This can be caused by a subtle issue related to VPATH handling
+# of version.texi (see also the comment in texi-vers.am): because
+# stamp-vti is newer than version.texi, the 'version.texi: stamp-vti'
+# rule is always triggered. Still that's not a reason for 'make'
+# to think 'version.texi' has been created...
+check-local:
+ test ! -e mu.info
+ test -f $(srcdir)/mu.info
+END
+
+mkdir subdir
+
+cat > foo.texi << 'END'
+\input texinfo
+@setfilename foo.info
+@settitle foo
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+cat > mu.texi << 'END'
+\input texinfo
+@setfilename mu.info
+@settitle mu
+@node Top
+Mu mu mu.
+@bye
+END
+
+cat > subdir/bar.texi << 'END'
+\input texinfo
+@setfilename bar.info
+@settitle bar
+@node Top
+Hello walls.
+@include inc.texi
+@bye
+END
+
+echo "I'm included." > subdir/inc.texi
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+mkdir build
+cd build
+../configure
+$MAKE info
+test -f foo.info
+test -f subdir/bar.info
+test -f mu.info
+test -f ../stamp-vti
+test -f ../version.texi
+test ! -e ../foo.info
+test ! -e ../subdir/bar.info
+test ! -e ../mu.info
+$MAKE clean
+test -f foo.info
+test -f subdir/bar.info
+test ! -e mu.info
+test -f ../stamp-vti
+test -f ../version.texi
+
+# Make sure stamp-vti is older that version.texi.
+# (A common situation in a real tree).
+$sleep
+touch ../stamp-vti
+
+$MAKE distcheck
+# Being distributed, this file should have been rebuilt.
+test -f mu.info
+
+$MAKE distclean
+test -f ../stamp-vti
+test -f ../version.texi
+test -f foo.info
+test -f subdir/bar.info
+test ! -e mu.info
+
+../configure
+$MAKE maintainer-clean
+test ! -e ../stamp-vti
+test ! -e ../version.texi
+test ! -e stamp-vti
+test ! -e version.texi
+test ! -e foo.info
+test ! -e subdir/bar.info
+test ! -e mu.info
+
+:
diff --git a/t/txinfo-clean.sh b/t/txinfo-clean.sh
new file mode 100644
index 000000000..9c1a23098
--- /dev/null
+++ b/t/txinfo-clean.sh
@@ -0,0 +1,126 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# DVIS, PDFS, PSS, HTMLS should not be cleaned upon 'mostlyclean'.
+# Similar to txinfo25.sh.
+
+required='makeinfo tex texi2dvi dvips'
+. test-init.sh
+
+mkdir sub
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = main.texi other.texi sub/another.texi
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+cat > other.texi << 'END'
+\input texinfo
+@setfilename other.info
+@settitle other
+@node Top
+Hello walls.
+@include version2.texi
+@bye
+END
+
+cat > sub/another.texi << 'END'
+\input texinfo
+@setfilename another.info
+@settitle another
+@node Top
+Hello walls.
+@include version3.texi
+@bye
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+# In-tree build.
+./configure
+$MAKE dvi ps pdf html
+
+test -f main.dvi
+test -f main.ps
+test -f main.html || test -d main.html
+test -f main.pdf
+test -f other.pdf
+test -f sub/another.pdf
+
+test -f other.dvi
+test -f other.html || test -d other.html
+test -f other.ps
+test -f sub/another.dvi
+test -f sub/another.html || test -d sub/another.html
+test -f sub/another.ps
+
+$MAKE mostlyclean
+
+ls *.aux && exit 1
+ls sub/*.aux && exit 1
+
+test -f main.dvi
+test -f main.ps
+test -f main.html || test -d main.html
+test -f main.pdf
+test -f other.pdf
+test -f sub/another.pdf
+
+test -f other.dvi
+test -f other.html || test -d other.html
+test -f other.ps
+test -f sub/another.dvi
+test -f sub/another.html || test -d sub/another.html
+test -f sub/another.ps
+
+$MAKE clean
+
+test ! -e main.dvi
+test ! -e main.ps
+test ! -e main.html
+test ! -e main.pdf
+test ! -e other.pdf
+test ! -e sub/another.pdf
+test ! -e sub/yetanother.pdf
+
+test ! -e other.dvi
+test ! -e other.html
+test ! -e other.ps
+test ! -e sub/another.dvi
+test ! -e sub/another.html
+test ! -e sub/another.ps
+
+./configure
+$MAKE
+
+$MAKE distcheck
+
+:
diff --git a/t/txinfo-dvi-recurs.sh b/t/txinfo-dvi-recurs.sh
new file mode 100644
index 000000000..f47e9ddad
--- /dev/null
+++ b/t/txinfo-dvi-recurs.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure dvi target recurses into subdir.
+# Reported by Pavel Roskin.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+END
+
+mkdir sub
+cat > sub/Makefile.am << 'END'
+info_TEXINFOS = maude.texi
+END
+
+echo '@setfilename maude.info' > sub/maude.texi
+: > sub/texinfo.tex
+
+$ACLOCAL
+$AUTOMAKE
+
+grep dvi-recursive Makefile.in
+grep '[^-]info-recursive' Makefile.in
+grep '[^n]install-info-recursive' Makefile.in
diff --git a/t/txinfo-include.sh b/t/txinfo-include.sh
new file mode 100644
index 000000000..eef4f927a
--- /dev/null
+++ b/t/txinfo-include.sh
@@ -0,0 +1,164 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Texinfo input files using @include directives. Check both in-tree
+# and VPATH builds, and both top-level and subdir input.
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = main.texi sub/more.texi
+main_TEXINFOS = one.texi two.texi three.texi
+sub_more_TEXINFOS = sub/desc.texi sub/hist.texi
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@ifnottex
+@node Top
+@top GNU dummy.
+@menu
+* one:: Chapter one
+* two:: Chapter two
+* three:: Chapter three
+@end menu
+@end ifnottex
+@include one.texi
+@include two.texi
+@include three.texi
+@bye
+END
+
+cat > one.texi << 'END'
+@node one
+@chapter Chapter one
+Foo bar, baz.
+END
+
+cat > two.texi << 'END'
+@node two
+@chapter Chapter two
+Blah Blah Blah.
+END
+
+cat > three.texi << 'END'
+@node three
+@chapter Chapter two
+GNU's Not Unix.
+END
+
+mkdir sub
+
+cat > sub/more.texi << 'END'
+\input texinfo
+@setfilename more.info
+@settitle main
+@ifnottex
+@node Top
+@top GNU more.
+@menu
+* desc:: Description of this program
+* hist:: History of this program
+@end menu
+@end ifnottex
+@include desc.texi
+@include hist.texi
+@bye
+END
+
+cat > sub/desc.texi << 'END'
+@node desc
+@chapter Description of this program
+It does something, really.
+END
+
+cat > sub/hist.texi << 'END'
+@node hist
+@chapter History of this program
+It was written somehow.
+END
+
+cat > exp << 'END'
+./main.info
+./sub/more.info
+END
+
+check_info_contents ()
+{
+ srcdir=${1-.}
+ $FGREP "Foo bar, baz." $srcdir/main.info
+ $FGREP "Blah Blah Blah." $srcdir/main.info
+ $FGREP "GNU's Not Unix." $srcdir/main.info
+ $FGREP 'It does something, really.' $srcdir/sub/more.info
+ $FGREP 'It was written somehow.' $srcdir/sub/more.info
+}
+
+get_info_names ()
+{
+ find ${1-.} -type f -name '*.info' | LC_ALL=C sort > got
+}
+
+check_expected ()
+{
+ cat exp
+ cat got
+ diff exp got
+}
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure
+
+$MAKE info
+get_info_names
+check_expected
+
+check_info_contents
+
+$MAKE dvi
+test -f main.dvi
+test -f sub/more.dvi
+
+$MAKE maintainer-clean
+test ! -f main.dvi
+test ! -f sub/more.dvi
+test ! -f main.info
+test ! -f sub/more.info
+
+mkdir build
+cd build
+../configure
+$MAKE all dvi
+
+get_info_names ..
+sed 's|^\./|../|' ../exp > exp
+check_expected
+
+test -f main.dvi
+test -f sub/more.dvi
+
+check_info_contents ..
+
+$MAKE distcheck
+
+:
diff --git a/t/txinfo-info-in-srcdir.sh b/t/txinfo-info-in-srcdir.sh
new file mode 100644
index 000000000..13d38213b
--- /dev/null
+++ b/t/txinfo-info-in-srcdir.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that info files are normally built in $(srcdir),
+# not in $(builddir).
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = main.texi
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+mkdir build
+cd build
+../configure
+$MAKE
+test -f ../main.info
+test ! -e main.info
+test -f ../stamp-vti
+test ! -e stamp-vti
+test -f ../version.texi
+test ! -e version.texi
+
+cd ..
+rm -rf build make.info* stamp-vti version.texi
+./configure
+$MAKE
+test -f main.info
+
+# Make sure stamp-vti is older that version.texi.
+# (A common situation in a real tree.)
+# This is needed to test the "subtle" issue described below.
+test -f stamp-vti
+test -f version.texi
+$sleep
+touch stamp-vti
+
+$MAKE distclean
+test -f stamp-vti
+test -f version.texi
+
+mkdir build
+cd build
+../configure
+$MAKE
+# main.info should not be rebuilt in the current directory, since
+# it's up-to-date in $(srcdir).
+# This can be caused by a subtle issue related to VPATH handling
+# of version.texi (see also the comment in texi-vers.am): because
+# stamp-vti is newer than version.texi, the 'version.texi: stamp-vti'
+# rule is always triggered. Still that's not a reason for 'make'
+# to think 'version.texi' has been created...
+test ! -e main.info
+$MAKE dvi
+test -f main.dvi
+
+$MAKE distcheck
+
+:
diff --git a/t/txinfo-makeinfo-error-no-clobber.sh b/t/txinfo-makeinfo-error-no-clobber.sh
new file mode 100644
index 000000000..b8d966dab
--- /dev/null
+++ b/t/txinfo-makeinfo-error-no-clobber.sh
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure info files survive makeinfo errors.
+
+required=makeinfo
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = main.texi sub/main.texi
+END
+
+mkdir sub
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@bye
+END
+
+cp main.texi sub/main.texi
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure
+$MAKE
+
+# Feign more info files.
+: > main.info-1
+: > sub/main.info-1
+
+# Break main.texi.
+$sleep
+cp main.texi main.old
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+@unknown_macro{Hello walls.}
+@bye
+END
+
+# makeinfo will bail out, but we should conserve the old info files.
+$MAKE && exit 1
+test -f main.info
+test -f main.info-1
+
+# Restore main.texi, and break sub/main.texi.
+cp main.texi sub/main.texi
+mv main.old main.texi
+$MAKE && exit 1
+test -f main.info
+test ! -e main.info-1
+test -f sub/main.info
+test -f sub/main.info-1
+
+:
diff --git a/t/txinfo-many-output-formats-vpath.sh b/t/txinfo-many-output-formats-vpath.sh
new file mode 100644
index 000000000..7172a06b1
--- /dev/null
+++ b/t/txinfo-many-output-formats-vpath.sh
@@ -0,0 +1,206 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test support for building HTML documentation, and the many
+# install-DOC flavors, in VPATH builds.
+# Keep in sync with sister test 'txinfo-many-output-formats.sh'.
+# FIXME: in the long term, the best thing to do is probably to convert
+# FIXME: this test and that sister test to TAP, and merge them.
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+cat >>configure.ac <<\EOF
+AC_CONFIG_FILES([rec/Makefile])
+
+# At the time of writing, Autoconf does not supplies any of these
+# definitions (and those below are purposely not those of the standard).
+AC_SUBST([dvidir], ['${datadir}/${PACKAGE}/dvi'])
+AC_SUBST([htmldir], ['${datadir}/${PACKAGE}/html'])
+AC_SUBST([pdfdir], ['${datadir}/${PACKAGE}/pdf'])
+AC_SUBST([psdir], ['${datadir}/${PACKAGE}/ps'])
+
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'END'
+SUBDIRS = rec
+info_TEXINFOS = main.texi sub/main2.texi
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@bye
+END
+
+mkdir sub
+cat > sub/main2.texi << 'END'
+\input texinfo
+@setfilename main2.info
+@settitle main2
+@node Top
+Hello walls.
+@bye
+END
+
+mkdir rec
+cat > rec/main3.texi << 'END'
+\input texinfo
+@setfilename main3.info
+@settitle main3
+@node Top
+Hello walls.
+@bye
+END
+
+cat > rec/Makefile.am << 'END'
+info_TEXINFOS = main3.texi
+
+install-pdf-local:
+ @$(MKDIR_P) "$(pdfdir)"
+ : > "$(pdfdir)/hello"
+uninstall-local:
+ rm -f "$(pdfdir)/hello"
+
+check-local: ps pdf dvi html # For "make distcheck".
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+# To simplify syncing with sister test 'txinfo-many-output-formats.sh'
+srcdir=..
+
+if test $srcdir = ..; then
+ mkdir build
+ cd build
+fi
+
+$srcdir/configure --prefix="$(pwd)"
+
+$MAKE
+
+$sleep
+# Test production of split-per-node HTML.
+$MAKE html
+test -d main.html
+test -d sub/main2.html
+test -d rec/main3.html
+
+# Rebuilding main.html should cause its timestamp to be updated.
+is_newest main.html $srcdir/main.texi
+$sleep
+touch $srcdir/main.texi
+$MAKE html
+is_newest main.html $srcdir/main.texi
+
+$MAKE clean
+test ! -e main.html
+test ! -e sub/main2.html
+test ! -e rec/main3.html
+
+# Test production of a single HTML file.
+run_make MAKEINFOFLAGS=--no-split html
+test -f main.html
+test -f sub/main2.html
+test -f rec/main3.html
+$MAKE clean
+test ! -e main.html
+test ! -e sub/main2.html
+test ! -e rec/main3.html
+
+# Make sure AM_MAKEINFOHTMLFLAGS is supported, and override AM_MAKEINFO.
+
+cp $srcdir/Makefile.am $srcdir/Makefile.sav
+cat >> $srcdir/Makefile.am <<'EOF'
+AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
+AM_MAKEINFOFLAGS = --unsupported-option
+EOF
+(cd $srcdir && $AUTOMAKE)
+./config.status Makefile
+
+$MAKE html
+test -f main.html
+test -f sub/main2.html
+test -d rec/main3.html
+$MAKE clean
+test ! -e main.html
+test ! -e sub/main2.html
+test ! -e rec/main3.html
+
+$MAKE install-html
+test -f share/$me/html/main.html
+test -f share/$me/html/main2.html
+test -d share/$me/html/main3.html
+$MAKE uninstall
+test ! -e share/$me/html/main.html
+test ! -e share/$me/html/main2.html
+test ! -e share/$me/html/main3.html
+
+$MAKE dvi
+test -f main.dvi
+test -f sub/main2.dvi
+test -f rec/main3.dvi
+$MAKE clean
+test ! -e main.dvi
+test ! -e sub/main2.dvi
+test ! -e rec/main3.dvi
+
+$MAKE install-dvi
+test -f share/$me/dvi/main.dvi
+test -f share/$me/dvi/main2.dvi
+test -f share/$me/dvi/main3.dvi
+$MAKE uninstall
+test ! -e share/$me/dvi/main.dvi
+test ! -e share/$me/dvi/main2.dvi
+test ! -e share/$me/dvi/main3.dvi
+
+dvips --help || skip_ "dvips is missing"
+
+$MAKE install-ps
+test -f share/$me/ps/main.ps
+test -f share/$me/ps/main2.ps
+test -f share/$me/ps/main3.ps
+$MAKE uninstall
+test ! -e share/$me/ps/main.ps
+test ! -e share/$me/ps/main2.ps
+test ! -e share/$me/ps/main3.ps
+
+pdfetex --help || pdftex --help \
+ || skip_ "pdftex and pdfetex are both missing"
+
+$MAKE install-pdf
+test -f share/$me/pdf/main.pdf
+test -f share/$me/pdf/main2.pdf
+test -f share/$me/pdf/main3.pdf
+test -f share/$me/pdf/hello
+$MAKE uninstall
+test ! -e share/$me/pdf/main.pdf
+test ! -e share/$me/pdf/main2.pdf
+test ! -e share/$me/pdf/main3.pdf
+test ! -e share/$me/pdf/hello
+
+# Restore the makefile without a broken AM_MAKEINFOFLAGS definition.
+cp -f $srcdir/Makefile.sav $srcdir/Makefile.am
+using_gmake || $MAKE Makefile
+$MAKE distcheck
+
+:
diff --git a/t/txinfo-many-output-formats.sh b/t/txinfo-many-output-formats.sh
new file mode 100644
index 000000000..cbc97bbf9
--- /dev/null
+++ b/t/txinfo-many-output-formats.sh
@@ -0,0 +1,206 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test support for building HTML documentation, and the many
+# install-DOC flavors.
+# Keep in sync with sister test 'txinfo-many-output-formats-vpath.sh'.
+# FIXME: in the long term, the best thing to do is probably to convert
+# FIXME: this test and that sister test to TAP, and merge them.
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+cat >>configure.ac <<\EOF
+AC_CONFIG_FILES([rec/Makefile])
+
+# At the time of writing, Autoconf does not supplies any of these
+# definitions (and those below are purposely not those of the standard).
+AC_SUBST([dvidir], ['${datadir}/${PACKAGE}/dvi'])
+AC_SUBST([htmldir], ['${datadir}/${PACKAGE}/html'])
+AC_SUBST([pdfdir], ['${datadir}/${PACKAGE}/pdf'])
+AC_SUBST([psdir], ['${datadir}/${PACKAGE}/ps'])
+
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'END'
+SUBDIRS = rec
+info_TEXINFOS = main.texi sub/main2.texi
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@bye
+END
+
+mkdir sub
+cat > sub/main2.texi << 'END'
+\input texinfo
+@setfilename main2.info
+@settitle main2
+@node Top
+Hello walls.
+@bye
+END
+
+mkdir rec
+cat > rec/main3.texi << 'END'
+\input texinfo
+@setfilename main3.info
+@settitle main3
+@node Top
+Hello walls.
+@bye
+END
+
+cat > rec/Makefile.am << 'END'
+info_TEXINFOS = main3.texi
+
+install-pdf-local:
+ @$(MKDIR_P) "$(pdfdir)"
+ : > "$(pdfdir)/hello"
+uninstall-local:
+ rm -f "$(pdfdir)/hello"
+
+check-local: ps pdf dvi html # For "make distcheck".
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+# To simplify syncing with sister test 'txinfo-many-output-formats.sh'
+srcdir=.
+
+if test $srcdir = ..; then
+ mkdir build
+ cd build
+fi
+
+$srcdir/configure --prefix="$(pwd)"
+
+$MAKE
+
+$sleep
+# Test production of split-per-node HTML.
+$MAKE html
+test -d main.html
+test -d sub/main2.html
+test -d rec/main3.html
+
+# Rebuilding main.html should cause its timestamp to be updated.
+is_newest main.html $srcdir/main.texi
+$sleep
+touch $srcdir/main.texi
+$MAKE html
+is_newest main.html $srcdir/main.texi
+
+$MAKE clean
+test ! -e main.html
+test ! -e sub/main2.html
+test ! -e rec/main3.html
+
+# Test production of a single HTML file.
+run_make MAKEINFOFLAGS=--no-split html
+test -f main.html
+test -f sub/main2.html
+test -f rec/main3.html
+$MAKE clean
+test ! -e main.html
+test ! -e sub/main2.html
+test ! -e rec/main3.html
+
+# Make sure AM_MAKEINFOHTMLFLAGS is supported, and override AM_MAKEINFO.
+
+cp $srcdir/Makefile.am $srcdir/Makefile.sav
+cat >> $srcdir/Makefile.am <<'EOF'
+AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
+AM_MAKEINFOFLAGS = --unsupported-option
+EOF
+(cd $srcdir && $AUTOMAKE)
+./config.status Makefile
+
+$MAKE html
+test -f main.html
+test -f sub/main2.html
+test -d rec/main3.html
+$MAKE clean
+test ! -e main.html
+test ! -e sub/main2.html
+test ! -e rec/main3.html
+
+$MAKE install-html
+test -f share/$me/html/main.html
+test -f share/$me/html/main2.html
+test -d share/$me/html/main3.html
+$MAKE uninstall
+test ! -e share/$me/html/main.html
+test ! -e share/$me/html/main2.html
+test ! -e share/$me/html/main3.html
+
+$MAKE dvi
+test -f main.dvi
+test -f sub/main2.dvi
+test -f rec/main3.dvi
+$MAKE clean
+test ! -e main.dvi
+test ! -e sub/main2.dvi
+test ! -e rec/main3.dvi
+
+$MAKE install-dvi
+test -f share/$me/dvi/main.dvi
+test -f share/$me/dvi/main2.dvi
+test -f share/$me/dvi/main3.dvi
+$MAKE uninstall
+test ! -e share/$me/dvi/main.dvi
+test ! -e share/$me/dvi/main2.dvi
+test ! -e share/$me/dvi/main3.dvi
+
+dvips --help || skip_ "dvips is missing"
+
+$MAKE install-ps
+test -f share/$me/ps/main.ps
+test -f share/$me/ps/main2.ps
+test -f share/$me/ps/main3.ps
+$MAKE uninstall
+test ! -e share/$me/ps/main.ps
+test ! -e share/$me/ps/main2.ps
+test ! -e share/$me/ps/main3.ps
+
+pdfetex --help || pdftex --help \
+ || skip_ "pdftex and pdfetex are both missing"
+
+$MAKE install-pdf
+test -f share/$me/pdf/main.pdf
+test -f share/$me/pdf/main2.pdf
+test -f share/$me/pdf/main3.pdf
+test -f share/$me/pdf/hello
+$MAKE uninstall
+test ! -e share/$me/pdf/main.pdf
+test ! -e share/$me/pdf/main2.pdf
+test ! -e share/$me/pdf/main3.pdf
+test ! -e share/$me/pdf/hello
+
+# Restore the makefile without a broken AM_MAKEINFOFLAGS definition.
+cp -f $srcdir/Makefile.sav $srcdir/Makefile.am
+using_gmake || $MAKE Makefile
+$MAKE distcheck
+
+:
diff --git a/t/txinfo-no-clutter.sh b/t/txinfo-no-clutter.sh
new file mode 100644
index 000000000..9987aa856
--- /dev/null
+++ b/t/txinfo-no-clutter.sh
@@ -0,0 +1,146 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The info, html, pdf, ps and dvi targets shouldn't let clutter in the
+# build directory. Related to automake bug#11146.
+
+required='makeinfo tex texi2dvi dvips'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+all-local: ps pdf dvi html # For "make distcheck".
+info_TEXINFOS = foo.texi doc/bar.texi baz.texi
+SUBDIRS = sub
+END
+
+mkdir sub doc
+
+cat > sub/Makefile.am << 'END'
+all-local: ps pdf dvi html # For "make distcheck".
+info_TEXINFOS = baz.texi
+END
+
+cat > foo.texi << 'END'
+\input texinfo
+@setfilename foo.info
+@settitle foo
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+cat > doc/bar.texi << 'END'
+\input texinfo
+@setfilename bar.info
+@settitle bar
+@node Top
+Hello walls.
+@include version2.texi
+@bye
+END
+
+cat > baz.texi << 'END'
+\input texinfo
+@setfilename baz.info
+@settitle baz
+@defindex au
+@defindex sa
+@defindex sb
+@node Top
+Hello walls.
+@cindex foo
+foo
+@pindex bar
+bar
+@auindex baz
+baz
+@saindex sa
+sa
+@sbindex sb
+sb
+@bye
+END
+
+cp baz.texi sub
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure
+
+# Try one by one, to ensure later targets don't involuntarily
+# clean up potential cruft left by earlier ones.
+for fmt in info pdf ps dvi html all; do
+ $MAKE $fmt
+ # For debugging.
+ ls -l . doc sub
+ # Sanity check.
+ case $fmt in
+ html)
+ test -e foo.html
+ test -e doc/bar.html
+ test -e baz.html
+ test -e sub/baz.html
+ ;;
+ all)
+ for x in info pdf ps dvi; do
+ test -f foo.$x
+ test -f doc/bar.$x
+ test -f baz.$x
+ test -f sub/baz.$x
+ done
+ test -e foo.html
+ test -e doc/bar.html
+ test -e baz.html
+ test -e sub/baz.html
+ ;;
+ *)
+ test -f foo.$fmt
+ test -f doc/bar.$fmt
+ test -f baz.$fmt
+ test -f sub/baz.$fmt
+ ;;
+ esac
+ # Real test.
+ ls -d foo* baz* sub/baz* doc/bar* > lst
+ basename_rx='(foo|doc/bar|baz|sub/baz)'
+ case $fmt in
+ pdf) extension_rx="(texi|pdf|t2p)";;
+ dvi) extension_rx="(texi|dvi|t2d)";;
+ ps) extension_rx="(texi|ps|dvi|t2d)";;
+ info) extension_rx="(texi|info)";;
+ html) extension_rx="(texi|html)";;
+ all) extension_rx="(texi|html|info|pdf|ps|dvi|t2[pd])";;
+ *) fatal_ "unreachable code reached";;
+ esac
+ $EGREP -v "^$basename_rx\.$extension_rx$" lst && exit 1
+ # Cleanup for checks on the next format.
+ case $fmt in
+ info) rm -f *.info doc/*.info sub/*.info;;
+ *) $MAKE clean;;
+ esac
+done
+
+$MAKE distcheck
+
+:
diff --git a/t/txinfo-no-extra-dist.sh b/t/txinfo-no-extra-dist.sh
new file mode 100644
index 000000000..2e89cfb4a
--- /dev/null
+++ b/t/txinfo-no-extra-dist.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to ensure that a ".info~" or ".info.bak" file doesn't end up
+# in the distribution. Bug report from Greg McGary.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = textutils.texi subdir/main.texi
+test: distdir
+ @echo DISTFILES = $(DISTFILES)
+ @case '$(DISTFILES)' in *'~'*|*'.bak'*) exit 1;; *) exit 0;; esac
+ st=0; \
+ find $(distdir) | grep '~' && st=1; \
+ find $(distdir) | grep '\.bak' && st=1; \
+ exit $$st
+PHONY: test
+END
+
+: > texinfo.tex
+mkdir subdir
+echo '@setfilename textutils.info' > textutils.texi
+echo '@setfilename main.info' > subdir/main.texi
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+: > textutils.info
+: > subdir/main.info
+: > textutils.info~
+: > textutils.info.bak
+: > subdir/main.info~
+: > subdir/main.info.bak
+$MAKE test
+$MAKE maintainer-clean
+test -f subdir/main.info~
+test -f subdir/main.info.bak
+
+:
diff --git a/t/txinfo-no-installinfo.sh b/t/txinfo-no-installinfo.sh
new file mode 100644
index 000000000..31f99dacb
--- /dev/null
+++ b/t/txinfo-no-installinfo.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure install-info works even if no-installinfo is given.
+
+required='makeinfo'
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = main.texi
+AUTOMAKE_OPTIONS = no-installinfo
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure --prefix="$(pwd)/inst" --infodir="$(pwd)/inst/info"
+$MAKE install-info
+test -f inst/info/main.info
+
+:
diff --git a/t/txinfo-no-repeated-targets.sh b/t/txinfo-no-repeated-targets.sh
new file mode 100644
index 000000000..03ab54140
--- /dev/null
+++ b/t/txinfo-no-repeated-targets.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we only create texinfo-related targets once.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = maude.texi liver.texi heart.texi
+END
+
+echo '@setfilename maude.info' > maude.texi
+echo '@setfilename liver.info' > liver.texi
+echo '@setfilename heart.info' > heart.texi
+: > texinfo.tex
+
+$ACLOCAL
+$AUTOMAKE
+
+# These are just examples -- basically for many targets in texinfos.am
+# we only want them to appear once. But grepping them all would be
+# overkill.
+for t in info dist-info dvi-am install-html uninstall-pdf-am; do
+ $EGREP "(^| )$t*.:" Makefile.in # For debugging.
+ test $($EGREP -c "(^| )$t(:| *.:)" Makefile.in) -eq 1
+done
+
+:
diff --git a/t/txinfo-no-split.sh b/t/txinfo-no-split.sh
new file mode 100644
index 000000000..ba7ec0d29
--- /dev/null
+++ b/t/txinfo-no-split.sh
@@ -0,0 +1,101 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Info split files should not be produced (automake bug#13351).
+
+required=makeinfo
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+MAKEINFO = makeinfo --split-size 10
+info_TEXINFOS = foo.texi
+
+test-split: # A sanity check.
+ $(MAKEINFO) -o split.info foo.texi
+
+check-local:
+ test -f $(srcdir)/foo.info
+ test ! -f $(srcdir)/foo.info-1
+ test "`find $(srcdir) . | grep '\.info'`" = "$(srcdir)/foo.info"
+END
+
+# Systems lacking a working TeX installation cannot run "make dvi".
+if test -z "$TEX"; then
+ warn_ "TeX installation missing, \"make dvi\" will be skipped"
+ echo AUTOMAKE_OPTIONS = -Wno-override >> Makefile.am
+ echo 'dvi:; @echo Tex is missing, do nothing' >> Makefile.am
+fi
+
+cat > foo.texi << 'END'
+\input texinfo
+@setfilename foo.info
+@settitle foo
+@dircategory Dummy utilities
+@direntry
+* Foo: (foo). Does nothing at all.
+@end direntry
+
+@node Top
+@top Foo
+
+@menu
+* Intro:: Introduction
+* Planets:: List of Planets
+@end menu
+
+@node Intro
+@chapter Introduction
+Will list planets.
+
+@node Planets
+@chapter List of planets
+Hello Mercury.
+Hello Venus
+Hello Earth
+Hello Mars.
+Hello Jupiter.
+Hello Saturn.
+Hello Uran.
+Hello Neptune.
+Hello Pluto.
+@bye
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE test-split
+ls -l # For debugging.
+test -f split.info
+test -f split.info-1
+test -f split.info-2
+rm -f split*
+
+$MAKE
+
+ls -l # For debugging.
+test -f foo.info
+test ! -f foo.info-1
+test "$(find . | $FGREP '.info' | sed 's|^\./||')" = foo.info
+
+$MAKE distcheck
+
+:
diff --git a/t/txinfo-nodist-info.sh b/t/txinfo-nodist-info.sh
new file mode 100644
index 000000000..3f4146b14
--- /dev/null
+++ b/t/txinfo-nodist-info.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2013-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that we can force generated '.info' info files not to be
+# distributed.
+
+required=makeinfo
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = info-in-builddir
+info_TEXINFOS = foo.texi
+CLEANFILES = foo.info
+
+# To make distcheck work without requiring TeX and texi2dvi.
+dvi:
+
+# Do not distribute generated '.info' files.
+dist-info:
+ @:
+END
+
+mkdir subdir
+
+cat > foo.texi << 'END'
+\input texinfo
+@setfilename foo.info
+@settitle foo
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a -Wno-override
+
+./configure
+$MAKE distdir
+ls -l . $distdir # For debugging.
+test ! -e foo.info
+test ! -e $distdir/foo.info
+$MAKE
+test -f foo.info
+$MAKE distdir
+ls -l $distdir # For debugging.
+test ! -f $distdir/foo.info
+$MAKE distcheck
+
+:
diff --git a/t/txinfo-other-suffixes.sh b/t/txinfo-other-suffixes.sh
new file mode 100644
index 000000000..83b20fbc6
--- /dev/null
+++ b/t/txinfo-other-suffixes.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure '.txi' and '.texinfo' extensions are deprecated,
+# but still work.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = foo.txi bar.texinfo
+END
+
+echo '@setfilename foo.info' > foo.txi
+echo '@setfilename bar.info' > bar.texinfo
+: > texinfo.tex
+
+$ACLOCAL
+AUTOMAKE_fails
+grep "^Makefile\.am:.*suffix '.txi'.*Texinfo file.*discouraged" stderr
+grep "^Makefile\.am:.*suffix '.texinfo'.*Texinfo file.*discouraged" stderr
+grep "^Makefile\.am:.* use '.texi' instead" stderr
+
+$AUTOMAKE -Wno-obsolete
+
+grep '^\.txi\.info: *$' Makefile.in
+grep '^\.texinfo\.info: *$' Makefile.in
+
+:
diff --git a/t/txinfo-override-infodeps.sh b/t/txinfo-override-infodeps.sh
new file mode 100644
index 000000000..9fd5a609a
--- /dev/null
+++ b/t/txinfo-override-infodeps.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that INFO_DEPS can be overridden.
+# Report from Bruce Korb.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+INFO_DEPS = foo.info
+info_TEXINFOS = bar.texi
+END
+
+echo '@setfilename baz.info' > bar.texi
+
+$ACLOCAL
+AUTOMAKE_fails --add-missing
+grep '^Makefile\.am:1:.*user variable.*INFO_DEPS' stderr
+grep 'overrides Automake variable.*INFO_DEPS' stderr
+
+$AUTOMAKE -Wno-override
+
+# There is only one definition of INFO_DEPS ...
+test 1 -eq $(grep -c '^INFO_DEPS.*=' Makefile.in)
+# ... and it is the right one.
+grep '^INFO_DEPS *= *foo.info *$' Makefile.in
+
+# Likewise with AC_SUBST.
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = bar.texi
+END
+cat >> configure.ac << 'END'
+AC_SUBST([INFO_DEPS])
+END
+rm -rf autom4te.cache # Make sure autoconf sees the configure.ac update.
+AUTOMAKE_fails
+
+grep '^configure\.ac:4:.*user variable.*INFO_DEPS' stderr
+grep 'overrides Automake variable.*INFO_DEPS' stderr
+
+$AUTOMAKE -Wno-override
+
+# There is only one definition of INFO_DEPS ...
+test 1 -eq $(grep -c '^INFO_DEPS.*=' Makefile.in)
+# ... and it is the right one.
+grep '^INFO_DEPS *= *@INFO_DEPS@ *$' Makefile.in
+
+:
diff --git a/t/txinfo-override-texinfo-tex.sh b/t/txinfo-override-texinfo-tex.sh
new file mode 100644
index 000000000..b605bd55d
--- /dev/null
+++ b/t/txinfo-override-texinfo-tex.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the user can override TEXINFO_TEX.
+# Also make sure TEXINFO_TEX is not distributed.
+# Report from Tom Tromey.
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([aux1])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEXINFO_TEX = ../tex/texinfo.tex
+info_TEXINFOS = main.texi
+sure_it_exists:
+ test -f $(srcdir)/$(TEXINFO_TEX)
+sure_it_is_not_distributed: distdir
+ test ! -f $(distdir)/tex/texinfo.tex
+check-local: sure_it_exists
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@bye
+END
+
+mkdir aux1
+mkdir tex
+cp "$am_pkgvdatadir/texinfo.tex" tex
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+test ! -e texinfo.tex
+test ! -e aux1/texinfo.tex
+test -f tex/texinfo.tex
+
+./configure
+
+$MAKE distcheck
+$MAKE sure_it_is_not_distributed
+
+:
diff --git a/t/txinfo-setfilename-repeated.sh b/t/txinfo-setfilename-repeated.sh
new file mode 100644
index 000000000..a9ab21fe1
--- /dev/null
+++ b/t/txinfo-setfilename-repeated.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure Automake uses the _first_ @setfilname it sees.
+# Report from Karl Berry.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = texinfo.texi
+END
+
+cat > texinfo.texi << 'END'
+@setfilename texinfo.info
+...
+@verbatim
+@setfilename example.info
+@end verbatim
+...
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+grep 'example' Makefile.in && exit 1
+grep 'texinfo\.info:' Makefile.in
+
+:
diff --git a/t/txinfo-setfilename-suffix-strip.sh b/t/txinfo-setfilename-suffix-strip.sh
new file mode 100644
index 000000000..10453efa6
--- /dev/null
+++ b/t/txinfo-setfilename-suffix-strip.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure file extensions are matched correctly in the code
+# parsing texi files for @setfilename declarations.
+# Report from Eric Dorland.
+
+. test-init.sh
+
+echo info_TEXINFOS = bar.texi >Makefile.am
+cat >bar.texi <<EOF
+@setfilename bar-1.9.info
+EOF
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+$EGREP '[ /]bar-1\.9\.info( |$)' Makefile.in
+
+:
diff --git a/t/txinfo-subdir-pr343.sh b/t/txinfo-subdir-pr343.sh
new file mode 100644
index 000000000..ea393ea68
--- /dev/null
+++ b/t/txinfo-subdir-pr343.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for subdir Texinfo (PR/343).
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = subdir/main.texi
+subdir_main_TEXINFOS = subdir/inc.texi
+
+installcheck-local:
+ test -f "$(infodir)/main.info"
+END
+
+mkdir subdir
+
+cat > subdir/main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@include version.texi
+@include inc.texi
+@bye
+END
+
+cat > subdir/inc.texi << 'END'
+I'm included.
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+mkdir build
+cd build
+../configure
+$MAKE distcheck
+test -f ../subdir/main.info
+test ! -e subdir/main.info
+
+:
diff --git a/t/txinfo-tex-dist.sh b/t/txinfo-tex-dist.sh
new file mode 100644
index 000000000..68daacf94
--- /dev/null
+++ b/t/txinfo-tex-dist.sh
@@ -0,0 +1,47 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to ensure texinfo.tex is included in distribution. Bug report by
+# Jim Meyering.
+
+required=makeinfo
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = textutils.texi
+.PHONY: test1 test2
+test1:
+ @echo DISTFILES = $(DISTFILES)
+ echo ' ' $(DISTFILES) ' ' | grep '[ /]texinfo\.tex '
+test2: distdir
+ ls -l $(distdir)
+ test -f $(distdir)/texinfo.tex
+END
+
+echo '@setfilename textutils.info' > textutils.texi
+: > texinfo.tex
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE test1 test2
+
+:
diff --git a/t/txinfo-unrecognized-extension.sh b/t/txinfo-unrecognized-extension.sh
new file mode 100644
index 000000000..c93c007ee
--- /dev/null
+++ b/t/txinfo-unrecognized-extension.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that automake complains properly when the files with unrecognized
+# extensions are passed to the TEXINFOS primary.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = foobar.foo bazquux.tex zardoz.c
+END
+
+echo '@setfilename foobar.info' > foobar.foo
+echo '@setfilename bazquux.info' > bazquux.tex
+echo '@setfilename zardoz.info' > zardoz.c
+: > texinfo.tex
+
+$ACLOCAL
+AUTOMAKE_fails
+
+for x in 'foobar\.foo' 'bazquux\.tex' 'zardoz\.c'; do
+ grep "^Makefile\\.am:.* texinfo file .*$x.* unrecognized extension" stderr
+done
+
+:
diff --git a/t/txinfo-unrecognized-info-suffix.sh b/t/txinfo-unrecognized-info-suffix.sh
new file mode 100644
index 000000000..811e28e8d
--- /dev/null
+++ b/t/txinfo-unrecognized-info-suffix.sh
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure non-empty, non-info suffixes are diagnosed.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = textutils.texi
+END
+
+echo '@setfilename textutils.frob' > textutils.texi
+: > texinfo.tex
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'textutils\.texi:1:.*textutils\.frob.*extension' stderr
+
+:
diff --git a/t/txinfo-vtexi.sh b/t/txinfo-vtexi.sh
new file mode 100644
index 000000000..7d8ff77f9
--- /dev/null
+++ b/t/txinfo-vtexi.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic checks and some regressions testing on 'version.texi'
+# support for texinfo files.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = textutils.texi
+END
+
+cat > textutils.texi << 'END'
+@include version.texi
+@setfilename textutils.info
+END
+
+# Required when using Texinfo.
+: > mdate-sh
+: > texinfo.tex
+
+$ACLOCAL
+$AUTOMAKE
+
+# Test for bug reported by Jim Meyering:
+# When I ran automake-0.29 on textutils,
+# I noticed that doc/Makefile.in had
+# textutils.info: textutils.texi
+# instead of
+# textutils.info: textutils.texi version.texi
+# Today this should be:
+# $(srcdir)/textutils.info: $(srcdir)/version.texi
+# or:
+# $(srcdir)/textutils.info: version.texi
+grep '^\$(srcdir)/textutils\.info:.*[ /]version\.texi *$' Makefile.in
+
+# Test for bug reported by Lars Hecking:
+# When running the first version of configure.ac aware automake,
+# @CONFIGURE_AC@ was not properly substituted.
+$EGREP 'stamp-vti:.*textutils\.texi( .*)?$' Makefile.in
+$EGREP 'stamp-vti:.*\$\(top_srcdir\)/configure( .*)?$' Makefile.in
+
+# Check that the path to mdate-sh is correct. Over escaping of '$'
+# etc. once led to '\$\(srcdir\)/mdate-sh'.
+# Filter out '$(srcdir)/mdate-sh'; there should be no occurrences
+# of '.../mdate-sh' left then.
+sed 's,\$(srcdir)/mdate-sh,,g' Makefile.in | grep '/mdate-sh' && exit 1
+
+:
diff --git a/t/txinfo-vtexi2.sh b/t/txinfo-vtexi2.sh
new file mode 100644
index 000000000..5f6fc7359
--- /dev/null
+++ b/t/txinfo-vtexi2.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for bug reported by Glenn Amerine:
+# When automake sees version.texi is being included by a texi file,
+# version.texi gets listed as a dependency for the .info file but
+# not the .dvi file.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = zardoz.texi
+END
+
+cat > zardoz.texi << 'END'
+@setfilename zardoz.info
+@include version.texi
+END
+
+# Required when using Texinfo.
+: > mdate-sh
+: > texinfo.tex
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^zardoz\.dvi:.*[ /]version.texi' Makefile.in
+
+:
diff --git a/t/txinfo-vtexi3.sh b/t/txinfo-vtexi3.sh
new file mode 100644
index 000000000..043ba7a23
--- /dev/null
+++ b/t/txinfo-vtexi3.sh
@@ -0,0 +1,124 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that vers*.texi files are automatically created and distributed
+# if @included into a texi source. Also check that they correctly contain
+# the @values definitions they are advertised to.
+# See also the related test 'txinfo-vtexi4.sh', which does similar checks,
+# but for version.texi only, and requires makeinfo, tex and texi2dvi.
+
+. test-init.sh
+
+# We are going to override package version in AC_INIT, so we need
+# to redefine the name of the distdir as well.
+distdir=$me-7.45.3a
+
+# This should work without tex, texinfo or makeinfo.
+TEX=false TEXI2DVI=false MAKEINFO=false
+export TEX TEXI2DVI MAKEINFO
+
+cat > configure.ac << END
+AC_INIT([$me], [7.45.3a])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = foobar.texi quux.texi zardoz.texi
+.PHONY: echo-distfiles
+echo-distfiles:
+ @echo ' ' $(DISTFILES) ' '
+END
+
+cat > foobar.texi << 'END'
+@setfilename foobar.info
+random text
+@include version.texi
+END
+
+cat > quux.texi << 'END'
+@setfilename quux.info
+@include version-quux.texi
+random text
+END
+
+cat > zardoz.texi << 'END'
+@setfilename zardoz.info
+some randome text
+@include vers1a_2b.texi
+more random text
+END
+
+# Required when using Texinfo.
+: > texinfo.tex
+cp "$am_scriptdir"/mdate-sh .
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+day='([1-9]|1[0-9]|2[0-9]|3[01])'
+month='(January|February|March|April|May|June|July|August|September|October|November|December)'
+year='20[0-9][0-9]' # Hopefully automake will be obsolete in 80 years ;-)
+date="$day $month $year"
+
+do_check ()
+{
+ # Basename of the vers*.texi file.
+ vfile=$1
+ # The $(srcdir) of the current build.
+ srcdir=$2
+ # The vers*.texi file must be created in $(srcdir).
+ $MAKE $srcdir/$vfile.texi
+ cat $srcdir/$vfile.texi
+ # EDITION and VERSION are synonyms, as per documentation.
+ grep "^@set EDITION 7\\.45\\.3a$" $srcdir/$vfile.texi
+ grep "^@set VERSION 7\\.45\\.3a$" $srcdir/$vfile.texi
+ # Check that UPDATED seems right, and that UPDATED and UPDATED-MONTH
+ # are consistent.
+ $EGREP "^@set UPDATED $date$" $srcdir/$vfile.texi
+ vmonth=$(grep '^@set UPDATED ' $srcdir/$vfile.texi | awk '{print $4, $5}')
+ grep "^@set UPDATED-MONTH $vmonth$" $srcdir/$vfile.texi
+ # Check that the vers*.texi file is distributed according
+ # to $(DISTFILES).
+ $MAKE echo-distfiles # For debugging.
+ $MAKE -s echo-distfiles | grep "[ /]$vfile\\.texi"
+}
+
+mkdir build
+cd build
+../configure
+
+do_check version ..
+do_check version-quux ..
+do_check vers1a_2b ..
+
+# The various $(srcdir)/*.info are required for the distribution
+# and they must be newer than version.texi, so that make won't try
+# to rebuild them.
+$sleep
+touch ../foobar.info
+touch ../quux.info
+touch ../zardoz.info
+# Check that the vers*.texi files are really distributed.
+$MAKE distdir
+ls -l $distdir
+diff ../version.texi $distdir/version.texi
+diff ../version-quux.texi $distdir/version-quux.texi
+diff ../version.texi $distdir/vers1a_2b.texi
+
+:
diff --git a/t/txinfo-vtexi4.sh b/t/txinfo-vtexi4.sh
new file mode 100644
index 000000000..8f9eab414
--- /dev/null
+++ b/t/txinfo-vtexi4.sh
@@ -0,0 +1,106 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the version.texi file is automatically created and distributed
+# if @included into a texi source. Also check that is correctly defined
+# @values definitions it is advertised to.
+# See also the related test 'txinfo-vtexi4.sh', which does similar checks,
+# but for more vers*.texi files, and does not require makeinfo, tex and
+# texi2dvi.
+
+required='makeinfo tex texi2dvi grep-nonprint'
+. test-init.sh
+
+test $(LC_ALL=C date '+%u') -gt 0 && test $(LC_ALL=C date '+%u') -lt 8 \
+ && day=$(LC_ALL=C date '+%d') && test -n "$day" \
+ && month=$(LC_ALL=C date '+%B') && test -n "$month" \
+ && year=$(LC_ALL=C date '+%Y') && test -n "$year" \
+ || skip_ "'date' is not POSIX-compliant enough"
+day=$(echo "$day" | sed 's/^0//')
+
+cat > configure.ac << END
+AC_INIT([$me], [123.456])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+cat > defs.am <<END
+my_date_rx = $day $month $year
+my_month_rx = $month $year
+my_version_rx = 123\.456
+END
+
+cat > Makefile.am << 'END'
+include defs.am
+info_TEXINFOS = foo.texi
+test-grepinfo:
+## Not useless uses of cat: we only tested that grep works on
+## non-text input when that's given from a pipe.
+ cat $(srcdir)/foo.info | grep 'GREPVERSION=$(my_version_rx)='
+ cat $(srcdir)/foo.info | grep 'GREPEDITION=$(my_version_rx)='
+ cat $(srcdir)/foo.info | grep 'GREPDATE=$(my_date_rx)='
+ cat $(srcdir)/foo.info | grep 'GREPMONTH=$(my_month_rx)='
+test-distfiles:
+ @echo DISTFILES = $(DISTFILES)
+ echo ' ' $(DISTFILES) ' ' | grep '[ /]version.texi '
+test-distdir: distdir
+ ls -l $(distdir)
+ diff $(srcdir)/version.texi $(distdir)/version.texi
+.PHONY: test-grepinfo test-distfiles test-distdir
+check-local: test-grepinfo test-distfiles test-distdir
+END
+
+cat > foo.texi << 'END'
+\input texinfo
+@c %**start of header
+@setfilename foo.info
+@settitle Zardoz
+@c %**end of header
+
+@node Top
+@include version.texi
+
+GREPVERSION=@value{VERSION}=
+
+GREPEDITION=@value{EDITION}=
+
+GREPDATE=@value{UPDATED}=
+
+GREPMONTH=@value{UPDATED-MONTH}=
+
+@bye
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE all dvi
+
+# Debugging & sanity checks.
+ls -l
+cat version.texi
+cat foo.info
+test -f foo.dvi
+
+$MAKE test-grepinfo
+$MAKE test-distfiles
+$MAKE test-distdir
+$MAKE distcheck
+
+:
diff --git a/t/txinfo-without-info-suffix.sh b/t/txinfo-without-info-suffix.sh
new file mode 100644
index 000000000..529596aab
--- /dev/null
+++ b/t/txinfo-without-info-suffix.sh
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure .info-less @setfilename works.
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = textutils.texi
+END
+
+cat > textutils.texi <<EOF
+\input texinfo
+@c dummy comment
+@setfilename textutils
+@settitle main
+@node Top
+Hello walls.
+@bye
+EOF
+
+$ACLOCAL
+$AUTOCONF
+AUTOMAKE_fails -a
+$EGREP '^(\./)?textutils\.texi:3:.*suffix-less info file' stderr
+
+$AUTOMAKE -a -Wno-obsolete
+
+grep '^INFO_DEPS.*textutils$' Makefile.in
+
+# We should not use single suffix inference rules (with separate
+# dependencies), this confuses Solaris make.
+grep '^\.texi:$' Makefile.in && exit 1
+grep 'textutils: *textutils\.texi' Makefile.in
+
+./configure
+$MAKE distcheck
+
+:
diff --git a/t/txinfo19.sh b/t/txinfo19.sh
new file mode 100644
index 000000000..45dd2f9ac
--- /dev/null
+++ b/t/txinfo19.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test support for DJGPP's .iNN info files.
+
+required=makeinfo
+. test-init.sh
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = main.texi
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@bye
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+
+./configure "--infodir=$(pwd)/_inst"
+$MAKE
+
+# Make sure .iNN files are installed.
+: > main.i1
+: > main.i21
+$MAKE install
+test -f _inst/main.i1
+test -f _inst/main.i21
+
+# They should be uninstalled too.
+$MAKE uninstall
+test ! -e _inst/main.i1
+test ! -e _inst/main.i21
+
+# Make sure rebuild rules erase old .iNN files when they run makeinfo.
+$sleep
+touch main.texi
+test -f main.i1
+test -f main.i21
+$MAKE
+test ! -e main.i1
+test ! -e main.i21
+
+# Finally, we also want them erased by maintainer-clean.
+: > main.i7
+: > main.i39
+$MAKE maintainer-clean
+test ! -e main.i7
+test ! -e main.i39
+
+:
diff --git a/t/txinfo23.sh b/t/txinfo23.sh
new file mode 100644
index 000000000..b684f9985
--- /dev/null
+++ b/t/txinfo23.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that info files are built in builddir when needed.
+# Test with subdir Texinfo.
+# (Similar to txinfo13.sh, plus DISTCLEANFILES).
+# (See also txinfo24.sh and txinfo25.sh).
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+DISTCLEANFILES = subdir/*.info*
+info_TEXINFOS = subdir/main.texi
+subdir_main_TEXINFOS = subdir/inc.texi
+
+installcheck-local:
+ test -f "$(infodir)/main.info"
+END
+
+mkdir subdir
+
+cat > subdir/main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@include version.texi
+@include inc.texi
+@bye
+END
+
+cat > subdir/inc.texi << 'END'
+I'm included.
+END
+
+$ACLOCAL
+$AUTOCONF
+
+AUTOMAKE_run --add-missing -Wno-error
+grep "Makefile\.am:.*undocumented.* automake hack" stderr
+grep "Makefile\.am:.*'info-in-builddir' automake option" stderr
+
+mkdir build
+cd build
+../configure
+$MAKE distcheck
+test -f subdir/main.info
+test ! -e ../subdir/main.info
+
+:
diff --git a/t/txinfo24.sh b/t/txinfo24.sh
new file mode 100644
index 000000000..f3c908ce8
--- /dev/null
+++ b/t/txinfo24.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that info files are built in builddir when needed.
+# (Similar to txinfo16.sh, plus CLEANFILES).
+# (See also txinfo23.sh and txinfo25.sh).
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+CLEANFILES = main.info
+info_TEXINFOS = main.texi
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing -Wno-obsolete
+$AUTOCONF
+
+mkdir build
+cd build
+../configure
+$MAKE
+test ! -e ../main.info
+test -f main.info
+
+cd ..
+rm -rf build
+./configure
+$MAKE
+test -f main.info
+
+# Make sure stamp-vti is older that version.texi.
+# (A common situation in a real tree).
+test -f stamp-vti
+test -f version.texi
+$sleep
+touch stamp-vti
+
+$MAKE distclean
+test -f stamp-vti
+test -f version.texi
+
+mkdir build
+cd build
+../configure
+$MAKE
+# main.info should be rebuilt in the current directory.
+test -f main.info
+test ! -e ../main.info
+$MAKE dvi
+test -f main.dvi
+
+$MAKE distcheck
+
+:
diff --git a/t/txinfo25.sh b/t/txinfo25.sh
new file mode 100644
index 000000000..62237d351
--- /dev/null
+++ b/t/txinfo25.sh
@@ -0,0 +1,116 @@
+#! /bin/sh
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that info files are built in builddir and in srcdir can safely
+# co-exist. This setup is obtained by having two info files, only one
+# of which being cleaned.
+# (Similar to txinfo16.sh, plus CLEANFILES).
+# (See also txinfo23.sh and txinfo24.sh).
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+CLEANFILES = [a-m]*.info
+info_TEXINFOS = main.texi other.texi
+END
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+cat > other.texi << 'END'
+\input texinfo
+@setfilename other.info
+@settitle other
+@node Top
+Hello walls.
+@include version2.texi
+@bye
+END
+
+$ACLOCAL
+$AUTOCONF
+
+AUTOMAKE_fails --add-missing
+grep "Makefile\.am:.*undocumented.* automake hack" stderr
+grep "Makefile\.am:.*'info-in-builddir' automake option" stderr
+
+$AUTOMAKE --add-missing -Wno-obsolete
+
+mkdir build
+cd build
+../configure
+$MAKE
+test -f main.info
+test ! -e ../main.info
+test ! -e other.info
+test -f ../other.info
+
+cd ..
+rm -rf build
+./configure
+$MAKE
+test -f main.info
+test -f other.info
+
+# Make sure stamp-vti is older that version.texi.
+# (A common situation in a real tree).
+# This is needed to test the "subtle" issue described below.
+test -f stamp-vti
+test -f version.texi
+test -f stamp-1
+test -f version2.texi
+$sleep
+touch stamp-vti
+touch stamp-1
+
+$MAKE distclean
+test -f stamp-vti
+test -f stamp-1
+test -f version.texi
+test -f version2.texi
+
+mkdir build
+cd build
+../configure
+$MAKE
+# other.info should not be rebuilt in the current directory, since
+# it's up-to-date in $(srcdir).
+# This can be caused by a subtle issue related to VPATH handling
+# of version.texi (see also the comment in texi-vers.am): because
+# stamp-vti is newer than version.texi, the 'version.texi: stamp-vti'
+# rule is always triggered. Still that's not a reason for 'make'
+# to think 'version.texi' has been created...
+test -f main.info
+test ! -e other.info
+$MAKE dvi
+test -f main.dvi
+test -f other.dvi
+
+$MAKE distcheck
+
+:
diff --git a/t/txinfo28.sh b/t/txinfo28.sh
new file mode 100644
index 000000000..27974bd42
--- /dev/null
+++ b/t/txinfo28.sh
@@ -0,0 +1,89 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that info files are built in builddir when needed.
+# Similar to txinfo24.sh, but obfuscating filenames with variable
+# references.
+# Report from Ralf Corsepius.
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+# This setting, when honored by GNU ls, used to cause an infinite loop
+# in mdate-sh.
+TIME_STYLE="+%Y-%m-%d %H:%M:%S"
+export TIME_STYLE
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am << 'END'
+MA = ma
+IN = in
+PROJ = $(MA)$(IN)
+include fragment.mk
+info_TEXINFOS = ma$(IN).texi
+END
+
+echo 'CLEANFILES = $(PROJ).info' > fragment.mk
+
+cat > main.texi << 'END'
+\input texinfo
+@setfilename main.info
+@settitle main
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing -Wno-error
+$AUTOCONF
+
+mkdir build
+cd build
+../configure
+$MAKE
+test -f main.info
+
+cd ..
+rm -rf build
+./configure
+$MAKE
+test -f main.info
+
+# Make sure stamp-vti is older that version.texi.
+# (A common situation in a real tree).
+test -f stamp-vti
+test -f version.texi
+$sleep
+touch stamp-vti
+
+$MAKE distclean
+test -f stamp-vti
+test -f version.texi
+
+mkdir build
+cd build
+../configure
+$MAKE
+# main.info should be rebuilt in the current directory.
+test -f main.info
+test ! -e ../main.info
+$MAKE dvi
+test -f main.dvi
+
+$MAKE distcheck
diff --git a/t/uninstall-fail.sh b/t/uninstall-fail.sh
new file mode 100644
index 000000000..d712f8c6f
--- /dev/null
+++ b/t/uninstall-fail.sh
@@ -0,0 +1,101 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# "make uninstall" complains and errors out on failures.
+
+# FIXME: this test only deal with DATA primary; maybe we need sister
+# tests for other primaries too? E.g., SCRIPTS, PROGRAMS, LISP, PYTHON,
+# etc...
+
+. test-init.sh
+
+mkdir d
+: > d/f
+chmod a-w d || skip "cannot make directories unwritable"
+
+# On Solaris 10, if '/bin/rm' is run with the '-f' option, it doesn't
+# print any error message when failing to remove a file (due to e.g.,
+# "Permission denied"). And it gets weirder. On OpenIndiana 11, the
+# /bin/sh shell (in many respects a decent POSIX shell) seems to somehow
+# "eat" the error message from 'rm' in some situation, although the 'rm'
+# utility itself correctly prints it when invoked from (say) 'env' or
+# 'bash'. Yikes.
+# We'll cater to these incompatibilities by relaxing a test below if
+# a faulty shell or 'rm' program is detected.
+st=0; $SHELL -c 'rm -f d/f' 2>stderr || st=$?
+cat stderr >&2
+test $st -gt 0 || skip_ "can delete files from unwritable directories"
+if grep 'rm:' stderr; then
+ rm_f_is_silent_on_error=no
+else
+ rm_f_is_silent_on_error=yes
+fi
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+data_DATA = foobar.txt
+END
+
+: > foobar.txt
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+# Weird name, to make it harder to experience false positives when
+# grepping error messages.
+inst=__inst-dir__
+
+./configure --prefix="$(pwd)/$inst"
+
+mkdir $inst $inst/share
+: > $inst/share/foobar.txt
+
+chmod a-w $inst/share
+run_make -M -e FAIL uninstall
+if test $rm_f_is_silent_on_error = yes; then
+ : "rm -f" is silent on errors, skip the grepping of make output
+else
+ grep "rm: .*foobar\.txt" output
+fi
+
+chmod a-rwx $inst/share
+(cd $inst/share) && skip_ "cannot make directories fully unreadable"
+
+run_make -M -e FAIL uninstall
+
+# Some shells, like Solaris 10 /bin/ksh and /usr/xpg4/bin/sh, do not
+# report the name of the 'cd' builtin upon a chdir error:
+#
+# $ /bin/ksh -c 'cd /none'
+# /bin/ksh: /none: not found
+#
+# and also print a line number in the error message *if the command
+# contains newlines*:
+#
+# $ /bin/ksh -c 'cd unreadable'
+# /bin/ksh: unreadable: permission denied
+# $ /bin/ksh -c '\
+# > \
+# > cd unreadable'
+# /bin/ksh[3]: unreadable: permission denied
+
+$EGREP "(cd|sh)(\[[0-9]*[0-9]\])?: .*$inst/share" output
+
+:
diff --git a/t/uninstall-pr9578.sh b/t/uninstall-pr9578.sh
new file mode 100644
index 000000000..5be96c77e
--- /dev/null
+++ b/t/uninstall-pr9578.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check against automake bug#9578: "make uninstall" issued before
+# "make install" or after a mere "make install-data" or a mere
+# "make install-exec" failed spuriously.
+#
+# FIXME: this test only deal with DATA and script primaries; maybe we
+# need sister tests for other primaries too? E.g., PROGRAMS, LISP,
+# PYTHON, etc...
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_OUTPUT
+END
+
+: > foo
+: > bar
+
+cat > Makefile.am << 'END'
+bin_SCRIPTS = foo
+data_DATA = bar
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure --prefix="$(pwd)/inst"
+
+$MAKE uninstall
+test ! -e inst
+
+rm -rf inst
+
+$MAKE install-exec
+test -f inst/bin/foo || exit 99 # Sanity check.
+$MAKE uninstall
+test ! -e inst/bin/foo
+
+$MAKE install-data
+test -f inst/share/bar || exit 99 # Sanity check.
+$MAKE uninstall
+test ! -e inst/share/bar
+
+rm -rf inst
+
+$MAKE install-exec
+test -f inst/bin/foo || exit 99 # Sanity check.
+$MAKE uninstall
+test ! -e inst/bin/foo
+
+:
diff --git a/t/unused.sh b/t/unused.sh
new file mode 100644
index 000000000..78a97d095
--- /dev/null
+++ b/t/unused.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for failing check for unused macros. From Johan Danielsson.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+MACRO_1
+MACRO_1_2
+MACRO_1_2_3
+END
+
+cat > acinclude.m4 << 'END'
+AC_DEFUN([MACRO_1], echo 1)
+AC_DEFUN([MACRO_1_2], echo 12)
+AC_DEFUN([MACRO_1_2_3], echo 123)
+END
+
+$ACLOCAL 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+test ! -s stderr
diff --git a/t/upc.sh b/t/upc.sh
new file mode 100644
index 000000000..e6453f60d
--- /dev/null
+++ b/t/upc.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# A simple Hello World for UPC.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AM_PROG_UPC
+AC_OUTPUT
+END
+
+cat > hello.upc << 'END'
+#include <stdio.h>
+#include <upc.h>
+int
+main (void)
+{
+ printf ("Thread %d says, 'Hello.'\n", MYTHREAD);
+ return 0;
+}
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = hello
+hello_SOURCES = hello.upc
+hello_LDADD = -lm
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure || exit $?
+$MAKE distcheck
+
+:
diff --git a/t/upc2.sh b/t/upc2.sh
new file mode 100644
index 000000000..0b2c801ed
--- /dev/null
+++ b/t/upc2.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that Automake suggests using AM_PROG_UPC if Unified Parallel C
+# sources are used.
+
+. test-init.sh
+
+echo AC_PROG_CC >>configure.ac
+
+cat >Makefile.am <<'END'
+bin_PROGRAMS = hello
+hello_SOURCES = hello.upc
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep AM_PROG_UPC stderr
diff --git a/t/upc3.sh b/t/upc3.sh
new file mode 100644
index 000000000..c5dce2607
--- /dev/null
+++ b/t/upc3.sh
@@ -0,0 +1,65 @@
+#! /bin/sh
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test that C and Unified Parallel C link safely.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_UPC
+AC_OUTPUT
+END
+
+cat > hello.upc << 'END'
+#include <stdio.h>
+#include <upc.h>
+#include "message.h"
+int
+main (void)
+{
+ printf ("Thread %d says, '%s'\n", MYTHREAD, message());
+ return 0;
+}
+END
+
+cat > message.h << 'END'
+const char *message (void);
+END
+
+cat > mix.c << 'END'
+#include "message.h"
+const char *
+message (void)
+{
+ return "Hello.";
+}
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = hello
+hello_SOURCES = hello.upc mix.c message.h
+hello_LDADD = -lm
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+./configure || exit $?
+$MAKE distcheck
+
+:
diff --git a/t/vala-configure.sh b/t/vala-configure.sh
new file mode 100644
index 000000000..b7ba9db14
--- /dev/null
+++ b/t/vala-configure.sh
@@ -0,0 +1,118 @@
+#! /bin/sh
+# Copyright (C) 2008-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test AM_PROG_VALAC.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_VALAC([1.2.3])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+has-valac:
+ case '$(VALAC)' in */bin/valac) exit 0;; *) exit 1;; esac
+no-valac:
+ test x'$(VALAC)' = x'valac'
+END
+
+mkdir bin
+cat > bin/valac << 'END'
+#! /bin/sh
+if test "x$1" = x--version; then
+ echo "${vala_version-1.2.3}"
+fi
+exit 0
+END
+chmod +x bin/valac
+
+cat > bin/valac.old << 'END'
+#! /bin/sh
+if test "x$1" = x--version; then
+ echo 0.1
+fi
+exit 0
+END
+chmod +x bin/valac.old
+
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
+
+# Avoid interferences from the environment.
+unset VALAC vala_version
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+st=0; ./configure 2>stderr || st=$?
+cat stderr >&2
+grep 'WARNING.*vala' stderr && exit 1
+test $st -eq 0
+$MAKE has-valac
+
+st=0; vala_version=99.9 ./configure 2>stderr || st=$?
+cat stderr >&2
+grep 'WARNING.*vala' stderr && exit 1
+test $st -eq 0
+$MAKE has-valac
+
+st=0; vala_version=0.1.2 ./configure 2>stderr || st=$?
+cat stderr >&2
+test $st -eq 0
+grep '^configure: WARNING: no proper vala compiler found' stderr
+$MAKE no-valac
+
+st=0; ./configure VALAC="$(pwd)/bin/valac.old" 2>stderr || st=$?
+cat stderr >&2
+test $st -eq 0 || exit 1
+grep '^configure: WARNING: no proper vala compiler found' stderr
+$MAKE no-valac
+
+sed 's/^\(AM_PROG_VALAC\).*/\1([1], [: > ok], [: > ko])/' <configure.ac >t
+mv -f t configure.ac
+rm -rf autom4te*.cache
+$ACLOCAL
+$AUTOCONF
+
+st=0; ./configure 2>stderr || st=$?
+cat stderr >&2
+grep 'WARNING.*vala' stderr && exit 1
+test -f ok
+test ! -e ko
+$MAKE has-valac
+rm -f ok ko
+
+st=0; vala_version=0.1.2 ./configure 2>stderr || st=$?
+cat stderr >&2
+grep 'WARNING.*vala' stderr && exit 1
+test $st -eq 0
+test ! -e ok
+test -f ko
+$MAKE no-valac
+rm -f ok ko
+
+st=0; ./configure VALAC="$(pwd)/bin/valac.old" 2>stderr || st=$?
+cat stderr >&2
+grep 'WARNING.*vala' stderr && exit 1
+test $st -eq 0
+test ! -e ok
+test -f ko
+$MAKE no-valac
+rm -f ok ko
+
+:
diff --git a/t/vala-grepping.sh b/t/vala-grepping.sh
new file mode 100644
index 000000000..528b9faad
--- /dev/null
+++ b/t/vala-grepping.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic "grepping" test on vala support.
+
+. test-init.sh
+
+# So that we won't require libtool macros.
+cat > acinclude.m4 <<'END'
+AC_DEFUN([AC_PROG_LIBTOOL],
+ [AC_SUBST([LIBTOOL], [:])])
+END
+
+cat >> 'configure.ac' << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AM_PROG_VALAC
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = zardoz.vala
+zardoz_VALAFLAGS = --debug
+
+lib_LTLIBRARIES = libzardoz.la
+libzardoz_la_SOURCES = zardoz-foo.vala zardoz-bar.vala
+END
+
+mkdir sub
+
+cat > sub/Makefile.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = bar.vala baz.vala mu.c zap.cxx
+END
+
+: > ltmain.sh
+: > config.sub
+: > config.guess
+
+$ACLOCAL
+$AUTOMAKE -a
+
+grep '\$(VALAC).* \$(AM_VALAFLAGS) \$(VALAFLAGS) ' Makefile.in
+grep '\$(VALAC).* \$(zardoz_VALAFLAGS) \$(VALAFLAGS) ' Makefile.in
+$FGREP 'am_zardoz_OBJECTS' Makefile.in
+$FGREP 'am_libzardoz_la_OBJECTS' Makefile.in
+$FGREP 'zardoz_vala.stamp:' Makefile.in
+$FGREP 'libzardoz_la_vala.stamp:' Makefile.in
+test $($FGREP -c '.stamp:' Makefile.in) -eq 2
+$FGREP 'zardoz.c' Makefile.in
+$FGREP 'zardoz-foo.c' Makefile.in
+$FGREP 'zardoz-bar.c' Makefile.in
+
+grep '\$(VALAC).* \$(AM_VALAFLAGS) \$(VALAFLAGS) ' sub/Makefile.in
+$FGREP 'foo_VALAFLAGS' sub/Makefile.in && exit 1
+$FGREP 'am_foo_OBJECTS' sub/Makefile.in
+$FGREP 'bar.c' sub/Makefile.in
+$FGREP 'baz.c' sub/Makefile.in
+$FGREP 'foo_vala.stamp:' sub/Makefile.in
+test $($FGREP -c '.stamp:' sub/Makefile.in) -eq 1
+
+# Check against regression for weird bug due to unescaped '@'
+# characters used in a "..." perl string when writing the vala
+# rules from automake.in.
+grep '\$[0-9][0-9]*t' Makefile.in sub/Makefile.in && exit 1
+
+:
diff --git a/t/vala-headers.sh b/t/vala-headers.sh
new file mode 100644
index 000000000..07f471c25
--- /dev/null
+++ b/t/vala-headers.sh
@@ -0,0 +1,85 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure compiling Vala code really works with recursive make.
+
+required="pkg-config valac gcc GNUmake"
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_VALAC([0.7.0])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz quux
+
+zardoz_SOURCES = zardoz.vala
+quux_SOURCES = quux.vala
+quux.vala: zardoz.vala
+ sed 's/Zardoz/Quux/' <zardoz.vala >quux.vala
+
+quux_VALAFLAGS = \
+ --header HDR.h \
+ --vapi hello.vapi
+
+zardoz_VALAFLAGS = \
+ -H foo.h \
+ --internal-header foo2.h \
+ --internal-vapi foo3.vapi
+
+AM_CFLAGS = $(GOBJECT_CFLAGS)
+LDADD = $(GOBJECT_LIBS)
+END
+
+headers='HDR.h hello.vapi foo.h foo2.h foo3.vapi'
+
+cat > zardoz.vala << 'END'
+using GLib;
+public class Zardoz {
+ public static void main () {
+ stdout.printf ("Zardoz!\n");
+ }
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+
+# Test rebuild rules.
+
+for h in $headers; do
+ rm -f $h
+ $MAKE $h
+ test -f $h
+done
+
+rm -f $headers
+$MAKE $headers
+for h in $headers; do test -f $h; done
+
+$MAKE distcheck
+
+$MAKE maintainer-clean
+for h in $headers; do test ! -e $h; done
+
+:
diff --git a/t/vala-libs.sh b/t/vala-libs.sh
new file mode 100644
index 000000000..60e41579d
--- /dev/null
+++ b/t/vala-libs.sh
@@ -0,0 +1,100 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Building libraries (libtool and static) from Vala sources.
+# And use of vapi files to call C code from Vala.
+
+required="valac cc pkg-config libtoolize GNUmake"
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_PROG_LIBTOOL
+AM_PROG_VALAC([0.7.3])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+lib_LIBRARIES = libmu.a
+lib_LTLIBRARIES = src/libzardoz.la
+libmu_a_SOURCES = mu.vala mu2.c mu.vapi mu2.h
+libmu_a_CPPFLAGS = -DOKOKIMDEFINED=1
+libmu_a_VALAFLAGS = --vapidir=$(srcdir)
+AM_CFLAGS = $(GOBJECT_CFLAGS)
+src_libzardoz_la_LIBADD = $(GOBJECT_LIBS)
+src_libzardoz_la_SOURCES = src/zardoz-foo.vala src/zardoz-bar.vala
+src/zardoz-bar.vala: src/zardoz-foo.vala
+ sed 's/Foo/Bar/g' $< >$@
+END
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+cat > mu2.c << 'END'
+#include "mu2.h"
+int mu2 (void)
+{
+ return OKOKIMDEFINED;
+}
+END
+
+cat > mu2.h << 'END'
+int mu2 (void);
+END
+
+cat > mu.vapi <<'END'
+[CCode (cheader_filename = "mu2.h", cname = "mu2")]
+public int c_mu2 ();
+END
+
+cat > mu.vala << 'END'
+int main ()
+{
+ stdout.printf ("mumumu\n");
+ return c_mu2 ();
+}
+END
+
+mkdir -p src
+cat > src/zardoz-foo.vala << 'END'
+using GLib;
+public class Foo {
+ public static void zap () {
+ stdout.printf ("FooFooFoo!\n");
+ }
+}
+END
+
+$MAKE
+test -f libmu.a
+test -f src/libzardoz.la
+$FGREP "mumumu" mu.c
+$FGREP "FooFooFoo" src/zardoz-foo.c
+$FGREP "BarBarBar" src/zardoz-bar.c
+test -f libmu_a_vala.stamp
+test -f src_libzardoz_la_vala.stamp
+
+$MAKE distcheck
+
+:
diff --git a/t/vala-mix.sh b/t/vala-mix.sh
new file mode 100644
index 000000000..384efa9ac
--- /dev/null
+++ b/t/vala-mix.sh
@@ -0,0 +1,125 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Vala sources and C sources in the same program. Functional test.
+
+required='valac cc pkg-config GNUmake'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_VALAC([0.7.3])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = zardoz mu baz
+AM_CFLAGS = $(GOBJECT_CFLAGS)
+LDADD = $(GOBJECT_LIBS)
+zardoz_SOURCES = foo.vala bar.c
+mu_SOURCES = 1.vala 2.c
+mu_VALAFLAGS = --main=run
+mu_CFLAGS = -DHAVE_MU $(AM_CFLAGS)
+baz_SOURCES = baz.c
+END
+
+if ! cross_compiling; then
+ unindent >> Makefile.am <<'END'
+ check-local:
+ ./zardoz
+ ./mu
+ ./zardoz | grep "foo is alive"
+ ./mu | grep "Howdy, World!"
+END
+fi
+
+cat > foo.vala <<'END'
+int main ()
+{
+ stdout.printf ("foo is alive\n");
+ return 0;
+}
+END
+
+echo 'extern int i = 0;' > bar.c
+
+cat > 1.vala <<'END'
+int run ()
+{
+ stdout.printf ("Howdy, World!\n");
+ return 0;
+}
+END
+
+cat > 2.c <<'END'
+#ifdef HAVE_MU
+int all_is_ok = 1;
+#else
+#error "HAVE_MU no defined"
+chocke me
+#endif
+END
+
+# For automake bug#11229.
+cat > baz.c <<'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+./configure
+
+$MAKE all
+ls -l # For debugging.
+$MAKE check
+
+have_generated_files ()
+{
+ test -f mu_vala.stamp
+ test -f zardoz_vala.stamp
+ test -f foo.c
+ test -f 1.c
+}
+
+# Our vala-related rules must create stamp files and intermediate
+# C files.
+have_generated_files
+
+# Remake rules are not uselessly triggered.
+$MAKE -q
+$MAKE -n | $FGREP vala.stamp && exit 1
+
+# Check the distribution.
+$MAKE distcheck
+
+# Stamp files and intermediate C files should *not* be removed
+# by "make clean".
+$MAKE clean
+have_generated_files
+
+# But stamp files should be removed by "maintainer-clean" (the
+# behaviour w.r.t. intermediate C files is still unclear, and
+# better left undefined for the moment).
+$MAKE maintainer-clean
+ls *vala*.stamp | grep . && exit 1
+
+:
diff --git a/t/vala-mix2.sh b/t/vala-mix2.sh
new file mode 100644
index 000000000..35f3abda6
--- /dev/null
+++ b/t/vala-mix2.sh
@@ -0,0 +1,122 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Vala sources, C and C++ sources and C and C++ headers in the same
+# program. Functional test. See automake bug#10894.
+
+required='valac cc c++ pkg-config GNUmake'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_PROG_CXX
+AM_PROG_VALAC([0.7.3])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = zardoz
+AM_CFLAGS = $(GOBJECT_CFLAGS)
+zardoz_LDADD = $(GOBJECT_LIBS)
+zardoz_SOURCES = zardoz.vala foo.h bar.c baz.c zen.hh master.cxx
+END
+
+cat > zardoz.vala <<'END'
+int main ()
+{
+ stdout.printf ("foo is alive\n");
+ return 0;
+}
+END
+
+cat > foo.h <<'END'
+int foo;
+int bar (void);
+int baz (void);
+END
+
+cat > bar.c <<'END'
+#include "foo.h"
+int bar (void) { return foo + baz (); }
+END
+
+cat > baz.c <<'END'
+#include "foo.h"
+extern int foo = 0;
+int baz (void) { return 0; }
+END
+
+cat > zen.hh <<'END'
+#include <iostream>
+END
+
+cat > master.cxx <<'END'
+#include "zen.hh"
+void chatty (void) { std::cout << "Hello, stranger!\n"; }
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+# Do not reject slower dependency extractors.
+./configure --enable-dependency-tracking
+
+$MAKE all
+ls -l # For debugging.
+
+have_generated_files ()
+{
+ test -f zardoz_vala.stamp
+ test -f zardoz.c
+}
+
+# Our vala-related rules must create stamp files and intermediate
+# C files.
+have_generated_files
+
+# Remake rules are not uselessly triggered.
+$MAKE -q
+$MAKE -n | $FGREP vala.stamp && exit 1
+
+# But are triggered when they should.
+for file in zardoz.vala foo.h bar.c baz.c zen.hh master.cxx; do
+ $sleep
+ echo '& choke me !' >> $file
+ $MAKE && exit 1
+ $sleep
+ sed '$d' $file > t
+ mv -f t $file
+ $MAKE
+done
+
+# Check the distribution.
+$MAKE distcheck
+
+# Stamp files and intermediate C files should *not* be removed
+# by "make clean".
+$MAKE clean
+ls -l # For debugging.
+have_generated_files
+
+# But stamp files should be removed by "maintainer-clean" (the
+# behaviour w.r.t. intermediate C files is still unclear, and
+# better left undefined for the moment).
+$MAKE maintainer-clean
+ls *vala*.stamp | grep . && exit 1
+
+:
diff --git a/t/vala-non-recursive-setup.sh b/t/vala-non-recursive-setup.sh
new file mode 100644
index 000000000..6c20d9662
--- /dev/null
+++ b/t/vala-non-recursive-setup.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure compiling Vala code really works with non-recursive make.
+
+required="pkg-config valac gcc GNUmake"
+. test-init.sh
+
+mkdir src
+
+cat >> 'configure.ac' << 'END'
+AC_PROG_CC
+AM_PROG_VALAC([0.7.0])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AC_OUTPUT
+END
+
+cat > 'src/zardoz.vala' <<'END'
+using GLib;
+
+public class Zardoz {
+ public static void main () {
+ stdout.printf ("Zardoz!\n");
+ }
+}
+END
+
+cat > 'Makefile.am' <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = src/zardoz
+src_zardoz_CFLAGS = $(GOBJECT_CFLAGS)
+src_zardoz_LDADD = $(GOBJECT_LIBS)
+src_zardoz_SOURCES = src/zardoz.vala
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+test -f src/zardoz.c
+test -f src_zardoz_vala.stamp
+$MAKE distcheck
+$MAKE maintainer-clean
+test ! -e src/zardoz.c
+test ! -e src_zardoz_vala.stamp
+
+mkdir build
+cd build
+../configure
+$MAKE
+$MAKE distcheck
+
+cd ..
+rm -rf build
+
+# Try again with subdir-objects.
+
+cat > 'Makefile.am' <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+
+bin_PROGRAMS = src/zardoz
+src_zardoz_CFLAGS = $(GOBJECT_CFLAGS)
+src_zardoz_LDADD = $(GOBJECT_LIBS)
+src_zardoz_SOURCES = src/zardoz.vala
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure || skip_ "configure failure"
+$MAKE
+$MAKE distcheck
+$MAKE distclean
+mkdir build
+cd build
+../configure
+$MAKE
+$MAKE distcheck
diff --git a/t/vala-parallel.sh b/t/vala-parallel.sh
new file mode 100644
index 000000000..24a66c613
--- /dev/null
+++ b/t/vala-parallel.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Vala support with parallel make.
+
+required='valac cc pkg-config GNUmake'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_PROG_CXX
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AM_PROG_VALAC([0.7.3])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = zardoz
+AM_CFLAGS = $(GOBJECT_CFLAGS)
+LDADD = $(GOBJECT_LIBS)
+zardoz_SOURCES = main.vala 1.vala 2.vala 3.vala 4.vala 5.vala 6.vala
+END
+
+echo 'int main () {' > main.vala
+for i in 1 2 3 4 5 6; do
+ echo "void foo$i () { stdout.printf (\"ok $i\\n\"); }" > $i.vala
+ echo "foo$i ();" >> main.vala
+done
+echo 'return 0; }' >> main.vala
+
+cat main.vala # For debugging.
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+./configure
+
+$MAKE -j3
+ls -l # For debugging.
+for x in main 1 2 3 4 5 6; do test -f $x.c; done
+test -f zardoz_vala.stamp
+
+$MAKE maintainer-clean -j4
+ls -l # For debugging.
+for x in main 1 2 3 4 5 6; do test ! -e $x.c; done
+test ! -e zardoz_vala.stamp
+
+mkdir build
+cd build
+../configure
+$MAKE -j6
+ls -l . .. # For debugging.
+for x in main 1 2 3 4 5 6; do test -f ../$x.c; done
+test -f ../zardoz_vala.stamp
+
+$MAKE distcheck -j4
+
+$MAKE maintainer-clean -j2
+for x in main 1 2 3 4 5 6; do test ! -e ../$x.c; done
+test ! -e ../zardoz_vala.stamp
+
+:
diff --git a/t/vala-per-target-flags.sh b/t/vala-per-target-flags.sh
new file mode 100644
index 000000000..e0cf7ddb1
--- /dev/null
+++ b/t/vala-per-target-flags.sh
@@ -0,0 +1,100 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test per-target flags in vala support.
+
+required="pkg-config valac gcc GNUmake"
+. test-init.sh
+
+mkdir src
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_VALAC([0.7.0])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AC_CONFIG_FILES([src/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = src
+END
+
+cat > src/Makefile.am <<'END'
+bin_PROGRAMS = foo bar
+foo_CFLAGS = $(GOBJECT_CFLAGS)
+foo_LDADD = $(GOBJECT_LIBS)
+foo_SOURCES = xfoo.vala
+bar_SOURCES = xbar.vala
+bar_VALAFLAGS = -D BAR
+bar_CFLAGS = $(GOBJECT_CFLAGS)
+bar_LDADD = $(GOBJECT_LIBS)
+END
+
+cat > src/xfoo.vala <<'END'
+int main ()
+{
+ stdout.printf ("foo\n");
+ return 0;
+}
+END
+
+cat > src/xbar.vala <<'END'
+void main ()
+{
+#if BAR
+ stdout.printf ("bar\n");
+#else
+ stdout.oops_an_invalid_method ();
+#endif
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+
+if ! cross_compiling; then
+ ./src/foo
+ ./src/bar
+ test "$(./src/foo)" = foo
+ test "$(./src/bar)" = bar
+fi
+
+# Test clean rules.
+
+cp config.status config.sav
+
+$MAKE clean
+test -f src/xfoo.c
+test -f src/xbar.c
+
+$MAKE distclean
+test -f src/xfoo.c
+test -f src/xbar.c
+
+# Re-create Makefile.
+mv config.sav config.status
+./config.status
+
+$MAKE maintainer-clean
+test ! -e src/xfoo.c
+test ! -e src/xbar.c
+
+:
diff --git a/t/vala-recursive-setup.sh b/t/vala-recursive-setup.sh
new file mode 100644
index 000000000..5404e8f8e
--- /dev/null
+++ b/t/vala-recursive-setup.sh
@@ -0,0 +1,107 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure compiling Vala code really works with recursive make.
+
+required="pkg-config valac gcc GNUmake"
+. test-init.sh
+
+mkdir src
+
+cat >> 'configure.ac' << 'END'
+AC_PROG_CC
+AM_PROG_VALAC([0.7.0])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AC_CONFIG_FILES([src/Makefile])
+AC_OUTPUT
+END
+
+cat > 'Makefile.am' <<'END'
+SUBDIRS = src
+END
+
+cat > 'src/Makefile.am' <<'END'
+bin_PROGRAMS = zardoz
+zardoz_VALAFLAGS = -H zardoz.h
+zardoz_CFLAGS = $(GOBJECT_CFLAGS)
+zardoz_LDADD = $(GOBJECT_LIBS)
+zardoz_SOURCES = zardoz.vala
+END
+
+cat > 'src/zardoz.vala' <<'END'
+using GLib;
+
+public class Zardoz {
+ public static void main () {
+ stdout.printf ("Zardoz!\n");
+ }
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+
+# Test rebuild rules.
+
+rm -f src/zardoz.h
+$MAKE -C src zardoz.h
+test -f src/zardoz.h
+rm -f src/zardoz.c
+$MAKE -C src
+test -f src/zardoz.c
+
+echo am--error > src/zardoz.h
+echo am--error > src/zardoz.c
+$sleep
+touch src/zardoz.vala
+$MAKE
+grep 'am--error' src/zardoz.[ch] && exit 1
+
+# Check the distribution.
+
+$MAKE distcheck
+$MAKE distclean
+
+# Tru a VPATH setup.
+
+mkdir build
+cd build
+../configure
+$MAKE
+$MAKE distcheck
+
+# Test rebuild rules from builddir.
+
+rm -f ../src/zardoz.h
+$MAKE -C src ../../src/zardoz.h
+test -f ../src/zardoz.h
+
+rm -f ../src/zardoz.c
+$MAKE
+grep 'Zardoz!' ../src/zardoz.c
+
+$sleep
+sed 's/Zardoz!/FooBar!/' ../src/zardoz.vala > t
+mv -f t ../src/zardoz.vala
+$MAKE
+grep 'FooBar!' ../src/zardoz.c
+grep 'Zardoz!' ../src/zardoz.c && exit 1
+
+:
diff --git a/t/vala-vapi.sh b/t/vala-vapi.sh
new file mode 100644
index 000000000..67bdbd24d
--- /dev/null
+++ b/t/vala-vapi.sh
@@ -0,0 +1,95 @@
+#! /bin/sh
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test and that vapi files are correctly handled by Vala support.
+
+required='pkg-config valac cc GNUmake'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AM_PROG_VALAC([0.7.3])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = zardoz
+AM_CFLAGS = $(GOBJECT_CFLAGS)
+LDADD = $(GOBJECT_LIBS)
+zardoz_SOURCES = zardoz.vala foo.vapi foo.h
+END
+
+cat > zardoz.vala <<'END'
+using GLib;
+public class Zardoz {
+ public static void main () {
+ stdout.printf (BARBAR);
+ }
+}
+END
+
+# Use printf, not echo, to avoid '\n' being considered and escape
+# sequence and printed as a newline in 'foo.h'.
+printf '%s\n' '#define BARBAR "Zardoz!\n"' > foo.h
+
+cat > foo.vapi <<'END'
+[CCode (cprefix="", lower_case_cprefix="", cheader_filename="foo.h")]
+public const string BARBAR;
+END
+
+if ! cross_compiling; then
+ unindent >> Makefile.am <<'END'
+ check-local: test2
+ .PHONY: test1 test2
+ test1:
+ ./zardoz
+ ./zardoz | grep 'Zardoz!'
+ test2:
+ ./zardoz
+ ./zardoz | grep 'Quux!'
+END
+fi
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+./configure --enable-dependency-tracking
+
+$MAKE
+ls -l # For debugging.
+cat zardoz.c # Likewise.
+grep 'BARBAR' zardoz.c
+cross_compiling || $MAKE test1 || exit 1
+
+# Simple check on remake rules.
+$sleep
+# Use printf, not echo, to avoid '\n' being considered and escape
+# sequence and printed as a newline in 'foo.h'.
+printf '%s\n' '#define BAZBAZ "Quux!\n"' > foo.h
+sed 's/BARBAR/BAZBAZ/' zardoz.vala > t && mv -f t zardoz.vala || exit 99
+$MAKE && exit 1
+sed 's/BARBAR/BAZBAZ/' foo.vapi > t && mv -f t foo.vapi || exit 99
+$MAKE
+cat zardoz.c # For debugging.
+grep 'BAZBAZ' zardoz.c
+cross_compiling || $MAKE test2 || exit 1
+
+# Check the distribution.
+$MAKE distcheck
+
+:
diff --git a/t/vala-vpath.sh b/t/vala-vpath.sh
new file mode 100644
index 000000000..5a841c6be
--- /dev/null
+++ b/t/vala-vpath.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure vala support handles from-scratch VPATH builds.
+# See automake bug#8753.
+
+required="cc valac pkg-config GNUmake"
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_SRCDIR([hello.vala])
+AC_PROG_CC
+AM_PROG_VALAC([0.7.3])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo bar
+AM_CFLAGS = $(GOBJECT_CFLAGS)
+LDADD = $(GOBJECT_LIBS)
+foo_SOURCES = hello.vala
+bar_VALAFLAGS = -H zardoz.h
+bar_SOURCES = goodbye.vala
+END
+
+cat > hello.vala <<'END'
+void main ()
+{
+ stdout.printf ("foofoofoo\n");
+}
+END
+cp hello.vala goodbye.vala
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+mkdir build
+cd build
+../configure
+$MAKE
+test -f ../foo_vala.stamp
+test -f ../bar_vala.stamp
+grep foofoofoo ../hello.c
+test -f ../zardoz.h
+$MAKE distcheck
+
+# Rebuild rules work also in VPATH builds.
+
+cat > ../hello.vala <<'END'
+int main ()
+{
+ stdout.printf ("barbarbar\n");
+ return 0;
+}
+END
+
+$MAKE
+test -f ../foo_vala.stamp
+test -f ../bar_vala.stamp
+grep barbarbar ../hello.c
+
+# Rebuild rules are not uselessly triggered.
+$MAKE -q
+$MAKE -n | grep '\.stamp' && exit 1
+
+# Cleanup rules work also in VPATH builds.
+$MAKE clean
+test -f ../foo_vala.stamp
+test -f ../bar_vala.stamp
+test -f ../zardoz.h
+test -f ../hello.c
+$MAKE maintainer-clean
+test ! -e ../zardoz.h
+test ! -e ../hello.c
+test ! -e ../foo_vala.stamp
+test ! -e ../bar_vala.stamp
+
+:
diff --git a/t/var-recurs.sh b/t/var-recurs.sh
new file mode 100644
index 000000000..571ea86bd
--- /dev/null
+++ b/t/var-recurs.sh
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure recursive variable definitions die.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = $(foo)
+foo = $(bin_PROGRAMS)
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'Makefile\.am:.*bin_PROGRAMS.*recursively defined' stderr
+
+:
diff --git a/t/var-recurs2.sh b/t/var-recurs2.sh
new file mode 100644
index 000000000..a3480fae2
--- /dev/null
+++ b/t/var-recurs2.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure recursive variable definitions die.
+# From Jim Meyering.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+man_MANS = chgrp.1
+man_aux = $(man_MANS:.1=.x)
+EXTRA_DIST = $(man_aux) $(man_MANS)
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/vars.sh b/t/vars.sh
new file mode 100644
index 000000000..73ee29f45
--- /dev/null
+++ b/t/vars.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test various variable definitions that include an '=' sign.
+# From Raja R Harinath.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+MY_FLAGS_1=-DABC=345
+MY_FLAGS_2= -DABC=345
+MY_FLAGS_3 =-DABC=345
+MY_FLAGS_4 = -DABC=345
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+for i in 1 2 3 4; do
+ grep "^MY_FLAGS_$i *= *-DABC=345 *$" Makefile.in
+done
+
+:
diff --git a/t/vars3.sh b/t/vars3.sh
new file mode 100644
index 000000000..22931a54c
--- /dev/null
+++ b/t/vars3.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that Automake warns about variables containing spaces
+# and other non-POSIX characters.
+
+. test-init.sh
+
+cat >Makefile.am <<'EOF'
+L01 = $(shell echo *)
+L02 = $$(not an error)
+L03 = $$(this is)$${ok too}
+L04 = $(nextvariableisbad)$(addsuffix .a, $(A))
+L05 = "$(bad boy)"
+L06 = $(this:is= ok)
+L07 = ${three errors}${on this} $(long line)
+L08$(o u c h): $(wildcard *.c)
+ ${another Error}
+ echo $${ok-this is}
+L11: $(thisis) $(ok)
+ ${here}
+EOF
+
+$ACLOCAL
+# Make sure this warning is print in the 'portability' category.
+$AUTOMAKE --warnings=no-error,none,portability 2>stderr \
+ || { cat stderr >&2; exit 1; }
+cat stderr >&2
+
+# Lines number are printed in error message.
+# Use them to make sure errors are diagnosed against the right lines.
+
+# No error expected apart from those on these lines.
+grep -v '^Makefile\.am:[145789]:' stderr | grep . && exit 1
+
+# Now check some individual values.
+grep ':1:.*shell echo' stderr
+grep 'nextvariableisbad' stderr && exit 1
+grep ':4:.*addsuffix' stderr
+grep ':5:.*bad boy' stderr
+grep ':7:.*three errors' stderr
+grep ':7:.*on this' stderr
+grep ':7:.*long line' stderr
+grep ':8:.*o u c h' stderr
+grep ':8:.*wildcard' stderr
+grep ':9:.*another Error' stderr
+
+$EGREP 'ok|thisis|here' stderr && exit 1
+
+# None of these errors be diagnosed with '-Wno-portability'.
+$AUTOMAKE -Wno-portability
+
+# Likewise if we add this in the Makefile.am
+# (although this makes some difference internally: AUTOMAKE_OPTIONS is
+# processed far later).
+echo 'AUTOMAKE_OPTIONS = -Wno-portability' >> Makefile.am
+$AUTOMAKE
+
+:
diff --git a/t/vartar.sh b/t/vartar.sh
new file mode 100644
index 000000000..0e611b6e6
--- /dev/null
+++ b/t/vartar.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Targets and macros are two different name spaces.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+install = install
+install:
+ $(install) install
+END
+
+$ACLOCAL
+$AUTOMAKE -Wno-override
+
+grep '^install = install$' Makefile.in
+
+cat > target.expected <<'EOF'
+install:
+ $(install) install
+EOF
+sed -n '/^install:/,/^ /p' Makefile.in > target.value
+diff target.expected target.value
+
+:
diff --git a/t/vartypo2.sh b/t/vartypo2.sh
new file mode 100644
index 000000000..77c05a6d6
--- /dev/null
+++ b/t/vartypo2.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we warn about possible variable typos when we should,
+# Libtool variant.
+
+required=libtoolize
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AM_PROG_AR
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+libfoo_la_SOURCES = unused
+nodist_libfoo_la_SOURCES = unused
+EXTRA_libfoo_la_SOURCES = unused
+libfoo_la_LIBADD = unused
+libfoo_la_DEPENDENCIES = unused
+EXTRA_libfoo_la_DEPENDENCIES = unused
+END
+
+libtoolize
+$ACLOCAL
+AUTOMAKE_fails --add-missing
+# The expected diagnostic is:
+# automake: warnings are treated as errors
+# Makefile.am:3: warning: variable 'EXTRA_libfoo_la_SOURCES' is defined but no program or
+# Makefile.am:3: library has 'libfoo_la' as canonical name (possible typo)
+# Makefile.am:1: warning: variable 'libfoo_la_SOURCES' is defined but no program or
+# Makefile.am:1: library has 'libfoo_la' as canonical name (possible typo)
+# Makefile.am:2: warning: variable 'nodist_libfoo_la_SOURCES' is defined but no program or
+# Makefile.am:2: library has 'libfoo_la' as canonical name (possible typo)
+# Makefile.am:4: warning: variable 'libfoo_la_LIBADD' is defined but no program or
+# Makefile.am:4: library has 'libfoo_la' as canonical name (possible typo)
+# Makefile.am:6: warning: variable 'EXTRA_libfoo_la_DEPENDENCIES' is defined but no program or
+# Makefile.am:6: library has 'libfoo_la' as canonical name (possible typo)
+# Makefile.am:5: warning: variable 'libfoo_la_DEPENDENCIES' is defined but no program or
+# Makefile.am:5: library has 'libfoo_la' as canonical name (possible typo)
+
+grep 'as canonical' stderr | grep -v ' .libfoo_la. ' && exit 1
+test $(grep -c 'variable.*is defined but' stderr) -eq 6
+
+# If we add a global -Wnone, all warnings should disappear.
+$AUTOMAKE -Wnone
+
+# Likewise, if matching programs or libraries are defined.
+cat >>Makefile.am <<'END'
+lib_LTLIBRARIES = libfoo.la
+END
+
+$AUTOMAKE
+
+:
diff --git a/t/vartypos.sh b/t/vartypos.sh
new file mode 100644
index 000000000..adfee9641
--- /dev/null
+++ b/t/vartypos.sh
@@ -0,0 +1,89 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure we warn about possible variable typos when we should.
+
+. test-init.sh
+
+cat >>configure.ac <<'END'
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+foo_SOURCES = unused
+nodist_foo_SOURCES = unused
+EXTRA_foo_SOURCES = unused
+foo_LDADD = unused
+foo_LDFLAGS = unused
+foo_DEPENDENCIES = unused
+EXTRA_foo_DEPENDENCIES = unused
+
+libfoo_a_SOURCES = unused
+nodist_libfoo_a_SOURCES = unused
+EXTRA_libfoo_a_SOURCES = unused
+libfoo_a_LIBADD = unused
+libfoo_a_DEPENDENCIES = unused
+EXTRA_libfoo_a_DEPENDENCIES = unused
+END
+
+$ACLOCAL
+AUTOMAKE_fails -Wno-extra-portability
+# The expected diagnostic is:
+# automake: warnings are treated as errors
+# Makefile.am:2: warning: variable 'nodist_foo_SOURCES' is defined but no program or
+# Makefile.am:2: library has 'foo' as canonical name (possible typo)
+# Makefile.am:1: warning: variable 'foo_SOURCES' is defined but no program or
+# Makefile.am:1: library has 'foo' as canonical name (possible typo)
+# Makefile.am:9: warning: variable 'libfoo_a_SOURCES' is defined but no program or
+# Makefile.am:9: library has 'libfoo_a' as canonical name (possible typo)
+# Makefile.am:10: warning: variable 'nodist_libfoo_a_SOURCES' is defined but no program or
+# Makefile.am:10: library has 'libfoo_a' as canonical name (possible typo)
+# Makefile.am:11: warning: variable 'EXTRA_libfoo_a_SOURCES' is defined but no program or
+# Makefile.am:11: library has 'libfoo_a' as canonical name (possible typo)
+# Makefile.am:3: warning: variable 'EXTRA_foo_SOURCES' is defined but no program or
+# Makefile.am:3: library has 'foo' as canonical name (possible typo)
+# Makefile.am:12: warning: variable 'libfoo_a_LIBADD' is defined but no program or
+# Makefile.am:12: library has 'libfoo_a' as canonical name (possible typo)
+# Makefile.am:4: warning: variable 'foo_LDADD' is defined but no program or
+# Makefile.am:4: library has 'foo' as canonical name (possible typo)
+# Makefile.am:5: warning: variable 'foo_LDFLAGS' is defined but no program or
+# Makefile.am:5: library has 'foo' as canonical name (possible typo)
+# Makefile.am:14: warning: variable 'EXTRA_libfoo_a_DEPENDENCIES' is defined but no program or
+# Makefile.am:14: library has 'libfoo_a' as canonical name (possible typo)
+# Makefile.am:7: warning: variable 'EXTRA_foo_DEPENDENCIES' is defined but no program or
+# Makefile.am:7: library has 'foo' as canonical name (possible typo)
+# Makefile.am:6: warning: variable 'foo_DEPENDENCIES' is defined but no program or
+# Makefile.am:6: library has 'foo' as canonical name (possible typo)
+# Makefile.am:13: warning: variable 'libfoo_a_DEPENDENCIES' is defined but no program or
+# Makefile.am:13: library has 'libfoo_a' as canonical name (possible typo)
+
+grep 'as canonical' stderr | grep -v ' .foo. ' | grep -v ' .libfoo_a. ' \
+ && exit 1
+test $(grep -c 'variable.*is defined but' stderr) -eq 13
+
+# If we add a global -Wnone, all warnings should disappear.
+$AUTOMAKE -Wnone
+
+# Likewise, if matching programs or libraries are defined.
+cat >>Makefile.am <<'END'
+bin_PROGRAMS = foo
+lib_LIBRARIES = libfoo.a
+END
+
+$AUTOMAKE -Wno-extra-portability
+
+:
diff --git a/t/version3.sh b/t/version3.sh
new file mode 100644
index 000000000..b01eafbbf
--- /dev/null
+++ b/t/version3.sh
@@ -0,0 +1,27 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure version in AUTOMAKE_OPTIONS works.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = 9.9x
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'Makefile.am:1:.*Automake 9.9x' stderr
diff --git a/t/version4.sh b/t/version4.sh
new file mode 100644
index 000000000..2504ad77e
--- /dev/null
+++ b/t/version4.sh
@@ -0,0 +1,26 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure we are compatible with the 1.4-p1 series.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = 1.4-p3
+END
+
+$ACLOCAL
+$AUTOMAKE
diff --git a/t/version6.sh b/t/version6.sh
new file mode 100644
index 000000000..8d5dea74b
--- /dev/null
+++ b/t/version6.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure the current version can be required.
+
+. test-init.sh
+
+amver=$($AUTOMAKE --version | sed -e 's/.* //;1q')
+
+# Does the extracted version number seems legit?
+case $amver in
+ *[0-9].[0-9]*) ;;
+ *) fatal_ "couldn't extract version number from automake" ;;
+esac
+
+cat > Makefile.am << END
+AUTOMAKE_OPTIONS = $amver
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/version7.sh b/t/version7.sh
new file mode 100644
index 000000000..9f9cf7044
--- /dev/null
+++ b/t/version7.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for a special setup where the package's version isn't defined
+# in configure.ac. We want GNU Make for this test (part of the test
+# is to make sure Makefile.ins get rebuilt when a m4_included file
+# changes -- we don't support this feature on non-GNU Makes).
+
+required='makeinfo tex texi2dvi'
+. test-init.sh
+
+cat >configure.ac <<END
+m4_include([version.m4])
+AC_INIT([$me], [THE_VERSION])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END
+
+echo 'm4_define([THE_VERSION], [2.718])' > version.m4
+
+cat > Makefile.am << 'END'
+info_TEXINFOS = zardoz.texi
+
+check:
+ test -f $(srcdir)/version.m4
+END
+
+cat > zardoz.texi << 'END'
+\input texinfo
+@setfilename zardoz.info
+@settitle Zardoz
+@node Top
+Hello walls.
+@include version.texi
+@bye
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure --version | grep '2\.718'
+./configure
+$MAKE
+grep '2\.718' version.texi
+
+$sleep
+echo 'm4_define([THE_VERSION], [3.141])' > version.m4
+using_gmake || $MAKE Makefile
+$MAKE distcheck
+./configure --version | grep '3\.141'
+grep '3\.141' version.texi
+
+:
diff --git a/t/version8.sh b/t/version8.sh
new file mode 100644
index 000000000..82647589b
--- /dev/null
+++ b/t/version8.sh
@@ -0,0 +1,24 @@
+#! /bin/sh
+# Copyright (C) 2005-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Calling AM_AUTOMAKE_VERSION by hand is a bug.
+
+. test-init.sh
+
+echo 'AM_AUTOMAKE_VERSION([1.9])' >>configure.ac
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 0; }
+cat stderr >&2
+$FGREP 'AM_INIT_AUTOMAKE([1.9])' stderr
diff --git a/t/vpath.sh b/t/vpath.sh
new file mode 100644
index 000000000..878e5420a
--- /dev/null
+++ b/t/vpath.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure VPATH can be overridden.
+# Report from Anthony Green.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+VPATH = zardoz
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep VPATH Makefile.in # For debugging.
+grep '^VPATH = zardoz$' Makefile.in
+grep 'VPATH.*@srcdir@' Makefile.in && exit 1
+
+:
diff --git a/t/warning-groups-win-over-strictness.sh b/t/warning-groups-win-over-strictness.sh
new file mode 100644
index 000000000..5c61357d4
--- /dev/null
+++ b/t/warning-groups-win-over-strictness.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that explicitly-defined warning levels take precedence over
+# implicit strictness-implied warnings, even when these explicit warning
+# levels are "catch-all warnings" (such as '-Wall' and '-Wnone').
+# Since we are at it, also throw in *.am and *.m4 file inclusions.
+
+. test-init.sh
+
+# We want complete control over automake options.
+AUTOMAKE=$am_original_AUTOMAKE
+
+# Files required in gnu and/or gnits strictness.
+touch README INSTALL NEWS AUTHORS ChangeLog COPYING THANKS
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+m4_include([am-init-automake.m4])
+AC_PROG_CC
+AC_CONFIG_FILES([Makefile])
+# Other similar tests do not use AC_OUTPUT, so we use it here,
+# for completeness and for better coverage.
+AC_OUTPUT
+END
+
+cat > Makefile.am <<END
+include automake-options.am
+FOO := bar
+END
+
+rm -rf autom4te*.cache
+: > automake-options.am
+echo 'AM_INIT_AUTOMAKE' > am-init-automake.m4
+$ACLOCAL
+AUTOMAKE_fails -Werror -Wall --foreign
+grep '^Makefile\.am:.*:=.*not portable' stderr
+
+rm -rf autom4te*.cache
+: > automake-options.am
+echo 'AM_INIT_AUTOMAKE([-Werror -Wnone gnu])' > am-init-automake.m4
+$ACLOCAL
+$AUTOMAKE
+
+rm -rf autom4te*.cache
+echo 'AUTOMAKE_OPTIONS = -Werror -Wnone gnits' > automake-options.am
+echo 'AM_INIT_AUTOMAKE' > am-init-automake.m4
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/warnings-obsolete-default.sh b/t/warnings-obsolete-default.sh
new file mode 100644
index 000000000..e95dd6b6e
--- /dev/null
+++ b/t/warnings-obsolete-default.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake warnings in the 'obsolete' category are enabled
+# by default.
+
+. test-init.sh
+
+# We want (almost) complete control over automake options.
+AUTOMAKE="$am_original_AUTOMAKE --foreign -Werror"
+
+echo AC_PROG_CC >> configure.ac
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo
+INCLUDES = -Ibar
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+grep '^Makefile\.am:2:.*INCLUDES.*AM_CPPFLAGS' stderr
+
+# Check that we can override warnings about obsolete stuff.
+$AUTOMAKE -Wno-obsolete
+
+:
diff --git a/t/warnings-override.sh b/t/warnings-override.sh
new file mode 100644
index 000000000..f5431ae74
--- /dev/null
+++ b/t/warnings-override.sh
@@ -0,0 +1,111 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# The warnings specified in Makefile.am:AUTOMAKE_OPTIONS should override
+# those specified in configure.ac:AM_INIT_AUTOMAKE, and both should
+# override the warnings specified on the command line.
+# NOTE: the current semantics might not be the best one (even if it has
+# been in place for quite a long time); see also Automake bug #7673.
+# Update this test if the semantics are changed.
+
+. test-init.sh
+
+# We want (almost) complete control over automake options.
+AUTOMAKE="$am_original_AUTOMAKE -Werror"
+
+cat > Makefile.am <<'END'
+FOO := bar
+AUTOMAKE_OPTIONS =
+END
+
+set_warnings ()
+{
+ set +x
+ sed <$2 >$2-t -e "s|^\\(AUTOMAKE_OPTIONS\\) *=.*|\\1 = $1|" \
+ -e "s|^\\(AM_INIT_AUTOMAKE\\).*|\\1([$1])|"
+ mv -f $2-t $2
+ set -x
+ cat $2
+}
+
+ok ()
+{
+ $AUTOMAKE $*
+}
+
+ko ()
+{
+ AUTOMAKE_fails $*
+ grep '^Makefile\.am:1:.*:=.*not portable' stderr
+}
+
+$ACLOCAL
+
+# Files required in gnu strictness.
+touch README INSTALL NEWS AUTHORS ChangeLog COPYING
+
+rm -rf autom4te*.cache
+set_warnings '-Wno-portability' Makefile.am
+set_warnings '' configure.ac
+
+ok -Wportability
+ok
+
+rm -rf autom4te*.cache
+set_warnings '' Makefile.am
+set_warnings '-Wno-portability' configure.ac
+
+ok -Wportability
+ok
+
+rm -rf autom4te*.cache
+set_warnings '-Wno-portability' Makefile.am
+set_warnings '-Wno-portability' configure.ac
+
+ok -Wportability
+
+rm -rf autom4te*.cache
+set_warnings '-Wportability' Makefile.am
+set_warnings '' configure.ac
+
+ko
+ko -Wno-portability
+
+rm -rf autom4te*.cache
+set_warnings '' Makefile.am
+set_warnings '-Wportability' configure.ac
+
+ko
+ko -Wno-portability
+
+rm -rf autom4te*.cache
+set_warnings '-Wportability' Makefile.am
+set_warnings '-Wportability' configure.ac
+ko -Wno-portability
+
+rm -rf autom4te*.cache
+set_warnings '-Wno-portability' Makefile.am
+set_warnings '-Wportability' configure.ac
+ok
+ok -Wportability
+
+rm -rf autom4te*.cache
+set_warnings '-Wportability' Makefile.am
+set_warnings '-Wno-portability' configure.ac
+ko
+ko -Wno-portability
+
+:
diff --git a/t/warnings-precedence.sh b/t/warnings-precedence.sh
new file mode 100644
index 000000000..d4237d49e
--- /dev/null
+++ b/t/warnings-precedence.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# On the command line, in AM_INIT_AUTOMAKE, and in AUTOMAKE_OPTIONS,
+# warnings specified later should take precedence over those specified
+# earlier.
+
+. test-init.sh
+
+# We want (almost) complete control over automake options.
+AUTOMAKE="$am_original_AUTOMAKE -Werror"
+
+cat > Makefile.am <<'END'
+FOO := bar
+AUTOMAKE_OPTIONS =
+END
+
+set_warnings ()
+{
+ set +x
+ sed <$2 >$2-t -e "s|^\\(AUTOMAKE_OPTIONS\\) *=.*|\\1 = $1|" \
+ -e "s|^\\(AM_INIT_AUTOMAKE\\).*|\\1([$1])|"
+ mv -f $2-t $2
+ set -x
+ cat $2
+}
+
+ok ()
+{
+ $AUTOMAKE $*
+}
+
+ko ()
+{
+ AUTOMAKE_fails $*
+ grep '^Makefile\.am:1:.*:=.*not portable' stderr
+}
+
+# Files required in gnu strictness.
+touch README INSTALL NEWS AUTHORS ChangeLog COPYING
+
+$ACLOCAL
+ok -Wportability -Wno-portability
+ko -Wno-portability -Wportability
+
+set_warnings '' Makefile.am
+set_warnings '-Wportability -Wno-portability' configure.ac
+rm -rf autom4te*.cache
+$ACLOCAL
+ok
+set_warnings '-Wno-portability -Wportability' configure.ac
+rm -rf autom4te*.cache
+$ACLOCAL
+ko
+
+set_warnings '' configure.ac
+rm -rf autom4te*.cache
+$ACLOCAL
+set_warnings '-Wportability -Wno-portability' Makefile.am
+ok
+set_warnings '-Wno-portability -Wportability' Makefile.am
+ko
+
+:
diff --git a/t/warnings-strictness-interactions.sh b/t/warnings-strictness-interactions.sh
new file mode 100644
index 000000000..206278b95
--- /dev/null
+++ b/t/warnings-strictness-interactions.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the default warnings triggered by a strictness specified
+# in AUTOMAKE_OPTIONS take precedence over explicit warnings given in
+# AM_INIT_AUTOMAKE.
+
+. test-init.sh
+
+# We want (almost) complete control over automake options.
+AUTOMAKE="$am_original_AUTOMAKE -Werror"
+
+cat > Makefile.am <<END
+AUTOMAKE_OPTIONS =
+FOO := bar
+END
+
+set_am_opts ()
+{
+ set +x
+ sed <$2 >$2-t -e "s|^\\(AUTOMAKE_OPTIONS\\) *=.*|\\1 = $1|" \
+ -e "s|^\\(AM_INIT_AUTOMAKE\\).*|\\1([$1])|"
+ mv -f $2-t $2
+ set -x
+ cat $2
+}
+
+set_am_opts '-Wportability' configure.ac
+set_am_opts 'foreign' Makefile.am
+
+$ACLOCAL
+$AUTOMAKE
+
+rm -rf autom4te*.cache
+
+# Files required in gnu strictness.
+touch README INSTALL NEWS AUTHORS ChangeLog COPYING
+
+set_am_opts '-Wno-portability' configure.ac
+set_am_opts 'gnu' Makefile.am
+
+AUTOMAKE_fails
+$ACLOCAL
+grep '^Makefile\.am:2:.*:=.*not portable' stderr
+
+:
diff --git a/t/warnings-unknown.sh b/t/warnings-unknown.sh
new file mode 100644
index 000000000..7497dad03
--- /dev/null
+++ b/t/warnings-unknown.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake complains about unknown warnings.
+
+. test-init.sh
+
+# We want (almost) complete control over automake options.
+AUTOMAKE="$am_original_AUTOMAKE --foreign -Werror"
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AM_INIT_AUTOMAKE([-Wno-zardoz])
+AC_CONFIG_FILES([Makefile])
+END
+
+cat > Makefile.am <<END
+AUTOMAKE_OPTIONS = -Wfoobar
+END
+
+$ACLOCAL
+
+AUTOMAKE_fails -Wbazquux
+grep '^configure\.ac:2:.* unknown warning category.*zardoz' stderr
+grep '^Makefile\.am:1:.* unknown warning category.*foobar' stderr
+grep "^automake-$APIVERSION:.* unknown warning category.*bazquux" stderr
+
+# Check that we can override warnings about unknown warning categories.
+$AUTOMAKE -Wno-unsupported -Wbazquux
+
+:
diff --git a/t/warnings-win-over-strictness.sh b/t/warnings-win-over-strictness.sh
new file mode 100644
index 000000000..72d193ee2
--- /dev/null
+++ b/t/warnings-win-over-strictness.sh
@@ -0,0 +1,90 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that, on the command line, explicitly-defined warnings take
+# precedence over implicit strictness-implied warnings.
+
+. test-init.sh
+
+# We want complete control over automake options.
+AUTOMAKE=$am_original_AUTOMAKE
+
+ok ()
+{
+ AUTOMAKE_run $*
+ test ! -s stderr
+}
+
+ko ()
+{
+ AUTOMAKE_run $*
+ grep '^Makefile\.am:.*:=.*not portable' stderr
+ test $(wc -l <stderr) -eq 1
+}
+
+set_am_opts()
+{
+ set +x
+ sed <$2 >$2-t -e "s|^\\(AUTOMAKE_OPTIONS\\) *=.*|\\1 = $1|" \
+ -e "s|^\\(AM_INIT_AUTOMAKE\\).*|\\1([$1])|"
+ mv -f $2-t $2
+ set -x
+ cat $2
+}
+
+# Files required in gnu strictness.
+touch README INSTALL NEWS AUTHORS ChangeLog COPYING
+
+cat > Makefile.am <<END
+AUTOMAKE_OPTIONS =
+FOO := bar
+END
+
+$ACLOCAL
+
+ko --foreign -Wportability
+ko -Wportability --foreign
+ok --gnu -Wno-portability
+ok -Wno-portability --gnu
+
+set_am_opts '' Makefile.am
+
+rm -rf autom4te*.cache
+set_am_opts 'foreign -Wportability' configure.ac
+ko
+rm -rf autom4te*.cache
+set_am_opts '-Wportability foreign' configure.ac
+ko
+rm -rf autom4te*.cache
+set_am_opts 'gnu -Wno-portability' configure.ac
+ok
+rm -rf autom4te*.cache
+set_am_opts '-Wno-portability gnu' configure.ac
+ok
+
+rm -rf autom4te*.cache
+set_am_opts '' configure.ac
+
+set_am_opts 'foreign -Wportability' Makefile.am
+ko
+set_am_opts '-Wportability foreign' Makefile.am
+ko
+set_am_opts 'gnu -Wno-portability' Makefile.am
+ok
+set_am_opts '-Wno-portability gnu' Makefile.am
+ok
+
+:
diff --git a/t/warnopts.sh b/t/warnopts.sh
new file mode 100644
index 000000000..003e44ef6
--- /dev/null
+++ b/t/warnopts.sh
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that we can enable or disable warnings on a per-file basis.
+
+. test-init.sh
+
+cat >>configure.ac <<END
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+# These two Makefile contain the same errors, but have different
+# warnings disabled.
+
+cat >Makefile.am <<END
+AUTOMAKE_OPTIONS = -Wno-obsolete
+INCLUDES = -Ifoo
+foo_SOURCES = unused
+SUBDIRS = sub
+END
+
+cat >sub/Makefile.am <<END
+AUTOMAKE_OPTIONS = -Wno-syntax
+INCLUDES = -Ifoo
+foo_SOURCES = unused
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+# The expected diagnostic is
+# Makefile.am:3: warning: variable 'foo_SOURCES' is defined but no program or
+# library has 'foo' as canonical name (possible typo)
+# sub/Makefile.am:2: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS'
+grep '^Makefile.am:.*foo_SOURCES' stderr
+grep '^sub/Makefile.am:.*INCLUDES' stderr
+grep '^sub/Makefile.am:.*foo_SOURCES' stderr && exit 1
+grep '^Makefile.am:.*INCLUDES' stderr && exit 1
+# Only three lines of warnings.
+test $(grep -v 'warnings are treated as errors' stderr | wc -l) -eq 3
+
+# On fast machines the autom4te.cache created during the above run of
+# $AUTOMAKE is likely to have the same time stamp as the configure.ac
+# created below; thus causing traces for the old configure.ac to be
+# used. We could do '$sleep', but it's faster to erase the
+# directory. (Erase autom4te*.cache, not autom4te.cache, because some
+# bogus installations of Autoconf use a versioned cache).
+rm -rf autom4te*.cache
+
+# If we add a global -Wnone, all warnings should disappear.
+cat >configure.ac <<END
+AC_INIT([warnopts], [1.0])
+AM_INIT_AUTOMAKE([-Wnone])
+AC_CONFIG_FILES([Makefile sub/Makefile])
+AC_OUTPUT
+END
+$ACLOCAL
+$AUTOMAKE
+
+:
diff --git a/t/werror.sh b/t/werror.sh
new file mode 100644
index 000000000..18f445491
--- /dev/null
+++ b/t/werror.sh
@@ -0,0 +1,26 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure -Werror and --add-missing work together.
+
+. test-init.sh
+
+: > Makefile.am
+
+rm -f install-sh depcomp missing mkinstalldirs
+
+$ACLOCAL
+$AUTOMAKE -Werror --add-missing
diff --git a/t/werror2.sh b/t/werror2.sh
new file mode 100644
index 000000000..2605f3c4e
--- /dev/null
+++ b/t/werror2.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure that Makefile.in is not overwritten on error. Otherwise
+# although the rebuilding rules would fail on error, they would
+# succeed if make is run a second time immediately afterwards.
+# Report from Harlan Stenn.
+
+. test-init.sh
+
+echo AC_OUTPUT>>configure.ac
+
+: > Makefile.am
+
+$ACLOCAL
+# Create Makefile.in before configure. configure ensures files
+# generated by it or later are newer than configure, so this allows
+# us to avoid a $sleep before updating Makefile.am below.
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+$MAKE
+
+cat >Makefile.am <<END
+AUTOMAKE_OPTIONS = -Werror
+INCLUDES = -Ifoo
+foo_SOURCES = unused
+END
+
+# This repetition is deliberate; see heading comments.
+$MAKE && exit 1
+$MAKE && exit 1
+
+:
diff --git a/t/werror3.sh b/t/werror3.sh
new file mode 100644
index 000000000..450f1101f
--- /dev/null
+++ b/t/werror3.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure a per-Makefile.am -Werror setting is not carried over
+# to another Makefile.am.
+
+. test-init.sh
+
+cat >>configure.ac <<\END
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+cat >sub/Makefile.am <<\END
+AUTOMAKE_OPTIONS = -Werror
+END
+cat >Makefile.am <<\END
+VAR = foo
+VAR = bar
+END
+
+$ACLOCAL
+
+# The issue would not manifest with threaded execution.
+unset AUTOMAKE_JOBS
+AUTOMAKE_run -Wno-error
+grep 'VAR multiply defined' stderr
+
+AUTOMAKE_JOBS=2
+export AUTOMAKE_JOBS
+AUTOMAKE_run -Wno-error
+grep 'VAR multiply defined' stderr
+
+:
diff --git a/t/werror4.sh b/t/werror4.sh
new file mode 100644
index 000000000..e0d1118b1
--- /dev/null
+++ b/t/werror4.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# -Werror and local -Werror settings should be flagged for the user.
+
+. test-init.sh
+
+cat >>configure.ac <<\END
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+cat >sub/Makefile.am <<\END
+AUTOMAKE_OPTIONS = -Werror
+SUB = foo
+SUB = bar
+END
+cat >Makefile.am <<\END
+AUTOMAKE_OPTIONS = -Werror
+VAR = foo
+VAR = bar
+END
+
+$ACLOCAL
+
+AUTOMAKE_fails -Wno-error
+grep 'VAR multiply defined' stderr
+grep 'SUB multiply defined' stderr
+test $(grep -c 'warnings are treated as errors' stderr) -eq 1
+
+sed '/AUTOMAKE_OPTIONS/d' sub/Makefile.am > t
+mv -f t sub/Makefile.am
+
+AUTOMAKE_fails -Wno-error
+grep 'VAR multiply defined' stderr
+grep 'SUB multiply defined' stderr
+test $(grep -c 'warnings are treated as errors' stderr) -eq 1
+
+sed '/AUTOMAKE_OPTIONS/d' Makefile.am > t
+mv -f t Makefile.am
+
+AUTOMAKE_fails -Werror
+grep 'VAR multiply defined' stderr
+grep 'SUB multiply defined' stderr
+test $(grep -c 'warnings are treated as errors' stderr) -eq 1
+
+AUTOMAKE_run -Wno-error
+grep 'VAR multiply defined' stderr
+grep 'SUB multiply defined' stderr
+grep 'warnings are treated as errors' stderr && exit 1
+
+:
diff --git a/t/whoami.sh b/t/whoami.sh
new file mode 100644
index 000000000..4eb32a9aa
--- /dev/null
+++ b/t/whoami.sh
@@ -0,0 +1,27 @@
+#! /bin/sh
+# Copyright (C) 1998-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure aclocal doesn't barf on "WHO_AM_I=...". Report
+# from Johan Danielsson (and a very nice bug report, too, I might
+# add).
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+WHO_AM_I=17
+END
+
+$ACLOCAL
diff --git a/t/xsource.sh b/t/xsource.sh
new file mode 100644
index 000000000..b0b503440
--- /dev/null
+++ b/t/xsource.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure multiple source files with the same object
+# file causes error.
+
+. test-init.sh
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = z.c x/z.c
+END
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+END
+
+mkdir x
+
+: > z.c
+: > x/z.c
+
+$ACLOCAL
+AUTOMAKE_fails
+$FGREP 'z.$(OBJEXT)' stderr
diff --git a/t/yacc-auxdir.sh b/t/yacc-auxdir.sh
new file mode 100644
index 000000000..326a41957
--- /dev/null
+++ b/t/yacc-auxdir.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure ylwrap is put in right location.
+# Report from Tim Van Holder.
+
+. test-init.sh
+
+mkdir aux1 sub
+
+cat > configure.ac << END
+AC_INIT([$me], [1.0])
+# 'aux' is not an acceptable file/directory name on Windows systems
+AC_CONFIG_AUX_DIR([aux1])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([Makefile sub/Makefile])
+AC_PROG_CC
+AC_PROG_YACC
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+bin_PROGRAMS = foo
+AM_YFLAGS = -d
+foo_SOURCES = foo.y
+END
+
+cat > sub/Makefile.am << 'END'
+bin_PROGRAMS = bar
+AM_YFLAGS = -d
+bar_SOURCES = bar.y main.c
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+test -f aux1/ylwrap
+test ! -e ylwrap
+test ! -e sub/ylwrap
+grep -i 'ylwrap' Makefile.in sub/Makefile.in # For debugging.
+$FGREP '$(top_srcdir)/aux1/ylwrap' Makefile.in
+$FGREP '$(top_srcdir)/aux1/ylwrap' sub/Makefile.in
+
+:
diff --git a/t/yacc-basic.sh b/t/yacc-basic.sh
new file mode 100644
index 000000000..4b33d6c2f
--- /dev/null
+++ b/t/yacc-basic.sh
@@ -0,0 +1,108 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic semantic checks on Yacc support (without yacc-generated headers).
+# Keep in sync with sister test 'yacc-cxx.sh'.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo bar
+foo_SOURCES = parse.y foo.c
+bar_SOURCES = $(foo_SOURCES)
+bar_YFLAGS = -v
+
+.PHONY: echo-distcom
+echo-distcom:
+ @echo ' ' $(DIST_COMMON) ' '
+END
+
+cat > parse.y << 'END'
+%{
+#include <stdio.h>
+#include <stdlib.h>
+int yylex () { return getchar (); }
+void yyerror (char *s) {}
+%}
+%%
+a : 'a' { exit(0); };
+END
+
+cat > foo.c << 'END'
+int main () { yyparse (); return 1; }
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+ls -l
+# The Yacc-derived C sources must be created, and not removed once
+# compiled (i.e., not treated like "intermediate files" in the GNU
+# make sense).
+test -f parse.c
+test -f bar-parse.c
+# Check that per-object flags are honored.
+test -f bar-parse.output
+
+if ! cross_compiling; then
+ echo a | ./foo
+ echo b | ./foo && exit 1
+ echo a | ./bar
+ echo b | ./bar && exit 1
+ : For shells with busted 'set -e'.
+fi
+
+# The Yacc-derived C sources must be shipped.
+$MAKE echo-distcom
+$MAKE -s echo-distcom | grep '[ /]parse\.c '
+$MAKE -s echo-distcom | grep '[ /]bar-parse\.c '
+$MAKE distdir
+ls -l $distdir
+test -f $distdir/parse.c
+test -f $distdir/bar-parse.c
+
+# Sanity check on distribution.
+# Note that, for this to succeed, bar-parse.output must either not
+# be distributed, or properly cleaned by automake-generated rules.
+# We don't want to set the exact semantics yet, but want to ensure
+# they are are consistent.
+yl_distcheck
+
+# Make sure that the Yacc-derived C sources are erased by
+# maintainer-clean, and not by distclean.
+test -f parse.c
+test -f bar-parse.c
+$MAKE distclean
+ls -l
+test -f parse.c
+test -f bar-parse.c
+./configure # We must re-create 'Makefile'.
+$MAKE maintainer-clean
+ls -l
+test ! -e parse.c
+test ! -e bar-parse.c
+
+:
diff --git a/t/yacc-bison-skeleton-cxx.sh b/t/yacc-bison-skeleton-cxx.sh
new file mode 100644
index 000000000..dde4a891b
--- /dev/null
+++ b/t/yacc-bison-skeleton-cxx.sh
@@ -0,0 +1,102 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure bison + bison's C++ skeleton + C++ works.
+# For Automake bug#7648 and PR automake/491.
+
+required='c++ bison'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = zardoz.yy foo.cc
+
+# This is required even with %defines in zardoz.yy.
+AM_YFLAGS = -d
+
+BUILT_SOURCES = zardoz.hh
+EXTRA_DIST = stack.hh location.hh position.hh
+END
+
+cat > zardoz.yy << 'END'
+%skeleton "lalr1.cc"
+%defines
+%locations
+
+%union
+{
+ int ival;
+};
+%{
+int yylex (yy::parser::semantic_type *yylval,
+ yy::parser::location_type *yylloc);
+%}
+
+%%
+start : /* empty */
+%%
+
+int
+yylex (yy::parser::semantic_type *yylval,
+ yy::parser::location_type *yylloc)
+{
+ return 0;
+}
+
+void
+yy::parser::error(const yy::parser::location_type&, const std::string&)
+{
+ return;
+}
+END
+
+cat > foo.cc << 'END'
+#include "zardoz.hh"
+
+int
+main(int argc, char** argv)
+{
+ yy::parser my_parser;
+ return my_parser.parse ();
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# Try a VPATH build first.
+mkdir build
+cd build
+../configure YACC='bison -y'
+$MAKE
+cd ..
+
+# Now try an in-tree build.
+./configure YACC='bison -y'
+$MAKE
+
+# Check that distribution is self-contained, and do not require
+# bison to be built.
+yl_distcheck YACC=false DISTCHECK_CONFIGURE_FLAGS='YACC=false'
+
+:
diff --git a/t/yacc-bison-skeleton.sh b/t/yacc-bison-skeleton.sh
new file mode 100644
index 000000000..0b28737be
--- /dev/null
+++ b/t/yacc-bison-skeleton.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure bison + bison's skeleton works.
+# For Automake bug#7648 and PR automake/491.
+
+required='cc bison'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_C_INLINE dnl Required by some pre-C99 compilers such as MSVC.
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = zardoz.y foo.c
+AM_YFLAGS = -d --skeleton glr.c
+BUILT_SOURCES = zardoz.h
+END
+
+# Parser.
+cat > zardoz.y << 'END'
+%{
+int yylex ();
+void yyerror (const char *s);
+%}
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+%%
+int yylex () { return 0; }
+void yyerror (const char *s) { return; }
+END
+
+cat > foo.c << 'END'
+#include "zardoz.h"
+int main (void)
+{
+ return yyparse ();
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# Try a VPATH build first.
+mkdir build
+cd build
+../configure YACC='bison -y'
+$MAKE
+cd ..
+
+# Now try an in-tree build.
+./configure YACC='bison -y'
+$MAKE
+
+# Check that distribution is self-contained, and do not require
+# bison to be built.
+yl_distcheck YACC=false DISTCHECK_CONFIGURE_FLAGS='YACC=false'
+
+:
diff --git a/t/yacc-clean-cxx.sh b/t/yacc-clean-cxx.sh
new file mode 100644
index 000000000..38dbb4adc
--- /dev/null
+++ b/t/yacc-clean-cxx.sh
@@ -0,0 +1,161 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that C++ source and header files derived from non-distributed
+# Yacc sources are cleaned by "make clean", while C++ source and
+# header files derived from distributed Yacc sources are cleaned by
+# "make maintainer-clean".
+# See also sister test 'yacc-clean.sh'.
+
+required='c++ yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_PROG_YACC
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# Use two subdirectories, one to test with '-d' in YFLAGS, the
+# other one to test with empty YFLAGS.
+SUBDIRS = sub1 sub2
+END
+
+mkdir sub1 sub2
+
+cat > sub1/Makefile.am << 'END'
+bin_PROGRAMS = foo bar baz qux
+
+foo_SOURCES = mainfoo.cc parsefoo.yxx
+
+bar_SOURCES = mainbar.cpp parsebar.yy
+bar_YFLAGS = $(AM_YFLAGS)
+
+baz_SOURCES = mainbaz.c++
+nodist_baz_SOURCES = parsebaz.y++
+
+qux_SOURCES = mainqux.cxx
+nodist_qux_SOURCES = parsequx.ypp
+qux_YFLAGS = $(AM_YFLAGS)
+
+parsebaz.y++ parsequx.ypp:
+ cp $(srcdir)/parsefoo.yxx $@
+
+CLEANFILES = parsebaz.y++ parsequx.ypp
+END
+
+cat > sub2/Makefile.am << 'END'
+include $(top_srcdir)/sub1/Makefile.am
+AM_YFLAGS = -d
+END
+
+cat > sub1/parsefoo.yxx << 'END'
+%{
+// This file should contain valid C++ but invalid C.
+#include <cstdio>
+// "std::" qualification required by Sun C++ 5.9.
+int yylex (void) { return std::getchar (); }
+void yyerror (const char *s) { return; }
+%}
+%%
+x : 'x' { };
+END
+cp sub1/parsefoo.yxx sub1/parsebar.yy
+cp sub1/parsefoo.yxx sub2/parsefoo.yxx
+cp sub1/parsefoo.yxx sub2/parsebar.yy
+
+cat > sub1/mainfoo.cc << 'END'
+// This file should contain valid C++ but invalid C.
+using namespace std;
+int main (int argc, char **argv)
+{
+ extern int yyparse (void);
+ return yyparse ();
+}
+END
+cp sub1/mainfoo.cc sub1/mainbar.cpp
+cp sub1/mainfoo.cc sub1/mainbaz.c++
+cp sub1/mainfoo.cc sub1/mainqux.cxx
+cp sub1/main???.c* sub2
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+cp config.status config.sav
+
+$MAKE
+ls -l . sub1 sub2
+# Sanity checks.
+test -f sub1/parsefoo.cxx
+test -f sub1/bar-parsebar.cc
+test -f sub1/parsebaz.y++
+test -f sub1/parsebaz.c++
+test -f sub1/parsequx.ypp
+test -f sub1/qux-parsequx.cpp
+test -f sub2/parsefoo.cxx
+test -f sub2/parsefoo.hxx
+test -f sub2/bar-parsebar.cc
+test -f sub2/bar-parsebar.hh
+test -f sub2/parsebaz.y++
+test -f sub2/parsebaz.c++
+test -f sub2/parsebaz.h++
+test -f sub2/parsequx.ypp
+test -f sub2/qux-parsequx.cpp
+test -f sub2/qux-parsequx.hpp
+
+for target in clean distclean; do
+ $MAKE $target
+ ls -l . sub1 sub2
+ test -f sub1/parsefoo.cxx
+ test -f sub1/bar-parsebar.cc
+ test ! -e sub1/parsebaz.y++
+ test ! -e sub1/parsebaz.c++
+ test ! -e sub1/parsequx.ypp
+ test ! -e sub1/qux-parsequx.cpp
+ test -f sub2/parsefoo.cxx
+ test -f sub2/parsefoo.hxx
+ test -f sub2/bar-parsebar.cc
+ test -f sub2/bar-parsebar.hh
+ test ! -e sub2/parsebaz.y++
+ test ! -e sub2/parsebaz.c++
+ test ! -e sub2/parsebaz.h++
+ test ! -e sub2/parsequx.ypp
+ test ! -e sub2/qux-parsequx.cpp
+ test ! -e sub2/qux-parsequx.hpp
+done
+
+cp config.sav config.status
+./config.status # re-create Makefile
+
+$MAKE maintainer-clean
+ls -l . sub1 sub2
+test -f sub1/parsefoo.yxx
+test -f sub1/parsebar.yy
+test ! -e sub1/parsefoo.cxx
+test ! -e sub1/bar-parsebar.cc
+test -f sub2/parsefoo.yxx
+test -f sub2/parsebar.yy
+test ! -e sub2/parsefoo.cxx
+test ! -e sub2/parsefoo.hxx
+test ! -e sub2/bar-parsebar.cc
+test ! -e sub2/bar-parsebar.hh
+
+:
diff --git a/t/yacc-clean.sh b/t/yacc-clean.sh
new file mode 100644
index 000000000..bbda4a275
--- /dev/null
+++ b/t/yacc-clean.sh
@@ -0,0 +1,147 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that .c and .h files derived from non-distributed .y sources
+# are cleaned by "make clean", while .c and .h files derived from
+# distributed .y sources are cleaned by "make maintainer-clean".
+# See also sister test 'yacc-cxx-clean.sh'.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# Use two subdirectories, one to test with '-d' in YFLAGS, the
+# other one to test with empty YFLAGS.
+SUBDIRS = sub1 sub2
+END
+
+mkdir sub1 sub2
+
+cat > sub1/Makefile.am << 'END'
+bin_PROGRAMS = foo bar baz qux
+
+foo_SOURCES = main.c parse.y
+
+bar_SOURCES = main.c parse.y
+bar_YFLAGS = $(AM_YFLAGS)
+
+baz_SOURCES = main.c
+nodist_baz_SOURCES = baz.y
+
+qux_SOURCES = main.c
+nodist_qux_SOURCES = baz.y
+qux_YFLAGS = $(AM_YFLAGS)
+
+baz.y:
+ cp $(srcdir)/parse.y $@
+
+CLEANFILES = baz.y
+END
+
+cat > sub2/Makefile.am << 'END'
+include $(top_srcdir)/sub1/Makefile.am
+AM_YFLAGS = -d
+END
+
+cat > sub1/parse.y << 'END'
+%{
+int yylex () { return (getchar ()); }
+void yyerror (char *s) {}
+%}
+%%
+x : 'x' { };
+END
+cp sub1/parse.y sub2/parse.y
+
+cat > sub1/main.c << 'END'
+int main ()
+{
+ return yyparse ();
+}
+END
+cp sub1/main.c sub2/main.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+cp config.status config.sav
+
+$MAKE
+ls -l . sub1 sub2
+# Sanity checks.
+test -f sub1/parse.y
+test -f sub1/parse.c
+test -f sub1/bar-parse.c
+test -f sub1/baz.y
+test -f sub1/baz.c
+test -f sub1/qux-baz.c
+test -f sub2/parse.y
+test -f sub2/parse.c
+test -f sub2/parse.h
+test -f sub2/bar-parse.c
+test -f sub2/bar-parse.h
+test -f sub2/baz.y
+test -f sub2/baz.c
+test -f sub2/baz.h
+test -f sub2/qux-baz.c
+test -f sub2/qux-baz.h
+
+for target in clean distclean; do
+ $MAKE $target
+ ls -l . sub1 sub2
+ test -f sub1/parse.y
+ test -f sub1/parse.c
+ test -f sub1/bar-parse.c
+ test ! -e sub1/baz.y
+ test ! -e sub1/baz.c
+ test ! -e sub1/qux-baz.c
+ test -f sub2/parse.y
+ test -f sub2/parse.c
+ test -f sub2/parse.h
+ test -f sub2/bar-parse.c
+ test -f sub2/bar-parse.h
+ test ! -e sub2/baz.y
+ test ! -e sub2/baz.c
+ test ! -e sub2/baz.h
+ test ! -e sub2/qux-baz.c
+ test ! -e sub2/qux-baz.h
+done
+
+cp config.sav config.status
+./config.status # Re-create 'Makefile'.
+
+$MAKE maintainer-clean
+ls -l . sub1 sub2
+test -f sub1/parse.y
+test ! -e sub1/parse.c
+test ! -e sub1/bar-parse.c
+test -f sub2/parse.y
+test ! -e sub2/parse.c
+test ! -e sub2/parse.h
+test ! -e sub2/bar-parse.c
+test ! -e sub2/bar-parse.h
+
+:
diff --git a/t/yacc-cxx-grepping.sh b/t/yacc-cxx-grepping.sh
new file mode 100644
index 000000000..3de9a7dc9
--- /dev/null
+++ b/t/yacc-cxx-grepping.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure Yacc + C++ is not obviously broken.
+# See also related tests 'yacc-cxx.sh' and 'yacc-d-cxx.sh',
+# which does much more in-depth checks (but requires an actual
+# Yacc program and a working C++ compiler).
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_PROG_YACC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo bar baz qux
+foo_SOURCES = foo.y++
+bar_SOURCES = bar.ypp
+baz_SOURCES = baz.yy
+qux_SOURCES = qux.yxx
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+$EGREP '(\.[ch]|foo|bar|baz|qux)' Makefile.in # For debugging.
+
+$EGREP '(foo|bar|baz|qux)\.h' Makefile.in && exit 1
+
+sed -e 's/^/ /' -e 's/$/ /' Makefile.in >mk
+
+$FGREP ' foo.c++ ' mk
+$FGREP ' bar.cpp ' mk
+$FGREP ' baz.cc ' mk
+$FGREP ' qux.cxx ' mk
+
+cat >> Makefile.am <<END
+AM_YFLAGS = -d
+qux_YFLAGS = foo
+END
+
+$AUTOMAKE
+
+$EGREP '(\.[ch]|foo|bar|baz|qux)' Makefile.in # For debugging.
+
+sed -e 's/^/ /' -e 's/$/ /' Makefile.in >mk
+
+$FGREP ' foo.c++ ' mk
+$FGREP ' foo.h++ ' mk
+$FGREP ' bar.cpp ' mk
+$FGREP ' bar.hpp ' mk
+$FGREP ' baz.cc ' mk
+$FGREP ' baz.hh ' mk
+
+$EGREP '(^| )foo\.h\+\+(:| .*:)' Makefile.in
+$EGREP '(^| )bar\.hpp(:| .*:)' Makefile.in
+$EGREP '(^| )baz\.hh(:| .*:)' Makefile.in
+
+grep ' foo\.h[ :]' mk && exit 1
+grep ' bar\.h[ :]' mk && exit 1
+grep ' baz\.h[ :]' mk && exit 1
+
+$FGREP ' qux-qux.cxx ' mk
+$EGREP '(^| )qux-qux\.cxx(:| .*:)' Makefile.in
+grep 'qux\.h.*:' Makefile.in && exit 1
+
+:
diff --git a/t/yacc-cxx.sh b/t/yacc-cxx.sh
new file mode 100644
index 000000000..a351e7af9
--- /dev/null
+++ b/t/yacc-cxx.sh
@@ -0,0 +1,140 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Basic semantic checks on Yacc + C++ support (when yacc-generated
+# headers are not involved).
+# Keep in sync with sister test 'yacc-basic.sh'.
+
+required='c++ yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo1 foo2 foo3 foo4
+foo1_SOURCES = parse1.yy foo.cc
+foo2_SOURCES = parse2.y++ bar.c++
+foo3_SOURCES = parse3.yxx foo.cc
+foo4_SOURCES = parse4.ypp bar2.cxx
+foo3_YFLAGS = -v
+foo4_YFLAGS = $(foo3_YFLAGS)
+
+.PHONY: echo-distcom
+echo-distcom:
+ @echo ' ' $(DIST_COMMON) ' '
+END
+
+cat > parse1.yy << 'END'
+%{
+// Valid C++, but deliberately invalid C.
+#include <cstdio>
+#include <cstdlib>
+// "std::" qualification required by Sun C++ 5.9.
+int yylex (void) { return std::getchar (); }
+void yyerror (const char *s) { return; }
+%}
+%%
+a : 'a' { exit(0); };
+END
+cp parse1.yy parse2.y++
+cp parse1.yy parse3.yxx
+cp parse1.yy parse4.ypp
+
+cat > foo.cc << 'END'
+// Valid C++, but deliberately invalid C.
+using namespace std;
+int main (int argc, char **argv)
+{
+ int yyparse (void);
+ yyparse ();
+ return 1;
+}
+END
+cp foo.cc bar.c++
+cp foo.cc bar2.cxx
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE
+
+# The Yacc-derived C++ sources must be created, and not removed once
+# compiled (i.e., not treated like "intermediate files" in the GNU
+# make sense).
+test -f parse1.cc
+test -f parse2.c++
+test -f foo3-parse3.cxx
+test -f foo4-parse4.cpp
+# Check that per-object flags are honored.
+test -f foo3-parse3.output
+test -f foo4-parse4.output
+
+if ! cross_compiling; then
+ for i in 1 2 3 4; do
+ echo a | ./foo$i
+ echo b | ./foo$i && exit 1
+ : For shells with busted 'set -e'.
+ done
+fi
+
+# The Yacc-derived C++ sources must be shipped.
+$MAKE echo-distcom
+$MAKE -s echo-distcom | grep '[ /]parse1\.cc '
+$MAKE -s echo-distcom | grep '[ /]parse2\.c++ '
+$MAKE -s echo-distcom | grep '[ /]foo3-parse3\.cxx '
+$MAKE -s echo-distcom | grep '[ /]foo4-parse4\.cpp '
+$MAKE distdir
+ls -l $distdir
+test -f $distdir/parse1.cc
+test -f $distdir/parse2.c++
+test -f $distdir/foo3-parse3.cxx
+test -f $distdir/foo4-parse4.cpp
+
+# Sanity check on distribution.
+# Note that, for this to succeed, foo3-parse3.output and foo4-parse4.output
+# must either not be distributed, or properly cleaned by automake-generated
+# rules. We don't want to set the exact semantics yet, but want to ensure
+# they are are consistent.
+yl_distcheck
+
+# Make sure that the Yacc-derived C++ sources are erased by
+# maintainer-clean, and not by distclean.
+test -f parse1.cc
+test -f parse2.c++
+test -f foo3-parse3.cxx
+test -f foo4-parse4.cpp
+$MAKE distclean
+ls -l
+test -f parse1.cc
+test -f parse2.c++
+test -f foo3-parse3.cxx
+test -f foo4-parse4.cpp
+./configure # Re-create 'Makefile'.
+$MAKE maintainer-clean
+ls -l
+test ! -e parse1.cc
+test ! -e parse2.c++
+test ! -e foo3-parse3.cxx
+test ! -e foo4-parse4.cpp
+
+:
diff --git a/t/yacc-d-basic.sh b/t/yacc-d-basic.sh
new file mode 100644
index 000000000..9e9e94b10
--- /dev/null
+++ b/t/yacc-d-basic.sh
@@ -0,0 +1,163 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Tests Yacc support with yacc-generated headers
+# (i.e., '-d' in *YFLAGS).
+# Keep in sync with sister test 'yacc-d-cxx.sh'.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = foo bar baz
+END
+
+mkdir foo bar baz
+
+cat > foo/Makefile.am <<'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = parse.y main.c
+.PHONY: echo-distcom
+echo-distcom:
+ @echo ' ' $(DIST_COMMON) ' '
+END
+cp foo/Makefile.am bar/Makefile.am
+cp foo/Makefile.am baz/Makefile.am
+
+cat > foo/parse.y << 'END'
+%{
+#include "parse.h"
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+x : 'x' {};
+%%
+END
+# Using ylwrap, we actually generate y.tab.[ch]. Unfortunately, we
+# forgot to rename #include "y.tab.h" into #include "parse.h" during
+# the conversion from y.tab.c to parse.c. This was OK when Bison was
+# not issuing such an #include (up to 2.6).
+#
+# To make sure that we perform this conversion even with version of
+# Bison that do not generate this include, in bar/parse.y, use y.tab.h
+# instead of parse.h, and check the ylwrap does replace "y.tab.h" with
+# "parse.h".
+sed -e 's/parse\.h/y.tab.h/' <foo/parse.y >bar/parse.y
+
+cat > foo/main.c << 'END'
+#include "parse.h"
+int main ()
+{
+ return yyparse ();
+}
+END
+cp foo/main.c bar/main.c
+
+# Even the generated header file is renamed when target-specific YFLAGS
+# are used. This might not be the best behavior, but it has been in
+# place for quite a long time, so just go along with it for now.
+sed 's/"parse\.h"/"zardoz-parse.h"/' foo/parse.y > baz/parse.y
+sed 's/"parse\.h"/"zardoz-parse.h"/' foo/main.c > baz/main.c
+
+$ACLOCAL
+$AUTOCONF
+
+$AUTOMAKE -a
+$FGREP parse.h foo/Makefile.in bar/Makefile.in baz/Makefile.in && exit 1
+
+cat >> foo/Makefile.am <<END
+BUILT_SOURCES = parse.h
+YFLAGS=\
+-d
+END
+$AUTOMAKE -Wno-gnu foo/Makefile
+
+sed 's/EOL$//' >> bar/Makefile.am <<END
+AM_YFLAGS${tab}= -d EOL
+BUILT_SOURCES = parse.h
+END
+$AUTOMAKE bar/Makefile
+
+cat >> baz/Makefile.am <<END
+BUILT_SOURCES = zardoz-parse.h
+zardoz_YFLAGS =-d${tab}
+END
+$AUTOMAKE baz/Makefile
+
+./configure
+
+$MAKE
+
+generated="
+ foo/parse.c
+ foo/parse.h
+ bar/parse.c
+ bar/parse.h
+ baz/zardoz-parse.c
+ baz/zardoz-parse.h
+"
+
+for i in $generated; do
+ test -f $i
+done
+
+# There must remain no obsolete header guard.
+grep Y_TAB_H $generated && exit 1
+
+# The generated C source and header files must be shipped.
+for dir in foo bar; do
+ cd $dir
+ $MAKE echo-distcom
+ $MAKE -s echo-distcom | grep '[ /]parse.c '
+ $MAKE -s echo-distcom | grep '[ /]parse.h '
+ cd ..
+done
+cd baz
+$MAKE echo-distcom
+$MAKE -s echo-distcom | grep '[ /]zardoz-parse.c '
+$MAKE -s echo-distcom | grep '[ /]zardoz-parse.h '
+cd ..
+
+$MAKE distdir
+ls -l $distdir
+for i in $generated; do
+ test -f $distdir/$i
+done
+
+# Sanity check the distribution.
+yl_distcheck
+
+# While we are at it, make sure that 'parse.c' and 'parse.h' are erased
+# by maintainer-clean, and not by distclean.
+$MAKE distclean
+for i in $generated; do
+ test -f $i
+done
+./configure # Re-create 'Makefile'.
+$MAKE maintainer-clean
+for i in $generated; do
+ test ! -e $i
+done
+
+:
diff --git a/t/yacc-d-cxx.sh b/t/yacc-d-cxx.sh
new file mode 100644
index 000000000..c6452a3ad
--- /dev/null
+++ b/t/yacc-d-cxx.sh
@@ -0,0 +1,232 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Various tests on Yacc/C++ support with yacc-generated headers
+# (i.e., '-d' in *YFLAGS).
+# Keep in sync with sister test 'yacc-d-basic.sh'.
+
+required='c++ yacc'
+. test-init.sh
+
+write_parse ()
+{
+ header=$1
+ unindent <<END
+ %{
+ // Valid C++, but deliberately invalid C.
+ #include <cstdlib>
+ #include "$header"
+ int yylex (void) { return 0; }
+ void yyerror (const char *s) {}
+ %}
+ %%
+ x : 'x' {};
+ %%
+END
+}
+
+write_main ()
+{
+ header=$1
+ unindent <<END
+ // Valid C++, but deliberately invalid C.
+ #include <cstdio>
+ #include "$header"
+ int main (int argc, char **argv)
+ {
+ int yyparse (void);
+ return yyparse ();
+ }
+END
+}
+
+cat >> configure.ac << 'END'
+AC_PROG_CXX
+AC_PROG_YACC
+AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile qux/Makefile])
+AC_OUTPUT
+END
+
+mkdir foo bar baz qux baz/sub
+
+# These makefiles will be extended later.
+cat > Makefile.am <<'END'
+.PHONY: echo-distcom
+echo-distcom:
+ @echo ' ' $(DIST_COMMON) ' '
+END
+cp Makefile.am foo/Makefile.am
+cp Makefile.am bar/Makefile.am
+cp Makefile.am baz/Makefile.am
+cp Makefile.am qux/Makefile.am
+
+cat >> Makefile.am <<'END'
+SUBDIRS = foo bar baz qux
+END
+
+$ACLOCAL
+$AUTOCONF
+
+cp "$am_scriptdir/ylwrap" . \
+ || fatal_ "cannot fetch auxiliary script 'ylwrap'"
+
+$AUTOMAKE Makefile
+
+# Try with -d in $(YFLAGS) (don't do this in real life!).
+cat >> foo/Makefile.am <<END
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = parse.yy main.cc
+BUILT_SOURCES = parse.hh
+YFLAGS=\
+-d
+END
+
+$AUTOMAKE -Wno-gnu foo/Makefile
+
+write_parse parse.hh > foo/parse.yy
+write_main parse.hh > foo/main.cc
+
+# Try with -d in $(AM_YFLAGS).
+cat >> bar/Makefile.am <<END
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = parse.ypp main.cpp
+BUILT_SOURCES = parse.hpp
+AM_YFLAGS${tab}= -d ${tab}
+END
+
+$AUTOMAKE bar/Makefile
+
+write_parse parse.hpp > bar/parse.ypp
+write_main parse.hpp > bar/main.cpp
+
+# Try with -d in $(AM_YFLAGS), and a subdir parser.
+cat >> baz/Makefile.am <<END
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = joe
+joe_SOURCES = sub/parse.y++ sub/main.c++
+BUILT_SOURCES = sub/parse.h++
+AM_YFLAGS = \
+${tab}-d
+END
+
+$AUTOMAKE baz/Makefile
+
+write_parse sub/parse.h++ > baz/sub/parse.y++
+write_main sub/parse.h++ > baz/sub/main.c++
+
+# Try with -d in $(xxx_YFLAGS) (per-object flag).
+cat >> qux/Makefile.am <<END
+bin_PROGRAMS = maude
+maude_SOURCES = parse.yxx main.cxx
+maude_YFLAGS=${tab} -d${tab}
+BUILT_SOURCES = maude-parse.hxx
+END
+
+$AUTOMAKE qux/Makefile
+
+write_parse maude-parse.hxx > qux/parse.yxx
+write_main maude-parse.hxx > qux/main.cxx
+
+./configure
+
+$MAKE
+ls -l . foo bar baz baz/sub qux # For debugging.
+
+test -f foo/parse.cc
+test -f foo/parse.hh
+test -f bar/parse.cpp
+test -f bar/parse.hpp
+test -f baz/sub/parse.c++
+test -f baz/sub/parse.h++
+test -f qux/maude-parse.cxx
+test -f qux/maude-parse.hxx
+
+# The ylwrap script must be shipped.
+$MAKE echo-distcom
+$MAKE -s echo-distcom | grep '[ /]ylwrap '
+
+# The generated C++ source and header files must be shipped.
+cd foo
+$MAKE echo-distcom
+$MAKE -s echo-distcom | grep '[ /]parse\.cc '
+$MAKE -s echo-distcom | grep '[ /]parse\.hh '
+cd ..
+cd bar
+$MAKE echo-distcom
+$MAKE -s echo-distcom | grep '[ /]parse\.cpp '
+$MAKE -s echo-distcom | grep '[ /]parse\.hpp '
+cd ..
+cd baz
+$MAKE echo-distcom
+$MAKE -s echo-distcom | grep '[ /]sub/parse\.c++ '
+$MAKE -s echo-distcom | grep '[ /]sub/parse\.h++ '
+cd ..
+cd qux
+$MAKE echo-distcom
+$MAKE -s echo-distcom | grep '[ /]maude-parse\.cxx '
+$MAKE -s echo-distcom | grep '[ /]maude-parse\.hxx '
+cd ..
+
+$MAKE distdir
+find $distdir # For debugging.
+
+test -f $distdir/ylwrap
+test -f $distdir/foo/parse.cc
+test -f $distdir/foo/parse.hh
+test -f $distdir/bar/parse.cpp
+test -f $distdir/bar/parse.hpp
+test -f $distdir/baz/sub/parse.c++
+test -f $distdir/baz/sub/parse.h++
+test -f $distdir/qux/maude-parse.cxx
+test -f $distdir/qux/maude-parse.hxx
+
+# The Yacc-derived C++ sources must be created, and not removed once
+# compiled (i.e., not treated like "intermediate files" in the GNU
+# make sense).
+yl_distcheck
+
+# Check that we can recover from deleted headers.
+$MAKE clean
+rm -f foo/parse.hh bar/parse.hpp baz/sub/parse.h++ qux/maude-parse.hxx
+$MAKE
+test -f foo/parse.hh
+test -f bar/parse.hpp
+test -f baz/sub/parse.h++
+test -f qux/maude-parse.hxx
+
+# Make sure that the Yacc-derived C++ sources are erased by
+# maintainer-clean, and not by distclean.
+$MAKE distclean
+test -f foo/parse.cc
+test -f foo/parse.hh
+test -f bar/parse.cpp
+test -f bar/parse.hpp
+test -f baz/sub/parse.c++
+test -f baz/sub/parse.h++
+test -f qux/maude-parse.cxx
+test -f qux/maude-parse.hxx
+./configure # Re-create 'Makefile'.
+$MAKE maintainer-clean
+test ! -e foo/parse.cc
+test ! -e foo/parse.hh
+test ! -e bar/parse.cpp
+test ! -e bar/parse.hpp
+test ! -e baz/sub/parse.c++
+test ! -e baz/sub/parse.h++
+test ! -e qux/maude-parse.cxx
+test ! -e qux/maude-parse.hxx
+
+:
diff --git a/t/yacc-d-vpath.sh b/t/yacc-d-vpath.sh
new file mode 100644
index 000000000..da679b413
--- /dev/null
+++ b/t/yacc-d-vpath.sh
@@ -0,0 +1,108 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# This test checks that dependent files are updated before including
+# in the distribution. 'parse.c' depends on 'parse.y'. The latter is
+# updated so that 'parse.c' should be rebuilt. Then we are running
+# 'make' and 'make distdir' and check whether the version of 'parse.c'
+# to be distributed is up to date.
+
+# Please keep this in sync with sister test 'yaccvpath.sh'.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = parse.y foo.c
+AM_YFLAGS = -d
+END
+
+# Original parser, with 'foobar'.
+cat > parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%token FOOBAR
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+cat > foo.c << 'END'
+#include "parse.h"
+int main () { return 0; }
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+$YACC -d parse.y
+mv y.tab.c parse.c
+mv y.tab.h parse.h
+# Sanity checks.
+grep foobar parse.c
+grep FOOBAR parse.h
+
+mkdir sub
+cd sub
+../configure
+
+$sleep
+
+# New parser, with 'fubar'.
+cat > ../parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%token FUBAR
+%%
+fubar : 'f' 'u' 'b' 'a' 'r' {};
+END
+
+$MAKE
+$MAKE distdir
+$FGREP fubar $distdir/parse.c
+$FGREP FUBAR $distdir/parse.h
+
+# Now check to make sure that 'make dist' will rebuild the parser.
+
+$sleep
+
+# New parser, with 'maude'.
+cat > ../parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%token MAUDE
+%%
+maude : 'm' 'a' 'u' 'd' 'e' {};
+END
+
+$MAKE distdir
+$FGREP maude $distdir/parse.c
+$FGREP MAUDE $distdir/parse.h
+
+:
diff --git a/t/yacc-deleted-headers.sh b/t/yacc-deleted-headers.sh
new file mode 100644
index 000000000..87a2acca1
--- /dev/null
+++ b/t/yacc-deleted-headers.sh
@@ -0,0 +1,163 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Tests that we can recover from deleted headers generated by 'yacc -d'.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = p1 p2 p3 p4
+# The order in which files are listed in the p*_SOURCES variables
+# below is significant, since it causes make failures whenever
+# the proper definition of BUILT_SOURCES or the declaration of
+# extra dependencies for 'main3.o' are removed.
+p1_SOURCES = main1.c parse1.y
+p2_SOURCES = main2.c parse2.y
+p3_SOURCES = main3.c parse3.y parse3.h
+p4_SOURCES = parse4.y
+AM_YFLAGS = -d
+p2_YFLAGS = -d
+
+BUILT_SOURCES = parse1.h p2-parse2.h
+
+# When we know which files include a yacc-generated header, we
+# should be able to just declare dependencies directly instead
+# of relying on the BUILT_SOURCES hack, and things should still
+# work correctly.
+main3.@OBJEXT@ parse3.@OBJEXT@: parse3.h
+
+.PHONY: clean-p3 build-p3
+build-p3: p3$(EXEEXT)
+clean-p3:
+ rm -f p3$(EXEEXT)
+END
+
+cat > parse1.y << 'END'
+%{
+#include "parse1.h"
+int yylex () { return 0; }
+void yyerror (char *s) { return; }
+%}
+%token ZARDOZ
+%%
+x : 'x' {};
+%%
+END
+
+cat > main1.c << 'END'
+#include "parse1.h"
+int main (void)
+{
+ return ZARDOZ + yyparse ();
+}
+END
+
+sed 's/"parse1\.h"/"p2-parse2.h"/' parse1.y > parse2.y
+sed 's/"parse1\.h"/"p2-parse2.h"/' main1.c > main2.c
+
+sed 's/"parse1\.h"/"parse3.h"/' parse1.y > parse3.y
+sed 's/"parse1\.h"/"parse3.h"/' main1.c > main3.c
+
+cat > parse4.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) { return; }
+%}
+%%
+x : 'x' {};
+%%
+int main (void)
+{
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+
+headers='parse1.h p2-parse2.h parse3.h parse4.h'
+
+# Check that we remake only the necessary headers.
+
+rm -f $headers
+$MAKE parse1.h
+test -f parse1.h
+test ! -e p2-parse2.h
+test ! -e parse3.h
+test ! -e parse4.h
+
+rm -f $headers
+$MAKE p2-parse2.h
+test ! -e parse1.h
+test -f p2-parse2.h
+test ! -e parse3.h
+test ! -e parse4.h
+
+rm -f $headers
+$MAKE parse3.h
+test ! -e parse1.h
+test ! -e p2-parse2.h
+test -f parse3.h
+test ! -e parse4.h
+# Since we declared parse3.h into $(p3_SOURCES), make should be
+# able to rebuild it automatically before remaking 'p3'.
+rm -f $headers
+$MAKE clean-p3
+test ! -e parse3.h # Sanity check.
+$MAKE build-p3
+test -f parse3.h
+
+$MAKE
+
+rm -f $headers
+$MAKE parse4.h
+test ! -e parse1.h
+test ! -e p2-parse2.h
+test ! -e parse3.h
+test -f parse4.h
+
+# Now remake all the headers together.
+
+rm -f $headers
+$MAKE $headers
+test -f parse1.h
+test -f p2-parse2.h
+test -f parse3.h
+test -f parse4.h
+
+# Most headers should be remade by "make all".
+
+rm -f $headers
+$MAKE all
+test -f parse1.h
+test -f p2-parse2.h
+test -f parse3.h
+# parse4.h is not declared in any *_SOURCES variable, nor #included
+# by any C source file, so it shouldn't be rebuilt by "make all".
+test ! -e parse4.h
+
+:
diff --git a/t/yacc-depend.sh b/t/yacc-depend.sh
new file mode 100644
index 000000000..d3d568b0a
--- /dev/null
+++ b/t/yacc-depend.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure depcomp does not needlessly update headers for yacc rules.
+# Report from Paolo Bonzini.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+AM_YFLAGS = -d
+foo_SOURCES = foo.y main.c
+BUILT_SOURCES = foo.h
+END
+
+cat > foo.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) { return; }
+%}
+%token TOKEN
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+
+cat > main.c << 'END'
+#include "foo.h"
+int main(void)
+{
+ return yyparse ();
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# Try to enable dependency tracking if possible, even if that means
+# using slow dependency extractors.
+./configure --enable-dependency-tracking
+$MAKE
+ls -l # For debugging.
+
+# Make sure foo.h is not updated if not really needed.
+$sleep
+: > my-timestamp
+$sleep
+touch foo.y
+$MAKE
+stat my-timestamp foo.* || : # For debugging.
+is_newest my-timestamp foo.h
+
+# Make sure foo.h is updated if needed.
+$sleep
+sed 's/TOKEN/TEKON/g' foo.y > t
+mv -f t foo.y
+$MAKE
+stat my-timestamp foo.* || : # For debugging.
+is_newest foo.h my-timestamp
+
+:
diff --git a/t/yacc-depend2.sh b/t/yacc-depend2.sh
new file mode 100644
index 000000000..3d9ebb1d0
--- /dev/null
+++ b/t/yacc-depend2.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Make sure depcomp does not needlessly update headers and objects
+# for yacc rules. This test still fails with FreeBSD make (but passes
+# with NetBSD make).
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+AM_YFLAGS = -d
+foo_SOURCES = foo.y main.c
+BUILT_SOURCES = foo.h
+.PHONY: test-time-unchanged test-time-changed
+test-time-unchanged:
+ is_newest foo.y foo.h main.$(OBJEXT)
+test-time-changed:
+ is_newest main.$(OBJEXT) foo.y foo.h
+END
+
+cat > foo.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) { return; }
+%}
+%token TOKEN
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+
+cat > main.c << 'END'
+#include "foo.h"
+int main(void)
+{
+ return yyparse ();
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# Try to enable dependency tracking if possible, even if that means
+# using slow dependency extractors.
+./configure --enable-dependency-tracking
+$MAKE
+ls -l # For debugging.
+
+$sleep
+touch foo.y
+$MAKE
+$MAKE test-time-unchanged
+$sleep
+sed 's/TOKEN/TEKON/g' foo.y > t
+mv -f t foo.y
+$MAKE
+$MAKE test-time-changed
+
+:
diff --git a/t/yacc-dist-nobuild-subdir.sh b/t/yacc-dist-nobuild-subdir.sh
new file mode 100644
index 000000000..5fe1b5218
--- /dev/null
+++ b/t/yacc-dist-nobuild-subdir.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that VPATH builds and "make distcheck" works with packages
+# using yacc and the automake 'subdir-objects' option.
+# Exposes automake bug#8485.
+
+required='cc yacc'
+. test-init.sh
+
+# This test is bounded to fail for any implementation that
+# triggers automake bug#7884.
+useless_vpath_rebuild && skip_ "would trip on automake bug#7884"
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > sub/parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) { return; }
+%}
+%%
+x : 'x' {};
+%%
+int main (void)
+{
+ return yyparse ();
+}
+END
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = subdir-objects
+noinst_PROGRAMS = foo bar
+foo_SOURCES = sub/parse.y
+bar_SOURCES = $(foo_SOURCES)
+AM_YFLAGS = -d
+bar_YFLAGS =
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE distdir
+
+# Yacc-derived C source and header files must be built and distributed.
+
+test -f sub/parse.c
+test -f sub/parse.h
+test -f sub/bar-parse.c
+test ! -e sub/bar-parse.h
+
+test -f $distdir/sub/parse.c
+test -f $distdir/sub/parse.h
+test -f $distdir/sub/bar-parse.c
+test ! -e $distdir/sub/bar-parse.h
+
+# But they shouldn't be rebuilt in VPATH builds.
+
+mkdir $distdir/build
+chmod -R a-w $distdir
+cd $distdir/build
+chmod u+w .
+# Try to enable dependency tracking even with slow dependency
+# extractors, to improve coverage.
+../configure --enable-dependency-tracking YACC=false
+$MAKE
+ls -l sub/*.[ch] && exit 1
+
+env DISTCHECK_CONFIGURE_FLAGS='YACC=false' $MAKE distcheck
+
+:
diff --git a/t/yacc-dist-nobuild.sh b/t/yacc-dist-nobuild.sh
new file mode 100644
index 000000000..247e32b3f
--- /dev/null
+++ b/t/yacc-dist-nobuild.sh
@@ -0,0 +1,89 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that distributed Yacc-generated parsers are not uselessly
+# remade from an unpacked distributed tarball.
+# See automake bug#7884.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foobar zardoz
+foobar_SOURCES = parse.y main.c
+zardoz_SOURCES = $(foobar_SOURCES)
+zardoz_YFLAGS = -d
+END
+
+cat > parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+cat > main.c << 'END'
+int main () { return 0; }
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+
+$MAKE distdir
+chmod -R a-w $distdir
+
+mkdir bin
+cat > bin/yacc <<'END'
+#!/bin/sh
+echo "$0 invoked, shouldn't happen!" >&2
+exit 1
+END
+cp bin/yacc bin/bison
+chmod a+x bin/yacc bin/bison
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH
+
+YACC=yacc BISON=bison
+export YACC BISON
+
+mkdir build
+cd build
+../$distdir/configure
+$MAKE
+
+# Sanity check.
+cd ..
+chmod u+w $distdir
+rm -f $distdir/parse.c
+chmod a-w $distdir
+mkdir build2
+cd build2
+../$distdir/configure
+run_make -e FAIL -M
+$FGREP parse.c output
+
+:
diff --git a/t/yacc-dry.sh b/t/yacc-dry.sh
new file mode 100644
index 000000000..d76f26ffe
--- /dev/null
+++ b/t/yacc-dry.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Removal recovery rules for headers should not remove files with 'make -n'.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_YFLAGS = -d
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c parse.y
+END
+
+cat > foo.c << 'END'
+int main () { return 0; }
+END
+
+cat > parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+$AUTOCONF
+./configure
+$MAKE
+
+rm -f parse.h
+$MAKE -n parse.h
+test -f parse.c
+test ! -e parse.h
+
+:
diff --git a/t/yacc-grepping.sh b/t/yacc-grepping.sh
new file mode 100644
index 000000000..b45ca7abc
--- /dev/null
+++ b/t/yacc-grepping.sh
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Some grep-based checks on yacc support:
+#
+# - Make sure intermediate .c file is built from yacc source.
+# Report from Thomas Morgan.
+#
+# - Make sure intermediate .h file is not generated nor removed
+# if (AM_)?YFLAGS do not contain '-d'.
+# Requested by Jim Meyering.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+END
+
+# Run it here once and for all, since we are not going to modify
+# configure.ac anymore.
+$ACLOCAL
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = zardoz.y
+END
+
+# Don't redefine several times the same variable.
+cp Makefile.am Makefile.src
+
+$AUTOMAKE -a
+$FGREP 'zardoz.c' Makefile.in
+# If zardoz.h IS mentioned, fail.
+$FGREP 'zardoz.h' Makefile.in && exit 1
+
+cp Makefile.src Makefile.am
+echo 'AM_YFLAGS = -d' >> Makefile.am
+$AUTOMAKE
+$FGREP 'zardoz.c' Makefile.in
+# If zardoz.h is NOT mentioned, fail.
+$FGREP 'zardoz.h' Makefile.in
+
+cp Makefile.src Makefile.am
+echo 'AM_YFLAGS = ' >> Makefile.am
+$AUTOMAKE
+$FGREP 'zardoz.c' Makefile.in
+# If zardoz.h IS mentioned, fail.
+$FGREP 'zardoz.h' Makefile.in && exit 1
+
+cp Makefile.src Makefile.am
+echo 'YFLAGS = -d' >> Makefile.am
+# YFLAGS is a user variable.
+AUTOMAKE_fails
+grep 'YFLAGS.* user variable' stderr
+grep 'AM_YFLAGS.* instead' stderr
+$AUTOMAKE -Wno-gnu
+# If zardoz.h is NOT mentioned, fail.
+$FGREP 'zardoz.h' Makefile.in
+
+cp Makefile.src Makefile.am
+echo 'YFLAGS = ' >> Makefile.am
+$AUTOMAKE -Wno-gnu
+# If zardoz.h IS mentioned, fail.
+$FGREP 'zardoz.h' Makefile.in && exit 1
+
+:
diff --git a/t/yacc-grepping2.sh b/t/yacc-grepping2.sh
new file mode 100644
index 000000000..71be64dbe
--- /dev/null
+++ b/t/yacc-grepping2.sh
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test of yacc functionality, derived from GNU binutils
+# by Tim Van Holder.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = maude
+maude_SOURCES = sub/maude.y
+END
+
+mkdir sub
+
+: > sub/maude.y
+
+$ACLOCAL
+# FIXME: stop disabling the warnings in the 'unsupported' category
+# FIXME: once the 'subdir-objects' option has been mandatory.
+$AUTOMAKE -a -Wno-unsupported
+
+grep '^maude\.c:.*maude\.y' Makefile.in
+
+
+## Try again with subdir-objects.
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = maude
+maude_SOURCES = sub/maude.y
+END
+
+$AUTOMAKE -a
+
+# No rule needed, the default .y.c: inference rule is enough
+# (but there may be an additional dependency on a dirstamp file).
+grep '^sub/maude\.c:.*maude\.y' Makefile.in && exit 1
+
+
+## Try again with per-exe flags.
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = maude
+maude_SOURCES = sub/maude.y
+## A particularly trickey case.
+maude_YFLAGS = -d
+END
+
+# FIXME: stop disabling the warnings in the 'unsupported' category
+# FIXME: once the 'subdir-objects' option has been mandatory.
+$AUTOMAKE -a -Wno-unsupported
+
+# Rule should use maude_YFLAGS.
+grep 'AM_YFLAGS.*maude' Makefile.in && exit 1
+
+# Silly regression.
+grep 'maudec' Makefile.in && exit 1
+
+# Make sure the .o file is required.
+grep '^am_maude_OBJECTS.*maude' Makefile.in
+
+:
diff --git a/t/yacc-headers-and-dist-pr47.sh b/t/yacc-headers-and-dist-pr47.sh
new file mode 100644
index 000000000..ef81f7a23
--- /dev/null
+++ b/t/yacc-headers-and-dist-pr47.sh
@@ -0,0 +1,89 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test to make sure dependencies are generated correctly for .h files.
+# Report from Richard Boulton.
+#
+# Also check that the sources of the generated parser are distributed.
+# PR/47.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.y
+AM_YFLAGS = -d
+
+check-dist: distdir
+ test -f $(distdir)/foo.y
+ test -f $(distdir)/foo.c
+ test -f $(distdir)/foo.h
+END
+
+# The %union will cause Bison to output '#line's in y.tab.h too.
+cat > foo.y << 'END'
+%union
+{
+ int i;
+ char c;
+}
+%%
+WORD: "up";
+%%
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+./configure
+
+$MAKE foo.h
+
+test -f foo.h
+
+rm -f foo.h foo.c
+$MAKE check-dist
+
+# We should be able to recover if foo.h is deleted.
+
+rm -f foo.h
+$MAKE foo.h
+test -f foo.h
+
+# Make sure '#line ... y.tab.h' gets replaced.
+$FGREP 'y.tab.h' foo.h && exit 1
+
+# Make distclean must not erase foo.c nor foo.h (by GNU standards) ...
+$MAKE foo.c
+test -f foo.h
+test -f foo.c
+$MAKE distclean
+test -f foo.h
+test -f foo.c
+# ... but maintainer-clean should.
+./configure # Re-create 'Makefile'.
+$MAKE maintainer-clean
+test ! -e foo.h
+test ! -e foo.c
+
+:
diff --git a/t/yacc-line.sh b/t/yacc-line.sh
new file mode 100644
index 000000000..6bf349f17
--- /dev/null
+++ b/t/yacc-line.sh
@@ -0,0 +1,126 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake yacc support ensures that yacc-generated C
+# files use correct "#line" directives. Try also with the
+# 'subdir-object' option enabled.
+# See also sister test 'lex-line.sh'.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+mkdir dir sub sub/dir
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+bin_PROGRAMS = foo bar
+AM_YFLAGS = -d
+bar_YFLAGS =
+foo_SOURCES = zardoz.y
+bar_SOURCES = dir/quux.y
+## Avoid spurious failures with Solaris make.
+zardoz.@OBJEXT@: zardoz.c
+bar-quux.@OBJEXT@: bar-quux.c
+END
+
+cat > sub/Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+noinst_PROGRAMS = foo bar
+foo_YFLAGS = -d
+foo_SOURCES = zardoz.y
+bar_SOURCES = dir/quux.y
+## Avoid spurious failures with Solaris make.
+foo-zardoz.@OBJEXT@: foo-zardoz.c
+dir/quux.@OBJEXT@: dir/quux.c
+END
+
+cat > zardoz.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) { return; }
+%}
+%%
+x : 'x' {};
+%%
+int main(void)
+{
+ return yyparse ();
+}
+END
+
+cp zardoz.y dir/quux.y
+cp zardoz.y sub/zardoz.y
+cp zardoz.y sub/dir/quux.y
+
+c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
+
+$ACLOCAL
+$AUTOCONF
+# FIXME: stop disabling the warnings in the 'unsupported' category
+# FIXME: once the 'subdir-objects' option has been mandatory.
+$AUTOMAKE -a -Wno-unsupported
+
+for vpath in : false; do
+
+ if $vpath; then
+ srcdir=..
+ mkdir build
+ cd build
+ else
+ srcdir=.
+ fi
+
+ $srcdir/configure
+ $MAKE
+
+ # For debugging,
+ ls -l . sub sub/dir
+ $EGREP 'line|\.y' $c_outputs
+
+ # Adjusted "#line" should not contain reference to the builddir.
+ grep '#.*line.*build.*\.y' $c_outputs && exit 1
+ # Adjusted "#line" should not contain reference to the absolute
+ # srcdir.
+ $EGREP '#.*line *"?/.*\.y' $c_outputs && exit 1
+ # Adjusted "#line" should not contain reference to the default
+ # output file names, e.g., 'y.tab.c' and 'y.tab.h'.
+ grep '#.*line.*y\.tab\.' $c_outputs && exit 1
+ # Look out for a silly regression.
+ grep "#.*\.y.*\.y" $c_outputs && exit 1
+ if $vpath; then
+ grep '#.*line.*"\.\./zardoz\.y"' zardoz.c
+ grep '#.*line.*"\.\./dir/quux\.y"' bar-quux.c
+ grep '#.*line.*"\.\./\.\./sub/zardoz\.y"' sub/foo-zardoz.c
+ grep '#.*line.*"\.\./\.\./sub/dir/quux\.y"' sub/dir/quux.c
+ else
+ grep '#.*line.*"zardoz\.y"' zardoz.c
+ grep '#.*line.*"dir/quux\.y"' bar-quux.c
+ grep '#.*line.*"zardoz\.y"' sub/foo-zardoz.c
+ grep '#.*line.*"dir/quux\.y"' sub/dir/quux.c
+ fi
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/yacc-misc.sh b/t/yacc-misc.sh
new file mode 100644
index 000000000..2206073c7
--- /dev/null
+++ b/t/yacc-misc.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Some simple tests of ylwrap functionality.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo bar
+foo_SOURCES = parse.y foo.c
+bar_SOURCES = bar.y foo.c
+END
+
+# First parser.
+cat > parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+# Second parser.
+cat > bar.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+fubar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+cat > foo.c << 'END'
+int main (void)
+{
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+test -f ylwrap
+
+mkdir sub
+cd sub
+
+../configure
+$MAKE
+
+grep '^#.*/sub/\.\./' bar.c && exit 1
+grep '^#.*/sub/\.\./' parse.c && exit 1
+
+# Make distclean must not erase bar.c nor parse.c (by GNU standards) ...
+$MAKE distclean
+test -f bar.c
+test -f parse.c
+# ... but maintainer-clean should.
+../configure
+$MAKE maintainer-clean
+test ! -e bar.c
+test ! -e parse.c
+
+:
diff --git a/t/yacc-mix-c-cxx.sh b/t/yacc-mix-c-cxx.sh
new file mode 100644
index 000000000..615a3a258
--- /dev/null
+++ b/t/yacc-mix-c-cxx.sh
@@ -0,0 +1,206 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that many different Yacc parsers (both C and C++) can co-exists
+# in the same directory.
+
+required='cc c++ yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = c1 c2 cxx1 cxx2 cxx3
+AM_YFLAGS = -d
+
+c1_SOURCES = p.y p.h 1.c
+c2_SOURCES = p.y 2.c
+c2_YFLAGS =
+
+cxx1_SOURCES = parse.yy main1.cc parse.hh
+
+cxx2_SOURCES = parse2.y++ main2.c++
+cxx2_YFLAGS =
+
+cxx3_SOURCES = parse3.yxx main3.cxx
+
+BUILT_SOURCES = p.h parse.hh parse3.hxx
+END
+
+# The content of all the .c and .y files created below is valid C but
+# deliberately invalid C++.
+# Vice versa, the content of all the .c++, .cxx, .cc, .y++, .yxx and
+# .yy files created below is valid C++ but deliberately invalid C.
+
+cat > p.y <<'END'
+%{
+int yylex (void) { int new = 0; return new; }
+void yyerror (char *s) { return; }
+%}
+%token ZARDOZ
+%%
+x : 'x' {};
+%%
+END
+
+cat > 1.c <<'END'
+#include "p.h"
+int main ()
+{
+ int new = ZARDOZ;
+ return yyparse () + new;
+}
+
+END
+
+cat > 2.c <<'END'
+int main ()
+{
+ int yyparse ();
+ int new = 0;
+ return yyparse () + new;
+}
+END
+
+cat > parse.yy <<'END'
+%{
+#include <cstdlib>
+#include "parse.hh"
+int yylex (void) { return 0; }
+void yyerror (const char *s) { return; }
+%}
+%token FOOBAR
+%%
+x : 'x' {};
+%%
+END
+
+cat > parse2.y++ <<'END'
+%{
+#include <cstdlib>
+int yylex (void) { return 0; }
+void yyerror (const char *s) { return; }
+%}
+%%
+x : 'x' {};
+%%
+END
+
+cat > main1.cc <<'END'
+using namespace std;
+#include "parse.hh"
+int main (int argc, char **argv)
+{
+ int yyparse (void);
+ return yyparse () + FOOBAR;
+}
+END
+
+cat > main2.c++ <<'END'
+using namespace std;
+int main (int argc, char **argv)
+{
+ int yyparse (void);
+ return yyparse ();
+}
+END
+
+edit () { sed -e 's/FOOBAR/BAZQUUX/' -e 's/"parse\.hh"/"parse3.hxx"/'; }
+edit <parse.yy >parse3.yxx
+edit <main1.cc >main3.cxx
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+# Try a VPATH and by default serial build first, and then an in-tree
+# and by default parallel build.
+
+for try in 0 1; do
+
+ if test $try -eq 0; then
+ # VPATH serial build.
+ mkdir build
+ cd build
+ srcdir=..
+ debug_info="ls -l . $srcdir"
+ run_make=$MAKE
+ elif test $try -eq 1; then
+ # In-tree parallel build.
+ srcdir=.
+ debug_info="ls -l"
+ case $MAKE in
+ *\ -j*)
+ # Degree of parallelism already specified by the user: do
+ # not override it.
+ run_make=$MAKE;;
+ *)
+ # Some make implementations (e.g., HP-UX) don't grok '-j',
+ # some require no space between '-j' and the number of jobs
+ # (e.g., older GNU make versions), and some *do* require a
+ # space between '-j' and the number of jobs (e.g., Solaris
+ # dmake). We need a runtime test to see what works.
+ echo 'all:' > Makefile
+ for run_make in "$MAKE -j3" "$MAKE -j 3" "$MAKE"; do
+ $run_make && break
+ done
+ rm -f Makefile
+ esac
+ else
+ echo "$me: invalid value of \$try '$try'" >&2
+ exit 99
+ fi
+
+ $srcdir/configure
+
+ $run_make
+ $debug_info
+
+ test -f p.c
+ test -f p.h
+ test -f c2-p.c
+ test ! -e c2-p.h
+
+ test -f parse.cc
+ test -f parse.hh
+ test -f parse3.cxx
+ test -f parse3.hxx
+
+ test -f cxx2-parse2.c++
+ test ! -e parse2.h++
+ test ! -e cxx2-parse2.h++
+
+ # Minimal checks about recovering from header removal.
+ rm -f p.h parse.hh parse3.hxx
+ $run_make p.h parse.hh
+ $debug_info
+ test -f p.h
+ test -f parse.hh
+ test ! -e parse3.hxx
+ $run_make
+ $debug_info
+ test -f parse3.hxx
+
+ cd $srcdir
+
+done
+
+:
diff --git a/t/yacc-nodist.sh b/t/yacc-nodist.sh
new file mode 100644
index 000000000..8717d67a3
--- /dev/null
+++ b/t/yacc-nodist.sh
@@ -0,0 +1,101 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Checks for .c and .h files derived from non-distributed yacc sources.
+# The test 'yacc-pr204.sh' does similar check with AM_MAINTAINER_MODE
+# enabled.
+# The tests 'lex-nodist.sh' and 'lex-pr204.sh' does similar checks
+# for lex-generated .c files.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub1 sub2
+.PHONY: test-build test-dist
+test-build: all
+ ls -l . sub1 sub2
+ test -f sub1/parse.y
+ test -f sub1/parse.c
+ test -f sub2/parse.y
+ test -f sub2/parse.c
+ test -f sub2/parse.h
+test-dist: distdir
+ ls -l $(distdir) $(distdir)/sub1 $(distdir)/sub2
+ test ! -r $(distdir)/sub1/parse.y
+ test ! -r $(distdir)/sub1/parse.c
+ test ! -r $(distdir)/sub1/parse.h
+ test ! -r $(distdir)/sub2/parse.y
+ test ! -r $(distdir)/sub2/parse.c
+ test ! -r $(distdir)/sub2/parse.h
+check-local: test-build test-dist
+END
+
+mkdir sub1 sub2
+
+cat > sub1/Makefile.am << 'END'
+parse.y:
+ rm -f $@ $@-t
+ :; { : \
+ && echo "%{" \
+ && echo "int yylex () { return 0; }" \
+ && echo "void yyerror (char *s) {}" \
+ && echo "%}" \
+ && echo "%%" \
+ && echo "maude : 'm' 'a' 'u' 'd' 'e' {}"; \
+ } > $@-t
+ chmod a-w $@-t && mv -f $@-t $@
+
+bin_PROGRAMS = prog
+prog_SOURCES = main.c
+nodist_prog_SOURCES = parse.y
+CLEANFILES = $(nodist_prog_SOURCES)
+END
+
+cat sub1/Makefile.am - > sub2/Makefile.am << 'END'
+AM_YFLAGS = -d
+BUILT_SOURCES = parse.h
+END
+
+cat > sub1/main.c << 'END'
+int main ()
+{
+ return yyparse ();
+}
+END
+cat - sub1/main.c > sub2/main.c << 'END'
+#include "parse.h"
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+$MAKE test-build
+$MAKE test-dist
+
+yl_distcheck
+
+:
diff --git a/t/yacc-pr204.sh b/t/yacc-pr204.sh
new file mode 100644
index 000000000..edf463f0c
--- /dev/null
+++ b/t/yacc-pr204.sh
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# For PR 204.
+# C sources derived from nodist_ yacc sources should not be distributed.
+# See also related test 'yacc-nodist.sh'.
+# The tests 'lex-nodist.sh' and 'lex-pr204.sh' does similar checks
+# for lex-generated C files.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac <<'EOF'
+AM_MAINTAINER_MODE
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+EOF
+
+# The PARSE2 intermediate variable is there to make
+# sure Automake match 'nodist_' against the right
+# variable name...
+cat > Makefile.am << 'EOF'
+AM_YFLAGS = -d
+EXTRA_PROGRAMS = foo
+PARSE2 = parse2.y
+nodist_foo_SOURCES = parse.y $(PARSE2)
+
+distdirtest: distdir
+ test ! -f $(distdir)/parse.c
+ test ! -f $(distdir)/parse.y
+ test ! -f $(distdir)/parse.h
+ test ! -f $(distdir)/parse2.c
+ test ! -f $(distdir)/parse2.y
+ test ! -f $(distdir)/parse2.h
+EOF
+
+cat > parse.y << 'END'
+%{
+int yylex () {return 0;}
+void yyerror (char *s) {}
+%}
+%%
+maude : 'm' 'a' 'u' 'd' 'e' {};
+END
+
+cp parse.y parse2.y
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE distdirtest
+
+# Make sure parse.c and parse2.c are still targets.
+$MAKE parse.c parse2.c
+test -f parse.c
+test -f parse2.c
+
+# Ensure the rebuild rule works despite AM_MAINTAINER_MODE, because
+# it's a nodist_ parser.
+$sleep
+touch parse.y parse2.y
+$sleep
+$MAKE parse.c parse2.c
+is_newest parse.c parse.y
+is_newest parse2.c parse2.y
+
+:
diff --git a/t/yacc-subdir.sh b/t/yacc-subdir.sh
new file mode 100644
index 000000000..f34868576
--- /dev/null
+++ b/t/yacc-subdir.sh
@@ -0,0 +1,106 @@
+#! /bin/sh
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for subdir parsers.
+
+required='cc yacc'
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = foo/foo
+foo_foo_SOURCES = foo/parse.y
+AM_YFLAGS = -d
+
+.PHONY: obj
+obj: foo/parse.$(OBJEXT)
+
+.PHONY: test1 test2
+test1: foo/parse.$(OBJEXT)
+ test -f foo/parse.c
+ test -f foo/parse.$(OBJEXT)
+test2: foo/parse2.$(OBJEXT)
+ test -f foo/parse2.c
+ test -f foo/parse2.$(OBJEXT)
+END
+
+mkdir foo
+
+cat > foo/parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+mkdir sub
+cd sub
+
+../configure
+$MAKE test1
+
+# Aside of the rest of this test, let's see if we can recover from
+# parse.h removal.
+test -f foo/parse.h
+rm -f foo/parse.h
+$MAKE foo/parse.h
+test -f foo/parse.h
+
+# Make sure foo/parse.h is not updated, unless when needed.
+$sleep
+touch ../foo/parse.y
+$MAKE obj
+is_newest ../foo/parse.y foo/parse.h
+$sleep
+sed 's/%%/%token TOKEN\n%%/g' ../foo/parse.y >../foo/parse.yt
+mv -f ../foo/parse.yt ../foo/parse.y
+$MAKE obj
+is_newest foo/parse.h ../foo/parse.y
+
+# Now, adds another parser to test ylwrap.
+
+cd ..
+
+# Sleep some to make sure timestamp of Makefile.am will change.
+$sleep
+
+cp foo/parse.y foo/parse2.y
+cat >> Makefile.am << 'END'
+EXTRA_foo_foo_SOURCES = foo/parse2.y
+END
+
+$AUTOMAKE -a
+test -f ./ylwrap
+
+cd sub
+# Regenerate Makefile (automatic in GNU Make, but not in other Makes).
+./config.status
+$MAKE test2
+
+:
diff --git a/t/yacc-vpath.sh b/t/yacc-vpath.sh
new file mode 100644
index 000000000..55dff67c2
--- /dev/null
+++ b/t/yacc-vpath.sh
@@ -0,0 +1,97 @@
+#! /bin/sh
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# This test checks that dependent files are updated before including
+# in the distribution. 'parse.c' depends on 'parse.y'. The later is
+# updated so that 'parse.c' should be rebuild. Then we are running
+# 'make' and 'make distdir' and check whether the version of 'parse.c'
+# to be distributed is up to date.
+
+# Please keep this in sync with sister test 'yacc-d-vpath.sh'.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = parse.y foo.c
+END
+
+# Original parser, with 'foobar'.
+cat > parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+cat > foo.c << 'END'
+int main () { return 0; }
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+$YACC parse.y
+mv y.tab.c parse.c
+
+mkdir sub
+cd sub
+../configure
+
+$sleep
+
+# New parser, with 'fubar'.
+cat > ../parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+fubar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+$MAKE
+$MAKE distdir
+$FGREP fubar $distdir/parse.c
+
+# Now check to make sure that 'make dist' will rebuild the parser.
+
+$sleep
+
+# New parser, with 'maude'.
+cat > ../parse.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) {}
+%}
+%%
+maude : 'm' 'a' 'u' 'd' 'e' {};
+END
+
+$MAKE distdir
+$FGREP maude $distdir/parse.c
+
+:
diff --git a/t/yacc-weirdnames.sh b/t/yacc-weirdnames.sh
new file mode 100644
index 000000000..a40e55725
--- /dev/null
+++ b/t/yacc-weirdnames.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that yacc sources with many dots in their name are handled
+# correctly.
+
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo bar foo2 bar2
+
+foo_SOURCES = parse.y.y
+bar_SOURCES = parse.s.f..y
+bar_YFLAGS = -d
+
+foo2_SOURCES = parse..5.y++
+bar2_SOURCES = parse.yxx.yy
+bar2_YFLAGS = -d
+END
+
+outputs=' parse.y.c bar-parse.s.f..c bar-parse.s.f..h
+ parse..5.c++ bar2-parse.yxx.cc bar2-parse.yxx.hh '
+
+$ACLOCAL
+$AUTOMAKE -a
+
+$EGREP '(\.[ch]|parse)' Makefile.in # For debugging.
+
+# All expected files should be mentioned in the generated Makefile.in.
+for s in $outputs; do
+ $FGREP $s Makefile.in
+done
+
+:
diff --git a/t/yflags-cmdline-override.sh b/t/yflags-cmdline-override.sh
new file mode 100644
index 000000000..dd2bc644f
--- /dev/null
+++ b/t/yflags-cmdline-override.sh
@@ -0,0 +1,87 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake can cope with user-redefinition of $(YFLAGS)
+# at configure time and/or at make time.
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.y
+# A minor automake wart: automake doesn't generate code to clean
+# '*.output' files generated by yacc (it's not even clear if that
+# would be useful in general, so it's probably better to be
+# conservative).
+CLEANFILES = foo.output
+# As the '-d' flag won't be given at automake time, automake won't
+# be able to generate code to clean 'foo.h'. We can't really blame
+# automake for that.
+MAINTAINERCLEANFILES = foo.h
+END
+
+cat > foo.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) { return; }
+int main () { return 0; }
+%}
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+$AUTOCONF
+
+./configure YFLAGS='-d -v'
+$MAKE
+ls -l
+test -f foo.c
+test -f foo.h
+test -f foo.output
+
+$MAKE maintainer-clean
+ls -l
+
+./configure YFLAGS='-v'
+$MAKE
+ls -l
+test -f foo.c
+test ! -e foo.h
+test -f foo.output
+
+$MAKE maintainer-clean
+ls -l
+
+./configure YFLAGS='-v'
+run_make YFLAGS=-d
+ls -l
+test -f foo.c
+test -f foo.h
+test ! -e foo.output
+
+$MAKE maintainer-clean
+ls -l
+
+:
diff --git a/t/yflags-conditional.sh b/t/yflags-conditional.sh
new file mode 100644
index 000000000..612c5219b
--- /dev/null
+++ b/t/yflags-conditional.sh
@@ -0,0 +1,143 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake complains about *_YFLAGS variables which have
+# conditional content.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+
+# 'YFLAGS' is AC_SUBST'd by AC_PROG_YACC by default, but we
+# don't want this, since it might confuse our error messages.
+# Also, AM_SUBST_NOTMAKE seems not to help about this.
+# So we simply define $(YACC) by hand.
+AC_SUBST([YACC], [yacc])
+
+AM_CONDITIONAL([COND], [:])
+END
+
+$ACLOCAL
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo zardoz
+foo_SOURCES = foo.y
+zardoz_SOURCES = zardoz.y
+if COND
+AM_YFLAGS = -v
+zardoz_YFLAGS = -v
+endif COND
+END
+
+cat > Makefile1.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.y
+## This is a dummy comment to keep line count right.
+if COND
+YFLAGS = foo
+endif COND
+END
+
+cat > Makefile2.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.y
+AM_YFLAGS = am_yflags
+if COND
+YFLAGS = yflags
+endif COND
+END
+
+cat > Makefile3.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.y
+foo_YFLAGS = foo_yflags
+if COND
+YFLAGS = yflags
+endif COND
+END
+
+cat > Makefile4.am <<'END'
+bin_PROGRAMS = foo zardoz
+
+foo_SOURCES = foo.y
+zardoz_SOURCES = $(foo_SOURCES)
+
+YFLAGS =
+AM_YFLAGS = $(COND_VAR1)
+zardoz_YFLAGS = $(COND_VAR2:z=r)
+
+COND_VAR2 = foo
+if COND
+YFLAGS += -v
+COND_VAR2 += bar
+else !COND
+COND_VAR1 = -d
+endif !COND
+END
+
+cat > Makefile5.am <<'END'
+bin_PROGRAMS = foo zardoz
+foo_SOURCES = foo.y
+zardoz_SOURCES = zardoz.y
+YFLAGS = -v
+AM_YFLAGS = -v
+if COND
+zardoz_YFLAGS = -v
+endif
+END
+
+cat > Makefile6.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.y
+foo_YFLAGS = -v
+if COND
+quux_YFLAGS = -v
+AM_YFLAGS = -v
+endif
+END
+
+: > ylwrap
+
+LC_ALL=C; export LC_ALL; # For grep regexes below.
+
+AUTOMAKE_fails -Wnone -Wunsupported Makefile
+grep '^Makefile\.am:5:.*AM_YFLAGS.* conditional contents' stderr
+grep '^Makefile\.am:6:.*zardoz_YFLAGS.* conditional contents' stderr
+
+for i in 1 2 3; do
+ AUTOMAKE_fails -Wnone -Wunsupported Makefile$i
+ grep "^Makefile$i\\.am:5:.*[^a-zA-Z0-9_]YFLAGS.* conditional contents" \
+ stderr
+done
+
+AUTOMAKE_fails -Wnone -Wunsupported Makefile4
+grep '^Makefile4\.am:6:.*[^a-zA-Z0-9_]YFLAGS.* conditional contents' stderr
+grep '^Makefile4\.am:7:.*AM_YFLAGS.* conditional contents' stderr
+grep '^Makefile4\.am:8:.*zardoz_YFLAGS.* conditional contents' stderr
+
+# Now let's check we avoid false positives.
+
+# Disable 'gnu' warnings because we override the user variable 'YFLAGS'.
+AUTOMAKE_fails -Wno-gnu Makefile5
+grep -v '^Makefile5\.am:.*zardoz_YFLAGS' stderr \
+ | grep -v ': warnings are treated as errors' \
+ | grep . && exit 1
+
+# Disable 'gnu' warnings because we override the user variable 'YFLAGS'.
+$AUTOMAKE -Wno-gnu Makefile6
+
+:
diff --git a/t/yflags-cxx.sh b/t/yflags-cxx.sh
new file mode 100644
index 000000000..bf4a25cee
--- /dev/null
+++ b/t/yflags-cxx.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that $(YFLAGS) takes precedence over both $(AM_YFLAGS) and
+# $(foo_YFLAGS). This is the C++ case.
+# Please keep this in sync with the sister tests:
+# - yflags.sh
+# - lflags.sh
+# - lflags-cxx.sh
+
+. test-init.sh
+
+cat >fake-yacc <<'END'
+#!/bin/sh
+echo '/*' "$*" '*/' >y.tab.c
+echo 'extern int dummy;' >> y.tab.c
+END
+chmod a+x fake-yacc
+
+cat >> configure.ac <<'END'
+AC_SUBST([CXX], [false])
+# Simulate presence of Yacc using our fake-yacc script.
+AC_SUBST([YACC], ['$(abs_top_srcdir)'/fake-yacc])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = no-dependencies
+bin_PROGRAMS = foo bar
+foo_SOURCES = main.cc foo.yy
+bar_SOURCES = main.cc bar.y++
+AM_YFLAGS = __am_flags__
+bar_YFLAGS = __bar_flags__
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+grep '\$(YFLAGS).*\$(bar_YFLAGS)' Makefile.in && exit 1
+grep '\$(YFLAGS).*\$(AM_YFLAGS)' Makefile.in && exit 1
+
+: > foo.yy
+: > bar.y++
+
+$AUTOCONF
+./configure
+run_make YFLAGS=__user_flags__ foo.cc bar-bar.c++
+
+cat foo.cc
+cat bar-bar.c++
+
+grep '__am_flags__.*__user_flags__' foo.cc
+grep '__bar_flags__.*__user_flags__' bar-bar.c++
+
+:
diff --git a/t/yflags-d-false-positives.sh b/t/yflags-d-false-positives.sh
new file mode 100644
index 000000000..f3d172fd0
--- /dev/null
+++ b/t/yflags-d-false-positives.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check for false positives in automake recognition of '-d' in YFLAGS.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_PROG_YACC
+END
+
+$ACLOCAL
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = zardoz foobar
+zardoz_SOURCES = zardoz.y
+foobar_SOURCES = foobar.y
+# All the "almost -d" substrings ("- d", "-dd", etc.) are meant.
+AM_YFLAGS = -xd --d - d --output=d
+foobar_YFLAGS = - d $(foovar)-d -dd
+END
+
+$AUTOMAKE -a
+$EGREP '(foobar|zardoz)\.h.*:' Makefile.in && exit 1
+$EGREP '(foobar|zardoz)\.h' Makefile.in | $FGREP -v '$(YLWRAP) ' && exit 1
+
+:
diff --git a/t/yflags-force-conditional.sh b/t/yflags-force-conditional.sh
new file mode 100644
index 000000000..edae2b963
--- /dev/null
+++ b/t/yflags-force-conditional.sh
@@ -0,0 +1,85 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that the user can force automake to use *_YFLAGS variables
+# which have conditional content.
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_SUBST([CC], [false])
+AC_PROG_YACC
+AM_CONDITIONAL([COND], [test x"$cond" = x"yes"])
+AC_OUTPUT
+END
+
+mkdir bin
+cat > bin/fake-yacc <<'END'
+#!/bin/sh
+echo "/* $* */" > y.tab.c
+echo 'extern int dummy;' >> y.tab.c
+END
+chmod a+x bin/fake-yacc
+PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
+YACC=fake-yacc; export YACC
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = no-dependencies
+bin_PROGRAMS = foo bar
+foo_SOURCES = foo.y main.c
+bar_SOURCES = $(foo_SOURCES)
+bar_YFLAGS = $(bar_yflags2)
+if COND
+AM_YFLAGS = __am_cond_yes__
+bar_YFLAGS += __bar_cond_yes__
+else !COND
+AM_YFLAGS = __am_cond_no__
+bar_yflags2 = __bar_cond_no__
+endif !COND
+END
+
+: > foo.y
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a -Wno-unsupported
+
+$EGREP '(YFLAGS|yflags|am__append)' Makefile.in # For debugging.
+
+./configure cond=yes
+$MAKE foo.c bar-foo.c
+
+cat foo.c
+cat bar-foo.c
+
+$FGREP ' __am_cond_yes__ ' foo.c
+$FGREP ' __bar_cond_yes__ ' bar-foo.c
+$FGREP 'cond_no' foo.c bar-foo.c && exit 1
+
+$MAKE maintainer-clean
+ls -l
+
+./configure cond=no
+$MAKE foo.c bar-foo.c
+
+cat foo.c
+cat bar-foo.c
+
+$FGREP ' __am_cond_no__ ' foo.c
+$FGREP ' __bar_cond_no__ ' bar-foo.c
+$FGREP 'cond_yes' foo.c bar-foo.c && exit 1
+
+:
diff --git a/t/yflags-force-override.sh b/t/yflags-force-override.sh
new file mode 100644
index 000000000..aa078d40b
--- /dev/null
+++ b/t/yflags-force-override.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake can cope with a definition of the $(YFLAGS) variable
+# in Makefile.am (even if that is extremely bad practice, because that
+# variable is user-reserved).
+
+required='cc yacc'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.y
+# Don't do this in a real-life Makefile.am!
+YFLAGS = -d -v
+END
+
+cat > foo.y << 'END'
+%{
+int yylex () { return 0; }
+void yyerror (char *s) { return; }
+int main () { return 0; }
+%}
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
+END
+
+$ACLOCAL
+$AUTOMAKE -a -Wno-gnu
+
+$EGREP '(foo|YFLAGS)' Makefile.in # For debugging.
+grep '^foo\.h *:' Makefile.in
+
+$AUTOCONF
+./configure
+
+$MAKE
+
+test -f foo.c
+test -f foo.h
+test -f foo.output
+
+:
diff --git a/t/yflags-var-expand.sh b/t/yflags-var-expand.sh
new file mode 100644
index 000000000..2a6b8832e
--- /dev/null
+++ b/t/yflags-var-expand.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that automake expand variables when looking for '-d' in YFLAGS;
+# for example, the following is supposed to work:
+# foo_flags = -d
+# AM_YFLAGS = $(foo_flags)
+
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_PROG_YACC
+END
+
+$ACLOCAL
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo bar
+foo_SOURCES = foo.y
+bar_SOURCES = bar.y
+my_YFLAGS = -x
+AM_YFLAGS = $(my_YFLAGS:x=d)
+bar_YFLAGS = $(AM_YFLAGS)
+END
+
+$AUTOMAKE -a
+
+$EGREP '(foo|bar|YFLAGS)' Makefile.in # For debugging.
+grep '^foo.h *:' Makefile.in
+grep '^bar-bar.h *:' Makefile.in
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = -Wno-gnu
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = parser.y
+my_YFLAGS = $(my_YFLAGS_1)
+my_YFLAGS += $(my_YFLAGS_2)
+my_YFLAGS_2 = -d
+YFLAGS = $(my_YFLAGS)
+END
+
+$AUTOMAKE
+
+$EGREP 'parser|YFLAGS' Makefile.in # For debugging.
+grep '^parser.h *:' Makefile.in
+
+:
diff --git a/t/yflags.sh b/t/yflags.sh
new file mode 100644
index 000000000..3aaec0eb2
--- /dev/null
+++ b/t/yflags.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Check that $(YFLAGS) takes precedence over both $(AM_YFLAGS) and
+# $(foo_YFLAGS).
+# Please keep this in sync with the sister tests:
+# - yflags-cxx.sh
+# - lflags.sh
+# - lflags-cxx.sh
+
+. test-init.sh
+
+cat >fake-yacc <<'END'
+#!/bin/sh
+echo '/*' "$*" '*/' >y.tab.c
+echo 'extern int dummy;' >> y.tab.c
+END
+chmod a+x fake-yacc
+
+cat >> configure.ac <<'END'
+AC_SUBST([CC], [false])
+# Simulate presence of Yacc using our fake-yacc script.
+AC_SUBST([YACC], ['$(abs_top_srcdir)'/fake-yacc])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+AUTOMAKE_OPTIONS = no-dependencies
+bin_PROGRAMS = foo bar
+foo_SOURCES = main.c foo.y
+bar_SOURCES = main.c bar.y
+AM_YFLAGS = __am_flags__
+bar_YFLAGS = __bar_flags__
+END
+
+$ACLOCAL
+$AUTOMAKE -a
+
+grep '\$(YFLAGS).*\$(bar_YFLAGS)' Makefile.in && exit 1
+grep '\$(YFLAGS).*\$(AM_YFLAGS)' Makefile.in && exit 1
+
+: > foo.y
+: > bar.y
+
+$AUTOCONF
+./configure
+run_make YFLAGS=__user_flags__ foo.c bar-bar.c
+
+cat foo.c
+cat bar-bar.c
+
+grep '__am_flags__.*__user_flags__' foo.c
+grep '__bar_flags__.*__user_flags__' bar-bar.c
+
+: