使用rpmbuild制作rpm包

使用rpmbuild制作rpm包

这里以制作cmake-3.15.5为例,首先保证环境中安装有rpmbuild,其次下载cmake-3.15.5.tar.gz源代码包,下载地址见下spec文件。

  • rpmbuild –ba cmake.spec生成打包目录

这个命令可以在任意目录下执行,执行后会报如下错误

 

这里报错正常, 因为此时并没有cmake.spec文件,这个文件是需要我们手工编写的。

执行完成后会发现在/root目录下形成了rpmbuild目录.

如果没有在/root下形成,可以修改/usr/lib/cpm/macros文件中的_topdir宏,这里不再过多解释.

 

关于rpmbuild目录的结构含义这里不过多解释。

  • vi ~/rpmbuild/SPECS/cmake.spec 自动生成spec模板文件,并填写相关字段,现给出我的spec文件
#
# spec file for package cmake
#
# Copyright (c) 2020 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

%define version 3.15.5

Name:            cmake
Version:                %{version}
Release:                1
License:                GPL
Summary:                cmake tools
# Url:
# Group:
Source:                 https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5.tar.gz
# Patch:
# BuildRequires:
# PreReq:
# Provides:
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description

%prep
%setup -q

%build
./configure
make %{?_smp_mflags}

%install
make install DESTDIR=%{buildroot} %{?_smp_mflags}

%post

%postun

%files

关于spec文件的具体字段含义这里不过多解释。

  • 执行 rpmbuild ~/rpmbuild/SPECS/cmake.spec

接下来是比较长的编译和安装过程,当完成后会发现在BUILD目录下有cmake-3.15.5.tar.gz的解压后的文件夹,BUILDTOOR目录下有已经被安装完成的cmake的文件

  • 解析rpm包

rpm –qpl *.rpm    # 列出rpm包包含的内容

rpm2cpio *.rpm | cpio –div    # 解压rpm包

猜你喜欢

转载自www.cnblogs.com/tongyishu/p/12294523.html