[Fedora-packaging] Correction to guidelines on %define vs %global

Yaakov Nemoy loupgaroublond at gmail.com
Thu May 21 07:00:55 UTC 2009


2009/5/20 Toshio Kuratomi <a.badger at gmail.com>:
> On 05/20/2009 03:23 AM, Panu Matilainen wrote:
>>
>> Apologies for missing this when the recommendation of %global over
>> %define in Fedora guidelines was being discussed, but better late than
>> never...
>>
>>
>> https://fedoraproject.org/wiki/Packaging/Guidelines#.25global_preferred_over_.25define
>>
>> says "The two macro defining statements behave the same when they are a
>> the top level of rpm's nesting level" but this is not correct:
>>
>> The body of a %global macro is expanded at definition time, whereas the
>> body of a %define is expanded only when used. For many uses it doesn't
>> make any difference but identical they are not, even on top level - for
>> example see the attached example spec:
>>
>> $ rpmbuild -bp macroex.spec 2>/dev/null|grep ^case
>> case1: first - second
>> case2: second - %{xxx}
>>
>> Another example of this difference (in case of parametrized macros):
>> https://bugzilla.redhat.com/show_bug.cgi?id=495658
>>
>
>
> Hi Panu, How does this look?  (Note, I haven't tested any of this code yet
> as I'm running out the door.  I wrote it just from how I understand your
> message and bz#495658).  Also note that I don't know what causes rpm to
> clear the %defines that have been defined.  If you can fill that in that
> would be great.  If it's too complex, we can figure out some way to rephrase
> around it.
>
> """
> %global and %define are both used to define macros inside rpm spec files.
>  We generally prefer using %global over %define.
>
> %define created macros when they are used in nested macro expansions (like
> in  %{!?foo: ... }  constructs theoretically only lasts until the end brace
> (local scope), while %global definitions have global scope. However, rpm
> currently doesn't clear the scope for the macros unless [Accurate
> information needed here]. So %define'd macros often last throughout a spec
> file.  However, when they don't, it's often non-obvious why the spec file is
> failing as the failure is caused by something changing in another part of
> the spec file.

This is somewhat strange behavior to a packager who is not the most skilled developers. Granted RPM spec files are pretty much a programming language, how often do we see it with all these different scoping and evaluation rules? Even more so when we use more complex macros to make the job easier for the packager and hide these details?

> %global has another major difference from %define that can cause problems
> when you first write the macro.  %global is evaluated at the time that it is
> written whereas %define is evaluated separately everytime it occurs in a
> spec file.  As an example, if you do the following in a spec file::

With my limited understanding of RPM internals, in order to maintain consistency, would we need perhaps another form of global? Just asking. What are the cons at looking at a '%macro' macro that will delay evaluation, unlike %global?

-Yaakov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 270 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/fedora-packaging/attachments/20090521/b3992282/attachment.sig>


More information about the Fedora-packaging mailing list