安装rpm-build,rpmdevtools等工具
我的制作目录在 /root/rpmbuild/下,用户直接root
刚开始的目录文件如下,其他目录都是空的
SOURCES
│ └── helloworld-0.1-1.tar.gz
SPECS
│ └── helloworld.spec
tar中的文件内容如下
├── helloworld
│ ├── configure
│ ├── helloworld.c
│ └── readme
- helloword.c
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
- configue (chmod u+x ),就是makefile相关
#!/bin/sh
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
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
make
%install
cd $RPM_BUILD_DIR/helloworld
make install
%clean
rm -rf $RPM_BUILD_DIR/helloworld
%files
%defattr(-,root,root)
/usr/bin/helloworld
%doc $RPM_BUILD_DIR/helloworld/readme
第一次rpbuild会出现如下的错误
# rpmbuild -ba SPECS/helloworld.spec
%install
cd $RPM_BUILD_DIR/helloworld
make install
mkdir -p /root/rpmbuild/BUILDROOT/helloworld-0.1-1.el6.x86_64/usr/bin/
cp $RPM_BUILD_DIR/helloworld/helloworld /root/rpmbuild/BUILDROOT/helloworld-0.1-1.el6.x86_64/usr/bin/
- 验证rpm(rpm的安装,卸载)