#! /bin/sh
# Copyright (C) 2001, 2002, 2004, 2006, 2010, 2011 Free Software
# Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Files specified by AC_REQUIRE_AUX_FILE must exist, and they get
# distributed by the top-level Makefile.am.

. ./defs || Exit 1

set -e

cat > configure.in <<END
AC_INIT([$me], [1.0])
AC_CONFIG_AUX_DIR([.])
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

cat > Makefile.am <<'END'
SUBDIRS = subdir

test: distdir
	ls -l $(distdir) $(distdir)/*      ;: For debugging.
	@echo DIST_COMMON = $(DIST_COMMON) ;: Likewise.
	echo ' ' $(DIST_COMMON) ' ' | grep '[ /]foo.txt '
	echo ' ' $(DIST_COMMON) ' ' | grep '[ /]bar.sh '
	echo ' ' $(DIST_COMMON) ' ' | grep '[ /]zardoz '
	test -f $(distdir)/foo.txt
	test -f $(distdir)/bar.sh
	test -f $(distdir)/zardoz
.PHONY: test
check-local: test
END

mkdir subdir
: > subdir/Makefile.am

for dir in .; do

  rm -rf autom4te*.cache
  test -d $dir || mkdir $dir
  echo "AC_CONFIG_AUX_DIR([$dir])" > config-aux-dir.m4
  $ACLOCAL
  $AUTOCONF

  AUTOMAKE_fails
  grep "^configure\\.in:4:.* required file.*$dir/foo\\.txt" stderr
  grep "^configure\\.in:5:.* required file.*$dir/bar\\.sh"  stderr
  grep "^configure\\.in:6:.* required file.*$dir/zardoz"    stderr

  touch foo.txt bar.sh zardoz
  $AUTOMAKE
  ./configure
  $MAKE test
  $EGREP '(foo\.txt|bar\.sh|zardoz)' subdir/Makefile.in && Exit 1

  $MAKE distcheck
  $MAKE distclean

done

:
