编写spec文件,将tar.gz文件制作为rpm包

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编写spec文件,将tar.gz文件制作为rpm包相关的知识,希望对你有一定的参考价值。

1.安装相关rpm-build包
2.编写相关的spec文件,以tengine-2.3.1为例子
tengine-2.3.1.spec文件内容如下:

%define name tengine
%define Version 2.3.1
Name: %name
Version: %Version
Release: 1%?dist
Summary:tengine rmp package production

Group: Applications/Archiving
License:  GPLv2
URL: https://tengine.taobao.org
Source0: https://tengine.taobao.org/download/%name-%Version.tar.gz

BuildRequires:  gcc
Requires: gcc gcc-c++ autoconf automake

%description
Custom tengine rpm package
%prep
rm -rf $RPM_BUILD_DIR/tengine-%Version
tar -xvf $RPM_SOURCE_DIR/tengine-%Version.tar.gz
%setup -q

%build
./configure --user=www-data --group=www-data --prefix=%_sysconfdir/nginx --sbin-path=%_sbindir/nginx --error-log-path=%_localst
atedir/log/nginx/error.log --conf-path=%_sysconfdir/nginx/nginx.conf --pid-path=/run/nginx.pid
make %?_smp_mflags

%install
make install DESTDIR=%buildroot

%clean
rm -rf %buildroot

%files
%defattr(-,root,root,-)
%_sbindir/nginx
%config(noreplace) %_sysconfdir/nginx/*

%doc

%changelog

其中自定义宏变量必须使用define来声明,其中默认的宏变量有如下:

%_sysconfdir ==> /etc 
%_prefix ==>  /usr 
%_localstatedir ==> /var 
%_exec_prefix ==>  %_prefix 
%_bindir ==> %_exec_prefix/bin 
%_lib ==> lib (lib64 on 64bit systems) 
%_libdir ==> %_exec_prefix/%_lib 
%_libexecdir==> %_exec_prefix/libexec 
%_sbindir ==> %_exec_prefix/sbin
%_sharedstatedir  ==> /var/lib
%_datadir  ==> %_prefix/share 
%_includedir ==> %_prefix/include 
%_oldincludedir ==> /usr/include 
%_infodir ==> /usr/share/info 
%_mandir ==> /usr/share/man 
%_initddir ==> %_sysconfdir/rc.d/init.d

%_topdir  %getenv:HOME/rpmbuild
%_builddir  %_topdir/BUILD 
%_rpmdir  %_topdir/RPMS 
%_sourcedir  %_topdir/SOURCES 
%_specdir  %_topdir/SPECS 
%_srcrpmdir  %_topdir/SRPMS
%_buildrootdir  %_topdir/BUILDROOT

详细参照https://docs.fedoraproject.org/en-US/packaging-guidelines/RPMMacros/#RPM_directory_macros

以上是关于编写spec文件,将tar.gz文件制作为rpm包的主要内容,如果未能解决你的问题,请参考以下文章

linux下制作安装rpm包的方法

制作RPM包

实验:将inotify-tools-3.14.tar.gz源码包做成rpm包

RPM包制作之Spec文件详解

Linux系统Yum仓库制作

mysql5.7制作rpm包spec文件