So, you want to rebuild a Fedora package from source using a src.rpm file? Maybe make some tweaks along the way? This is how.
Quick Prerequisites Check
First, make sure you have yum-utils and rpmdevtools installed
sudo yum -y install yum-utils rpmdevtools
Next, configure your user's .rpmmacros file. Use your username, not root! Edit ~/.rpmmacros and add these lines:
%_topdir %(echo $HOME)/rpmbuild
%__arch_install_post /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot
The first line, indicates the rpm build top directory. Then, we add some some post install commands. Systems with SMP enabled should also add the following to enable parallel compiles during builds. Adjust the job number to be the number of CPU cores available. In my example, two.
%_smp_mflags -j2
I also like to format my rpm query string so that architecture is part of the name:
%_query_all_fmt %%{name}-%%{version}-%%{release}.%%{arch}
To review, here is my .rpmmacros file:
%_topdir %(echo $HOME)/rpmbuild
%_smp_mflags -j2
%__arch_install_post /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot
%_query_all_fmt %%{name}-%%{version}-%%{release}.%%{arch}
Get the Source
Build the rpmbuild folder and it's subfolders using rpmdev-setuptree from the rpmdevtools package. Note that you can also wipe ~/rpmbuild clean with /usr/bin/rpmdev-wipetree.
/usr/bin/rpmdev-setuptree
Then, cd into ~/rpmbuild/SRPMS and use yumdownloader (part of yum-utils) to download the source code. In the following example, I am downloading httpd.
cd ~/rpmbuild/SRPMS/
yumdownloader --source httpd
Build the Source
Use yum-builddep as root to install all packages needed to build the source RPM. The yum-builddep tool is part of the yum-utils package.
sudo yum-builddep httpd-2.2.8-3.src.rpm
You have two options when compiling the RPM from source. One, you just rebuild the src.rpm as-is. This will drop a binary RPM in ~/rpmbuild/RPMS/$(arch):
rpmbuild --rebuild httpd-2.2.8-3.src.rpm
Otherwise, if you want to make changes to the source RPM's spec file, first install the source RPM:
rpm -ivh httpd-2.2.8-3.src.rpm
Now you can edit the spec file in ~/rpmbuild/SPECS and build a binary package using the edited spec file:
cd ~/rpmbuild
vim SPECS/httpd.spec
rpmbuild -bb SPECS/httpd.spec
To also build a new source RPM from your edited SPEC, use rpmbuild -bs
rpmbuild -bs SPECS/httpd.spec
Again, binary RPMs are produced in ~/rpmbuild/RPMS/$(arch).
Sources
FedoraProject.org: Docs/CustomKernel
HowToForge.com: How To Compile A Kernel - The Fedora Way