[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AS_CASE vs case/esac
From: |
NightStrike |
Subject: |
Re: AS_CASE vs case/esac |
Date: |
Thu, 13 Mar 2008 17:35:47 -0400 |
On 3/13/08, Ralf Wildenhues <address@hidden> wrote:
> * NightStrike wrote on Thu, Mar 13, 2008 at 10:07:31PM CET:
> > On 3/13/08, Ralf Wildenhues <address@hidden> wrote:
> > >
> > > AC_INIT
> > > AC_DEFUN([FOO], [echo foo])
> > > AC_DEFUN([BAR], [AC_REQUIRE([FOO])
> > > echo bar])
> > > x=zork
> > > AS_CASE([$x], [y*], [BAR])
> > >
> > > will print 'foo' because FOO will be expanded outside of the AS_CASE.
>
> > I'm trying to follow this logic, but I'm not putting it together in my
> > head. Why isn't the result nothing?
>
> Because it expands to this:
>
> x=zork
> echo foo
> case $x in
> y*)
> echo bar
> ;;
> esac
>
> That is, required macros of macro expansions that happen inside
> defun'ed macros get pushed right before the outermost defun'ed macro.
> <http://www.gnu.org/software/autoconf/manual/html_node/Dependencies-Between-Macros.html>
>
> Here's a slightly more useful example:
>
> # FIND(PATTERN, FILE)
> # -------------------
> AC_DEFUN([FIND],
> [AC_REQUIRE([AC_PROG_GREP])
> $GREP $1 $2
> ])
>
> AS_CASE([$whatever],
> [blabla], [FIND([pattern], [file])])
> FIND([pattern2], [file2])
>
>
> The AC_PROG_GREP will be expanded only once (that's what AC_REQUIRE
> does). If it were expanded inside the case..esac, then if $whatever
> did not match, the second FIND would provoke a syntax error because
> $GREP has not been initialized at that point.
>
> One should not that this also frequently leads to confusion, because
> users don't realize AC_REQUIRE'd macros end up quite a bit earlier than
> they expect.
Ok, now I understand. This is quite an interesting situation. I am
guessing that this is why tools like autoscan or autoupdate will use
actual case/if statements instead of the AS_CASE/IF macros.
The bottom line is that if I stay away from AC_REQUIRE inside of these
macros, there shouldn't ever be a problem, yes?
- AS_CASE vs case/esac, NightStrike, 2008/03/13
- Re: AS_CASE vs case/esac, Ralf Wildenhues, 2008/03/13
- Re: AS_CASE vs case/esac, NightStrike, 2008/03/13
- Re: AS_CASE vs case/esac, Ralf Wildenhues, 2008/03/13
- Re: AS_CASE vs case/esac,
NightStrike <=
- Re: AS_CASE vs case/esac, Ralf Wildenhues, 2008/03/13
- Re: AS_CASE vs case/esac, NightStrike, 2008/03/13
- Re: AS_CASE vs case/esac, Ralf Wildenhues, 2008/03/13
- Re: AS_CASE vs case/esac, NightStrike, 2008/03/13
- Re: AS_CASE vs case/esac, Ralf Wildenhues, 2008/03/13
- Re: AS_CASE vs case/esac, NightStrike, 2008/03/13
- Re: AS_CASE vs case/esac, Ralf Wildenhues, 2008/03/13
- Re: AS_CASE vs case/esac, Ralf Wildenhues, 2008/03/13