目錄:
指定新的工作區_topdir
在工作區創建工作目錄
創建SPEC文件
建立源文件
編譯RPM包
查看生成的RPM包類容
安裝和卸載生成的RPM包
SPEC文件中的一些重要字段
_topdir
默認的工作區為/usr/src/RedHat
;通過配置文件rpmmacros
指定:
cat>>~/.rpmmacros<<end > %_topdir /root/helloworld > end
這個配置也可以用命令行
來指定:
rpmbuild --define "_topdir /root/helloworld"
mkdir -p /root/helloworld/{RPMS,SRPMS,BUILD,SOURCES,SPECS}
工作目錄解釋:
helloworld/SPECS/hello.spec
:
Summary: hello world rpm package Name: hello Version: 0.1 Release: 1 Source: %{name}-%{version}.tar.gz License: GPL Packager: amoblin Group: Application/System BuildRoot: %{_topdir}/root/ %description This is a software for making your life more beautiful! %prep rm -rf $RPM_BUILD_DIR/%{name}-%{version} zcat $RPM_SOURCE_DIR/%{name}-%{version}.tar.gz | tar -xv %build cd %{name}-%{version} gcc -o hello hello.c %install rm -rf %{buildroot} mkdir -p %{buildroot}/usr/local/bin/ cd %{name}-%{version} cp hello %{buildroot}/usr/local/bin/hello %files /usr/local/bin/hello
hello.c
:
#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
把源文件打包放到SOURCES
目錄下
mkdir -p hello-0.1 mv hello.c hello-0.1 tar czvf hello-0.1.tar.gz hello-0.1 mv hello-0.1.tar.gz /root/helloworld/SOURCES/
#編譯rpm rpmbuild -vv -ba helloworld/SPECS/hello.spec #或者通過命令行指定topdir編譯 rpmbuild --define "_topdir /root/helloworld" -vv -ba helloworld/SPECS/hello.spec #驗證SPEC rpmbuild --define "_topdir /root/helloworld" -vv -bl helloworld/SPECS/hello.spec
[root@localhost ~]# rpm -qpil helloworld/RPMS/i386/hello-0.1-1.i386.rpm
[root@localhost ~]# rpm -iv helloworld/RPMS/i386/hello-0.1-1.i386.rpm Preparing packages for installation... hello-0.1-1 [root@localhost ~]# hello Hello, World! [root@localhost ~]# rpm -ev hello-0.1-1
less /usr/share/doc/rpm-*/GROUPS
]install
的根目錄(在%build
階段之後). 默認的根目錄是 %{_topdir}/BUILDROOT/
prepare
准備階段調用的shell腳本build
編譯階段調用的shell腳本install
安裝階段候調用的shell腳本 pwd
目錄為/root/helloworld/BUILDBuildRoot
目錄下存在如何在Linux中創建RPM包? http://www.linuxidc.com/Linux/2012-05/60278.htm