Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make the source package as a rpm package under the Linux system

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to make the source package as a rpm package under the Linux system". The content in the article is simple and clear, and it is easy to learn and understand. Please follow Xiaobian's train of thought to study and learn "how to make the source package as a rpm package under the Linux system".

1. To use the rpmbuild command, to install rpm-build, you can use yum-y intall rpm-build under centos to complete the installation.

2.rpmbuild package and / usr/src/redhat directory, these rpmbuild programs are controlled by spec files. It is installed on another machine as specified by the configuration

A package used to indicate that the converted source patch is compiled into a binary file. The default compilation operation is in the following directory, which is the location of the relevant actions for compiling the source code.

If you do not specify other places, then the place of rpm building is mainly in the / usr/src/redhat directory, the directory structure is as follows, which is the directory structure provided for rpm-build.

The code is as follows:

/ usr/src/redhat/

|-- BUILD

|-- RPMS

| |-- i386 |

| `- -.

|-- SOURCES

| |-- foo-1.2.tar.gz |

| |-- foo-1.2-add_feature.patch |

| | `--foo-1.2-change_default.patch |

|-- SPECS

| | `--foo.spec |

`--SRPMS

% define name foo # first name

% define version 16 # version

Name:% {name} # name is the macro instruction used above

Version:% {version} # version is also using the above macro instruction

Release: 1

License: GPL

Group: which group does the Applications/Productivity # software belong to? for more information, see / usr/share/doc/rpm-version/GROUPS

URL: http://www.mysqlops.com

Source: ftp://www.mysqlops.com/pub/xxx.tar.gz

Patch0: foo-1.2-change_default.patch

Patch2: foo-1.2-add_feature.patch

PreReq: what is required for unzip # before installation

Requires: what is required after pam # installation

BuildPreReq: gcc > = 2.96 # what do you need before packing

BuildRoot:% {_ tmppath} /% {name}-root # directory where the chroot of the source code file is prepared

Summary: A fictional open source package for the offering. # Summary

% description # description

Note that much of the information in the spec file is taken from the macro instruction, and if not explicitly specified, it will inherit / usr/lib/rpm/macros and other related macro instruction files.

% prep of the Spec file

The other part of% prep consists of some parameters to form a shell script to extract the source code from SOURCES and apply patches to the BUILD directory to prepare the following compilation.

Macro instructions related to% prep

The code is as follows:

% setup

% patch

Example:

The code is as follows:

% prep

% setup-Q # extracts the source code to the BUILD directory;-Q means that the output is not displayed (quietly)

% patch0-p1 # apply patch0

% patch2-p1-b. Orig # applies Patch2 but saves the source file as a .oring suffix

Unzip foo_data.zip # next extract the zip file

% build of the Spec file

% build is compilation and preparation software that runs like a shell script in the source directory specified in the context directory. During compilation, the script .config is called in the local directory (configured in% configure).

Macros related to% build

% configure # can see its settings by running rpm-eval% configure

Example:

The code is as follows:

% build

% configure-enable-shared

CFLAGS=-O2 make

% install of the Spec file

% install is used to do all the required files for rpm installation. These packaged files will be copied to the directory tree in the BuildRoot described earlier. Usually this directory is used in / var/tmp.

$RPM_BUILD_ROOT parameter to set BuildRoot. The main reason why real directories cannot be used to set up is that during compilation, files may be replaced with files in your system to cause the system

And software problems. Other file paths such as% {_ mandir},% {_ bindir},% {_ sysconfdir}, etc., are specified using predefined macros.

The default is to run in this RPM_BUILD_ROOT directory.

Example:

The code is as follows:

% install

Rm-rf $RPM_BUILD_ROOT # default $RPM_BUILD_ROOT is / var/tmp/% {name}-root

Make DESTDIR=$RPM_BUILD_ROOT install # specify the path to the installation file

Install-m644 foo.8 ${RPM_BUILD_ROOT} /% {_ mandir} / man8/foo.8

% clean of the Spec file

% clean is used to clean up temporary files after build, mainly for fear that these old files will affect later compilation. The main thing is to delete $RPM_BUILD_ROOT and run make clean.

Example:

The code is as follows:

% clean

Rm-rf $RPM_BUILD_ROOT

Make clean

Scriptlets of the Spec file

These options allow you to dynamically use shell scripts to control installation and removal

% pre,%post is run as a script after the package is installed, note that it cannot be interacted with each other

% preun,%postun runs with script when the package is deleted

The code is as follows:

Rpm-Q-scripts packagename # can see the information of the script

For example:

The code is as follows:

% pre

Groupadd-g 201 foo

Useradd-g foo-s / bin/false-d / var/foo-M foo

% post

/ sbin/ldconfig

Chkconfig-add food

% preun

If [= 0]

Then

Service food stop > / dev/null 2 > & 1

Chkconfig-del food

Fi

% postun

If [= 0]

Then

Userdel foo

Groupdel foo

Else

/ sbin/ldconfig

Service food condrestart > / dev/null 2 > & 1

Fi

Note that the number in this, if 1 means first installation, if 2 means maybe upgrade. If 0 is in% postun, it is completely deleted.

% files of the Spec file

% files any packaged file needs to be in the detailed file list of this package. If it is a directory, all directories of the owner of the package are in the middle.% dir specifies an empty directory. You can use the

% files-f / tmp/dyanmic_filelist to specify a list of files. The default% config replaces the configuration and renames the original configuration to .rpmorig

If you don't want to modify it, use% config (noreplace) to name the new configuration file .rpmnew.

% defattr (mode,user,group)

% attr (mode,user,group) filename

% config profile

% doc document

Example:

The code is as follows:

% files

% defattr (-, root,root)

% config / etc/foo.conf # is specified to be useful for updates and deletions

/ usr/sbin/food

/ usr/bin/foo

The% doc README # directory is in / usr/share/doc/% {name} -% {version}

% doc / usr/share/man/man8/food.8

/ usr/share/foo/

% dir / var/lock/foo/ # empty directory

% changelog of the Spec file

% changelog is to record changes to the package, such as adding a new patch, changing the configuration, logging using data + "a% b% d% Y"

To display the log changes of the package, you can use rpm-q-changelog. Example:

The code is as follows:

% changelog

? Mon Aug 5 2002 Elvis Presley

Thank you for your reading, the above is the content of "how to make the source package as a rpm package under the Linux system". After the study of this article, I believe you have a deeper understanding of how to make the source package as a rpm package under the Linux system. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report