Trying to understand if the following patch is needed in libreplace

Timur I. Bakeyev timur at
Wed Feb 13 08:20:47 MST 2013

Hi, Richard!

I see it defined in autoconf-2.69/m4sugar/m4sh.m4:

# --------------------
# Transform EXPRESSION into a valid shell variable name.
# sh/m4 polymorphic.
# Be sure to update the definition of `$as_tr_sh' if you change this.

It then used in this macro in libreplace:

dnl check if the prototype in the header matches the given one
[AC_CACHE_CHECK([for prototype $1], AS_TR_SH([ac_cv_c_prototype_$1]),
                    eval AS_TR_SH([ac_cv_c_prototype_$1])=yes
                    eval AS_TR_SH([ac_cv_c_prototype_$1])=no
AS_IF([eval test \$AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])

It happened to be used only in few places and seems that no one paid
attention to the results(i.e. bogus behaviour of the macro gave appropriate
results, as it happens a lot in autoconf).

I was puzzled  why function, which exists in FreeBSD wasn't recognized
right an that brought me down to this macro and resulting SH code it

AC_VERIFY_C_PROTOTYPE([struct group *getgrent_r(struct group *src, char
*buf, int buflen)]

For example generates:

if ac_fn_c_try_compile "$LINENO"; then :

                    eval `$as_echo "ac_cv_c_prototype_struct group
*getgrent_r(struct group *src, char *buf, int buflen)" | $as_tr_sh`=yes


                    eval `$as_echo "ac_cv_c_prototype_struct group
*getgrent_r(struct group *src, char *buf, int buflen)" | $as_tr_sh`=no

rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

eval ac_res=\$`$as_echo "ac_cv_c_prototype_struct group *getgrent_r(struct
group *src, char *buf, int buflen)" | $as_tr_sh`
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }

if test $`$as_echo "ac_cv_c_prototype_struct group *getgrent_r(struct group
*src, char *buf, int buflen)" | $as_tr_sh` = yes; then :

$as_echo "#define SOLARIS_GETGRENT_R 1" >>confdefs.h


Please note the last 'if' statement. It useless, as it produces smth.
like(it's another function snippet but they all the same):

+ test
= yes

We get the name of the variable right, but we need to get it's value to see
if it is "yes' or 'no'. Hence we need to evaluate the obtained expression:

+ eval test
= yes
+ test yes = yes

The bottom like is - WAF may be hard to grasp, but at least it won't let
you silently stay with bogus code like this.

With regards,
Timur Bakeyev.

On Tue, Feb 12, 2013 at 9:16 PM, Richard Sharpe <realrichardsharpe at
> wrote:

> Hi folks,
> I have come across the following patch from Timur in the FreeBSD ports
> collection:
> rsharpe-bsd# more patch-lib__replace__libreplace_macros.m4
> --- ./lib/replace/libreplace_macros.m4.orig     2011-10-12
> 01:38:14.000000000 +0200
> +++ ./lib/replace/libreplace_macros.m4  2011-10-12 01:39:36.000000000 +0200
> @@ -298,7 +298,7 @@
>                 eval AS_TR_SH([ac_cv_c_prototype_$1])=no
>         ])
>  )
> -AS_IF([test $AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])
> +AS_IF([eval test \$AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])
>  ])
> Where is AS_TR_SH defined? Is it possible that we actually need the
> change more generally?
> --
> Regards,
> Richard Sharpe
> (何以解憂?唯有杜康。--曹操)

More information about the samba-technical mailing list