Overview

The spec file is a script file for making an rpm package. It defines the information, content and installation location of the rpm package in detail, such as the name, version, category, description summary of the software package, what instructions to execute when creating, and what operations to perform when installing. And the list of files to be included in the software package, etc.

The spec file is composed of multiple sections, which respectively define the work content of rpm compilation, packaging, installation and other stages.

Examples are as follows:

Name: myprogram
Version: 1.0
Release: 1
Vendor: Jaun
Summary: My program
License: GPL
URL: http://myprogram.com
Source0: myprogram-1.0.tar.gz
Group: Development/Tools
BuildRequires: gcc
%description
My program is a simple example program.
%prep
%setup -q
%build
  ./configure
  make
%install
	make install DESTDIR=%{buildroot}
%clean
	rm -rf %{buildroot}
%files
	%defattr(-,root,root)
	/sbin/myprogram
%post
	/sbin/ldconfig /sbin/myprogram
%preun
	/sbin/ldconfig /sbin/myprogram
%postun
	/sbin/ldconfig
%changelog

1. Software package description

The first part of the spec file is usually the package description content, which can contain the following information:

1.1、Name

The name of the software package can be referenced later using %{name}. The final RPM software package uses this name, version number, release number and system number to name the software package.

1.2、Version

The version number of the software package can be referenced later using %{version}. The version number will only be increased when the software package has changed significantly from before.

1.3、Release

The actual release serial number, indicating the packaging time, number of times and other information, can be referenced later using %{release}

1.4、Vendor

The name of the software developer.

1.5、Summary

Summarize as much information as possible about the package in one sentence

1.6、License/Copyright

The distribution license of the software package, that is, the software authorization method, is usually GPL. Other common ones are: GPL (free software), BSD, MIT, Public Domain (public domain), Distributable (contribution), commercial (commercial), Share (share), etc.

1.7、URL

The publisher’s website, blog, email and other information can be placed here

1.8、Source

Source code packages usually use Source0, Source1..., and can also be referenced later using %{source0}, %{source1}.

1.9、Group

For software grouping, it is recommended to use standard grouping. Common groupings are as follows:

Amusements/Games	(娱乐/游戏)
Amusements/Graphics	(娱乐/图形)
Applications/Archiving	(应用/文档)
Applications/Communications	(应用/通讯)
Applications/Databases	(应用/数据库)
Applications/Editors	(应用/编辑器)
Applications/Emulators	(应用/仿真器)
Applications/Engineering	(应用/工程)
Applications/File	(应用/文件)
Applications/Internet	(应用/因特网)
Applications/Multimedia	(应用/多媒体)
Applications/Productivity	(应用/产品)
Applications/Publishing	(应用/印刷)
Applications/System	(应用/系统)
Applications/Text	(应用/文本)
Development/Debuggers	(开发/调试器)
Development/Languages	(开发/语言)
Development/Libraries	(开发/函数库)
Development/System	(开发/系统)
Development/Tools	(开发/工具)
Documentation	(文档)
System Environment/Base	(系统环境/基础)
System Environment/Daemons	(系统环境/守护)
System Environment/Kernel	(系统环境/内核)
System Environment/Libraries	(系统环境/函数库)
System Environment/Shells	(系统环境/接口)
User Interface/Desktops	(用户界面/桌面)
User Interface/X	(用户界面/X窗口)
User Interface/X Hardware Support	(用户界面/X硬件支持)

1.10、Patch

Patch source code package path, you can use Patch0, Patch1..., you can also use %{patch0}, %{patch1} for reference later.

1.11、BuildRoot

The root directory during installation or compilation. When the package is generated, if this directory is not specified as the virtual root directory, during the installation phase, the system root directory will be used as the installation root directory.

1.12、Requires

The currently generated RPM package needs to rely on the name of the software package. Use >= or <= to indicate greater than or equal to or less than or equal to the specified version. The symbols are separated by spaces on both sides. Different software packages are also separated by spaces.

1.13、Packager

Packager information

1.14、%description

Detailed description of the software, can be written on multiple lines

1.15、BuildArch

Refers to the target processor architecture for compilation. The noarch flag is not specified, but the content in /usr/lib/rpm/marcros is usually used as the default value.

2. Software package generation phase script

The package generation phase defines the detailed work content of the installation package production phase, including preparation, compilation, packaging, cleaning, inspection, etc.

The code of this process is running in the production stage, that is, running on the packaging machine. When you run the rpmbuild command, the following stages are executed in order.

2.1、%prep

In the preparatory compilation stage, you can use a script to decompress the source code package. If there is a patch, the patch will also be processed, and then the compilation configuration information will be generated (most software will execute the configure script at this stage for compilation check); in addition to In addition to executing the macro commands defined by RPM (starting with %), you can also execute the SHELL command. The command can have many lines, such as the tar unpacking command we often write.

2.2、%build

In the compilation stage, the command to be executed is to generate software package services. Most software will perform the make operation at this stage.

2.3、%install

During the installation phase, most software will perform the make install operation at this stage.

2.4、%clean

In the cleanup phase, after the installation is completed, the temporary files generated by the above stages will be cleaned up.

2.5、%check rpm

Testing of software packages.

3. Package installation phase script

The installation phase script of the package is run during the rpm package installation process and runs on the target machine. When you type the rpm command to start the installation time execution.

3.1、%pre

Pre-installation script, that is, before the RPM package is installed, execute this part of the script first, such as creating a designated account, etc.

3.2、%post

Post-installation script, that is, after the RPM package is successfully installed, this part of the script will continue to be executed, such as setting up startup, starting services, etc.

3.3

Uninstall pre-execution script, that is, before the RPM package is uninstalled, execute this part of the script first, such as stopping services, canceling boot, etc.

3.4、% post

Post-uninstall script, that is, after the RPM package is successfully uninstalled, this part of the script will continue to be executed, such as deleting the specified account, etc.

4. Package configuration information

4.1. %files packaged file list. Files that need to be put into the RPM package are listed here. They can be directories.

4.2. %changelog change log can indicate the information that needs to be prompted for this packaging.

4.3. %doc indicates that this is a documentation file, so if you use –excludedocs during installation, such files will not be installed.

4.4. %dir means to enter the contents of the dir directory path into the rpm software package.

4.5. %config (noreplace) This configuration file will not overwrite existing files (the files in the RPM package will exist in the system as .rpmnew. When uninstalling, the configuration file in the system will be saved as .rpmsave. If there is no such option, the installation When the file in the RPM package exists in the system as .rpmorig), it overwrites the existing file (not modified) and creates a new file with the extension suffix .rpmnew (modified).

4.6. %attr controls file permissions

5. Production and installation commands

make

rpmbuild -bb xxx.spec

View detailed help:

rpmbuild --help

Install

rpm -ivh xxx.rpm

Query package content

rpm -qlp xxx.rpm

Query installed packages

rpm -qa