• 利用src.rpm包修改源码后重新制作rpm包


    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/huv520@126/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个过程分别生成的包。存放在相应的目录下。

  • 相关阅读:
    读《大道至简》第一章有感
    jdk和jre的区别
    题解 LA2911
    题解 UVa11461
    题解 UVa10791
    题解 UVa11489
    题解 LA2889
    题解 UVa11609
    题解 UVa11076
    题解 UVa11752
  • 原文地址:https://www.cnblogs.com/Clisa/p/3906494.html
Copyright © 2020-2023  润新知