安装依赖
yum install -y rpm-build rpmdevtools
创建默认文件夹
# 清空历史文件夹
rm -rf ~/rpmbuild
# 重新创建文件夹
rpmdev-setuptree
默认文件夹结构
[root@4d689974a6c5 ~]# rm -rf ~/rpmbuild
[root@4d689974a6c5 ~]# rpmdev-setuptree
[root@4d689974a6c5 ~]# find ~/rpmbuild
/root/rpmbuild
/root/rpmbuild/RPMS
/root/rpmbuild/SOURCES
/root/rpmbuild/SPECS
/root/rpmbuild/SRPMS
/root/rpmbuild/BUILD
[root@4d689974a6c5 ~]#
准备软件 hello-world.sh
cat > ~/rpmbuild/BUILD/hello-world.sh <<EOF
#!/bin/bash
echo "Hello RPM World!"
EOF
准备 hello-world.spec
Name: hello-world
Version: %{?version}%{!?version:1}
Release: %{?release}%{!?release:1}%{?dist}
Summary: Most simple RPM package
License: Apache-2.0
%description
This is my first RPM package.
%prep
# This example has no source, so nothing here
%build
# Generate the script directly
echo "Generate hello-world"
%install
mkdir -p %{buildroot}/usr/bin/
install -m 755 hello-world.sh %{buildroot}/usr/bin/hello-world.sh
%files
/usr/bin/hello-world.sh
%changelog
# We will skip this for now
构建
Version=1.0.0
Release=21
rpmbuild -ba --define "version ${Version}" --define "release ${Release}" hello-world.spec
$ Version=1.0.0
$ Release=21
$ rpmbuild -ba --define "version ${Version}" --define "release ${Release}" hello-world.spec
warning: source_date_epoch_from_changelog set but %changelog is missing
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.iyvs7k
+ umask 022
+ cd /root/rpmbuild/BUILD
+ RPM_EC=0
++ jobs -p
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.jvmLGt
+ umask 022
+ cd /root/rpmbuild/BUILD
+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/anolis/anolis-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CFLAGS
+ CXXFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/anolis/anolis-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CXXFLAGS
+ FFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/anolis/anolis-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FFLAGS
+ FCFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/anolis/anolis-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FCFLAGS
+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/anolis/anolis-hardened-ld -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -Wl,--build-id=sha1 '
+ export LDFLAGS
+ LT_SYS_LIBRARY_PATH=/usr/lib64:
+ export LT_SYS_LIBRARY_PATH
+ CC=gcc
+ export CC
+ CXX=g++
+ export CXX
+ echo 'Generate hello-world'
Generate hello-world
+ RPM_EC=0
++ jobs -p
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.O9aez0
+ umask 022
+ cd /root/rpmbuild/BUILD
+ '[' /root/rpmbuild/BUILDROOT/hello-world-1.0.0-21.an23.x86_64 '!=' / ']'
+ rm -rf /root/rpmbuild/BUILDROOT/hello-world-1.0.0-21.an23.x86_64
++ dirname /root/rpmbuild/BUILDROOT/hello-world-1.0.0-21.an23.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT
+ mkdir /root/rpmbuild/BUILDROOT/hello-world-1.0.0-21.an23.x86_64
+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/anolis/anolis-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CFLAGS
+ CXXFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/anolis/anolis-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CXXFLAGS
+ FFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/anolis/anolis-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FFLAGS
+ FCFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/anolis/anolis-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FCFLAGS
+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/anolis/anolis-hardened-ld -specs=/usr/lib/rpm/anolis/anolis-annobin-cc1 -Wl,--build-id=sha1 '
+ export LDFLAGS
+ LT_SYS_LIBRARY_PATH=/usr/lib64:
+ export LT_SYS_LIBRARY_PATH
+ CC=gcc
+ export CC
+ CXX=g++
+ export CXX
+ mkdir -p /root/rpmbuild/BUILDROOT/hello-world-1.0.0-21.an23.x86_64/usr/bin/
+ install -m 755 hello-world.sh /root/rpmbuild/BUILDROOT/hello-world-1.0.0-21.an23.x86_64/usr/bin/hello-world.sh
+ '[' '%{buildarch}' = noarch ']'
+ QA_CHECK_RPATHS=1
+ case "${QA_CHECK_RPATHS:-}" in
+ /usr/lib/rpm/check-rpaths
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/anolis/brp-ldconfig
+ COMPRESS='zstd -f --rm -19 -T0'
+ COMPRESS_EXT=.zst
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip /usr/bin/strip
+ /usr/lib/rpm/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/anolis/brp-strip-lto /usr/bin/strip
+ /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/check-rpaths
+ /usr/lib/rpm/brp-remove-la-files
+ /usr/lib/rpm/anolis/clean_perl
+ /usr/lib/rpm/anolis/check_elf_files
+ /usr/lib/rpm/anolis/brp-mangle-shebangs
mangling shebang in /usr/bin/hello-world.sh from /bin/bash to #!/usr/bin/bash
+ /usr/lib/rpm/anolis/remove-info-dir
+ /usr/lib/rpm/anolis/check-desktop-files
+ env -u SOURCE_DATE_EPOCH /usr/lib/rpm/anolis/brp-python-bytecompile '' 1 0 -j8
+ /usr/lib/rpm/anolis/brp-python-hardlink
Processing files: hello-world-1.0.0-21.an23.x86_64
Provides: hello-world = 1.0.0-21.an23 hello-world(x86-64) = 1.0.0-21.an23
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: /usr/bin/bash
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/hello-world-1.0.0-21.an23.x86_64
Wrote: /root/rpmbuild/SRPMS/hello-world-1.0.0-21.an23.src.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/hello-world-1.0.0-21.an23.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.cm5cWw
+ umask 022
+ cd /root/rpmbuild/BUILD
+ /usr/bin/rm -rf /root/rpmbuild/BUILDROOT/hello-world-1.0.0-21.an23.x86_64
+ RPM_EC=0
++ jobs -p
+ exit 0
Executing(rmbuild): /bin/sh -e /var/tmp/rpm-tmp.LFLLYC
+ umask 022
+ cd /root/rpmbuild/BUILD
+ RPM_EC=0
++ jobs -p
+ exit 0
source_date_epoch_from_changelog set but %changelog is missing
RPM build warnings:
$ find ~/rpmbuild
/root/rpmbuild
/root/rpmbuild/RPMS
/root/rpmbuild/RPMS/x86_64
/root/rpmbuild/RPMS/x86_64/hello-world-1.0.0-21.an23.x86_64.rpm
/root/rpmbuild/SOURCES
/root/rpmbuild/SPECS
/root/rpmbuild/SRPMS
/root/rpmbuild/SRPMS/hello-world-1.0.0-21.an23.src.rpm
/root/rpmbuild/BUILD
/root/rpmbuild/BUILD/hello-world.sh
/root/rpmbuild/BUILDROOT
多平台 CPU 制作、签名、CI/CD 流水线自动化制作