操作平台: fedora 29
需要的包
dnf install rpmdevtools rpmlint
示例源文件:
hello-2.10.tar.gz
使用 rpmdev-setuptree
创建编译所需要的目录, 会创建在当前用户的主目录下.
~/rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS
将源代码包放入 SOURCES
目录.
使用 rpmdev-newspec hello
在~/rpmbuild/SPECS
目录创建 .spec
文件.
~/rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
│ └── hello-2.10.tar.gz
├── SPECS
│ └── hello.spec
└── SRPMS
此时 hello.spec
内容为:
ame: hello
Version:
Release: 1%{?dist}
Summary:
License:
URL:
Source0:
BuildRequires:
Requires:
%description
%prep
%autosetup
%build
%configure
%make_build
%install
rm -rf $RPM_BUILD_ROOT
%make_install
%files
%license add-license-file-here
%doc add-docs-here
%changelog
* Sat May 11 2019 Nick
-
修改该说明文件. 然后在 ~/rpmbuild/SPECS/
用 rpmbuild -ba hello.spec
进行打包
注意事项有:
每一项后面不要为空.
所有需要安装的文件都要在该文件中有指定.
每一个文件要用 utf8 格式
Summary
首字母要大写
每一项中尽量使用变量来指代.
使用 #
进行注释. 注释行中不要有变量.
changelog
的格式也要注意, 前面的日期的格式也是固定的. 第一条 changelog
前面是 *
号, 最后要包含版本号 - 2.10-1
打包过程最好使用独立普通帐户进行操作.
本例中生成的文件如下:
~/rpmbuild/RPMS/x86_64/
hello-2.10-1.fc29.x86_64.rpm
hello-debuginfo-2.10-1.fc29.x86_64.rpm
hello-debugsource-2.10-1.fc29.x86_64.rpm
~/rpmbuild/SRPMS/
hello-2.10-1.fc29.src.rpm
最后使用 rpmlint hello.spec ../SRPMS/hello* ../RPMS/*/hello*
进行规范一致性检查.
更多说明见参考文献.
最终完成的无警告和错误的配置文件如下:
Name: hello
Version: 2.10
Release: 1%{?dist}
Summary: The "Hello World" program from GNU
License: GPLv3+
URL: https://www.gnu.org/software/%{name}
#Source0: https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz
Source0: http://files.git.oschina.net/group1/M00/07/A6/PaAvDFzWvNiAZPhOAAsWd2xzuuI7717.gz?token=587733e6cb3c40d6ffcbcf6535b494aa&ts=1557576946&disposition=attachment&attname=%{name}-%{version}.tar.gz
BuildRequires: gettext
Requires(post): info
Requires(preun): info
%description
The "Hello World" program, done with all bells and whistles of a proper FOSS
project, including configuration, build, internationalization, help files, etc.
%prep
%autosetup
%build
%configure
make %{?_smp_mflags}
%install
%make_install
%find_lang %{name}
rm -f %{buildroot}/%{_infodir}/dir
%post
/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || :
%preun
if [ $1 = 0 ] ; then
/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || :
fi
%files -f %{name}.lang
%{_mandir}/man1/hello.1.*
%{_infodir}/hello.info.*
%{_bindir}/hello
%license COPYING
%doc AUTHORS ChangeLog NEWS README THANKS TODO
%changelog
* Sat May 11 2019 test rpm build Nick - 2.10-1
- Thu Jul 07 2011 The Coon of Ty - 2.10-1
- Initial version of the package
[1]. https://developer.fedoraproject.org/deployment/rpm/about.html
[2]. https://fedoraproject.org/wiki/How_to_create_a_GNU_Hello_RPM_package
[3]. https://docs.fedoraproject.org/en-US/quick-docs/creating-rpm-packages/
[4]. https://blog.csdn.net/get_set/article/details/53453320