This section describes the package by using tags and directives.
For example, the following tags describe a package: Name, Arch, Version, Release, URL, and License. The %description directive describes the usage for the package. After the package is built, the tags and directive information become part of the package.
You can display the tags and other information in an existing package by using the yum info <package name>command:
# yum info bash
Loaded plugins: aliases, langpacks Installed Packages Name : bash Arch : x86_64 Version : 4.2.46 Release : 12.el7 ....
Description : The GNU Bourne Again shell (Bash) is a shell ... ...
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
spec
File to Build a Binary RPM Package
•
The spec file describes the package and lists the steps to
build the software in the package.
•
It contains the following sections:
–
Header: Describes the package with a collection of tags
–
%prep: Prepares files for the build
–
%build: Builds the software
–
%install: Copies files to their installation location
–
%clean: Cleans the build directory tree
–
%files: Identifies the files to be packaged
Oracle Internal & Oracle
Each section following the header information is a step in the build process. Any command, script, macro or directive in a section is executed like a script when that step is executed. Before each step is executed, several environment variables are set. For example, the value for the RPM_BUILD_DIR variable is set.
%prep
During the execution of this step, the source files are unpacked into the build directory. If present, patches are applied. The %setup macro is responsible for unpacking the source files.
%build
There are no special macros for this section. Generally, you specify one or more make commands in this section to build the software.
%install
The role of this section is to install the newly built software. This means that the files that make up the package along with their directory location are copied into a directory structure. After the files are copied, the build reads the list of files in the %files section and creates the binary RPM package.
%clean
At this step, the packaging is already done. This macro cleans the directory tree where the software is installed (default is variable RPM_BUILD_ROOT) or any directory specified in this section.
%files
This section lists the files that are to be part of the final RPM. In this section, you can use macros to set file and directory permissions.
As stated in the description of the sections in the spec file, you can use macros and directives to perform specific steps in each section.
Example:
• %setupmacro in the %prep section unpacks the source files.
• %configdirective in the %files section labels files as configuration files.
You can find more information about the tags, macros, and directives in the RPM-based spec file at this location: http://www.rpm.org/max-rpm/.
Oracle Linux 7: Advanced Administration 8 - 9
Oracle Internal & Oracle
Use the rpmdev-newspec command to create a skeleton spec file. The following example creates the hello.spec file in the SPECS directory:
# rpmdev-newspec SPECS/hello.spec
From the contents of the hello.spec file shown in the slide, you can gather the following information:
• Both the package and the program in the package are called hello. • This is version 1.0 of the software being packaged (Version: 1.0).
• This is version 1 of the package itself with the distribution appended (Release: 1.el7.x86_64).
• There is no step for the %build section. The build process goes from the %prep section to the %install section without any build command or script. Generally, this section contains build instructions.
• There is only one file in the final package, the hello program, which is installed into the /usr/local/bindirectory when the package is installed.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
spec
File: Example
Name: hello
Version: 1.0 Release: 1%{?dist) Summary: hello program License: GPL #URL: Source0: hello-1.0.tar.gz #BuildRequires: #Requires: %description
A program to display Hello World %prep %setup -q %build %install rm -rf $RPM_BUILD_ROOT #%make_install install -d $RPM_BUILD_ROOT/usr/local/bin install hello $RPM_BUILD_ROOT/usr/local/bin/h ello %files /usr/local/bin/hello %changelog
Oracle Internal & Oracle
Yum tools, including the yum command, provide more services and functionality than is available with the rpm command and other RPM-based tools.
With Yum tools and plug-ins, you can:
• List software packages, both installed and available, in local or remote repositories • Check for package dependencies (packages required to install a package)
• Check for dependent software (packages that depend on another package) • Create new repositories and enable or disable access to existing repositories • Speed up package installation by using cached information (Yum cache)
• Extend Yum’s functionality with plug-ins such as the aliases plug-in (to create and view aliases for Yum commands)
• Use package management GUI tools such as PackageKit. PackageKit uses Yum tools. PackageKit is discussed later in this lesson.
Note that when creating packages, either binary or source RPMs, you use RPM-type tools such as rpmbuild and rpmdev-setuptree. These commands were discussed in the RPM Packages topic earlier in this lesson.
Oracle Linux 7: Advanced Administration 8 - 11
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.