天天看點

源碼包制作成RPM包

源碼包制作成RPM包

第一步:首先安裝rpm-build軟體包:實作生成rpm包操作

[root@server1 ~]#rpm -qa | grep rpm-build

[root@server1 ~]#yum install -y rpm-build

第二步:制作httpd.spec檔案

注:必須普通使用者來做

[root@server1 ~]# useradd tom

[root@server1 ~]# su - tom

[tom@server1 ~]$ vim httpd.spec

[tom@server1 ~]$ cat httpd.spec

Name:       httpd              //程式名

Version:    2.2.25            //版本号

Release:    1%{?dist}

Summary:    compiled from 2.2.25 by zsp         //描述資訊,這個可以自定義寫

Group:      System  Environment/Daemons

License:    GPL

URL:        http://www.tarnea.com              //自定義該資訊

Source0:    httpd-2.2.25.tar.gz               //源檔案名稱,需和下面第四步對應,檔案名稱要一直

BuildRoot:  %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

BuildRequires:  gcc, gcc-c++, openssl-devel          //生成rpm包所需要的軟體支援

Requires:   wireshark-gnome                        //執行該rpm

%description

Apache web server. Compiled from  2.2.25 by zsp

%prep

%setup -q

%build

./configure  --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi  --enable-ssl --enable-charset-lite --enable-suexec --with-suexec-caller=daemon  --with-suexec-docroot=/usr/local/httpd/htdocs

make %{?_smp_mflags}

%install              //安裝之前需初始化安裝目錄

rm -rf %{buildroot}

make install DESTDIR=%{buildroot}

%clean

%files                    //安裝之後生成的檔案

%defattr(-,root,root,-)

/usr/local/httpd/bin/*

/usr/local/httpd/build/*

/usr/local/httpd/cgi-bin/*

%config  /usr/local/httpd/conf/*

/usr/local/httpd/error/*

/usr/local/httpd/htdocs/*

/usr/local/httpd/icons/*

/usr/local/httpd/include/*

/usr/local/httpd/lib/*

%dir  /usr/local/httpd/logs

%doc  /usr/local/httpd/man/*

%doc  /usr/local/httpd/manual/*

/usr/local/httpd/modules/*

%post                         //安裝之後需要執行的動作,将apachectl拷貝成myhttpd

cp  /usr/local/httpd/bin/apachectl /etc/init.d/myhttpd

sed -i '1a # chkconfig:  2345 85 15' /etc/init.d/myhttpd

sed -i '2a #  description: apache web server' /etc/init.d/myhttpd

chkconfig --add myhttpd

%preun                         //解除安裝該rpm包所執行的一些操作

/etc/init.d/myhttpd stop

chkconfig --del myhttpd

%changelog                       //定義一些日志檔案,可以使用:rpm -q  --changelog httpd檢視到

* Wed Mar 26 2014  zhangzhg <[email protected]> 2.2.25

- first rpm from  httpd-2.2.25

[tom@server1 ~]$

第三步:生成相關目錄

[tom@server1  ~]$ ls

httpd-2.2.25.tar.gz  httpd.spec

[tom@server1  ~]$ rpmbuild httpd.spec           //生成相關目錄,有錯誤類型的提示資訊,屬正常

error:  File /home/tom/rpmbuild/SOURCES/httpd-2.2.25.tar.gz: No such file or  directory      

httpd-2.2.25.tar.gz  httpd.spec   rpmbuild          //生成之後會出現rpmbuild目錄

[tom@server1  ~]$ ls rpmbuild/

BUILD  BUILDROOT   RPMS  SOURCES  SPECS   SRPMS       //rpmbuild目錄下有這六個目錄

第四步:把檔案拷貝到指定目錄

[tom@server1  ~]$ cp httpd.spec rpmbuild/SPECS/

[tom@server1  ~]$ cp httpd-2.2.25.tar.gz rpmbuild/SOURCES/

第五步:生成RPM包

[tom@server1 ~]$ rpmbuild -ba rpmbuild/SPECS/httpd.spec

如果無法執行,則可能會提示沒有安裝gcc、gcc-c++和openssl-devel軟體,退出tom使用者,執行yum安裝即可;[root@server1~]# yum install -y gcc gcc-c++ openssl-devel

安裝完成後,會在在RPMS目錄下生成rpm包,在SRPMS目錄下生成源碼包:

[tom@server1 ~]$ ls rpmbuild/RPMS/x86_64/

httpd-2.2.25-1.el6.x86_64.rpm

[tom@server1 ~]$ ls rpmbuild/SRPMS/

httpd-2.2.25-1.el6.src.rpm

第六步:測試新生成的RPM包

[root@server1  ~]# cp /home/tom/rpmbuild/RPMS/x86_64/httpd-2.2.25-1.el6.x86_64.rpm .

[root@server1  ~]# rpm -ivh httpd-2.2.25-1.el6.x86_64.rpm  

//由于在httpd.spec檔案中設定了依賴關系,是以安裝的時候會提示有wireshark-gnome的依賴,做這個設定為了驗證rpm制作時的依賴選項,是以,可以通過忽略依賴關系安裝。

error:  Failed dependencies:

   wireshark-gnome is needed by  httpd-2.2.25-1.el6.x86_64

[root@server1  ~]# rpm -ivh --nodeps  httpd-2.2.25-1.el6.x86_64.rpm       //忽略依賴關系安裝

Preparing...                 ########################################### [100%]

  1:httpd                   ########################################### [100%]

[root@server1  ~]# rpm -e --nodeps httpd-2.2.25-1.el6.x86_64

httpd  (no pid file) not running        

//由于沒有開啟myhttpd,而在httpd.spec檔案中設定了%preun 選項,是以會有提示說httpd沒有運作

[root@server1  ~]#

本文轉自 murongqingqqq  51CTO部落格,原http://blog.51cto.com/murongqingqqq/1396751文連結:

繼續閱讀