#! /bin/sh
# Copyright (C) 2010 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General 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/>.

# Check that automake-generated remake rules work when the `foreign'
# option is removed from AM_INIT_AUTOMAKE.

. ./defs || Exit 1

set -e

# We want complete control over automake options.
AUTOMAKE=$original_AUTOMAKE

set_am_opts()
{
   sed -e "s|^\\(AM_INIT_AUTOMAKE\\).*|\\1([$1])|" <$2 >$2-t  
   mv -f $2-t $2
   cat $2
}

cat >> configure.in <<'END'
AC_OUTPUT
END

: > Makefile.am

set_am_opts 'foreign' configure.in

$ACLOCAL
$AUTOCONF
$AUTOMAKE -Wall -Werror

./configure
$MAKE

$sleep

# OK, now we warn to enable 'gnu' strictness, but we "forget" to
# create the required file `AUTHORS'.
touch README INSTALL NEWS ChangeLog COPYING

set_am_opts '' configure.in
$MAKE Makefile >out 2>&1 && { cat out; Exit 1; }
cat out
grep 'required file.*AUTHORS.*not found' out

: > AUTHORS

$MAKE Makefile
$MAKE distcheck # for completeness

:
