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:
CODE
arusabal@mandrakeusers ~$ cd ~
arusabal@mandrakeusers ~$ find /usr/src/RPM -type d -exec sh -c 'mkdir -p ${0##*/src/}' '{}';
arusabal@mandrakeusers ~$
arusabal@mandrakeusers ~$ find /usr/src/RPM -type d -exec sh -c 'mkdir -p ${0##*/src/}' '{}';
arusabal@mandrakeusers ~$
Next I create a temporary building directory:
CODE
arusabal@mandrakeusers ~$ mkdir -p RPM/tmp
arusabal@mandrakeusers ~$
arusabal@mandrakeusers ~$
Let's check that everything is OK:
CODE
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 ~$
/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)):
CODE
arusabal@mandrakeusers ~$ cat > ~/.rpmmacros
%_topdir /home/arusabal/RPM
%_tmppath /home/arusabal/RPM/tmp
arusabal@mandrakeusers ~$
%_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:
CODE
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/
CODE
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 ~$
/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>