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: Zack Weinberg
Subject: Re: Using "m4_bpatsubst/patsubst" to remove a string from a variable
Date: Mon, 6 Jun 2016 09:31:14 -0400

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]