Re: m4 macro whose name depends on a a variable

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

 



-----BEGIN PGP SIGNED MESSAGE-----
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)
> AC_DEFUN([EVAS_CHECK_IMAGE_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"
> 
> EVAS_CHECK_LOADER_DEP_[]UP(

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
versions):

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             ebb9@xxxxxxx
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkYNKIACgkQ84KuGfSFAYC/tQCfbgu7Fmk+b/KHrfNEn1lBUbwh
L6kAn1uyyUyGxASV/md2zTqSWbj+nGtV
=qgI9
-----END PGP SIGNATURE-----


_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux