RPM构建 – 源码编译

1. RPM构建 - 介绍
2. RPM构建 - SPEC文件参数解析
3. RPM构建 - 简单实例
4. RPM构建 – 源码编译

实例:下面源码,将iftop-0.17构建为rpm包。

  

1     构建目录结构

依照 rpmbuild 规范设定一个目录结构, 

[root@node0 rpmbuild]# ls
BUILD BUILDROOT  RPMS  SOURCES SPECS  SRPMS

 

2     准备要打包文件

将源代码(理想情况下应为一个 tar.gz压缩文件)复制到 SOURCES 目录中。如果有必要,重命名 tar压缩文件,以包含应用程序的版本号,便于与其他文件区分开。约定的命名格式为包-版本.tar.gz

 [root@node0SOURCES]# ls
iftop-0.17.tar.gz

 

3     Spec文件

在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

 

4     编译RPM

通过指定spec文件编译RPM包,命令如下:选项含义参加《RPM构建 - 介绍》 

[root@node0 SPECS]# rpmbuild -ba iftop.spec

 

5     测试RPM 

测试结果:

[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]#

---轻轻地我走了,正如我轻轻地来---

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YoungerChina

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值