参考资料

https://docs-old.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html-single/RPM_Guide/index.html

http://ftp.rpm.org/max-rpm/

http://www.tldp.org/HOWTO/RPM-HOWTO/

RPM使用

# install packages
rpm -i foobar-1.0-1.i386.rpm # uninstall package
rpm -e foobar # get help
rpm --help #查找文件所属包
[root@~]$rpm -qf /etc/redis.conf
redis-3.2.10-2.el7.x86_64 #查看包相关文件
[root@~]$rpm -ql python
/usr/bin/pydoc
/usr/bin/python
/usr/bin/python2
/usr/bin/python2.7
/usr/share/doc/python-2.7.5
/usr/share/doc/python-2.7.5/LICENSE
/usr/share/doc/python-2.7.5/README
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/python2.1.gz
/usr/share/man/man1/python2.7.1.gz #查看包信息
[root@~]$rpm -qi python
Name : python
Version : 2.7.5
Release : 58.el7
Architecture: x86_64
Install Date: Mon 12 Feb 2018 09:51:04 PM CST
Group : Development/Languages
Size : 80827
License : Python
..... #查找相关包
[root@~]$rpm -q python
python-2.7.5-58.el7.x86_64 #罗列所有包
[root@~]$rpm -qa

SPEC File

demo

Summary: A program that ejects removable media using software control.
Name: eject
Version: 2.0.2
Release: 3
Copyright: GPL
Group: System Environment/Base
Source: http://metalab.unc.edu/pub/Linux/utils/disk-management/eject-2.0.2.tar.gz
Patch: eject-2.0.2-buildroot.patch
BuildRoot: /var/tmp/%{name}-buildroot %description
The eject program allows the user to eject removable media
(typically CD-ROMs, floppy disks or Iomega Jaz or Zip disks)
using software control. Eject can also control some multi-
disk CD changers and even some devices' auto-eject features. Install eject if you'd like to eject removable media using
software control. %prep
%setup -q
%patch -p1 -b .buildroot %build
make RPM_OPT_FLAGS="$RPM_OPT_FLAGS" %install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/bin
mkdir -p $RPM_BUILD_ROOT/usr/man/man1 install -s -m 755 eject $RPM_BUILD_ROOT/usr/bin/eject
install -m 644 eject.1 $RPM_BUILD_ROOT/usr/man/man1/eject.1 %clean
rm -rf $RPM_BUILD_ROOT %files
%defattr(-,root,root)
%doc README TODO COPYING ChangeLog /usr/bin/eject
/usr/man/man1/eject.1 %changelog
* Sun Mar 21 1999 Cristian Gafton <gafton@redhat.com>
- auto rebuild in the new build environment (release 3) * Wed Feb 24 1999 Preston Brown <pbrown@redhat.com>
- Injected new description and group. [ Some changelog entries trimmed for brevity. -Editor. ]

The Header段-基本描述信息

  • Summary: This is a one line description of the package.
  • Name: This must be the name string from the rpm filename you plan to use.
  • Version: This must be the version string from the rpm filename you plan to use.
  • Release: This is the release number for a package of the same version
  • Copyright: This line tells how a package is copyrighted. You should use something like GPL, BSD, MIT, public domain, distributable, or commercial.
  • Group: This is a group that the package belongs to in a higher level package tool or the Red Hat installer.
  • Source: This line points at the HOME location of the pristine source file. You can also specify more than one source file using lines like:
Source0: blah-0.tar.gz
Source1: blah-1.tar.gz
Source2: fooblah.tar.gz
  • Patch: This is the place you can find the patch if you need to download it again.
  • BuildRoot: This line allows you to specify a directory as the "root" for building and installing the new package.
  • %description It's not really a header item, but should be described with the rest of the header. You need one description tag per package and/or subpackage. This is a multi-line field that should be used to give a comprehensive description of the package.

%prep段

获取源码&准备构建。这个段的内容就是shell脚本

%setup

解压缩源码包,并cd到源码目录。可以携带如下参数:

  • -n name will set the name of the build directory to the listed name. The default is $NAME-$VERSION.

  • -c will create and cd to the named directory before doing the untar.

  • -b # will untar Source# before cd'ing into the directory.

  • -a # will untar Source# after cd'ing into the directory.

  • -T This option overrides the default action of untarring the Source and requires a -b 0 or -a 0 to get the main source file untarred. You need this when there are secondary sources.

  • -D Do not delete the directory before unpacking. This is only useful where you have more than one setup macro. It should only be used in setup macros after the first one (but never in the first one).

  • -q option is used to direct %setup to quiet its output. Verbose file listings won't be displayed when unpacking archives with this option.

%patch

对源码打补丁,可选参数如下:

  • # will apply Patch# as the patch file.
  • -p # specifies the number of directories to strip for the patch(1) command.
  • -P The default action is to apply Patch (or Patch0). This flag inhibits the default action and will require a 0 to get the main source file untarred. This option is useful in a second (or later) %patch macro that required a different number than the first macro.
  • You can also do %patch# instead of doing the real command: %patch # -P
  • -b extension will save originals as filename.extension before patching.

%build段

用于编译的shell脚本段。没有特殊宏。

%install段

用于安装的shell脚本段。没有特殊宏。$RPM_BUILD_ROOT 变量指向Buildroot

%clean段

clean build root

其他可选段

  • %pre is the macro to do pre-install scripts.
  • %post is the macro to do post-install scripts.
  • %preun is the macro to do pre-uninstall scripts.
  • %postun is the macro to do post-uninstall scripts.

常见的用途有在安装/卸载后允许ldconfig

%Files段

列出rpm包安装的文件。有一些宏可以使用

  • %doc is used to mark documentation in the source package that you want installed in a binary install. The documents will be installed in /usr/doc/$NAME-$VERSION-$RELEASE.
  • %config is used to mark configuration files in a package. If you later uninstall a package containing config files, any unchanged files will be removed and any changed files will get moved to their old name with a .rpmsave appended to the filename.
  • %dir marks a single directory in a file list to be included as being owned by a package. By default, if you list a directory name WITHOUT a %dir macro, EVERYTHING in that directory is included in the file list and later installed as part of that package.
  • %defattr allows you to set default attributes for files listed after the defattr declaration.
  • %files -f will allow you to list your files in some arbitrary file within the build directory of the sources.

%Changelog段

新的log用 * + date + name + email格式

打包

rpmbuild -ba foobar-1.0.spec

-b 相关参数

  • p means just run the prep section of the specfile.
  • l is a list check that does some checks on %files.
  • c do a prep and compile. This is useful when you are unsure of whether your source will build at all. It seems useless because you might want to just keep playing with the source itself until it builds and then start using RPM, but once you become accustomed to using RPM you will find instances when you will use it.
  • ido a prep, compile, and install.
  • b prep, compile, install, and build a binary package only.
  • abuild it all (both source and binary packages).
  • --short-circuit will skip straight to a specified stage (can only be used with c and i).
  • --clean removes the build tree when done.
  • --keep-temps will keep all the temp files and scripts that were made in /tmp. You can actually see what files were created in /tmp using the *-v* option.
  • --test does not execute any real stages, but does keep-temp.

    http://ftp.rpm.org/max-rpm/rpmbuild.8.html

RPM包构建的更多相关文章

  1. Linux下基于官方源代码RPM包构建自定义MySQL RPM包

    rpmbuild时不要以root用户执行! 方法一: 1.首先安装rpmbuild #yum install rpm-build gcc gcc-c++ cmake bison ncurses-dev ...

  2. RPM包制作过程(一)

    本机环境:centos7,64位 1. 首先安装工具,rpmbuild可能在rpmdevtools里已经包含 #yum install rpm-devel.x86_64 #yum install rp ...

  3. RPM 包的构建 - 实例

    打包目录 rpm 打包目录有一些严格的层次上的要求. rpm 的版本 <=4.4.x,rpmbuid 工具其默认的工作路径是 /usr/src/redhat.因为权限的问题,普通用户不能制作 r ...

  4. RPM 包的构建 - SPEC 基础知识

    spec 文件 制作 rpm 软件包并不是一件复杂的工作,其中的关键在于编写软件包的 spec 描述文件. 要想制作一个 rpm 软件包就必须写一个软件包描述文件 spec.这个文件中包含了软件包的诸 ...

  5. RPM包的制作

    RPM包的制作 前言 按照其软件包的格式来划分,常见的Linux发行版主要可以分为两类,类ReadHat系列和类Debian系列,这两类系统分别提供了自己的软件包管理系统和相应的工具. 类RedHat ...

  6. 根据某个文件或文件夹自制rpm包

    首先安装打包软件# yum install rpmbuild  rpmdevtools -y 生成打包路径1.使用rpmdev-setuptree ,会自动在用户家目录生成一个rpmbuild的文件夹 ...

  7. Centos 中如何快速定制二进制的内核RPM 包

    随着Linux服务器越来越多了,底层系统内核想要保持版本统一就需要定制专门的二进制安装包来便捷的升级和管理. RedHat系那当然就是使用rpmbuild来做定制化管理了. 今天我们分俩个部分(roo ...

  8. 手动制作rpm包

    制作RPM包的过程,简单的说,就是为制作过程提供一个“工作车间”,即一个目录,里面需要包含以下几个子目录: BUILD        ————编译相关源码包时的工作目录: RPMS         — ...

  9. centos 打包RPM包 ntopng

    需要在centos7上,将ntopng及其依赖的包一起打包成rpm包,了解centos7打包. 1.执行: yum -y install rpmdevtools  安装rpm工具 2.接下来执行:rp ...

随机推荐

  1. D类功放基础简介

    DAC和D类PA的开关时序是先开dac再开D类pa,先关D类pa再关dac

  2. 36:字符串排序SortString

    题目描述:编写一个程序,将输入字符串中的字符按如下规则排序. 规则1:英文字母从A到Z排列,不区分大小写. 如,输入:Type 输出:epTy 规则2:同一个英文字母的大小写同时存在时,按照输入顺序排 ...

  3. 配置mysql 编码

    配置mysql 编码 [client]default-character-set=utf8mb4 default-storage-engine=INNODB [mysql]default-charac ...

  4. GIT简单使用——多人协作篇

    多人协作的工作模式通常是这样:1.首先,可以试图用git push origin <branch-name>推送自己的修改:2.如果推送失败,则因为远程分支比你的本地更新,需要先用git ...

  5. Codeforces 558(C、D、E)总结

    558C 题意:给你n个数,可对每一个数进行操作(乘2或者除以2).求最少的操作使得全部的数都相等. 思路 : dp[ t ] 表示全部的数转化到 t 所需的最少操作, vis[ t ] 表示有多少数 ...

  6. x264代码剖析(十三):核心算法之帧间预測函数x264_mb_analyse_inter_*()

    x264代码剖析(十三):核心算法之帧间预測函数x264_mb_analyse_inter_*() 帧间预測是指利用视频时间域相关性,使用临近已编码图像像素预測当前图像的像素,以达到有效去除视频时域冗 ...

  7. 【WPF学习笔记】之如何点登录按钮时判断用户名密码进行登录:动画系列之(二)

    ...... 承接动画系列之(一)的代码: 再添加登录按钮代码进行登录,验证用户名和密码在数据库是否正确. 直接上代码: using System; using System.Collections. ...

  8. MySQL技术内幕InnoDB存储引擎(表&索引算法和锁)

    表 4.1.innodb存储引擎表类型 innodb表类似oracle的IOT表(索引聚集表-indexorganized table),在innodb表中每张表都会有一个主键,如果在创建表时没有显示 ...

  9. 目标跟踪之粒子滤波---Opencv实现粒子滤波算法

    目标跟踪学习笔记_2(particle filter初探1) 目标跟踪学习笔记_3(particle filter初探2) 前面2篇博客已经提到当粒子数增加时会内存报错,后面又仔细查了下程序,是代码方 ...

  10. 多媒体开发之---live555 分析客户端

    live555的客服端流程:建立任务计划对象--建立环境对象--处理用户输入的参数(RTSP地址)--创建RTSPClient实例--发出DESCRIBE--发出SETUP--发出PLAY--进入Lo ...