利用src.rpm包修改源碼後重新製作rpm包

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   使用   os   io   

1. 下載 .src.rpm包。
例:https://repos.fedorapeople.org/repos/openstack/EOL/openstack-grizzly/epel-6/openstack-quantum-2013.1.4-4.el6.src.rpm

2. 使用" rpm -ivh "解壓源碼包。
例:rpm -ivh openstack-quantum-2013.1.4-4.el6.src.rpm  (--root=xxx 指定路徑)
解壓的結果放在 /root/rpmbuild/ 下面。

3.(optional) 檢查解壓檔案。
例:cd /root/rpmbuild/SPECS/
ls openstack-quantum.spec

4.(optional) 修改原始碼。

5. 使用 rpmbuild 打包。(註:如果沒有rpmbuild命令,請從CentOS光碟片鏡像安裝: yum install rpm-build 如果有相關依賴包未安裝,一併安裝:yum install python2-devel, yum install dos2unix )
例: rpmbuild -ba openstack-quantum.spec (--define "_topdir xxx/root/rpmbuild" 指定buildroot)
  

------------------------------------------------------------------------------------------------------

附:rpmbuild命令的詳解  <轉自http://blog.163.com/[email protected]/blog/static/27765239200992110163786/>

Usage: rpmbuild [OPTION...]
*使用命令:rpmbuild ·[OPTION]
Build options with [ <specfile> | <tarball> | <source package> ]:
*建立包的選項有:[ 從檔案<specfile>建立 |從 <tarball>包建立 |從 <source package>包建立]
*從檔案<specfile>建立

  -bp      build through %prep (unpack sources and apply patches) from <specfile>
              * -bp 從<specfile>檔案的%prep段開始建立(解開源碼包並打補丁)
  -bc      build through %build (%prep, then compile) from <specfile>
              *-bc 從<specfile>檔案的%build
  -bi       build through %install (%prep, %build, then install) from <specfile>

  -bl       verify %files section from <specfile>
              *檢查<specfile>檔案的%files段
  -ba      build source and binary packages from <specfile>
              *建立源碼和二進位包
  -bb      build binary package only from <specfile>
              *只建立二進位包
  -bs      build source package only from <specfile>
              *只建立源碼包

*從 <tarball>包建立

  -tp      build through %prep (unpack sources and apply patches) from <tarball>

  -tc      build through %build (%prep, then compile) from <tarball>

  -ti       build through %install (%prep, %build, then install) from <tarball>

  -ta      build source and binary packages from <tarball>
             *建立源碼和二進位包
  -tb      build binary package only from <tarball>
             *只建立二進位包
  -ts      build source package only from <tarball>
             *只建立源碼包

*從 <source package>包建立

  --rebuild  
            build binary package from <source package>
             *建立二進位包
  --recompile
           build through %install (%prep, %build, then install) from <source package>


*rpmbuild的其他使用項

  --buildroot=DIRECTORY  override build root
                                          *確定以root目錄建立包
  --clean                           remove build tree when done
                                          *完成打包後清除BUILD下的檔案目錄
  --nobuild                       do not execute any stages of the build
                                          *不進行BUILD的階段
  --nodeps                       do not verify build dependencies
                                          *不檢查建立包時的關聯檔案
  --nodirtokens 
         generate package header(s) compatible with (legacy) rpm[23] packaging

  --rmsource                   remove sources when done
                                       *完成打包後清除sources
  --rmspec                      remove specfile when done
                                       *完成打包後清除specfile
  --short-circuit              skip straight to specified stage (only for c,i)
                                      *跳過
  --target=CPU-VENDOR-OS       
         override target platform
             *確定包的最終使用平台

Common options for all rpm modes:
*所有rpm都可使用的選項

  -D, --define=‘MACRO EXPR‘     define MACRO with value EXPR
                                               *預定義
  -E, --eval=‘EXPR‘          print macro expansion of EXPR
                                         *顯示大量EXPR擴充資訊
  --macros=<FILE:...>    read <FILE:...> instead of default file(s)
                                         *讀<FILE:...>檔案代替預設檔案
  --nodigest                   don‘t verify package digest(s)
                                         *不檢查包的說明資訊
  --nosignature              don‘t verify package signature(s)
                                        *不檢查包的簽名資訊
  --rcfile=<FILE:...>        read <FILE:...> instead of default file(s)
                                        *讀<FILE:...>檔案代替預設檔案
  -r, --root=ROOT           use ROOT as top level directory (default: "/")
                                        *使ROOT為最進階別的路徑
  --querytags                 display known query tags
                                       *顯示已知的有疑問的地方
  --showrc                      display final rpmrc and macro configuration
                                        *顯示最終的配置資訊
  --quiet                         provide less detailed output
                                        *提供少量的資訊
  -v, --verbose               provide more detailed output
                                        * 提供大量的詳細的資訊
  --version                     print the version of rpm being used
                                        *顯示rpm包的版本

Options implemented via popt alias/exec:
*附加選項

  --dbpath=DIRECTORY   use database in DIRECTORY
                                         
  --with=<option>          enable configure <option> for build
                                         *建立時允許配置的選項
  --without=<option>     disable configure <option> for build
                                        *建立時不允許配置的選項

Help options:
*協助選項

  -?, --help                    Show this help message
                                   * 顯示協助資訊
  --usage                       Display brief usage message
                                   *顯示使用方法的資訊

打包

如果想發布rpm格式的源碼包或者是二進位包,就要使用rpmbuild工具(rpm最新打包工具)。如果我們已經根據本地源碼包的成功編譯安裝而寫了spec檔案(該檔案要以.spec結束),那我們就可以建立一個打包環境,也就是分類樹的建立,一般是在/usr/src/redhat/目錄下建立5個目錄。它門分別是BUILD、SOURCE、SPEC、SRPM、RPM。其中BUILD目錄用來存放打包過程中的源檔案,SOURCE用來存放打包是要用到的源檔案和patch,SPEC用來存放spec檔案,SRPM、RPM分別存放打包產生的rpm格式的源檔案和二進位檔案。當然我們可以根據需要來選用不同的參數打包檔案,筆者總結如下3條。

1) 只產生二進位格式的rpm包

rpmbuild -bb xxx.spec

用此命令產生軟體包,執行後螢幕將顯示如下資訊:(每行開頭為行號)

 

1 Executing: %prep 2 + umask 022 3 + cd /usr/src/dist/BUILD 4 + exit 0 5 Executing: %build 6 + umask 022 7 + cd /usr/src/dist/BUILD

產生的檔案會在剛才建立的RPM目錄下存在。

2)只產生src格式的rpm包

rpmbuild -bs xxx.spec

產生的檔案會在剛才建立的SRPM目錄下存在。

3) 只需要產生完整的源檔案

rpmbuild -bp xxx.spec

源檔案存在目錄BUILD下。

讀者朋友可能對這個命令不太明白,這個命令的作用就是把tar包解開然後把所有的補丁檔案合并而產生一個完整的具最新功能的源檔案。

4) 完全打包

rpmbuild -ba xxx.spec

產生以上3個過程分別產生的包。存放在相應的目錄下。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.