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