rpmbuild
1. rpm是什么
RPM = RPM Package Manager = Redhat Package Manager
https://en.wikipedia.org/wiki/Rpm_(software)
2. two forks
1. RPM.org redhat 维护的,
This version is used by distributions such as Fedora, Red Hat Enterprise Linux and derivatives, openSUSE, SUSE Linux Enterprise, Unity Linux, Mageia[16], OpenEmbedded, Tizen and OpenMandriva Lx(formerly Mandriva).
2. RPM V5 红帽前雇员维护
This version is used by distributions such as Wind River Linux (until Wind River Linux 10), Rosa Linux, and OpenMandriva Lx (former Mandriva Linux which switched to rpm5 in 2011[17]) and also by the
OpenPKG project which provides packages for other common UNIX-platforms. OpenMandriva Lx is going to switch back to rpm.org[18] for 4.0 release. OpenEmbedded switched back to rpm.org due to issues in RPM5.[19]
3. 官网
http://rpm.org/
4. rpm packaging文档
https://rpm-packaging-guide.github.io/
高级用法:https://rpm-packaging-guide.github.io/#triggers-and-scriptlets
5. spec file 是 rpmbuild 的配置文件,配置rpmbuild的行为,以及定制rpm包的内容。
A SPEC file can be thought of as the "recipe" that the rpmbuild utility uses to actually build an RPM. It tells the build system what to do by defining instructions in a series of sections.
The sections are defined in the Preamble and the Body. The Preamble contains a series of metadata items that are used in the Body. The Body contains the main part of the instructions.
6。 查看各种默认宏的值
[root@D129 j-dpdk]# rpm --eval %{buildroot} /root/rpmbuild/BUILDROOT/%{name}-%{version}-%{release}.x86_64 [root@D129 j-dpdk]# rpm --eval %{_bindir} /usr/bin
查看设置和环境变量。
[root@test ~]# rpm --showrc
ARCHITECTURE AND OS:
build arch : x86_64
compatible build archs: x86_64 noarch
build os : Linux
... ...
7. 安装rpmdev tools。
其实不装也是可以的。这个工具包主要帮助编写spec文件。和配置等?
[root@D129 j]# yum install rpmdevtools
77. rpm包需要与systemd serivce联动。见 https://fedoraproject.org/wiki/Packaging:Systemd
8. quick start
8.1 用rpmdev-newspec工具生成一个空 spec 模板,或者到什么地方去随便考一个过来。
[root@D129 copyright]# man rpmdev-newspec
[root@D129 j]# rpmdev-newspec newpackage.spec created; type minimal, rpm version >= 4.11.
8.2 改 spec文件
写法可以读前边提到的文档,或者靠天分自己推理。
8.3 拷贝源代码的 gz tar包 到 $ROOT/rpmbuild/SOURCES
要求包名与解压后的文件夹名相同,且格式为 $NAME-$VERSION
rpmbuild在解压,找目录的时候,根据:定义在spec文件的Source变量:Source: http://dpdk.org/browse/dpdk/snapshot/%{name}-%{version}.tar.gz
如果不喜欢,也可以自己定义这个过程:https://rpm-packaging-guide.github.io/#setup
8.4 使用命令开始做包:
[root@D129 pkg]# rpmbuild -ba dpdk.spec
成功之后,生成的包,在这里:
[root@D129 pkg]# ll /root/rpmbuild/RPMS/x86_64/ total 3544 -rw-r--r-- 1 root root 2778612 Jul 13 21:14 dpdk-16.07-1.x86_64.rpm -rw-r--r-- 1 root root 147028 Jul 13 21:14 dpdk-debuginfo-16.07-1.x86_64.rpm -rw-r--r-- 1 root root 699036 Jul 13 21:14 dpdk-devel-16.07-1.x86_64.rpm [root@D129 pkg]# ll /root/rpmbuild/SRPMS/ total 16548 -rw-r--r-- 1 root root 16941800 Jul 13 21:14 dpdk-16.07-1.src.rpm
9. 最终,我是为dpdk打了个轻量的rpm包,做了些裁剪定制。修改过的内容如下:
dpdk.spec
Name: xxxx-dpdk Version: 16.07 Release: 1 Packager: packaging@6wind.com URL: http://dpdk.org Source: http://dpdk.org/browse/dpdk/snapshot/%{name}-%{version}.tar.gz Summary: Data Plane Development Kit core Group: System Environment/Libraries License: BSD and LGPLv2 and GPLv2 ExclusiveArch: x86_64 %global target %{_arch}-native-linuxapp-gcc %global config %{target} BuildRequires: kernel-devel, kernel-headers %description DPDK core includes kernel modules, core libraries and tools. testpmd application allows to test fast packet processing environments on x86 platforms. For instance, it can be used to check that environment can support fast path applications such as 6WINDGate, pktgen, rumptcpip, etc. More libraries are available as extensions in other packages. %package devel Summary: Data Plane Development Kit for development Requires: %{name}%{?_isa} = %{version}-%{release} %description devel DPDK devel is a set of makefiles, headers and examples for fast packet processing on x86 platforms. %prep %setup -q %build make O=%{target} T=%{config} config sed -ri 's,(RTE_APP_TEST=).*,\1n,' %{target}/.config sed -ri 's,(RTE_BUILD_SHARED_LIB=).*,\1y,' %{target}/.config sed -ri 's,(RTE_NEXT_ABI=).*,\1n,' %{target}/.config sed -ri 's,(LIBRTE_VHOST=).*,\1y,' %{target}/.config make O=%{target} %{?_smp_mflags} %install rm -rf %{buildroot} make install O=%{target} DESTDIR=%{buildroot} \ prefix=%{_prefix} bindir=%{_bindir} sbindir=%{_sbindir} \ includedir=%{_includedir}/dpdk libdir=%{_libdir} \ datadir=%{_datadir}/dpdk docdir=%{_docdir}/dpdk %files %dir %{_datadir}/dpdk %{_datadir}/dpdk/tools /lib/modules/%(uname -r)/extra/* %{_sbindir}/* %{_bindir}/* %{_libdir}/* %files devel %{_includedir}/dpdk %{_datadir}/dpdk/mk %{_datadir}/dpdk/scripts %{_datadir}/dpdk/%{target} %{_datadir}/dpdk/examples %post /sbin/ldconfig /sbin/depmod %postun /sbin/ldconfig /sbin/depmod