1#! /bin/sh
2# Copyright (C) 2011-2021 Free Software Foundation, Inc.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17# Test that we can define a distcheck-hook to diagnose outdated m4
18# files in a dist tarball (interaction with '--install').
19# See automake bug#9037.
20
21. test-init.sh
22
23cwd=$(pwd) || fatal_ "cannot get current working directory"
24
25cp "$am_testaux_srcdir"/distcheck-hook-m4.am . \
26  || fatal_ "cannot fetch makefile fragment 'distcheck-hook-m4.am'"
27
28cat > Makefile.am << 'END'
29## The lack of '--install' here is meant.
30ACLOCAL_AMFLAGS = -I m4
31include $(srcdir)/distcheck-hook-m4.am
32END
33
34cat >> configure.ac << 'END'
35AC_OUTPUT
36MY_FOO
37MY_BAR
38MY_BAZ
39END
40
41mkdir m4 acdir
42echo 'AC_DEFUN([MY_FOO], [:])' > m4/foo.m4
43echo 'AC_DEFUN([MY_BAR], [:])' > acdir/bar.m4
44cat > acdir/baz.m4 << 'END'
45# serial 1
46AC_DEFUN([MY_BAZ], [:])
47END
48
49ACLOCAL="$ACLOCAL --system-acdir=$cwd/acdir"; export ACLOCAL
50
51# The use of '--install' here won't help when the installed file '.m4'
52# will become out-of-date w.r.t. the one in the system acdir.
53$ACLOCAL -I m4 --install
54$AUTOCONF
55$AUTOMAKE
56
57./configure
58$MAKE distcheck # Sanity check.
59
60check_no_spurious_error ()
61{
62  $EGREP -i 'mkdir:|:.*(permission|denied)' output && exit 1
63  # On failure, some make implementations (such as Solaris make) print the
64  # whole failed recipe on stdout.  The first grep works around this.
65  grep -v 'rm -rf ' output | grep -i 'autom4te.*\.cache' && exit 1
66  : To placate 'set -e'.
67}
68
69# We start to use a new "third-party" macro in a new version
70# of a pre-existing third-party m4 file, but forget to re-run
71# "aclocal --install" by hand, relying on automatic remake
72# rules.  Our distcheck-hook should catch this too.
73echo MY_ZARDOZ >> configure.ac
74
75cat > acdir/baz.m4 << 'END'
76# serial 2
77AC_DEFUN([MY_BAZ], [:])
78AC_DEFUN([MY_ZARDOZ], [:])
79END
80
81$MAKE # Rebuild configure and makefiles.
82run_make -M -e FAIL distcheck
83$EGREP "required m4 file.* outdated.* baz.m4( |$)" output
84check_no_spurious_error
85# Check that we don't complain for files that aren't outdated.
86$EGREP " (foo|bar).m4" output && exit 1
87
88# Now we again use '--install' explicitly, and "make distcheck"
89# should pass.
90$ACLOCAL -I m4 --install
91using_gmake || $MAKE Makefile
92$MAKE distcheck
93
94# Similar to what have been done above, but this time we:
95#  - use ACLOCAL_PATH, and
96#  - do not add the use of a new macro.
97
98echo MY_FNORD >> configure.ac
99
100mkdir pth
101cat > pth/fnord.m4 << 'END'
102# serial 1
103AC_DEFUN([MY_FNORD], [:])
104END
105
106ACLOCAL_PATH="$cwd/pth"; export ACLOCAL_PATH
107
108# The explicit use of '--install' here won't help when the installed file
109# '.m4' will become out-of-date w.r.t. the one in the system acdir.
110$ACLOCAL -I m4 --install
111using_gmake || $MAKE Makefile
112$MAKE distcheck
113
114# Only increase serial number, without changing the other contents; this
115# is deliberate.
116cat > pth/fnord.m4 << 'END'
117# serial 2
118AC_DEFUN([MY_FNORD], [:])
119END
120
121$MAKE # Rebuild configure and makefiles.
122run_make -M -e FAIL distcheck
123$EGREP "required m4 file.* outdated.* fnord.m4( |$)" output
124check_no_spurious_error
125# Check that we don't complain for files that aren't outdated.
126$EGREP " (foo|bar|baz).m4" output && exit 1
127
128# Now we again use '--install' explicitly, and "make distcheck"
129# should pass.
130$ACLOCAL -I m4 --install
131using_gmake || $MAKE Makefile
132$MAKE distcheck
133
134:
135