rpmbuild 底层原理
Preparing to build RPMs
The main tasks in building RPMs are:
Planning what you want to build
- 应用软件
- 二进制程序、程序库
- 一堆系统配置文件
- 文档包
- 创建一个二进制RPM或者是一个src.rpm包
- tar.gz,spec
- 手动去编译
Gathering the software to package
Patching the software as needed
Creating a reproducible build of the software
Planning for upgrades
Outlining any dependencies(Spec文件)
Building the RPMs
Set up the directory structure(禁止使用root用户)
- BUILD 源代码解压后放的位置,只需要提供这个目录
- RPMS 制作完成后的rpm包存放目录,里面还有子目录i386,交叉编译,noarch没有平台限制
- SOURCES 原材料,tar.gz、补丁、配置文件
- SPECS 存放spec文件,nginx.spec
- SRPMS src格式的rpm包,src.rpm官方提供
yum install rpm-build
[root@oe-20-03-LTS ~]# rpmbuild --help Usage: rpmbuild [OPTION...]Build options with [ <specfile> | <tarball> | <source package> ]:-bp build through %prep (unpack sources and apply patches) from <specfile>-bc build through %build (%prep, then compile) from <specfile>-bi build through %install (%prep, %build, then install) from <specfile>-bl verify %files section from <specfile>-ba build source and binary packages from <specfile>-bb build binary package only from <specfile>-bs build source package only from <specfile>-rp build through %prep (unpack sources and apply patches) from <sourcepackage>-rc build through %build (%prep, then compile) from <source package>-ri build through %install (%prep, %build, then install) from <source package>-rl verify %files section from <source package>-ra build source and binary packages from <source package>-rb build binary package only from <source package>-rs build source package only from <source package>-tp build through %prep (unpack sources and apply patches) from <tarball>-tc build through %build (%prep, then compile) from <tarball>-ti build through %install (%prep, %build, then install) from <tarball>-ta build source and binary packages from <tarball>-tb build binary package only from <tarball>-ts build source package only from <tarball>--rebuild build binary package from <source package>--recompile build through %install (%prep, %build, then install) from <source package>--buildroot=DIRECTORY override build root--build-in-place run build in current directory--clean remove build tree when done--nobuild do not execute any stages of the build--nodeps do not verify build dependencies--nodirtokens generate package header(s) compatible with (legacy) rpm v3 packaging--noclean do not execute %clean stage of the build--noprep do not execute %prep stage of the build--nocheck do not execute %check stage of the build--rmsource remove sources when done--rmspec remove specfile when done--short-circuit skip straight to specified stage (only for c,i)--target=CPU-VENDOR-OS override target platformCommon options for all rpm modes and executables:-D, --define='MACRO EXPR' define MACRO with value EXPR--undefine=MACRO undefine MACRO-E, --eval='EXPR' print macro expansion of EXPR--target=CPU-VENDOR-OS Specify target platform--macros=<FILE:...> read <FILE:...> instead of default file(s)--noplugins don't enable any plugins--nodigest don't verify package digest(s)--nosignature don't verify package signature(s)--rcfile=<FILE:...> read <FILE:...> instead of default file(s)-r, --root=ROOT use ROOT as top level directory (default: "/")--dbpath=DIRECTORY use database in DIRECTORY--querytags display known query tags--showrc display final rpmrc and macro configuration--quiet provide less detailed output-v, --verbose provide more detailed output--version print the version of rpm being usedOptions implemented via popt alias/exec:--with=<option> enable configure <option> for build--without=<option> disable configure <option> for build--buildpolicy=<policy> set buildroot <policy> (e.g. compress man pages)--sign generate GPG signature (deprecated, use command rpmsign instead)--nodebuginfo do not generate debuginfo for this packageHelp options:-?, --help Show this help message--usage Display brief usage message [root@oe-20-03-LTS ~]#
rpm宏查看 rpmbuild --showrc
[root@oe-20-03-LTS ~]# rpmbuild --showrc ARCHITECTURE AND OS: build arch : aarch64 compatible build archs: aarch64 noarch build os : Linux compatible build os's : Linux install arch : aarch64 install os : Linux compatible archs : aarch64 aarch64_ilp32 noarch compatible os's : LinuxRPMRC VALUES: archcolor : 2 optflags : -O2 -gFeatures supported by rpmlib:rpmlib(BuiltinLuaScripts) = 4.2.2-1rpmlib(CompressedFileNames) = 3.0.4-1rpmlib(ConcurrentAccess) = 4.1-1rpmlib(ExplicitPackageProvide) = 4.0-1rpmlib(FileCaps) = 4.6.1-1rpmlib(FileDigests) = 4.6.0-1rpmlib(HeaderLoadSortsTags) = 4.0.1-1rpmlib(LargeFiles) = 4.12.0-1rpmlib(PartialHardlinkSets) = 4.0.4-1rpmlib(PayloadFilesHavePrefix) = 4.0-1rpmlib(PayloadIsBzip2) = 3.0.5-1rpmlib(PayloadIsLzma) = 4.4.2-1rpmlib(PayloadIsXz) = 5.2-1rpmlib(PayloadIsZstd) = 5.4.18-1rpmlib(RichDependencies) = 4.12.0-1rpmlib(ScriptletExpansion) = 4.9.0-1rpmlib(ScriptletInterpreterArgs) = 4.0.3-1rpmlib(TildeInVersions) = 4.10.0-1rpmlib(VersionedDependencies) = 3.0.3-1Macro path: /usr/lib/rpm/macros:/usr/lib/rpm/macros.d/macros.*:/usr/lib/rpm/platform/%{_target}/macros:/usr/l ib/rpm/fileattrs/*.attr:/usr/lib/rpm/redhat/macros:/etc/rpm/macros.*:/etc/rpm/macros:/etc/rpm/%{_target}/macr os:~/.rpmmacros======================== -13: __7zip /usr/bin/7za -13: ___build_args -e -13: ___build_cmd %{?_sudo:%{_sudo} }%{?_remsh:%{_remsh} %{_remhost} }%{?_remsudo:%{_remsudo} }%{?_remc hroot:%{_remchroot} %{_remroot} }%{___build_shell} %{___build_args} -13: ___build_post exit $? -13: ___build_preRPM_SOURCE_DIR="%{u2p:%{_sourcedir}}"RPM_BUILD_DIR="%{u2p:%{_builddir}}"RPM_OPT_FLAGS="%{optflags}"RPM_LD_FLAGS="%{?__global_ldflags}"RPM_ARCH="%{_arch}"RPM_OS="%{_os}"export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_LD_FLAGS RPM_ARCH RPM_OSRPM_DOC_DIR="%{_docdir}"export RPM_DOC_DIRRPM_PACKAGE_NAME="%{NAME}"RPM_PACKAGE_VERSION="%{VERSION}"RPM_PACKAGE_RELEASE="%{RELEASE}"export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASELANG=Cexport LANGunset CDPATH DISPLAY ||:%{?buildroot:RPM_BUILD_ROOT="%{u2p:%{buildroot}}"export RPM_BUILD_ROOT}%{?_javaclasspath:CLASSPATH="%{_javaclasspath}"export CLASSPATH}PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:%{_libdir}/pkgconfig:%{_datadir}/pkgconfig"export PKG_CONFIG_PATHCONFIG_SITE=${CONFIG_SITE:-NONE}export CONFIG_SITE%{verbose:set -x}%{!verbose:exec > /dev/null}umask 022cd "%{u2p:%{_builddir}}" -13: ___build_shell %{?_buildshell:%{_buildshell}}%{!?_buildshell:/bin/sh} -13: ___build_template #!%{___build_shell} %{___build_pre} %{nil} -13: __aclocal aclocal -13: __ar ar -13: __arch_install_post %{nil} -13: __as as -13: __autoconf autoconf -13: __autoheader autoheader -13: __automake automake -13: __awk gawk -13: __brp_boot_efi_times /usr/lib/rpm/brp-boot-efi-times -13: __brp_compress %{_rpmconfigdir}/brp-compress -13: __brp_java_gcjcompile %{_rpmconfigdir}/brp-java-bytecompile -13: __brp_python_bytecompile %{_rpmconfigdir}/brp-python-bytecompile "" "%{?_python_bytecompile_errors_ter minate_build}" "%{?_python_bytecompile_extra}" -13: __brp_strip %{_rpmconfigdir}/brp-strip %{__strip} -13: __brp_strip_comment_note %{_rpmconfigdir}/brp-strip-comment-note %{__strip} %{__objdump} -13: __brp_strip_shared %{_rpmconfigdir}/brp-strip-shared -13: __brp_strip_static_archive %{_rpmconfigdir}/brp-strip-static-archive %{__strip} -13: __bzip2 /usr/bin/bzip2 -13: __bzr /usr/bin/bzr -13: __cat /usr/bin/cat -13: __cc gcc -13: __check_files %{_rpmconfigdir}/check-files %{buildroot} -13: __chgrp /usr/bin/chgrp -13: __chmod /usr/bin/chmod -13: __chown /usr/bin/chown -13: __cmake /usr/bin/cmake -13: __cmake_path ^(%{_libdir}|%{_datadir})/cmake/.*/.*(Config.cmake|-config.cmake)$ -13: __cmake_provides %{_rpmconfigdir}/cmake.prov -13: __cmake_requires %{_rpmconfigdir}/cmake.req -13: __cp /usr/bin/cp -13: __cpio /usr/bin/cpio -13: __cpp gcc -E -13: __cxx g++
vi .rpmmacros
%{_top_dir} /…
mkdir -pv rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
rpmbuild --showrc | grep _topdir
Place the sources in the right directory
Create a spec file that tells the rpmbuild command what to do
.spec格式文件
rpm -qi httpd
rrdtool
introduction section
Summary:
Name: 名字
Version: 版本2.4.2,不能使用横线
Release: 1%{?dist} 宏,制作者,rpm发型号
License: GPLv2,版权信息,正确版权信息
Group: 属于哪个组,事先定义好的,/usr/share/doc/rpm-4.4.2.3/GROUPS
URL: 制作者,从哪可以下载到,获取到,源码包下载路径
Packager: 制作者,制作者邮件地址
Vendor: 提供者,公司,开发者
Source: 下载链接找到这个软件包,绝对不是去下载
BuildRoot:
SOURCES目录源码包
.spec写好文件
BUILD目录
BUILDROOT目录当做根来用,编译好的程序安装到这个目录
%{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: 制作过程依赖哪些软件包
用于定义依赖关系的,制作过程依赖哪些软件安装包的
%description: 描述信息
多个自然段空行隔开
prep section 准备阶段 (不可少)
- %prep
- %setup自己解压缩
build section
%build
%{__make} %{?__smp_mflags}
install section 安装阶段(不可少)
%install
%{__rm} -rf %{buildroot}
%{__make} install DESTDIR="%{buildroot}"
%find_lang %{name}
clean section
%clean
%{__rm} -rf %{buildroot}
脚本段:
httpd
%pre
%post
%preun
%postun
files section 文件段(files段 列出的文件必须要一一对应BUILDROOT目录下的每一个文件,不能多也不能少)
%files -f %{name}.lang %defattr(-, root, root, 0755) %doc API CHANGES COPYING CREDITS README axelrc.example %doc %{_mandir}/main/axel.l* %doc %{_mandir}/*/main/axel.l* %config %{_sysconfdir}/axelrc /usr/local/bin/axel %attr(0755, root, root) /etc/rc.d/init.d/nginx
change log section 日志段,修改日志,改变日志段
%changelog * Wed Apr 11 2012 xxx.com <1@admin.com> - 1.0.14-1 - 注释 Initial version
Build the source and binary RPMs
rpmbuild command
-bp 执行到 %prep
-bi 执行到 %install
-bc 执行到 %build
-bb 执行到 制作二进制格式的rpm包
-bs 执行到 制作源码格式的rpm包
-ba 执行到 all,二进制格式的、源码格式的都制作
-bl 执行到 制作完成后,检测哪些文件在BUILDROOT目录下存在安装生成,但是却在制作rpm过程中在files段中没有给它包含到rpm包中,会帮忙检查报错,安装了却没包含rpm包会报错,包含进rpm包却没安装生成也会报错,双方必须要一一对应。
Testing the RPMs
rpmbuild -bp nginx.spec
如果报缺少依赖关系,yum给它装上执行build阶段
rpmbuild -bc nginx.spec执行install安装阶段
rpmbuild -bi nginx.spec
安装报错,没有文件,自己建立没有文件制作所有包
执行build all安装阶段
rpmbuild -ba nginx.spec
到RPMS目录
每一个RPM包都有一种capability能力
自身名字、提供的文件
编译依赖、安装依赖
如果有src.rpm包,直接 rpmbuild --rebuild 去制作,不用root用户
展开src.rpm包
rpm2cpio nginx-1.0.14-3.src.rpm | cpio -id
寻找rpm包的两个常用站点
rpmfind.net
rpmpone.com
你懂的:b站快速通道
rpmbuild 底层原理相关推荐
- 没有与参数列表匹配的 重载函数 getline 实例_面试题:方法重载的底层原理?...
前语:微信改版后,大量读者还没养成点赞的习惯,如写得好,望大家阅读后在右下边"好看"处点个赞,以示鼓励!长期坚持原创真的很不容易,多次想放弃,坚持是一种信仰,专注是一种态度. 关于 ...
- synchronized底层原理_你用过synchronized吗?它的底层原理是什么?Java经典面试题来了...
并发编程已经成为程序员必备技能 作为Java程序员,不懂得并发编程显然已经不能满足市场需求了,尤其是在面试过程中将处于被动地位,也有可能面试将就此终结. 那么作为Java开发者的你,日常虽然可以基于J ...
- iOS底层原理 - 常驻线程
iOS底层原理 - 常驻线程 在 AFN 2.0 时代,会经常看到 AFN 创建一个常驻线程的方式: 0️⃣ AFN 2.0 时代的常驻线程 + (NSThread *)networkRequestT ...
- elasticsearch原理_ElasticSearch读写底层原理及性能调优
ES写入/查询底层原理 1. Elasticsearch写入数据流程 客户端随机选择一个ES集群中的节点,发送POST/PUT请求,被选择的节点为协调节点(coordinating node) 协调节 ...
- 嘿嘿,我就知道面试官接下来要问我 ConcurrentHashMap 底层原理了,看我怎么秀他...
来自:烟雨星空 前言 上篇文章介绍了 HashMap 源码后,在博客平台广受好评,让本来己经不打算更新这个系列的我,仿佛被打了一顿鸡血.真的,被读者认可的感觉,就是这么奇妙. 原文:面试官再问你 Ha ...
- 面试官再问你 HashMap 底层原理,就把这篇文章甩给他看
来自:烟雨星空 前言 HashMap 源码和底层原理在现在面试中是必问的.因此,我们非常有必要搞清楚它的底层实现和思想,才能在面试中对答如流,跟面试官大战三百回合.文章较长,介绍了很多原理性的问题,希 ...
- 为了把mysql的索引底层原理讲清楚,我把计算机翻了个底朝天
来自:非科班的科班 什么是索引 概念:索引是提高mysql查询效率的数据结构.总的一句话概括就是索引是一种数据结构. 数据库查询是数据库的最主要功能之一.设计者们都希望查询数据的速度能尽可能的快,因此 ...
- 面试官:说说Spring Cloud底层原理?
点击上方"蓝字", 右上角选择"设为星标" 周一至周五上午11:45!精品文章准时送上! 本文转载自公众号:石杉的架构笔记 目录 一.业务场景介绍 二.Spri ...
- Go语言底层原理剖析
作者:郑建勋 出版社:电子工业出版社 品牌:博文视点 出版时间:2021-08-01 Go语言底层原理剖析
最新文章
- 演化理解 Android 异步加载图片
- 使用CURL构建爬虫,抓取百度百科内容
- BZOJ 1924 [Sdoi2010]所驼门王的宝藏
- 神经网络训练集最少可以是多少个?
- python计角_最小角python算法
- 使用Java进行查询hugegraph_HugeGraph Examples
- SAP在中国的发展和现状(培训公司欺诈推广)
- 【Java进阶】Eureka讲解与应用
- 解决scala对象转化为json对象为{}
- 《剑指offer》数组中重复的数字
- 在DOS下修改本机IP地址
- word图片靠右_如何设置word图片边缘透明
- 如何查看Hive版本
- Swift字符串多行的写法
- 四个开放源代码审查工具【图文】
- Ubuntu/Linux备份/还原系统
- ubuntu 16.04 安装谷歌拼音输入法
- 【内网学习笔记】14、发现主机缺失补丁
- 关于火车采集文章发布到wordpress后台待审核模块的设置
- mac android 模拟器启动,react-native使用脚本启动android模拟器(macos)