#! /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/>.

# What happens with aclocal and automake when both `configure.in' and
# `configure.ac' are present.

. ./defs || Exit 1

set -e

: > Makefile.am

cat > configure.ac <<END
AC_INIT([$me], [1.0])
AM_INIT_AUTOMAKE
AC_CONFIG_FILES([Makefile])
END

sed 's/^AM_INIT_AUTOMAKE/&([an-invalid-automake-option])/' \
  <configure.ac >configure.in

$ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
cat stderr
grep 'configure\.ac.*configure\.in.*both present' stderr
grep 'proceeding with.*configure\.ac' stderr

test ! -r aclocal.m4

# We need aclocal.m4 for automake to find AM_INIT_AUTOMAKE
$ACLOCAL -Wno-error 2>stderr
cat stderr
grep 'configure\.ac.*configure\.in.*both present' stderr
grep 'proceeding with.*configure\.ac' stderr

AUTOMAKE_fails
grep 'configure\.ac.*configure\.in.*both present' stderr
grep 'proceeding with.*configure\.ac' stderr

test ! -r Makefile.in

mv -f configure.ac t
mv -f configure.in configure.ac
mv -f t configure.in

# To ensure a clean rerun of autom4te, aclocal and automake
rm -rf aclocal.m4 autom4te.cache

$ACLOCAL -Wno-error
# Ensure we really proceed with configure.ac
AUTOMAKE_fails -Wno-error
$FGREP 'an-invalid-automake-option' stderr
