%files - A list of the files owned by the RPM. Remember that two packages shouldn't own the same directory! For example, you may have a file in /usr/bin but it doesn't mean you have to own the entire /usr/bin directory. Just own your package's file in /usr/bin.
%defattr(-,root,root,-) - Set the default attributes on files.
Now, make that list. Here's a few examples:
Code:
%dir %{_sysconfdir}/fwbackups
Let's say your package needs to own the /etc/fwbackups directory, this is how you do it.
Code:
%{_bindir}/fwbackups
It owns /usr/bin/fwbackups.
Code:
%{_datadir}/fwbackups/*
A neat trick that makes it own everything in /usr/share/fwbackups - Recursive, too.
This works well because since we build everything in a buildroot, telling it even '%{_datadir}/*' isn't everything in /usr/share but everything in /usr/share in your buildroot. Useful
Code:
%config(noreplace) %{_sysconfdir}/fwbackups/fwbackups.conf
Don't replace /etc/fwbackups/fwbackups.conf. Will result in .rpmnew/.rpmsave files.
%doc - List the documentation files - some examples are COPYING, LICENCE, README.
Code:
%doc COPYING LICENSE README
%changelog - You have to add a changelog entry for each change you make to the package, even if it's just a simple rebuild for the next 'Core and nothing's changed. Just put that:
Code:
* 3-letter-day 3-letter-month Day Year Name Lastname <e.mail@domain.com> version-release
- Rebuilt for new Fedora Core
You can follow that format for any date, and log. Other examples:
Code:
* Thu Sep 21 2006 Stewart Adam <s.adam@diffingo.com> 1.42-5
- Add %%requires: pygtk2-libglade
We use %%requires because it's like the backslash for Bash - Using %requires in changelog would make RPM see two %requires and get confused. %%requires safely escapes it. The same applies for all macros - For the %changelog section, don't use %{_libdir} but %%{_libdir}.
Code:
* Thu Aug 15 2006 Stewart Adam <s.adam@diffingo.com> 1.42-0
- Rebuild using sample .spec file from Fedora Extras
- Update to version 1.42 (see CHANGELOG file for details on version changes)
Simple enough 
Setup your system for RPM building
** IMPORTANT NOTE **
This section is vital. No matter which step you'd like to start at, this needs to be done only once before starting.
This is just setting up your user for RPM building, and only needs to be done once.
(Not once per step, once until you erase your account and need to start over completely.)
Code:
echo '%_topdir %(echo $HOME)/rpmbuild' > .rpmmacros
mkdir rpmbuild
cp -a /usr/src/redhat/* rpmbuild
su -
yum install fedora-rpmdevtools rpm-build mock
One should also note it's unsafe to build RPMS as root, this now allows you to build RPMS as your regular user.
** END IMPORTANT NOTE **
Overview on building your own RPMS from scratch
-- to come, but start with this --
Code:
su -
yum install rpmdevtools
exit
cd ~/rpmbuild/SPECS
fedora-newrpmspec
And now start by editing the new specfile.
Overview on rebuilding existing SRPMS
-- to come, but in short --
Code:
rpmbuild --rebuild SRPM_HERE.src.rpm
Overview on rebuilding kernel modules
This one breaks down to a few steps:
(Pre). You must have the kernel-devel (the kernel source) package installed, with the version that you want to build against. For example, if I would like to build a module for kernel 2.6.18-1.2746.fc6, I have to have kernel-devel-2.6.18-1.2746.fc6 installed.
Install kernel-devel with:
Code:
su -
yum install kernel-devel
exit
1. Download the kernel modules SRPMs and any other SRPMs needed
For example in the case of graphics drivers, you need the kernel module AND xorg SRPM packages
2. Install the SRPM packages:Their source and specs are now in your ~/rpmbuild/SOURCES and ~/rpmbuild/SPECS directories, respectively.
3. Edit the specfile, if needed.
Common use is changing the kernel version to build a module against
4. Build the RPM:
Code:
rpmbuild -ba --target=[architecture] ~/rpmbuild/SPECS/specname.spec
where [architecture] is the arch you'd like to build for. Some examples are i386, i586, i686, x86_64, etc...
(After) Successfully build RPMs go into the ~/rpmbuild/RPMS/[arch] folder, and your generated SRPMs into ~/rpmbuild/SRPMS
Little tricks when rebuilding Livna modules
- You can find the Livna module sources at: http://rpm.livna.org/fedora/
So the SRPMS are in http://rpm.livna.org/fedora/yourfedoraversion/SRPMS
- Currently, the 'fc5' SRPMS are more updated than the 'development' ones are. So I would use those when re-building kernel module RPMS.
- The names of the modules may be reversed. Example, rather than kmod-nvidia the source package may be named nvidia-kmod.
- When rebuilding, you may get errors about kernel devel packages being required. Try adding this option to the rpmbuild command:
Code:
--define 'kvariants ""'
It worked for me when rebuilding the nVidia modules.
Examples
Here's an example of how to modify the Livna nVidia RPMs, following the same steps I wrote above
fglrx users, you can use this same basic theory and apply it to the fglrx packages, it will work too.
(pre):
Code:
yum install kernel-devel
It installs these two packages:
(1) kernel-2.6.18-1.2726.fc6 (2) kernel-devel2.6.18-1.2726.fc6
)I'm on fc6 / development repos, it's why yum grabs the fc6 kernels and not the fc5 ones...)
1. Download:
http://rpm.livna.org/fedora/5/SRPMS/...87_FC5.src.rpm
http://rpm.livna.org/fedora/5/SRPMS/...1.lvn5.src.rpm
2. Install:
Code:
rpm -ihv nvidia-kmod-1.0.8774-1.2.6.17_1.2187_FC5.src.rpm xorg-x11-drv-nvidia-1.0.8774-1.lvn5.src.rpm
3. Modify the spec file:
Code:
gedit ~/rpmbuild/SPECS/nvidia-kmod.spec&
I change:
Code:
%{!?kversion: %define kversion 2.6.17_1.2187_FC5}
to read:
Code:
%{!?kversion: %define kversion 2.6.18-1.2726.fc6}
because I want to build a module for kernel-2.6.18-1.2726.fc6.
4. Build:
** Commands are bold, results are normal **
Code:
rpmbuild -ba xorg-x11-drv-nvidia.spec
It succeeds. So let's try the kernel module:
Code:
rpmbuild -ba nvidia-kmod.spec
error: Architecture is not included: i386
OK, so let's try with a different architecture; `uname -m` output's your system's architecture:
Code:
rpmbuild -ba nvidia-kmod.spec --target=`uname -m`
error: Failed build dependencies:
kernel-smp-devel-i686 = 2.6.18-1.2726.fc6 is needed by nvidia-kmod-1.0.9625-1.2.6.18_1.2741.fc6.i686
kernel-xen0-devel-i686 = 2.6.18-1.2726.fc6 is needed by nvidia-kmod-1.0.9625-1.2.6.18_1.2741.fc6.i686
kernel-kdump-devel-i686 = 2.6.18-1.2726.fc6 is needed by nvidia-kmod-1.0.9625-1.2.6.18_1.2726.fc6.i686
There go those kernel requires errors I was talking about in the 'Tips' section. Let's try messing around with --define and kvariants:
Code:
rpmbuild -ba nvidia-kmod.spec --target=`uname -m` --define 'kvariants ""'
And now it builds. All that's left is to install the new RPMs you've just made!
Participate in the Fedora Extras!
You're encouraged to help out and participate in the Fedora Extras project. If you'd like to help out by adding your RPMS to the Extras, please see these two pages to start:
http://fedoraproject.org/wiki/Extras/Contributors
http://fedoraproject.org/wiki/Packag...viewGuidelines