Subject: AM_INIT_AUTOMAKE followed by comment

From: Scott Pakin <[email-masked]>
Date: Mon, 21 Jul 2014 15:39:13 -0600

The definition of AM_INIT_AUTOMAKE does not end in a newline
character, which can cause tricky-to-track errors if the call is
followed by an M4 comment.  I believe this is new behavior because an
old set of Autotools configuration files that used to work failed when
I recently re-ran automake.

I'm running Ubuntu Trusty Tahr (14.04 LTS) with the following Automake
and Autoconf versions:

    $ automake --version | head -1
    automake (GNU automake) 1.14.1
    $ autoconf --version | head -1
    autoconf (GNU Autoconf) 2.69

I've attached a minimal reproducer, a configure.ac file with only the
following contents:

    AC_INIT([badness], [1.0], [[email-masked]], [badness])
    AM_INIT_AUTOMAKE([1.14])dnl This comment causes configure to break.
    AC_CONFIG_FILES([Makefile])
    AC_OUTPUT

Here's how to produce the error:

    $ touch Makefile.am
    $ aclocal
    $ automake --add-missing --foreign
    configure.ac:2: installing './install-sh'
    configure.ac:2: installing './missing'
    $ autoconf
    $ ./configure
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for a thread-safe mkdir -p... /bin/mkdir -p
    checking for gawk... gawk
    checking whether make sets $(MAKE)... yes
    checking whether make supports nested variables... yes
    ./configure: line 3493: syntax error: unexpected end of file

The error is caused by line 2313, which contains

    fiac_config_files="$ac_config_files Makefile"

instead of

    fi
    ac_config_files="$ac_config_files Makefile"

That is, bash is in fact complaining about a missing "fi".

Removing the comment from configure.ac or moving it onto a line of its
own works around the problem, but I think it would be nicer if init.m4
replaced the final "fi])" (right after the "Your 'rm' program is bad"
message) with

    fi
    ])

Hopefully, that'll save someone else the effort of associating an "end
of file" error with a comment appearing in the wrong place.

Thanks for your time,
-- Scott