Expanding RPM macros

Panu Matilainen pmatilai at laiskiainen.org
Tue Nov 4 08:13:53 UTC 2014

On 11/02/2014 09:33 PM, Peter Lemenkov wrote:
> Hello All!
> One of my packages defines an essential information regarding the API
> (API version string) during the %build stage. It's possible to extract
> this information by invoking a binary from the %{buildroot} with
> certain parameters. I'd love to add this information to the spec-file
> during to Provides. Something like
> Provides: %{name}_api_ver = %(%{buildroot}/bin/app --some params)
> Unfortunately it seems that rpmbuild tries to expand all macros at the
> very initial stage when this binary isn't available yet (not built
> yet). I've tied playing with %{eval: ...} but without any luck.
> Could anyone tell me if it's possible at all? And if possible how
> could this be achieved?

Macros are necessarily expanded at the time of reading the spec, and 
tags such as Provides are processed at that time as well. So the time of 
macro expansion is actually irrelevant here - the provides (and 
requires) declared in the spec are added long before the package is built.

You'll need to use the automatic dependency generator for generating 
dependencies from buildroot contents:

> Also I wonder why even rpmbuild -bs performs macro expansion? I
> thought it should just pack spec-file and sources/patches together.

Macro expansion is a very integral part of spec parsing, it cannot be 
turned off. Also its a rare package where even sources and patches can 
addressed be done without expanding macros.

	- Panu -

More information about the Rpm-list mailing list