Mailinglist Archive: opensuse-packaging (85 mails)

< Previous Next >
Re: [opensuse-packaging] Variables in %Files Section
  • From: Reinhard Max <max@xxxxxxx>
  • Date: Tue, 3 Jun 2008 16:01:08 +0200 (CEST)
  • Message-id: <alpine.LNX.1.10.0806031546360.5016@xxxxxxxxxxxxxx>

besides the fact that is seems sort of wrong to embed the host name of the building machine into an RPM, as others explained already, let me try to explain what's going on:

On Tue, 3 Jun 2008 at 15:17, Andre Hübner wrote:

if there is no way to use my variable [...]

What you have is not a variable, it is a macro. The expansion of the macro is the verbatim string "`/bin/hostname -s`" and not the output of this command as you seem to expect.

why %files is different to %install etc?

Because %install (as well as %prep, %build, %check and %clean) are shell scripts, but %files is just a list of file names. RPM performs macro and glob expansion on the files list, but no variable or command substitution.

Now when processin the spec file RPM first replaces %{HOSTNAME_SHORT} by the string

`/bin/hostname -s`

in all sections and then runs the resulting shell scripts or processes the files list, respectively. It is the shell running the scripts who then interprets the backticks and replace the commands by their output.

The solution for your question (though probably not the right solution for packaging your package - I am repeating myself and others here) would be to let RPM run the command once and set the macro to the command's output rather than the command string:

%define HOSTNAME_SHORT %(/bin/hostname -s)

To unsubscribe, e-mail: opensuse-packaging+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse-packaging+help@xxxxxxxxxxxx

< Previous Next >