[Top][All Lists]

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

Re: m4 macro whose name depends on a a variable

From: Eric Blake
Subject: Re: m4 macro whose name depends on a a variable
Date: Mon, 10 Nov 2008 06:18:26 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20080914 Thunderbird/ Mnenhy/

Hash: SHA1

According to Vincent Torri on 11/10/2008 12:47 AM:

Hello Vincent,

> I want to write a generic macro that check if different image library
> (libjpeg, libpng, etc...) are available.

> Is it possible to achieve what I want ?

Yes, it is possible.

> dnl use: EVAS_CHECK_IMAGE_LOADER(loader, want_loader)
> [
> pushdef([UP], translit([$1], [a-z], [A-Z]))dnl

Please use m4sugar names; while autoconf currently re-exports raw m4
names, this may trigger a warning in the future (as it is not namespace
clean).  So this should be m4_pushdef, not pushdef.

> pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl

Underquoted - translit does not output its argument with quotes, so if $1
happens to match a macro name, it will be re-expanded.  Also, you may want
to consider using m4_toupper/m4_tolower instead of directly calling
translit.  As in:

pushdef([UP], m4_toupper([[$1]], [a-z], [A-Z]))

> have_evas_image_loader_[]DOWN="no"

Here's your problem.  You are outputting the literal string
EVAS_CHECK_LOADER_DEP_ (which is not defined as a macro), then outputting
the expansion of UP(args) (which is also not defined as a macro).  What
you really need is another layer of expansion that pastes together the two
strings, and expands the pasted result as a single macro name.  There are
several possibilities, pick the one you think looks nicest (and recalling
that some of these macros weren't available/documented in older autoconf

m4_unquote(m4_join([], [EVAS_CHECK_LOADER_DEP_], m4_defn([UP])))(args)

m4_default([], [EVAS_CHECK_LOADER_DEP_]m4_defn([UP]))(args)

>    [DOWN],

Possibly overquoted.  You need to decide whether you want to pass the
lower-case name as the argument, rather than the name of a macro that
expands to the lower-case name (it depends on whether
EVAS_CHECK_LOADER_DEP_* use their $1 as a literal string in investigating
further macro names, or whether waiting until after the child macro is
expanded before converting to lower-case is acceptable).

>    [have_evas_image_loader_[]DOWN="yes"],
>    [have_evas_image_loader_[]DOWN="no"])
> popdef([UP])
> popdef([DOWN])

Again, use m4_popdef.  And in newer autoconf, it is more efficient to pop
two definitions at once:

m4_popdef([UP], [DOWN])

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at
Comment: Using GnuPG with Mozilla -


reply via email to

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