• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Setting and using environment variables when building RPMs

I'm trying to build an RPM from the GPL'd Emulex driver for the LP9002L HBA. The initial build works fine, but I'm trying to change the SPEC file so that the RPM is built for the currently running kernel. This way we don't have to update the SPEC file every time we want to build for a new kernel, just build on a machine running the new kernel.

I tried using the following lines in my spec file:

mkdir -p $RPM_BUILD_ROOT/lib/modules/$KERNEL_VERSION/kernel/drivers/scsi
install -s -m 755 lpfcdd.o $RPM_BUILD_ROOT/lib/modules/$KERNEL_VERSION/kernel/drivers/scsi/lpfcdd.o


I'm then doing
KERNEL_VERSION=`uname -r` rpmbuild -bb specfile

Looking at the output, it appears that the variable is being used in the %install section, but not in the %files section. I say this because I get the following output:
mkdir -p /var/tmp/lpfcdriver-buildroot/lib/modules/2.4.21-20.ELsmp/kernel/drivers/scsi
install -s -m 755 lpfcdd.o /var/tmp/lpfcdriver-buildroot/lib/modules/2.4.21-20.ELsmp/kernel/drivers/scsi/lpfcdd.o
error: File not found: /var/tmp/lpfcdriver-buildroot/lib/modules/$KERNEL_VERSION/kernel/drivers/scsi/lpfcdd.o

RPM build errors:
    File not found: /var/tmp/lpfcdriver-buildroot/lib/modules/$KERNEL_VERSION/kernel/drivers/scsi/lpfcdd.o

Can anyone advise how I could go about fixing this ?
1 Solution

   You probably need to do
export KERNEL_VERSION=`uname -r` ; rpmbuild -bb specfile

   If you don't export the variable, then the value of variable won't pass to the sub-shell.

AnonymouslemmingAuthor Commented:
That doesn't appear to work. It still works in the %install section, but it still does not work in the %files section.
I thought maybe to export, is there someway to dynamically export a global setting, a switch on export that passes it to all shells?

I know that you can set the variable in the shells settings file, eg ~/.bashrc, but dynamically? Basically this could do it for you, but really I haven't a clue!!

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

AnonymouslemmingAuthor Commented:
I have found a solution to this.

Variables in RPMs must be defined by using
%define variablename = %(system command to generate variable)

For example, to define a variable for %kernelver, you would do
%define kernelver = %(uname -r)

Also, when you wish to use variables you must use %variablename. So in my example I need to use

This information was provided by a very helpful person at Red Hat.

   Thanks for the information.  It's very useful. ^_^

AnonymouslemmingAuthor Commented:
If this question is PAQ-d, will it become a featured solution ?
PAQd, 445 points refunded.

Community Support Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now