By thomas, Fri, 09/11/2009 - 16:53
In our example we'll build tar, so first off we'll download tar from gnu, the homepage for gnu tar is http://directory.fsf.org/project/tar/

[root@client11 ~]# useradd build
[root@client11 ~]# su - build
[build@client11 ~]$ wget http://ftp.gnu.org/gnu/tar/tar-1.22.tar.bz2
--20:37:37--  http://ftp.gnu.org/gnu/tar/tar-1.22.tar.bz2
Resolving ftp.gnu.org... 140.186.70.20
Connecting to ftp.gnu.org|140.186.70.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2094575 (2.0M) [application/x-tar]
Saving to: `tar-1.22.tar.bz2'

100%[=======================================>] 2,094,575   2.39M/s   in 0.8s   

16:32:16 (2.39 MB/s) - `tar-1.22.tar.bz2' saved [2094575/2094575]
The next thing I like to do is make a build directory for myself. On recent versions of fedora, rpm will build a directory called rpmbuild for you in your home directory. On older versions rpm will try and install files in /usr/src. It's probably better to just specify your build directory just in case. You can do that with the .rpmmacros file, the option to specify is %_topdir.
[build@client11 ~]$ mkdir rpmbuild
[build@client11 ~]$ cd rpmbuild
[build@client11 rpmbuild]$ mkdir -p BUILD RPMS/x86_64 SOURCES SPECS SRPMS
[build@client11 rpmbuild]$ cd
[build@client11 ~]$ cat .rpmmacros
%_topdir /home/build/rpmbuild
[build@client11 ~]$ rpmbuild
-bash: rpmbuild: command not found
If you haven't already done so, install the rpm-build rpm so you have access to the rpmbuild command.
[build@client11 ~]$ exit
[root@client11 yum.repos.d]# yum install rpm-build
Loading "installonlyn" plugin
...
=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 rpm-build               x86_64     4.4.2-37.el5     Workstation       558 k
...
Installed: rpm-build.x86_64 0:4.4.2-37.el5
Dependency Installed: elfutils.x86_64 0:0.125-3.el5 elfutils-libs.x86_64 0:0.125-3.el5
Complete!
[root@client11 yum.repos.d]# su - build
[build@client11 ~]$ rpmbuild
rpmbuild: no spec files given for build
As rpmbuild has indicated, we need to make a spec file, lets start making one now.