Solved

Setting and using environment variables when building RPMs

Posted on 2004-10-28
235 Views
Last Modified: 2013-12-06
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:

%install
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

%files
/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 ?
0
Question by:Anonymouslemming
    7 Comments
     
    LVL 38

    Expert Comment

    by:wesly_chen
    Hi,

       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.

    Wesly
    0
     
    LVL 5

    Author Comment

    by:Anonymouslemming
    That doesn't appear to work. It still works in the %install section, but it still does not work in the %files section.
    0
     
    LVL 5

    Expert Comment

    by:pbhj
    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!!

    :0)>
    0
     
    LVL 5

    Author Comment

    by:Anonymouslemming
    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
    %kernelver

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

    Expert Comment

    by:wesly_chen
    Hi,

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

    Wesly
    0
     
    LVL 5

    Author Comment

    by:Anonymouslemming
    If this question is PAQ-d, will it become a featured solution ?
    0
     
    LVL 1

    Accepted Solution

    by:
    PAQd, 445 points refunded.

    GhostMod
    Community Support Moderator
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
    The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    934 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now