autoconf
[Top][All Lists]
Advanced

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

Re: adding a shell function


From: Andreas Schwab
Subject: Re: adding a shell function
Date: Wed, 21 Jan 2004 10:08:51 +0100
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (gnu/linux)

Eric Sunshine <address@hidden> writes:

> (4) m4 strips away [ and ] characters as part of its normal processing, so  
> you need to account for this in your 'sed' expression, as illustrated above  
> with [[ and ]].

It might be better to use @<:@ and @:>@ for this (*note
(autoconf)Quadrigraphs::).

> For especially simple functions like yours, you can often easily define m4  
> macros which get the job done just as well, without worrying about  
> portability problems involved with shell functions.  For instance, you can  
> define an m4 macro ADD_TRAILING_SLASH which performs the same job as your  
> shell function, and you can use it in the same way from configure.ac.  For  
> instance:
>
> # aclocal.m4
> AC_DEFUN([ADD_TRAILING_SLASH],
> [{ case $1 in
>   */) echo "$1" ;;
>   *) echo "$1/" ;;
> esac }
> ])
>
> # configure.ac
> AC_INIT(...)
> HAHA=`ADD_TRAILING_SLASH([$somevar])`
> AC_SUBST([HAHA])
> AC_OUTPUT
>
> Note that, in this case, the $1 is an argument of the m4 macro, and is  
> expanded by m4.  The $1 is not intended for the shell.

In which case you have to watch out for proper shell quoting, since the $1
in "case $1 in" may be replaced by a literal that includes meta
characters.

Andreas.

-- 
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

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