linux下rpm包的构建方法

说明

rpm包构建的前提是获取其源码或者源码包,如果可能尽量选择下载源码包src.rpm,原因是src.rpm中已经包含了构建rpm包所需的SPEC和SOURCES;

获取组件源码包的常用网站: http://rpm.pbone.net/      http://rpmfind.net/

构建rpm包基本步骤

1 解压src.rpm至当前目录

rpm -ivh xxx.src.rpm --define="_topdir `pwd`"

2 在当前目录下构建rpm

rpmbuild -bb SPECS/xxx.spec --define="_topdir `pwd`"

3 如果实在找不到src.rpm

  模仿已有的spec自己编写spec文件,Centos终端环境下直接执行vim xxx.spec会自动生成spec的基本目录结构

Name:
Version:
Release:        1%{?dist}
Summary:

Group:
License:
URL:
Source0:

BuildRequires:
Requires:

%description


%prep
%setup -q


%build
%configure
make %{?_smp_mflags}


%install
make install DESTDIR=%{buildroot}


%files
%doc


%changelog

备注:

rpmbuild 查看构建时的定义rpm宏

rpmbuild --showrc

其他用法可通过rpmbuild --help进行查询

[root@localhost centos-release]# rpmbuild --help
Usage: rpmbuild [OPTION...]

Build options with [ <specfile> | <tarball> | <source package> ]:
  -bp                           build through %prep (unpack sources and apply patches) from <specfile>
  -ba                           build source and binary packages from <specfile>
  -bb                           build binary package only from <specfile>
  -bs                           build source package only from <specfile>

  --recompile                   build through %install (%prep, %build, then install) from <source package>
  --buildroot=DIRECTORY         override build root
  --clean                       remove build tree when done
  --nobuild                     do not execute any stages of the build
  --nodeps                      do not verify build dependencies
  --nodirtokens                 generate package header(s) compatible with (legacy) rpm v3 packaging
  --noclean                     do not execute %clean stage of the build
  --nocheck                     do not execute %check stage of the build
  --rmsource                    remove sources when done
  --rmspec                      remove specfile when done
  --short-circuit               skip straight to specified stage (only for c,i)
  --target=CPU-VENDOR-OS        override target platform

Common options for all rpm modes and executables:
  -D, --define='MACRO EXPR'     define MACRO with value EXPR
  --undefine=MACRO              undefine MACRO
  -E, --eval='EXPR'             print macro expansion of EXPR
  --macros=<FILE:...>           read <FILE:...> instead of default file(s)
  --nodigest                    don't verify package digest(s)
  --nosignature                 don't verify package signature(s)
  --rcfile=<FILE:...>           read <FILE:...> instead of default file(s)
  -r, --root=ROOT               use ROOT as top level directory (default: "/")
  --dbpath=DIRECTORY            use database in DIRECTORY
  --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

Options implemented via popt alias/exec:
  --with=<option>               enable configure <option> for build
  --without=<option>            disable configure <option> for build
  --buildpolicy=<policy>        set buildroot <policy> (e.g. compress man pages)
  --sign                        generate GPG signature (deprecated, use command rpmsign instead)

Help options:
  -?, --help                    Show this help message
  --usage                       Display brief usage message

 

posted @ 2019-05-20 15:22  无边身尊者  阅读(939)  评论(0编辑  收藏  举报