summaryrefslogtreecommitdiff
path: root/lib/m4sugar/m4sh.m4
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2014-07-17 14:52:57 -0600
committerEric Blake <eblake@redhat.com>2014-07-17 15:40:12 -0600
commit0443fa8d4320b3f42a7774c470cc40921cf74d00 (patch)
treeab26c21d3b6584a3a9f68dad77b95622bd125e2c /lib/m4sugar/m4sh.m4
parent5dcda009ef77b657e5a78ad88774fe50c5088abc (diff)
downloadautoconf-0443fa8d4320b3f42a7774c470cc40921cf74d00.tar.gz
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>
Diffstat (limited to 'lib/m4sugar/m4sh.m4')
-rw-r--r--lib/m4sugar/m4sh.m415
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 91cdeac5..a94999e7 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -618,9 +618,11 @@ done[]_m4_popdef([$1])])
# AS_IF(TEST1, [IF-TRUE1 = :]...[IF-FALSE = :])
# ---------------------------------------------
# Expand into
-# | if TEST1; then
+# | if TEST1
+# | then
# | IF-TRUE1
-# | elif TEST2; then
+# | elif TEST2
+# | then
# | IF-TRUE2
# [...]
# | else
@@ -629,7 +631,8 @@ done[]_m4_popdef([$1])])
# with simplifications when IF-TRUE1 and/or IF-FALSE are empty.
#
m4_define([_AS_IF],
-[elif $1; then :
+[elif $1
+then :
$2
])
m4_define([_AS_IF_ELSE],
@@ -639,7 +642,8 @@ m4_define([_AS_IF_ELSE],
])])
m4_defun([AS_IF],
-[if $1; then :
+[if $1
+then :
$2
m4_map_args_pair([_$0], [_$0_ELSE], m4_shift2($@))]dnl
[fi[]])# AS_IF
@@ -1389,7 +1393,8 @@ _ASBOX])
# Remove all contents from within DIR, including any unwritable
# subdirectories, but leave DIR itself untouched.
m4_define([_AS_CLEAN_DIR],
-[if test -d $1; then
+[if test -d $1
+then
find $1 -type d ! -perm -700 -exec chmod u+rwx {} \;
rm -fr $1/* $1/.[[!.]] $1/.??*
fi])