RPM Community Forums

Mailing List Message of <rpm-users>

Re: Evaluating macros defined in specfiles

From: Jeff Johnson <n3npq@mac.com>
Date: Sun 03 May 2009 - 01:30:09 CEST
Message-id: <78CB2074-4251-4C5A-98FE-AFA1CE1A8565@mac.com>

On May 2, 2009, at 6:38 PM, Eric MSP Veith wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello list,
>
> if one defines a macro in a spec file, is there any way to evaluate  
> it from
> a process started during/by rpmbuild?
>
> Background is: I wrote a little Perl script that translates macros  
> in files
> for me. I use this for config or init files I supply with packages  
> and which
> sometimes need a full path, and since I don't want to explicility  
> use sed
> every time, I wrote this convenience script. I basically have lines  
> like
>
> "%{__cat} '%{SOURCE1}' | %{__m2rpath} > somefile'
>
> in my specfile, with '%{__m2rpath}' beeing my utility. It does  
> nothing more
> than scanning each line for something that looks like a RPM macro  
> definition
> (m/(%{\w+})/) and runs "rpm -E $1" against it. This works, of  
> course, well
> with macros that are known to the whole build system, but fails with  
> new
> definitions made in the spec file.
>
> Is there any way to catch those, too?
>

Hmmm, I'm not quite sure what you are asking ... BUT ...

you seem to want macros expanded in a text file.

but you also want definitions from the spec file.

which means that rpm -E isn't the right approach because its
a whole different process context.

you can expand macros in another file (there will be limits on buffer  
size ~8192b)
if you do

%{expand:%(cat %{SOURCE1})}

All that %{expand:...} does is continue expansion from the begin  
point, not the
end point, of the text added by %(cat %{SOURCE1}).

So that achieves the expansion in the current process with the current  
defines.

You can likely do something like (but it will be dependent on buried  
double quotes etc)

echo "%{expand:%(cat %{SOURCE1})}" > somefile

If you think a bit you might be able to use a construct like
    cat << GO_SYSIN_DD > somefile
    ...
    GO_SYSIN_DD
to avoid the embedded quote failures.

hth

73 de Jeff
Received on Sun May 3 02:31:07 2009
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.