Centos 制作rpm包

本文中的所有操作均在根用户下操作执行
第一步:安装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包

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值