Jump to content

RPM-01: How can I recompile SRPMs as normal user?


Recommended Posts

Browse: [About the FAQ Forum] [Table of Contents] [FAQs] [Contribute] [RPM: About RPM usage (urpmi, rpmbuild...)]

 

RPM-01: How can I recompile SRPMs as normal user?

 

I've been told that is much more safe to recompile my source rpms as a normal user. I have no problems at all in doing this as root, but when I try to do it in my home directory, rpm complains because it is unable to use the /usr/src directories due to permission problems.

 

Answer:

 

It is true, your normal user isn't allowed to use the system /usr/src tree. So in order to compile source rpm packages as normal user you have to set up a RPM tree in your home directory.

 

This is how I do it:

 

First I set up a /home/arusabal/RPM/ tree mirroring the system's rpm tree at /usr/src/RPM; you can do it either by creating by hand each directory, or in a single step using the following command:

arusabal@mandrakeusers ~$ cd ~

arusabal@mandrakeusers ~$ find /usr/src/RPM -type d -exec sh -c 'mkdir -p ${0##*/src/}'  '{}';

arusabal@mandrakeusers ~$

Next I create a temporary building directory:

arusabal@mandrakeusers ~$ mkdir -p RPM/tmp

arusabal@mandrakeusers ~$

Let's check that everything is OK:

arusabal@mandrakeusers ~$ tree ~/RPM

/home/arusabal/RPM

|-- BUILD

|-- RPMS

|   |-- i386

|   |-- i486

|   |-- i586

|   |-- i686

|   |-- k6

|   `-- noarch

|-- SOURCES

|-- SPECS

|-- SRPMS

`-- tmp



12 directories, 0 files

arusabal@mandrakeusers ~$

 

Now I have to tell rpm that instead of the system default directories, I'm going to use my own tree; so I create the user's .rpmmacros file (any settings you put in there will override the system rpm macros, as any settings you put in ~/.rpmrc will override the default rpm settings (side note, not related to our case)):

arusabal@mandrakeusers ~$ cat > ~/.rpmmacros 

%_topdir      /home/arusabal/RPM

%_tmppath     /home/arusabal/RPM/tmp

arusabal@mandrakeusers ~$

 

...And that's it! Now you can compile any SRPM package you want into your own home directory.

 

For example:

arusabal@mandrakeusers ~$ rpmbuild --rebuild --target $CHOST ~/tmp/attr-2.0.8-1mdk.src.rpm 

....

Substitute or define $CHOST with your machine type (i586, i686, athlon...). I'm used to set CFLAGS, CXXFLAGS and CHOST environment variables on /etc/profile.d/

 

See that the built packages will be located at ~/RPM/RPMS/i586/

 

arusabal@mandrakeusers ~$ tree ~/RPM

/home/arusabal/RPM

|-- BUILD

|-- RPMS

|   |-- i386

|   |-- i486

|   |-- i586

|   |   |-- attr-2.0.8-1mdk.i586.rpm

|   |   |-- libattr1-2.0.8-1mdk.i586.rpm

|   |   `-- libattr1-devel-2.0.8-1mdk.i586.rpm

|   |-- i686

|   |-- k6

|   `-- noarch

|-- SOURCES

|-- SPECS

|-- SRPMS

`-- tmp



12 directories, 3 files

arusabal@mandrakeusers ~$

 

Of course only root can install your brand new rpm packages.

 

<TODO>Add further info links</TODO>

<TODO>Talk about optimizations (CFLAGS et al.)</TODO>

Link to comment
Share on other sites

Since I do quite a bit of rebuilding, I have made what I think is quite a cool .rpmmacros file, mainly for my own use, but also to make it easier for other users to get going.

 

Features:

-Seperation of RPMS,SRPMS and SPECS per distro. At present, it's mainly Mandrake, PLF and personal

-Seperation of RPMs per distro release, so my RPMS for 9.0 stay seperate from those for 9.1. This means that if I boot into a different install (shared /home), that I can just build and reboot, no worrying about which RPM goes where

-Automatic creation of required directories. This means you don't have to manually create the directories ... but you may have to delete extra ones if you don't use them and have changed the config

-Avoidance of spurious libGLcore.so.1 dep for people using NVIdia drivers

-Sane defaults. Where I can get a value from your system, I can. If you don't like the default, you can change it.

 

To get it going, you need to:

1)Download this .rpmmacros file and save it as .rpmmacros in your home directory

2)If you use the NVidia binary drivers, download this script, save it in ~/bin (mkdir ~/bin first if necessary) and mark it executable.

 

Now if you rebuild a Mandrake RPM for 9.1/i586, you should see the RPM will be written to ~/rpm/mdk/RPMS.mdk9.1/i586, whereas a PLF RPM for 9.1/i586 will go in ~/rpm/plf/9.1/i586 (to match the PLF directory structure better). My personal RPMs (the default extension is the first 3 letters of your username, otherwise change %_my_ext in the .rpmmacros file) go in ~/rpm/bgm/RPMS.mdk9.1/i586

 

WDYT??

 

Do you think we should lobby to get some of these into the standard mandrake macros?

Link to comment
Share on other sites

 Share

×
×
  • Create New...