rpm 製作

RPM是RedHat Package Manager(RedHat軟件包管理工具)的縮寫,是一種用於互聯網下載包的打包及安裝工具,它包含在某些Linux分發版中。它生成具有.RPM擴展名的文件。使用rpm安裝軟件和管理軟件非常的方便。而這節我們不是介紹如何使用rpm安裝或管理軟件,而是如何把源碼製作成rpm包。

我們日常工作一般會使用源碼包安裝軟件,因爲源碼包相對靈活多變,操作自由,唯一的問題就是容易編譯出錯。rpm包安裝簡單方便,唯一問題就是不能自定義參數且更新的速度相對於源碼慢很多。


rpm軟件包製作

yum -y install gcc* rpm-build pcre-devel

mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}


SOURCES存放源代碼,補丁,圖標等文件

BUILD解壓後的文件存放在這裏

SPECS存放用於管理rpm製作進程的spec文件

RPMS存放由rpmbuild製作好的二進制包

SRPMS存放由rpmbuild製作好的源碼包


cd rpmbuild/SOURCES/

wget http://nginx.org/download/nginx-1.4.4.tar.gz


cd rpmbuild/SPECS/


例如:

vim nginx.spec


#軟件包簡要介紹

Summary: hellorpm is a test program。

#軟件包的名字

Name: hellorpm        

#軟件包的主版本號          

Version: 2.2.6          

#軟件包的次版本號            

Release: 1  

#源代碼包,默認將在上面提到的SOURCES目錄中尋找                        

Source0: %{name}-%{version}.tar.gz  

#授權協議

License: GPL    


#定義臨時構建目錄,這個地址將作爲臨時安裝目錄在後面引用

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

#軟件分類

Group: Development/Tools  

#軟件包的內容介紹              

%description                        

The hellorpm program is a test.

#表示預操作字段,後面的命令將在源碼代碼BUILD前執行

%prep                    

#構建BUILD環境,將解壓源碼壓縮包到BUILD目錄

%setup -q      

#BUILD字段,將通過直接調用源碼目錄中自動構建工具完成源碼編譯操作        

%build      

#調用源碼目錄中的configure命令            

./configure        

#在源碼目錄中執行自動構建命令make    

make            

#安裝字段        

%install    

#調用源碼中安裝執行腳本            

make DESTDIR=$RPM_BUILD_ROOT install

#文件說明字段,聲明多餘或者缺少都將可能出錯

%files              

#設置文件權限屬性      

%defattr(-,root,root)      

#聲明/usr/local/bin/hellorpm將出現在軟件包中      

/usr/local/bin/hellorpm      

#聲明並設置文件屬性  

%doc %attr(0444,root,root) /usr/local/man/man1/hellorpm.1  

#同上,聲明文檔文件

%doc README  


例如:vim nginx.spec

Name:nginx

Version:1.4.4

Release:1%{?dist}

Summary:nginx-1.4.4 from wenji


Group:Development/Tools

License:GPL

URL:http://nginx.org

Source0:%{name}-%{version}.tar.gz

Source1: nginx

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


#BuildRequires:

#Requires:


%description

Nginx is a http server


%prep

%setup -q



%build

./configure \

               --user=daemon --group=daemon --prefix=%{_prefix} --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-md5=/usr/lib --with-sha1=/usr/lib  --with-http_gzip_static_module

make %{?_smp_mflags}



%install

%{__rm} -rf $RPM_BUILD_ROOT

%{__make} DESTDIR=$RPM_BUILD_ROOT install

test -z %{buildroot}/etc/init.d/ || /bin/mkdir -p %{buildroot}/etc/init.d/

%{__install} -m 655 -p %{SOURCE1} $RPM_BUILD_ROOT/etc/init.d/nginx


%clean

%{__rm} -rf $RPM_BUILD_ROOT


%files

%defattr(-,root,root)

%{_prefix}

/etc/init.d/nginx


%postun

#if [ $1 -eq 0  ]

#then

rm -rfv %{_prefix}

rm -rfv /etc/init.d/nginx

#fi


%changelog



cd rpmbuild/SPECS/

rpmbuild -bb nginx.spec


###rpmbuild -ba ‘spec文件路徑’

###(rpmbuild常用參數: -bb 只編譯二進制rpm包 -bs 只編譯源碼rpm包 -ba 同時編譯二進制和源碼rpm包)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章