Discussion:
help loading additional macros from file
Tim Mooney
2007-07-03 16:54:03 UTC
Permalink
All-

I need some macro-fu help. I want to (in a spec file)

- test to see if a particular macro is defined.
- if it's not, I would like to
- source/load a file that has additional macro definitions, making
them available in my spec file.
- for extra credit, if the file doesn't exist, exit with an error.


It looks like I can do the test part with something like

%if %{undefined perl_sitelib}

but I'm unsure how to accomplish the "load additional macros from an
external file" part. I would be using this with rpm 4.0.4 (from RHEL 2.1)
all the way up to current rpm.


Thanks,

Tim
--
Tim Mooney ***@dogbert.cc.ndsu.NoDak.edu
Information Technology Services (701) 231-1076 (Voice)
Room 242-J6, IACC Building (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164
Michael Jennings
2007-07-03 20:02:32 UTC
Permalink
On Tuesday, 03 July 2007, at 11:54:03 (-0500),
Post by Tim Mooney
I need some macro-fu help. I want to (in a spec file)
- test to see if a particular macro is defined.
- if it's not, I would like to
- source/load a file that has additional macro definitions, making
them available in my spec file.
- for extra credit, if the file doesn't exist, exit with an error.
It looks like I can do the test part with something like
%if %{undefined perl_sitelib}
%if %{?perl_sitelib:1}0

is probably more portable.
Post by Tim Mooney
but I'm unsure how to accomplish the "load additional macros from
an external file" part. I would be using this with rpm 4.0.4 (from
RHEL 2.1) all the way up to current rpm.
With RPM 4.0.4, I'm pretty sure the answer is "you can't."

Michael
--
Michael Jennings (a.k.a. KainX) http://www.kainx.org/ <***@kainx.org>
n + 1, Inc., http://www.nplus1.net/ Author, Eterm (www.eterm.org)
-----------------------------------------------------------------------
"Sometimes I give myself the creeps. Sometimes my mind plays tricks
on me. It all keeps adding up; I think I'm cracking up. Am I just
paranoid? Am I just stoned?" -- Green Day, "Basket Case"
Tim Mooney
2007-07-03 20:43:34 UTC
Permalink
Post by Michael Jennings
Post by Tim Mooney
It looks like I can do the test part with something like
%if %{undefined perl_sitelib}
%if %{?perl_sitelib:1}0
is probably more portable.
Ok, thanks.
Post by Michael Jennings
Post by Tim Mooney
but I'm unsure how to accomplish the "load additional macros from
an external file" part. I would be using this with rpm 4.0.4 (from
RHEL 2.1) all the way up to current rpm.
With RPM 4.0.4, I'm pretty sure the answer is "you can't."
Can it be done with recent RPM?

Tim
--
Tim Mooney ***@dogbert.cc.ndsu.NoDak.edu
Information Technology Services (701) 231-1076 (Voice)
Room 242-J6, IACC Building (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164
Michael Jennings
2007-07-03 21:13:31 UTC
Permalink
On Tuesday, 03 July 2007, at 15:43:34 (-0500),
Post by Tim Mooney
Can it be done with recent RPM?
Yes.

I forget exactly when it went in, but at least in 4.4.9 you can do
something like this:

Source10: mymacros
%{load:%{SOURCE10}}

Michael
--
Michael Jennings (a.k.a. KainX) http://www.kainx.org/ <***@kainx.org>
n + 1, Inc., http://www.nplus1.net/ Author, Eterm (www.eterm.org)
-----------------------------------------------------------------------
"I am I am I said I'm not myself, I'm not dead, and I'm not for sale.
So keep your bankroll lottery eat your salad day deathbed motor-
cade." -- Stone Temple Pilots, "Trippin' on a Hole in a Paper Heart"
Tim Mooney
2007-07-03 21:55:02 UTC
Permalink
Post by Michael Jennings
On Tuesday, 03 July 2007, at 15:43:34 (-0500),
Post by Tim Mooney
Can it be done with recent RPM?
Yes.
I forget exactly when it went in, but at least in 4.4.9 you can do
Source10: mymacros
%{load:%{SOURCE10}}
Thanks.

Tim
--
Tim Mooney ***@dogbert.cc.ndsu.NoDak.edu
Information Technology Services (701) 231-1076 (Voice)
Room 242-J6, IACC Building (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164
Paul Nasrat
2007-07-04 07:39:47 UTC
Permalink
Post by Tim Mooney
All-
I need some macro-fu help. I want to (in a spec file)
- test to see if a particular macro is defined.
- if it's not, I would like to
- source/load a file that has additional macro definitions, making
them available in my spec file.
- for extra credit, if the file doesn't exist, exit with an error.
It looks like I can do the test part with something like
%if %{undefined perl_sitelib}
Does something like this work for you:

%{!?foo: %{expand: %%include /path/to/foo}}

Where /path/to/foo contains a bunch of %global foo bar type definitions,
you can include from the build root or a SourceN too

Paul
Tim Mooney
2007-07-05 18:39:05 UTC
Permalink
Post by Paul Nasrat
Post by Tim Mooney
All-
I need some macro-fu help. I want to (in a spec file)
- test to see if a particular macro is defined.
- if it's not, I would like to
- source/load a file that has additional macro definitions, making
them available in my spec file.
- for extra credit, if the file doesn't exist, exit with an error.
It looks like I can do the test part with something like
%if %{undefined perl_sitelib}
%{!?foo: %{expand: %%include /path/to/foo}}
Where /path/to/foo contains a bunch of %global foo bar type definitions,
you can include from the build root or a SourceN too
Yup, works perfectly, even on RHEL 2.1.

Thanks for the tip!

Tim
--
Tim Mooney ***@dogbert.cc.ndsu.NoDak.edu
Information Technology Services (701) 231-1076 (Voice)
Room 242-J6, IACC Building (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164
Jeff Johnson
2007-07-05 18:51:44 UTC
Permalink
Post by Tim Mooney
Yup, works perfectly, even on RHEL 2.1.
Thanks for the tip!
All that is really needed is
SourceN: mymacros
...
%if %{!? perl_sitelib:1}0
%(cat %SOURCEn)
%endif
where mymacros contains
%define foo bar
...

That improves on %include (which is hardly ever used), and
preserves the pretense of reproducible builds.

73 de Jeff

Loading...