一、打包rpm包所需安装工具
1.yum install rpm-build
2.yum install rpmdevtools
二、制作过程
1.创建rpmbuild文件夹
rpmdev-setuptree
实际操作截图
2.打包源码程序到/rpmbuild/SOURCS下
1> 编写一个hello.c的源码
#include<stdio.h>
int main()
{
printf("hello woeld! My first rpm!\n");
return 0;
}
3.关于.spec文件的分析
Name:
Version:
Release: 1%{?dist}
Summary:
Group:
License:
URL:
Source0:
BuildRequires:
Requires:
%description
%prep
%setup -q
%build
%configure
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%files
%doc
%changelog
1>引言部分(the introduction section)
Name:
Version: //版本号
Release: 1%{?dist} //发行号
Summary:
Group: //软件包属于哪个组
License: //版本权
URL: //制作者
Source0: //rpm包使用的源文件
BuildRequires: //定义依赖关系
Requires:
%description //描述信息
2>准备部分(The prep section)
%prep
%setup -q //自动执行解压缩
3>构建部分(The build section)
%build
%configure
make %{?_smp_mflags} //_spm_mflags宏存在使用
4>安装部分(The install section)
%install
make install DESTDIR=%{buildroot}
5>清理部分
%clean
%{__rm} -rf %{buidroot}
6>文件部分(The files section)
%files
%defattr(-,root,root,0755)//定义文件权限
%doc //做文档使用
7>改变日志部分
%changelog
4.rpmbuild命令
-ba //既制作二进制又制作rpm格式
-bb //制作二进格式rpm包
-bc //执行到build部分
-bp //只执行到prep部分
-bi //只执行install部分
-bl //检查报错
-bs //制作成源码格式的二进制包
三、rpm包制作示例
1.将编写好的hello.c文件放入hello-1.0文件中,然后压缩成hello-1.0.tar.gz,然后cp到rpmbuild/SOURCE下
2.编写hello.spec文件
Name: hello
Version: 1.0
Release: 1
Summary: hello
License: GPL
Source0: hello-1.0.tar.gz
%description
%prep
%setup -q
%build
gcc -o hello hello.c
%install
install -m 777 hello /home/bxn/
%files
%doc
%changelog
3.编译生成rpm包
rpmbuild -ba ./rpmbuild/SPECS/hello.spec