1. RPM构建 - 介绍
2. RPM构建 - SPEC文件参数解析
3. RPM构建 - 简单实例
4. RPM构建 – 源码编译
实例:下面源码,将iftop-0.17构建为rpm包。
依照 rpmbuild 规范设定一个目录结构,
[root@node0 rpmbuild]# ls BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
将源代码(理想情况下应为一个 tar.gz压缩文件)复制到 SOURCES 目录中。如果有必要,重命名 tar压缩文件,以包含应用程序的版本号,便于与其他文件区分开。约定的命名格式为包-版本.tar.gz
[root@node0SOURCES]# ls iftop-0.17.tar.gz
在SPEC目录通过以下命令初始化spec文件:
[root@node0 SPECS]# rpmdev-newspec iftop.spec
根据具体情况进行修改,示例:请参照< RPM构建 - SPEC文件参数解析>
%define workdir /usr/bin Name: iftop Version: 0.17 Release: 1%{?dist} Summary: displaybandwidth usage on an interface by host Group: Development/System License: GPL URL: www.123456789.com Source0: %{name}-%{version}.tar.gz BuildRequires: bluez-libslibpcap byacc libpcap-devel Requires: bluez-libslibpcap byacc %description display bandwidth usage on an interface by host %prep %setup -q %build ./configure make %install make install prefix=$RPM_BUILD_ROOT/usr %clean rm -rf $RPM_BUILD_ROOT/ %files %defattr(0755,root,root) /usr/sbin/iftop %doc %attr(0444,root,root) /usr/man/man8/iftop.8.gz %changelog
通过指定spec文件编译RPM包,命令如下:选项含义参加《RPM构建 - 介绍》
[root@node0 SPECS]# rpmbuild -ba iftop.spec
测试结果:
[root@node0 x86_64]# ls /usr/bin/pybin.py ls: cannot access /usr/bin/pybin.py: No such fileor directory [root@node0 x86_64]# rpm -ivhpybin-0.0.1-1.el7.centos.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:pybin-0.0.1-1.el7.centos ################################# [100%] [root@node0 x86_64]# rpm -q pybin-0.0.1 pybin-0.0.1-1.el7.centos.x86_64 [root@node0 x86_64]# ls /usr/bin/pybin.py -al -rwxr-xr-x 1 root root 329 Nov 10 15:16/usr/bin/pybin.py [root@node0 x86_64]# rpm -e pybin-0.0.1 [root@node0 x86_64]# ls /usr/bin/pybin.py ls: cannot access /usr/bin/pybin.py: No such fileor directory [root@node0 x86_64]# rpm -q pybin-0.0.1 package pybin-0.0.1 is not installed [root@node0 x86_64]#
---轻轻地我走了,正如我轻轻地来---