Discussion:
passing a variable to a spec file from rpmbuild command line
r***@amnesia.accessgate.com.sg
2007-11-11 08:23:16 UTC
Permalink
Hi all,

I have a question on passing a variable to a spec file.

Say, for example, I have a feature, and i want to pass information to the spec
file to either enable or disable that feature, so that the spec file can then
pass to configure appropriayte option to enable/disable the cooresponding
feature.

I've seen some references to "--with abc" or "--without abc"

what exactly happens here ? is there a variable that I can reference inside the
spec file to see if "abc" was mentioned with either "--with" or "--without" ?
and how might I reference that variable?

I also have seen the syntax:

%{?variable:1}

I think this is testing "variable" and if the "variable" in question doesn't
exist (hasn't been defined), then return a "1" for the test value. Is this true
? and what gets returned if the variable IS defined? the variables value ?

I've searched high and low all over the net as regards to the intracies of user
defined variables, and the answers to the above questions have been eluding me.
I'd be grateful for answers and/or pointers/urls to documentation.

thanks you, and best rgds,

-Greg Hosler

+---------------------------------------------------------------------+

Please also check the log file at "/dev/null" for additional information.
(from /var/log/Xorg.setup.log)

| Greg Hosler ***@hosler.per.sg |
+---------------------------------------------------------------------+
Jeff Johnson
2007-11-12 08:11:24 UTC
Permalink
Post by r***@amnesia.accessgate.com.sg
Hi all,
I have a question on passing a variable to a spec file.
Say, for example, I have a feature, and i want to pass information to the spec
file to either enable or disable that feature, so that the spec file can then
pass to configure appropriayte option to enable/disable the cooresponding
feature.
I've seen some references to "--with abc" or "--without abc"
what exactly happens here ? is there a variable that I can reference inside the
spec file to see if "abc" was mentioned with either "--with" or "--without" ?
and how might I reference that variable?
What happens is that a macro is conventionally defined.


Here's what happens with "--with abc"


This line in /usr/lib/rpm/rpmpopt-X.Y
rpmb alias --with --define "_with_!#:+ --with-!#:+"


causes a macro "_with_abc" to be defined with value "--with-abc".


The option "--with abc" is exactly the same as typing
--define '_with_abc --with-abc'
Post by r***@amnesia.accessgate.com.sg
%{?variable:1}
I think this is testing "variable" and if the "variable" in question doesn't
exist (hasn't been defined), then return a "1" for the test value. Is this true
? and what gets returned if the variable IS defined? the variables value ?
Not quite. The construct expands to "1" if variable is defined, ""
otherwise.


If you wanted to use the defined value (if it exists) or a default value (if
not),
then that could be done with this (kinda clunky) construct.
%{?variable}%{!?variable:1}


The construct %{?variable} expands variable if defined, otherwise "" is the
value.

Since one is often using 1/0 as TRUE/FALSE with %if statements, then


%if %{?variable:1}0


can be used. The expansion is either "10" or "0" depending on whether
variable is defined (or not),
and the %if is then either TRUE or FALSE.

I've searched high and low all over the net as regards to the intracies of
Post by r***@amnesia.accessgate.com.sg
user
defined variables, and the answers to the above questions have been eluding me.
I'd be grateful for answers and/or pointers/urls to documentation.
You can define any macro you please using --define 'name value' from the
CLI.
Macros are just a means to substitute strings recursively.


Macros are distantly related to how gcc parses CLI arguments. Many ideas
(but not code)
were borrowed and reworked.

hth

73 de Jeff

Loading...