linux makeinfo rpm,KDeveloper 下如何正确的生成RPM程序包?(高分求助)

小弟在KDeveloper下做了一个比较大的工程,调试运行斗都正常.现在急于将程序打包,生成可安装执行的程序.恳请高手指点迷津,不胜感激.

具体问题是: 1. KDeveloper下程序发布的基本步骤和技术细节;

2. spec文件的编写方法;

|

安裝套件:

rpm -i package-version.rpm

昇級套件:

rpm -U package-version.rpm

移除套件:

rpm -e package

註: 這裡不需 .rpm extension

展示套件所含之檔案:

rpm -qpl package-version.rpm

如果套件已安裝在系統中:

rpm -ql package

顯示 Linux 系統中所有 RPM 套件:

rpm -qa

追查檔案是屬那一套件的:

rpm -qf /full/path/to/the/file.ext

好了,我們現在便由一個簡單的 hellome.c 程式開始我們建做 RPM 套件過程。筆者使用的是 Red Hat Linux 7.0 環境,整個工作流程如下:

1. 使用 /usr/lib/rpm/rpmrc。這是 RPM build 的系統設定,初學者暫不需要更改它的設定。

2. 建造所需的 Makefile 及 source tarball

3. 進行對 source 所需的 patch,在這例子裏暫不需要。

4. 撰寫一份為包 RPM 所需的 spec 檔。

5. 使用 rpm 命令建造出套件包 (source 及 binary)

系統所需的軟體:

1. RPM

2. GNU C/C++ compiler

3. GNU Automake

4. GNU Autoconf

5. m4

6. Perl

7. GNU libtools

以上軟體大家在安裝 Red Hat Linux 選了 Development 這一組別時便有了。

STEP 1: 編輯 source code

我們的例子所用的 source code 只是非常簡單:

[barry@easytech hellome-1.0]$ more hellome.c

#include

main ()

{

printf("This is my first test for RPM

");

exit(0);

}

這個 C code 我們放在 hellome-1.0 的目錄內。

STEP 2: 編寫一個簡單的 README 檔在 hellome-1.0 目錄內:

[barry@easytech hellome-1.0]$ more README

This is just a test for RPM

This is a dummy README

STEP 3: 在 hellome-1.0 目錄中使用 autoscan 產生一個 configure.scan 檔

[barry@easytech hellome-1.0]$ autoscan

STEP 4: 編輯 configure.scan 檔

barry@easytech hellome-1.0]$ vi configure.scan

dnl Process this file with autoconf to produce a configure script.

AC_INIT(hellome.c)

AM_INIT_AUTOMAKE(hellome, 1.0)

dnl Checks for programs.

AC_PROG_CC

dnl Checks for libraries.

dnl Checks for header files.

dnl Checks for typedefs, structures, and compiler characteristics.

dnl Checks for library functions.

AC_OUTPUT(Makefile)

儲存此檔為 configure.in

STEP 5: 執行 aclocal,建立 acolocal.m4

[barry@easytech hellome-1.0]$ aclocal

STEP 6: 執行 autoconf,建立 configure

[barry@easytech hellome-1.0]$ autoconf

STEP 7: 編寫 Makefile.am,內容如下:

[barry@easytech hellome-1.0]$ more Makefile.am

AUTOMAKE_OPTIONS=foreign

bin_PROGRAMS=hellome

hellome_SOURCES=hellome.c

STEP 8: 執行 automake --add-missing,建做 Makefile.in

[barry@easytech hellome-1.0]$ automake --add-missing

STEP 9: 執行 ./configure 建造 Makefile.

[barry@easytech hellome-1.0]$ ./configure

creating cache ./config.cache

checking for a BSD compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

checking whether make sets ${MAKE}... yes

checking for working aclocal... found

checking for working autoconf... found

checking for working automake... found

checking for working autoheader... found

checking for working makeinfo... found

checking for gcc... gcc

checking whether the C compiler (gcc  ) works... yes

checking whether the C compiler (gcc  ) is a cross-compiler... no

checking whether we are using GNU C... yes

checking whether gcc accepts -g... yes

updating cache ./config.cache

creating ./config.status

creating Makefile

這便是 hellome-1.0 所有檔案了:

[barry@easytech hellome-1.0]$ ls

Makefile     README        config.log     configure.in    install-sh

Makefile.am  aclocal.m4    config.status  configure.scan  missing

Makefile.in  config.cache  configure      hellome.c       mkinstalldirs

STEP 10: 製造 tarball

[barry@easytech hellome-1.0]$ cd ..

[barry@easytech barry]$ tar cvfz hellome-1.0.tar.gz hellome-1.0

hellome-1.0/

hellome-1.0/configure.scan

hellome-1.0/hellome.c

hellome-1.0/README

hellome-1.0/aclocal.m4

hellome-1.0/configure.in

hellome-1.0/configure

hellome-1.0/install-sh

hellome-1.0/Makefile.am

hellome-1.0/mkinstalldirs

hellome-1.0/missing

hellome-1.0/Makefile.in

hellome-1.0/config.log

hellome-1.0/config.cache

hellome-1.0/config.status

hellome-1.0/Makefile

[barry@easytech barry]$

STEP 11: 將這 tarball 拷貝至 /usr/src/redhat/SOURCES

STEP 12: 在 /usr/src/redhat/SPEC 中建立 hellome-1.0.spec

[root@easytech SPECS]# more hellome-1.0.spec

Summary: My first example for RPM Building.

Name: hellome

Version: 1.0

Release: 1

Copyright: GPL

Group: Utilities/System

Source: hellome-1.0.tar.gz

Distribution: RedHat Linux

Vendor: EasyTech (http://www.easytech.com.hk)

Packager: Barry Kwok;

%description

This package is my first example for RPM build.

%changelog

* Thu May 30 2001 Barry Kwok

- build for the first time.

%prep

%setup

%build

%configure

make

%install

install -m 755 hellome /usr/local/bin/hellome

%files

%doc README

/usr/local/bin/hellome

[root@easytech SPECS]#

STEP 13: 在 /usr/src/redhat/SPEC 目錄中執行 rpm -ba 建立 source 及 binary RPM。

[root@easytech SPECS]# rpm -ba hellome-1.0.spec

我們所 build 的 source RPM 會放在 /usr/src/redhat/SRPMS 目錄內,而 binary RPM 則放在 /usr/src/redhat/RPMS 目錄內。

我們現在安裝這 RPM 來證明這套件包是否正確

[root@easytech /root]# cd /usr/src/redhat/RPMS/i386

[root@easytech i386]# rpm -ivh hellome-1.0-1.i386.rpm

hellome

##################################################

[root@easytech /root]# hellome

This is my first test for RPM

[root@easytech /root]#

[root@easytech /root]# rpm -qi hellome

Name : hellome Relocations: (not relocateable)

Version : 1.0 Vendor: EasyTech (http://www.easytech.com.hk)

Release : 1 Build Date: Wed May 30 18:23:30 2001

Install date: Wed May 30 18:28:34 2001 Build Host: easytech

Group : Utilities/System Source RPM: hellome-1.0-1.src.rpm

Size : 17698 License: GPL

Packager : Barry Kwok

Summary : My first example for RPM Building.

Description :

This package is my first example for RPM build.

[root@easytech /root]#

SUCCESS!

結語

我們以上的只是一個很簡單的例子,打包 RPM 最重要的是 spec 檔。學習編寫 spec 檔別無他法,唯有從其他現成的 spec 檔中「偷學」 過來。讀者如果所購買的是 Official Red Hat Linux,它便有一片 SOURCE RPM 的光碟。否則也可由 Red Hat 或 其它 mirror sites 中 FTP 過來。安裝這些 SPRMS 後便可由它的 spec 檔中學習它是怎樣 build 出 RPM 檔。正如其它新知識一樣,最重要的還是練習。

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

RPM資料室

RPM全名Red Hat Package Manager,顧名思意是Red Hat的套件管理系統,他負責安裝和移除軟件,function可說是與微軟視窗中的新增及移除相近。使用人在視窗中安裝軟件基本上是不需要用者費心,因為用家跟本沒有甚麼權力過問,亦不會預先知道將會有甚麼東西安裝在你的系統內。在RPM的管理下你可以知道一切有關安裝軟件的資料,更甚的是可以改變安位置,或只抽出一個部份來填補系統中的損壞部份。當然不想過問的人可以不需理會這些資料而直接安裝。

雖然是名為Red Hat Package Manager,由於是opensource的,其他的Distribution都採用了這個RPM。現在全球採用RPM的Distribution有超22個之多。

參考網站:http://www.rpm.org

擁有最大rpm存量的網站:http://www.rpmfind.net

|

自已好好写,不要以为Kdeveloper能帮你解决这个问题,Kdeveloper里面一样要自己写一些脚本和Makefile.am

我也用Kdeveloper,除了编码的时候他有很大帮助以外,其它控制编译,生成安装包的部分都是自己写脚本,别指望能象WINDOWS下一样傻瓜的东西出现了。

|

http://www-128.ibm.com/developerworks/cn/linux/management/package/rpm/part1/

|

http://www.rpm.org/support/RPM-HOWTO.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值