%vendor Chris Tyler
%_home /home/chris
%_topdir /home/chris/rpm
%_tmppath /home/chris/rpm/tmp
%_builddir /home/chris/rpm/tmp
%_rpmtopdir /home/chris/rpm/%{name}
%_sourcedir %{_rpmtopdir}
%_specdir %{_rpmtopdir}
%_rpmdir /home/chris/rpm/RPMS
%_srcrpmdir /home/chris/rpm/RPMS
%_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm
%_signature gpg
%_gpg_path /home/chris/.gnupg
%_gpgbin /usr/bin/gpg
%_gpg_name Chris Tyler
To test that this file has been saved in the correct location and is being correctly interpreted by rpm , execute rpm --eval followed by the name of one of the macros:
$ rpm --eval "%_gpg_name"
Chris Tyler
$ rpm --eval "%_srcrpmdir"
/home/chris/rpm/RPMS
Both versions of this file use the directory ~/rpm to hold packages being built. Within this directory, there will be:
A directory for each package being built, named after that package.
A directory named tmp , for temporary files created during the building process.
A directory named RPMS , to hold the final RPM packages.
You'll need to create these directories:
$ mkdir -p ~/rpm/RPMS ~/rpm/tmp
The fedora-rpmdevtools package provides the fedora-buildrpmtree command, which prepares a suitable directory structure within your home directory and creates a very basic .rpmmacros file. If you use this command, your RPMs will be built within the directory ~/rpmbuild .
5.7.1.2. Creating a spec file
The RPM building process is controlled by a spec file . Creating a good spec file is both a science and an art.
To start, create a new directory within ~/rpm to hold your source tarball and the spec file. In this example, I'm going to package up the game Critical Mass (also called critter ), available from http://sourceforge.net/projects/criticalmass . I'll name the directory after the package:
$ mkdir ~/rpm/ CriticalMass
I'll place the source tarball CriticalMass-1.0.0.tar.bz2 in this directory. The spec file will also be named after the package: CriticalMass.spec .
The first part of any spec file is called the preamble and contains the fields, or tags, outlined in Table 5-7 . Each tag is placed on a line by itself, followed by a colon and the value for that tag.
Table 5-7. Basic preamble tags in a spec file
Tag |
Description |
Name |
Name of the package. |
Version |
Version of the software in the package (software version). |
Release |
Release number of the package (package version). |
Group |
The application group to which the software belongs. See /usr/share/doc/rpm-4.4.2/GROUPS for a list of possible values. |
URL |
The software's home page on the Web. |
License |
The license used for the software (such as GPL or Mozilla). |
Summary |
A one-line summary of the package description. |
Requires |
Capabilities needed by the software in order to be successfully installed. Many requirements are automatically determined, so this line is often not needed. Also include in this tag any special capabilities required by install and uninstall scripts (or triggers). If a package name is given as an argument, a version number can be provided, and a comparison can be given (such as gcc >= 4.0 or sendmail = 8.13.4). |
BuildRequires |
Capabilities needed by the software in order to be successfully built, but not needed simply to install the RPM. For example, the gcc C compiler may be required to build the RPM package, but not to install it once it has been built. |
Provides |
Capabilities provided by the package. Like Requires, most of the Provides will be determined automatically. |
BuildRoot |
Specifies where the package should be installed during the package-building process. Many packages use %{_tmppath}/%{name}-root, which will create a package-specific directory within ~/rpm/tmp . It is strongly recommended that you do not use / . |
This is the initial information for the Critical Mass spec file:
Name: CriticalMass
Version: 1.0.0
Release: 1
Group: Amusements/Games
Summary: An arcade-style shoot-em-up game.
License: GPL
Source0: CriticalMass-1.0.0.tar.bz2
URL: http://sourceforge.net/projects/criticalmass
BuildRoot: %{_tmppath}/%{name}-root
One more tag must be defined %description but this tag does not take the name:value form. Instead, a description of the package follows on the lines after the tag:
%description
CriticalMass is an old-style arcade-style shoot-em-up game with
modern graphics and sound.
The description text will be automatically wrapped and formatted to fit available space when it is displayed. To include preformatted text, leave a space at the start of each preformatted line.
After this initial information are seven sections, each identified by a section name:
%prep
Commands used to prepare the package for building.
%build
Commands used to build the package from the source (such as make ).
%install
Commands to install the software (such as make install ).
%check
Commands to test whether the software built correctly ( make test ). Optional; many packages do not include this section.
%clean
Commands to remove temporary files after a build.
%files
A list of the files that are to be included in the package.
%changelog
A history of package versions.
The %prep section might include all of the commands that would normally be used to prepare the package:
%prep
tar xvjf CriticalMass-1.0.0.tar.bz2
cd CriticalMass-1.0.0
However, since most open source packages use some simple variation of the same steps, Fedora's standard RPM setup includes a macro script to do this work for you. It's named %setup ; to use it, specify it as the only step in the %prep section of the spec file:
%prep
%setup
Similarly, the %build stage can use the predefined %configure macro to run ./configure before make is run:
%build
%configure
make %{_smp_mflags}
The %{_smp_mflags} macro, used as an argument to make , will contain the options required to configure the build process for a symmetric multiprocessor system with multiple CPUs if the package is being built on an SMP system. (For many applications, this will make no difference).
The %install section installs the filesnot into the final destination directories, but into the appropriate directories under the BuildRoot . In this case, since we've defined the BuildRoot as ~rpm/tmp/CriticalMass-root/ , files that would normally be installed into /usr/bin will be installed into ~rpm/tmp/CriticalMass-root/usr/bin .
Читать дальше