Subject: Automake does not warn if AM_YFLAGS is conditionally extended
From: Stefano Lattarini <[email-masked]>
To: [email-masked]
Date: Fri, 7 Jan 2011 23:31:59 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello automakers.

Due to current implementation details, when dealing with Yacc sources, automake
must know the contents of the `$(AM_YFLAGS)' variable (or similar `$(foo_YFLAGS)'
variables) *statically and unconditionally* in order to always generate proper
code.

This is due to the special handling of the `-d' yacc flag; on this issue, read
at <http://www.gnu.org/software/automake/manual/html_node/Yacc-and-Lex.html>:
 ``AM_YFLAGS is usually used to pass the -d option to yacc. Automake knows what
   this means and will automatically adjust its rules to update and distribute
   the header file built by 'yacc -d'. ''

And while automake correctly warns if AM_YFLAGS is conditionally *defined*:

  $ cat configure.ac
  AC_INIT(x,0)
  AM_INIT_AUTOMAKE(foreign)
  AC_PROG_CC
  AC_PROG_YACC
  AC_CONFIG_FILES(Makefile)
  AM_CONDITIONAL(COND,:)
  $ aclocal
  $ cat > Makefile.am <<'END'
  bin_PROGRAMS = foo bar
  foo_SOURCES = foo.y
  bar_SOURCES = bar.y
  if COND
  AM_YFLAGS = -d
  endif
  END
  $ automake -a -Werror; echo status=$?
  Makefile.am:5: automake does not support AM_YFLAGS being defined conditionally
  status=1

it erronously doesn't warn if AM_YFLAGS is conditionally *extended*:

  $ cat configure.ac
  AC_INIT(x,0)
  AM_INIT_AUTOMAKE(foreign)
  AC_PROG_CC
  AC_PROG_YACC
  AC_CONFIG_FILES(Makefile)
  AM_CONDITIONAL(COND,:)
  $ aclocal
  $ cat > Makefile.am <<'END'
  bin_PROGRAMS = foo bar
  foo_SOURCES = foo.y
  bar_SOURCES = bar.y
  AM_YFLAGS =
  if COND
  AM_YFLAGS += -d
  endif
  END
  $ automake -a -Werror; echo status=$?
  status=0

I think this bug shouldn't be difficult to fix, and I'll attempt a fix
soonish; but as usual, having it in the bug tracker doesn't hurt IMHO.

Regards,
  Stefano