autoconf
[Top][All Lists]
Advanced

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

Re: string manipulation : removing a part of a string


From: Eric Blake
Subject: Re: string manipulation : removing a part of a string
Date: Fri, 15 Jun 2012 17:13:23 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

On 06/15/2012 04:55 PM, Vincent Torri wrote:

> 
> thank you for all the tips ! Just for information, I use
> 
> EFL_CHECK_COMPILER_FLAGS([-Wno-foo -Wbar])

Don't you mean:

EFL_CHECK_COMPILER_FLAGS([efl], [-Wno-foo -Wbar])

> 
> with the code below (i've taken into account your remarks)
> 
> i'm not sure that the m4_foreach below is properly quoted
> 

> AC_DEFUN([EFL_CHECK_COMPILER_FLAG],
> [
> m4_pushdef([UPEFL], m4_translit([[$1]], [-a-z], [_A-Z]))
> m4_pushdef([UP], m4_translit([[$2]], [-a-z], [_A-Z]))
> 
> m4_if(m4_index([$2], [-Wno-]), [0], [m4_pushdef([flagm4],
> [m4_bpatsubst([[$2]], [no-])])], [m4_pushdef([flagm4], [$2])])

This can be shortened:

m4_pushdef([flagm4], m4_bpatsubst([[$2]], [no-]))

since m4_bpatsubst is a no-op if the pattern 'no-' doesn't appear.

> 
> option=flagm4

And since this is the only use of flagm4, and I have now shortened the
computation, you could inline the computation instead of using a temp m4
variable:

option=m4_bpatsubst([[$2]], [no-])

> CFLAGS_save="${CFLAGS}"

Personally, I'd write this as:

CFLAGS_save=$CFLAGS

as "" are unnecessary in a single-word assignment, and {} is unnecessary
when there is nothing after the variable name.  I might not be terse in
my comments, but I try to be terse in my code :)  But what you have is
correct, and I won't fault you if that is your personal shell coding style.

> CFLAGS="${CFLAGS} ${option}"

Here, the "" are necessary, but again the ${} is extra typing.

> 
> UPEFL[_CFLAGS]="${UPEFL[_CFLAGS]} [$2]"
> AC_ARG_VAR(UPEFL[_CFLAGS], [preprocessor flags for $2])
> AC_SUBST(UPFEL[_CFLAGS])

Hope that typo was unintentional (EFL vs. FEL).

> 
> AM_CONDITIONAL([EFL_HAVE]UP, [test "x${have_flag}" = "xyes"])
> 
> m4_popdef([UP])
> m4_popdef([UPEFL])

missing m4_popdef([flagm4]) if you keep the temp m4 variable.

> ])
> 
> dnl Macro that iterates over a sequence of white separated flags
> dnl and that call EFL_CHECK_COMPILER_FLAG() for each of these flags
> dnl
> dnl EFL_CHECK_COMPILER_FLAGS(EFL, FLAGS)
> 
> AC_DEFUN([EFL_CHECK_COMPILER_FLAGS],
> [
> m4_foreach_w([flag], [$2], [EFL_CHECK_COMPILER_FLAG($1, m4_defn([flag]))])

Almost.

m4_foreach_w([flag], [$2],
 [EFL_CHECK_COMPILER_FLAG([$1], m4_defn([flag]))])

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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