autoconf
[Top][All Lists]
Advanced

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

Re: m4 macro whose name depends on a a variable


From: Vincent Torri
Subject: Re: m4 macro whose name depends on a a variable
Date: Mon, 10 Nov 2008 19:22:27 +0100 (CET)


Hey,

On Mon, 10 Nov 2008, Eric Blake wrote:

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]))

thank you for the fix. I've sen the second mail about the correct call.

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)

I decided to use the second one as I need to suppot old autoconf macros.


   [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).

That argument is just a string i need to pass as lower case. Here is the macro for the libjpeg detection:

dnl use : EVAS_CHECK_LOADER_DEP_JPEG(loader[, ACTION-IF-FOUND[, 
ACTION-IF-NOT-FOUND]])
AC_DEFUN([EVAS_CHECK_LOADER_DEP_JPEG],
[

have_dep="no"
evas_image_loader_[]$1[]_cflags=""
evas_image_loader_[]$1[]_libs=""

AC_CHECK_HEADER([jpeglib.h],
   [
    have_dep="yes"
    evas_image_loader_[]$1[]_cflags=""
    evas_image_loader_[]$1[]_libs="-ljpeg"
   ]
)

AC_SUBST([evas_image_loader_$1_cflags])
AC_SUBST([evas_image_loader_$1_libs])

if test "x${have_dep}" = "xyes" ; then
  ifelse([$2], , :, [$2])
else
  ifelse([$3], , :, [$3])
fi

])

some notes:

1) i do not check libjpeg.a intetionaly, as i suppose that if jpeglib.h exists, then the static lib is available too. I can add a check on that lib tough.

2) Is the 'ifelse' correct or should I use also m4 macros ?

So, should I use [DOWN] or just DOWN ?

Anyway, it works very well, now. Thank you for your answers

Vincent




reply via email to

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