Go to file
Zack Weinberg fd633e92cb
AS_IF: Handle else clause being empty after macro expansion (#110369)
AS_IF can emit a syntactically invalid shell if-then-else,

  if CONDITION
  then :
    # ...
  else
  fi

when its IF-FALSE argument consists of macros that don’t produce any
shell code.  This was a documented limitation in AS_IF, but it’s a bad
limitation to have, because macros that *used* to expand to shell
commands might start expanding to nothing in future releases.  For
instance, this broke the libzmq configure script, which did

  AC_PROG_CC
  AX_CHECK_COMPILE_FLAG([-std=gnu11],
    [CFLAGS+=" -std=gnu11"],
    [AC_PROG_CC_C99])

Perfectly valid in 2.69, but in 2.70 AC_PROG_CC_C99 doesn’t produce
any shell code and the script crashes.

We had that limitation for good reason: we can’t just put ‘:’ at the
beginning of the else-clause, like we do for the then-clause, because
that would clobber $? and the IF-FALSE commands might want to inspect
it.  (This doesn’t matter for the then-clause, because $? is always
zero at the beginning of a then-clause anyway.)  The simplest and
least inefficient shell construct I can find that works in this
context is a shell function that does ‘return $?’.  Due to awkward
M4sh initialization ordering constraints (AS_IF gets used before we
can safely use shell functions) an indirection through a shell
variable is necessary.  The structure of a m4sh script is now

  #! /bin/sh
  ## M4sh Initialization
  as_nop=:

  ...
  ## M4sh Shell Functions

  as_fn_nop () { return $?; }
  as_nop=as_fn_nop
  ...

and AS_IF emits

  if CONDITION
  then :
    # ...
  else $as_nop
    # ...
  fi

The uses of AS_IF that appear before the beginning of the M4sh Shell
Functions section are all under our control and they don’t need to
look at $?.

If anyone has a better idea for how to make this work I will be glad
to hear it.

Fixes bug #110369.

* lib/m4sugar/m4sh.m4
  (_AS_IF_ELSE): When $1 is nonempty, invoke _AS_EMPTY_ELSE_PREPARE.
  Emit $as_nop at beginning of else clause.
  (_AS_BOURNE_COMPATIBLE): Initialize as_nop to ‘:’.
  (_AS_EMPTY_ELSE_PREPARE): New macro which emits a definition of
  as_fn_nop and resets as_nop to as_fn_nop.
  (AS_PREPARE, _AS_PREPARE): Invoke _AS_EMPTY_ELSE_PREPARE.
  (_AS_UNSET_PREPARE): Tweak white space.

* tests/m4sh.at (AS_IF and AS_CASE): Test AS_IF’s IF-FALSE argument
  being empty after macro expansion.

* doc/autoconf.texi (AS_IF): Remove warning about use with
  ‘run-if-false’ argument empty after macro expansion.
2020-11-15 14:16:16 -05:00
bin autom4te: replace output file atomically (#110305) 2020-11-10 09:42:58 -05:00
build-aux make fetch 2020-11-09 15:24:53 -05:00
doc AS_IF: Handle else clause being empty after macro expansion (#110369) 2020-11-15 14:16:16 -05:00
lib AS_IF: Handle else clause being empty after macro expansion (#110369) 2020-11-15 14:16:16 -05:00
m4 make fetch 2020-09-03 12:08:31 -04:00
man Generate manpages directly from source code. 2020-08-21 16:23:32 -04:00
tests AS_IF: Handle else clause being empty after macro expansion (#110369) 2020-11-15 14:16:16 -05:00
.gitattributes maint: don't sync elisp-comp or missing from gnulib 2012-06-27 16:59:21 -06:00
.gitignore Check in install-sh as synced from automake (#110368) 2020-11-09 13:51:20 -05:00
.prev-version maint: post-release administrivia 2012-04-24 21:06:32 -06:00
.x-update-copyright
AUTHORS maint: make update-copyright 2020-01-01 11:45:50 -08:00
BUGS BUGS: Remove mention of old shells lacking functions. 2020-08-28 16:44:59 -04:00
cfg.mk Rewrite fetch.sh in Perl. 2020-09-11 14:51:00 -04:00
ChangeLog.0 Prefer HTTPS to FTP and HTTP 2017-09-16 17:48:51 -07:00
ChangeLog.1 Prefer HTTPS to FTP and HTTP 2017-09-16 17:48:51 -07:00
ChangeLog.2 Prefer HTTPS to FTP and HTTP 2017-09-16 17:48:51 -07:00
ChangeLog.3 maint: update URLs 2017-09-23 12:49:23 -07:00
configure.ac Add NetBSD /bin/sh to the -n whitelist. 2020-08-26 15:08:26 -04:00
COPYING Update links in COPYING, COPYINGv3, and COPYING.EXCEPTION. 2020-07-10 16:43:22 -04:00
COPYING.EXCEPTION Update links in COPYING, COPYINGv3, and COPYING.EXCEPTION. 2020-07-10 16:43:22 -04:00
COPYINGv3 Update links in COPYING, COPYINGv3, and COPYING.EXCEPTION. 2020-07-10 16:43:22 -04:00
GNUmakefile Partially revert e54e3f90: restore use of $(MAKE) in error message. 2020-08-04 08:46:59 -04:00
HACKING Update release advice 2020-06-29 17:08:27 -07:00
maint.mk make fetch 2020-06-29 17:08:26 -07:00
Makefile.am Generate manpages directly from source code. 2020-08-21 16:23:32 -04:00
NEWS AS_IF: Handle else clause being empty after macro expansion (#110369) 2020-11-15 14:16:16 -05:00
README maint: make update-copyright 2020-01-01 11:45:50 -08:00
README-alpha maint: make update-copyright 2020-01-01 11:45:50 -08:00
README-hacking * doc/autoconf.texi: Fix mishandling of `. 2020-07-13 12:55:19 -07:00
THANKS maint: make update-copyright 2020-01-01 11:45:50 -08:00
TODO * TODO: Add -Werror support. 2020-08-06 12:28:40 -07:00

-*- text -*-

Autoconf

Autoconf is an extensible package of M4 macros that produce shell
scripts to automatically configure software source code packages.
These scripts can adapt the packages to many kinds of UNIX-like
systems without manual user intervention.  Autoconf creates a
configuration script for a package from a template file that lists the
operating system features that the package can use, in the form of M4
macro calls.

Producing configuration scripts using Autoconf requires GNU M4 and
Perl.  You should install GNU M4 (version 1.4.6 or later is required;
1.4.14 or later is recommended) and Perl (5.006 or later) before
configuring Autoconf, so that Autoconf's configure script can find
them.  The configuration scripts produced by Autoconf are
self-contained, so their users do not need to have Autoconf (or GNU
M4, Perl, etc.).

You can get GNU M4 here:

https://ftp.gnu.org/gnu/m4/

The file INSTALL should be distributed with packages that use
Autoconf-generated configure scripts and Makefiles that conform to the
GNU coding standards.  The package's README can just give an overview
of the package, where to report bugs, and a pointer to INSTALL for
instructions on compilation and installation.  This removes the need
to maintain many similar sets of installation instructions.

Be sure to read BUGS and INSTALL.

Mail suggestions to autoconf@gnu.org, report bugs to
bug-autoconf@gnu.org, and submit patches to autoconf-patches@gnu.org.
All changes can be tracked at the read-only autoconf-commit@gnu.org.
Always include the Autoconf version number, which you can get by
running `autoconf --version'.  Archives of bug-autoconf@gnu.org can be
found in <https://lists.gnu.org/archive/html/bug-autoconf/>, and
similarly for the other mailing lists.

Licensing

Autoconf is released under the General Public License version 3 (GPLv3+).
Additionally, Autoconf includes a licensing exception in some of its
source files; see the respective copyright notices for how your
project is impacted by including scripts generated by Autoconf, and the
COPYING.EXCEPTION file for the exception in terms of the Additional
Permissions as described in section 7 of GPLv3.

For more licensing information, see
<https://www.gnu.org/licenses/gpl-faq.html> and
<https://www.gnu.org/licenses/exceptions.html>.

For any copyright year range specified as YYYY-ZZZZ in this package
note that the range specifies every single year in that closed interval.

-----

Copyright (C) 1992-1994, 1998, 2000-2017, 2020 Free Software Foundation,
Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.  This file is offered as-is,
without warranty of any kind.