autoconf
[Top][All Lists]
Advanced

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

Re: Using "m4_bpatsubst/patsubst" to remove a string from a variable


From: Manuel Bachmann
Subject: Re: Using "m4_bpatsubst/patsubst" to remove a string from a variable
Date: Mon, 6 Jun 2016 19:14:02 +0200

Hi Zack, and many thanks for the thorough answer !

> This is an easy mistake to make. Remember that configure.ac is an M4
> script, that generates a shell script, configure.  When configure is
> run, M4 is no longer around to help out.

You're right ; shell variables are only available when running
"./configure", when it is far too late... it is so obvious now, that I'm
facepalming myself.

> So you can't mix M4 and shell like the above.  Instead, you can do it all
in M4:
> or you can do it all

Yes, since it is a ad-hoc solution and it is a lot easier to read, shell
syntax is definitely better for my usecase.

I've just implemented it by using AS_ECHO, and a grep/sed logic as you
suggested. Seems to work fine.

Thanks a lot Zack !

Regards,

*Manuel Bachmann, Graphics & Multimedia Engineer www.iot.bzh
<http://iot.bzh> *


2016-06-06 15:31 GMT+02:00 Zack Weinberg <address@hidden>:

> On Mon, Jun 6, 2016 at 5:17 AM, Manuel Bachmann <address@hidden>
> wrote:
> > Hi folks,
> >
> > I am trying to use the "m4_bpatsubst" and/or "patsubst" macros (which I
> > found documented here : [1] [2]), to remove a string from a variable in
> my "
> > configure.ac" ; and pass it to "Makefile.am", so it ends up in final
> > "Makefile".
> >
> > I was able to get some kind of output, with this in "configure.ac" :
> >
> > VAR="text1 text2"
> > VAR2=m4_bpatsubst("$VAR", "text1")
> > AC_SUBST(VAR2)
>
> This is an easy mistake to make. Remember that configure.ac is an M4
> script, that generates a shell script, configure.  When configure is
> run, M4 is no longer around to help out.  (This is an intentional
> design decision; it was, many years ago, not considered appropriate to
> require people to have M4 available when running configure.)
>
> So you can't mix M4 and shell like the above.  Instead, you can do it all
> in M4:
>
> m4_define([VAR],[text1 text2])
> m4_define([VAR2],[m4_bpatsubst([VAR1],[text1],)
> [VAR2=]VAR2
> AC_SUBST([VAR])
>
> or you can do it all in shell:
>
> VAR="text1 text2"
> VAR2="`AS_ECHO("$VAR") | sed 's/text1//g'`" dnl yes, the nested double
> quotes are correct
> AC_SUBST([VAR2])
>
> You probably want to do it all in shell.  The only situation I can
> think of where you would want the all-in-M4 version is if you were
> implementing a new Autoconf macro, VAR came from one of its arguments,
> and it was guaranteed to be literal text - not the result of any
> configure-time processing - in the caller.
>
> zw
>


reply via email to

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