autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] more cleanup before adding shell functions


From: Eric Blake
Subject: Re: [PATCH] more cleanup before adding shell functions
Date: Thu, 9 Oct 2008 15:11:08 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Paolo Bonzini <bonzini <at> gnu.org> writes:

> 
> This instroduces _AS_ME_PREPARE, which is needed to properly order
> the initialization of as_me after the definition of shell functions.
> Otherwise, _AS_BASENAME_PREPARE places shell functions in M4SH-INIT-FN,
> and setting as_me in AS_SHELL_SANITIZE fails miserably if basename is
> not present in the system.

Hmmm.  Since AS_SHELL_SANITIZE does not use $as_me, maybe a better approach is 
to make _AS_ECHO_LOG, AS_MESSAGE, _AS_LINENO_PREPARE, and AS_TMPDIR (ie. the 
actual clients of $as_me) be the ones that AS_REQUIRE([_AS_ME_PREPARE]).  I 
guess I'm just a bit leery of seeing a macro generate text that is output in a 
later diversion without any guarantee that the text is needed by the rest of 
the script; in general, it seems like it should be possible to write an m4sh 
input file that does not call AS_PREPARE, and instead uses AS_REQUIRE for lazy 
initialization of only the *_PREPARE features it uses, for a smaller/faster 
output file.

> 
> In addition, _AS_PREPARE macros are sorted correctly, and AS_PREPARE is
> modified to use AS_REQUIRE properly.

This part looks correct.

> 
> I'm going to push this shortly as well.
> 
> Paolo
> 
> 2008-10-09  Paolo Bonzini  <bonzini <at> gnu.org>
> 
>       * m4sugar/m4sh.m4 (AS_SHELL_SANITIZE): Delay setting as_me
>       until the M4SH-INIT diversion using _AS_ME_PREPARE.
>       (_AS_PREPARE): Invoke _AS_EXPR_PREPARE before _AS_BASENAME_PREPARE
>       and _AS_DIRNAME_PREPARE, and _AS_BASENAME_PREPARE and _AS_ME_PREPARE
>       before _AS_LINENO_PREPARE.
>       (AS_PREPARE): Include all the AS_REQUIREs manually.
>       (_AS_ME_PREPARE): New.
>       (_AS_LINENO_PREPARE): Use m4_defun.

I'm okay if you push as is (I can write the followup that shuffles around who 
calls AS_REQUIRE([_AS_ME_PREPARE], if you don't get to it before you push).

Now, some rambling thoughts on the direction that we should head with 
basename/dirname (unrelated to whether the patch in this mail should be 
applied, but affects later patches in your series):

> +# _AS_ME_PREPARE
> +# --------------
> +# Define $as_me to the basename of the executable file's name.
> +m4_defun([_AS_ME_PREPARE],
> +[AS_REQUIRE([_AS_BASENAME_PREPARE])dnl
> +as_me=`AS_BASENAME("$[0]")`

Here's where a rewrite of AS_BASENAME might be useful to avoid forks.  As 
written, this spawns a subshell no matter what.  But if we want to use XSI 
parameter expansion on the shells that provide it, then the libtool solution is 
to make the function assign to a known variable, which can then be copied into 
the user's variable without ``.  Something like:

as_func_basename ()
{
  as_func_basename_result="${1##*/}"
}
as_func_basename "$0"
as_me=$as_func_basename_result

Note that with existing semantics, outputting something like:

echo "AS_BASENAME(["$[]0"]"

is not safe (it expands to the nonportable "`""`"), so if AS_BASENAME is going 
to be used inside command substitution, it is only useful in contexts where the 
command substitution does not need to be surrounded in "" (variable assignment, 
and the word after case).

Since AS_BASENAME is undocumented, and since it is most useful in variable 
assignments, perhaps it is time to redefine it as follows (untested)

# AS_BASENAME(var, name, [ext])
# -----------------------------
# Compute the basename of NAME, with trailing EXT removed, and assign
# the result to the shell variable VAR.
m4_defun([AS_BASENAME],
[AS_REQUIRE([_AS_BASENAME_PREPARE])dnl
as_func_basename "$2"m4_ifval([$3], [ "$3"])
$1=$as_func_basename_result
])

where as_func_basename is appropriately defined in _AS_BASENAME_PREPARE, and 
includes any `` necessary for shells that lack XSI parameter expansion.

In other words, change the semantics of AS_BASENAME to make assigning the 
result to a variable part of the macro's job, at which point clients must no 
longer use AS_BASENAME inside command substitution, and a fork or two is 
avoided in decent shells.  Carrying on in the example, it would mean:

m4_defun([_AS_ME_PREPARE]
[AS_BASENAME([as_me], ["$[0]"])
])

-- 
Eric Blake






reply via email to

[Prev in Thread] Current Thread [Next in Thread]