Heads-up: %define vs %global in specs

Panu Matilainen pmatilai at laiskiainen.org
Tue Jan 5 16:34:12 UTC 2010


For the impatient:

Starting with today's rawhide, the these kind of constructs in specs 
no longer "work":
 	%{?!foo: %define foo bar}
For the generally desired effect, the above simply becomes:
 	%{?!foo: %global foo bar}

This is already recommended by the Fedora guidelines, but packages which 
haven't been updated to follow the guideline might need revising:
https://fedoraproject.org/wiki/Packaging/Guidelines#.25global_preferred_over_.25define

The longer version:

As explained in the guidelines, %define nested in %{ } block was never 
supposed to work, but due to a longstanding bug in rpm macro engine it has 
seemed to work in many cases... until you do something completely 
unrelated in the spec and it suddenly breaks in mysterious ways. Consider 
this example spec:

--- snip ---
%{!?foo: %define foo bar}
%define dofoo() true

Name:             macroscope
Version:          1.0
Release:          1
License:          Testing
Summary:          Testing macro behavior

%description
%{summary}

%prep
echo 1: %{foo}

%dofoo

echo 2: %{foo}

%files
%defattr(-,root,root)
--- snip ---

You'd probably expect %{foo} to expand to "bar" in both 1 and 2, but due 
to this funny little macro buglet, you'd get this rather non-obvious 
result:
1: bar
2: %{foo}

What you start getting now is:
1: %{foo}
2: %{foo}

...in other words, the %define inside %{} block goes out of scope when the 
block ends, and you probably wanted to use %global there instead.

 	- Panu -




More information about the fedora-devel-list mailing list