Recently, i need to study building a rpm package. after searching on google, i found a very useful document about how to build and rpm.
Reference: RPMS for fun and Profit or, How I Learned to Love the Package
So first of all, i setup an openSUSE 11.2 vm for my building purpose. This is the first time i use openSUSE and i found that the graphics look good and the YaST manager is really useful for package management and system configuration.

so make sure u have the require softwares for building rpm like gcc, make and build etc…
here comes to the steps. =)
*The .spec file i used in this post is different from the one in the above reference link. If i used that .spec file, the build will fail due to file not found or undeclared file in the %file stage.
1. Create the following folders as your rpm home folder
- */rpm
- */rpm/BUILD
- */rpm/RPMS
- */rpm/SOURCES
- */rpm/SPECS
- */rpm/SRPMS
2. Create the .rpmmacros at your home folder for your own rpm build configuration
%packager ykyuen <yingkityuen@gmail.com>
%_topdir /home/ykyuen/rpm
%_tmppath /var/tmp
%_rpmtopdir %{_topdir}
%_builddir %{_rpmtopdir}/BUILD
%_rpmdir %{_rpmtopdir}/RPMS
%_sourcedir %{_rpmtopdir}/SOURCES
%_specdir %{_rpmtopdir}/SPECS
%_srcrpmdir %{_rpmtopdir}/SRPMS
3. Download the hello-2.1.1.tar.gz to */rpm/SOURCES folder
4. Create the hello-2.1.1.spec in the */rpm/SPECS folder
Summary: GNU Hello
Name: hello
Version: 2.1.1
Release: 1
Source: http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz
URL: http://www.gnu.org/software/hello/hello.html
License: GPL
Group: System Environment/Libraries
%description
This project is an example that demonstrates GNU coding standards.
%prep
%setup
%build
CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%{_prefix}
make
%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%doc AUTHORS BUGS ChangeLog COPYING INSTALL NEWS README THANKS TODO
%{_prefix}/bin/hello
%{_prefix}/info/dir
%{_prefix}/info/hello.info.gz
%{_prefix}/man/man1/*
%{_prefix}/share/locale/*/LC_MESSAGES/hello.mo
%changelog
* Wed Dec 23 2009 ykyuen <yingkityuen@gmail.com>
- First draft of the spec file
5. Run the rpm build command
- rpmbuild -ba hello-2.1.1.spec
6. If everything works fine u should be able to find the following 2 rpm files.
- */rpm/RPMS/i586/hello-2.1.1-1.i586.rpm
- */rpm/SRPMS/hello-2.1.1-1.src.rpm
7. Then you can try to install the rpm u just created and test it
- rpm -ivh hello-2.1.1-1.i586.rpm
Done =)

Great post. Easy, quick readable and provides a good reference. Thanks!
you are welcome =D
One of the few linux post out there that really provide useful information in an accessible manner – simple and straight to the point. Good Job!
The only problem I had in following this guide was that when issuing the “rpmbuild -ba hello-2.1.1.spec” command was that it was searching for the file a directory called “rpmbuild” and not “rpm”. I renamed it and it was OK.
I guess the reason it searches for a directory called “rpmbuild” is becoz of the setting in .rpmmacros.
Anyway, good to know that this post could help. =D
Pingback: Rename kernel external build packages