[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AS_CASE vs case/esac
From: |
Ralf Wildenhues |
Subject: |
Re: AS_CASE vs case/esac |
Date: |
Thu, 13 Mar 2008 22:25:46 +0100 |
User-agent: |
Mutt/1.5.17+20080114 (2008-01-14) |
* 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.
Cheers,
Ralf
- 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 <=
- 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, 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