Mailinglist Archive: opensuse-packaging (284 mails)

< Previous Next >
Re: [opensuse-packaging] Where do the macros "BUILD_ORIG" and "BUILD_ORIG_ADDON" come from?
On 02/01/2011 01:58 PM, Tejas Guruswamy wrote:
On 01/02/11 10:37, Dave Plater wrote:

On 01/31/2011 09:16 PM, Tejas Guruswamy wrote:

%{?macro} expands to the value of %macro if %macro is defined, and ""
(empty string) if it isn't.
similarly %{?macro:foo} expands to "foo" if %macro is defined.
and the opposite is %{!?macro:bar} which expands to "bar" if %macro
isn't defined.
These can be nested.

I spent quite a few days googling and researching, which lead to me
spending quite a while on fedora's packaging as well, the openSUSE
packaging portal is improving day by day btw.
The bookmark (it was me who changed
the old wiki to point to the snapshot version) I've had for a while
since my first blender maintainance and never found anything about "?".
Your explanation explains why rpmlint complains about "%if %suse_version
<= 1020" but doesn't complain about "%if 0%{?suse_version} <= 1020" rpm
in <= 1020 most probably won't see the macro at all?

Yeah, max-rpm is missing info on macro conditionals. But to answer what
seems to be your question.
On a suse distro,
%if 0%{?suse_version} <= 1020
expands to (e.g. on 11.1)
%if 01110 <= 1020
giving the expected result - false (leading zero is ignored for
arithmetic comparison)

But on a non-suse distro,
%if 0%{?suse_version} <= 1020
expands to
%if 0 <= 1020
so no errors, but it will be true! Maybe not what you expected. So be
careful! The behaviour on non-suse distros could depend on the direction
of the comparison (greater than/less than)!

A (slightly unwieldy) construct which fixes this to be true ONLY on
suse-distros satisfying the version requirement, and not on anything else:
%if %{?suse_version:%{suse_version} <= 1020} %{!?suse_version:0}
but most people don't bother to check for this.

The invert "!" next
to "?" is a new one, I would only use "!" in "%if ! %{with foo}" does it
invert when used inside the braces to the left of "?"? I don't
understand the usage of the colon ":" inside the macro either, I've seen
it used but it doesn't seem to do anything except obfuscate the macro a
bit more than normal.

The colon is very useful. Try it:
> rpm --eval '%{?suse_version:foo} %{!?blah:bar}'
# foo bar

where ofc %suse_version is defined, and %blah is not defined.

The construct %{?foo:bar} can be thought of as a contracted form of the
if-statement, usable on one line and as an argument to something else.
if %{foo}
bar <--- note this could be a macro too (
%{?foo:%{?bar:blah}} is fine, it's just like nested if's )
"" (empty string)

and conversely %{!?foo:bar} is like
if ! %{foo} (not foo)
"" (empty string)

It's a little bit like the C-style ternary operator: ( cond ? foo : bar
) is equivalent to if(cond); then foo; else bar

Last but not least, like a small boy asking his mother where babies come
from, where is "BUILD_ORIG" and "BUILD_ORIG_ADDON" defined, I still
haven't tried an online build %dump but I've looked everywhere else,
including a local factory build with %dump. When I first found the use
of %bcond I could find /usr/lib/rpm /etc/rpm grep and I found a very
good explanation (I was able to fix the original packagers use of it)
but the only answer I've had for the BUILD macros (are they macros?) is
it's there, which to me is the same as "the stork drops them down the

If they are being used without %'s, i.e. "BUILD_ORIG" and not
"%BUILD_ORIG", then they are shell environment variables, not rpm
macros. No idea where the default would come from in that case.
If they are macros, it seems the packager is expected to define it on
the command-line when running rpmbuild (see the --define option) or in
his ~/.rpmmacros. On the OBS it could be defined in a prjconf. Which
means in the default state it is undefined. See Ludwig's earlier answer.

I now fully understand the use of "?".
Thanks very much, knowledge is my heroin.
Dave P



I'll experiment with "!" and ":" later on the matter of "BUILD_ORIG"
it's not defined and it's used as a macro ie. taken from
"gstreamer-0_10-plugins-bad.spec" :
Provides: patched_subset
Provides: %{name}-orig-addon = %{version}
Obsoletes: %{name}-orig-addon

And with rpmbuild -D 'BUILD_ORIG 1' you get the unpatched build. It must
be an environment variable defined by rpm, I must try a "set|grep
BUILD_ORIG" inside a spec file
rpm --eval="BUILD_ORIG 1" and rpm --querytags|grep BUILD_ORIG shows
nothing. Anyway enough time spent, it works which is what really
matters, time to put it on the back burner and I will find it later.
Dave P
To unsubscribe, e-mail: opensuse-packaging+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse-packaging+help@xxxxxxxxxxxx

< Previous Next >