RPM Package Making method

Source: Internet
Author: User
Tags rpmbuild

First, RPM introduction

Before RPM is the Red Hat Package manager abbreviation, the original meaning is Red Hat packages management, as the name implies Red Hat to contribute to the package management; In the mainstream releases, such as Fedora, Redhat, Mandriva, SuSE, Yellowdog, and the two-time distributions that have been developed on top of these editions; RPM packages include files that are required to run the program, and other files; an application in a RPM package , and sometimes other specific versions of files are required in addition to the additional files that they carry, which is the dependency of the package.

RPM allows the user to install the package directly in binary mode, and can query the user whether the library file is already installed, and when the program is removed with RPM, it intelligently asks the user if they want to delete the program. If you use RPM to upgrade the software, RPM retains the original configuration file so that the user does not have to reconfigure the new software. RPM maintains a database that contains all the information about the package, which allows the user to query the package. RPM is designed for Linux, but it has been shifted to SunOS, Solaris, AIX, IRIX and other Unix systems. RPM complies with the GPL, and users are free to use and disseminate rpm under the GPL.

Second, RPM package classification

RPM is divided into two main categories,

1 Binary class package, including RPM installation package (generally divided into i386 and x86, etc.) and modal information packets, etc. 2 Source class package, source package and development package should be returned to this class

The relationship between them is, first we according to RPM packaging requirements to transform the software project source code, when the requirements can be used to generate different RPM packages, and the resulting package between the version is directly corresponding, such as the same source package will produce the exact same binary RPM package. Rpmbuild When you look up the RPM package online, you can usually find the precompiled binary package in the RPMs directory, and the source package will be within the Srpms directory.

The RPM production we mentioned here refers to the process of transforming the software source code to conform to RPM packaging requirements, which can also be equivalent to the production of RPM source packages, because when you have a source package you can directly compile the binary installation package and any other packages.

Three, RPM package production Introduction

RPM package production, that is, the production of RPM source package.

The principle of RPM package work

RPM is to solve the source package is not easy to install (need to compile) and dependencies between the package (is the RPM Package Manager to some extent to solve the dependency problem), it through the detection source package in the build and install phase of the action to obtain the final generation of the system needs to install the files, and record some necessary actions (such as performing an action after installation), and then turn this group into a whole, when the user installs the package and puts all the previously acquired issues and records all the actions on the actual system.

To put a common source into the RPM package, need some of the following operations

1 , first need to makefile the project to make the necessary modifications to support RPM packaging operations (in fact, this operation is not absolute, spec documents and makefile is coordinated work, as long as they cooperate with the other do not matter, We generally only recommend you as far as possible according to industry standard operation only)2, the second is to write a spec document for the current project, the spec document includes the RPM packaging process operation content and the new RPM package basic information, etc. Its object is the wrapper rpmbuild.

Four, RPM package production process

Reference: https://www.centos.bz/2012/06/make-rpm-package-methods/

1 Preparing the packaging environment

Execute the following command to install Rpmbuild and Rpmdevtools

#Yuminstall rpmbuild
#yum Install

Execute the following command to generate the working directory of the Rpmbuild

#rpmdev-setuptree

The working directory structure is as follows

~/rpmbuild~/rpmbuild/SOURCES              #放置打包资源, including source packaging files and patch files ~/rpmbuild/SPECS                #放置SPEC文档 ~/rpmbuild/BUILD                #打包过程中的工作目录~/rpmbuild/RPMS                 #存放生成的二进制包~/rpmbuild/rpms/i386            #存放生成的i386结构包~/rpmbuild/srpms                #存放生成的源码包
Tip: The Rpmdev-setuptree command defaults to the current user home directory to create a RPM build root structure, if you need to change the secondary default location, you can modify the configuration file: ~/.rpmmacros variable _topdir corresponding value.

2, download source package to sources directory, do not need decompression

CD sources/wget http://nginx.org/download/nginx-1.2.1.tar.gz

3. Write Spec file

Spec writing is the core of packaging rpm, is also the most difficult step, fortunately, we can refer to a simple template file, in the basic functions can be achieved on the basis of the next step to expand the content of the document, until fully meet the requirements. Here is a simple spec document, which includes some explanatory information (note: #后面的内容为说明信息), the spec document is written for a test software project hellorpm, the HELLORPM package compiles with only one execution file, one manual file, and one project said file.

The contents of the Nginx.spec document are as follows:

# # Example Specfile  fornginx# #软件包简要介绍Summary: The name of the high performance Web server# software package name:nginx# The major version number of the package version:1.2.1#软件包的次版本号Release:1. el5.ngx# License Agreement license:2-clause bsd-Like license# software classification Group:applications/serversource:http://nginx.org/download/nginx-1.2.1.tar.gzUrl:http://nginx.org/Distribution:LinuxPackager:zhumaohai<[email protected]>#软件包的内容介绍%Descriptionnginx [engine x] is a HTTP and reverse proxy server, as well ASA Mail proxy server# represents a pre-action field, the following command will be in the source code build Pre-execution%PrepRM-RF $RPM _build_dir/nginx-1.2.1Zcat$RPM _source_dir/nginx-1.2.1.Tar. gz |Tar-XVF-#BUILD字段, the source code compilation operation will be done by directly invoking the automatic build tool in the source directory%BUILDCD Nginx-1.2.1#调用源码目录中的configure命令./configure--prefix=/usr/local/nginx# Execute the Automatic build command in the source directory make Make#安装字段%InstallCD Nginx-1.2.1#调用源码中安装执行脚本 Make Install%Preunif[-Z"' ps aux | grep nginx | grep-v grep '"]; ThenKillallNginx >/dev/NULLExit0fi#文件说明字段, statements that are redundant or missing can be error-prone%files# declaration/usr/local/nginx will appear in the package
/usr/local/nginx

4. Build RPM Package

Start the build operation by first entering the Rpmbuild root directory of the current user

#cd ~/rpmbuild/-ba specs/nginx.spec

Tip:-ba represents build all, which generates all RPM packages including binary packages and source packages, and if normal, rpmbuild exits normally, and the corresponding RPM packages are generated in the RPMs directory and Srpms directory.

RPM Package Making method

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.