[Comprehensive] production of simple RPM suite

Source: Internet
Author: User

When using Linux, you may need to install new software, upgrade installed software, or delete installed
Software, which involves RPM more or less.
Rpm is a source code and binary code encapsulation method developed by RedHat.
Users can easily manage software packages, including installation, upgrade, deletion, query, and management of software packages. Thanks to RPM
The installation software package is more simple than the method of .tar.gz.
Rpm software has become the standard for installing software in Linux.
It is very useful for programmers to master the preparation of simple RPM kits for promoting their own programs.
The RPM kit can be roughly divided:
1. Obtain the software source program and patch file in .tar.gz format.
2. Create a spec file for the RPM kit.
3. Run RPM? Ba generates and tests the RPM suite.
The focus of the entire RPM package is how to define the complete RPM suite specification file (specification) and Package
Testing after installation. Before creating the RPM kit, you must first understand the directory structure and running of the entire system file, because
The preparation of RPM suites often involves system running problems. For example, if a new shell is installed, it must be in/etc/shells.
In order to use the shell correctly only by adding the executable file path and name of the shell. To avoid this concern, you can
Start with the application software running on unrelated systems, and get familiar with the Linux system.
Production of the RPM kit.
The RPM spec is like the makefile during program compilation. It defines all the file information and production process for creating the RPM package,
Its main work is to decompress the source program, patch the source program, compile the source program, package the binary code RPM package, and package the source code
RPM package to clear the temporary directory generated in the build directory during the packaging process.
It is the rock of the mountains. You can take a look at the spec files compiled by others. It is a shortcut to learn how to write spec files.
Command to retrieve the spec file.
$: Rpm? Qlp *. SRC. rpm
$: Rpm2cpio *. SRC. RPM | cpio? IVH *. spec
First Run RPM? Qlp query, know that the suite has a. spec file, and then execute rpm2cpio to convert the RPM file
To the cpio file format, and output the conversion results to the cpio program, extract the sepc file in the source RPM suite.
Open a spec file and you can find it in the following sections: % define, % description, % prep, % build,
% Install, % clean, % files, and % changelog.
The % define section is mainly used for global definition, such as: Version Number: version; simple summary: summary;
Sequential name: Name; Copyright: copyright; group to which the software belongs: group; source name is the most important position,
In this example, we define the source file (a few tar.gz files and some patch files. if the source of the software has only one
File. You can specify multiple source programs. You only need to specify the "Source" and "patch" labels in sequence.
The file must be placed in the/usr/src/RedHat/sources directory before rpm can be packaged. Icon indicates the set.
A GIF file in the/usr/src/RedHat/source directory.
Some software may have some dependency information, telling the user that some kits must be installed before the RPM kit can be installed
In this case, the RPM suite that needs to make this function depends on the "requires" label. There are total requires <,>, <=,
=,> = These five types. If a software requires three or four function libraries at the same time, the requires tag must define three or four rows. or
Use commas to separate a line. For example: requires: kdesupport. Of course, there are still several tags for the % define segment, but no
Frequently used. I will not talk about it here.

The % description section is relatively simple, mainly a brief introduction to the software.

% Prep is the spec preparation section. This section mainly performs preparation for packaging the RPM package and checks whether the label syntax is correct.
Check whether the/usr/src/RedHat/sources directory stores the source program and patch files, and delete the old software source program,
And perform untar, patch, and other work for the program. Of course, you can write some shell scripts to specify
Work, but it may be annoying to write shell scripts for these preparations. So rpm is enabled
The sender provides the % setup and % patch commands for users to handle these complicated preparations.
% Setup only opens the software package without any options.
% Setup? N newdir decompress the package in the newdir directory.
Before % setup-C is decompressed, a directory is generated.
% Setup? B num: Decompress the num source file.
% Setup? T does not use the default decompression operation.
% Setup? T? B 0 decompress 0th source code files.
% Setup? C? N newdir specifies the directory name newdir and generates the RPM suite in this directory.
% Patch: Specifies the patch level automatically.
% Patch 0 uses 0th patch files, which is equivalent to % patch? P 0.
% Patch? S does not display the patch information.
% Patch? T delete all output files generated during patching.

The % build section is mainly used to compile the program. Normally, a make command is used to compile the program.

The % install section is complex. It mainly performs installation. Here you can write some scripts
In the menu bar, the scripts are not common because of different releases. simply execute make install
To install the program (depending on the installation of different programs ).

% Clean is the delete segment of the spec. Does it use RM? F command to delete the temporary directory during compilation, usually using Rm-RF
$ Rpm_build_root.

The % files and % changelog sections are used to tell the user where the software is installed and some updates of the software.

After this is done, a spec file will be completed. Run RPM? Ba generates and tests the RPM suite.
If it is incorrect, a binary RPM package and a source code srpm package will be generated. They are located in
/Usr/src/RedHat/RPMS and/usr/src/RedHat/srpms directory (Note: I am using RedHat 7.0, different hair
Line version paths are different ).

/* We can communicate with each other in areas that are relatively simple and hard to understand */

/* Cloud Flying, E-mail: yfy001@etang.com, tel: 025-4705268-23 */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.