10. Rebuild a Source RPM (SRPM)

最後更新: 2021-10-25

目錄

  • Get SRPM
  • Prepare the RPM Building Environment
  • Rebuild the SRPM in One Step
  • Macros
  • Step by Step rebuild httpd
  • Compile httpd
  • Compile pure-ftpd

 


Get SRPM

 

CentOS SRPMs are available at:

http://vault.centos.org/

EPEL 的 SRPMs are available at:

https://dl.fedoraproject.org/

i.e.

http://vault.centos.org/4.5/os/SRPMS/

https://dl.fedoraproject.org/pub/epel/7/SRPMS/

 


Prepare the RPM Building Environment

 

yum install rpm-build -y

yum install autoconf -y

yum groupinstall "Development Tools" -y

 


Rebuild the SRPM in One Step

 

Syntax

rpmbuild --rebuild mypackage-1.0.0-1.src.rpm

i.e.

cd /usr/src

wget http://vault.centos.org/4.5/os/SRPMS/php-4.3.9-3.22.4.src.rpm

rpmbuild --rebuild php-4.3.9-3.22.4.src.rpm

Output rpm location:

/usr/src/redhat/RPMS/i386/

 


Macros

 

# Macros mimicking autoconf variables   

%{_sysconfdir}        /etc
%{_prefix}            /usr
%{_exec_prefix}       %{_prefix}
%{_bindir}            %{_exec_prefix}/bin
%{_libdir}            %{_exec_prefix}/%{_lib}
%{_libexecdir}        %{_exec_prefix}/libexec
%{_sbindir}           %{_exec_prefix}/sbin
%{_sharedstatedir}    /var/lib
%{_datarootdir}       %{_prefix}/share
%{_datadir}           %{_datarootdir}
%{_includedir}        %{_prefix}/include
%{_infodir}           /usr/share/info
%{_mandir}            /usr/share/man
%{_localstatedir}     /var
%{_initddir}          %{_sysconfdir}/rc.d/init.d

# Other macros and variables for paths

%{_var}               /var
%{_tmppath}           %{_var}/tmp
%{_usr}               /usr
%{_usrsrc}            %{_usr}/src
%{_lib}               lib (lib64 on 64bit multilib systems)
%{_docdir}            %{_datadir}/doc
%{buildroot}          %{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch}
$RPM_BUILD_ROOT       %{buildroot}

# RPM directory macros

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

# Other

%define contentdir /var/www
 


Step by Step rebuild httpd

 

1) 建立 .rpmmacros file (Optional)

It to instruct rpm to build in a directory off your home directory.

cd                                                 # 返回 ~

cat <<EOF > .rpmmacros
%HOME       %{expand:%%(cd; pwd)}
%_topdir    %{HOME}/rpmbuild
EOF

2) Create the rpm directory

mkdir rpmbuild; cd rpmbuild

mkdir BUILD RPMS SOURCES SPECS SRPMS

# Default rpmbuild 的 %_topdir

tree -L 1 /root/rpmbuild/

/root/rpmbuild/
├── SOURCES
└── SPECS

3) Install the SRPM Package

cd

wget http://vault.centos.org/4.5/os/SRPMS/httpd-2.0.52-32.ent.centos4.src.rpm

rpm -i httpd-2.0.52-32.ent.centos4.src.rpm

Remark

# Default Install 了 .src.rpm 後會有 %_topdir

tree -L 1 /root/rpmbuild/

/root/rpmbuild/
├── SOURCES
└── SPECS

4) Unpack & Patch Source

# Unpack the tarfiles into the BUILD tree and apply the patches in SOURCE to the BUILD tree,

# with a record of the steps taken saved in bp.log

# -bp               Executes the "%prep" stage from the spec file.

cd rpmbuild/SPECS

rpmbuild -bp httpd.spec

5) Build the binary .rpm package (Note 1):

# -bb                Build a binary package

rpmbuild -bb httpd.spec

 


Compile pure-ftpd

 

# 查看由那裡安裝

yum list | grep pure-ftpd

pure-ftpd.x86_64                         1.0.47-4.el7                 @epel

# 備 準備所需 Package

yum install mariadb-devel pam-devel openssl-devel selinux-policy-devel -y

# 修改 pure-ftpd.spec

[1] 拿走 "--with-capabilities"

%build
--with-capabilities

[2] 拿走 libcap

#BuildRequires:  pam-devel, perl, python, libcap-devel
BuildRequires:  pam-devel, perl, python

[3] 拿走對 openldap 及 postgresql 的依賴

%{!?_without_ldap:BuildRequires:  openldap-devel}
%{!?_without_pgsql:BuildRequires: postgresql-devel}

# Patch & Compile

rpmbuild -bb pure-ftpd.spec

rpmbuild -bb pure-ftpd.spec --without ldap --without pgsql

建立了

./RPMS/x86_64/pure-ftpd-1.0.47-4.el7.x86_64.rpm

# Force install

rpm -Uvh --force ./RPMS/x86_64/pure-ftpd-1.0.47-4.el7.x86_64.rpm

 

Creative Commons license icon Creative Commons license icon