Re: m4 macro expansion problem

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

 



On Wed, Aug 25, 2021, at 10:49 AM, Sébastien Hinderer wrote:
> Sébastien Hinderer (2021/08/25 15:45 +0200):
> > My preference would be to have VERSION generated at the same time than
> > the configure script, i.e. during the autoconf invocation.
> >
> > Is that possible?
> >
> > I started to investigate diversions, but it felt like this kkind of
> > thing is not their real purpose. Is there another way? Perhaps macros
> > are available that let one write some content to a file directly from
> > aclocal.m4?

Unfortunately no, I believe this would require extensions to m4 itself.

Also, you should be aware that autoconf runs m4 over configure.ac several times, and if you use autoreconf or any of the other tools that autoreconf can invoke, they will run m4 over configure.ac several times more.  (I'm guessing you're *not* using aclocal right now since you're talking about writing code directly in aclocal.m4, but perhaps you are using some of the other tools.)  The upshot is that your m4_syscmd invocation, or any use of a hypothetical future m4_open_file extension, will also get run several times.  This is fine (just wastes some cycles) as long as the operation does the exact same thing every time, but it's easy to write code that doesn't *quite* do the same thing every time and then you would have an intermittent bug.

> m4_syscmd([cat > VERSION << END_OF_VERSION_FILE
> PKG_VERSION
> 
> # Some comments about the format of version numbers
> END_OF_VERSION_FILE
> ])
> 
> To some extent it works, i.e. VERSION is indeed generated, but the
> PKG_VERSION macro is not replaced by its value.

m4_syscmd is a primitive, and it doesn't expand its argument, so you need to expand PKG_VERSION first:

m4_syscmd([cat > VERSION << \END_OF_VERSION_FILE
]PKG_VERSION[

# Some comments about the format of version numbers
END_OF_VERSION_FILE
])

zw





[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux