Linux rpm build

Source: Internet
Author: User

The principle of rpm package creation is not complex. It can be understood as sorting out some information in a standard format, including basic software information and scripts executed before and after installation and uninstallation, decompress, patch, compile, and install the source code package.

1. Compile the spec File

1.1 spec script keywords

Name: the name of the software package, which can be referenced later in the form of % {Name}

Summary: Summary of the Package content

Version: the actual version of the software, such as 1.0.1, which can be referenced later by % {Version }.

Release: release serial number, such as 1linuxing, indicating the number of packages. It can be referenced later using % {Release }.

Group: Software Group. Standard Group is recommended.

License: Software authorization method, usually GPL

Source: Source code package, which can contain multiple sources such as Source1 and Source2, and can be referenced later by % {source1} and % {source2}

BuildRoot: this is the "virtual directory" used for installation or compilation. Considering the multi-user environment, it is generally defined:

% {_ Tmppath}/% {name}-% {version}-% {release}-root or % {_ tmppath}/% {name}-% {version}-% {release}-buildroot-% (% {__ id_u}-n} this parameter is very important, during the rpm generation process, the software will be installed to the above path when you execute make install. During packaging, it also relies on "virtual directory" as "root directory" for operations. You can reference it later using the $ RPM_BUILD_ROOT method.

URL: home page of the software

Vendor: information of a publisher or package organization, such as RedFlag Co, Ltd

Disstribution: Release ID

Patch: Patch source code. Multiple patches can be identified using patch0 or % {patch0 }.

Prefix: % {_ prefix} is mainly used to solve the problem of installing the rpm package in the rpm package directory. In this way, you must define this identifier here and reference it when writing the % install script to re-specify the location during rpm installation.

Prefix: % {_ sysconfdir} is the same reason as above, but because % {_ prefix} refers to/usr, for other files, such as the configuration file in/etc, % {_ sysconfdir} is required.

Build Arch: indicates the compiled target processor architecture. The noarch identifier is not specified, but the default value is usually the content in/usr/lib/rpm/marcros.

Requires: name of the software package on which the rpm package depends. You can use >=or <=to indicate that the package is greater than or less than a specific version. For example:

Libpng-devel> = 1.0.20 zlib

※"> = "Must be separated by spaces, and different software names must be separated by spaces.

For example, PreReq, Requires (pre), Requires (post), Requires (preun), Requires (postun), and BuildRequires are all specified for dependencies of different stages.

Provides: specifies some specific features of the software for other RPMs to identify

Packager: package information

% Description

1.2 spec script subject description

% Prep preprocessing script

% Setup-n % {name}-% {version} decompress the source code package and set it

Usually decompress the package from/usr/src/asianux/SOURCES to/usr/src/asianux/BUILD/% {name}-% {version.

Generally, you can use % setup-c, but there are two cases: one is to compile multiple source code packages at the same time, second, the tar package name of the source code is inconsistent with the extracted directory. In this case, you need to use the-n parameter to specify it.

% Patch Patching

The common patch will be in the source code tar.gz package together or in the SOURCES directory. The general parameter is:

% Patch-p1 is performed with the Patch defined earlier.-p1 is the first directory to ignore the patch.

% Patch2-p1-B xxx. patch with the specified patch,-B is used to generate a backup file

◎ Add

Reference

% 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 the 0th source code files.

% Setup-c-n newdir: Specify the directory name newdir and generate 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 information during patching.

% Patch-T delete all output files generated during patching.

% Configure is not a keyword, but a standard macro command defined by rpm. Execute the configure configuration of source code.

Run the following command in the/usr/src/asianux/BUILD/% {name}-% {version} directory, parameters defined in/usr/lib/rpm/marcros are referenced.

Another non-standard writing method is to refer to the parameter customization in the source code, for example:

Reference CFLAGS = "$ RPM_OPT_FLAGS" CXXFLAGS = "$ RPM_OPT_FLAGS"./configure -- prefix =%{_ prefix}

% Build start build package

Make in the/usr/src/asianux/BUILD/% {name}-% {version} directory. Common Syntax:

Reference

Make % {? _ Smp_mflags} OPTIMIZE = "% {optflags }"

Are some optimization parameters, defined in/usr/lib/rpm/marcros

% Install start to install the software to the virtual root directory

Perform the make install operation in the/usr/src/asianux/BUILD/% {name}-% {version} directory. This is very important, because if the path here is incorrect, it will fail to find the file in % file below. Common Content:

% Makeinstall is not a keyword, but a standard macro command defined by rpm. You can also use a non-standard statement:

Reference

Make DESTDIR = $ RPM_BUILD_ROOT install

Or

Reference

Make prefix = $ RPM_BUILD_ROOT install

It should be noted that the % install here is mainly for the following % file service. Therefore, you can also use common system commands:

Reference

Install-d $ RPM_BUILD_ROOT/

Cp-a * $ RPM_BUILD_ROOT/

% Clean clear temporary files

The general content is:

Reference

["$ RPM_BUILD_ROOT "! = "/"] & Rm-rf "$ RPM_BUILD_ROOT"

Rm-rf $ RPM_BUILD_DIR/% {name}-% {version}

※Differentiate between $ RPM_BUILD_ROOT and $ RPM_BUILD_DIR:

$ RPM_BUILD_ROOT refers to the BuildRoot defined at the beginning, while $ RPM_BUILD_DIR usually refers to/usr/src/asianux/BUILD. In this example, the preceding content is required by % file.

% Pre rpm script executed before installation

% Post rpm script executed after installation

% Preun rpm script executed before uninstallation

% Postun rpm script executed after uninstalling

What is the difference between % preun % postun?

The former will be executed during the upgrade, and the latter will not be executed during the upgrade of the rpm package

% Files defines which files or directories will be placed in rpm

This will be performed in the virtual root directory. Do not write absolute paths, and apply macros or variables to indicate relative paths. If it is described as a directory, it indicates all the files except % exclude in the directory.

% Defattr (-, root, root) specifies the properties of the packaging file, namely (mode, owner, group).-indicates the default value. For text files, the value is 0644, And the executable file is 0755.

% Exclude list files that do not want to be packaged into rpm

※Be careful. If the file specified by % exclude does not exist, an error will also occur.

% Changelog change log

1.3

2. Run rpmbuild for packaging

1) generate only rpm packages in binary format

Rpmbuild-bb xxx. spec

Use this command to generate a software package. After the package is executed, the screen displays the following information: (each line starts with a line number)

1 Executing: % prep 2 + umask 022 3

+ Cd/usr/src/dist/BUILD 4

+ Exit 0

5 Executing: % build 6

+ Umask 022 7

+ Cd/usr/src/dist/BUILD

The generated file will exist in the created RPM directory.

2) generate only the rpm package in src format

Rpmbuild-bs xxx. spec

The generated file will exist in the SRPM directory just created.

3) you only need to generate the complete source file

Rpmbuild-bp xxx. spec

The source file exists in the directory BUILD.

Readers may not understand this command. The purpose of this command is to unbind the tar package and merge all the patch files to generate a complete source file with the latest functions.

4) Complete Packaging

Rpmbuild-ba xxx. spec

Generate packages generated in the preceding three processes. Stored in the corresponding directory.

 

4. Appendix: Macro path

 

% {_ Sysconfdir}/etc

% {_ Prefix}/usr

% {_ Exec_prefix }%{_ prefix}

% {_ Bindir }%{_ exec_prefix}/bin

% {_ Lib} lib (lib64 on 64bit systems)

% {_ Libdir }%{_ exec_prefix}/% {_ lib}

% {_ Libexecdir} % {_ exec_prefix}/libexec

% {_ Sbindir }%{_ exec_prefix}/sbin

% {_ Sharedstatedir}/var/lib

% {_ Datadir }%{_ prefix}/share

% {_ Includedir }%{_ prefix}/include

% {_ Oldincludedir}/usr/include

% {_ Infodir}/usr/share/info

% {_ Mandir}/usr/share/man

% {_ Localstatedir}/var

% {_ Initddir} % {_ sysconfdir}/rc. d/init. d

Note: On releases older than Fedora 10 (and EPEL), % {_ initddir} does not exist. Instead, you shocould use the deprecated % {_ initrddir} macro.

 

RPM directory macros

% {_ Topdir }%{ getenv: HOME}/rpmbuild

% {_ Builddir }%{_ topdir}/BUILD

% {_ Rpmdir }%{_ topdir}/RPMS

% {_ Sourcedir }%{_ topdir}/SOURCES

% {_ Specdir} % {_ topdir}/SPECS

% {_ Srcrpmdir }%{_ topdir}/SRPMS

% {_ Buildrootdir }%{_ topdir}/BUILDROOT

Note: On releases older than Fedora 10 (and EPEL), % {_ buildrootdir} does not exist.

Build flags macros

 

% {_ Global_cflags}-O2-g-pipe

% {_ Optflags }%{__ global_cflags}-m32-march = i386-mtune = pentium4 # if redhat-rpm-config is installed

Other macros

% {_ Var}/var

% {_ Tmppath }%{_ var}/tmp

% {_ Usr}/usr

% {_ Usrsrc} % {_ usr}/src

% {_ Docdir }%{_ datadir}/doc

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.