By thomas, Fri, 09/11/2009 - 17:08
In the header you specify the name of the package, the version, a summary of the package, any requirements the package may have (packages on which this one depends, either for building or running) as well as any licensing and source file information you may need.

To start our spec file, we'll create the SPECS directory to contain our spec files.

[build@client11 ~]$ cd rpmbuild
[build@client11 rpmbuild]$ mkdir SPECS
[build@client11 rpmbuild]$ cd SPECS
Now our package will be called tar, tar is "A GNU file archiving program". Like most GNU software it is released under the GPL. So we can put all that information into our spec file.
Summary: A GNU file archiving program
Name: tar
License: GPL
Our spec file should look like this at the end of this section. Summary: A GNU file archiving program
Name: tar
License: GPL
Version: 1.22
Source: http://ftp.gnu.org/gnu/tar/%{name}-%{version}.tar.bz2
Release: 1
Group: Applications/Archiving
BuildRoot: /tmp/rpm-buildroot-%{name}-%{version}
We downloaded version 1.22 of tar in the file tar-1.22.tar.bz2 from http://ftp.gnu.org. To tell rpm what the name of our source file is, we use a Source line, if we had more than one source file, we would add Source1, Source2, etc. Now we can add the Version and Source lines to the spec.
Version: 1.22
Source: http://ftp.gnu.org/gnu/tar/%{name}-%{version}.tar.bz2
In the source line instead of using tar and 1.22, we used the variables that we already defined of name and version. Any of the lines that you specify in your spec can be used as variables later in your spec file. The advantage to doing things this way is that when tar 1.23 comes out, you only have to change the version (assuming ftp.gnu.org names version 1.23 as tar-1.23.tar.bz2)

Next we need to identify the release of our package, since this is our initial build of the package, we'll set our release tag to 1. You could put in your name here or some other identifier. Dag Wiers sometimes has dag, Red Hat will put el[4|5] here, fedora will put f11 etc. If you aren't too grandiose, use a number.

Release: 1
Next is a bit of housekeeping, we need to tell rpm what this package contains, is it System software, a Game, or an Office or Productivity package, etc. In this case we'll use Applications/Archiving
Group: Applications/Archiving

One important thing to set at this point is the BuildRoot, this is the location where files created by this rpm should live temporarily during the build process. You need this set in order to make clean rpms that don't touch the system on which they are building.

BuildRoot: /tmp/rpm-buildroot-%{name}-%{version}

This should be enough of a header, some other things you can add in the header are:

Packager:
Requires:
Vendor:
BuildRequires:+
+We'll cover requires and buildrequires later.