制作GCC的RPM包


制作RPM包(for gcc)

注意事項:

制作RPM包最好不要使用ROOT用戶,以防止制作過程中不慎執行有害命令

需要安裝的依賴包:

$ yum install gcc rpm-build rpm-devel rpmlint make python bash coreutils diffutils patch rpmdevtools

STEP1:

執行如下命令生成工作區目錄:

$ rpmdev-setuptree

生成的工作區目錄結構如下:

Directory Usage
BUILD rpmbuild命令構建軟件的目錄
RPMS 用於存儲生成的rpm包
SOURCES 所有要用到的源文件(.src .conf)都放在這里,並在spec文件中用source引用
SPEC 用於存放.spec文件,spec文件是構建rpm包的主要腳本文件
SRPMS 用於存放.src.rpm文件,此文件無法直接使用,執行rpm -ivh會將源文件放到工作區目錄下,仍然需要執行.spec文件進行編譯

STEP2:

將要使用的源碼放到SOURCES目錄當中:

$ cd /root/rpmbuild/SOURCES
$ wget http://mirrors.ustc.edu.cn/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz

STEP3:

創建gcc.spec文件,編寫rpm包構建過程:

$ cd /root/rpmbuild/SPECS
$ vim gcc.spec
#gcc.spec
Summary: Install gcc
Name: gcc
Version: 4.8.5
Release: 1%{?dist}
License: GPL
Group: Development/Languages
Source0: gcc-4.8.5.tar.gz

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

BuildRequires: gcc-c++ tar libstdc++-devel

%define __debug_install_post   \
   %{_rpmconfigdir}/find-debuginfo.sh %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
%{nil}

%description
The gcc package contains the GNU Compiler Collection. This package installs
all compilers in /usr/local/gcc48 directory.

%prep
%setup -q

%build
./contrib/download_prerequisites
mkdir gcc-build-4.8.5
cd gcc-build-4.8.5
#$PWD/../configure --prefix=/usr/local/gcc48 --enable-checking=release --enable-languages=c,c++ --disable-multilib
$PWD/../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
%{__make} %{?_smp_mflags}

%install
%{__rm} -rf %{buildroot}
cd gcc-build-4.8.5
%{__make} install DESTDIR=%{buildroot}

%clean
%{__rm} -rf %{buildroot}

%pre

%post
echo "/usr/local/lib64" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig &> /dev/null

%postun

%files
%defattr(-, root, root, 0755)
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/lib64
/usr/local/libexec
/usr/local/share

%changelog
* Tue Apr 23 2019 lei.guo <lei.guo@funplus.com> - 4.8.5-2
- change
* Mon Apr 22 2019 lei.guo <lei.guo@funplus.com> - 4.8.5-1
- test

STEP4:

編譯生成二進制RPM包:

QA_RPATHS=0x0020 rpmbuild -bb gcc.spec

總結:

  • 這里簡單的介紹了制作gcc的rpm包的大致方法,詳細的rpm包制作過程見rpm包官方指導手冊
  • SPEC文件中_tmppath這類變量是其自帶的宏,想查看其真實的值可以使用如下命令:
rpmbuild --showrc | grep _prefix


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM