实例说明:源码包生成RPM格式

平台:Redhat 9.0系统
制作RPM包之前,先介绍一下/usr/src/redhat/下的几个目录:
BUILD目录:编译时存放临时文件
SOURCES目录:存放.tar.gz源码包
SPECS目录:存放spec文件
RPMS目录:存放打包好的rpm文件
SRPMS目录:存放src.rpm文件。

实例说明:
步骤1:利用http://bbs.lupaworld.com/thread-35011-1-1.html的方法,生成源码。
[root@localhost hello]# ls
源码程序:
aclocal.m4      config.h     config.status  configure.scan  hello.c  install-sh   Makefile.in    stamp-h1
autom4te.cache  config.h.in  configure      depcomp         hello.h  Makefile     missing
autoscan.log    config.log   configure.in   hello           hello.o  Makefile.am  mkinstalldirs


步骤2:把源码打包成.tar.gz格式。
[root@localhost hello]#cd ..
[root@localhost home]# tar cvf hello-1.0-3.tar.gz ./

步骤3:把源码包拷贝到/usr/src/redhat/SOURCES/
[root@localhost home]# cp hello-1.0-3.tar.gz /usr/src/redhat/SOURCES/

步骤4:进入到/usr/src/redhat/SPECS/目录下,编写文件”软件名-版本号-释出号.spec”
[root@localhost home]# cd /usr/src/redhat/SPECS/
[root@localhost SPECS]# vim hello-1.0-3.spec

内容:
Summary:Hello for linux    #简介rpm软件
Name:hello                                #软件名称
Version:1.0                                #版本号
Release:3                                        #释放号
Copyright:GPL                                #
Group:Application/System                
Source:hello-1.0-3.tar.gz                        #源码包,如hello-1.0-3.i386.rpm        
Packager:zhull                                        #作者
Autoprov:yes
%description                                        #对软件描述
This package is a widget system form RPM building
%changelog
                                                                                
*Wed Apr 16 2008 Bowdar
- build for the first time
%prep                                              
#$RPM_SOURCE_DIR其实目录为/usr/src/redhat/SOURCES
#tar命令对#hello-1.0-3.tar.gz解压实现上解压到/usr/src/redhat/SOURCES
tar -zxvf $RPM_SOURCE_DIR/hello-1.0-3.tar.gz
%build                                                                                        #编译
cd $RPM_BUILD_DIR/hello                
./configure --prefix=/usr/local/hello
                                
Make
/***********************************************************************/
/*由于源码包中本来就有makefile文件了,所以此处不用./configure也没有关系,由于make
不用也是同样的道理。*/
/***************************************************************************/

%install                  
#将代码安装到指定的目录中
cd $RPM_BUILD_DIR/hello   #此处注意,hello为hello-1.0-3.tar.gz解压后的目录,此目录很重要
make install
install -m 755 hello /usr/local/bin   #把hello安装到/usr/local/bin目录下
%clean          #清除临时目录
rm -rf $RPM_BUILD_DIR/hello         #清除BUILD中的临时目录
%files
%defattr (-,root,root)                                                  #设置权限
/usr/local/bin
                                                                                #指定安装路径


以上蓝颜色内容可以省略,因为,源码包已经配置及编译过了

步骤5:编译并打包成RPM格式。
[root@localhost SPECS]# rpmbuild -ba hello-1.0-3.spec

显示内容:
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.7275
+ umask 022
+ cd /usr/src/redhat/BUILD
+ LANG=C
+ export LANG
+ tar -zxvf /usr/src/redhat/SOURCES/hello-1.0-3.tar.gz
./hello/
./hello/hello.c
./hello/hello.h
./hello/autoscan.log
./hello/configure.scan
./hello/aclocal.m4
./hello/configure.in
./hello/autom4te.cache/
./hello/autom4te.cache/requests
./hello/autom4te.cache/output.0
./hello/autom4te.cache/traces.0
./hello/configure
./hello/config.h.in
./hello/install-sh
./hello/Makefile.am
./hello/mkinstalldirs
./hello/missing
./hello/depcomp
./hello/Makefile.in
./hello/config.log
./hello/hello.o
./hello/config.status
./hello/hello
./hello/Makefile
./hello/config.h
./hello/stamp-h1
./hello/.deps/
./hello/.deps/hello.Po
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.20836
+ umask 022
+ cd /usr/src/redhat/BUILD
+ LANG=C
+ export LANG
+ cd /usr/src/redhat/BUILD/hello
+ ./configure --prefix=/usr/local/hello
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
+ make
make  all-am
make[1]: Entering directory `/usr/src/redhat/BUILD/hello'
make[1]: Leaving directory `/usr/src/redhat/BUILD/hello'
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.25120
+ umask 022
+ cd /usr/src/redhat/BUILD
+ LANG=C
+ export LANG
+ cd /usr/src/redhat/BUILD/hello
+ make install
make[1]: Entering directory `/usr/src/redhat/BUILD/hello'
/bin/sh ./mkinstalldirs /usr/local/hello/bin
  /usr/bin/install -c hello /usr/local/hello/bin/hello
make[1]: Nothing to be done for `install-data-am'.
make[1]: Leaving directory `/usr/src/redhat/BUILD/hello'
+ install -m 755 hello /usr/local/bin
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
Processing files: hello-1.0-3
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: /bin/bash libc.so.6 libc.so.6(GLIBC_2.0)
Checking for unpackaged file(s): /usr/lib/rpm/check-files %{buildroot}
Wrote: /usr/src/redhat/SRPMS/hello-1.0-3.src.rpm
Wrote: /usr/src/redhat/RPMS/i386/hello-1.0-3.i386.rpm

Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.28008
+ umask 022
+ cd /usr/src/redhat/BUILD
+ rm -rf /usr/src/redhat/BUILD/hello
+ exit 0

以上显示信息可以得到:
在/usr/src/redhat/SRPMS/目录下生成hello-1.0-3.src.rpm
在/usr/src/redhat/RPMS/i386目录下生成了hello-1.0-3.rpm


步骤6:在没有安装之前执行hello命令
[root@localhost SPECS]#hello

显示:
Hello world!

也就是说,不用对hello-1.0-3.i386.rpm包安装也可以运行了。Hello二进制文件在/usr/local/bin目录下,当rpmbuild时,就会生成的。现在我们用以下命令把hello二进制文件删除。
[root@localhost SPECS]#rm /usr/local/bin/hello

步骤7:然后,进入/ usr/src/redhat/RPMS/i386/目录。
[root@localhost SPECS]# cd /usr/src/redhat/RPMS/i386/

步骤8:安装rpm包。
[root@localhost i386]# rpm -ivh hello-1.0-3.i386.rpm
显示如下:
Preparing...                ########################################### [100%]
   1:hello                  ########################################### [100%]

[root@localhost i386]#hello

显示如下:
Hello,world!

说明这个安装包制作正确了。

步骤9:列出与hello有关的信息。
[root@localhost i386]# rpm -qi hello
显示内容:
Name        : hello                        Relocations: (not relocateable)
Version     : 1.0                               Vendor: (none)
Release     : 3                             Build Date: 2008年04月16日 星期三 21时37分33秒
Install Date: 2008年04月16日 星期三 21时38分36秒      Build Host: localhost.localdomain
Group       : Application/System            Source RPM: hello-1.0-3.src.rpm
Size        : 15841                            License: GPL
Signature   : (none)
Packager    : zhull
Summary     : Hello for linux
Description :
This package is a widget system form RPM building



步骤10:查看hello可执行程序的路径。
[root@localhost i386]# rpm -ql hello
显示内容:
/usr/local/bin
/usr/local/bin/hello



步骤11:卸载hello
[root@localhost i386]# rpm -e hello

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值