]> git.ipfire.org Git - thirdparty/autoconf.git/commit
m4sh: allow trailing newlines in shell conditions
authorEric Blake <eblake@redhat.com>
Thu, 17 Jul 2014 20:52:57 +0000 (14:52 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 17 Jul 2014 21:40:12 +0000 (15:40 -0600)
commit0443fa8d4320b3f42a7774c470cc40921cf74d00
treeab26c21d3b6584a3a9f68dad77b95622bd125e2c
parent5dcda009ef77b657e5a78ad88774fe50c5088abc
m4sh: allow trailing newlines in shell conditions

Dimitrios Apostolou reported getting a shell syntax error for
this construct in his configure.ac:

AM_CONDITIONAL([HAVE_LIBXML2],
    [test "x$with_libxml2" != xno &&
     test "x$ac_cv_lib_xml2_xmlFirstElementChild" = xyes]
)

He analyzed it to a root cause: his trailing newline, coupled
with an 'if $2; then' construct in the macro body, resulted in
configure containing:
if test ... xyes
; then
where the semicolon is a syntax error in shell; and proposed
a patch to automake to fix his use case.

While that macro is not under our control, it does highlight
the fact that the shell can use either ; or newline to
terminate a conditional prior to the next keyword in a compound
statement.  If we use newline, we gain two benefits - the
configure file is slightly smaller (more lines, but fewer
bytes), and any user that doesn't realize that unquoted
trailing newlines in a macro argument are still significant
can still generate valid shell code when their argument is
used in a shell compound statement.

* lib/m4sugar/m4sh.m4 (AS_IF, _AS_IF, _AS_CLEAN_DIR): Prefer
newline over semicolon to end user-supplied conditionals.
* lib/autoconf/general.m4 (AC_CONFIG_AUX_DIRS): Likewise.
* lib/autoconf/libs.m4 (AC_SEARCH_LIBS): Likewise.
* lib/autoconf/programs.m4 (_AC_PATH_PROGS_FEATURE_CHECK):
Likewise.
* tests/m4sh.at (AS_IF and AS_CASE): Test it.

Signed-off-by: Eric Blake <eblake@redhat.com>
lib/autoconf/general.m4
lib/autoconf/libs.m4
lib/autoconf/programs.m4
lib/m4sugar/m4sh.m4
tests/m4sh.at