本文中的所有操作均在根用户下操作执行
第一步:安装rpm-build
yum -y install rpm-build
第二步:创建6个文件夹
mkdir -p /root/rpmbuild/{BUILD,BUILDROOT,\
SPECS,RPMS,SRPMS,SOURCES}
SOURCES:存放tar.gz包
BUILD:存放tar.gz解压的文件
BUILDROOT:rpm包的临时安装文件,放置执行文件和操作文档
RPMS:存放生成的rpm文件
SRPMS:存放生成的src.rpm文件
SPECS:存放spec文件
第三步,制作tar.gz压缩包,里面有helloworld.c文件、configure文件和readme文件
helloworld.c文件如下所示:
#include <stdio.h>
int main()
{
printf("hello world!\n");
return 0;
}
configure文件如下所示:
chmod u+x configure 赋予执行权限
#!/bin/bash
cat > Makefile <<EOF
all:helloworld
helloworld.o:helloworld.c
gcc -c helloworld.c
helloworld:helloworld.o
gcc helloworld.o -o helloworld
fresh:
rm -f Makefile
clean:
rm -f helloworld helloworld.o
install:
cp helloworld /usr/bin
uninstall:
rm -f /usr/bin/helloworld
EOF
readme文件一般放置软件的安装说明和功能解释。将3个文件放在helloworld文件夹,
tar czvf helloworld-0.1-1.tar.gz helloworld
将helloworld-0.1-1.tar.gz复制到SOURCES文件夹中。编写helloworld.spec文件
Summary:the first rpm
Name:helloworld
Version:0.1
Release:1%{?dist}
Vendor:john
License:Share
Group:Applications/Text
Source0:helloworld-0.1-1.tar.gz
#Patch0:hellow-0.1-1.patch
%description
rpm test helloworld
#描述信息
%prep
#安装前的准备工作解压文件
export RPM_SOURCES_DIR=/root/rpmbuild/SOURCES
export RPM_BUILD_DIR=/root/rpmbuild/BUILD
tar -xzvf $RPM_SOURCES_DIR/helloworld-0.1-1.tar.gz
#%patch -p0`
%build
cd $RPM_BUILD_DIR/helloworld
./configure #这一步会生成Makefile文件
make #编译
%install
cd $RPM_BUILD_DIR/helloworld
make install #链接
# el7 是因为我使用的是Centos7,6则为el6,8则为el8.
mkdir -p /root/rpmbuild/BUILDROOT/helloworld-0.1-1.el7.x86_64/usr/bin/
cp $RPM_BUILD_DIR/helloworld/helloworld /root/rpmbuild/BUILDROOT/helloworld-0.1-1.el7.x86_64/usr/bin/
%clean
rm -rf $RPM_BUILD_DIR/helloworld
%files
%defattr(-,root,root)
/usr/bin/helloworld
%doc $RPM_BUILD_DIR/helloworld/readme
然后执行helloworl.spec
rpmbuild -ba helloworld.spec
-ba 生城rpm和src.rpm
执行过后可以去RPM查看rpm包