Your first RPM with rpmbuild on openEuler — a minimal spec built end to end (including the gotcha that %{?dist} expands to empty on openEuler)
Verification scope
Section titled “Verification scope”Evidence on this page comes from the container track (E2, build-type) — openeuler/openeuler:latest (online repos, 2026-11-05): toolchain installation, minimal-spec build, installing and running the home-grown RPM, release-tag observation. Raw log: evidence/logs/openeuler-rpmbuild-intro.log.
Five minutes end to end (the verified command surface)
Section titled “Five minutes end to end (the verified command surface)”dnf -y install rpm-build # rpmbuild --version → RPM version 4.18.2mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}The minimal spec (~/rpmbuild/SPECS/hello.spec, an equivalent form of the one verified on this page):
Name: hello-eulerVersion: 1.0Release: 1%{?dist}Summary: minimal rpmLicense: MIT
%descriptionminimal test package
%files/usr/bin/hello-euler
%installmkdir -p %{buildroot}/usr/binecho '#!/bin/shecho hello openEuler' > %{buildroot}/usr/bin/hello-eulerchmod +x %{buildroot}/usr/bin/hello-eulerBuilding and verifying (verified output):
$ rpmbuild -ba ~/rpmbuild/SPECS/hello.spec… ~/rpmbuild/RPMS/aarch64/hello-euler-1.0-1.aarch64.rpm$ dnf -y install ~/rpmbuild/RPMS/*/*.rpm$ rpm -q hello-euler && /usr/bin/hello-eulerhello-euler-1.0-1.aarch64hello openEulerA package from a local file:// path installs directly through dnf’s default trust path — for distributing internal tools that is already a usable minimal loop; external distribution is what needs signing (see the end).
A finding from testing: %{?dist} expands to empty
Section titled “A finding from testing: %{?dist} expands to empty”The artifact name is hello-euler-1.0-1.aarch64.rpm — the release is a bare 1, with no .oe2403sp4 suffix (in testing, rpm -q --qf '%{RELEASE}\n' printed 1). Compare against an official package (dnf-4.16.2-10.oe2403sp4):
- openEuler’s official build environment injects the
%distmacro at build time (.oe2403sp4); on ordinary containers/machines this macro is not preset, and%{?dist}quietly expands to empty; - to replicate the official style (internal packages recognizable at a glance by distro and SP), declare it explicitly in
~/.rpmmacros:
%dist .oe2403sp4The value of this gotcha: it gives “should internal packages carry a release tag” a clear decision point — without one (the default), the same spec can be reused across distros; with one, it must be edited manually on version upgrades (or managed centrally via a macro file).
Three disciplines for internal packaging
Section titled “Three disciplines for internal packaging”- Run the full
rpmbuild -bachain on a spec before committing it to the repo (both BUILD→RPMS and SRPMS produced) — running only-bbhides SRPM reproducibility problems; - %files uses an absolute-path whitelist, never wildcarded big directories (packing in something that should not be there is the most common internal-package accident);
- The License field is mandatory (even the minimal spec above has one) — openEuler’s official packages follow Mulan PSL v2 and other licenses; internal packages fill in their actual license, and a false License is a compliance mine.
Unverified
Section titled “Unverified”- Signing home-grown RPMs (rpmsign + a self-built GPG + import on the distribution side) not tested in this environment (a prerequisite for external distribution, queued for a later batch);
- Dissecting openEuler’s official spec structure (the spec ecosystem on src-openEuler/Gitee, Mulan PSL license headers) left for a deep-dive page;
- mock/scm packaging workflows not covered (this page is the minimal loop).